mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
parent
425ce80530
commit
a36c26f922
4 changed files with 46 additions and 45 deletions
|
@ -32,5 +32,7 @@ cargo clippy || true
|
|||
_commit
|
||||
log::note "dot code beautify..."
|
||||
find scripts -type f | xargs -I% dot code beautify % || true
|
||||
dot code beautify "${NAVI_HOME}/shell/navi.plugin.bash" || true
|
||||
dot code beautify "${NAVI_HOME}/shell/navi.plugin.zsh" || true
|
||||
dot code beautify "${NAVI_HOME}/tests/core.bash" || true
|
||||
dot code beautify "${NAVI_HOME}/tests/run" || true
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
_navi_call() {
|
||||
local result="$(navi "$@" </dev/tty)"
|
||||
if [ -z "${result}" ]; then
|
||||
result="$(navi --print </dev/tty)"
|
||||
fi
|
||||
printf "%s" "$result"
|
||||
local result="$(navi "$@" </dev/tty)"
|
||||
printf "%s" "$result"
|
||||
}
|
||||
|
||||
_navi_widget() {
|
||||
local -r input="${READLINE_LINE}"
|
||||
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
||||
local -r input="${READLINE_LINE}"
|
||||
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
||||
|
||||
if [ -z "${last_command}" ]; then
|
||||
local -r output="$(FZF_OVERRIDES="${FZF_OVERRIDES:-} --no-select-1" _navi_call --print)"
|
||||
else
|
||||
local -r find="$last_command"
|
||||
local -r replacement="$(_navi_call --print --query "${last_command}")"
|
||||
local -r output="${input//$find/$replacement}"
|
||||
fi
|
||||
if [ -z "${last_command}" ]; then
|
||||
local -r output="$(_navi_call --print)"
|
||||
else
|
||||
local -r find="$last_command"
|
||||
local -r replacement="$(_navi_call --print --query "$last_command")"
|
||||
local output="$input"
|
||||
if [ -n "$replacement" ]; then
|
||||
output="${input//$find/$replacement}"
|
||||
fi
|
||||
fi
|
||||
|
||||
READLINE_LINE="$output"
|
||||
READLINE_POINT=${#READLINE_LINE}
|
||||
READLINE_LINE="$output"
|
||||
READLINE_POINT=${#READLINE_LINE}
|
||||
}
|
||||
|
||||
_navi_widget_legacy() {
|
||||
_navi_call --print
|
||||
_navi_call --print
|
||||
}
|
||||
|
||||
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
|
||||
bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
|
||||
if [ ${BASH_VERSION:0:1} -lt 4 ]; then
|
||||
bind '"\C-g": " \C-b\C-k \C-u`_navi_widget_legacy`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
|
||||
else
|
||||
bind -x '"\C-g": _navi_widget'
|
||||
bind -x '"\C-g": _navi_widget'
|
||||
fi
|
|
@ -1,35 +1,34 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
_navi_call() {
|
||||
local result="$(navi "$@" </dev/tty)"
|
||||
if [ -z "${result}" ]; then
|
||||
result="$(navi --print </dev/tty)"
|
||||
fi
|
||||
printf "%s" "$result"
|
||||
local result="$(navi "$@" </dev/tty)"
|
||||
printf "%s" "$result"
|
||||
}
|
||||
|
||||
_navi_widget() {
|
||||
local -r input="${LBUFFER}"
|
||||
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
||||
local find="$last_command"
|
||||
local replacement="$last_command"
|
||||
local -r input="${LBUFFER}"
|
||||
local -r last_command="$(echo "${input}" | navi fn widget::last_command)"
|
||||
local find="$last_command"
|
||||
local replacement="$last_command"
|
||||
|
||||
if [ -z "${last_command}" ]; then
|
||||
replacement="$(FZF_OVERRIDES="${FZF_OVERRIDES:-} --no-select-1" _navi_call --print)"
|
||||
elif [ "${LASTWIDGET}" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
|
||||
find="$input"
|
||||
replacement="$(_navi_call --print --query "${previous_last_command:-$last_command}")"
|
||||
else
|
||||
replacement="$(_navi_call --print --best-match --query "${last_command}")"
|
||||
fi
|
||||
if [ -z "$last_command" ]; then
|
||||
replacement="$(_navi_call --print)"
|
||||
elif [ "$LASTWIDGET" = "_navi_widget" ] && [ "$input" = "$previous_output" ]; then
|
||||
replacement="$(_navi_call --print --query "$last_command")"
|
||||
else
|
||||
replacement="$(_navi_call --print --best-match --query "$last_command")"
|
||||
fi
|
||||
|
||||
previous_last_command="$last_command"
|
||||
previous_output="${input//$find/$replacement}"
|
||||
if [ -n "$replacement" ]; then
|
||||
previous_output="${input//$find/$replacement}"
|
||||
else
|
||||
previous_output="$input"
|
||||
fi
|
||||
|
||||
zle kill-whole-line
|
||||
LBUFFER="${previous_output}"
|
||||
region_highlight=("P0 100 bold")
|
||||
zle redisplay
|
||||
zle kill-whole-line
|
||||
LBUFFER="${previous_output}"
|
||||
region_highlight=("P0 100 bold")
|
||||
zle redisplay
|
||||
}
|
||||
|
||||
zle -N _navi_widget
|
||||
|
|
|
@ -41,13 +41,13 @@ test::run() {
|
|||
}
|
||||
|
||||
test::_escape() {
|
||||
tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
|
||||
tr '\n' "$NEWLINE_CHAR" | sed -E "s/[\s$(printf "$NEWLINE_CHAR") ]+$//g"
|
||||
}
|
||||
|
||||
test::equals() {
|
||||
local -r actual="$(cat)"
|
||||
local -r expected="$(echo "${1:-}")"
|
||||
|
||||
|
||||
local -r actual2="$(echo "$actual" | test::_escape)"
|
||||
local -r expected2="$(echo "$expected" | test::_escape)"
|
||||
|
||||
|
|
Loading…
Reference in a new issue