Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal, Streamlined, Powerful (Improvement for an older PR) #1419

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .local/bin/searchfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/dash
p() { printf "%s\n" "${@}"; }
d() { dmenu -l "15" -p "${1}"; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
d() { dmenu -l "15" -p "${1}"; }
d() { dmenu -l "15" -i -p "${1}"; }

Useful if some filenames are capitalized (makes searches case-insensitive).

f() {
r="$(locate -b -e --regex -d "${XDG_CONFIG_HOME}/.p.db" "(${1})$")"
Copy link

@RetroViking RetroViking Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r="$(locate -b -e --regex -d "${XDG_CONFIG_HOME}/.p.db" "(${1})$")"
r="$(locate -b -e --regex "(${1})$")"

This can also work. It uses the default plocate database instead of this custom one. By default, Arch Linux auto-updates the database once a day (if plocate is installed). Otherwise, running sudo updatedb will manually refresh it when needed.

By default, plocate scans everything, which can add a lot of junk to the output. For example, the "Image" category shows the thumbnails generated in ~/.cache/lf and ~/.cache/ueberzug. This can be fixed by creating an /etc/updatedb.conf file with something like this 1:

PRUNENAMES=".git .bzr .hg .svn .cache .local .cargo .librewolf"
PRUNEPATHS="/boot /dev /etc /opt /proc /run /srv /sys /tmp /usr /var"

This restricts scanning to only /home, /root and a few other places, leading to a cleaner file list and faster database updates.

Overall, nice work! Thanks for sharing!

1: updatedb.conf man page

o="$(p "${r}" | sed 's|.*/||; s/\.[^.]*$//' | d "${c}")"
[ "${o}" ] && ${2} "$(p "${r}" | grep -Fm "1" "/${o}.")"
}
c="$(p "Doc" "Image" "Music" "Office" "Video" | d "Categories")"
case "${c}" in
"Doc") f "cb.|djvu|epup|mobi|p(df|s)" "zathura --mode fullscreen" ;;
"Image") f "j(pe?g|xl)|png|webp" "nsxiv -bfq" ;;
"Music") f "flac|m(p3|4a)|o(gg|pus)|wav" "mpv" ;;
"Office") f "(doc|ppt|xls)x?|od(p|s)" "libreoffice" ;;
"Video") f "avi|flv|gif|m(2ts|p4)|m(4|o|k)v|w(ebm|mv)" "mpv" ;;
*) exit ;;
esac