Skip to content

Commit 983438c

Browse files
authored
Merge pull request #288 from unixorn/1p-support
Make it possible to disable using the 1Password `ssh` agent
2 parents ec5b5c6 + 4e0efcb commit 983438c

File tree

2 files changed

+140
-88
lines changed

2 files changed

+140
-88
lines changed

Readme.md

Lines changed: 75 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,73 @@
1010
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1111
## Table of Contents
1212

13-
- [ZSH Quickstart Kit](#zsh-quickstart-kit)
14-
- [Table of Contents](#table-of-contents)
15-
- [Announcement](#announcement)
16-
- [Installation](#installation)
17-
- [Prerequisites](#prerequisites)
18-
- [Fonts](#fonts)
19-
- [OS-specific setup](#os-specific-setup)
20-
- [fzf](#fzf)
21-
- [macOS](#macos)
22-
- [Linux](#linux)
23-
- [Set up Zgenom and the starter kit](#set-up-zgenom-and-the-starter-kit)
24-
- [Contents of the kit](#contents-of-the-kit)
25-
- [Included plugins](#included-plugins)
26-
- [Customizing the kit](#customizing-the-kit)
27-
- [Behavior toggles](#behavior-toggles)
28-
- [zqs](#zqs)
29-
- [zqs check-for-updates](#zqs-check-for-updates)
30-
- [zqs disable-bindkey-handling](#zqs-disable-bindkey-handling)
31-
- [zqs enable-bindkey-handling](#zqs-enable-bindkey-handling)
32-
- [zqs disable-diff-so-fancy](#zqs-disable-diff-so-fancy)
33-
- [zqs enable-diff-so-fancy](#zqs-enable-diff-so-fancy)
34-
- [zqs disable-omz-plugins](#zqs-disable-omz-plugins)
35-
- [zqs enable-control-c-decorator](#zqs-enable-control-c-decorator)
36-
- [zqs disable-control-c-decorator](#zqs-disable-control-c-decorator)
37-
- [zqs enable-omz-plugins](#zqs-enable-omz-plugins)
38-
- [zqs enable-ssh-askpass-require](#zqs-enable-ssh-askpass-require)
39-
- [zqs disable-ssh-askpass-require](#zqs-disable-ssh-askpass-require)
40-
- [zqs-disable-ssh-key-listing](#zqs-disable-ssh-key-listing)
41-
- [zqs-enable-ssh-key-listing](#zqs-enable-ssh-key-listing)
42-
- [zqs-disable-ssh-key-loading](#zqs-disable-ssh-key-loading)
43-
- [zqs-enable-ssh-key-loading](#zqs-enable-ssh-key-loading)
44-
- [zqs-disable-zmv-autoloading](#zqs-disable-zmv-autoloading)
45-
- [zqs-enable-zmv-autoloading](#zqs-enable-zmv-autoloading)
46-
- [\`zqs-disable-zsh-profiling](#zqs-disable-zsh-profiling)
47-
- [\`zqs-enable-zsh-profiling](#zqs-enable-zsh-profiling)
48-
- [zqs selfupdate](#zqs-selfupdate)
49-
- [zqs update](#zqs-update)
50-
- [zqs update-plugins](#zqs-update-plugins)
51-
- [zqs cleanup](#zqs-cleanup)
52-
- [zqs get-setting](#zqs-get-setting)
53-
- [zqs set-setting](#zqs-set-setting)
54-
- [zqs delete-setting](#zqs-delete-setting)
55-
- [Functions and Aliases](#functions-and-aliases)
56-
- [Customizing with ~/.zshrc.d](#customizing-with-zshrcd)
57-
- [I like a plugin, but some of the aliases and functions it installs overwrite other commands or aliases I use](#i-like-a-plugin-but-some-of-the-aliases-and-functions-it-installs-overwrite-other-commands-or-aliases-i-use)
58-
- [ZSH options](#zsh-options)
59-
- [Fragment file directories](#fragment-file-directories)
60-
- [Self-update Settings](#self-update-settings)
61-
- [Customizing the plugin list](#customizing-the-plugin-list)
62-
- [Using fragment files](#using-fragment-files)
63-
- [Complete plugin list replacement](#complete-plugin-list-replacement)
64-
- [Disabling zmv](#disabling-zmv)
65-
- [Disabling oh-my-zsh](#disabling-oh-my-zsh)
66-
- [FAQ](#faq)
67-
- [How do I reconfigure the prompt?](#how-do-i-reconfigure-the-prompt)
68-
- [Powerlevel 10k warns that there is console output during startup](#powerlevel-10k-warns-that-there-is-console-output-during-startup)
69-
- [I added a new completion plugin, and it isn't working](#i-added-a-new-completion-plugin-and-it-isnt-working)
70-
- [I get a git error when I try to update the kit](#i-get-a-git-error-when-i-try-to-update-the-kit)
71-
- [GNU stow is warning that stowing zsh would cause conflicts](#gnu-stow-is-warning-that-stowing-zsh-would-cause-conflicts)
72-
- [\_arguments:comparguments:325: can only be called from completion function](#_argumentscomparguments325-can-only-be-called-from-completion-function)
73-
- [Could not open a connection to your authentication agent](#could-not-open-a-connection-to-your-authentication-agent)
74-
- [I want to pin a plugin version](#i-want-to-pin-a-plugin-version)
75-
- [Other Resources](#other-resources)
76-
- [ZSH](#zsh)
77-
- [Dotfiles in general](#dotfiles-in-general)
78-
- [Vim](#vim)
79-
- [Thanks](#thanks)
13+
- [Announcement](#announcement)
14+
- [Installation](#installation)
15+
- [Prerequisites](#prerequisites)
16+
- [Fonts](#fonts)
17+
- [OS-specific setup](#os-specific-setup)
18+
- [fzf](#fzf)
19+
- [macOS](#macos)
20+
- [Linux](#linux)
21+
- [Set up Zgenom and the starter kit](#set-up-zgenom-and-the-starter-kit)
22+
- [Contents of the kit](#contents-of-the-kit)
23+
- [Included plugins](#included-plugins)
24+
- [Customizing the kit](#customizing-the-kit)
25+
- [Behavior toggles](#behavior-toggles)
26+
- [zqs](#zqs)
27+
- [zqs check-for-updates](#zqs-check-for-updates)
28+
- [zqs disable-bindkey-handling](#zqs-disable-bindkey-handling)
29+
- [zqs disable-1password-agent](#zqs-disable-1password-agent)
30+
- [zqs enable-1password-agent](#zqs-enable-1password-agent)
31+
- [zqs enable-bindkey-handling](#zqs-enable-bindkey-handling)
32+
- [zqs disable-diff-so-fancy](#zqs-disable-diff-so-fancy)
33+
- [zqs enable-diff-so-fancy](#zqs-enable-diff-so-fancy)
34+
- [zqs disable-omz-plugins](#zqs-disable-omz-plugins)
35+
- [zqs enable-control-c-decorator](#zqs-enable-control-c-decorator)
36+
- [zqs disable-control-c-decorator](#zqs-disable-control-c-decorator)
37+
- [zqs enable-omz-plugins](#zqs-enable-omz-plugins)
38+
- [zqs enable-ssh-askpass-require](#zqs-enable-ssh-askpass-require)
39+
- [zqs disable-ssh-askpass-require](#zqs-disable-ssh-askpass-require)
40+
- [zqs-disable-ssh-key-listing](#zqs-disable-ssh-key-listing)
41+
- [zqs-enable-ssh-key-listing](#zqs-enable-ssh-key-listing)
42+
- [zqs-disable-ssh-key-loading](#zqs-disable-ssh-key-loading)
43+
- [zqs-enable-ssh-key-loading](#zqs-enable-ssh-key-loading)
44+
- [zqs-disable-zmv-autoloading](#zqs-disable-zmv-autoloading)
45+
- [zqs-enable-zmv-autoloading](#zqs-enable-zmv-autoloading)
46+
- [`zqs-disable-zsh-profiling](#zqs-disable-zsh-profiling)
47+
- [`zqs-enable-zsh-profiling](#zqs-enable-zsh-profiling)
48+
- [zqs selfupdate](#zqs-selfupdate)
49+
- [zqs update](#zqs-update)
50+
- [zqs update-plugins](#zqs-update-plugins)
51+
- [zqs cleanup](#zqs-cleanup)
52+
- [zqs get-setting](#zqs-get-setting)
53+
- [zqs set-setting](#zqs-set-setting)
54+
- [zqs delete-setting](#zqs-delete-setting)
55+
- [Functions and Aliases](#functions-and-aliases)
56+
- [Customizing with ~/.zshrc.d](#customizing-with-zshrcd)
57+
- [I like a plugin, but some of the aliases and functions it installs overwrite other commands or aliases I use](#i-like-a-plugin-but-some-of-the-aliases-and-functions-it-installs-overwrite-other-commands-or-aliases-i-use)
58+
- [ZSH options](#zsh-options)
59+
- [Fragment file directories](#fragment-file-directories)
60+
- [Self-update Settings](#self-update-settings)
61+
- [Customizing the plugin list](#customizing-the-plugin-list)
62+
- [Using fragment files](#using-fragment-files)
63+
- [Complete plugin list replacement](#complete-plugin-list-replacement)
64+
- [Disabling zmv](#disabling-zmv)
65+
- [Disabling oh-my-zsh](#disabling-oh-my-zsh)
66+
- [FAQ](#faq)
67+
- [How do I reconfigure the prompt?](#how-do-i-reconfigure-the-prompt)
68+
- [Powerlevel 10k warns that there is console output during startup](#powerlevel-10k-warns-that-there-is-console-output-during-startup)
69+
- [I added a new completion plugin, and it isn't working](#i-added-a-new-completion-plugin-and-it-isnt-working)
70+
- [I get a git error when I try to update the kit](#i-get-a-git-error-when-i-try-to-update-the-kit)
71+
- [GNU stow is warning that stowing zsh would cause conflicts](#gnu-stow-is-warning-that-stowing-zsh-would-cause-conflicts)
72+
- [_arguments:comparguments:325: can only be called from completion function](#_argumentscomparguments325-can-only-be-called-from-completion-function)
73+
- [Could not open a connection to your authentication agent](#could-not-open-a-connection-to-your-authentication-agent)
74+
- [I want to pin a plugin version](#i-want-to-pin-a-plugin-version)
75+
- [Other Resources](#other-resources)
76+
- [ZSH](#zsh)
77+
- [Dotfiles in general](#dotfiles-in-general)
78+
- [Vim](#vim)
79+
- [Thanks](#thanks)
8080

8181
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
8282

@@ -252,6 +252,14 @@ Updates the quickstart kit if it has been longer than seven days since the last
252252

253253
Disable `bindkey` setup and alias expansion in the quickstart `.zshrc` so people can use plugins like [globalias](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/globalias) to handle it instead.
254254

255+
##### zqs disable-1password-agent
256+
257+
Disable using 1Password's `ssh` agent
258+
259+
##### zqs enable-1password-agent
260+
261+
Enable using 1Password's `ssh` agent starting with the next new ZSH session. This is the default behavior when `op` is in your `$PATH`.
262+
255263
##### zqs enable-bindkey-handling
256264

257265
Let the quickstart's `.zshrc` configure `bindkey` setup and alias expansion. This is the default behavior.

zsh/.zshrc

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function can_haz() {
2929
which "$@" > /dev/null 2>&1
3030
}
3131

32+
function zqs-debug() {
33+
if [[ -f ~/.zqs-debug-mode ]]; then
34+
echo $@
35+
fi
36+
}
37+
3238
# Fix weirdness with intellij
3339
if [[ -z "${INTELLIJ_ENVIRONMENT_READER}" ]]; then
3440
export POWERLEVEL9K_INSTANT_PROMPT='quiet'
@@ -178,6 +184,13 @@ function zsh-quickstart-select-powerlevel10k() {
178184
_zqs-trigger-init-rebuild
179185
}
180186

187+
function zsh-quickstart-disable-1password-ssh-agent() {
188+
_zqs-set-setting use-1password-ssh-agent false
189+
}
190+
function zsh-quickstart-enable-1password-ssh-agent() {
191+
_zqs-set-setting use-1password-ssh-agent true
192+
}
193+
181194
# Binary feature settings functions should always be named
182195
# zsh-quickstart-disable-FEATURE and zsh-quickstart-enable-FEATURE
183196

@@ -242,7 +255,6 @@ function _zqs-disable-diff-so-fancy() {
242255
_zqs-set-setting diff-so-fancy false
243256
}
244257

245-
246258
function zsh-quickstart-check-for-ssh-askpass() {
247259
if ! can_haz ssh-askpass; then
248260
echo "If you disable the ssh-askpass-require feature, you'll"
@@ -316,32 +328,44 @@ if [[ -z "$LS_COLORS" ]]; then
316328
export LS_COLORS='di=1;34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'
317329
fi
318330

319-
load-our-ssh-keys() {
320-
if can_haz op; then
331+
onepassword-agent-check() {
332+
# 1password ssh agent support
333+
zqs-debug "Checking for 1password"
334+
if [[ $(_zqs-get-setting use-1password-ssh-agent true) == 'true' ]]; then
321335
if [[ "$(uname -s)" == "Darwin" ]]; then
322-
export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
336+
local ONE_P_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
323337
fi
324338
if [[ "$(uname -s)" == "Linux" ]]; then
325-
export SSH_AUTH_SOCK=~/.1password/agent.sock
339+
local ONE_P_SOCK=~/.1password/agent.sock
326340
fi
327-
else
328-
# If keychain is installed let it take care of ssh-agent, else do it manually
329-
if can_haz keychain; then
330-
eval `keychain -q --eval`
341+
zqs-debug "ONE_P_SOCK=$ONE_P_SOCK"
342+
if [[ -r "$ONE_P_SOCK" ]];then
343+
export SSH_AUTH_SOCK="$ONE_P_SOCK"
331344
else
332-
if [ -z "$SSH_AUTH_SOCK" ]; then
333-
# If user has keychain installed, let it take care of ssh-agent, else do it manually
334-
# Check for a currently running instance of the agent
335-
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')"
336-
if [ "$RUNNING_AGENT" = "0" ]; then
337-
if [ ! -d ~/.ssh ] ; then
338-
mkdir -p ~/.ssh
339-
fi
340-
# Launch a new instance of the agent
341-
ssh-agent -s &> ~/.ssh/ssh-agent
345+
echo "Quickstart is set to use 1Password's ssh agent, but $ONE_P_SOCK isn't readable!"
346+
fi
347+
zqs-debug "Set SSH_AUTH_SOCK to $SSH_AUTH_SOCK"
348+
fi
349+
}
350+
351+
load-our-ssh-keys() {
352+
onepassword-agent-check
353+
# If keychain is installed let it take care of ssh-agent, else do it manually
354+
if can_haz keychain; then
355+
eval `keychain -q --eval`
356+
else
357+
if [ -z "$SSH_AUTH_SOCK" ]; then
358+
# If user has keychain installed, let it take care of ssh-agent, else do it manually
359+
# Check for a currently running instance of the agent
360+
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')"
361+
if [ "$RUNNING_AGENT" = "0" ]; then
362+
if [ ! -d ~/.ssh ] ; then
363+
mkdir -p ~/.ssh
342364
fi
343-
eval $(cat ~/.ssh/ssh-agent)
365+
# Launch a new instance of the agent
366+
ssh-agent -s &> ~/.ssh/ssh-agent
344367
fi
368+
eval $(cat ~/.ssh/ssh-agent)
345369
fi
346370
fi
347371

@@ -368,7 +392,8 @@ load-our-ssh-keys() {
368392
if [[ $(sw_vers -productVersion | cut -d '.' -f 1) -ge "12" ]]; then
369393
# Load all ssh keys that have pass phrases stored in macOS keychain using new flags
370394
ssh-add --apple-load-keychain
371-
else ssh-add -qA
395+
else
396+
ssh-add -qA
372397
fi
373398
fi
374399

@@ -777,6 +802,10 @@ function zqs-help() {
777802
echo "zqs cleanup - Cleanup unused plugins after removing them from the list"
778803
echo ""
779804
echo "Quickstart settings commands:"
805+
806+
echo "zqs disable-1password-agent - New sessions will not use 1Password's ssh agent"
807+
echo "zqs enable-1password-agent - New sessions will use 1Password's ssh agent if present."
808+
780809
echo "zqs disable-bindkey-handling - Set the quickstart to not touch any bindkey settings. Useful if you're using another plugin to handle it."
781810
echo "zqs enable-bindkey-handling - Set the quickstart to configure your bindkey settings. This is the default behavior."
782811

@@ -847,6 +876,15 @@ function zqs() {
847876

848877
# Set/Unset settings
849878

879+
'disable-1password-agent')
880+
echo "Disabling 1password ssh-agent. New ZSH sessions will no longer use 1password's ssh agent."
881+
_zqs-set-setting use-1password-ssh-agent false
882+
;;
883+
'enable-1password-agent')
884+
echo "Enabling 1password ssh-agent. New ZSH sessions will use 1password's ssh agent."
885+
_zqs-set-setting use-1password-ssh-agent true
886+
;;
887+
850888
'disable-bindkey-handling')
851889
zsh-quickstart-disable-bindkey-handling
852890
;;
@@ -860,6 +898,12 @@ function zqs() {
860898
'enable-control-c-decorator')
861899
zqs-quickstart-enable-control-c-decorator
862900
;;
901+
'disable-debug-mode')
902+
rm -f ~/.zqs-debug-mode
903+
;;
904+
'enable-debug-mode')
905+
date > ~/.zqs-debug-mode
906+
;;
863907

864908
'disable-diff-so-fancy')
865909
echo "Disabling diff-so-fancy plugin. New ZSH sessions will no longer use the plugin."

0 commit comments

Comments
 (0)