mirror of
https://github.com/denisidoro/navi.git
synced 2024-11-09 23:38:08 +03:00
Merge branch 'master' into master
This commit is contained in:
commit
68ba9ed3df
@ -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 "$@"
|
||||||
|
7
scripts/playground
Executable file
7
scripts/playground
Executable 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" "$@"
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
ARG_REGEX="<\w+([- ]?\w+)*>"
|
ARG_REGEX="<[a-zA-Z_]+([- ]?\w+)*>"
|
||||||
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
|
||||||
|
15
src/dict.sh
15
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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ dict::assoc() {
|
|||||||
local -r value="$(echo "${2:-}" | dict::_escape_value)"
|
local -r value="$(echo "${2:-}" | dict::_escape_value)"
|
||||||
|
|
||||||
shift 2
|
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() {
|
dict::get() {
|
||||||
@ -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() {
|
||||||
|
@ -38,9 +38,9 @@ handler::main() {
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
newArg=$(echo "$arg" | sed -e 's/-/_/g;s/ /_/g')
|
escaped_arg="$(echo "$arg" | tr '-' '_' | tr ' ' '_')"
|
||||||
cmd=$(echo "$cmd" | sed "s|<${arg}>|<${newArg}>|g")
|
cmd="$(echo "$cmd" | sed "s|<${arg}>|<${escaped_arg}>|g")"
|
||||||
arg=$newArg
|
arg="$escaped_arg"
|
||||||
|
|
||||||
value="$(arg::pick "$arg" "$cheat" || echo "")"
|
value="$(arg::pick "$arg" "$cheat" || echo "")"
|
||||||
if [ -z "$value" ]; then
|
if [ -z "$value" ]; then
|
||||||
|
@ -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)"
|
||||||
|
@ -6,6 +6,7 @@ source "${SCRIPT_DIR}/src/main.sh"
|
|||||||
source "${SCRIPT_DIR}/test/log.sh"
|
source "${SCRIPT_DIR}/test/log.sh"
|
||||||
|
|
||||||
opts::eval "$@"
|
opts::eval "$@"
|
||||||
|
TEST_DIR="${SCRIPT_DIR}/test"
|
||||||
|
|
||||||
PASSED=0
|
PASSED=0
|
||||||
FAILED=0
|
FAILED=0
|
||||||
|
@ -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
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
# this should be the first test. single and double quotes + newlines
|
# this should be the first test. single and double quotes + newlines
|
||||||
echo <x> <y>
|
echo <x> <y>
|
||||||
|
|
||||||
|
# variable names
|
||||||
|
echo <x> <foo> <foo_bar> <lorem-ipsum> <dolor sit>
|
||||||
|
|
||||||
# use %
|
# use %
|
||||||
coll::new 1 2 3 | xargs -I% echo "hello %"
|
coll::new 1 2 3 | xargs -I% echo "hello %"
|
||||||
|
|
||||||
|
@ -11,7 +11,10 @@ check_all_vars() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path="$NAVI_PATH"
|
||||||
|
NAVI_PATH="${NAVI_PATH}:${TEST_DIR}"
|
||||||
for cheat in $(cheat::find); do
|
for cheat in $(cheat::find); do
|
||||||
test::run "All variables in $(basename $cheat) are valid" \
|
test::run "All variables in $(basename $cheat) are valid" \
|
||||||
'check_all_vars "$cheat"'
|
'check_all_vars "$cheat"'
|
||||||
done
|
done
|
||||||
|
NAVI_PATH="$path"
|
Loading…
Reference in New Issue
Block a user