diff options
| author | 0scar <qgt268@alumni.ku.dk> | 2021-06-10 08:05:06 +0000 |
|---|---|---|
| committer | 0scar <qgt268@alumni.ku.dk> | 2021-06-10 08:05:06 +0000 |
| commit | 7ad685aa6bd77d76115132280ce323d7fc5aeeb0 (patch) | |
| tree | c605992dfb5582a050b8847eb624fa84f1f97d91 /.local/bin/dmenu_run_history | |
| parent | 6e4a15d79352ca2707a3b0d81d158228a7d14704 (diff) | |
Add scripts
Diffstat (limited to '.local/bin/dmenu_run_history')
| -rwxr-xr-x | .local/bin/dmenu_run_history | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/.local/bin/dmenu_run_history b/.local/bin/dmenu_run_history new file mode 100755 index 0000000..6085d13 --- /dev/null +++ b/.local/bin/dmenu_run_history @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"} +if [ -d "$cachedir" ]; then + cache=$cachedir/dmenu_run + historyfile=$cachedir/dmenu_history +else # if no xdg dir, fall back to dotfiles in ~ + cache=$HOME/.dmenu_cache + historyfile=$HOME/.dmenu_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" \ + | dmenu "$@" \ + | 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:-"/usr/bin/env bash"} -c "$cmd" & done |
