-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts-autocomplete
More file actions
129 lines (111 loc) · 4.34 KB
/
scripts-autocomplete
File metadata and controls
129 lines (111 loc) · 4.34 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
_scripts_autocomplete() {
# Entrypoint location
local lib_path="/usr/local/lib/scripts"
# Current word (currently being typed)
local cur="${COMP_WORDS[COMP_CWORD]}"
# Previous word (word before $cur)
local prev="${COMP_WORDS[COMP_CWORD-1]}"
# Get the list of providers (first argument suggestions)
local providers=$(ls -1d "$lib_path"/*/ 2>/dev/null | xargs -n 1 basename)
# Add uninstall and update commands to providers
providers="$providers uninstall update"
# Handle special case for uninstall command
if [[ $COMP_CWORD -eq 2 && "$prev" == "uninstall" ]]; then
# Provide flags for uninstall command
COMPREPLY=( $(compgen -W "-v --verbose" -- "$cur") )
return
fi
# Get the actions for the selected provider (second argument suggestions)
if [[ $COMP_CWORD -eq 2 ]]
then
# If provider already typed and exists
if [[ -d "$lib_path/$prev" ]]
then
# Store available actions under typed provider
actions=$(ls -1 "$lib_path/$prev" | sed 's/\.sh$//')
fi
# Search actions that match $cur
COMPREPLY=( $(compgen -W "$actions" -- "$cur") )
return
fi
# Handle special case for gitlab mr-create command
if [[ $COMP_CWORD -ge 3 && "${COMP_WORDS[1]}" == "gitlab" && "${COMP_WORDS[2]}" == "mr-create" ]]; then
# Check if we're in a Git repository
if git rev-parse --is-inside-work-tree &>/dev/null; then
# If previous word is -m, we're expecting a title (no completion)
if [[ "$prev" == "-m" ]]; then
return
fi
# Check if we already have a branch name, -m flag, --draft flag, and --no-squash flag in the command
local has_branch=false
local has_m_flag=false
local has_draft_flag=false
local has_no_squash_flag=false
for ((i=3; i<COMP_CWORD; i++)); do
if [[ "${COMP_WORDS[i]}" == "-m" ]]; then
has_m_flag=true
# Skip the argument after -m (the title)
((i++))
elif [[ "${COMP_WORDS[i]}" == "--draft" ]]; then
has_draft_flag=true
elif [[ "${COMP_WORDS[i]}" == "--no-squash" ]]; then
has_no_squash_flag=true
elif [[ "${COMP_WORDS[i]}" != "-"* ]]; then
has_branch=true
fi
done
# Build suggestions for flags
local flag_suggestions=""
if ! $has_m_flag; then
flag_suggestions="$flag_suggestions -m"
fi
if ! $has_draft_flag; then
flag_suggestions="$flag_suggestions --draft"
fi
if ! $has_no_squash_flag; then
flag_suggestions="$flag_suggestions --no-squash"
fi
# If we don't have a branch yet
if ! $has_branch; then
# Get list of local branches
local branches=$(git branch --format='%(refname:short)' 2>/dev/null)
# Combine branches with flag suggestions
COMPREPLY=( $(compgen -W "$branches $flag_suggestions" -- "$cur") )
return
# If we have a branch but there are still flags to suggest
elif [[ -n "$flag_suggestions" ]]; then
COMPREPLY=( $(compgen -W "$flag_suggestions" -- "$cur") )
return
fi
else
# Not in a Git repository, just suggest flags
COMPREPLY=( $(compgen -W "-m --draft --no-squash" -- "$cur") )
return
fi
fi
# Handle ClickUp task-get command flags
if [[ $COMP_CWORD -ge 3 && "${COMP_WORDS[1]}" == "clickup" && "${COMP_WORDS[2]}" == "task-get" ]]; then
COMPREPLY=( $(compgen -W "-l --list -t --team -a --assignees -s --status -me --only-me" -- "$cur") )
return
fi
# Handle ClickUp team-get command flags
if [[ $COMP_CWORD -ge 3 && "${COMP_WORDS[1]}" == "clickup" && "${COMP_WORDS[2]}" == "team-get" ]]; then
COMPREPLY=( $(compgen -W "-e --email -s --search -c --columns" -- "$cur") )
return
fi
# Handle ClickUp space-get command flags
if [[ $COMP_CWORD -ge 3 && "${COMP_WORDS[1]}" == "clickup" && "${COMP_WORDS[2]}" == "space-get" ]]; then
COMPREPLY=( $(compgen -W "-t --team" -- "$cur") )
return
fi
# Handle ClickUp list-get command flags
if [[ $COMP_CWORD -ge 3 && "${COMP_WORDS[1]}" == "clickup" && "${COMP_WORDS[2]}" == "list-get" ]]; then
COMPREPLY=( $(compgen -W "-s --space" -- "$cur") )
return
fi
# Default to suggesting providers
COMPREPLY=( $(compgen -W "$providers" -- "$cur") )
}
# Register the completion function for the "scripts" command
complete -F _scripts_autocomplete scripts