@@ -15,7 +15,7 @@ opcode_context() {
1515 printf " Usage:\n"
1616 printf " %s CODE [ARGS]\n" " $PROGRAM_NAME "
1717 if [[ $long_usage == 1 ]]; then
18- printf " Execute a command from the config file (%s)\n" " $CONFIG_FILE "
18+ printf " Execute a command from the config file (%s)\n" " $opcode_file "
1919 printf " Arguments will be passed to the command (use with \"\$ @\" )\n\n"
2020 fi
2121
@@ -31,7 +31,7 @@ opcode_context() {
3131
3232 printf " %s -s, --show\n" " $PROGRAM_NAME "
3333 if [[ $long_usage == 1 ]]; then
34- printf " Show the config file (%s)\n\n" " $CONFIG_FILE "
34+ printf " Show the config file (%s)\n\n" " $opcode_file "
3535 fi
3636
3737 printf " %s -w, --what [CODE]\n" " $PROGRAM_NAME "
@@ -77,8 +77,8 @@ opcode_context() {
7777 }
7878
7979 need_config () {
80- if [[ ! -f $CONFIG_FILE ]]; then
81- abort " Cannot find config file ($CONFIG_FILE )"
80+ if [[ ! -f $opcode_file ]]; then
81+ abort " Cannot find config file ($opcode_file )"
8282 fi
8383 }
8484
@@ -126,7 +126,7 @@ opcode_context() {
126126 break
127127 fi
128128 fi
129- done < " $CONFIG_FILE "
129+ done < " $opcode_file "
130130
131131 printf " %s\n" " ${script[@]} "
132132 }
@@ -156,7 +156,7 @@ opcode_context() {
156156 shift
157157 new_command=$( shellwords " ${@ } " )
158158
159- echo " $new_code : $new_command " >> " $CONFIG_FILE "
159+ echo " $new_code : $new_command " >> " $opcode_file "
160160 show_config
161161 }
162162
@@ -193,7 +193,7 @@ opcode_context() {
193193 elif [[ $line =~ $break_regex ]]; then
194194 break
195195 fi
196- done < " $CONFIG_FILE "
196+ done < " $opcode_file "
197197
198198 printf " \n"
199199
@@ -234,17 +234,17 @@ opcode_context() {
234234 printf " %s\n" " ${BASH_REMATCH[1]} "
235235
236236 fi
237- done < " $CONFIG_FILE "
237+ done < " $opcode_file "
238238 printf " \n"
239239 }
240240
241241 edit_config () {
242- ${EDITOR:- vi} " $CONFIG_FILE "
242+ ${EDITOR:- vi} " $opcode_file "
243243 }
244244
245245 show_config () {
246246 need_config
247- cat " $CONFIG_FILE "
247+ cat " $opcode_file "
248248 }
249249
250250 show_syntax () {
@@ -318,33 +318,33 @@ EOF
318318 }
319319
320320 set_config_file () {
321- if [[ -n ${CONFIG_FILE_OVERRIDE :- } ]]; then
322- CONFIG_FILE =" $CONFIG_FILE_OVERRIDE "
321+ if [[ -n ${opcode_file_override :- } ]]; then
322+ opcode_file =" $opcode_file_override "
323323 elif [[ -n ${OPCODE_CONFIG:- } ]]; then
324- CONFIG_FILE =" $OPCODE_CONFIG "
324+ opcode_file =" $OPCODE_CONFIG "
325325 elif [[ $PROGRAM_NAME == " op" && -f " opcode" ]]; then
326- CONFIG_FILE =" opcode"
326+ opcode_file =" opcode"
327327 elif [[ $PROGRAM_NAME == " op" ]]; then
328- CONFIG_FILE =" op.conf"
328+ opcode_file =" op.conf"
329329 elif [[ -f " $PROGRAM_NAME .op.conf" ]]; then
330- CONFIG_FILE =" $PROGRAM_NAME .op.conf"
330+ opcode_file =" $PROGRAM_NAME .op.conf"
331331 elif [[ -f " $PROGRAM_NAME .conf" ]]; then
332- CONFIG_FILE =" $PROGRAM_NAME .conf"
332+ opcode_file =" $PROGRAM_NAME .conf"
333333 else
334- CONFIG_FILE =" $PROGRAM_NAME .op.conf"
334+ opcode_file =" $PROGRAM_NAME .op.conf"
335335 fi
336336 }
337337
338338 list_or_usage () {
339- if [[ -f $CONFIG_FILE ]]; then
339+ if [[ -f $opcode_file ]]; then
340340 list_codes
341341 else
342342 usage
343343 fi
344344 }
345345
346346 send_completion () {
347- [[ -z " $COMP_LINE " || ! -f $CONFIG_FILE ]] && return
347+ [[ -z " $COMP_LINE " || ! -f $opcode_file ]] && return
348348 # shellcheck disable=SC2086
349349 set $COMP_LINE
350350 if [[ $# -eq 1 ]]; then
@@ -355,24 +355,28 @@ EOF
355355 }
356356
357357 parse_config_option () {
358- CONFIG_FILE_OVERRIDE =" "
358+ opcode_file_override =" "
359359
360360 if [[ $1 == " -c" || $1 == " --config" ]]; then
361361 if [[ -z ${2:- } ]]; then
362362 abort " Missing config file for $1 "
363363 fi
364364
365- CONFIG_FILE_OVERRIDE =" $2 "
365+ opcode_file_override =" $2 "
366366 shift 2
367367 fi
368368
369- OPCODE_ARGS =(" $@ " )
369+ opcode_args =(" $@ " )
370370 }
371371
372372 opcode_run () {
373+ local opcode_file
374+ local opcode_file_override
375+ local -a opcode_args
376+
373377 parse_config_option " $@ "
374378 set_config_file
375- set -- " ${OPCODE_ARGS [@]} "
379+ set -- " ${opcode_args [@]} "
376380
377381 case " $1 " in
378382 " " ) list_or_usage ;;
400404 cyan () { printf " \e[36m%b\e[0m\n" " $* " ; }
401405
402406 opcode_initialize () {
403- VERSION=" 1.2.0 "
407+ VERSION=" 1.2.1 "
404408 PROGRAM_NAME=$( basename " $0 " )
405409 set -e
406410 }
0 commit comments