mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
Add a "prompt_login" helper function
This prints a description of the "host". Currently that's `(chroot:debianchroot) $USER@$hostname` with the chroot part when needed. This also switches the default and terlar prompts to use it, the other prompts have slightly different coloring or logic here.
This commit is contained in:
parent
f768389cf7
commit
2cea5b8eb1
26
doc_src/cmds/prompt_login.rst
Normal file
26
doc_src/cmds/prompt_login.rst
Normal file
|
@ -0,0 +1,26 @@
|
|||
.. _cmd-prompt_login:
|
||||
|
||||
prompt_login - describe the login suitable for prompt
|
||||
=====================================================
|
||||
|
||||
Synopsis
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
function fish_prompt
|
||||
echo -n (prompt_login) (prompt_pwd) '$ '
|
||||
end
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
``prompt_login`` is a function to describe the current login. It will show the user, the host and also whether the shell is running in a chroot (currently debian's debian_chroot is supported).
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
>_ prompt_login
|
||||
root@bananablaster
|
|
@ -16,12 +16,6 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set suffix '#'
|
||||
end
|
||||
|
||||
# If we're running via SSH, change the host color.
|
||||
set -l color_host $fish_color_host
|
||||
if set -q SSH_TTY
|
||||
set color_host $fish_color_host_remote
|
||||
end
|
||||
|
||||
# Write pipestatus
|
||||
# If the status was carried over (e.g. after `set`), don't bold it.
|
||||
set -l bold_flag --bold
|
||||
|
@ -34,5 +28,5 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set -l statusb_color (set_color $bold_flag $fish_color_status)
|
||||
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
echo -n -s (prompt_login)' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
end
|
||||
|
|
28
share/functions/prompt_login.fish
Normal file
28
share/functions/prompt_login.fish
Normal file
|
@ -0,0 +1,28 @@
|
|||
function prompt_login --description "Print a description of the user and host suitable for the prompt"
|
||||
if not set -q __fish_machine
|
||||
set -g __fish_machine
|
||||
set -l debian_chroot $debian_chroot
|
||||
|
||||
if test -r /etc/debian_chroot
|
||||
set debian_chroot (cat /etc/debian_chroot)
|
||||
end
|
||||
|
||||
if set -q debian_chroot[1]
|
||||
and test -n "$debian_chroot"
|
||||
set -g __fish_machine "(chroot:$debian_chroot)"
|
||||
end
|
||||
end
|
||||
|
||||
# Prepend the chroot environment if present
|
||||
if set -q __fish_machine[1]
|
||||
echo -n -s (set_color yellow) "$__fish_machine" (set_color normal) ' '
|
||||
end
|
||||
|
||||
# If we're running via SSH, change the host color.
|
||||
set -l color_host $fish_color_host
|
||||
if set -q SSH_TTY; and set -q fish_color_host_remote
|
||||
set color_host $fish_color_host_remote
|
||||
end
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" (set_color normal) @ (set_color $color_host) (prompt_hostname) (set_color normal)
|
||||
end
|
|
@ -16,12 +16,6 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set suffix '#'
|
||||
end
|
||||
|
||||
# If we're running via SSH, change the host color.
|
||||
set -l color_host $fish_color_host
|
||||
if set -q SSH_TTY
|
||||
set color_host $fish_color_host_remote
|
||||
end
|
||||
|
||||
# Write pipestatus
|
||||
# If the status was carried over (e.g. after `set`), don't bold it.
|
||||
set -l bold_flag --bold
|
||||
|
@ -34,5 +28,5 @@ function fish_prompt --description 'Write out the prompt'
|
|||
set -l statusb_color (set_color $bold_flag $fish_color_status)
|
||||
set -l prompt_status (__fish_print_pipestatus "[" "]" "|" "$status_color" "$statusb_color" $last_pipestatus)
|
||||
|
||||
echo -n -s (set_color $fish_color_user) "$USER" $normal @ (set_color $color_host) (prompt_hostname) $normal ' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
echo -n -s (prompt_login)' ' (set_color $color_cwd) (prompt_pwd) $normal (fish_vcs_prompt) $normal " "$prompt_status $suffix " "
|
||||
end
|
||||
|
|
|
@ -4,17 +4,7 @@
|
|||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_status $status
|
||||
|
||||
# User
|
||||
set_color $fish_color_user
|
||||
echo -n $USER
|
||||
set_color normal
|
||||
|
||||
echo -n '@'
|
||||
|
||||
# Host
|
||||
set_color $fish_color_host
|
||||
echo -n (prompt_hostname)
|
||||
set_color normal
|
||||
prompt_login
|
||||
|
||||
echo -n ':'
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user