From 8deceedae9386b1b4b009dd24a8106066e9a8309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Sun, 2 Jun 2024 07:15:46 +0300 Subject: [PATCH 1/2] Minimal, Streamlined, Powerful (Improvement for an older PR) --- .local/bin/searchfiles | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .local/bin/searchfiles diff --git a/.local/bin/searchfiles b/.local/bin/searchfiles new file mode 100644 index 0000000000..b58342ff8f --- /dev/null +++ b/.local/bin/searchfiles @@ -0,0 +1,15 @@ +#!/bin/sh +f() { + r="$(locate -d "${XDG_CONFIG_HOME}/.p.db" -b -r ".*\.\(${1}\)$")" + o="$(printf "%s\n" "${r}" | sed 's|.*/||;s/\.[^.]*$//' | dmenu -i -p "${c}" -l "20")" + [ "${o}" ] && ${2} "$(printf "%s\n" "${r}" | grep -Fm "1" "/${o}.")" +} +c="$(printf "Video\nDoc\nImage\nOffice\nMusic\n" | dmenu -i -p "Categories" -l "5")" +case "${c}" in + "Video") f "mp4\|mkv\|webm\|mov\|m4v\|wmv\|flv\|avi\|gif\|m2ts" "mpv" ;; + "Doc") f "pdf\|djvu\|ps\|epub\|mobi\|cb." "zathura --mode fullscreen" ;; + "Image") f "jpg\|jpeg\|webp\|png\|jxl" "nsxiv -bfq" ;; + "Office") f "xls\|xlsx\|ods\|doc\|docx\|ppt\|pptx\|odp" "libreoffice" ;; + "Music") f "mp3\|wav\|flac\|ogg\|m4a\|opus" "mpv --no-video" ;; + *) exit "0" ;; +esac From 20c16d980f3977609e1b2c04e2ea19dab638ecfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20AKY=C3=9CZ?= Date: Fri, 30 Aug 2024 15:10:12 +0300 Subject: [PATCH 2/2] Streamline further | Better Regex --- .local/bin/searchfiles | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/.local/bin/searchfiles b/.local/bin/searchfiles index b58342ff8f..b480a51eda 100644 --- a/.local/bin/searchfiles +++ b/.local/bin/searchfiles @@ -1,15 +1,17 @@ -#!/bin/sh +#!/bin/dash +p() { printf "%s\n" "${@}"; } +d() { dmenu -l "15" -p "${1}"; } f() { - r="$(locate -d "${XDG_CONFIG_HOME}/.p.db" -b -r ".*\.\(${1}\)$")" - o="$(printf "%s\n" "${r}" | sed 's|.*/||;s/\.[^.]*$//' | dmenu -i -p "${c}" -l "20")" - [ "${o}" ] && ${2} "$(printf "%s\n" "${r}" | grep -Fm "1" "/${o}.")" + r="$(locate -b -e --regex -d "${XDG_CONFIG_HOME}/.p.db" "(${1})$")" + o="$(p "${r}" | sed 's|.*/||; s/\.[^.]*$//' | d "${c}")" + [ "${o}" ] && ${2} "$(p "${r}" | grep -Fm "1" "/${o}.")" } -c="$(printf "Video\nDoc\nImage\nOffice\nMusic\n" | dmenu -i -p "Categories" -l "5")" +c="$(p "Doc" "Image" "Music" "Office" "Video" | d "Categories")" case "${c}" in - "Video") f "mp4\|mkv\|webm\|mov\|m4v\|wmv\|flv\|avi\|gif\|m2ts" "mpv" ;; - "Doc") f "pdf\|djvu\|ps\|epub\|mobi\|cb." "zathura --mode fullscreen" ;; - "Image") f "jpg\|jpeg\|webp\|png\|jxl" "nsxiv -bfq" ;; - "Office") f "xls\|xlsx\|ods\|doc\|docx\|ppt\|pptx\|odp" "libreoffice" ;; - "Music") f "mp3\|wav\|flac\|ogg\|m4a\|opus" "mpv --no-video" ;; - *) exit "0" ;; + "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