aboutsummaryrefslogtreecommitdiffstats
path: root/nlay
blob: 437dd7e8b0f65321f27a5dabe485f7516565da97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

# #############################################################################
# nlay: a customizable script to play files in different apps by file type
#
# usage: nlay file type
#
# MUST READ:
#
# 1. Feel free to change the default apps to your favourite ones.
#    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.
#
#    The bg setting depends on personal preference and type of app, e.g.,
#    I would start vim (CLI) in the foreground but Sublime Text (GUI) in the
#    background.
#
#    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
#    to stop console based background apps.
#
# 3. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
#    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.
#
# Author: Arun Prakash Jana
# Email: engineerarun@gmail.com
# #############################################################################


# 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


#------------ PLAINTEXT (UNUSED) ------------
if [ "$2" == "text" ]; then
    app=("vim")

    opts=("")

    bg=("")

#----------------- SEARCH -------------------
elif [ "$2" == "search" ]; then
    app=("gnome-search-tool"
         "catfish")

    opts=(""
          "--path")

    bg=(">/dev/null 2>&1 &"
        ">/dev/null 2>&1 &")

#--------------- SCREENSAVER ----------------
elif [ "$2" == "screensaver" ]; then
    app=vlock

    #opts=

    #bg=">/dev/null 2>&1 &"

    type -P $app &>/dev/null &&
    eval $app $opts $bg
    exit 0
fi

#------------------- PLAY -------------------
for index in ${!app[@]}
do
    type -P ${app[$index]} &>/dev/null &&
    eval ${app[$index]} ${opts[$index]} "\"$1\"" ${bg[$index]} &&
    break
done