Last active
August 21, 2018 00:54
-
-
Save Trucido/e12b9ea8f65f99e1eb92985d85649e8a to your computer and use it in GitHub Desktop.
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
fish_path() { | |
setopt localoptions rcquotes nullglob | |
local result part; local -a tree expn; local -i i | |
( | |
tree=(${(s:/:)${1-${PWD/#$HOME/\~}}}) | |
if [[ $tree[1] == \~* ]] { | |
cd -q ${~tree[1]} | |
result=$tree[1]; shift tree | |
} else { cd -q / } | |
for dir in $tree; { | |
if (( $#tree == 1 )) { | |
result+="/$tree" && break | |
} | |
expn=(a b); part=''; i=0 | |
until [[ (( ${#expn} == 1 )) || $dir = $expn || $i -gt 99 ]] do | |
(( i++ )); part+=$dir[$i]; expn=($(part*(-/))) && break | |
done | |
result+="/$part"; cd -q $dir && shift tree | |
} | |
print -n ${result:-/} | |
) | |
} | |
setopt promptsubst | |
if (( EUID == 0 || UID == 0 )) then | |
PS1='%n@%m %F{red}$(fish_path)%f# ' | |
else | |
PS1='%n@%m %F{green}$(fish_path)%f> ' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment