diff --git a/scripts/playground b/scripts/playground new file mode 100755 index 0000000..62b805f --- /dev/null +++ b/scripts/playground @@ -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" "$@" \ No newline at end of file diff --git a/src/arg.sh b/src/arg.sh index 9033a39..f01fd40 100644 --- a/src/arg.sh +++ b/src/arg.sh @@ -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" diff --git a/src/main.sh b/src/main.sh index 97d323a..947811f 100644 --- a/src/main.sh +++ b/src/main.sh @@ -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'!" diff --git a/test/core.sh b/test/core.sh index 0af5d48..bf7d348 100644 --- a/test/core.sh +++ b/test/core.sh @@ -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 diff --git a/test/playground.cheat b/test/playground.cheat index f451a71..abd859f 100644 --- a/test/playground.cheat +++ b/test/playground.cheat @@ -3,6 +3,9 @@ # this should be the first test. single and double quotes + newlines echo +# variable names +echo + # use % coll::new 1 2 3 | xargs -I% echo "hello %" diff --git a/test/var_test.sh b/test/var_test.sh index 38f148a..e9bfbd5 100644 --- a/test/var_test.sh +++ b/test/var_test.sh @@ -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" \ No newline at end of file