navi/shell/navi.plugin.fish

51 lines
1.1 KiB
Fish
Raw Normal View History

2020-03-05 00:01:23 +03:00
function __call_navi
2020-03-08 00:03:51 +03:00
navi --print
2020-03-05 00:01:23 +03:00
end
function navi-widget -d "Show cheat sheets"
begin
set ttysettings (stty -g)
2020-03-05 00:01:23 +03:00
stty sane
__call_navi | perl -pe 'chomp if eof' | read -lz result
and commandline -- $result
stty $ttysettings
2020-03-05 00:01:23 +03:00
end
commandline -f repaint
end
2021-12-16 20:43:52 +03:00
# set -g navi_last_cmd ""
2021-12-16 15:21:07 +03:00
function smart_replace
set -l current_process (commandline -p)
2021-12-16 20:43:52 +03:00
if [ $current_process = "" ]
commandline -p (navi --print)
2021-12-16 16:54:09 +03:00
commandline -f repaint
2021-12-16 15:21:07 +03:00
else
2021-12-16 20:43:52 +03:00
set -l best_match (navi --print --best-match --query $current_process)
if not [ $best_match > /dev/null ];
commandline -p $current_process
commandline -f repaint
return
end
2021-12-16 20:43:52 +03:00
if [ $best_match = "" ]
commandline -p (navi --print --query $current_process)
commandline -f repaint
else if [ $current_process != $best_match ]
commandline -p $best_match
commandline -f repaint
else if [ $current_process = $best_match ]
commandline -p (navi --print --query $current_process)
commandline -f repaint
end
2021-12-16 15:21:07 +03:00
end
2021-12-16 15:35:15 +03:00
end
2021-12-16 14:24:21 +03:00
2021-12-16 15:27:13 +03:00
bind \cg smart_replace
2020-03-05 00:01:23 +03:00
if bind -M insert > /dev/null 2>&1
2021-12-16 15:27:13 +03:00
bind -M insert \cg smart_replace
2020-03-05 00:01:23 +03:00
end