Merge branch 'master' into master

This commit is contained in:
Denis Isidoro 2019-09-28 23:26:27 -03:00 committed by GitHub
commit 68ba9ed3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 54 additions and 18 deletions

View File

@ -19,4 +19,8 @@ netstat -tn 2>/dev/null \
dig +short myip.opendns.com @resolver1.opendns.com
# Find primary, local IP address
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | tail -n1
ifconfig \
| grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' \
| grep -Eo '([0-9]*\.){3}[0-9]*' \
| grep -v '127.0.0.1' \
| tail -n1

2
navi
View File

@ -35,7 +35,7 @@ source "${SCRIPT_DIR}/src/main.sh"
##? full docs
##? Please refer to the README at https://github.com/denisidoro/navi
VERSION="0.10.1"
VERSION="0.10.2"
NAVI_ENV="${NAVI_ENV:-prod}"
opts::eval "$@"

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

@ -2,7 +2,7 @@ _call_navi() {
local buff="$BUFFER"
zle kill-whole-line
local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true navi --print <> /dev/tty)"
zle -U "$buff$(echo "$cmd")"
zle -U "${buff}${cmd}"
# zle accept-line
}

View File

@ -1,8 +1,9 @@
#!/usr/bin/env bash
ARG_REGEX="<\w+([- ]?\w+)*>"
ARG_REGEX="<[a-zA-Z_]+([- ]?\w+)*>"
ARG_DELIMITER="\f"
ARG_DELIMITER_2="\v"
ARG_DELIMITER_3="\r"
arg::dict() {
local -r input="$(cat | sed 's/\\n/\\f/g')"
@ -30,7 +31,7 @@ arg::next() {
arg::deserialize() {
local arg="$1"
arg="${arg:1:${#arg}-2}"
echo "$arg" | tr "${ARG_DELIMITER}" " " | tr "${ARG_DELIMITER_2}" "'"
echo "$arg" | tr "${ARG_DELIMITER}" " " | tr "${ARG_DELIMITER_2}" "'" | tr "${ARG_DELIMITER_3}" '"'
}
# TODO: separation of concerns
@ -61,7 +62,7 @@ arg::pick() {
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
fi
elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then
echo "" | ui::pick --prompt "$arg: " --print-query --height 1
echo "" | ui::pick --prompt "$arg: " --print-query --no-select-1 --height 1
else
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
read -r value

View File

@ -13,7 +13,7 @@ dict::new() {
if [ $# = 0 ]; then
echo ""
else
echo "" | dict::assoc "$@"
echo "" | dict::assoc "$@" | sed '/^$/d'
fi
}
@ -48,7 +48,7 @@ dict::assoc() {
local -r value="$(echo "${2:-}" | dict::_escape_value)"
shift 2
echo "$(echo "$input" | dict::dissoc "$key")${key}: ${value}\n" | dict::assoc "$@"
echo "$(echo "$input" | dict::dissoc "$key")${key}: ${value}\n" | dict::assoc "$@"
}
dict::get() {
@ -72,11 +72,18 @@ dict::get() {
}
dict::keys() {
grep -Eo '^[^:]+: ' | sed 's/: //g'
grep -Eo '^[^:]+: ' \
| sed 's/: //g'
}
dict::values() {
awk -F':' '{$1=""; print $0}' | cut -c3-
awk -F':' '{$1=""; print $0}' \
| cut -c3-
}
dict::merge() {
awk -F':' '{$1=""; print $0}' \
| cut -c3-
}
dict::zipmap() {

View File

@ -38,9 +38,9 @@ handler::main() {
break
fi
newArg=$(echo "$arg" | sed -e 's/-/_/g;s/ /_/g')
cmd=$(echo "$cmd" | sed "s|<${arg}>|<${newArg}>|g")
arg=$newArg
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

View File

@ -30,6 +30,8 @@ opts::eval() {
widget) entry_point="widget"; shift; wait_for="widget" ;;
esac
i=0
for arg in "$@"; do
case $wait_for in
path) path="$arg"; wait_for="" ;;
@ -42,11 +44,12 @@ opts::eval() {
case $arg in
--print) print=true ;;
--no-interpolation) interpolation=false ;;
--command-for) wait_for="command-for" ;;
--no-preview) preview=false ;;
--path|--dir) wait_for="path" ;;
--no-autoselect) autoselect=false ;;
esac
i=$((i+1))
done
OPTIONS="$(dict::new \

View File

@ -19,7 +19,7 @@ ui::select() {
local -r cheats="$1"
local -r script_path="${SCRIPT_DIR}/navi"
local -r preview_cmd="echo \'{}\' | tr \"'\" '${ARG_DELIMITER_2}' | tr ' ' '${ARG_DELIMITER}' | xargs -I% \"${script_path}\" preview %"
local -r preview_cmd="echo \'{}\' | tr \"'\" '${ARG_DELIMITER_2}' | tr ' ' '${ARG_DELIMITER}' | tr '\"' '${ARG_DELIMITER_3}' | xargs -I% \"${script_path}\" preview %"
local -r query="$(dict::get "$OPTIONS" query)"
local -r entry_point="$(dict::get "$OPTIONS" entry_point)"

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

@ -86,14 +86,14 @@ dict_get_keys() {
dict::new \
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
| dict::keys \
| test::equals "bar.a\nbar.b\nbaz\nfoo"
| test::equals "$(echo -e "foo\nbar.a\nbar.b\nbaz")"
}
dict_get_values() {
dict::new \
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
| dict::values \
| test::equals "5\n6\n63\n42"
| test::equals "$(echo -e "5\n6\n42\n63")"
}
dict_zipmap() {
@ -107,8 +107,15 @@ dict_update() {
| test::map_equals "foo" 42 "bar" 6
}
dict_merge() {
dict::new "foo" 42 "bar" 5 \
| dict::merge "$(dict::new "bar" 7 "lorem" "ipsum")" \
| test::map_equals "foo" 42
}
test::set_suite "dict"
test::run "We can assoc a value" dict_assoc
test::skip "We can merge dicts" dict_merge
test::run "We can assoc values with %" dict_assoc_perc
test::run "We can assoc multiple values" dict_assoc_multiple
test::skip "We can assoc a nested value" dict_assoc_nested
@ -118,7 +125,7 @@ test::run "Dissocing a key will replace all its subvalues" dict_dissoc_nested
test::run "We can get a value" dict_get
test::run "We can get a nested value" dict_get_nested
test::run "We can get a dictionary" dict_get_dict
test::skip "We can get all keys" dict_get_keys
test::run "We can get all keys" dict_get_keys
test::skip "We can get all values" dict_get_values
test::skip "We can get create a dict from a zipmap" dict_zipmap
test::skip "We can update a value" dict_update

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"