Close#1102
fzf --preview 'imgcat -W $FZF_PREVIEW_COLUMNS -H $FZF_PREVIEW_LINES {}'
Notes:
* There is no good way to determine the height of the rendered image,
so we assume that the image takes the full height of the preview
window. So the image cannot be displayed with the other text.
* fzf-preview.sh script was updated to use `imgcat` if it's available
but `chafa` is not.
* iTerm2 also supports Sixel, so adding support for this protocol is not
quite necessary but it renders animated GIFs much better (e.g. looping).
So that it can determine if it should subtract 1 from $FZF_PREVIEW_LINES
to avoid scrolling issue of Sixel image that touches the bottom of the
screen.
When a Sixel image touches the bottom of the screen, the whole screen
scrolls up one line to make room for the cursor. Add an ANSI escape
code to compensate for the movement. Unfortunately, the movement of the
screen is sometimes noticeable.
fzf --preview='fzf-preview.sh {}' --preview-window border-left
* Fix regression where previous image is not properly cleared
* Change the way fzf calculates the number of required lines to display
an image (ceil -> floor) to fix the issue where an image is always
rendered as a wireframe.
Progress:
* Sixel image can now be displayed with other text, and is scrollable
* If an image can't be displayed entirely due to the scroll offset, fzf
will render a wireframe to indicate that an image should be displayed
* Renamed $FZF_PREVIEW_{WIDTH,HEIGHT} to $FZF_PREVIEW_PIXEL_{WIDTH,HEIGHT}
for clarity
* Added bin/fzf-preview.sh script to demonstrate how to display an image
using Kitty or Sixel protocol
An example:
ls *.jpg | fzf --preview='seq $((FZF_PREVIEW_LINES*9/10)); fzf-preview.sh {}; seq 100'
A known issue:
* If you reduce the size of the preview window, the image may extend
beyond the preview window
when the preview window is re-enabled and the current preview process is
taking more than 500ms and previewDelayed is triggered
fzf --preview 'sleep 1; date; seq 1000' --bind space:toggle-preview
Just like with the other shells, exit fish to, if called from a non-interactive
shell.
We cannot use `return`, as older versions of fish (namely < 3.4.0) did not
support to use `return` in `.`-scripts (this was only added with fish commit
3359e5d2e9bcbf19d1652636c8e448a6889302ae).
Unlike in POSIX, fish’s `exit` is however documented to no cause the calling
shell to exit when executed in a sourced script (see:
0f70b2c0d3/doc_src/cmds/exit.rst (L20)
)
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
When bash-completion (and thus `_known_hosts_real()`) is / is not available this
will typically not change during the lifetime of a shell.
The only exception is if the user would unset `_known_hosts_real()`, but well,
that would be his problem.
So we can easily define `__fzf_list_hosts()` either using `_known_hosts_real()`
or using the old code, and avoid checking every time whether
`_known_hosts_real()` is defined.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
If defined, use bash-completions’s `_known_hosts_real()`-function to create the
list of hostnames.
This obviously requires bash-completion to be sourced before fzf.
If not defined, fall back to the previous code.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
Just like it’s already done for `_fzf_compgen_path()` and `_fzf_compgen_dir()`
allow a user to easily define his own version of `__fzf_list_hosts()`.
Also add some documentation on the expected “interface” of such custom function.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
`__fzf_list_hosts()` seems like a function a user may want to override with some
custom code.
For that reason it should be kept as simple as possible, that is printing only
hostnames, one per line, optionally in some sorting.
The handling of adding a `username@` (which is then the same for each line), if
any, would unnecessarily complicate that for people who want to override the
function.
Therefore this commit moves that to the places where it's actually used (as of
now only `_fzf_complete_ssh()`).
This also saves any such handling for `_fzf_host_completion()`, where this isn’t
needed at all.
Right now it comes at a cost, namely an extra invocation of `awk` in the
`_fzf_complete_ssh()`-case.
However, it should be easily possible to improve `__fzf_list_hosts()` to no
longer need the final `awk` in the pipeline there.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
This commit causes all simple commands that are not built-ins or functions to be
invoked via `command` in order to protect them from alias substitution or from
accidentally taking functions of the same name.
It was decided to not “protect” `fzf` and `fzf-tmux` for now.
Maybe a better solution should be implemented for that in the future.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
# Scrolling will behave similarly to CTRL-E and CTRL-Y of vim
fzf --bind scroll-up:offset-up,scroll-down:offset-down \
--bind ctrl-y:offset-up,ctrl-e:offset-down \
--scroll-off=5
Close#3456
* [bash] bring fzf’s own bash completion up to date
This orders and groups completed options and values in just as they appear in
the code respectively, for some option values, as they’d be printed in the
`--help`-output.
It does not add support for completion of `:` right after values that support an
optional `:some-further-value` postfix.
Neither does it add support for the `--option=value`-style.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
* [bash] drop unnecessary code in handling `history`
Presumably, the dropped code is not needed for any effect, thus drop it.
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
---------
Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>