forked from xalexalex/via
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvia-feed
executable file
·43 lines (32 loc) · 976 Bytes
/
via-feed
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
#!/bin/bash
cache_file="$HOME/.cache/via"
via_dir="$HOME/.config/via"
create_missing_files () {
[[ ! -d "${via_dir}" ]] && mkdir "${via_dir}"
[[ ! -f "${via_dir}/shortcuts" ]] && touch "${via_dir}/shortcuts"
[[ ! -f "${via_dir}/websites" ]] && touch "${via_dir}/websites"
[[ ! -f "${cache_file}" ]] && touch "${cache_file}"
}
reload_cache_file () {
cat "${via_dir}/shortcuts" > "${cache_file}"
cat "${via_dir}/websites" >> "${cache_file}"
find "$HOME" -mindepth 1 \( -name ".*" -o -path "$HOME/code/*" \) -prune -o -print | sort >> "$cache_file"
}
output_feed () {
local feed_list="${cache_file}"
local system="$OSTYPE"
if [[ "$system" == "linux*" ]]; then
wmctrl -xl | sed "s/^[^.]*\.//;s/ \+\S\+ \+/ /;s/^/w /;s/ \+/ /g"
fi
cat "$feed_list"
}
main () {
local first_arg="$1"
create_missing_files
if [[ "${first_arg}" == "-r" ]] || [[ ! -s "${cache_file}" ]]; then
reload_cache_file
fi
output_feed
}
args="$*"
main "$args"