summaryrefslogtreecommitdiffstats
path: root/.config/fish/functions
diff options
context:
space:
mode:
Diffstat (limited to '.config/fish/functions')
-rw-r--r--.config/fish/functions/fish_ssh_agent.fish32
1 files changed, 32 insertions, 0 deletions
diff --git a/.config/fish/functions/fish_ssh_agent.fish b/.config/fish/functions/fish_ssh_agent.fish
new file mode 100644
index 0000000..5960b75
--- /dev/null
+++ b/.config/fish/functions/fish_ssh_agent.fish
@@ -0,0 +1,32 @@
1function __ssh_agent_is_started -d "check if ssh agent is already started"
2 if begin; test -f $SSH_ENV; and test -z "$SSH_AGENT_PID"; end
3 source $SSH_ENV > /dev/null
4 end
5
6 if test -z "$SSH_AGENT_PID"
7 return 1
8 end
9
10 ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep -q ssh-agent
11 #pgrep ssh-agent
12 return $status
13end
14
15
16function __ssh_agent_start -d "start a new ssh agent"
17 ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV
18 chmod 600 $SSH_ENV
19 source $SSH_ENV > /dev/null
20 true # suppress errors from setenv, i.e. set -gx
21end
22
23
24function fish_ssh_agent --description "Start ssh-agent if not started yet, or uses already started ssh-agent."
25 if test -z "$SSH_ENV"
26 set -xg SSH_ENV $HOME/.ssh/environment
27 end
28
29 if not __ssh_agent_is_started
30 __ssh_agent_start
31 end
32end