A simple bash script designed for use with fzf
preview but maybe useful in other ways?
fzf --preview fzf--previewer
Instead of showing the usual directory error or binary file warning with the fancy bat
preview in fzf
this script conditionally checks the selected file and previews a tree, a highlighted text, or a hex viewer.
This uses the programs:
bat
, for text file viewingtree
, for graphical dir listingshexyl
, for binary file viewingatool
, for view archive file contentpdftotext
(poppler-utils), for PDF previewodt2txt
, simple converter from OpenDocument Textcatdoc
anddocx2txt
, for M$-Office preview- kitty
icat
orascii-image-converter
for images
On Debian/Devuan based systems you can install them like so:
sudo apt update; sudo apt install -y bat tree hexyl atool poppler-utils odt2txt catdoc kitty
Similarly, I use this with fzf
(fuzzy finder), which you will need to follow the usage example.
sudo apt update; sudo apt install -y fzf
I noticed hexyl
is sometimes problematic to install from apt, here is a workaround to install from source.
sudo apt install build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
cargo install hexyl
Similarly bat
doesn't seem to consistently install on Ubuntu/Debian, but you can install the Rust toolchain as per the previous hexyl
workaround and:
cargo install bat
I like to symlink this in ~/.local/bin
as opener
. So checkout the repo, then:
ln -s $HOME/opener/opener.bash $HOME/.local/bin/opener
Then you can add this alias to make fzf
much more useful in file system discovery..
alias fz="find . -maxdepth 1 | sed 's/^\.\///g' | fzf --preview 'opener {}'"
With the alias, running fz
will give a searchable directory listing with a
preview for every filetype. You should be able to use the up and down arrow
keys to navigate or just start typing and the fuzzy search will narrow down
what you want to find. The preview is scrollable on some systems. Hitting
[ENTER]
will output the filename of the current selection. Hitting
[ESCAPE]
will exit the curses
session.
NOTE: I've only tested this on Linux, but it might work elsewhere.