diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-05-26 12:47:33 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-05-26 12:56:17 +0200 |
commit | 4abab142a54a41f92160b2daf8c72b149947110e (patch) | |
tree | a08d9a35bef710e41e6f8a0ecfaf0e4c701e7ecc /dmemu | |
download | utils-4abab142a54a41f92160b2daf8c72b149947110e.tar utils-4abab142a54a41f92160b2daf8c72b149947110e.zip |
Initial import of dmemu
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" |