-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbolt.sh
executable file
·118 lines (108 loc) · 3.1 KB
/
bolt.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
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
#!/usr/bin/env sh
#
# Prompts you for keywords to your local files, directories or Google search and launches them respectively.
# Dependencies: grep, sed, find, awk, file, xargs
MAXDEPTH=6
SEARCHLIST=/tmp/searchlist
#========================================================
# Modify this section according to your preference
#========================================================
launch() {
case $(file --mime-type "$1" -bL) in
#====================================================
# Find out the mimetype of the file you wannna launch
#====================================================
video/*)
#================================================
# Launch using your favorite programs
#================================================
mpv "$1"
;;
#================================================
# So on and so forth
#================================================
application/pdf | application/epub+zip)
zathura "$1"
;;
text/* | inode/x-empty | application/json | application/octet-stream)
"$TERMINAL" "$EDITOR" "$1"
# st "$EDITOR" "$*"
;;
inode/directory)
"$TERMINAL" "$EXPLORER" "$*"
# st lf "$*"
;;
esac
}
search_n_launch() {
RESULT=$(grep "$1" "$SEARCHLIST" | head -1)
if [ -n "$RESULT" ]; then
launch "$RESULT"
else
"$BROWSER" google.com/search\?q="$1"
fi
}
get_config() {
while IFS= read -r line; do
case $line in
[[:alnum:]]* | /*) echo "$line" ;;
esac
done < "$1"
}
dmenu_search() {
QUERY=$(awk -F / '{print $(NF-1)"/"$NF}' "$SEARCHLIST" | "$1") &&
search_n_launch "$QUERY"
}
tmux_search() {
if pidof tmux; then
tmux new-window
else
tmux new-session -d \; switch-client
fi
if pidof "$TERMINAL"; then
[ "$(pidof "$TERMINAL")" != "$(xdo pid)" ] &&
xdo activate -N Alacritty
else
"$TERMINAL" -e tmux attach &
fi
tmux send "$0 --fzf-search" "Enter"
}
fzf_search() {
QUERY=$(awk -F / '{print $(NF-1)"/"$NF}' "$SEARCHLIST" |
fzf -e -i \
--reverse \
--border \
--margin 15%,25% \
--info hidden \
--bind=tab:down,btab:up \
--prompt "launch ") &&
search_n_launch "$QUERY"
}
watch() {
grep -v "^#" ~/.config/bolt/paths |
xargs inotifywait -m -r -e create,delete,move |
while read -r line; do
generate
done &
}
generate() {
FILTERS=$(get_config ~/.config/bolt/filters | awk '{printf "%s\\|",$0;}' | sed -e 's/|\./|\\./g' -e 's/\\|$//g')
get_config ~/.config/bolt/paths |
xargs -I% find % -maxdepth $MAXDEPTH \
! -regex ".*\($FILTERS\).*" > "$SEARCHLIST"
}
while :; do
case $1 in
--generate) generate ;;
--tmux-search) tmux_search ;;
--fzf-search) fzf_search ;;
--launch) launch "$2" ;;
--rofi-search)
dmenu_search "rofi -sort true -sorting-method fzf -dmenu -i -p Open)"
;;
--dmenu-search) dmenu_search "dmenu -i" ;;
--watch) watch ;;
*) break ;;
esac
shift
done