Minor fixes (#96)

- fix widget
- cleanup
- fix dict lib
This commit is contained in:
Denis Isidoro 2019-09-28 23:12:47 -03:00 committed by GitHub
parent d55b5725d4
commit 2aa07c2ce1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 14 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 "$@"

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

@ -3,6 +3,7 @@
ARG_REGEX="<[0-9a-zA-Z_]+>"
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
}
@ -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

@ -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

@ -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