From 6781da5828d2b59931e7b1d7d935990b4ab741a9 Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Sat, 2 May 2015 20:08:49 +0100 Subject: [PATCH] Add ssh-agent setup for fish --- fish/config.fish | 20 ++++++++++++++++++++ fish/functions/start_agent.fish | 9 +++++++++ fish/functions/test_identities.fish | 10 ++++++++++ 3 files changed, 39 insertions(+) create mode 100644 fish/functions/start_agent.fish create mode 100644 fish/functions/test_identities.fish diff --git a/fish/config.fish b/fish/config.fish index 596022f..7f714f3 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -42,6 +42,26 @@ alias mkdir "mkdir -p" # Make sl run ls afterwards alias sl "/usr/local/bin/sl; and ls" +# SSH Agent +setenv SSH_ENV "$HOME/.ssh/environment" +if [ -n "$SSH_AGENT_PID" ] + ps -ef | grep $SSH_AGENT_PID | grep ssh-agent > /dev/null + if [ $status -eq 0 ] + test_identities + end +else + if [ -f $SSH_ENV ] + . $SSH_ENV > /dev/null + end + ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep ssh-agent > /dev/null + if [ $status -eq 0 ] + test_identities + else + start_agent + end +end + + # Fish colour customisations set fish_color_autosuggestion "-o" "black" set fish_color_command "-o" "cyan" diff --git a/fish/functions/start_agent.fish b/fish/functions/start_agent.fish new file mode 100644 index 0000000..9457404 --- /dev/null +++ b/fish/functions/start_agent.fish @@ -0,0 +1,9 @@ +function start_agent + echo "Initializing new SSH agent ..." + ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV + echo "succeeded" + chmod 600 $SSH_ENV + . $SSH_ENV > /dev/null + ssh-add +end + diff --git a/fish/functions/test_identities.fish b/fish/functions/test_identities.fish new file mode 100644 index 0000000..89c8d33 --- /dev/null +++ b/fish/functions/test_identities.fish @@ -0,0 +1,10 @@ +function test_identities + ssh-add -l | grep "The agent has no identities" > /dev/null + if [ $status -eq 0 ] + ssh-add + if [ $status -eq 2 ] + start_agent + end + end +end +