blob: b6931a18a238153d18d4640e3d1eac03fa9786c0 (
plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
#!/bin/sh
# Copywrong © 2023 Ratakor. Under ISC License.
# plumber 🪠
# dependencies:
# - default programs
# - xdo
# - xclip or xsel
# - (optional) herbe and dmenusearch web
# - (optional) dmenu_path
# - (optional) st with plumber patch
# shellcheck disable=SC2086
# default programs
WEB="xdg-open"
TEXT="$TERMINAL -e $EDITOR"
VIDEO="mpv --ytdl-format=22 --loop"
AUDIO="music --shuffle"
PIC="nsxiv -a"
DOC="zathura"
DIR="$TERMINAL -e lfub"
openlink() {
case "$1" in
*.mkv|*.webm|*.mp4|*.mov|*youtube.com/watch*|*youtube.com/playlist*|\
*youtube.com/shorts*|*youtu.be*|*inv*/playlist*|*inv*/watch*)
setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
*.mp3|*.flac|*.opus|*mp3?source*|*.ogg|*.wav|*soundcloud.com*)
setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
*.png|*.jpg|*.jpeg|*.gif|*.webp)
file=$(printf '%s' "$1" | sed "s/.*\///;s/%20/ /g")
curl -sL "$1" > "/tmp/$file" &&
$PIC "/tmp/$file" >/dev/null 2>&1 & ;;
*.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
file=$(printf '%s' "$1" | sed "s/.*\///;s/%20/ /g")
curl -sL "$1" > "/tmp/$file" &&
$DOC "/tmp/$file" >/dev/null 2>&1 & ;;
*wp.com/stonetoss.com*)
file=$(printf '%s' "${1%"?resize=150%2C150&ssl=1"}" |\
sed "s/.*\///;s/%20/ /g")
curl -sL "${1%"?resize=150%2C150&ssl=1"}" > "/tmp/$file" &&
$PIC "/tmp/$file" >/dev/null 2>&1 & ;;
git://*|git@*|*.git)
"$TERMINAL" -e git clone "$1" ;;
*)
setsid -f $WEB "$1" >/dev/null 2>&1 ;;
esac
}
openfile() {
if [ -d "$1" ]; then
setsid -f $DIR "$1" >/dev/null 2>&1
return
fi
if [ ! -f "$1" ]; then
printf '\033[31mError:\033[m %s is not a valid file\n' "$1" >&2
return 1
fi
case "$1" in
*.mkv|*.webm|*.mp4|*.mov)
setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
*.mp3|*.flac|*.opus|*.ogg|*.wav)
setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
*.png|*.jpg|*.jpeg|*.gif|*.webp)
setsid -f $PIC "$1" >/dev/null 2>&1 ;;
*.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
setsid -f $DOC "$1" >/dev/null 2>&1 ;;
*)
setsid -f $TEXT "$1" >/dev/null 2>&1 ;;
esac
}
checksel() {
case "$1" in
http://*|https://*|irc://*|ircs://*|git://*|git@*)
openlink "$1" ;;
/*)
opensel "$1" "$1" ;;
*)
pid=$(pstree -lpA "$(xdo pid)" | tail -n 1 |\
awk -F '---' '{print $NF}' | sed -re 's/[^0-9]//g')
opensel "$(readlink "/proc/$pid/cwd")/$1" "$1" ;;
esac
}
opensel() {
if [ -d "$1" ]; then
case $1 in
"$XDG_MUSIC_DIR"/*)
setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
*)
xdo kill
$TERMINAL -e sh -c "cd $1; $SHELL" ;;
esac
return
fi
if [ ! -f "$1" ]; then
progname=${2%\ *}
for prog in $(dmenu_path); do
case $prog in
"$progname")
$TERMINAL -e sh -c\
"cd ${1%"$2"}; echo \$ $2; $2; $SHELL"
return ;;
esac
done
herbe "Do you want to search for '$2' ?" && dmenusearch web "$2"
return
fi
case "$1" in
*.mkv|*.webm|*.mp4|*.mov)
setsid -f $VIDEO "$1" >/dev/null 2>&1 ;;
*.mp3|*.flac|*.opus|*.ogg|*.wav)
setsid -f $AUDIO "$1" >/dev/null 2>&1 ;;
*.png|*.jpg|*.jpeg|*.gif|*.webp)
setsid -f $PIC "$1" >/dev/null 2>&1 ;;
*.pdf|*.ps|*.cbz|*.cbr|*.djvu|*.epub)
setsid -f $DOC "$1" >/dev/null 2>&1 ;;
*)
pid=$(xdo pid)
xdo hide -p "$pid"
$TEXT "$1" >/dev/null 2>&1
xdo show -p "$pid" ;;
esac
}
usage() {
cat << EOF >&2
Usage: ${0##*/} [options] [arg]
Options:
no option [arg] | Try to guess what to do
-l|--link [link] | Open the link
-f|--file [file] | Open the file or the folder
-s|--sel | Use the selection buffer instead, Plan9's way
-t|--term | To be used only when invoking through a patched st
-h|--help │ Print this help message
Config:
browser = $WEB
editor = $TEXT
video = $VIDEO
audio = $AUDIO
picture = $PIC
document = $DOC
file manager = $DIR
EOF
}
main() {
case "$1" in
-l|--link)
if [ -z "$2" ]; then
printf '\033[31mError:\033[m no argument given\n' >&2
usage
return 1
fi
openlink "$2" ;;
-f|--file)
if [ -z "$2" ]; then
printf '\033[31mError:\033[m no argument given\n' >&2
usage
return 1
fi
openfile "$2" ;;
-s|--sel|'')
sel=$(xclip -o -sel 2>/dev/null || xsel -opn 2>/dev/null)
sel=${sel#"${sel%%[![:space:]]*}"}
# clear clipboard
true | xclip 2>/dev/null || true | xsel 2>/dev/null
if [ -z "$sel" ]; then
printf '\033[31mError:\033[m selection buffer is empty\n' >&2
usage
return 1
fi
checksel "$sel" ;;
-t|--term)
#if [ "$(ps -o comm= $PPID)" != "st" ]; then
# printf '\033[31mError:\033[m --term option used outside of st\n' >&2
# usage
# return 1
#fi
[ -n "$2" ] && checksel "$2" ;;
-h|--help)
usage
return 0 ;;
-*)
printf '\033[31mError:\033[m unknown option\n' >&2
usage
return 1 ;;
*)
case "$1" in
http://*|https://*|git://*|irc://*|ircs://*)
openlink "$1" ;;
*)
openfile "$1" ;;
esac
esac
}
main "$@"
|