mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Improve fish widget code
This commit is contained in:
parent
153d081d40
commit
84d4cad405
1 changed files with 7 additions and 27 deletions
|
@ -1,43 +1,25 @@
|
||||||
function __call_navi
|
function _navi_smart_replace
|
||||||
navi --print
|
|
||||||
end
|
|
||||||
|
|
||||||
function navi-widget -d "Show cheat sheets"
|
|
||||||
begin
|
|
||||||
set ttysettings (stty -g)
|
|
||||||
stty sane
|
|
||||||
__call_navi | perl -pe 'chomp if eof' | read -lz result
|
|
||||||
and commandline -- $result
|
|
||||||
|
|
||||||
stty $ttysettings
|
|
||||||
end
|
|
||||||
commandline -f repaint
|
|
||||||
end
|
|
||||||
|
|
||||||
# set -g navi_last_cmd ""
|
|
||||||
|
|
||||||
function smart_replace
|
|
||||||
set -l current_process (commandline -p)
|
set -l current_process (commandline -p)
|
||||||
|
|
||||||
if [ $current_process = "" ]
|
if test $current_process = ""
|
||||||
commandline -p (navi --print)
|
commandline -p (navi --print)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
else
|
else
|
||||||
set -l best_match (navi --print --best-match --query $current_process)
|
set -l best_match (navi --print --best-match --query $current_process)
|
||||||
|
|
||||||
if not [ $best_match > /dev/null ];
|
if not test $best_match > /dev/null
|
||||||
commandline -p $current_process
|
commandline -p $current_process
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if [ $best_match = "" ]
|
if test $best_match = ""
|
||||||
commandline -p (navi --print --query $current_process)
|
commandline -p (navi --print --query $current_process)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
else if [ $current_process != $best_match ]
|
else if test $current_process != $best_match
|
||||||
commandline -p $best_match
|
commandline -p $best_match
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
else if [ $current_process = $best_match ]
|
else
|
||||||
commandline -p (navi --print --query $current_process)
|
commandline -p (navi --print --query $current_process)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
|
@ -45,6 +27,4 @@ function smart_replace
|
||||||
end
|
end
|
||||||
|
|
||||||
bind \cg smart_replace
|
bind \cg smart_replace
|
||||||
if bind -M insert > /dev/null 2>&1
|
|
||||||
bind -M insert \cg smart_replace
|
bind -M insert \cg smart_replace
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in a new issue