-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdpp.sh
54 lines (46 loc) · 1.07 KB
/
cdpp.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
cdpp() {
if [[ ${PWD//[^\/]} = '/' ]]; then
echo 'Please use "cd /"'
return
fi
## change to your favorite shortcuts, for example:
#local key=({1..9})
local key=(l k j f d s a)
while :; do
local cpath=$PWD
unset idpath
declare -A idpath
for i in ${key[@]}; do
cpath=${cpath%/*}
if [[ -z "$cpath" ]]; then
break
fi
idpath[$i]=$cpath
done
local cols=$(tput cols)
local leftlen=0
local idn=$(( ${#idpath[@]} - 1 ))
local idy=0
while (( leftlen <= ${#PWD} )); do
echo ${PWD:$leftlen:$cols}
leftlen=$(( leftlen + cols ))
while (( idn >= 0 )); do
local id=${key[idn]}
local idx=$(( ${#idpath[$id]} - idy * cols ))
(( idx <= cols && idx >= 0 )) || break
tput hpa $idx
printf "\e[1;31m%s\e[0m" $id
(( idn-- ))
done
(( idy++ ))
echo
done
read -s -n 1 id
case ${!idpath[@]} in
*$id*)
cd ${idpath[$id]};;
esac
[[ -n ${cpath} && ${cpath//[^\/]} != '/' ]] || break
done
}
alias c=cdpp