Add support for full paths in prompt

(and support for abbreviated project-relative paths!)

Use `fish_prompt_pwd_dir_length` and `theme_project_dir_length` to control the number of characters shown from each parent directory name.

Fixes #68
pull/72/head
Justin Hileman 7 years ago
parent d82bd5e214
commit 48f067bac0

@ -89,6 +89,8 @@ set -g theme_nerd_fonts yes
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_project_dir_length 1
```
**Title options**
@ -103,6 +105,8 @@ set -g theme_color_scheme dark
- `theme_display_vagrant`. This feature is disabled by default, use `yes` to display Vagrant status in your prompt. Please note that only the VirtualBox and VMWare providers are supported.
- `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.
- `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.
**Color scheme options**

@ -34,6 +34,8 @@
# 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_project_dir_length 1
# ===========================
# Helper methods
@ -69,7 +71,24 @@ 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'
echo -n (dirname $current_dir) | sed -e 's#/private##' -e "s#^$HOME#~#" -e 's#/\(\.\{0,1\}[^/]\)\([^/]*\)#/\1#g' -e 's#/$##'
set -q fish_prompt_pwd_dir_length
or set -l fish_prompt_pwd_dir_length 1
# Replace $HOME with ~
set -l real_home ~
set -l parent_dir (string replace -r '^'"$real_home"'($|/)' '~$1' (dirname $current_dir))
if [ $parent_dir = "/" ]
echo -n /
return
end
if [ $fish_prompt_pwd_dir_length -eq 0 ]
echo -n "$parent_dir/"
return
end
string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' "$parent_dir/"
end
function __bobthefish_git_project_dir -S -d 'Print the current git project base directory'
@ -129,7 +148,17 @@ function __bobthefish_hg_project_dir -S -d 'Print the current hg project base di
end
function __bobthefish_project_pwd -S -a current_dir -d 'Print the working directory relative to project root'
echo "$PWD" | sed -e "s#$current_dir##g" -e 's#^/##'
set -q theme_project_dir_length
or set -l theme_project_dir_length 0
set -l project_dir (string replace -r '^'"$current_dir"'($|/)' '' $PWD)
if [ $theme_project_dir_length -eq 0 ]
echo -n $project_dir
return
end
string replace -ar '(\.?[^/]{'"$theme_project_dir_length"'})[^/]*/' '$1/' $project_dir
end
function __bobthefish_git_ahead -S -d 'Print the ahead/behind state for the current branch'
@ -213,7 +242,6 @@ function __bobthefish_path_segment -S -a current_dir -d 'Display a shortened for
set directory '~'
case '*'
set parent (__bobthefish_pretty_parent "$current_dir")
set parent "$parent/"
set directory (basename "$current_dir")
end

Loading…
Cancel
Save