mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
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:
parent
a47b4b0e95
commit
81dee16d69
4 changed files with 31 additions and 18 deletions
|
@ -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.
|
||||
# This is a "launch", not an issue caused by autoloading during upgrades.
|
||||
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.
|
||||
# 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
|
||||
echo "You appear to be trying to launch an old fish binary with newer scripts "
|
||||
echo "installed into" (set_color --underline)"$__fish_datadir"
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue