Skip to content

Instantly share code, notes, and snippets.

@bjhomer
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjhomer/c005b2d2ffd767653669 to your computer and use it in GitHub Desktop.
Save bjhomer/c005b2d2ffd767653669 to your computer and use it in GitHub Desktop.
My fish prompt
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
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
@bjhomer
Copy link
Author

bjhomer commented Jul 10, 2014

The custom prompt_pwd ensures that the cwd portion never takes more than ~65 characters. Thus,

this: /Users/bjhomer/Library/Containers/com.dayoneapp.dayone/Data/Library/Application Support

becomes: ~/.../com.dayoneapp.dayone/Data/Library/Application Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment