mirror of
https://github.com/denisidoro/navi
synced 2024-11-21 19:13:07 +00:00
commit
b556808b06
1 changed files with 21 additions and 42 deletions
|
@ -1,50 +1,29 @@
|
||||||
function __call_navi
|
function _navi_smart_replace
|
||||||
navi --print
|
set -l current_process (commandline -p | string trim)
|
||||||
end
|
|
||||||
|
|
||||||
function navi-widget -d "Show cheat sheets"
|
if test -z "$current_process"
|
||||||
begin
|
commandline -i (navi --print)
|
||||||
set ttysettings (stty -g)
|
else
|
||||||
stty sane
|
set -l best_match (navi --print --best-match --query "$current_process")
|
||||||
__call_navi | perl -pe 'chomp if eof' | read -lz result
|
|
||||||
and commandline -- $result
|
|
||||||
|
|
||||||
stty $ttysettings
|
if not test "$best_match" >/dev/null
|
||||||
end
|
return
|
||||||
commandline -f repaint
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# set -g navi_last_cmd ""
|
if test -z "$best_match"
|
||||||
|
commandline -p (navi --print --query "$current_process")
|
||||||
|
else if test "$current_process" != "$best_match"
|
||||||
|
commandline -p $best_match
|
||||||
|
else
|
||||||
|
commandline -p (navi --print --query "$current_process")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function smart_replace
|
|
||||||
set -l current_process (commandline -p)
|
|
||||||
|
|
||||||
if [ $current_process = "" ]
|
|
||||||
commandline -p (navi --print)
|
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
else
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
bind \cg smart_replace
|
if test $fish_key_bindings = fish_default_key_bindings
|
||||||
if bind -M insert > /dev/null 2>&1
|
bind \cg _navi_smart_replace
|
||||||
bind -M insert \cg smart_replace
|
else
|
||||||
|
bind -M insert \cg _navi_smart_replace
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue