mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
implement a fish_prompt_hostname function
Standardize how the host name is included in the prompts that do so. Fixes #3480
This commit is contained in:
parent
668de88e69
commit
07de13f61f
14 changed files with 19 additions and 62 deletions
|
@ -3,11 +3,6 @@
|
|||
# Set the default prompt command.
|
||||
|
||||
function fish_fallback_prompt --description "A simple fallback prompt without too much color or special characters for linux VTs"
|
||||
# Just calculate this once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch $USER
|
||||
|
@ -23,5 +18,5 @@ function fish_fallback_prompt --description "A simple fallback prompt without to
|
|||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
end
|
||||
|
|
|
@ -3,11 +3,6 @@
|
|||
# Set the default prompt command.
|
||||
|
||||
function fish_prompt --description "Write out the prompt"
|
||||
# Just calculate this once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch $USER
|
||||
|
@ -23,5 +18,5 @@ function fish_prompt --description "Write out the prompt"
|
|||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
end
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
# name: Classic
|
||||
function fish_prompt --description "Write out the prompt"
|
||||
# Just calculate this once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch $USER
|
||||
|
@ -20,5 +15,5 @@ function fish_prompt --description "Write out the prompt"
|
|||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
end
|
||||
|
|
|
@ -10,11 +10,6 @@ function fish_prompt --description "Write out the prompt"
|
|||
printf "%s(%d)%s " (set_color red --bold) $last_status (set_color normal)
|
||||
end
|
||||
|
||||
# Just calculate this once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch $USER
|
||||
|
@ -30,5 +25,5 @@ function fish_prompt --description "Write out the prompt"
|
|||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
end
|
||||
|
|
|
@ -4,12 +4,6 @@
|
|||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_status $status
|
||||
|
||||
# Just calculate this once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
set -l normal (set_color normal)
|
||||
|
||||
# Hack; fish_config only copies the fish_prompt function (see #736)
|
||||
|
@ -21,13 +15,13 @@ function fish_prompt --description 'Write out the prompt'
|
|||
commandline -f repaint ^/dev/null
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function __fish_repaint_host --on-variable fish_color_host --description "Event handler, repaint when fish_color_host changes"
|
||||
if status --is-interactive
|
||||
commandline -f repaint ^/dev/null
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function __fish_repaint_status --on-variable fish_color_status --description "Event handler; repaint when fish_color_status changes"
|
||||
if status --is-interactive
|
||||
commandline -f repaint ^/dev/null
|
||||
|
@ -69,5 +63,5 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set prompt_status ' ' (set_color $fish_color_status) "[$last_status]" "$normal"
|
||||
end
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) "$__fish_prompt_hostname" $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (__fish_vcs_prompt) $normal $prompt_status "> "
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $fish_color_host) (fish_prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (__fish_vcs_prompt) $normal $prompt_status "> "
|
||||
end
|
||||
|
|
|
@ -2,12 +2,6 @@
|
|||
# author: Maurizio De Santis
|
||||
|
||||
function fish_prompt --description 'Write out the prompt, prepending the Debian chroot environment if present'
|
||||
|
||||
# Just calculate these once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
if not set -q __fish_prompt_normal
|
||||
set -g __fish_prompt_normal (set_color normal)
|
||||
end
|
||||
|
@ -41,7 +35,7 @@ function fish_prompt --description 'Write out the prompt, prepending the Debian
|
|||
end
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '# '
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '# '
|
||||
|
||||
case '*'
|
||||
|
||||
|
@ -49,7 +43,7 @@ function fish_prompt --description 'Write out the prompt, prepending the Debian
|
|||
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '> '
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '> '
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,11 +6,6 @@ function fish_prompt --description 'Write out the prompt'
|
|||
#Save the return status of the previous command
|
||||
set stat $status
|
||||
|
||||
# Just calculate these once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
|
||||
end
|
||||
|
||||
if not set -q __fish_prompt_normal
|
||||
set -g __fish_prompt_normal (set_color normal)
|
||||
end
|
||||
|
@ -37,7 +32,7 @@ if not set -q __fish_prompt_cwd
|
|||
end
|
||||
end
|
||||
|
||||
printf '%s@%s %s%s%s# ' $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal"
|
||||
printf '%s@%s %s%s%s# ' $USER (fish_prompt_hostname) "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal"
|
||||
|
||||
case '*'
|
||||
|
||||
|
@ -45,7 +40,7 @@ if not set -q __fish_prompt_cwd
|
|||
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
|
||||
end
|
||||
|
||||
printf '[%s] %s%s@%s %s%s %s(%s)%s \f\r> ' (date "+%H:%M:%S") "$__fish_color_blue" $USER $__fish_prompt_hostname "$__fish_prompt_cwd" "$PWD" "$__fish_color_status" "$stat" "$__fish_prompt_normal"
|
||||
printf '[%s] %s%s@%s %s%s %s(%s)%s \f\r> ' (date "+%H:%M:%S") "$__fish_color_blue" $USER (fish_prompt_hostname) "$__fish_prompt_cwd" "$PWD" "$__fish_color_status" "$stat" "$__fish_prompt_normal"
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
# author: Steve
|
||||
|
||||
function fish_prompt --description 'Write out the prompt'
|
||||
# Just calculate these once, to save a few cycles when displaying the prompt
|
||||
if not set -q __fish_prompt_hostname
|
||||
set -g __fish_prompt_hostname (hostname -s)
|
||||
end
|
||||
|
||||
if not set -q __fish_prompt_normal
|
||||
set -g __fish_prompt_normal (set_color normal)
|
||||
end
|
||||
|
@ -15,6 +10,5 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' "$__fish_prompt_cwd" (prompt_pwd) (__fish_vcs_prompt) "$__fish_prompt_normal" '> '
|
||||
|
||||
echo -n -s "$USER" @ (fish_prompt_hostname) ' ' "$__fish_prompt_cwd" (prompt_pwd) (__fish_vcs_prompt) "$__fish_prompt_normal" '> '
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ function fish_prompt
|
|||
else
|
||||
set_color -o cyan
|
||||
end
|
||||
echo -n (hostname)
|
||||
echo -n (fish_prompt_hostname)
|
||||
set_color -o white
|
||||
#echo -n :(prompt_pwd)
|
||||
echo -n :(pwd|sed "s=$HOME=~=")
|
||||
|
|
|
@ -12,7 +12,7 @@ function fish_prompt
|
|||
printf ' at '
|
||||
|
||||
set_color magenta
|
||||
printf '%s' (hostname|cut -d . -f 1)
|
||||
echo -n (fish_prompt_hostname)
|
||||
set_color normal
|
||||
printf ' in '
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
# author: Matthias
|
||||
function fish_prompt -d "Write out the prompt"
|
||||
if test -z $WINDOW
|
||||
printf '%s%s@%s%s%s%s%s> ' (set_color yellow) (whoami) (set_color purple) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
printf '%s%s@%s%s%s%s%s> ' (set_color yellow) (whoami) (set_color purple) (fish_prompt_hostname) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
else
|
||||
printf '%s%s@%s%s%s(%s)%s%s%s> ' (set_color yellow) (whoami) (set_color purple) (hostname|cut -d . -f 1) (set_color white) (echo $WINDOW) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
printf '%s%s@%s%s%s(%s)%s%s%s> ' (set_color yellow) (whoami) (set_color purple) (fish_prompt_hostname) (set_color white) (echo $WINDOW) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# author: Ivan Tham <ivanthamjunhoe@gmail.com>
|
||||
|
||||
function fish_prompt
|
||||
test $SSH_TTY; and printf (set_color red)(whoami)(set_color white)'@'(set_color yellow)(hostname)' '
|
||||
test $SSH_TTY; and printf (set_color red)(whoami)(set_color white)'@'(set_color yellow)(fish_prompt_hostname)' '
|
||||
|
||||
test $USER = 'root'; and echo (set_color red)"#"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ function fish_prompt --description 'Write out the prompt'
|
|||
|
||||
# Host
|
||||
set_color $fish_color_host
|
||||
echo -n (hostname -s)
|
||||
echo -n (fish_prompt_hostname)
|
||||
set_color normal
|
||||
|
||||
echo -n ':'
|
||||
|
|
|
@ -9,5 +9,5 @@ function fish_prompt -d "Write out the prompt"
|
|||
case root toor; set prompt_symbol '#'
|
||||
case '*'; set prompt_symbol '$'
|
||||
end
|
||||
printf "[%s@%s %s%s%s]%s " $USER (hostname -s) (set_color $fish_color_cwd) $pwd (set_color normal) $prompt_symbol
|
||||
printf "[%s@%s %s%s%s]%s " $USER (fish_prompt_hostname) (set_color $fish_color_cwd) $pwd (set_color normal) $prompt_symbol
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue