-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #671 from kidonng/patch-1
Improve fish widget code
- Loading branch information
Showing
1 changed file
with
24 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,29 @@ | ||
function __call_navi | ||
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) | ||
|
||
if [ $current_process = "" ] | ||
commandline -p (navi --print) | ||
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 | ||
function _navi_smart_replace | ||
set -l current_process (commandline -p | string trim) | ||
|
||
if test -z "$current_process" | ||
commandline -i (navi --print) | ||
else | ||
set -l best_match (navi --print --best-match --query "$current_process") | ||
|
||
if not test "$best_match" >/dev/null | ||
return | ||
end | ||
|
||
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 | ||
|
||
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 | ||
commandline -f repaint | ||
end | ||
|
||
bind \cg smart_replace | ||
if bind -M insert > /dev/null 2>&1 | ||
bind -M insert \cg smart_replace | ||
if test $fish_key_bindings = fish_default_key_bindings | ||
bind \cg _navi_smart_replace | ||
else | ||
bind -M insert \cg _navi_smart_replace | ||
end |