Last active
February 19, 2026 17:04
-
-
Save lf-araujo/1be8de2e72be0302ad49623f48ea0603 to your computer and use it in GitHub Desktop.
Gnome tracker search command line tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # lsfz: LocalSearch + fzf with compact labels and Enter-to-open | |
| # Deps: localsearch, fzf, gio (or xdg-open), bash | |
| set -euo pipefail | |
| # How many results to fetch | |
| LIMIT="${LIMIT:-200}" | |
| # What to search (e.g. --files | --documents | --images) | |
| CATEGORY_FLAGS="${CATEGORY_FLAGS:---files --documents --images --folders --audio --music-albums --music-artists --videos --software}" | |
| # ---------------------- option parsing (leading options only) ----------------- | |
| SEARCH_ARGS=() | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| --) shift; break ;; # end of options, rest are terms | |
| -*) break ;; # unknown flag -> treat as term | |
| *) break ;; # first search term | |
| esac | |
| done | |
| # Remaining args (including any flags you want to pass to localsearch later) | |
| SEARCH_ARGS=("$@") | |
| # ---------------------- usage check ------------------------------------------ | |
| if [[ ${#SEARCH_ARGS[@]} -lt 1 ]]; then | |
| cat >&2 <<USAGE | |
| Usage: $(basename "$0") <search terms...> | |
| Examples: | |
| $(basename "$0") report | |
| CATEGORY_FLAGS=--documents $(basename "$0") protocol | |
| USAGE | |
| exit 1 | |
| fi | |
| strip_ansi() { | |
| # Strip ANSI color sequences like \x1b[32m that clutter the list. | |
| sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' | |
| } | |
| to_rows() { | |
| # Convert lines into: "LABEL<TAB>URI" | |
| # LABEL = "filename — ~/short/path" | |
| # URI = original file:// URI (what we open) | |
| awk -v HOME="$HOME" ' | |
| { | |
| # Portable form: use if (...) next; not "match(...) || next" | |
| if (match($0, /(file:\/\/[^ \t]+)/, m) == 0) | |
| next | |
| uri = m[1] | |
| path = uri | |
| sub(/^file:\/\//, "", path) | |
| gsub(/%20/, " ", path) | |
| base = path | |
| sub(/^.*\//,"", base) | |
| short = path | |
| sub("^" HOME "/","~/", short) | |
| # compact long paths (middle ellipsis) | |
| if (length(short) > 70) | |
| short = substr(short,1,20) "…" substr(short, length(short)-40) | |
| printf "%s — %s\t%s\n", base, short, uri | |
| }' | |
| } | |
| localsearch search $CATEGORY_FLAGS --limit "$LIMIT" "${SEARCH_ARGS[@]}" \ | |
| | strip_ansi \ | |
| | to_rows \ | |
| | fzf --prompt="LocalSearch ▶ " \ | |
| --delimiter=$'\t' --with-nth=1 \ | |
| --height=100% --layout=reverse --border \ | |
| --preview 'localsearch info {2} 2>/dev/null | sed -E "s/\x1B\[[0-9;]*[A-Za-z]//g"' \ | |
| --bind 'enter:execute-silent(sh -c '\''setsid -f gio open "$1" >/dev/null 2>&1 || setsid -f xdg-open "$1" >/dev/null 2>&1'\'' _ {2})+abort' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment