mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 11:33:10 +00:00
parent
d55b5725d4
commit
2aa07c2ce1
8 changed files with 36 additions and 14 deletions
|
@ -19,4 +19,8 @@ netstat -tn 2>/dev/null \
|
||||||
dig +short myip.opendns.com @resolver1.opendns.com
|
dig +short myip.opendns.com @resolver1.opendns.com
|
||||||
|
|
||||||
# Find primary, local IP address
|
# 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
2
navi
|
@ -35,7 +35,7 @@ source "${SCRIPT_DIR}/src/main.sh"
|
||||||
##? full docs
|
##? full docs
|
||||||
##? Please refer to the README at https://github.com/denisidoro/navi
|
##? Please refer to the README at https://github.com/denisidoro/navi
|
||||||
|
|
||||||
VERSION="0.10.1"
|
VERSION="0.10.2"
|
||||||
NAVI_ENV="${NAVI_ENV:-prod}"
|
NAVI_ENV="${NAVI_ENV:-prod}"
|
||||||
|
|
||||||
opts::eval "$@"
|
opts::eval "$@"
|
||||||
|
|
|
@ -2,7 +2,7 @@ _call_navi() {
|
||||||
local buff="$BUFFER"
|
local buff="$BUFFER"
|
||||||
zle kill-whole-line
|
zle kill-whole-line
|
||||||
local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true navi --print <> /dev/tty)"
|
local cmd="$(NAVI_USE_FZF_ALL_INPUTS=true navi --print <> /dev/tty)"
|
||||||
zle -U "$buff$(echo "$cmd")"
|
zle -U "${buff}${cmd}"
|
||||||
# zle accept-line
|
# zle accept-line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
ARG_REGEX="<[0-9a-zA-Z_]+>"
|
ARG_REGEX="<[0-9a-zA-Z_]+>"
|
||||||
ARG_DELIMITER="\f"
|
ARG_DELIMITER="\f"
|
||||||
ARG_DELIMITER_2="\v"
|
ARG_DELIMITER_2="\v"
|
||||||
|
ARG_DELIMITER_3="\r"
|
||||||
|
|
||||||
arg::dict() {
|
arg::dict() {
|
||||||
local -r input="$(cat | sed 's/\\n/\\f/g')"
|
local -r input="$(cat | sed 's/\\n/\\f/g')"
|
||||||
|
@ -30,7 +31,7 @@ arg::next() {
|
||||||
arg::deserialize() {
|
arg::deserialize() {
|
||||||
local arg="$1"
|
local arg="$1"
|
||||||
arg="${arg:1:${#arg}-2}"
|
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
|
# TODO: separation of concerns
|
||||||
|
@ -61,7 +62,7 @@ arg::pick() {
|
||||||
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
|
echo "$suggestions" | ui::pick --prompt "$arg: " --header-lines "${headers:-0}" | str::column "${column:-}"
|
||||||
fi
|
fi
|
||||||
elif ${NAVI_USE_FZF_ALL_INPUTS:-false}; then
|
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
|
else
|
||||||
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
|
printf "\033[0;36m${arg}:\033[0;0m " > /dev/tty
|
||||||
read -r value
|
read -r value
|
||||||
|
|
13
src/dict.sh
13
src/dict.sh
|
@ -13,7 +13,7 @@ dict::new() {
|
||||||
if [ $# = 0 ]; then
|
if [ $# = 0 ]; then
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
echo "" | dict::assoc "$@"
|
echo "" | dict::assoc "$@" | sed '/^$/d'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +72,18 @@ dict::get() {
|
||||||
}
|
}
|
||||||
|
|
||||||
dict::keys() {
|
dict::keys() {
|
||||||
grep -Eo '^[^:]+: ' | sed 's/: //g'
|
grep -Eo '^[^:]+: ' \
|
||||||
|
| sed 's/: //g'
|
||||||
}
|
}
|
||||||
|
|
||||||
dict::values() {
|
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() {
|
dict::zipmap() {
|
||||||
|
|
|
@ -30,6 +30,8 @@ opts::eval() {
|
||||||
widget) entry_point="widget"; shift; wait_for="widget" ;;
|
widget) entry_point="widget"; shift; wait_for="widget" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
i=0
|
||||||
|
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case $wait_for in
|
case $wait_for in
|
||||||
path) path="$arg"; wait_for="" ;;
|
path) path="$arg"; wait_for="" ;;
|
||||||
|
@ -42,11 +44,12 @@ opts::eval() {
|
||||||
case $arg in
|
case $arg in
|
||||||
--print) print=true ;;
|
--print) print=true ;;
|
||||||
--no-interpolation) interpolation=false ;;
|
--no-interpolation) interpolation=false ;;
|
||||||
--command-for) wait_for="command-for" ;;
|
|
||||||
--no-preview) preview=false ;;
|
--no-preview) preview=false ;;
|
||||||
--path|--dir) wait_for="path" ;;
|
--path|--dir) wait_for="path" ;;
|
||||||
--no-autoselect) autoselect=false ;;
|
--no-autoselect) autoselect=false ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
OPTIONS="$(dict::new \
|
OPTIONS="$(dict::new \
|
||||||
|
|
|
@ -19,7 +19,7 @@ ui::select() {
|
||||||
local -r cheats="$1"
|
local -r cheats="$1"
|
||||||
|
|
||||||
local -r script_path="${SCRIPT_DIR}/navi"
|
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 query="$(dict::get "$OPTIONS" query)"
|
||||||
local -r entry_point="$(dict::get "$OPTIONS" entry_point)"
|
local -r entry_point="$(dict::get "$OPTIONS" entry_point)"
|
||||||
|
|
|
@ -86,14 +86,14 @@ dict_get_keys() {
|
||||||
dict::new \
|
dict::new \
|
||||||
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
|
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
|
||||||
| dict::keys \
|
| dict::keys \
|
||||||
| test::equals "bar.a\nbar.b\nbaz\nfoo"
|
| test::equals "$(echo -e "foo\nbar.a\nbar.b\nbaz")"
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_get_values() {
|
dict_get_values() {
|
||||||
dict::new \
|
dict::new \
|
||||||
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
|
| dict::assoc "foo" "42" "bar.a" 5 "bar.b" 6 "baz" 63 \
|
||||||
| dict::values \
|
| dict::values \
|
||||||
| test::equals "5\n6\n63\n42"
|
| test::equals "$(echo -e "5\n6\n42\n63")"
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_zipmap() {
|
dict_zipmap() {
|
||||||
|
@ -107,8 +107,15 @@ dict_update() {
|
||||||
| test::map_equals "foo" 42 "bar" 6
|
| 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::set_suite "dict"
|
||||||
test::run "We can assoc a value" dict_assoc
|
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 values with %" dict_assoc_perc
|
||||||
test::run "We can assoc multiple values" dict_assoc_multiple
|
test::run "We can assoc multiple values" dict_assoc_multiple
|
||||||
test::skip "We can assoc a nested value" dict_assoc_nested
|
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 value" dict_get
|
||||||
test::run "We can get a nested value" dict_get_nested
|
test::run "We can get a nested value" dict_get_nested
|
||||||
test::run "We can get a dictionary" dict_get_dict
|
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 all values" dict_get_values
|
||||||
test::skip "We can get create a dict from a zipmap" dict_zipmap
|
test::skip "We can get create a dict from a zipmap" dict_zipmap
|
||||||
test::skip "We can update a value" dict_update
|
test::skip "We can update a value" dict_update
|
||||||
|
|
Loading…
Reference in a new issue