Skip to content

Commit

Permalink
Merge pull request denisidoro#374 from wardwouts/filter_current_comma…
Browse files Browse the repository at this point in the history
…ndline_bash

similar command line filter as for zsh
  • Loading branch information
denisidoro authored Aug 13, 2020
2 parents ca1ff03 + 4b41945 commit 13a3b9d
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions shell/navi.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
#!/usr/bin/env bash

__call_navi() {
local -r result="$(navi --print)"
local -r linecount="$(echo "$result" | wc -l)"
_call_navi() {
local selected

if [[ "$linecount" -lt 2 ]]; then
printf "%s" "$result"
return 0
fi

IFS=$'\n'
local i=1;
for line in $result; do
if echo "$line" | grep -q '\\$'; then
printf "${line::-1} "
elif [[ "$i" -eq "$linecount" ]]; then
printf "$line "
else
printf "${line}; "
if [ -n "${READLINE_LINE}" ]; then
if selected="$(printf "%s" "$(navi --print --no-autoselect query "${READLINE_LINE}" </dev/tty)")"; then
READLINE_LINE="$selected"
READLINE_POINT=${#READLINE_LINE}
fi
i=$((i+1))
done
else
if selected="$(printf "%s" "$(navi --print </dev/tty)")"; then
READLINE_LINE="$selected"
READLINE_POINT=${#READLINE_LINE}
fi
fi
}

bind '"\C-g": " \C-b\C-k \C-u`__call_navi`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
bind -x '"\C-g": _call_navi'

0 comments on commit 13a3b9d

Please sign in to comment.