-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.abbr_pwd
41 lines (32 loc) · 792 Bytes
/
.abbr_pwd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/zsh
function felix_pwd_abbr {
base_pwd=$PWD
tilda_notation=${base_pwd//$HOME/\~}
pwd_list=(${(s:/:)tilda_notation})
list_len=${#pwd_list}
if [[ $list_len -le 1 ]]; then
echo $tilda_notation
return
fi
if [[ ${pwd_list[1]} != '~' ]]; then
formed_pwd='/'
fi
firstchar=$(echo ${pwd_list[1]} | cut -c1)
if [[ $firstchar == '.' ]] ; then
firstchar=$(echo ${pwd_list[1]} | cut -c1,2)
fi
formed_pwd=${formed_pwd}$firstchar
for ((i=2; i <= $list_len; i++)) do
if [[ $i != ${list_len} ]]; then
firstchar=$(echo ${pwd_list[$i]} | cut -c1)
if [[ $firstchar == '.' ]] ; then
firstchar=$(echo ${pwd_list[$i]} | cut -c1,2)
fi
formed_pwd=${formed_pwd}/$firstchar
else
formed_pwd=${formed_pwd}/${pwd_list[$i]}
fi
done
echo $formed_pwd
return
}