mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Fix regex checks
This commit is contained in:
parent
7c767810e4
commit
0941166c9c
2 changed files with 9 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ARG_REGEX="<[a-zA-Z_]+([- ]?\w+)*>"
|
||||
ARG_REGEX_WITHOUT_BRACKETS="[a-zA-Z_]+([- ]?\w+)*"
|
||||
ARG_REGEX="<${ARG_REGEX_WITHOUT_BRACKETS}>"
|
||||
ARG_DELIMITER="\f"
|
||||
ARG_DELIMITER_2="\v"
|
||||
ARG_DELIMITER_3="\r"
|
||||
|
|
19
src/main.sh
19
src/main.sh
|
@ -39,22 +39,17 @@ handler::main() {
|
|||
fi
|
||||
|
||||
escaped_arg="$(echo "$arg" | tr '-' '_' | tr ' ' '_')"
|
||||
if [[ $escaped_arg =~ $ARG_REGEX ]]; then
|
||||
cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")"
|
||||
arg="$escaped_arg"
|
||||
else
|
||||
exit 1
|
||||
if ! [[ $escaped_arg =~ $ARG_REGEX_WITHOUT_BRACKETS ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")"
|
||||
arg="$escaped_arg"
|
||||
value="$(arg::pick "$arg" "$cheat" || echo "")"
|
||||
if [[ $arg =~ $ARG_REGEX ]]; then
|
||||
if [ -z "$value" ]; then
|
||||
echoerr "Unable to fetch suggestions for '$arg'!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
else
|
||||
exit 1
|
||||
if [ -z "$value" ]; then
|
||||
echoerr "Unable to fetch suggestions for '$arg'!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
eval "local $arg"='$value'
|
||||
|
|
Loading…
Reference in a new issue