Last active
August 29, 2015 14:03
-
-
Save bjhomer/c005b2d2ffd767653669 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
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
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
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