-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_bindings.bash
100 lines (72 loc) · 2.89 KB
/
key_bindings.bash
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
__fsel_cat__() {
local file
file=$(python3 -m fsel.app -r -f "$@") && printf "${PAGER:-less} $file"
}
__fsel_edit__() {
local file
file=$(python3 -m fsel.app -r -f "$@") && printf "${EDITOR:-nano} $file"
}
__fsel_cd__() {
local args=("$@")
while true; do
local dir
local res
dir=$(python3 -m fsel.app -W "${args[@]}")
res=$?
# On Alt+Enter, continue with the link target
[[ $res == 80 ]] && args=($(realpath "$dir")) && continue
# On Alt+Home, continue with the parent of the returned root folder
[[ $res == 95 ]] && cd $(dirname "$dir") && args=($dir) && continue
[[ $res == 14 ]] && printf 'rm -rf %q' "$dir"
[[ $res == 0 ]] && printf 'cd %q' "$dir"
break
done
}
__fsel_run__() {
local file
file=$(python3 -m fsel.app -f -x "$@") && printf '%q' "$file"
}
__fsel_widget__() {
local selected
selected=$(python3 -m fsel.app "$@")
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
# Alt+Q: view selected file
bind '"\eq": "$(__fsel_cat__)\e\C-e\C-m"'
# Ctrl+Q: view selected file (including dot-files)
bind '"\C-Q": "$(__fsel_cat__ -a)\e\C-e\C-m"'
# Alt+Shift+Q: edit selected file
bind '"\eQ": "$(__fsel_edit__)\e\C-e\C-m"'
# Ctrl+Alt+Shift+Q: edit selected file (including dot-files)
bind '"\e\C-Q": "$(__fsel_edit__ -a)\e\C-e\C-m"'
# CTRL-ALT-Space: run selected executable
bind '"\e\C- ": "$(__fsel_run__)\e\C-e\C-m"'
# ALT-Z: run one of the recent executables
bind '"\ez": "$(__fsel_run__ -e)\e\C-e\C-m"'
# ALT-SHIFT-Z: insert the full path of one of the recent executables into command line
bind -x '"\eZ": "__fsel_widget__ -e -f -x"'
# ALT-X or Alt+End: cd into the selected directory
#bind '"\ex": "$(__fsel_cd__)\C-x\C-x\C-e\C-x\C-r\C-m\C-w"'
bind '"\ex": "$(__fsel_cd__)\e\C-e\C-m"'
bind '"\e[1;3F": "$(__fsel_cd__)\e\C-e\C-m"'
# ALT-SHIFT-X or Alt+Home: cd into one of the recent directories
bind '"\eX": "$(__fsel_cd__ -e)\e\C-e\C-m"'
bind '"\e[1;3H": "$(__fsel_cd__ -e)\e\C-e\C-m"'
# CTRL-]: insert the relative file path into command line
bind -x '"\C-]": "__fsel_widget__ -r -f"'
# ALT-]: insert the full file path into command line
bind -x '"\e]": "__fsel_widget__ -f"'
# ALT-SHIFT-]: insert the relative file path from root into command line
bind -x '"\e}": "__fsel_widget__ -R -f"'
# CTRL-ALT-]: insert the full path of one of the recent files into command line
bind -x '"\e\C-]": "__fsel_widget__ -e -f"'
# CTRL-G: insert the relative path to folder into command line
bind -x '"\C-g": "__fsel_widget__ -r"'
# ALT-G: insert the full path to folder into command line
bind -x '"\eg": "__fsel_widget__"'
# ALT-SHIFT-G: insert the relative path to folder from root into command line
bind -x '"\eG": "__fsel_widget__ -R"'
# CTRL-ALT-G: insert the full path of one of the recent folders into command line
bind -x '"\e\C-G": "__fsel_widget__ -e"'