-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_gen-header_completions
129 lines (120 loc) · 4.36 KB
/
_gen-header_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
#!/usr/bin/env bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
##@Version : 202108121903-git
# @Author : Jason Hempstead
# @Contact : jason@casjaysdev.pro
# @License : WTFPL
# @ReadME : gen-header --help
# @Copyright : Copyright: (c) 2021 Jason Hempstead, Casjays Developments
# @Created : Thursday, Aug 12, 2021 19:03 EDT
# @File : gen-header
# @Description : Create a script from template
# @TODO : Reactor code/Group Functions/Create separate gen-header script
# @Other :
# @Resource :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -'
_gen-header() {
___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}"
local cur="${COMP_WORDS[$COMP_CWORD]}"
local prev="${COMP_WORDS[$COMP_CWORD - 1]}"
local CONFFILE="settings.conf"
local CONFDIR="$HOME/.config/myscripts/gen-header"
local SEARCHDIR="${CONFDIR:-$HOME/.config/myscripts/gen-header}"
#local SEARCHCMD="$(___findcmd "$SEARCHDIR/" "d" "1" | sort -u)"
local SHOW_COMP_OPTS=""
local FILEDIR=""
local OPTS=""
local SHORTOPTS="a -e -h -d -t -c -o -r -i -f -n -u -l -p -k -s"
local LONGOPTS="--debug --options --config --version --help --dir "
local LONGOPTS+=",--all --no --help --user --raw --desc --todo --copywrite --other --res "
local LONGOPTS+=",--type --functions --name --prev --replace --keep --pause --system "
local LONGOPTS+=",--silent --license --skip "
local HEADER_OPTS="--no --help --user --raw --desc --todo --copywrite --other --res --type "
local HEADER_OPTS+="--functions --name --prev --replace --keep --pause --system "
local ARRAY="folders functions replace head version "
_init_completion || return
if [[ "$SHOW_COMP_OPTS" != "" ]]; then
local SHOW_COMP_OPTS_SEP="${SHOW_COMP_OPTS//,/ }"
compopt -o $SHOW_COMP_OPTS_SEP
fi
[[ ${#COMP_WORDS[@]} -le 2 ]] && COMPREPLY=($(compgen -W '${LONGOPTS} ${ARRAY}' -- ${cur}))
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
;;
folders)
shift
prev="folders"
COMPREPLY=($(compgen -W '$(user system profile)' "${cur}")) && _filedir
if [[ "${prev}" = -import ]]; then
COMPREPLY=($(compgen -W '${OTHER}' -- "${cur}")) && prev=-import
fi
;;
functions)
shift
prev="functions"
COMPREPLY=($(compgen -W '$(user system profile)' "${cur}")) && _filedir
if [[ "${prev}" = -import ]]; then
COMPREPLY=($(compgen -W '${OTHER}' -- "${cur}")) && prev=-import
fi
;;
replace)
prev="replace"
if [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
_filedir
elif [[ ${#COMP_WORDS[@]} -eq 4 ]]; then
COMPREPLY=($(compgen -W 'Author Contact License ReadME Copyright Created File Description Changelog TODO Other Resource Terminal sudo/root Template' -- "${cur}"))
elif [[ ${#COMP_WORDS[@]} -eq 5 ]]; then
COMPREPLY=($(compgen -W '\"\"' -- "${cur}"))
compopt -o nospace
else
COMPREPLY=($(compgen -W '' -- "${cur}"))
fi
;;
version)
prev="version"
_filedir
;;
head)
shift 1
if [[ ${cur} == --* ]]; then
COMPREPLY=($(compgen -W '${LONGOPTS}' -- ${cur}))
elif [[ ${cur} == -* ]]; then
COMPREPLY=($(compgen -W '${SHORTOPTS}' -- ${cur}))
else
if [[ ${#COMP_WORDS[@]} -eq 3 ]]; then
COMPREPLY=($(compgen -c -- "$cur"))
elif [[ ${#COMP_WORDS[@]} -eq 4 ]]; then
COMPREPLY=($(compgen -W '${HEADER_OPTS}' -- "${cur}"))
else
COMPREPLY=($(compgen -W '${HEADER_OPTS}' -- "${cur}"))
fi
fi
;;
esac
$split && return
} &&
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# enable completions
complete -F _gen-header gen-header