#!/bin/bash DMENU="dmenu $DMENU_OPTIONS" TERM="urxvtc -e" # edit it to what you like CACHE=${XDG_CACHE_HOME:-$HOME/.cache}/dmenu-recent-apps mkdir -p ${XDG_CACHE_HOME:-$HOME/.cache} CONFIG=${XDG_CONFIG_HOME:-$HOME/.config}/dmenu mkdir -p $CONFIG touch $CONFIG/apps-term touch $CONFIG/apps-bg MOST_USED=`sort $CACHE 2>/dev/null | uniq -c | sort -rn | colrm 1 8` RUN=`(echo "$MOST_USED"; dmenu_path_c | grep -vxF "$MOST_USED") | $DMENU -p Execute: "$@"` || exit (echo $RUN; head -n 99 $CACHE 2>/dev/null) > $CACHE.$$ mv $CACHE.$$ $CACHE # figure out how to run the command based on the first word. Note that this does not support # a bg/term decision based on further arguments (although you could easily add that) word0=${RUN%% *} match="^$word0$" while ! grep -q $match $CONFIG/apps-term $CONFIG/apps-bg do type=$(echo -e "term\nbg" | $DMENU -p type) [ $type = bg -o $type = term ] || continue echo $word0 >> $CONFIG/apps-$type done grep -q $match $CONFIG/apps-term && exec $TERM $RUN grep -q $match $CONFIG/apps-bg && exec $RUN