denisidoro / navi

An interactive cheatsheet tool for the command-line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create widgets for bash+zsh+fish

denisidoro opened this issue · comments

Hitting Ctrl-G for example could start the script.

When selecting an entry, instead of executing it, it could fill the prompt (similarly to ctrl-r).

This way the history will be kept clean and there will be the possibility to edit the command as you like.

Edit: this is done for zsh, bash and zsh already!
Please refer to README.md.

Widget

Problem: I don't know how to get input from user in a ZSH widget
Workaround: use fzf with --print-query

In case anyone is interested in trying it out (for zsh):

navi_home="$(echo "$(brew --prefix navi 2>/dev/null)/libexec" || echo "/opt/navi")"
source "${navi_home}/shell/widget.zsh"

# hit alt+g

this is cool! I would love to have this for the fish shell.

Looks like this isn't working for navi installed via Linuxbrew:

zshrc:source:176: no such file or directory: /home/linuxbrew/.linuxbrew/navi/shell/widget.zsh
(19-09-26 10:48:13) <0> [~]
u662b1ab6f1175f % which navi
/home/linuxbrew/.linuxbrew/bin/navi

(19-09-26 10:48:15) <0> [~]
u662b1ab6f1175f % brew --prefix
/home/linuxbrew/.linuxbrew

(19-09-26 10:51:02) <0> [~]
u662b1ab6f1175f % brew info navi
denisidoro/tools/navi: stable 0.9.4
An interactive cheatsheet tool for the command-line
https://github.com/denisidoro/navi
/home/linuxbrew/.linuxbrew/Cellar/navi/0.9.4 (43 files, 107.9KB) *
  Built from source on 2019-09-26 at 10:31:23
From: https://github.com/denisidoro/homebrew-tools/blob/master/navi.rb
==> Dependencies
Build: fzf ✔

(19-09-26 10:51:13) <0> [~]
u662b1ab6f1175f %

@adworacz the path in the instructions were wrong. I've just updated it. Could you confirm if it's working now?

I'll do you one better - instead of having the user embed the navi version into their .zshrc, it looks like we can use brew --prefix navi to handle things.

navi_home="$(echo "$(brew --prefix navi 2>/dev/null)" || echo "/opt/navi")"
source "${navi_home}/libexec/shell/widget.zsh"

That just worked for me, using the 0.9.4 version installed via brew install denis.../navi, (not HEAD).

Note that I had to add libexec to the source path, just FYI.

  • zsh: ✅
  • bash: help needed!
  • fish: help needed!

Just want to share this question and this one from stackexchange

The second answer from the first question has an excellent detailed description of how to achieve this in Bash.

I hope this is helpful.

There's an initial version for a fish widget here.

It doesn't allow editing the command before executing it, though.

Could anyone help me?