function __zmx_choose_session --description "Choose or create a zmx session name with fzf" argparse 'p/preview=' -- $argv or return 1 if not type -q fzf echo "__zmx_choose_session: fzf is not installed or not on PATH" >&2 return 127 end set -l preview_command 'zmx history {1}' if set -q _flag_preview set preview_command $_flag_preview end set -l display read -lz display set -l output_file (mktemp) begin if test -n "$display" printf "%s" $display end end | fzf \ --print-query \ --expect=ctrl-n \ --height=80% \ --reverse \ --prompt="zmx> " \ --header="Enter: select | Ctrl-N: create new" \ --preview=$preview_command \ --preview-window=right:60%:follow \ >$output_file set -l fzf_status $status set -l query (sed -n '1p' $output_file) set -l key (sed -n '2p' $output_file) set -l selected (sed -n '3p' $output_file) rm -f $output_file if test "$key" = ctrl-n; and test -n "$query" echo $query else if test $fzf_status -eq 0; and test -n "$selected" string split -f1 ' ' -- $selected else if test -n "$query" echo $query else return 130 end end