From 534c1287ca9e0376971c770dd82fa8957b1e8e00 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sun, 26 Jun 2016 19:49:57 -0700 Subject: [PATCH] Add back prompt_pwd to solve empty output problem ..by not manipulating path at all if we do not have the tools to do so. Tag changes with better comments. --- share/config.fish | 14 +++++-- .../functions/__fish_config_interactive.fish | 1 - share/functions/prompt_pwd.fish | 39 +++++++++++-------- share/functions/string.fish | 1 + 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/share/config.fish b/share/config.fish index 432fa6eb0..dae242244 100644 --- a/share/config.fish +++ b/share/config.fish @@ -18,12 +18,18 @@ function __fish_default_command_not_found_handler end if status --is-interactive - # Existance of string is a good pre-2.3.0 check. Could also check $FISH_VERSION in the future. - # This is a "launch", not an issue caused by autoloading during upgrades. + # The user has seemingly explicitly launched an old fish with + # too-new scripts installed. a if not contains "string" (builtin -n) - # the string.fish message to `exec` will probably not help here, so this will that. set -g __is_launched_without_string 1 + # XXX nostring - fix old fish binaries with no `string' builtin. + # When executed on fish 2.2.0, the `else' block after this would + # force on 24-bit mode due to changes to in test behavior + # Let's show a public serivec announcement. + + # Remove this code when it's safe to upgrade fish and we've solved fish-script conflicts. + set_color --bold echo "You appear to be trying to launch an old fish binary with newer scripts " echo "installed into" (set_color --underline)"$__fish_datadir" @@ -205,7 +211,7 @@ for file in $configdir/fish/conf.d/*.fish $__fish_sysconfdir/conf.d/*.fish $__ex end # Upgrade pre-existing abbreviations from the old "key=value" to the new "key value" syntax -# This needs to be in share/config.fish because __fish_config_interactive is called after sourcing config.fish, which might contain abbr calls +# This needs to be in share/config.fish because __fish_config_interactive is called after 2sourcing config.fish, which might contain abbr calls if not set -q __fish_init_2_3_0 set -l fab for abb in $fish_user_abbreviations diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index f8b08de62..b95d1f0c0 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -167,7 +167,6 @@ function __fish_config_interactive -d "Initializations that should be performed commandline -f repaint end - # Notify vte-based terminals when $PWD changes (issue #906) if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD' diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish index 96e9b2f33..4464d75d0 100644 --- a/share/functions/prompt_pwd.fish +++ b/share/functions/prompt_pwd.fish @@ -1,21 +1,28 @@ function prompt_pwd --description "Print the current working directory, shortened to fit the prompt" - set -q argv[1]; and switch $argv[1] - case -h --help - __fish_print_help prompt_pwd - return 0 - end + set -q argv[1] + and switch $argv[1] + case -h --help + __fish_print_help prompt_pwd + return 0 + end + if set -q $__is_launched_without_string + # There is no `string' builtin - do something sensible. XXX nostring + echo $PWD + return 0 + end - # This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it - set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1 + # This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it + set -q fish_prompt_pwd_dir_length + or set -l fish_prompt_pwd_dir_length 1 - # Replace $HOME with "~" - set realhome ~ - set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) + # Replace $HOME with "~" + set realhome ~ + set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) - if [ $fish_prompt_pwd_dir_length -eq 0 ] - echo $tmp - else - # Shorten to at most $fish_prompt_pwd_dir_length characters per directory - string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp - end + if [ $fish_prompt_pwd_dir_length -eq 0 ] + echo $tmp + else + # Shorten to at most $fish_prompt_pwd_dir_length characters per directory + string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp + end end diff --git a/share/functions/string.fish b/share/functions/string.fish index ec5cb2612..c86ec4ce8 100644 --- a/share/functions/string.fish +++ b/share/functions/string.fish @@ -1,4 +1,5 @@ if not contains string (builtin -n) + # XXX nostring function string if not set -q __is_launched_without_string if status --is-interactive