From a631177116cc6d74f32ae7a87ed1e2a5ac0db113 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Wed, 8 Nov 2023 13:00:45 +0700 Subject: [PATCH] Get ssh-agent working properly with fish --- .config/fish/config.fish | 2 ++ .config/fish/fish_variables | 3 +- .config/fish/functions/fish_ssh_agent.fish | 32 ++++++++++++++++++++++ .config/fish/functions/vim.fish | 3 ++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .config/fish/functions/fish_ssh_agent.fish create mode 100644 .config/fish/functions/vim.fish diff --git a/.config/fish/config.fish b/.config/fish/config.fish index 06a5275..d4b7c5f 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -73,3 +73,5 @@ function fish_prompt --description 'Write out the prompt; do not replace this. I printf "%b" (string join " \n" (vterm_old_fish_prompt)) vterm_prompt_end end + +fish_ssh_agent \ No newline at end of file diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables index 2373482..ba7c7bb 100644 --- a/.config/fish/fish_variables +++ b/.config/fish/fish_variables @@ -6,6 +6,7 @@ SETUVAR --export LC_COLLATE:C SETUVAR --export --path LD_LIBRARY_PATH:/usr/local/lib SETUVAR --export PYTHONSTARTUP:/etc/python/pythonrc SETUVAR --export RUSTUP_HOME:/home/joe/\x2elocal/share/rustup/ +SETUVAR SSH_AUTH_SOCK:/run/user/1000/ssh\x2dagent\x2esocket SETUVAR XDG_CACHE_HOME:/home/joe/\x2ecache SETUVAR XDG_CONFIG_HOME:/home/joe/\x2econfig SETUVAR XDG_DATA_HOME:/home/joe/\x2elocal/share @@ -40,4 +41,4 @@ SETUVAR fish_pager_color_description:B3A06D\x1eyellow SETUVAR fish_pager_color_prefix:normal\x1e\x2d\x2dbold\x1e\x2d\x2dunderline SETUVAR fish_pager_color_progress:brwhite\x1e\x2d\x2dbackground\x3dcyan SETUVAR fish_pager_color_selected_background:\x2dr -SETUVAR fish_user_paths:/home/joe/\x2elocal/share/JetBrains/Toolbox/scripts\x1e/home/joe/\x2elocal/bin/elm\x1e/home/joe/\x2elocal/share/bin/cargo/bin\x1e\x1e/home/joe/\x2elocal/bin +SETUVAR --export fish_user_paths:/home/joe/\x2elocal/share/bin/cargo/bin\x1e/home/joe/\x2elocal/bin\x1e/home/joe/\x2enimble/bin 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 @@ +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 test -z "$SSH_AGENT_PID" + return 1 + end + + ps -ef | grep $SSH_AGENT_PID | grep -v grep | grep -q ssh-agent + #pgrep ssh-agent + return $status +end + + +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 + true # suppress errors from setenv, i.e. set -gx +end + + +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 diff --git a/.config/fish/functions/vim.fish b/.config/fish/functions/vim.fish new file mode 100644 index 0000000..bb30961 --- /dev/null +++ b/.config/fish/functions/vim.fish @@ -0,0 +1,3 @@ +function vim --wraps=nvim --description 'alias vim nvim' + nvim $argv +end