From 89a70cd91c152f1d02faf6ee7bb923ab2a632c8a Mon Sep 17 00:00:00 2001 From: Jo De Boeck Date: Thu, 15 Feb 2018 16:13:04 +0200 Subject: [PATCH 1/2] Make it possible to show basename in prompt Signed-off-by: Jo De Boeck --- README.md | 2 +- fish_prompt.fish | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b366153..e891ed23 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ set -g theme_newline_cursor yes - `theme_display_k8s_context`. By default the current kubernetes context is shown (`> kubectl config current-context`). Use `no` to hide the context. - `theme_show_exit_status`. Set this option to yes to have the prompt show the last exit code if it was non_zero instead of just the exclamation mark. - `theme_git_worktree_support`. If you do any git worktree shenanigans, setting this to `yes` will fix incorrect project-relative path display. If you don't do any git worktree shenanigans, leave it disabled. It's faster this way :) -- `fish_prompt_pwd_dir_length`. bobthefish respects the Fish `$fish_prompt_pwd_dir_length` setting to abbreviate the prompt path. Set to `0` to show the full path, `1` (default) to show only the first character of each parent directory name, or any other number to show up to that many characters. +- `fish_prompt_pwd_dir_length`. bobthefish respects the Fish `$fish_prompt_pwd_dir_length` setting to abbreviate the prompt path. Set to `-1` to show basename, `0` to show the full path, `1` (default) to show only the first character of each parent directory name, or any other number to show up to that many characters. - `theme_project_dir_length`. The same as `$fish_prompt_pwd_dir_length`, but for the path relative to the current project root. Defaults to `0`; set to any other number to show an abbreviated path. - `theme_newline_cursor`. Use `yes` to have cursor start on a new line. By default the prompt is only one line. When working with long directories it may be preferrend to have cursor on the next line. Setting this to `clean` instead of `yes` suppresses the caret on the new line. diff --git a/fish_prompt.fish b/fish_prompt.fish index 98301f34..2965225e 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -90,8 +90,10 @@ function __bobthefish_pretty_parent -S -a current_dir -d 'Print a parent directo if [ $fish_prompt_pwd_dir_length -eq 0 ] echo -n "$parent_dir/" return + else if [ $fish_prompt_pwd_dir_length -eq -1 ] + echo -n (__bobthefish_basename "$parent_dir/") + return end - string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' "$parent_dir/" end From 30d349444906f66024b63a27f8249c667380935d Mon Sep 17 00:00:00 2001 From: Jo De Boeck Date: Tue, 20 Feb 2018 22:53:31 +0200 Subject: [PATCH 2/2] Update to use theme specific variable Signed-off-by: Jo De Boeck --- README.md | 4 +++- fish_prompt.fish | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e891ed23..9b370096 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ set -g theme_show_exit_status yes set -g default_user your_normal_user set -g theme_color_scheme dark set -g fish_prompt_pwd_dir_length 0 +set -g theme_prompt_pwd_dir_length 0 set -g theme_project_dir_length 1 set -g theme_newline_cursor yes ``` @@ -114,7 +115,8 @@ set -g theme_newline_cursor yes - `theme_display_k8s_context`. By default the current kubernetes context is shown (`> kubectl config current-context`). Use `no` to hide the context. - `theme_show_exit_status`. Set this option to yes to have the prompt show the last exit code if it was non_zero instead of just the exclamation mark. - `theme_git_worktree_support`. If you do any git worktree shenanigans, setting this to `yes` will fix incorrect project-relative path display. If you don't do any git worktree shenanigans, leave it disabled. It's faster this way :) -- `fish_prompt_pwd_dir_length`. bobthefish respects the Fish `$fish_prompt_pwd_dir_length` setting to abbreviate the prompt path. Set to `-1` to show basename, `0` to show the full path, `1` (default) to show only the first character of each parent directory name, or any other number to show up to that many characters. +- `fish_prompt_pwd_dir_length`. bobthefish respects the Fish `$fish_prompt_pwd_dir_length` setting to abbreviate the prompt path. Set to `0` to show the full path, `1` (default) to show only the first character of each parent directory name, or any other number to show up to that many characters. +- `theme_prompt_pwd_dir_length`. Overwrites the fish_prompt_pwd_dir_length variable supports one extra setting `-1` which uses the basename of the pwd in the prompt - `theme_project_dir_length`. The same as `$fish_prompt_pwd_dir_length`, but for the path relative to the current project root. Defaults to `0`; set to any other number to show an abbreviated path. - `theme_newline_cursor`. Use `yes` to have cursor start on a new line. By default the prompt is only one line. When working with long directories it may be preferrend to have cursor on the next line. Setting this to `clean` instead of `yes` suppresses the caret on the new line. diff --git a/fish_prompt.fish b/fish_prompt.fish index 2965225e..0b6e20a7 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -38,6 +38,7 @@ # set -g default_user your_normal_user # set -g theme_color_scheme dark # set -g fish_prompt_pwd_dir_length 0 +# set -g theme_prompt_pwd_dir_length -1 # set -g theme_project_dir_length 1 # set -g theme_newline_cursor yes @@ -74,8 +75,13 @@ function __bobthefish_hg_branch -S -d 'Get the current hg branch' end function __bobthefish_pretty_parent -S -a current_dir -d 'Print a parent directory, shortened to fit the prompt' - set -q fish_prompt_pwd_dir_length - or set -l fish_prompt_pwd_dir_length 1 + if not set -q theme_prompt_pwd_dir_length + if set -q fish_prompt_pwd_dir_length + set theme_prompt_pwd_dir_length "$fish_prompt_pwd_dir_length" + else + set theme_prompt_pwd_dir_length 1 + end + end # Replace $HOME with ~ set -l real_home ~ @@ -87,14 +93,14 @@ function __bobthefish_pretty_parent -S -a current_dir -d 'Print a parent directo return end - if [ $fish_prompt_pwd_dir_length -eq 0 ] + if [ $theme_prompt_pwd_dir_length -eq 0 ] echo -n "$parent_dir/" return - else if [ $fish_prompt_pwd_dir_length -eq -1 ] + else if [ $theme_prompt_pwd_dir_length -eq -1 ] echo -n (__bobthefish_basename "$parent_dir/") return end - string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' "$parent_dir/" + string replace -ar '(\.?[^/]{'"$theme_prompt_pwd_dir_length"'})[^/]*/' '$1/' "$parent_dir/" end function __bobthefish_ignore_vcs_dir -d 'Check whether the current directory should be ignored as a VCS segment'