Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add “smart replace” functionality to the fish shell widget #655

Merged
merged 8 commits into from
Dec 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions shell/navi.plugin.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env fish

function __call_navi
navi --print
end
Expand All @@ -16,7 +14,37 @@ function navi-widget -d "Show cheat sheets"
commandline -f repaint
end

bind \cg navi-widget
# 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
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

bind \cg smart_replace
if bind -M insert > /dev/null 2>&1
bind -M insert \cg navi-widget
bind -M insert \cg smart_replace
end