diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2022-03-12 19:54:51 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2022-03-12 19:54:51 +0530 |
commit | 54b772cae06eb25adf33297e35234f33ded81a7b (patch) | |
tree | f287ee48faa8013e4a8f0ee764a6d3cd850bb24d /.scripts/fmenu | |
parent | 7197e45d94dbcf4877d585fff8e634896876ae83 (diff) |
neovim addition
Diffstat (limited to '.scripts/fmenu')
-rwxr-xr-x | .scripts/fmenu | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.scripts/fmenu b/.scripts/fmenu new file mode 100755 index 0000000..d0c6fce --- /dev/null +++ b/.scripts/fmenu @@ -0,0 +1,77 @@ +#!/bin/bash + +usage() +{ + cat << EOF +usage: $0 options + +Index and search files using dmenu + +OPTIONS: + -h Show this message + -o Store index [default: /tmp/fmenu_index] + -i Search folders [default: $HOME] + -x Exclude files [default: ".*\/..*" (i.e. dot-files)] + -d dmenu parameters [default: -i -l 20] + -f force reloading index [default: false] + -t time [default: 5min] + -u Just update the index +EOF +} + +FORCE=false +INDEX="/tmp/fmenu_index" +DMENU="-i -l 20" +TIME="+5" +INPUT=$HOME +EXCLUDE='.*/\..*' +DRY=false +while getopts "ht:fd:o:i:x:u" OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + f) + FORCE=true + ;; + d) + DMENU=$OPTARG + ;; + t) + TIME=$OPTARG + ;; + o) + INDEX=$OPTARG + ;; + i) + INPUT=$OPTARG + ;; + x) + EXCLUDE=$OPTARG + ;; + u) + FORCE=true + DRY=true + ;; + ?) + usage + exit + ;; + esac +done + +function index_files { + find "$INPUT" \( ! -regex "$EXCLUDE" \) | sed 's/ /\\ /g' | sort -f > "$INDEX" +} + +if [[ ! -a "$INDEX" ]] || ( test `find $INDEX -mmin $TIME` ) || ($FORCE) +then + index_files +fi + +if ( ! $DRY ) +then + cat "$INDEX" | `dmenu $DMENU > /tmp/dmenu_find_output.txt` && cat /tmp/dmenu_find_output.txt | xargs xdg-open +fi |