fish: include term-specific config file, if available
3 files changed, 60 insertions(+), 0 deletions(-)
M user/settings/fish.nix → user/settings/fish.nix
@@ -56,6 +56,10 @@ xdg.configFile."fish/functions" = { recursive = true; source = direct_symlink "/user/settings/fish/functions"; }; + xdg.configFile."fish/per-term" = { + recursive = true; + source = direct_symlink "/user/settings/fish/per-term"; + }; xdg.configFile."fish/conf.d/user_config.fish" = { source = direct_symlink "/user/settings/fish/config.fish"; };
M user/settings/fish/config.fish → user/settings/fish/config.fish
@@ -4,3 +4,8 @@ for mode in default insert bind --mode $mode tab complete bind --mode $mode shift-tab _fifc end + +set --local fish_term_config $__fish_config_dir/per-term/$TERM_PROGRAM.fish +if set --query TERM_PROGRAM && path is $fish_term_config + source $fish_term_config +end
A user/settings/fish/per-term/Apple_Terminal.fish
@@ -0,0 +1,51 @@ +set window_and_tab 0 +set tab 1 +set window 2 +set document 6 +set wd 7 + +function update_terminal_path --argument-names ps pt + if set --query SSH_TTY + printf '\e]%d;file://%s@%s%s\a' $ps $USER (prompt_hostname) \ + (string escape --style=url $pt) + else + printf '\e]%d;file://%s\a' $ps (string escape --style=url $pt) + end +end + +function update_terminal_title --argument-names ps pt + printf '\e]%d;%s\a' $ps $pt +end + +function reset_title_document --on-event fish_postexec + # not _path because we don't want a file:// URL + update_terminal_title $document "" +end + +function reset_title_post_ssh --on-event fish_postexec --argument-names cmdline + if string match "ssh *" "$cmdline" + reset_title_document + update_terminal_path $wd "$PWD" + update_terminal_title $window_and_tab "" + end +end + +function clear_title --on-event fish_exit + update_terminal_title $window_and_tab "" +end + +function set_document_title --on-event fish_preexec --argument-names cmdline + set --local args (string split ' ' "$cmdline") + switch "$args[1]" + case e editor vi vim nvim + # move options to $argv_opts + argparse --move-unknown -- $args[2..] + + # check if any arg is a file or directory + for p in (path filter $argv) + # set Terminal path to full path of arg + update_terminal_path $document (path resolve $p) + return + end + end +end