Created
June 27, 2017 20:31
-
-
Save bjhomer/695c5ca1256394424ff71cdee4e42ba5 to your computer and use it in GitHub Desktop.
My fish prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/functions/fish_prompt.fish | |
function fish_prompt --description 'Write out the prompt' | |
# Just calculate these once, to save a few cycles when displaying the prompt | |
if not set -q __fish_prompt_normal | |
set -g __fish_prompt_normal (set_color normal) | |
end | |
set -l delim '$' | |
switch $USER | |
case root | |
if not set -q __fish_prompt_cwd | |
if set -q fish_color_cwd_root | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd_root) | |
else | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd) | |
end | |
end | |
case '*' | |
if not set -q __fish_prompt_cwd | |
set -g __fish_prompt_cwd (set_color $fish_color_cwd) | |
end | |
end | |
set -g __fish_git_prompt_showdirtystate 1 | |
set -g __fish_git_prompt_color purple | |
echo -n -s "$__fish_prompt_cwd" (prompt_pwd) (__fish_git_prompt) "$__fish_prompt_normal" ' ' "$delim" ' ' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/functions/prompt_pwd.fish | |
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt" | |
echo $PWD | sed -e "s|^$HOME|~|" | awk -F/ '{ | |
str = $NF | |
currfield = NF - 1 | |
maxlen = 60 # Well, possibly plus a few for "~/..." | |
while (currfield > 0 \ | |
&& length(str) + length($currfield) + 1 < maxlen \ | |
&& length($currfield) > 0 ) { | |
str = $currfield "/" str | |
currfield = currfield-1 | |
} | |
if ( currfield > 1 ) { | |
str = ".../" str; | |
} | |
if ( currfield > 0 ) { | |
str= $1 "/" str | |
} | |
print str | |
}' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment