Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #96

Merged
merged 6 commits into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Minor fixes
  • Loading branch information
denisidoro committed Sep 29, 2019
commit 5966b30c033e68470283ec7b167ef1afd1cc5a3f
6 changes: 5 additions & 1 deletion cheats/network.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion shell/widget.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions src/arg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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')"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/dict.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dict::new() {
if [ $# = 0 ]; then
echo ""
else
echo "" | dict::assoc "$@"
echo "" | dict::assoc "$@" | sed '/^$/d'
fi
}

Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
5 changes: 4 additions & 1 deletion src/opts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="" ;;
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion src/ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
24 changes: 17 additions & 7 deletions test/dict_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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\n63\n42")"
}

dict_zipmap() {
Expand All @@ -107,18 +107,28 @@ 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
}

dict::new "foo" 42 "bar" 5
return

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
test::run "We can assoc a nested value" dict_assoc_nested
test::run "We can dissoc a value" dict_dissoc
test::run "Associng the same value is a no-op" dict_assoc_again
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::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
test::run "We can get all keys" dict_get_keys
test::run "We can get all values" dict_get_values
test::run "We can get create a dict from a zipmap" dict_zipmap
test::run "We can update a value" dict_update