Skip to content

Commit

Permalink
Make it possible to disable using the 1Password ssh agent
Browse files Browse the repository at this point in the history
Currently if `op` is found in the user's `$PATH`, the quickstart
will try to use its `ssh` agent whether or not there are any keys
in there. Make it possible for users to disable using the 1Password
`ssh` agent.

Signed-off-by: Joe Block <jpb@unixorn.net>
  • Loading branch information
unixorn committed Apr 2, 2024
1 parent 70a356e commit 8903032
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 88 deletions.
142 changes: 75 additions & 67 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,73 +10,73 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents

- [ZSH Quickstart Kit](#zsh-quickstart-kit)
- [Table of Contents](#table-of-contents)
- [Announcement](#announcement)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Fonts](#fonts)
- [OS-specific setup](#os-specific-setup)
- [fzf](#fzf)
- [macOS](#macos)
- [Linux](#linux)
- [Set up Zgenom and the starter kit](#set-up-zgenom-and-the-starter-kit)
- [Contents of the kit](#contents-of-the-kit)
- [Included plugins](#included-plugins)
- [Customizing the kit](#customizing-the-kit)
- [Behavior toggles](#behavior-toggles)
- [zqs](#zqs)
- [zqs check-for-updates](#zqs-check-for-updates)
- [zqs disable-bindkey-handling](#zqs-disable-bindkey-handling)
- [zqs enable-bindkey-handling](#zqs-enable-bindkey-handling)
- [zqs disable-diff-so-fancy](#zqs-disable-diff-so-fancy)
- [zqs enable-diff-so-fancy](#zqs-enable-diff-so-fancy)
- [zqs disable-omz-plugins](#zqs-disable-omz-plugins)
- [zqs enable-control-c-decorator](#zqs-enable-control-c-decorator)
- [zqs disable-control-c-decorator](#zqs-disable-control-c-decorator)
- [zqs enable-omz-plugins](#zqs-enable-omz-plugins)
- [zqs enable-ssh-askpass-require](#zqs-enable-ssh-askpass-require)
- [zqs disable-ssh-askpass-require](#zqs-disable-ssh-askpass-require)
- [zqs-disable-ssh-key-listing](#zqs-disable-ssh-key-listing)
- [zqs-enable-ssh-key-listing](#zqs-enable-ssh-key-listing)
- [zqs-disable-ssh-key-loading](#zqs-disable-ssh-key-loading)
- [zqs-enable-ssh-key-loading](#zqs-enable-ssh-key-loading)
- [zqs-disable-zmv-autoloading](#zqs-disable-zmv-autoloading)
- [zqs-enable-zmv-autoloading](#zqs-enable-zmv-autoloading)
- [\`zqs-disable-zsh-profiling](#zqs-disable-zsh-profiling)
- [\`zqs-enable-zsh-profiling](#zqs-enable-zsh-profiling)
- [zqs selfupdate](#zqs-selfupdate)
- [zqs update](#zqs-update)
- [zqs update-plugins](#zqs-update-plugins)
- [zqs cleanup](#zqs-cleanup)
- [zqs get-setting](#zqs-get-setting)
- [zqs set-setting](#zqs-set-setting)
- [zqs delete-setting](#zqs-delete-setting)
- [Functions and Aliases](#functions-and-aliases)
- [Customizing with ~/.zshrc.d](#customizing-with-zshrcd)
- [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)
- [ZSH options](#zsh-options)
- [Fragment file directories](#fragment-file-directories)
- [Self-update Settings](#self-update-settings)
- [Customizing the plugin list](#customizing-the-plugin-list)
- [Using fragment files](#using-fragment-files)
- [Complete plugin list replacement](#complete-plugin-list-replacement)
- [Disabling zmv](#disabling-zmv)
- [Disabling oh-my-zsh](#disabling-oh-my-zsh)
- [FAQ](#faq)
- [How do I reconfigure the prompt?](#how-do-i-reconfigure-the-prompt)
- [Powerlevel 10k warns that there is console output during startup](#powerlevel-10k-warns-that-there-is-console-output-during-startup)
- [I added a new completion plugin, and it isn't working](#i-added-a-new-completion-plugin-and-it-isnt-working)
- [I get a git error when I try to update the kit](#i-get-a-git-error-when-i-try-to-update-the-kit)
- [GNU stow is warning that stowing zsh would cause conflicts](#gnu-stow-is-warning-that-stowing-zsh-would-cause-conflicts)
- [\_arguments:comparguments:325: can only be called from completion function](#_argumentscomparguments325-can-only-be-called-from-completion-function)
- [Could not open a connection to your authentication agent](#could-not-open-a-connection-to-your-authentication-agent)
- [I want to pin a plugin version](#i-want-to-pin-a-plugin-version)
- [Other Resources](#other-resources)
- [ZSH](#zsh)
- [Dotfiles in general](#dotfiles-in-general)
- [Vim](#vim)
- [Thanks](#thanks)
- [Announcement](#announcement)
- [Installation](#installation)
- [Prerequisites](#prerequisites)
- [Fonts](#fonts)
- [OS-specific setup](#os-specific-setup)
- [fzf](#fzf)
- [macOS](#macos)
- [Linux](#linux)
- [Set up Zgenom and the starter kit](#set-up-zgenom-and-the-starter-kit)
- [Contents of the kit](#contents-of-the-kit)
- [Included plugins](#included-plugins)
- [Customizing the kit](#customizing-the-kit)
- [Behavior toggles](#behavior-toggles)
- [zqs](#zqs)
- [zqs check-for-updates](#zqs-check-for-updates)
- [zqs disable-bindkey-handling](#zqs-disable-bindkey-handling)
- [zqs disable-1password-agent](#zqs-disable-1password-agent)
- [zqs enable-1password-agent](#zqs-enable-1password-agent)
- [zqs enable-bindkey-handling](#zqs-enable-bindkey-handling)
- [zqs disable-diff-so-fancy](#zqs-disable-diff-so-fancy)
- [zqs enable-diff-so-fancy](#zqs-enable-diff-so-fancy)
- [zqs disable-omz-plugins](#zqs-disable-omz-plugins)
- [zqs enable-control-c-decorator](#zqs-enable-control-c-decorator)
- [zqs disable-control-c-decorator](#zqs-disable-control-c-decorator)
- [zqs enable-omz-plugins](#zqs-enable-omz-plugins)
- [zqs enable-ssh-askpass-require](#zqs-enable-ssh-askpass-require)
- [zqs disable-ssh-askpass-require](#zqs-disable-ssh-askpass-require)
- [zqs-disable-ssh-key-listing](#zqs-disable-ssh-key-listing)
- [zqs-enable-ssh-key-listing](#zqs-enable-ssh-key-listing)
- [zqs-disable-ssh-key-loading](#zqs-disable-ssh-key-loading)
- [zqs-enable-ssh-key-loading](#zqs-enable-ssh-key-loading)
- [zqs-disable-zmv-autoloading](#zqs-disable-zmv-autoloading)
- [zqs-enable-zmv-autoloading](#zqs-enable-zmv-autoloading)
- [`zqs-disable-zsh-profiling](#zqs-disable-zsh-profiling)
- [`zqs-enable-zsh-profiling](#zqs-enable-zsh-profiling)
- [zqs selfupdate](#zqs-selfupdate)
- [zqs update](#zqs-update)
- [zqs update-plugins](#zqs-update-plugins)
- [zqs cleanup](#zqs-cleanup)
- [zqs get-setting](#zqs-get-setting)
- [zqs set-setting](#zqs-set-setting)
- [zqs delete-setting](#zqs-delete-setting)
- [Functions and Aliases](#functions-and-aliases)
- [Customizing with ~/.zshrc.d](#customizing-with-zshrcd)
- [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)
- [ZSH options](#zsh-options)
- [Fragment file directories](#fragment-file-directories)
- [Self-update Settings](#self-update-settings)
- [Customizing the plugin list](#customizing-the-plugin-list)
- [Using fragment files](#using-fragment-files)
- [Complete plugin list replacement](#complete-plugin-list-replacement)
- [Disabling zmv](#disabling-zmv)
- [Disabling oh-my-zsh](#disabling-oh-my-zsh)
- [FAQ](#faq)
- [How do I reconfigure the prompt?](#how-do-i-reconfigure-the-prompt)
- [Powerlevel 10k warns that there is console output during startup](#powerlevel-10k-warns-that-there-is-console-output-during-startup)
- [I added a new completion plugin, and it isn't working](#i-added-a-new-completion-plugin-and-it-isnt-working)
- [I get a git error when I try to update the kit](#i-get-a-git-error-when-i-try-to-update-the-kit)
- [GNU stow is warning that stowing zsh would cause conflicts](#gnu-stow-is-warning-that-stowing-zsh-would-cause-conflicts)
- [_arguments:comparguments:325: can only be called from completion function](#_argumentscomparguments325-can-only-be-called-from-completion-function)
- [Could not open a connection to your authentication agent](#could-not-open-a-connection-to-your-authentication-agent)
- [I want to pin a plugin version](#i-want-to-pin-a-plugin-version)
- [Other Resources](#other-resources)
- [ZSH](#zsh)
- [Dotfiles in general](#dotfiles-in-general)
- [Vim](#vim)
- [Thanks](#thanks)

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

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

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.

##### zqs disable-1password-agent

Disable using 1Password's `ssh` agent

##### zqs enable-1password-agent

Enable using 1Password's `ssh` agent starting with the next new ZSH session. This is the default behavior when `op` is in your `$PATH`.

##### zqs enable-bindkey-handling

Let the quickstart's `.zshrc` configure `bindkey` setup and alias expansion. This is the default behavior.
Expand Down
71 changes: 50 additions & 21 deletions zsh/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ function zsh-quickstart-select-powerlevel10k() {
_zqs-trigger-init-rebuild
}

function zsh-quickstart-disable-1password-ssh-agent() {
_zqs-set-setting use-1password-ssh-agent false
}
function zsh-quickstart-enable-1password-ssh-agent() {
_zqs-set-setting use-1password-ssh-agent true
}

# Binary feature settings functions should always be named
# zsh-quickstart-disable-FEATURE and zsh-quickstart-enable-FEATURE

Expand Down Expand Up @@ -244,7 +251,6 @@ function _zqs-disable-diff-so-fancy() {
_zqs-set-setting diff-so-fancy false
}


function zsh-quickstart-check-for-ssh-askpass() {
if ! can_haz ssh-askpass; then
echo "If you disable the ssh-askpass-require feature, you'll"
Expand Down Expand Up @@ -318,32 +324,41 @@ if [[ -z "$LS_COLORS" ]]; then
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:'
fi

load-our-ssh-keys() {
if can_haz op; then
onepassword-agent-check() {
# 1password ssh agent support
if [[ $(_zqs-get-setting use-1password-ssh-agent true) == 'true' ]]; then
if [[ "$(uname -s)" == "Darwin" ]]; then
export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
local ONE_P_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock
fi
if [[ "$(uname -s)" == "Linux" ]]; then
export SSH_AUTH_SOCK=~/.1password/agent.sock
local ONE_P_SOCK=~/.1password/agent.sock
fi
else
# If keychain is installed let it take care of ssh-agent, else do it manually
if can_haz keychain; then
eval `keychain -q --eval`
if [[ -r "$ONE_P_SOCK" ]];then
export SSH_AUTH_SOCK="$ONE_P_SOCK"
else
if [ -z "$SSH_AUTH_SOCK" ]; then
# If user has keychain installed, let it take care of ssh-agent, else do it manually
# Check for a currently running instance of the agent
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')"
if [ "$RUNNING_AGENT" = "0" ]; then
if [ ! -d ~/.ssh ] ; then
mkdir -p ~/.ssh
fi
# Launch a new instance of the agent
ssh-agent -s &> ~/.ssh/ssh-agent
echo "Quickstart is set to use 1Password's ssh agent, but $ONE_P_SOCK isn't readable!"
fi
fi
}

load-our-ssh-keys() {
onepassword-agent-check
# If keychain is installed let it take care of ssh-agent, else do it manually
if can_haz keychain; then
eval `keychain -q --eval`
else
if [ -z "$SSH_AUTH_SOCK" ]; then
# If user has keychain installed, let it take care of ssh-agent, else do it manually
# Check for a currently running instance of the agent
RUNNING_AGENT="$(ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]')"
if [ "$RUNNING_AGENT" = "0" ]; then
if [ ! -d ~/.ssh ] ; then
mkdir -p ~/.ssh
fi
eval $(cat ~/.ssh/ssh-agent)
# Launch a new instance of the agent
ssh-agent -s &> ~/.ssh/ssh-agent
fi
eval $(cat ~/.ssh/ssh-agent)
fi
fi

Expand All @@ -370,7 +385,8 @@ load-our-ssh-keys() {
if [[ $(sw_vers -productVersion | cut -d '.' -f 1) -ge "12" ]]; then
# Load all ssh keys that have pass phrases stored in macOS keychain using new flags
ssh-add --apple-load-keychain
else ssh-add -qA
else
ssh-add -qA
fi
fi

Expand Down Expand Up @@ -779,6 +795,10 @@ function zqs-help() {
echo "zqs cleanup - Cleanup unused plugins after removing them from the list"
echo ""
echo "Quickstart settings commands:"

echo "zqs disable-1password-agent - New sessions will not use 1Password's ssh agent"
echo "zqs enable-1password-agent - New sessions will use 1Password's ssh agent if present."

echo "zqs disable-bindkey-handling - Set the quickstart to not touch any bindkey settings. Useful if you're using another plugin to handle it."
echo "zqs enable-bindkey-handling - Set the quickstart to configure your bindkey settings. This is the default behavior."

Expand Down Expand Up @@ -849,6 +869,15 @@ function zqs() {

# Set/Unset settings

'disable-1password-agent')
echo "Disabling 1password ssh-agent. New ZSH sessions will no longer use 1password's ssh agent."
_zqs-set-setting use-1password-ssh-agent false
;;
'enable-1password-agent')
echo "Enabling 1password ssh-agent. New ZSH sessions will use 1password's ssh agent."
_zqs-set-setting use-1password-ssh-agent true
;;

'disable-bindkey-handling')
zsh-quickstart-disable-bindkey-handling
;;
Expand Down

0 comments on commit 8903032

Please sign in to comment.