Skip to content

Instantly share code, notes, and snippets.

@miekg
Last active December 21, 2015 05:18
Show Gist options
  • Save miekg/6255503 to your computer and use it in GitHub Desktop.
Save miekg/6255503 to your computer and use it in GitHub Desktop.
Fish like shell path in zsh.
# shorten path -> /home/miekg/bla -> /h/m/bla
function shorten() {
full=$(print -P "$1")
a=(${(s:/:)full})
if [[ $#a -eq 0 || $#a -eq 1 ]]; then
print $1; return
fi
last=$a[$#a]
a[$#a]= # clear last element
for i in $a; do
if [[ ${i:0:1} == "~" ]]; then
print -n $i
continue
fi
print -n "/"${i:0:1}
done
print -n "/"$last
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment