Comments (3)
Never mind. It's only for the few default snippets which are not read from any file. So, closing.
A more annoying issue is the fact that the editor specified in $VISUAL
is started in a broken way, when we press ctrl-o
after navi has been called from a command substitution:
$ bash --norc --noprofile
$ echo $(navi --path=$HOME/.local/share/navi/)
# press: C-o
I need --path=$HOME/.local/share/navi/
because that's where I put my navi files.
It's broken because the editor's UI is never drawn, and the latter seems stuck, which is very confusing when $VISUAL
is nano(1)
(less confusing with Vim, which at least prints some message "Vim: Warning: Output is not to a terminal"). To kill the editor, we need to press ctrl-c
.
For now, as a workaround, I remove the ctrl-o
key from the fzf option --expect
in the navi YAML config file:
overrides: >-
--no-expect
--expect ctrl-y,enter
Note that we need to specify --no-expect
before resetting the option, because:
If --expect option is specified multiple times, fzf will expect the union of
the keys. --no-expect will clear the list.
Source: fzf man page.
from navi.
For now, as a workaround, I remove the
ctrl-o
key from the fzf option--expect
in the navi YAML config file
Better way: leave --expect
alone, but reconnect the stdout of navi to the terminal:
$ echo $(navi --path=$HOME/.local/share/navi/ --print >$(tty))
^-----^
This example might look contrived, but it's a simplification of this fish code:
bind \cg\cg shell-snippets
function shell-snippets
set -f current_process $(commandline --current-process)
set -f leading_whitespace $(string match --regex -- '^\s*' $current_process)
set -f current_process $(string trim -- $current_process)
if test -z "$current_process"
# `--print` makes navi print the chosen snippet to stdout, instead of executing it.{{{
#
# This lets us insert the snippet on the command-line, using
# `commandline --insert` and a command substitution.
#}}}
# `>$(tty)`: for `C-o` to work as expected.{{{
#
# Without, the editor specified in $VISUAL is started in a broken way,
# when we press `C-o`. MRE:
#
# $ bash --norc --noprofile
# $ echo $(navi --path=$HOME/.local/share/navi/)
# # press: C-o
#
# It's broken because the editor's UI is never drawn, and the latter
# seems stuck, until we kill it by pressing `C-c`.
#}}}
commandline --insert -- $(navi --path=$HOME/.local/share/navi/ --print >$(tty))
commandline --function repaint
return
end
set -f snippet $(navi $options --query="$current_process")
commandline --replace --current-process "$(string join -- '' $leading_whitespace $snippet)"
commandline --function repaint
end
from navi.
Better way: leave
--expect
alone, but reconnect the stdout of navi to the terminal:
Actually, that's a bad idea. While it fixed C-o
, it also breaks Enter
.
So, I ended up removing ctrl-o
from --expect
, as explained before, and installing a M-e
key binding which correctly handles the case where navi is started from a command substitution:
finder:
command: fzf
# https://github.com/denisidoro/navi/blob/master/docs/customization.md#overriding-fzf-options
# `--no-expect`, `--expect ctrl-y,enter`{{{
#
# Problem: Pressing `C-o` might start `$VISUAL` in a broken way.
# Solution: Make navi ignore `C-o`.
#
# By default, navi sets `--expect` to `ctrl-y,ctrl-o,enter`:
#
# $ cd <navi source code>
# $ rg ctrl-o
# src/finder/mod.rs:106:51: command.args(["--expect", "ctrl-y,ctrl-o,enter"]);
# ^----^
#
# The purpose is to make navi starts `$VISUAL` to edit the file containing the
# definition of the currently selected snippet. However, it doesn't work as
# expected when navi is started from a command substitution:
#
# Vim: Warning: Output is not to a terminal
#
# The editor is stuck, and never draws its TUI (`C-c` needs to be pressed).
#
# To avoid this, we remove `C-o` from `--expect`. But before resetting the
# option, we first need to clear it; hence `--no-expect`:
#
# > If --expect option is specified multiple times, fzf will expect the union of
# > the keys. --no-expect will clear the list.
#
# MRE:
#
# $ bash --norc --noprofile
# $ echo $(navi --path=$HOME/.local/share/navi/)
# # press: C-o (make sure to select a snippet which comes a file; a few hard-coded and navi-related don't)
#
# ---
#
# Besides, we often press `C-o` by accident while navi is running; e.g.:
#
# start navi
# v-----v
# C-g C-g C-o
# ^^^
# accident
#
# Instead of:
#
# C-g C-o
# ^-----^
# run fish omni-TUI function
#
# When that happens, it's better for navi not to react.
#}}}
# `--bind='alt-e:execute(editor ...)'`{{{
#
# Problem: We can't edit the file containing the currently selected snippet.
# Solution: Install a (new) key binding.
#
# Contrary to `C-o`, it correctly handles the case where navi has been started
# from a command substitution, because we reconnect the editor's stdout to the
# terminal:
#
# --bind='alt-e:execute(editor ... >"$(tty)")'
# ^-------^
#}}}
overrides: >-
--no-expect
--expect ctrl-y,enter
--bind='alt-e:execute(editor "$HOME/.local/share/navi/$(sed --quiet "s/\([-_a-zA-Z0-9]\+\).*/\1/p" <<<{})".cheat >"$(tty)")'
# `>-` is a syntax which lets us split a long string on multiple lines.{{{
#
# It's called “Line Folding”: https://yaml.org/spec/1.2.2/#65-line-folding
#}}}
For anyone reading this: if your cheat files are in the default location, you might need to replace $HOME/.local/share/navi/
with $(navi info cheats-path)
.
from navi.
Related Issues (20)
- Basic curl cheatsheet doesn't work on zsh due to quoting issues HOT 2
- Respect FZF fg colors or disable text coloring entirely HOT 1
- Clearer information about the `.cheat` files and `navi` config paths HOT 1
- `navi info cheats-path` ignores `$NAVI_PATH` and `$NAVI_CONFIG` HOT 2
- Non-Interactive Cheatsheet Install HOT 6
- Any way to have snippets on the left rather than on the right? HOT 2
- Security concern about Windows binary (v2.23.0) HOT 2
- Enable the use of Bash on Windows for both Navi and fzf HOT 1
- Sort by recency of usage or priority HOT 1
- Unexpected output from zsh widget with input HOT 1
- zsh widget results vary with terminal width
- command not found trying to execute navi on windows HOT 1
- Add another topic for the repo `cheatsheet` HOT 1
- searching doesn't work for descriptions longer than terminal size
- Provide Statically Compiled Binaries for (aarch64|arm64) Linux HOT 1
- Using https://devhints.io/ as a backend HOT 1
- ":/Scoop/apps/gow/current/bin/bash.exe": E:Scoopappsnavi2.23.0navi.exe: command not found HOT 1
- Unable to execute some custom commands HOT 1
- Add optional arguments HOT 1
- Optional placeholder value for variable HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from navi.