Skip to content

Instantly share code, notes, and snippets.

@sathishvj
Last active August 19, 2023 08:19
Show Gist options
  • Save sathishvj/50a3bc1c2db50d890fbaf0a25d378987 to your computer and use it in GitHub Desktop.
Save sathishvj/50a3bc1c2db50d890fbaf0a25d378987 to your computer and use it in GitHub Desktop.
iterm2 multi cat chooses to run regular cat or imgcat based on file extension
# iterm2 has some tools that you can install. imgcat displays images on the command line.
# this command will flexibly choose the specific cat cmd to run based on the extension.
# you can add this to your ~/.profile or whichever other file you've configured for your shell.
# run iterm shell integration for each shell. See utilities here: https://iterm2.com/documentation-utilities.html
source ~/.iterm2_shell_integration.bash
# run different cat cmds based on extension. If img then run imgcat (which is installed with iterm2_shell_integration
function cat() {
fullfile="$1"
filename=$(basename -- "$fullfile")
extension="${filename##*.}"
#filename="${filename%.*}"
#lcextension="$(tr [A-Z] [a-z] <<< $extension)"
lcextension=`tr [A-Z] [a-z] <<< "$extension"`
echo "Lower case extension is:" $lcextension
images=("jpg" "jpeg" "png" "webp" "bmp" "tiff")
if [[ ${images[@]} =~ $lcextension ]]
then
imgcat "$fullfile"
else
/bin/cat "$fullfile"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment