Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to disable using the 1Password ssh agent #288

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
86 changes: 65 additions & 21 deletions zsh/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ function can_haz() {
which "$@" > /dev/null 2>&1
}

function zqs-debug() {
if [[ -f ~/.zqs-debug-mode ]]; then
echo $@
fi
}

# Fix weirdness with intellij
if [[ -z "${INTELLIJ_ENVIRONMENT_READER}" ]]; then
export POWERLEVEL9K_INSTANT_PROMPT='quiet'
Expand Down Expand Up @@ -178,6 +184,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 +257,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 +330,44 @@ 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
zqs-debug "Checking for 1password"
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`
zqs-debug "ONE_P_SOCK=$ONE_P_SOCK"
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
zqs-debug "Set SSH_AUTH_SOCK to $SSH_AUTH_SOCK"
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 +394,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 +804,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 +878,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 All @@ -862,6 +900,12 @@ function zqs() {
'enable-control-c-decorator')
zqs-quickstart-enable-control-c-decorator
;;
'disable-debug-mode')
rm -f ~/.zqs-debug-mode
;;
'enable-debug-mode')
date > ~/.zqs-debug-mode
;;

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