2018-03-14 18:59:29 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-04-23 17:42:54 +00:00
|
|
|
|
|
|
|
# #############################################################################
|
|
|
|
# nlay: a customizable script to play files in different apps by file type
|
|
|
|
#
|
2018-03-14 16:59:59 +00:00
|
|
|
# usage: nlay file/path type/action
|
2017-04-23 17:42:54 +00:00
|
|
|
#
|
|
|
|
# MUST READ:
|
|
|
|
#
|
|
|
|
# 1. Feel free to change the default apps to your favourite ones.
|
2017-06-05 04:54:28 +00:00
|
|
|
# If you change the app for a group you may also need to modify the opts and
|
|
|
|
# bg settings. If bg is set the app is detached and started in the background
|
|
|
|
# in silent mode.
|
2017-04-23 17:42:54 +00:00
|
|
|
#
|
2018-03-11 08:12:49 +00:00
|
|
|
# The bg setting depends on personal preferences and type of utility, e.g., I
|
|
|
|
# would start vi (CLI) in the foreground but Sublime Text (GUI) in background.
|
2017-04-23 17:42:54 +00:00
|
|
|
#
|
|
|
|
# Check (and TOGGLE as you wish) the default bg settings.
|
|
|
|
#
|
|
|
|
# 2. Detached apps are not killed when nnn exits. Use kill(1) or killall(1) to
|
2018-03-11 08:12:49 +00:00
|
|
|
# stop console based background apps.
|
2017-04-23 17:42:54 +00:00
|
|
|
#
|
2017-06-05 18:26:38 +00:00
|
|
|
# 3. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
|
2017-05-14 15:30:46 +00:00
|
|
|
# location other than the default and have an alias with nnn option '-p' to
|
|
|
|
# invoke it. Remember it might break or lack new capabilities added to nlay
|
|
|
|
# in future releases. Check the file diff once in a while.
|
2017-04-23 17:42:54 +00:00
|
|
|
#
|
|
|
|
# Author: Arun Prakash Jana
|
|
|
|
# Email: engineerarun@gmail.com
|
2018-02-24 05:25:35 +00:00
|
|
|
# Homepage: https://github.com/jarun/nnn
|
|
|
|
# Copyright © 2016-2018 Arun Prakash Jana
|
2017-04-23 17:42:54 +00:00
|
|
|
# #############################################################################
|
|
|
|
|
|
|
|
|
|
|
|
# Enable the lines below to handle file by extension
|
|
|
|
# This is provided for using a custom player for specific files
|
|
|
|
# $ext holds the extension
|
|
|
|
<<ENABLE_FILE_TYPE_HANDLING
|
|
|
|
fname=$(basename "$1")
|
|
|
|
if [[ $fname != *"."* ]]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
ext="${fname##*.}"
|
|
|
|
if [ -z "$ext" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# bash 4.0 way to switch to lowercase
|
|
|
|
ext="${ext,,}"
|
|
|
|
|
|
|
|
# handle this extension and exit
|
|
|
|
ENABLE_FILE_TYPE_HANDLING
|
|
|
|
|
|
|
|
|
2017-06-06 14:46:32 +00:00
|
|
|
#------------ PLAINTEXT (UNUSED) ------------
|
2017-06-05 18:26:38 +00:00
|
|
|
if [ "$2" == "text" ]; then
|
2018-03-11 08:12:49 +00:00
|
|
|
app=("vi")
|
2017-04-23 17:42:54 +00:00
|
|
|
|
2017-06-05 04:54:28 +00:00
|
|
|
opts=("")
|
2017-04-23 17:42:54 +00:00
|
|
|
|
2017-06-05 04:54:28 +00:00
|
|
|
bg=("")
|
2017-05-15 14:44:13 +00:00
|
|
|
|
|
|
|
#----------------- SEARCH -------------------
|
2017-06-05 04:54:28 +00:00
|
|
|
elif [ "$2" == "search" ]; then
|
|
|
|
app=("gnome-search-tool"
|
|
|
|
"catfish")
|
2017-05-15 14:44:13 +00:00
|
|
|
|
2017-08-17 03:13:24 +00:00
|
|
|
opts=("--path"
|
2017-06-05 04:54:28 +00:00
|
|
|
"--path")
|
2017-05-15 14:44:13 +00:00
|
|
|
|
2017-06-05 04:54:28 +00:00
|
|
|
bg=(">/dev/null 2>&1 &"
|
|
|
|
">/dev/null 2>&1 &")
|
2017-06-04 18:46:43 +00:00
|
|
|
|
|
|
|
#--------------- SCREENSAVER ----------------
|
2017-06-05 04:54:28 +00:00
|
|
|
elif [ "$2" == "screensaver" ]; then
|
2017-06-04 18:46:43 +00:00
|
|
|
app=vlock
|
2017-06-05 04:54:28 +00:00
|
|
|
|
2017-06-04 18:46:43 +00:00
|
|
|
#opts=
|
|
|
|
|
|
|
|
#bg=">/dev/null 2>&1 &"
|
|
|
|
|
2017-06-05 04:54:28 +00:00
|
|
|
type -P $app &>/dev/null &&
|
2017-06-04 18:46:43 +00:00
|
|
|
eval $app $opts $bg
|
2017-05-15 14:44:13 +00:00
|
|
|
exit 0
|
2018-03-19 00:02:16 +00:00
|
|
|
|
|
|
|
#------------------ SCRIPT ------------------
|
|
|
|
elif [ "$2" == "script" ]; then
|
|
|
|
# add commands or a custom script below
|
|
|
|
|
|
|
|
# echo "my commands or custom script"
|
|
|
|
# sh "path_to_script.sh"
|
|
|
|
$SHELL "$1"
|
|
|
|
|
|
|
|
exit 0
|
2017-05-15 14:44:13 +00:00
|
|
|
fi
|
2017-06-05 04:54:28 +00:00
|
|
|
|
2017-08-17 03:13:24 +00:00
|
|
|
#----------------- RUN APP ------------------
|
2017-06-05 04:54:28 +00:00
|
|
|
for index in ${!app[@]}
|
|
|
|
do
|
|
|
|
type -P ${app[$index]} &>/dev/null &&
|
2017-06-06 16:07:16 +00:00
|
|
|
eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]} &&
|
|
|
|
break
|
2017-06-05 04:54:28 +00:00
|
|
|
done
|