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

navi fish plugin with ability to edit commandline #123

Merged
merged 1 commit into from
Oct 14, 2019
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
30 changes: 13 additions & 17 deletions navi.plugin.fish
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
function navi-widget -d 'Call navi'
set -q NAVI_USE_FZF_ALL_INPUTS; or set -l NAVI_USE_FZF_ALL_INPUTS "true"
begin
navi --print | while read -l r; set result $result $r; end

if [ -n "$result" ]
echo $result

# Remove last token from commandline.
commandline -t ""
function navi_key_bindings
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you wrapping everything inside this fn?

I tried running source $NAVI_HOME/navi.plugin.fish and it didn't seem to work. Removing this line and the last one makes it work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adapted the script from the fzf fish script. The bindings are enabled by a line in ~/.config/fish/functions/fish_user_key_bindings.fish

function fish_user_key_bindings
  fzf_key_bindings
  navi_key_bindings
end

Otherwise they are always enabled. Not a big deal though, you can also delete the file if you want it disabled.

function navi-widget -d "Show cheat sheet"
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
begin
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✂️ (Actually, is this necessary? Why not let the user decide the defaults given his/her .fishrc?)

Copy link
Contributor Author

@tfriedel tfriedel Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary. I basically left it from the fzf script without thinking deeply if it's necessary. Personally I never used the shortcut to toggle the shorting mode. In the fzf case the idea was probably that you can have different options for different applications of fzf. Now the FZF_TMUX_HEIGHT variable doesn't seem to have an effect anyway. I'm also not sure if navi should support this or not.

stty sane
env NAVI_USE_FZF_ALL_INPUTS=true navi --print query (commandline) | perl -pe 'chomp if eof' | read -lz result
and commandline -- $result
end
commandline -f repaint
end

# commandline -f repaint
end

bind \cg navi-widget

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