A simple bash script designed for use with fzf preview but maybe useful in other ways?
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 viewing; tree, for graphical dir listings; hexyl, for binary file viewing.
On Ubuntu based systems you can install them like so:
sudo apt update; sudo apt install -y bat tree hexylSimilarly, I use this with fzf (fuzzy finder), which you will need to follow the usage example.
sudo apt update; sudo apt install -y fzfI 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 hexylSimilarly 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 batI like to symlink this in ~/.local/bin as opener. So checkout the repo, then:
ln -s $HOME/opener/opener.bash $HOME/.local/bin/openerThen 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.