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.
This commit is contained in:
Aaron Gyes 2016-06-26 19:49:57 -07:00
parent a47b4b0e95
commit 534c1287ca
4 changed files with 34 additions and 21 deletions

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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