-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_rura
More file actions
89 lines (76 loc) · 2.06 KB
/
_rura
File metadata and controls
89 lines (76 loc) · 2.06 KB
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
#compdef rura
function _rura() {
local -a cmd_list memory_list
local mem_path target name display_target
local context state state_descr line
typeset -A opt_args
cmd_list=(
'add:Memorize a directory'
'delete:Forget a memory'
'list:List memories'
'help:Show help'
'version:Show version'
)
local base_dir="${RURA_MEMORY_DIR:-$HOME/.rura}"
for mem_path in "$base_dir"/@*(N); do
name="${mem_path:t}"
if [[ -L "$mem_path" ]]; then
target="$(readlink "$mem_path")"
else
target=""
fi
display_target="${target/#$HOME/~}"
if [[ ! -d "$target" ]]; then
display_target="✖ ${display_target}"
fi
display_target="${display_target//:/\\:}"
memory_list+=("$name:$display_target")
done
_arguments -C \
'1: :->cmd' \
'*:: :->args' && return 0
case $state in
cmd)
local ret=1
_tags memories commands
while _tags; do
if _requested memories; then
_describe -t memories 'Memories' memory_list && ret=0
fi
if _requested commands; then
_describe -t commands 'Commands' cmd_list && ret=0
fi
(( ret )) || break
done
return ret
;;
args)
case $line[1] in
delete|d)
if (( CURRENT == 2 )); then
local -a del_targets
for mem_path in "$base_dir"/@*(N); do
name="${${mem_path:t}#@}"
target="$(readlink "$mem_path")"
display_target="${target/#$HOME/~}"
if [[ ! -d "$target" ]]; then
display_target="✖ ${display_target}"
fi
display_target="${display_target//:/\\:}"
del_targets+=("$name:$display_target")
done
_describe -t memories 'memories to forget' del_targets
fi
;;
add|a)
if (( CURRENT == 2 )); then
_directories
elif (( CURRENT == 3 )); then
_message "memory name (e.g. work)"
fi
;;
esac
;;
esac
}
_rura "$@"