Allow variable names to include dashes and spaces (#97)

Based on https://github.com/denisidoro/navi/pull/95 by @engrravijain 

Fixes #60
This commit is contained in:
Denis Isidoro 2019-09-28 23:24:12 -03:00 committed by GitHub
parent 2aa07c2ce1
commit d04dfc1003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 1 deletions

7
scripts/playground Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
export NAVI_PATH="${SCRIPT_DIR}/test:${SCRIPT_DIR}/cheats"
"${SCRIPT_DIR}/navi" "$@"

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
ARG_REGEX="<[0-9a-zA-Z_]+>"
ARG_REGEX="<[a-zA-Z_]+([- ]?\w+)*>"
ARG_DELIMITER="\f"
ARG_DELIMITER_2="\v"
ARG_DELIMITER_3="\r"

View File

@ -38,6 +38,10 @@ handler::main() {
break
fi
escaped_arg="$(echo "$arg" | tr '-' '_' | tr ' ' '_')"
cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")"
arg="$escaped_arg"
value="$(arg::pick "$arg" "$cheat" || echo "")"
if [ -z "$value" ]; then
echoerr "Unable to fetch suggestions for '$arg'!"

View File

@ -6,6 +6,7 @@ source "${SCRIPT_DIR}/src/main.sh"
source "${SCRIPT_DIR}/test/log.sh"
opts::eval "$@"
TEST_DIR="${SCRIPT_DIR}/test"
PASSED=0
FAILED=0

View File

@ -3,6 +3,9 @@
# this should be the first test. single and double quotes + newlines
echo <x> <y>
# variable names
echo <x> <foo> <foo_bar> <lorem-ipsum> <dolor sit>
# use %
coll::new 1 2 3 | xargs -I% echo "hello %"

View File

@ -11,7 +11,10 @@ check_all_vars() {
done
}
path="$NAVI_PATH"
NAVI_PATH="${NAVI_PATH}:${TEST_DIR}"
for cheat in $(cheat::find); do
test::run "All variables in $(basename $cheat) are valid" \
'check_all_vars "$cheat"'
done
NAVI_PATH="$path"