post your custom dmenu

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

post your custom dmenu

Unread post by pidsley » Fri Oct 18, 2013 5:09 pm

Most of the window managers I use don't have menus, and that's OK, because I don't really like most menus. I do like dmenu, and I use it a lot. I also use custom dmenus, partly because they make things a little easier, but mostly because they are an excuse for me to learn more script skills.

I have seen a lot of custom dmenus on various boards -- it's amazing what people have come up with. I swiped several of them from the Arch board dmenu hacking thread.

If you have any dmenu scripts, please post them here.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: post your custom dmenu

Unread post by machinebacon » Fri Oct 18, 2013 5:21 pm

Lovely thread, thanks!

Probably this one is not new for most, but nevertheless interesting (dmenu-bind.sh):
http://www.gambaru.de/blog/2011/12/10/e ... erstellen/

It's in German, but code is code

Edit Oct 19, 3:04am - moved to HOWTO->Configs
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: post your custom dmenu

Unread post by GekkoP » Fri Oct 18, 2013 5:22 pm

thanks! I love dmenu, I'll try some these scripts and see what's best for me.

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: post your custom dmenu

Unread post by johnraff » Fri Oct 18, 2013 6:30 pm

Pidsley, I'm sorry but I couldn't help suggesting, this:

Code: Select all

if [[ $str =~ 't:' ]]; then # this is a terminal command
    cmd=${str#*:}           # strip off leading t:
might be changed to this:

Code: Select all

if [[ $str =~ '^t:' ]]; then # this is a terminal command
    cmd=${str#t:}           # strip off leading t:
just to avoid problems if you had a command 'somethingt:something'

Yes, I know you didn't want any "critiques"... Image
All code is one.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: post your custom dmenu

Unread post by machinebacon » Sat Oct 19, 2013 7:49 am

For the kiTTY lovers, there's slmenu: https://bitbucket.org/rafaelgg/slmenu

Haven't tried it yet (actually zsh/bash-abcompletion works pretty well)
..gnutella..

beta
Oyster-Slurper
Posts: 20
Joined: Sun Nov 04, 2012 10:22 pm

Re: post your custom dmenu

Unread post by beta » Tue Oct 29, 2013 4:34 pm

dmenu quit dialog

Code: Select all

# a simple logout dialog
# based on arp
########################
choice=`echo -e "0: Cancel\n1: Logout\n2: Shutdown\n3: Reboot\n4: Lock" | dmenu -fn "snap" -nb "#222222" -nf "#7D7D7D" -sb "#005885" -sf "#BFBFBF" -p "select an action:" | cut -d ':' -f 1`

# execute the choice in background
case "$choice" in
    0) exit ;;
    1) xdotool key super+shift+q & ;;
    2) sudo systemctl poweroff & ;;
    3) sudo systemctl shutdown & ;;
    4) xscreensaver-command -lock & ;;
esac
calling this with a key combo from spectrwm
logout just quits x (using my spectrwm key combo)

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: post your custom dmenu

Unread post by stark » Tue Nov 25, 2014 6:42 pm

Well better late than never!

https://github.com/tlvince/dmenu-tools

And from that very same dmenu hacking thread:

https://github.com/orschiro/dmenu-scripts-collection
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: post your custom dmenu

Unread post by stark » Sat Dec 27, 2014 5:09 pm

Finally figured out how to automate the loop.

Posted a scrot here few days ago.

Note: If you don't use ( or don't want to use ) dmenu2 then remove the x y w values.

Get the script:

curl http://ix.io/dcC > ~/app-menu

Anyone has any suggestions how to improve this script ? because i'm sure its very badly written.

Code: Select all

#!/bin/sh

# Define your battery device. Look up in '/sys/class/power_supply/' for a directory named 'BAT0' ( it also can be 'BAT1 or something else )
device='BAT1'
battery="$(cat /sys/class/power_supply/$device/capacity)%"

# Volume Status for alsa users
volume="$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/')"

# Define your preferred terminal
terminal='urxvtc -e'

# How many spaces do you want before the battery status ?
spaces=10

# Automating the number of spaces
function auto_space
{
for ((i = 0; i <= $spaces; i++)); do
	printf ' '
done
}

# Menu Order.
menu_list="File\nEdit\nWeb\nTerm\nEmacs\nMusic\nWifi\nHtop\nRanger\nScrot\nScrot-s\n$(eval auto_space)Batt: $battery\n Vol: $volume"

# Dmenu Preferences
Dmenu="/usr/bin/dmenu -p '•' -fn 'Ubuntu Mono derivative Powerline:bold' -i -y 30 -x 70 -w 1141 -nb '#0E1826' -sb '#0E1826' -nf '#C0C0B0' -sf '#FF4945'"

cmd=$(echo -e "$menu_list" | eval $Dmenu)

case $cmd in
	Edit)
		$terminal vim ;;
	Web)
		chromium --incognito ;;
	Ranger)
		$terminal ranger ;;
	Htop)
		$terminal htop ;;
	Term)
		$terminal bash -c "tmux -q has-session && exec tmux attach-session -d || exec tmux new-session -nmain -s$USER@$HOSTNAME" ;;
	File)
		thunar ;;
	Emacs)
		emacs ;;
	Music)
		$terminal ncmpcpp ;;
	Scrot)
		scrot '%F--%I:%M:%S:%p--$wx$h--scrot.png' -e 'mv $f ~/.scrots/' && notify-send 'Scrot Saved !' ;;
	Scrot-s)
		scrot '%F--%I:%M:%S:%p--$wx$h--scrot.png' -s -e 'mv $f ~/.scrots/' && notify-send 'Scrot Saved !' ;;
	Wifi)
		gksudo ~/.scripts/dmenu-scripts/connman_dmenu ;;
esac
exit 0
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
kiiroitori
dpkg-reconfigure
Posts: 72
Joined: Tue Aug 27, 2013 12:22 pm

Re: post your custom dmenu

Unread post by kiiroitori » Fri Mar 06, 2015 12:29 am

Grillers,
I am not sure how different it is from the dmenu_recent script in the dmenu-tools posted by stark, it might be a somewhat bloated version of it but I like this script more than Dominique Strauss-Kahn likes hookers. It is taken from the dmenu hacking thread on the arch forums and I think it deserves to be posted again here too!

What it does:
1- Gives priority to your most recent commands in dmenu. For example if you have both "calendar" and "calc" packages but always want to run "calendar", you won't have to type until the fourth letter ("c-a-l-e") to discriminate from "calc".
2- On the first run of a command, ask whether you want to run it in "background", "terminal" or "terminal_hold" (I never needed the "terminal_hold" function and I am not sure if I will ever need it to be honest).

The script:

Code: Select all

#!/bin/bash

# Originally based on code by Dieter Plaetinck.
# Pretty much re-written by Mina Nagy (mnzaki)

dmenu_cmd="dmenu $DMENU_OPTIONS"
terminal="urxvt -e"
max_recent=99 # Number of recent commands to track

cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu-recent"
recent_cache="$cache_dir/recent"
rest_cache="$cache_dir/all"
known_types=" background terminal terminal_hold "

config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dmenu-recent"
mkdir -p "$cache_dir"
mkdir -p "$config_dir"
touch "$recent_cache"

IFS=:
if stest -dqr -n "$rest_cache" $PATH 2>/dev/null; then
     stest -flx $PATH | sort -u | grep -vf "$recent_cache" > "$rest_cache"
fi

IFS=" "
cmd=$(cat "$recent_cache" "$rest_cache" | $dmenu_cmd -b -h 19 -fn 'WenQuanYi Micro Hei -9' "$@") || exit

if ! grep -qx "$cmd" "$recent_cache" &> /dev/null; then
    grep -vx "$cmd" "$rest_cache" > "$rest_cache.$$"
    mv "$rest_cache.$$" "$rest_cache"
fi

echo "$cmd" > "$recent_cache.$$"
grep -vx "$cmd" "$recent_cache" | head -n "$max_recent" >> "$recent_cache.$$"
mv "$recent_cache.$$"  "$recent_cache"

# Figure out how to run the command based on the command name, disregarding
# arguments, if any.
word0=${cmd%% *}
match="^$word0$"

get_type () {
    while type=$(echo $known_types | xargs -n1 | $dmenu_cmd -b -h 19 -fn 'WenQuanYi Micro Hei -9' -p Type:); do
        [[ $known_types =~ " $type " ]] || continue
        echo "$word0" >> "$config_dir/$type"
        break
    done
    echo $type
}

if ! type=$(grep -lx "$match" -R "$config_dir"); then
    type=$(get_type)
else 
    type=${type##*/}
    if ! [[ $known_types =~ " $type " ]]; then
        rm "$config_dir/$type"
        type=$(get_type)
    fi
fi

[[ "$type" = "background" ]] && exec $cmd
[[ "$type" = "terminal" ]] && exec $terminal "$cmd"
[[ "$type" = "terminal_hold" ]] &&
    exec $terminal sh -c "$cmd && echo Press Enter to kill me... && read line"
Important note: you will need to adjust the " dmenu_cmd -b -h 19 -fn 'WenQuanYi Micro Hei -9' " bit to your needs. I run a patched dmenu that accepts the height argument but I guess most of you don't. Also I don't understand why but color arguments do not work, probably because of how the script parses dmenu arguments. Well I may be wrong, please remember that I don't know what I am doing most of the time.

That's it. I love this script because of the amount of typing saved at every dmenu run.
See you grillers!

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Fri Mar 06, 2015 12:56 am

thanks for this, only now paying attention to this thread, so wonderful revival, right on time!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: post your custom dmenu

Unread post by wuxmedia » Fri Mar 06, 2015 9:56 am

I managed to change the colour and font, that was about all I could manage :)
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Fri Mar 06, 2015 12:15 pm

^ well done! :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

twoion
Mr. Saggy Tits
Posts: 29
Joined: Sat Aug 09, 2014 6:19 pm

Re: post your custom dmenu

Unread post by twoion » Sat Mar 07, 2015 1:52 am

Does source code customization also count? If yes, there's now dmenuv, the gravitating dmenu with custom menu width and screen alignments ("gravity"). Displayed in the attached screenshot is the bunsen-exit-ng exit dialog (or whatever-you-configure-it-to-be-dialog) to exemplify its use.

The README in the dmenuv repo explains everything, as does the source code.
Attachments
2015_03_06_015232_1366x768_scrot.png
Last edited by twoion on Sun Mar 08, 2015 12:13 pm, edited 1 time in total.

User avatar
simgin
Meme Fodder
Posts: 1167
Joined: Sun Jan 06, 2013 12:07 am
Location: Bradford-on-Avon, UK

Re: post your custom dmenu

Unread post by simgin » Sun Mar 08, 2015 11:17 am

^ Very nice Twoion :) , and I am pretty sure that this counts as a dmenu customization!

Cheers
simon

Ps. I see bunsen is coming on fine.
Someone told me that I am delusional, I almost fell off my unicorn.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Sun Mar 08, 2015 1:25 pm

that looks really nice actually. most useful when using a floating window setup i imagine.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

twoion
Mr. Saggy Tits
Posts: 29
Joined: Sat Aug 09, 2014 6:19 pm

Re: post your custom dmenu

Unread post by twoion » Mon Mar 09, 2015 2:20 am

rhowaldt wrote:that looks really nice actually. most useful when using a floating window setup i imagine.
Actually I'm going to use it with dwm. Because my new display is very high-res (ok, just 1920x1080) and larger I find it quite pleasant that the menu pops up not at the upper/lower margings but in a somewhat central location (-g Tc). Saves eye-movement and refocusing.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Mon Mar 09, 2015 3:29 pm

^ that makes sense i suppose.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Wed Apr 29, 2015 5:24 pm

made a simple MOC-control for dmenu based on Jules' German example posted above, which was very helpful.
crop.png
crop.png (531 Bytes) Viewed 11435 times

Code: Select all

#!/bin/bash
 
#       Custom dmenu-moc.sh
#
#       Copyright 2009, Gatti Paolo (lordkrandel at gmail dot com)
#       Distributed as public domain.
#		Modified to use with MOC by rhowaldt 290415

xcolors=$(sed -n "/#include/s/#include//p" ~/.Xresources | sed "s/<\(.*\)>/\1/")
bgcol=$(sed -n "/*background:/s/*background://p" $xcolors | tr -d [:blank:]) 
fgcol=$(sed -n "/*foreground:/s/*foreground://p" $xcolors | tr -d [:blank:]) 
sbgcol=$(sed -n "/*color4:/s/*color4://p" $xcolors | tr -d [:blank:])
font='-misc-fixed-*-r-*-*-12-*-*-*-*-*-*-*'

title="MOC "
menu=( \
#               labels            commands
#           Main =========================================
                next               "mocp --next"
                play/pause               "mocp --toggle-pause"
                stop               "mocp --stop"
                quit               "mocp --exit"
    )

 
for (( count = 0 ; count < ${#menu[*]}; count++ )); do
 
#   build two arrays, one for labels, the other for commands
    temp=${menu[$count]}
    if (( $count < ${#menu[*]}-2 )); then
        temp+="\n"
    fi
    if (( "$count" % 2 == "0" )); then
        menu_labels+=$temp
    else
        menu_commands+=$temp
    fi
 
done
 
select=`echo -e $menu_labels | dmenu -p $title -nb $bgcol -nf $fgcol -sb $sbgcol -sf $fgcol -fn $font`
 
if [ "$select" != "" ]; then
 
#   fetch and clean the index of the selected label
    index=`echo -e "${menu_labels[*]}" | grep -xnm1 $select | sed 's/:.*//'`
 
#   get the command which has the same index
    part=`echo -e ${menu_commands[*]} | head -$index`
    exe=`echo -e "$part" | tail -1`
 
#   execute
    $exe &
fi
it takes colours from a different file than the default .Xresources so modify it to your needs if your situation differs (just change the xcolors variable to point to the file that has your xcolors)

of note: "play" in MOC is actually "play first item in playlist". i do not use a playlist 99% of the time, so in this case "play" doesnt work for me after "stop". in other words, you wont get it to play again once you pressed "stop", because MOC doesnt support that. however, you will notice that the command for "play" is actually "mocp --unpause", which means that as long as you pause instead of stop, you can continue playback (makes sense, but might not be obvious).
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: post your custom dmenu

Unread post by machinebacon » Wed Apr 29, 2015 6:07 pm

Rho, is "--toggle-pause" different from "--unpause"? I think you could use "--toggle-pause" for just one item like "Pause/Play" -- ah it's late here, guess you know what I mean :D
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: post your custom dmenu

Unread post by rhowaldt » Wed Apr 29, 2015 7:50 pm

you are completely right, it seems i completely missed the --toggle-pause option. script updated.
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

Post Reply