diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2025-02-13 16:50:30 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2025-02-13 16:50:30 +0000 |
| commit | 671c1608210ab47858da8ee7729ea81ce29a79e7 (patch) | |
| tree | e11a36ce07357a467c56353739cc17e3f52c9f35 /.local/bin/bemenu_run_history | |
| parent | e8d5c7f03b2fabd63cb87e26c303e73e0782ef17 (diff) | |
Add some scripts
Diffstat (limited to '.local/bin/bemenu_run_history')
| -rwxr-xr-x | .local/bin/bemenu_run_history | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/.local/bin/bemenu_run_history b/.local/bin/bemenu_run_history new file mode 100755 index 0000000..242d277 --- /dev/null +++ b/.local/bin/bemenu_run_history @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"} +if [ -d "$cachedir" ]; then + cache=$cachedir/bemenu_run + historyfile=$cachedir/bemenu_history +else # if no xdg dir, fall back to dotfiles in ~ + cache=$HOME/.bemenu_cache + historyfile=$HOME/.bemenu_history +fi + +IFS=: +if stest -dqr -n "$cache" $PATH; then + stest -flx $PATH | sort -u > "$cache" +fi +unset IFS + +awk -v histfile=$historyfile ' + BEGIN { + while( (getline < histfile) > 0 ) { + sub("^[0-9]+\t","") + print + x[$0]=1 + } + } !x[$0]++ ' "$cache" \ + | bemenu "$@" \ + | awk -v histfile=$historyfile ' + BEGIN { + FS=OFS="\t" + while ( (getline < histfile) > 0 ) { + count=$1 + sub("^[0-9]+\t","") + fname=$0 + history[fname]=count + } + close(histfile) + } + + { + history[$0]++ + print + } + + END { + if(!NR) exit + for (f in history) + print history[f],f | "sort -t '\t' -k1rn >" histfile + } + ' \ + | while read cmd; do ${SHELL:-"/bin/sh"} -c "$cmd" & done |
