dotfiles/oni/home/config/zsh/spwd.zsh

28 lines
639 B
Bash
Raw Normal View History

2025-01-21 23:33:39 +01:00
function spwd() {
# From https://stackoverflow.com/a/45336078
paths=(${(s:/:)PWD})
cur_path='/'
cur_short_path='/'
for directory in ${paths[@]}
do
cur_dir=''
for (( i=0; i<${#directory}; i++ )); do
cur_dir+="${directory:$i:1}"
matching=("$cur_path"/"$cur_dir"*/)
if [[ ${#matching[@]} -eq 1 ]]; then
break
fi
done
cur_short_path+="$cur_dir/"
cur_path+="$directory/"
if [[ $cur_path == $HOME/ ]];
then cur_short_path='~/'
fi
done
printf %b "${cur_short_path: : -1}"
echo
}