fish: smarter SSH_AUTH_SOCK refresh, reading tmux session env over stale global
This commit is contained in:
parent
497cbce0c6
commit
e3c9f4edd5
@ -12,8 +12,94 @@ set fish_color_valid_path
|
|||||||
set -g fish_greeting
|
set -g fish_greeting
|
||||||
|
|
||||||
|
|
||||||
if test -S ~/.1password/agent.sock
|
function __tmux_environment_value --argument-names name
|
||||||
set -gx SSH_AUTH_SOCK ~/.1password/agent.sock
|
# The session environment is refreshed on every attach (update-environment),
|
||||||
|
# while the global one is frozen at server start. Prefer the session value,
|
||||||
|
# treat its "-NAME" removal marker as unset, and only fall back to the
|
||||||
|
# global environment when the session has no entry at all.
|
||||||
|
set -l value (tmux show-environment "$name" 2>/dev/null)
|
||||||
|
if test -z "$value"
|
||||||
|
set value (tmux show-environment -g "$name" 2>/dev/null)
|
||||||
|
end
|
||||||
|
if string match -q -- "$name=*" "$value"
|
||||||
|
string replace -r "^$name=" "" -- "$value"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __is_1password_ssh_auth_sock --argument-names sock
|
||||||
|
test -n "$sock"; or return 1
|
||||||
|
|
||||||
|
string match -q -- "$HOME/.1password/agent.sock" "$sock"
|
||||||
|
or string match -q -- "$HOME/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" "$sock"
|
||||||
|
end
|
||||||
|
|
||||||
|
function __is_local_macos_ssh_auth_sock --argument-names sock
|
||||||
|
test -n "$sock"; or return 1
|
||||||
|
|
||||||
|
string match -q -- "/var/run/com.apple.launchd.*" "$sock"
|
||||||
|
or string match -q -- "/private/tmp/com.apple.launchd.*" "$sock"
|
||||||
|
end
|
||||||
|
|
||||||
|
function __find_forwarded_ssh_auth_sock
|
||||||
|
for sock in /tmp/ma-*/* /tmp/ssh-*/* /private/tmp/ssh-*/*
|
||||||
|
if test -S "$sock"
|
||||||
|
echo "$sock"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __refresh_ssh_auth_sock
|
||||||
|
set -l tmux_sock
|
||||||
|
set -l in_ssh_session 0
|
||||||
|
|
||||||
|
if set -q TMUX
|
||||||
|
set tmux_sock (__tmux_environment_value SSH_AUTH_SOCK)
|
||||||
|
set -l tmux_ssh_connection (__tmux_environment_value SSH_CONNECTION)
|
||||||
|
if test -n "$tmux_ssh_connection"
|
||||||
|
set -gx SSH_CONNECTION "$tmux_ssh_connection"
|
||||||
|
set in_ssh_session 1
|
||||||
|
else
|
||||||
|
set -e SSH_CONNECTION SSH_CLIENT SSH_TTY
|
||||||
|
end
|
||||||
|
else if set -q SSH_CONNECTION
|
||||||
|
set in_ssh_session 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if test "$in_ssh_session" = 1
|
||||||
|
if test -n "$tmux_sock"; and test -S "$tmux_sock"; and not __is_1password_ssh_auth_sock "$tmux_sock"; and not __is_local_macos_ssh_auth_sock "$tmux_sock"
|
||||||
|
set -gx SSH_AUTH_SOCK "$tmux_sock"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q SSH_AUTH_SOCK; and test -S "$SSH_AUTH_SOCK"; and not __is_1password_ssh_auth_sock "$SSH_AUTH_SOCK"; and not __is_local_macos_ssh_auth_sock "$SSH_AUTH_SOCK"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l forwarded_sock (__find_forwarded_ssh_auth_sock)
|
||||||
|
if test -n "$forwarded_sock"
|
||||||
|
set -gx SSH_AUTH_SOCK "$forwarded_sock"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
set -e SSH_AUTH_SOCK
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -S "$HOME/.1password/agent.sock"
|
||||||
|
set -gx SSH_AUTH_SOCK "$HOME/.1password/agent.sock"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -n "$tmux_sock"; and test -S "$tmux_sock"
|
||||||
|
set -gx SSH_AUTH_SOCK "$tmux_sock"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
__refresh_ssh_auth_sock
|
||||||
|
|
||||||
|
function __refresh_ssh_auth_sock_before_command --on-event fish_preexec
|
||||||
|
__refresh_ssh_auth_sock
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make Tide show context for orb/SSH sessions that set SSH_CONNECTION but not SSH_TTY
|
# Make Tide show context for orb/SSH sessions that set SSH_CONNECTION but not SSH_TTY
|
||||||
@ -192,5 +278,9 @@ source ~/.orbstack/shell/init2.fish 2>/dev/null || :
|
|||||||
set -gx GITHUB_PERSONAL_ACCESS_TOKEN (security find-generic-password -s codex-github-mcp-pat -w 2>/dev/null)
|
set -gx GITHUB_PERSONAL_ACCESS_TOKEN (security find-generic-password -s codex-github-mcp-pat -w 2>/dev/null)
|
||||||
|
|
||||||
|
|
||||||
# Added by Antigravity CLI installer
|
# >>> grok installer >>>
|
||||||
set -gx PATH "/Users/anton/.local/bin" $PATH
|
fish_add_path $HOME/.grok/bin
|
||||||
|
# <<< grok installer <<<
|
||||||
|
|
||||||
|
# mimocode
|
||||||
|
fish_add_path /Users/anton/.mimocode/bin
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user