diff options
author | Martin Polden <mpolden@mpolden.no> | 2024-01-16 14:12:18 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2024-01-16 14:13:10 +0100 |
commit | 5238229aad25a7ef2d28e15d2c7d98e8a8da29ab (patch) | |
tree | 1ff81f93558f8c894ce2ba8ce93febbe91b41063 | |
parent | 89eb021e70b296a04f016605179abc9eab0ea12f (diff) |
fish: in-line prompt config
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | config.fish | 33 | ||||
-rw-r--r-- | fish_prompt.fish | 32 |
3 files changed, 33 insertions, 34 deletions
@@ -63,9 +63,7 @@ else endif fish: - mkdir -p ~/.config/fish/functions ln $(LN_FLAGS) $(CURDIR)/config.fish ~/.config/fish/config.fish - ln $(LN_FLAGS) $(CURDIR)/fish_prompt.fish ~/.config/fish/functions/fish_prompt.fish # Maintenance diff --git a/config.fish b/config.fish index 474f6fc..cfe1bec 100644 --- a/config.fish +++ b/config.fish @@ -343,6 +343,39 @@ set -g fish_prompt_pwd_dir_length 0 # Make autosuggestion text slightly brighter set -g fish_color_autosuggestion 8a8a8a +function fish_prompt --description "Write out the prompt" + set last_status $status + if not set -q __fish_prompt_hostname + set -g __fish_prompt_hostname (hostname -s) + end + + set normal (set_color normal) + set -q fish_color_at + or set -U fish_color_at $normal + + # Add user@host when connected through SSH or using toolbox + set ssh_prefix + if set -q SSH_CLIENT + or set -q SSH_TTY + or set -q SSH_CONNECTION + or set -q TOOLBOX_PATH + set ssh_prefix (set_color $fish_color_user) $USER \ + (set_color $fish_color_at) @ (set_color $fish_color_host) \ + $__fish_prompt_hostname $normal ":" + end + + # Color prompt symbol based on exit status. Inspired by + # https://solovyov.net/blog/2020/useful-shell-prompt/ + set prompt_symbol '$' + if [ $last_status -ne 0 ] + set prompt_symbol "$(set_color yellow)\$$normal" + end + + # Print prompt + echo -n -s $ssh_prefix (set_color $fish_color_cwd) (prompt_pwd) \ + $normal (__fish_git_prompt " %s") $normal $prompt_symbol " " +end + # Print message if reboot is required if [ -n "$TERM" -a -f /var/run/reboot-required ] echo "reboot required" diff --git a/fish_prompt.fish b/fish_prompt.fish deleted file mode 100644 index ffe0f72..0000000 --- a/fish_prompt.fish +++ /dev/null @@ -1,32 +0,0 @@ -function fish_prompt --description "Write out the prompt" - set last_status $status - if not set -q __fish_prompt_hostname - set -g __fish_prompt_hostname (hostname -s) - end - - set normal (set_color normal) - set -q fish_color_at - or set -U fish_color_at $normal - - # Add user@host when connected through SSH or using toolbox - set ssh_prefix - if set -q SSH_CLIENT - or set -q SSH_TTY - or set -q SSH_CONNECTION - or set -q TOOLBOX_PATH - set ssh_prefix (set_color $fish_color_user) $USER \ - (set_color $fish_color_at) @ (set_color $fish_color_host) \ - $__fish_prompt_hostname $normal ":" - end - - # Color prompt symbol based on exit status. Inspired by - # https://solovyov.net/blog/2020/useful-shell-prompt/ - set prompt_symbol '$' - if [ $last_status -ne 0 ] - set prompt_symbol "$(set_color yellow)\$$normal" - end - - # Print prompt - echo -n -s $ssh_prefix (set_color $fish_color_cwd) (prompt_pwd) \ - $normal (__fish_git_prompt " %s") $normal $prompt_symbol " " -end |