diff --git a/doc_src/cmds/prompt_login.rst b/doc_src/cmds/prompt_login.rst new file mode 100644 index 000000000..29e0d699b --- /dev/null +++ b/doc_src/cmds/prompt_login.rst @@ -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 diff --git a/share/functions/fish_prompt.fish b/share/functions/fish_prompt.fish index e670991d2..20fe6cc50 100644 --- a/share/functions/fish_prompt.fish +++ b/share/functions/fish_prompt.fish @@ -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 diff --git a/share/functions/prompt_login.fish b/share/functions/prompt_login.fish new file mode 100644 index 000000000..0aaa4544b --- /dev/null +++ b/share/functions/prompt_login.fish @@ -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 diff --git a/share/tools/web_config/sample_prompts/default.fish b/share/tools/web_config/sample_prompts/default.fish index e670991d2..20fe6cc50 100644 --- a/share/tools/web_config/sample_prompts/default.fish +++ b/share/tools/web_config/sample_prompts/default.fish @@ -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 diff --git a/share/tools/web_config/sample_prompts/terlar.fish b/share/tools/web_config/sample_prompts/terlar.fish index 5423403f3..ff11260d9 100644 --- a/share/tools/web_config/sample_prompts/terlar.fish +++ b/share/tools/web_config/sample_prompts/terlar.fish @@ -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 ':'