aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/scripts/file-search
blob: bb744e5a99b2c18dc45cb4cf22c5fe7826f7e290 (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
#!/bin/sh -eu

cache=/tmp/file_search_results.cache
append() { find "$1" -maxdepth 1 -printf "%p\n"; }
appendRecursive() { find "$1" -printf "%p\n"; }
removeDuplicates() { awk '!visited[$0]++' "$1" | sponge "$1"; }

{ [ ! -f "$cache" ]                 \
  || [ "${1:-}" = "update" ]; }     \
  && locate -ie                     \
  "$HOME"/.vim                      \
  "$HOME"/Music                     \
  "$HOME"/Books                     \
  "$HOME"/Videos                    \
  "$HOME"/Documents                 \
  "$HOME"/Downloads                 \
  "$HOME"/Pictures                  \
  "$HOME"/.local/bin                \
  "$HOME"/.config/awesome           \
  "$HOME"/.config/systemd           \
  "$HOME"/.local/share/Trash        \
  "$HOME"/.local/share/applications \
  > "$cache"                        \
  && { append "$HOME"; } >> "$cache"

[ "${1:-}" = "update" ] && removeDuplicates "$cache" && exit;

xdg-open "$(rofi -font "ubuntu 12" -matching regex -padding 20 -dmenu -i -p 'Files' < "$cache")"