diff --git a/README.md b/README.md index bd68f3e..adfb35b 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,24 @@ Utility functions to start your ssh agent when using fish shell. You will only need to run `ssh-add` and type your password once, after the running ssh_agent should do the work for you. + +## Usage + +```fish +fish-ssh-agent +``` + + ## Installation -### Using [fundle](https://github.com/tuvistavie/fundle) (recommended) - -Add - -``` -fundle plugin 'tuvistavie/fish-ssh-agent' +```fish +git clone https://.../fish-ssh-agent +source fish-ssh-agent/install.fish ``` -to your `config.fish`, reload your shell and run `fundle install`. +or -### Using [Fisherman](https://github.com/fisherman/fisherman) - - fisher install tuvistavie/fish-ssh-agent - - -### Manually - -Put `functions/__ssh_agent_start` your `~/.config/fish/functions` directory, -and source `init.fish` on startup. +```sh +git clone https://.../fish-ssh-agent +cp fish-ssh-agent/functions/* ~/.config/fish/functions +``` diff --git a/functions/__ssh_agent_is_started.fish b/functions/__ssh_agent_is_started.fish index 882c8f0..fb3b46e 100644 --- a/functions/__ssh_agent_is_started.fish +++ b/functions/__ssh_agent_is_started.fish @@ -1,12 +1,13 @@ function __ssh_agent_is_started -d "check if ssh agent is already started" - if begin; test -f $SSH_ENV; and test -z "$SSH_AGENT_PID"; end - source $SSH_ENV > /dev/null - end + if begin; test -f $SSH_ENV; and test -z "$SSH_AGENT_PID"; end + source $SSH_ENV > /dev/null + end - if test -z "$SSH_AGENT_PID" - return 1 - end + if test -z "$SSH_AGENT_PID" + return 1 + end - ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep -q ssh-agent - return $status + ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep -q ssh-agent + #pgrep ssh-agent + return $status end diff --git a/functions/__ssh_agent_start.fish b/functions/__ssh_agent_start.fish index 3766fe4..3e965ce 100644 --- a/functions/__ssh_agent_start.fish +++ b/functions/__ssh_agent_start.fish @@ -1,5 +1,5 @@ function __ssh_agent_start -d "start a new ssh agent" - ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV - chmod 600 $SSH_ENV - source $SSH_ENV > /dev/null + ssh-agent -c | sed 's/^echo/#echo/' > $SSH_ENV + chmod 600 $SSH_ENV + source $SSH_ENV > /dev/null end diff --git a/functions/fish-ssh-agent.fish b/functions/fish-ssh-agent.fish new file mode 100644 index 0000000..177f097 --- /dev/null +++ b/functions/fish-ssh-agent.fish @@ -0,0 +1,9 @@ +function fish-ssh-agent --description "Start ssh-agent if not started yet, or uses already started ssh-agent." + if test -z "$SSH_ENV" + set -xg SSH_ENV $HOME/.ssh/environment + end + + if not __ssh_agent_is_started + __ssh_agent_start + end +end \ No newline at end of file diff --git a/init.fish b/init.fish deleted file mode 100644 index 719087a..0000000 --- a/init.fish +++ /dev/null @@ -1,7 +0,0 @@ -if test -z "$SSH_ENV" - set -xg SSH_ENV $HOME/.ssh/environment -end - -if not __ssh_agent_is_started - __ssh_agent_start -end diff --git a/install.fish b/install.fish new file mode 100644 index 0000000..9dd3eb3 --- /dev/null +++ b/install.fish @@ -0,0 +1,3 @@ + +source functions/* +funcsave __ssh_agent_is_started __ssh_agent_start fish-ssh-agent