-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_gen-script_completions
185 lines (175 loc) · 7.63 KB
/
_gen-script_completions
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202108121903-git
# @Author : Jason Hempstead
# @Contact : jason@casjaysdev.pro
# @License : WTFPL
# @ReadME : gen-script --help
# @Copyright : Copyright: (c) 2021 Jason Hempstead, Casjays Developments
# @Created : Thursday, Aug 12, 2021 19:03 EDT
# @File : gen-script
# @Description : Create a script from template
# @TODO : Reactor code/Group Functions/Create separate gen-header script
# @Other :
# @Resource :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
_gen-script() {
___findcmd() { find -L "${1:-$CONFDIR/}" -maxdepth ${3:-3} -type ${2:-f} 2>/dev/null | sed 's#'${1:-$CONFDIR}'##g' | grep '^' || return 1; }
local CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
local cur prev words cword opts split
local CASJAYSDEVDIR="${CASJAYSDEVDIR:-/usr/local/share/CasjaysDev/scripts}"
if [ -d "$HOME/.config/gen-script/files" ]; then
local GEN_SCRIPT_TEMPLATE_DIR="$HOME/.config/gen-script/files"
else
local GEN_SCRIPT_TEMPLATE_DIR="$CASJAYSDEVDIR/templates/scripts"
fi
local cur="${COMP_WORDS[$COMP_CWORD]}"
local prev="${COMP_WORDS[$COMP_CWORD - 1]}"
local CONFFILE="settings.conf"
local CONFDIR="$HOME/.config/myscripts/gen-script"
local SEARCHDIR="${CONFDIR:-$HOME/.config/myscripts/gen-script}"
#local SEARCHCMD="$(___findcmd "$SEARCHDIR/" "d" "1" | sort -u)"
local FOLDERS="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/" "d" "1" "$GEN_SCRIPT_TEMPLATE_DIR/" | grep -v ^'templates')"
local OS="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/os/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/os")"
local COMPLETIONS="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/completions/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/completions/")"
local SHELL="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/shell/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/shell/")"
local BASH="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/bash/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/bash/")"
local OTHER="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/other/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/other/")"
local READMES="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/other/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/other/")"
local INSTALLERS="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/installers/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/installers/")"
local FUNTIONS="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/functions/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/functions/")"
local ALL="$(___findcmd "$GEN_SCRIPT_TEMPLATE_DIR/" "f" "3" "$GEN_SCRIPT_TEMPLATE_DIR/")"
local SHOW_COMP_OPTS=""
local FILEDIR=""
local OPTS=""
local LONGOPTS="--options --config --version --help --dir --copy --config --function"
local SHORTOPTS="-z -a -g -f -replace -readme -head"
local ARRAY="new all ${FOLDERS}"
local HEADEROPTS="--no --help --user --raw --desc --todo --copy --other --res --type --functions --name --prev --replace --keep --pause --system"
_init_completion || return
if [[ "$SHOW_COMP_OPTS" != "" ]]; then
local SHOW_COMP_OPTS_SEP="${SHOW_COMP_OPTS//,/ }"
compopt -o $SHOW_COMP_OPTS_SEP
fi
case "${COMP_WORDS[1]:-$prev}" in
--options)
local prev="--options"
COMPREPLY=($(compgen -W '' -- "${cur}"))
;;
--config)
local prev="--config"
COMPREPLY=($(compgen -W '' -- "${cur}"))
;;
--help)
prev="--help"
COMPREPLY=($(compgen -W '' -- "${cur}"))
;;
--version)
local prev="--version"
COMPREPLY=($(compgen -W '' -- "${cur}"))
;;
--dir)
local prev="dir"
_filedir
return
;;
-head)
prev="head"
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- "${cur}"))
if [[ "${prev}" = "head" ]]; then
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- "${cur}"))
elif [[ ${#COMP_WORDS[@]} -eq 3 ]] && [[ ${COMP_WORDS[1]} = -header ]]; then
COMPREPLY=($(compgen -c -- "$cur"))
elif [[ ${#COMP_WORDS[@]} -gt 4 ]] && [[ ${COMP_WORDS[1]} = -header ]]; then
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- "${cur}"))
fi
;;
-readme)
prev="-readme"
COMPREPLY=($(compgen -W '-import . ${READMES}' -o plusdirs -- "${cur}")) && _filedir
if [[ "${prev}" = -import ]]; then
COMPREPLY=($(compgen -W '${OTHER}' -- "${cur}")) && prev=-import
fi
;;
all | installers | bash | shell | os | other | completions | functions)
if [[ "${next}" = "prevScripts" ]]; then
_filedir && next=filename
elif [[ "${next}" = "filename" ]]; then
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- ${cur})) && next=header
elif [[ "${next}" = "selected" ]] || [[ "${prev}" = "header" ]]; then
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- "${cur}")) && next=header
elif [[ "${prev}" = "" ]]; then
COMPREPLY=($(compgen -W '${ALL}' -- "${cur}")) && next=prevScripts
fi
if [[ "${prev}" = all ]]; then
COMPREPLY=($(compgen -W '${ALL}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = installers ]]; then
COMPREPLY=($(compgen -W '${INSTALLERS}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = bash ]]; then
COMPREPLY=($(compgen -W '${BASH}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = shell ]]; then
COMPREPLY=($(compgen -W '${SHELL}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = os ]]; then
COMPREPLY=($(compgen -W '${OS}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = other ]]; then
COMPREPLY=($(compgen -W '${OTHER}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = "completions" ]]; then
COMPREPLY=($(compgen -W '${COMPLETIONS}' -- "${cur}")) && next=prevScripts
elif [[ "${prev}" = "functions" ]]; then
COMPREPLY=($(compgen -W '${FUNTIONS}' -- "${cur}")) && next=prevScripts
fi
;;
new)
if [[ ${cword} -gt 3 ]]; then
COMPREPLY=($(compgen -W '${HEADEROPTS}' -- "${cur}"))
elif [[ ${cword} -eq 3 ]]; then
COMPREPLY=($(compgen -W '{a..z}' -- "${cur}")) && compopt -o nospace
elif [[ ${cword} -eq 2 ]]; then
COMPREPLY=($(compgen -W '_remove_ system user' -- "${cur}"))
fi
;;
*)
if [[ ${cur} == --* ]]; then
COMPREPLY=($(compgen -W '${LONGOPTS}' -- ${cur}))
elif [[ ${cur} == -* ]]; then
COMPREPLY=($(compgen -W '${SHORTOPTS}' -- ${cur}))
else
if [[ -n "$FILEDIR" ]]; then _filedir; fi
if [[ "$ARRAY" = "show__none" ]]; then
COMPREPLY=($(compgen -W '' -- "${cur}"))
elif [[ "$ARRAY" = "show__filedir" ]]; then
_filedir
elif [[ "$ARRAY" = "show__commands" ]]; then
COMPREPLY=($(compgen -c -- "${cur}"))
elif [ "$ARRAY" != "" ]; then
COMPREPLY=($(compgen -W '${ARRAY}' -- "${cur}"))
elif [ -n "$OPTS" ]; then
COMPREPLY=($(compgen -W '${OPTS}' -- "${cur}"))
else
COMPREPLY=($(compgen -W '${ARRAY}' -- "${cur}"))
# elif [[ ${cword} -gt 2 ]]; then
# return
# elif [[ ${cword} == 2 ]]; then
# _filedir
# compopt -o nospace
# return
# elif [[ $cword -eq 1 ]]; then
# COMPREPLY=($(compgen -W '{a..z}{a..z}' -- "${cur}"))
# compopt -o nospace
# return
fi
fi
;;
esac
#
# [[ ${cword} == 2 ]] && _filedir && compopt -o nospace
# [[ $COMP_CWORD -eq 2 ] && COMPREPLY=($(compgen -W '{a..z} {A..Z} {0..9}' -o nospace -- "${cur}"))
# [[ $COMP_CWORD -eq 3 ] && COMPREPLY=($(compgen -W '$(_filedir)' -o filenames -o dirnames -- "${cur}"))
# [[ $COMP_CWORD -gt 3 ] && COMPREPLY=($(compgen -W '' -- "${cur}"))
#prev=""
#compopt -o nospace
$split && return
} &&
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# enable completions
complete -F _gen-script gen-script