navi/shell/navi.plugin.fish

30 lines
801 B
Fish
Raw Normal View History

2022-01-16 18:22:32 +08:00
function _navi_smart_replace
2022-01-16 19:06:57 +08:00
set -l current_process (commandline -p | string trim)
2021-12-16 10:43:52 -07:00
2022-01-16 19:17:28 +08:00
if test -z "$current_process"
2022-01-16 19:06:57 +08:00
commandline -i (navi --print)
else
2022-01-16 19:17:28 +08:00
set -l best_match (navi --print --best-match --query "$current_process")
2022-01-16 19:17:28 +08:00
if not test "$best_match" >/dev/null
2022-01-16 19:06:57 +08:00
return
end
2022-01-16 19:17:28 +08:00
if test -z "$best_match"
2022-01-17 07:54:29 +08:00
commandline -p (navi --print --query "$current_process")
2022-01-16 19:17:28 +08:00
else if test "$current_process" != "$best_match"
2022-01-16 19:06:57 +08:00
commandline -p $best_match
else
2022-01-17 07:54:29 +08:00
commandline -p (navi --print --query "$current_process")
2022-01-16 19:06:57 +08:00
end
2021-12-16 10:43:52 -07:00
end
2022-01-16 19:02:36 +08:00
2022-01-16 19:06:57 +08:00
commandline -f repaint
2021-12-16 05:35:15 -07:00
end
2021-12-16 04:24:21 -07:00
if test $fish_key_bindings = fish_default_key_bindings
2022-01-16 19:06:57 +08:00
bind \cg _navi_smart_replace
else
2022-01-16 19:06:57 +08:00
bind -M insert \cg _navi_smart_replace
end