about summary refs log blame commit diff stats
path: root/bin/opener
blob: 4ae34464768b63716ade38cad264c48b3edaef27 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                                
                                                                  

                
                                                            




                                                       
                                                    

               
                                                             




                                                                                                                                                 
#!/bin/sh
# opener: opens files according to its contents
# takes one path as its argument, launches the appropriate program for it
if ! [ -f "$1" ]; then
	printf 'file %s does not exist!\n' "$1" >/dev/stderr
	return 1
fi
FILEPATH="$1"
FILEMIME="$(file -ib "$FILEPATH")"
echo() {
	printf '%s\n' "$*"
}
case "$FILEMIME" in
	#ebooks
	application/epub*|application/pdf|application/postscript|image/vnd.djvu)
		${READER:-zathura} "$FILEPATH">/dev/null 2>&1 & ;;
	#videos
	video/*)
		mpv --quiet "$FILEPATH" >/dev/null 2>&1 & ;;
	#images
	image/*)
		sxiv -a "$FILEPATH">/dev/null 2>&1 & ;;
	#audio
	audio/*)
		mpv "$FILEPATH" >/dev/null 2>&1 & ;;
	#text
	text/*)
		${EDITOR:-vi} "$FILEPATH">/dev/null 2>&1 & ;;
	#catchall
	*)
		echo "file $(basename "$FILEPATH") could not be opened. its type is $FILEMIME, go tell ensa that opener didn't work" >/dev/stderr
		return 1 ;;
esac