diff options
author | Yigit Sever | 2024-04-25 17:45:48 +0300 |
---|---|---|
committer | Yigit Sever | 2024-04-25 17:45:48 +0300 |
commit | 7bc07e5f4696da9f7881625d2fbe3d1cde86539b (patch) | |
tree | ea2b5246d8ed743af255011017ccaf0194b099af /.config/fish/functions | |
parent | db36e3c3957f01de9128971f326d36d4dc1d81bd (diff) | |
download | dotfiles-7bc07e5f4696da9f7881625d2fbe3d1cde86539b.tar.gz dotfiles-7bc07e5f4696da9f7881625d2fbe3d1cde86539b.tar.bz2 dotfiles-7bc07e5f4696da9f7881625d2fbe3d1cde86539b.zip |
fish: use fish_ssh_agent
Diffstat (limited to '.config/fish/functions')
-rw-r--r-- | .config/fish/functions/fish_ssh_agent.fish | 32 |
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 @@ | |||
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 | ||