From f2eb4b2d98e857b09e807ff07d238512a0d602e7 Mon Sep 17 00:00:00 2001 From: tdro Date: Fri, 4 Dec 2020 03:45:03 -0500 Subject: .local/bin/scripts/file-search: Increase reach and speed --- .local/bin/scripts/file-search | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to '.local') 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")" -- cgit v1.2.3