-
Notifications
You must be signed in to change notification settings - Fork 0
/
_nooks
55 lines (49 loc) · 1.58 KB
/
_nooks
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
#compdef nooks
# Function to load and complete tags from ~/.nooks file
_nooks_tags() {
local -a tags
# Read tags from ~/.nooks file, one per line
tags=(${(f)"$(awk '{print $1}' ~/.nooks 2>/dev/null)"})
# Present tags as completion options
_describe 'tag' tags
}
# Main completion function for nooks
_nooks() {
local context state state_descr line
typeset -A opt_args
# Define all possible options for nooks
local -a nooks_options=(
'(-s --save-mark)'{-s,--save-mark}'[Save current directory with NAME]'
'(-a --all)'{-a,--all}'[Show all saved directories]'
'(-h --help)'{-h,--help}'[Display help and exit]'
'(-q --quiet)'{-q,--quiet}'[Quiet mode]'
'(-v --version)'{-v,--version}'[Display version information]'
)
# Set up argument completion
_arguments -C \
$nooks_options[@] \
'1: :->cmds' \
'*:: :->args' && return 0
# Handle different completion states
case $state in
cmds)
# If no argument is given yet, complete with tags
_nooks_tags
;;
args)
# If an argument is already given, check what it is
case $line[1] in
-s|--save-mark)
# For -s or --save-mark, prompt for a name
_message 'name for saved directory'
;;
*)
# For any other case, complete with tags
_nooks_tags
;;
esac
;;
esac
}
# Execute the completion function
_nooks "$@"