aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/scripts/file-search
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/scripts/file-search')
-rwxr-xr-x.local/bin/scripts/file-search42
1 files changed, 26 insertions, 16 deletions
diff --git a/.local/bin/scripts/file-search b/.local/bin/scripts/file-search
index 339c7d5..bb744e5 100755
--- a/.local/bin/scripts/file-search
+++ b/.local/bin/scripts/file-search
@@ -1,18 +1,28 @@
#!/bin/sh -eu
-xdg-open "$(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 \
- \
-| rofi -font "ubuntu 12" -padding 20 -dmenu -i -p 'Files')"
+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")"