/
peco
61 lines (53 loc) · 1.64 KB
/
peco
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
55
56
57
58
59
60
61
# peco functions for bash
# select history
peco-history() {
local NUM=$(history | wc -l)
local FIRST=$((-1*(NUM-1)))
if [ $FIRST -eq 0 ] ; then
history -d $((HISTCMD-1))
echo "No history" >&2
return
fi
local CMD=$(fc -l $FIRST | sort -k 2 -k 1nr | uniq -f 1 | sort -nr | sed -E 's/^[0-9]+[[:blank:]]+//' | peco | head -n 1)
if [ -n "$CMD" ] ; then
READLINE_LINE="$CMD"
READLINE_POINT=${#CMD}
history -s $CMD
else
history -d $((HISTCMD-1)) > /dev/null 2>&1
fi
}
bind -x '"\C-r":peco-history'
# http://bio-eco-evo.hatenablog.com/entry/2017/04/30/044703
function peco-cd {
local sw="1"
while [ "$sw" != "0" ]
do
if [ "$sw" = "1" ];then
local list=$(echo -e "---$PWD\n../\n$( ls -F | grep / )\n---Show hidden directory\n---Show files, $(echo $(ls -F | grep -v / ))\n---HOME DIRECTORY")
elif [ "$sw" = "2" ];then
local list=$(echo -e "---$PWD\n$( ls -a -F | grep / | sed 1d )\n---Hide hidden directory\n---Show files, $(echo $(ls -F | grep -v / ))\n---HOME DIRECTORY")
else
local list=$(echo -e "---BACK\n$( ls -F | grep -v / )")
fi
local slct=$(echo -e "$list" | peco )
if [ "$slct" = "---$PWD" ];then
local sw="0"
elif [ "$slct" = "---Hide hidden directory" ];then
local sw="1"
elif [ "$slct" = "---Show hidden directory" ];then
local sw="2"
elif [ "$slct" = "---Show files, $(echo $(ls -F | grep -v / ))" ];then
local sw=$(($sw+2))
elif [ "$slct" = "---HOME DIRECTORY" ];then
cd "$HOME"
elif [[ "$slct" =~ / ]];then
cd "$slct"
elif [ "$slct" = "" ];then
:
else
local sw=$(($sw-2))
fi
done
}
alias sd='peco-cd'