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 81dee16d69
4 changed files with 31 additions and 18 deletions

View file

@ -21,9 +21,15 @@ if status --is-interactive
# Existance of string is a good pre-2.3.0 check. Could also check $FISH_VERSION in the future. # 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. # This is a "launch", not an issue caused by autoloading during upgrades.
if not contains "string" (builtin -n) 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 set -g __is_launched_without_string 1
# XXX nostring - fix old fish binaries with no string builtin.
# With fish 2.2.0, these newer scritps are going to later force on 24-bit color due
# to changes to in behavior with conditionals. Let's show a public serivec announcement
# before skipping the 24bit opportunity. The user has seemingly explicitly launched an old
# fish with too-new scripts installed.
# Remove this when it's safe to upgrade fish and we've solved fish-script conflicts.
set_color --bold set_color --bold
echo "You appear to be trying to launch an old fish binary with newer scripts " echo "You appear to be trying to launch an old fish binary with newer scripts "
echo "installed into" (set_color --underline)"$__fish_datadir" echo "installed into" (set_color --underline)"$__fish_datadir"

View file

@ -167,7 +167,6 @@ function __fish_config_interactive -d "Initializations that should be performed
commandline -f repaint commandline -f repaint
end end
# Notify vte-based terminals when $PWD changes (issue #906) # Notify vte-based terminals when $PWD changes (issue #906)
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" 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' 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" function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
set -q argv[1]; and switch $argv[1] set -q argv[1]
case -h --help and switch $argv[1]
__fish_print_help prompt_pwd case -h --help
return 0 __fish_print_help prompt_pwd
end 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 # 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 set -q fish_prompt_pwd_dir_length
or set -l fish_prompt_pwd_dir_length 1
# Replace $HOME with "~" # Replace $HOME with "~"
set realhome ~ set realhome ~
set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD)
if [ $fish_prompt_pwd_dir_length -eq 0 ] if [ $fish_prompt_pwd_dir_length -eq 0 ]
echo $tmp echo $tmp
else else
# Shorten to at most $fish_prompt_pwd_dir_length characters per directory # Shorten to at most $fish_prompt_pwd_dir_length characters per directory
string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp
end end
end end

View file

@ -1,4 +1,5 @@
if not contains string (builtin -n) if not contains string (builtin -n)
# XXX nostring
function string function string
if not set -q __is_launched_without_string if not set -q __is_launched_without_string
if status --is-interactive if status --is-interactive