From fa3797e7c60d5b5857f486a95e2ef9556b5c7d72 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sat, 15 Feb 2020 22:44:12 +0000 Subject: [PATCH] Update fish config for 3.1.0 --- config/fish/fish_variables | 6 +- config/fish/functions/cd.fish | 97 +++++++++++--------- config/fish/functions/fgrep.fish | 2 +- config/fish/functions/fish_prompt.fish | 2 +- config/fish/functions/fish_right_prompt.fish | 2 +- config/fish/functions/grep.fish | 2 +- config/fish/functions/ls.fish | 2 +- config/fish/functions/make.fish | 2 +- config/fish/functions/pw.fish | 4 +- 9 files changed, 69 insertions(+), 50 deletions(-) diff --git a/config/fish/fish_variables b/config/fish/fish_variables index f0b45e0..dc64412 100644 --- a/config/fish/fish_variables +++ b/config/fish/fish_variables @@ -6,6 +6,7 @@ SETUVAR --export MAKEFLAGS:\x2dj\x2016 SETUVAR __fish_init_2_39_8:\x1d SETUVAR __fish_init_2_3_0:\x1d SETUVAR __fish_init_3_x:\x1d +SETUVAR __fish_initialized:3100 SETUVAR _fish_abbr_gpg:gpg2 SETUVAR _fish_abbr_vi:vim SETUVAR fish_color_autosuggestion:303030 @@ -13,12 +14,14 @@ SETUVAR fish_color_cancel:normal SETUVAR fish_color_command:205cb3 SETUVAR fish_color_comment:6600cc SETUVAR fish_color_cwd:209060 +SETUVAR fish_color_cwd_root:red SETUVAR fish_color_end:730099 SETUVAR fish_color_error:ff0000 SETUVAR fish_color_escape:00a6b2 SETUVAR fish_color_history_current:normal SETUVAR fish_color_host:176945 -SETUVAR fish_color_jobs:ffff00 +SETUVAR fish_color_host_remote:yellow +SETUVAR fish_color_jobs:yellow SETUVAR fish_color_match:normal SETUVAR fish_color_normal:normal SETUVAR fish_color_operator:cc6fdf @@ -27,6 +30,7 @@ SETUVAR fish_color_quote:ff751a SETUVAR fish_color_redirection:bf4080 SETUVAR fish_color_search_match:ffff00 SETUVAR fish_color_selection:c0c0c0 +SETUVAR fish_color_status:red SETUVAR fish_color_suffix:29bc7d SETUVAR fish_color_user:00ff00 SETUVAR fish_color_valid_path:normal diff --git a/config/fish/functions/cd.fish b/config/fish/functions/cd.fish index 532aaf4..72b852e 100644 --- a/config/fish/functions/cd.fish +++ b/config/fish/functions/cd.fish @@ -1,51 +1,66 @@ -function cd --description 'Change directory' - set -l MAX_DIR_HIST 25 +# +# Wrap the builtin cd command to maintain directory history. +# +function cd --description "Change directory" + set -l MAX_DIR_HIST 25 - if test (count $argv) -gt 1 - printf "%s\n" (_ "Too many args for cd command") - return 1 - end + if test (count $argv) -gt (test "$argv[1]" = "--" && echo 2 || echo 1) + printf "%s\n" (_ "Too many args for cd command") + return 1 + end - # Skip history in subshells. - if status --is-command-substitution - builtin cd $argv - return $status - end + # Skip history in subshells. + if status --is-command-substitution + builtin cd $argv + return $status + end - # Avoid set completions. - set -l previous $PWD + # Avoid set completions. + set -l previous $PWD - if test "$argv" = "-" - if test "$__fish_cd_direction" = "next" - nextd - else - prevd - end - return $status - end + if test "$argv" = "-" + if test "$__fish_cd_direction" = "next" + nextd + else + prevd + end + return $status + end - # allow explicit "cd ." if the mount-point became stale in the meantime - if test "$argv" = "." - cd "$PWD" - return $status - end + # allow explicit "cd ." if the mount-point became stale in the meantime + if test "$argv" = "." + cd "$PWD" + return $status + end - builtin cd $argv - set -l cd_status $status + builtin cd $argv + set -l cd_status $status - if test $cd_status -eq 0 -a "$PWD" != "$previous" - set -q dirprev - or set -l dirprev - set -q dirprev[$MAX_DIR_HIST] - and set -e dirprev[1] - set -g -a dirprev $previous - set -e dirnext - set -g __fish_cd_direction prev - end + if test $cd_status -eq 0 -a "$PWD" != "$previous" + set -q dirprev + or set -l dirprev + set -q dirprev[$MAX_DIR_HIST] + and set -e dirprev[1] - if test $cd_status -eq 0 - ls - end + # If dirprev, dirnext, __fish_cd_direction + # are set as universal variables, honor their scope. - return $cd_status + set -U -q dirprev + and set -U -a dirprev $previous + or set -g -a dirprev $previous + + set -U -q dirnext + and set -U -e dirnext + or set -e dirnext + + set -U -q __fish_cd_direction + and set -U __fish_cd_direction prev + or set -g __fish_cd_direction prev + end + + if test $cd_status -eq 0 + ls + end + + return $cd_status end diff --git a/config/fish/functions/fgrep.fish b/config/fish/functions/fgrep.fish index 79758d1..33fd710 100644 --- a/config/fish/functions/fgrep.fish +++ b/config/fish/functions/fgrep.fish @@ -1,5 +1,5 @@ function fgrep - if which ggrep >/dev/null ^&1 + if type -q ggrep command ggrep -F --color=auto $argv else command fgrep --color=auto $argv diff --git a/config/fish/functions/fish_prompt.fish b/config/fish/functions/fish_prompt.fish index adb9c54..980ad12 100644 --- a/config/fish/functions/fish_prompt.fish +++ b/config/fish/functions/fish_prompt.fish @@ -2,7 +2,7 @@ function fish_prompt --description 'Write out the prompt' set -l suffix switch "$USER" case root toor - set suffix (set_color ff0000)'#' + set suffix (set_color $fish_color_cwd_root)'#' case '*' set suffix '>' end diff --git a/config/fish/functions/fish_right_prompt.fish b/config/fish/functions/fish_right_prompt.fish index 7c22f5e..5480f89 100644 --- a/config/fish/functions/fish_right_prompt.fish +++ b/config/fish/functions/fish_right_prompt.fish @@ -7,7 +7,7 @@ function fish_right_prompt and set -a prompt (set_color $fish_color_jobs)$jobs test $code -gt 0 - and set -a prompt (set_color $fish_color_error)$code + and set -a prompt (set_color $fish_color_status)$code echo $prompt diff --git a/config/fish/functions/grep.fish b/config/fish/functions/grep.fish index 6ddf50a..8682a49 100644 --- a/config/fish/functions/grep.fish +++ b/config/fish/functions/grep.fish @@ -1,5 +1,5 @@ function grep - if which ggrep >/dev/null ^&1 + if type -q ggrep command ggrep --color=auto $argv else command grep --color=auto $argv diff --git a/config/fish/functions/ls.fish b/config/fish/functions/ls.fish index b894cdb..9dd2a36 100644 --- a/config/fish/functions/ls.fish +++ b/config/fish/functions/ls.fish @@ -1,5 +1,5 @@ function ls --description 'List contents of directory' - if which gls >/dev/null ^&1 + if type -q gls command gls --color=auto $argv else command ls --color=auto $argv diff --git a/config/fish/functions/make.fish b/config/fish/functions/make.fish index 6902a6b..e994ff2 100644 --- a/config/fish/functions/make.fish +++ b/config/fish/functions/make.fish @@ -4,7 +4,7 @@ function make # pkgsrc does not like MAKEFLAGS including -j set -lx MAKEFLAGS - if which bmake >/dev/null ^&1 && \ + if type -q bmake command bmake $argv else command make $argv diff --git a/config/fish/functions/pw.fish b/config/fish/functions/pw.fish index 2e4f545..91e2eb0 100644 --- a/config/fish/functions/pw.fish +++ b/config/fish/functions/pw.fish @@ -1,8 +1,8 @@ function pw set -l clipboard - if which pbcopy >/dev/null ^&1 + if type -q pbcopy set clipboard pbcopy - else if which xclip >/dev/null ^&1 + else if type -q xclip set clipboard xclip else echo "No clipboard handler found!"