From 4abab142a54a41f92160b2daf8c72b149947110e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 26 May 2010 12:47:33 +0200 Subject: Initial import of dmemu --- dmemu | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 dmemu (limited to 'dmemu') diff --git a/dmemu b/dmemu new file mode 100755 index 0000000..d2b4c36 --- /dev/null +++ b/dmemu @@ -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" -- cgit v1.2.3