forked from ldelossa/sway-fzfify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.sh
executable file
·58 lines (48 loc) · 1.47 KB
/
launch.sh
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
#!/usr/bin/env bash
# Launch some modules
# Syntaxis: launch [-f <cache file>] {path to modules}
# TODO Error handling
# TODO Argument checking
panic () {
>&2 echo "Launch: Syntaxis: launch [-f <cache file>] {path to modules}"
exit 1
}
list="$HOME/.cache/fzf-jump/cache"
hist="$HOME/.cache/fzf-jump/history"
# Get options
while getopts ":f:" option ; do
case "${option}" in
f)
list="${OPTARG}"
if [[ ! -f "${list}" ]] ; then
>&2 echo "Launch: \"${list}\" does not exist\nMaking file..."
touch "${list}"
fi
if [[ ! -r "${list}" ]] ; then
>&2 echo "Launch: \"${list}\" is not readable"
exit 2
fi
if [[ ! -w "${list}" ]] ; then
>&2 echo "Launch: \"${list}\" is not writable"
fi
;;
*)
panic
;;
esac
done
# Update the cache file in the background
$(dirname ${0})/update.sh $@ &
# Pick something with fzf.
selection=$( cat "${list}" \
| cut -f1 -d';' \
| fzf --history="${hist}" \
--cycle \
--bind "change:reload(cat ${list} | cut -f1 -d';')" \
--border=sharp \
--layout="reverse"
)
selection=$( echo -n "${selection}" )
# Execute the command or start the application in another process.
ex=$(grep "^${selection};.*$" "${list}" | cut --complement -f1 -d';')
setsid --fork $SHELL -c "${ex}" &> /dev/null