From 8fd9f6a8e35ac803882458975578bc1512d14d57 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 29 Sep 2015 19:41:04 +0100 Subject: [PATCH 1/5] Ensure ssh-agent is running and a default key is added. --- .bashrc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.bashrc b/.bashrc index 6c7ecc0..f87f7d0 100644 --- a/.bashrc +++ b/.bashrc @@ -74,4 +74,29 @@ export GOPATH=${HOME}/src/go for FILE in ~/.bash/auto_complete.d/*; do source ${FILE}; done #-------------------------------------------------------------------------------- +#-------------------------------------------------------------------------------- +# Run an SSH agent, if possible +#-------------------------------------------------------------------------------- +SSH_ENV="$HOME/.ssh/environment" + +function start_agent { + echo -n "Initialising new SSH agent... " + /usr/bin/ssh-agent 2> /dev/null | sed 's/^echo/#echo/' > "${SSH_ENV}" + pgrep ssh-agent > /dev/null && echo "succeeded" || echo "failed" + chmod 0600 "${SSH_ENV}" + . "${SSH_ENV}" > /dev/null + /usr/bin/ssh-add ~/.ssh/scott_dsa +} + +# Source SSH settings, if applicable +if [ -f "${SSH_ENV}" ]; then + . "${SSH_ENV}" > /dev/null + pgrep ssh-agent | grep -E "^${SSH_AGENT_PID}" > /dev/null || { + start_agent + } +else + start_agent +fi +#-------------------------------------------------------------------------------- + [ -f ~/.bashrc_local ] && source ~/.bashrc_local From 56e206ab74a25bf9ff2812d5328d085f0eb3196c Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 29 Sep 2015 19:49:49 +0100 Subject: [PATCH 2/5] Ensure a noop if we have an ssh-agent environment configured. --- .bashrc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.bashrc b/.bashrc index f87f7d0..467f2e6 100644 --- a/.bashrc +++ b/.bashrc @@ -88,14 +88,17 @@ function start_agent { /usr/bin/ssh-add ~/.ssh/scott_dsa } -# Source SSH settings, if applicable -if [ -f "${SSH_ENV}" ]; then - . "${SSH_ENV}" > /dev/null - pgrep ssh-agent | grep -E "^${SSH_AGENT_PID}" > /dev/null || { - start_agent - } -else - start_agent +# Check if we already have an agent running and sourced +if [ -z "${SSH_AUTH_SOCK}" ]; then + # Source SSH settings, if applicable + if [ -f "${SSH_ENV}" ]; then + . "${SSH_ENV}" > /dev/null + pgrep ssh-agent | grep -E "^${SSH_AGENT_PID}" > /dev/null || { + start_agent + } + else + start_agent + fi fi #-------------------------------------------------------------------------------- From 10d8d833bd31b26320fccc51c9c98a4eeeb53b64 Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 29 Sep 2015 20:21:08 +0100 Subject: [PATCH 3/5] Make 'git history' alias backward compatible. --- .gitconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitconfig b/.gitconfig index c9e6052..9e3b898 100644 --- a/.gitconfig +++ b/.gitconfig @@ -16,7 +16,7 @@ lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all lg = !"git lg1" lgd = log -p --decorate - history = log --oneline --abbrev-commit --all --graph --decorate + history = log --pretty=oneline --abbrev-commit --all --graph --decorate tidy = remote prune origin st = status ci = commit From 8cfcd70408f2d608b3424ad9dc81ed25959f6aec Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 29 Sep 2015 20:56:02 +0100 Subject: [PATCH 4/5] Add auto-completion for scp. --- .bash/auto_complete.d/ssh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bash/auto_complete.d/ssh b/.bash/auto_complete.d/ssh index ea18fdb..521db46 100644 --- a/.bash/auto_complete.d/ssh +++ b/.bash/auto_complete.d/ssh @@ -22,4 +22,6 @@ _ssh() { complete -o bashdefault -o default -o nospace -F _ssh ssh 2>/dev/null \ || complete -o default -o nospace -F _ssh ssh +complete -o bashdefault -o default -o nospace -F _ssh scp 2>/dev/null \ + || complete -o default -o nospace -F _ssh scp #-------------------------------------------------------------------------------- From f77aef977933b1731dc3e26c83c7701f8ffe865a Mon Sep 17 00:00:00 2001 From: Scott Wallace Date: Tue, 29 Sep 2015 20:59:44 +0100 Subject: [PATCH 5/5] Provide a mechanism to allow hostname completion for any command. Added: - ssh - scp - ftp - ping - telnet - curl - nc --- .bash/auto_complete.d/ssh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.bash/auto_complete.d/ssh b/.bash/auto_complete.d/ssh index 521db46..49bbbc2 100644 --- a/.bash/auto_complete.d/ssh +++ b/.bash/auto_complete.d/ssh @@ -20,8 +20,8 @@ _ssh() { fi } -complete -o bashdefault -o default -o nospace -F _ssh ssh 2>/dev/null \ - || complete -o default -o nospace -F _ssh ssh -complete -o bashdefault -o default -o nospace -F _ssh scp 2>/dev/null \ - || complete -o default -o nospace -F _ssh scp +for CMD in ssh scp telnet nc ftp ping curl; do + complete -o bashdefault -o default -o nospace -F _ssh ${CMD} 2>/dev/null \ + || complete -o default -o nospace -F _ssh ${CMD} +done #--------------------------------------------------------------------------------