@@ -92,6 +92,10 @@ fundle plugin 'patrickf1/fzf.fish'
fundle plugin 'franciscolourenco/done'
fundle init
+{{- if or (eq .chezmoi.hostname "angmar") (eq .chezmoi.hostname "sidhe") (eq .chezmoi.username "exedev") }}
+set ZMX_AUTO_SELECT true
+{{- end }}
+
if status is-interactive
if not functions -q fundle; eval (curl -sfL https://git.io/fundle-install); end
@@ -139,6 +143,10 @@ if status is-interactive
sb completion fish | source
enable_transience
+
+ if set -q ZMX_AUTO_SELECT; and not set -q ZMX_SESSION; and type -q zs
+ zs; and exit
+ end
end
if status is-login
@@ -37,8 +37,12 @@ function __zmx_choose_session --description "Choose or create a zmx session name
set -l selected (sed -n '3p' $output_file)
rm -f $output_file
- if test "$key" = ctrl-n; and test -n "$query"- echo $query
+ if test "$key" = ctrl-n
+ if test -n "$query"
+ echo $query
+ else
+ printf "%s" $display | awk '{print $1}' | friendly-name --exclude-stdin
+ end
else if test $fzf_status -eq 0; and test -n "$selected"
string split -f1 ' ' -- $selected
else if test -n "$query"
@@ -1,15 +1,16 @@
function __zmx_format_sessions --description "Format zmx list output for fzf"
while read -l line
+ set line (string trim -- $line)
set -l fields (string split \t -- $line)
if test (count $fields) -lt 5
continue
end
- set -l name (string replace -r '^session_name=' '' -- $fields[1])
+ set -l name (string replace -r '^(session_)?name=' '' -- $fields[1])
set -l pid (string replace -r '^pid=' '' -- $fields[2])
set -l clients (string replace -r '^clients=' '' -- $fields[3])
- set -l dir (string replace -r '^started_in=' '' -- $fields[5])
+ set -l dir (string replace -r '^(start_dir|started_in)=' '' -- $fields[5])
printf "%-20s pid:%-8s clients:%-2s %s\n" $name $pid $clients $dir
end
@@ -1,11 +0,0 @@
-function zmx-select --description "Fuzzy-find or create a zmx session"- if not type -q zmx- echo "zmx-select: zmx is not installed or not on PATH" >&2- return 127- end-- set -l session_name (zmx list 2>/dev/null | __zmx_format_sessions | __zmx_choose_session --preview 'zmx history {1}')- or return $status-- zmx attach $session_name-end
@@ -1,41 +0,0 @@
-function zssh-select --description "Fuzzy-find or create a zmx session on a remote host"- argparse 'h/help' 'install' -- $argv- or return 1-- if set -q _flag_help; or test (count $argv) -ne 1- echo "Usage: zssh-select [--install] [user@]host"- echo "Example: zssh-select hel1"- return 0- end-- set -l destination $argv[1]-- if not string match -qr '^[A-Za-z0-9._@:%+-]+$' -- $destination- echo "zssh-select: destination contains characters that cannot be safely used in the preview command" >&2- return 2- end-- mkdir -p "$HOME/.ssh/controlmasters"-- if set -q _flag_install- zmx-remote-install $destination- or return $status- else- zmx-remote-install --upgrade-only $destination- or return $status- end-- set -l remote_list (command ssh \- -o ControlMaster=auto \- -o ControlPersist=10m \- -o ControlPath="$HOME/.ssh/controlmasters/%C" \- $destination \- "sh -c 'PATH=\"\$HOME/.local/bin:\$PATH\"; command -v zmx >/dev/null 2>&1 || { echo \"zssh-select: zmx is not installed on the remote host or is not on PATH; retry with zssh-select --install\" >&2; exit 127; }; zmx list 2>/dev/null'")- or return $status-- set -l preview_command "ssh -o ControlMaster=auto -o ControlPersist=10m -o ControlPath=$HOME/.ssh/controlmasters/%C $destination 'sh -c '\''PATH=\"\$HOME/.local/bin:\$PATH\"; zmx history {1}'\'' '"- set -l session_name (printf '%s\n' $remote_list | __zmx_format_sessions | __zmx_choose_session --preview $preview_command)- or return $status-- zssh $destination $session_name-end