Skip to content

Commit 2ef2086

Browse files
committed
v4.4.1
===================================================================== --- Bug Fixes ---------------------------- - scwrypts now run when using --group and --type options without --name - fixed spacing issues in scwrypts --help - added missing = sign in config --- New Features ------------------------- - zsh completion now loads with scwrypts.plugin.zsh (requires compdef)
1 parent 3fe01a7 commit 2ef2086

File tree

3 files changed

+142
-18
lines changed

3 files changed

+142
-18
lines changed

.config/env.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export DISCORD__DEFAULT_CHANNEL_ID=
1313
export DISCORD__DEFAULT_USERNAME=
1414
export DISCORD__DEFAULT_WEBHOOK=
1515
export LINEAR__API_TOKEN=
16-
export MEDIA_SYNC__S3_BUCKET
17-
export MEDIA_SYNC__TARGETS
16+
export MEDIA_SYNC__S3_BUCKET=
17+
export MEDIA_SYNC__TARGETS=
1818
export REDIS_AUTH=
1919
export REDIS_HOST=
2020
export REDIS_PORT=

scwrypts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
2323
-y, --yes auto-accept all [yn] prompts through current scwrypt
2424
-e, --env <env-name> set environment; overwrites SCWRYPTS_ENV
2525
26-
-n shorthand for "--log-level 0"
27-
-v, --log-level [0-4] set incremental scwrypts log level to one of the following:
28-
0 : only command output and critical failures; skips logfile
29-
1 : include success / failure messages
30-
2 : include status update messages
31-
3 : (default) include warning messages
32-
4 : include debug messages
33-
34-
-o, --output specify output format; one of:
35-
pretty (default)
36-
json (experimental)
26+
-n shorthand for "--log-level 0"
27+
-v, --log-level <0-4> set incremental scwrypts log level to one of the following:
28+
0 : only command output and critical failures; skips logfile
29+
1 : include success / failure messages
30+
2 : include status update messages
31+
3 : (default) include warning messages
32+
4 : include debug messages
33+
34+
-o, --output <format> specify output format; one of: pretty,json (default: pretty)
3735
3836
alternate commands
3937
-h, --help display this message and exit
@@ -119,7 +117,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
119117
--update )
120118
case $SCWRYPTS_INSTALLATION_TYPE in
121119
aur )
122-
SCWRYPTS_LOG_LEVEL=3 REMINDER "
120+
SCWRYPTS_LOG_LEVEL=3 REMINDER "
123121
This installation is built from the AUR. Update through 'makepkg' or use
124122
your preferred AUR package management tool (e.g. 'yay -Syu scwrypts')
125123
"
@@ -152,7 +150,7 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
152150
;;
153151

154152
* )
155-
SCWRYPTS_LOG_LEVEL=3 REMINDER "
153+
SCWRYPTS_LOG_LEVEL=3 REMINDER "
156154
This is a managed installation of scwrypts. Please update through your
157155
system package manager.
158156
"
@@ -173,12 +171,14 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
173171
((SHIFT_COUNT+=1))
174172
[ $2 ] || { ERROR "missing value for argument $1"; break; }
175173
SEARCH_GROUP=$2
174+
GROUP=$2
176175
;;
177176

178177
-t | --type )
179178
((SHIFT_COUNT+=1))
180179
[ $2 ] || { ERROR "missing value for argument $1"; break; }
181180
SEARCH_TYPE=$2
181+
TYPE=$2
182182
;;
183183

184184
### runtime settings #####################
@@ -249,7 +249,6 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
249249
echo $SCWRYPTS_AVAILABLE | head -n1
250250
echo $SCWRYPTS_AVAILABLE | grep ' [^/]*'$SEARCH_TYPE'[^/]* '
251251
} \
252-
| awk '{$2=""; print $0;}' \
253252
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
254253
| column -ts '^'
255254
)
@@ -259,9 +258,8 @@ source "$(dirname $(readlink -f "$0"))/zsh/lib/import.driver.zsh" || exit 42
259258
SCWRYPTS_AVAILABLE=$(
260259
{
261260
echo $SCWRYPTS_AVAILABLE | head -n1
262-
echo $SCWRYPTS_AVAILABLE | grep "$SEARCH_GROUP"'[^/]*$'
261+
echo $SCWRYPTS_AVAILABLE | grep "$SEARCH_GROUP"'[^/ ]*$'
263262
} \
264-
| awk '{$NF=""; print $0;}' \
265263
| sed 's/ \+$/'$(printf $__COLOR_RESET)'/; s/ \+/^/g' \
266264
| column -ts '^'
267265
)

scwrypts.plugin.zsh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,130 @@ __SCWRYPTS_PARSE() {
9494

9595
#####################################################################
9696

97+
# badass(/terrifying?) zsh autocompletion
98+
command -v compdef &>/dev/null && {
99+
_scwrypts() {
100+
echo $words | grep -q "\s--\s" && _arguments && return 0
101+
eval "_arguments $(
102+
{
103+
HELP=$(scwrypts --help 2>&1 | sed -n 's/^\s\+\(-.* .\)/\1/p' | sed 's/[[]/(/g; s/[]]/)/g')
104+
echo $HELP \
105+
| sed 's/^\(\(-[^-\s]\),*\s*\|\)\(\(--[-a-z0-9A-Z\]*\)\s\(<\([^>]*\)>\|\)\|\)\s\+\(.*\)/\2[\7]:\6:->\2/' \
106+
| grep -v '^[[]' \
107+
;
108+
109+
echo $HELP \
110+
| sed 's/^\(\(-[^-\s]\),*\s*\|\)\(\(--[-a-z0-9A-Z\]*\)\s\(<\([^>]*\)>\|\)\|\)\s\+\(.*\)/\4[\7]:\6:->\4/' \
111+
| grep -v '^[[]' \
112+
;
113+
114+
echo ":pattern:->pattern"
115+
echo ":pattern:->pattern"
116+
echo ":pattern:->pattern"
117+
echo ":pattern:->pattern"
118+
echo ":pattern:->pattern"
119+
120+
} | sed 's/::->.*$//g' | sed "s/\\(^\\|$\\)/'/g" | tr '\n' ' '
121+
)"
122+
123+
local _group=''
124+
echo $words | grep -q ' -g [^\s]' \
125+
&& _group=$(echo $words | sed 's/.*-g \([^ ]\+\)\s*.*/\1/')
126+
echo $words | grep -q ' --group .' \
127+
&& _group=$(echo $words | sed 's/.*--group \([^ ]\+\)\s*.*/\1/')
128+
129+
local _type=''
130+
echo $words | grep -q ' -t [^\s]' \
131+
&& _type=$(echo $words | sed 's/.*-t \([^ ]\+\)\s*.*/\1/')
132+
echo $words | grep -q ' --type .' \
133+
&& _type=$(echo $words | sed 's/.*--type \([^ ]\+\)\s*.*/\1/')
134+
135+
local _name=''
136+
echo $words | grep -q ' -m [^\s]' \
137+
&& _name=$(echo $words | sed 's/.*-m \([^ ]\+\)\s*.*/\1/')
138+
echo $words | grep -q ' --name .' \
139+
&& _name=$(echo $words | sed 's/.*--name \([^ ]\+\)\s*.*/\1/')
140+
141+
local _pattern _patterns=()
142+
[ ! $_name ] \
143+
&& _patterns=($(echo "${words[@]:1}" | sed 's/\s\+/\n/g' | grep -v '^-'))
144+
145+
_get_remaining_scwrypts() {
146+
[ $_name ] || local _name='[^ ]\+'
147+
[ $_type ] || local _type='[^ ]\+'
148+
[ $_group ] || local _group='[^ ]\+'
149+
150+
local remaining=$(\
151+
scwrypts --list \
152+
| sed "1d; s,\x1B\[[0-9;]*[a-zA-Z],,g" \
153+
| grep "^$_name\s" \
154+
| grep "\s$_group$" \
155+
| grep "\s$_type\s" \
156+
)
157+
158+
for _pattern in ${_patterns[@]}
159+
do
160+
remaining=$(echo "$remaining" | grep "$_pattern")
161+
done
162+
163+
echo "$remaining"
164+
}
165+
166+
case $state in
167+
( -m | --name )
168+
compadd $(_get_remaining_scwrypts | awk '{print $1;}' | sort -u)
169+
;;
170+
171+
( -t | --type )
172+
compadd $(_get_remaining_scwrypts | awk '{print $2;}' | sort -u)
173+
;;
174+
175+
( -g | --group )
176+
[[ $_name$_type$_group =~ ^$ ]] \
177+
&& compadd $(scwrypts --list-groups) \
178+
|| compadd $(_get_remaining_scwrypts | awk '{print $3;}' | sort -u) \
179+
;;
180+
181+
( -e | --env )
182+
compadd $(scwrypts --list-envs)
183+
;;
184+
185+
( -v | --log-level )
186+
local _help="$(\
187+
scwrypts --help 2>&1 \
188+
| sed -n '/-v, --log-level/,/^$/p' \
189+
| sed -n 's/\s\+\([0-9]\) : \(.*\)/\1 -- \2/p' \
190+
)"
191+
192+
eval "local _descriptions=($(echo "$_help" | sed "s/\\(^\|$\\)/'/g"))"
193+
local _values=($(echo "$_help" | sed 's/ --.*//'))
194+
compadd -d _descriptions -a _values
195+
;;
196+
197+
( -o | --output )
198+
compadd pretty json
199+
;;
200+
201+
( pattern )
202+
[[ $_name =~ ^$ ]] && {
203+
local _remaining_scwrypts="$(_get_remaining_scwrypts)"
204+
# stop providing suggestions if your pattern is sufficient
205+
[[ $(echo $_remaining_scwrypts | wc -l) -le 1 ]] && return 0
206+
207+
local _remaining_patterns="$(echo "$_remaining_scwrypts" | sed 's/\s\+/\n/g; s|/|\n|g;' | sort -u)"
208+
209+
for _pattern in ${_patterns[@]}
210+
do
211+
_remaining_patterns="$(echo "$_remaining_patterns" | grep -v "^$_pattern$")"
212+
done
213+
compadd $(echo $_remaining_patterns)
214+
}
215+
;;
216+
217+
( * ) ;;
218+
esac
219+
}
220+
compdef _scwrypts scwrypts
221+
}
222+
97223
__SCWRYPTS_PLUGIN_LOADED=true

0 commit comments

Comments
 (0)