This repository has been archived by the owner on Jun 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcdmenu.kak
80 lines (63 loc) · 2.42 KB
/
cdmenu.kak
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
##
## cdmenu.kak for kakoune-extra
## by lenormf
##
declare-user-mode cdmenu
declare-option str-to-str-map cdmenu_paths \
"/=/:/" \
"e=/etc:/etc" \
"g=git root:`git rev-parse --show-toplevel`" \
"h=client $HOME:`printenv kak_client_env_HOME`" \
"H=server $HOME:`printenv HOME`" \
"p=client pwd:`printenv kak_client_env_PWD`" \
"P=server pwd:`printenv PWD`" \
"t=/tmp:/tmp"
define-command -docstring %{
cdmenu [<index>]: quickly jump to a pre-defined path
Without the <index> argument, a menu listing all available indexes is displayed that allows the user to pick a path interactively.
An index can also be passed directly to the function.
} cdmenu -params ..1 %{ evaluate-commands %sh{
: # kak_client_env_HOME, kak_client_env_PWD
_do() {
action="$1"; shift
args="$*"
eval set -- "${kak_opt_cdmenu_paths}"
for i in "$@"; do
key="${i%%=*}"
case "${action}" in
get)
if [ "${args}" != "${key}" ]; then
continue
fi
path="${i#*:}"
if printf %s "${path}" | grep -q '^`.*`$'; then
path="${path#\`}"; path="${path%\`}"
path=$(eval "${path}")
fi
printf %s\\n "${path}";;
map)
doc=$(printf "${i}" | sed 's/^[^=]*=//; s/:[^:]*$//; s/~/~~/g')
printf 'map -docstring %%~%s~ global cdmenu %s %%{: cdmenu %s<ret>}\n' \
"${doc}" "${key}" "${key}";;
esac
done
}
get_path_index() {
_do "get" "$1"
}
map_indexes() {
_do "map"
}
if [ $# -eq 1 ]; then
path=$(get_path_index "$1")
if [ -z "${path}" ]; then
printf 'echo -markup {Error}Invalid index: %s' "${1}"
exit 1
fi
printf 'cd %%~%s~\n' "$(printf %s "${path}" | sed s/~/~~/g)"
printf 'echo -markup {Information}Path changed to: %s\n' "${path}"
else
map_indexes
echo enter-user-mode cdmenu
fi
} }