Posted by Wahaha in Linux

The magic line is:

find . -iname cover*.* | sxiv -fito

The way it works is I have a media collection inside folders and inside every folder there's a file called "cover.*". Maybe jpg, maybe png. Whatever. I'm using find to get all these and input them into sxiv, which then shows me all my media.

It is then possible to mark one with the 'm' button and quit, which leads sxiv to print out that file.

With some more bash...

#!/bin/bash

file=$(find . -iname cover*.* \
	| grep -v -e 'not_interested' -e 'not_working' -e 'boring' \
	| sxiv -fito)

if [[ -z "$file" ]]; then
	#empty
	exit
fi

game_path=$(dirname "$file")
rxvt-unicode -tr -sh 40 -depth 0 -e ranger "$game_path"

...I'll not only ignore some folders (the added grep), but also get the directory name and open a new terminal (rxvt-unicode) with my file-manager (ranger) inside that folder.

I'm using it for my game library, which I've lost track of over the years. But now (and after I added all the covers and changed the structure a little) I can just use this script to get to see the cover of all my games to select one I feel like playing.

And all that in one line of bash plus some extra to make it more comfy.

2

Comments

You must log in or register to comment.

div1337 wrote

Crafting a bash script is very satisfying, especially one liner chained bash command.

2