diff options
Diffstat (limited to '.config/fish')
-rw-r--r-- | .config/fish/config.fish | 2 | ||||
-rw-r--r-- | .config/fish/functions/fish_ssh_agent.fish | 32 |
2 files changed, 34 insertions, 0 deletions
diff --git a/.config/fish/config.fish b/.config/fish/config.fish index ad3c299..adcbe4a 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish | |||
@@ -63,4 +63,6 @@ if status is-interactive | |||
63 | 63 | ||
64 | zoxide init fish | source | 64 | zoxide init fish | source |
65 | direnv hook fish | source | 65 | direnv hook fish | source |
66 | |||
67 | fish_ssh_agent | ||
66 | end | 68 | end |
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 @@ | |||
1 | function __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 | ||
13 | end | ||
14 | |||
15 | |||
16 | function __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 | ||
21 | end | ||
22 | |||
23 | |||
24 | function 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 | ||
32 | end | ||