From 4877b9a6bb0b2c32a1076a1fefe63290e83fdc0d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Tue, 15 Nov 2022 18:39:25 +0100 Subject: [PATCH] sh: Add timg aliases Added shell aliases for 'image listings' which aims to mimic the `ls` command in a very simple way. Invoke it via `il` to display a grid of all images residing in current directory. Images are being detected not by their extension but by running a `file` operation on, so in very large directories this might take a little (though, your terminal will probably buckle under the weight of displaying thousands of images anyway, so use with care). `IL` provides the same functionality but recurses into an arbitrary amount of subdirectories. Very useful to get an overview of a certain directory and its children but, again, think for a second before using since this could easily spew thousands of pictures into your term. --- sh/.config/sh/alias.d/timg.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 sh/.config/sh/alias.d/timg.sh diff --git a/sh/.config/sh/alias.d/timg.sh b/sh/.config/sh/alias.d/timg.sh new file mode 100644 index 0000000..fb0d7e0 --- /dev/null +++ b/sh/.config/sh/alias.d/timg.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env sh +# Add simple 'image ls' for a directory using timg +# +# Prints a thumbnail gallery right in the terminal. +# WILL stutter when you go crazy in a hundred/thousand +# picture folder. + +if exist timg; then + il() { + images=$(find . -maxdepth 1 -type f -exec file --mime-type {} \+ | awk -F: '{if ($2 ~/image\//) print $1}') + if [ -z "$images" ]; then { + echo no images found. + return + }; fi + echo "$images" | timg --grid=4x3 --upscale=i --center --title --frames=1 -f - + } + IL() { + images=$(find . -type f -exec file --mime-type {} \+ | awk -F: '{if ($2 ~/image\//) print $1}') + if [ -z "$images" ]; then { + echo no images found. + return + }; fi + echo "$images" | timg --grid=4x3 --upscale=i --center --title --frames=1 -f - + } + qr() { + # if we are in a pipe, read from stdin and set fct arguments to it + if [ ! -t 0 ]; then + set -- "$(cat /dev/stdin)" + fi + qrencode -s1 -m2 "$@" -o- | timg --upscale=i - + } +fi