diff options
Diffstat (limited to 'dmemu')
-rwxr-xr-x | dmemu | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +#!/bin/bash + +PRIORITY_FACTOR=9/10 +BASE_PRIORITY=1000 +SAVE_FILE="$HOME/.dmemu" + + +INPUT="$(cat)" +DMENUINPUT="$INPUT" + +if [ -r "$SAVE_FILE" ]; then + SAVED_STRINGS="$(sort -rn $SAVE_FILE | cut -d ' ' -f 2- | grep -xF "$INPUT")" + if [ "$SAVED_STRINGS" ]; then + DMENUINPUT=$(echo "$SAVED_STRINGS"; echo "$INPUT" | grep -vxF "$SAVED_STRINGS") + fi +fi + +RET=$(echo "$DMENUINPUT" | dmenu "$@") + +if [ -z "$RET" ]; then + exit 0 +fi + +touch "$SAVE_FILE" || true + +if [ -w "$SAVE_FILE" ]; then + ( + HANDLED=0 + + IFS=" +" + for LINE in $(cat "$SAVE_FILE"); do + VAL="$(echo -n "$LINE" | cut -d ' ' -f 1)" + COMMAND="$(echo -n "$LINE" | cut -d ' ' -f 2-)" + if [ "$COMMAND" = "$RET" ]; then + echo $(($VAL+$BASE_PRIORITY)) "$COMMAND" + HANDLED=1 + else + echo $(($VAL*$PRIORITY_FACTOR)) "$COMMAND" + fi + done + if [ "$HANDLED" -eq 0 ]; then + echo $BASE_PRIORITY "$RET" + fi + ) > "$SAVE_FILE.new" + + mv "$SAVE_FILE.new" "$SAVE_FILE" +fi + +echo -n "$RET" |