You are not logged in.

#1 2010-04-25 15:26:26

rent0n
Member
From: Italy
Registered: 2009-10-29
Posts: 457
Website

[Solved] Create a dmenu custom menu

Hi,

I was wondering if it is possible to create a custom dmenu's menu.
For example I would like to have a special 'session' menu with logout, shutdown and reboot actions, with these actions bound to special commands like 'sudo shutdown -h now'.

Is this possible? How?

Thank you smile

Last edited by rent0n (2010-04-25 19:25:37)


rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686

Offline

#2 2010-04-25 15:44:54

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: [Solved] Create a dmenu custom menu

Create your own bash scripts where you start your programs or commands and put them in /usr/bin. dmenu will recognize them as /usr/bin is on the systempath.

Regards

Offline

#3 2010-04-25 16:07:24

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Create a dmenu custom menu

#! /bin/bash
actions="
logout killall X
shutdown halt
reboot reboot
new sed -i \"/^new/i\$(echo | dmenu -p \"Enter new name and action\")\" '$0'"
result=$(echo "$actions" | dmenu -l 10)
cmd=$(echo "$result" | cut -d' ' -f2-)
[ -n "$cmd" ] && eval setsid setsid "$cmd"

Offline

#4 2010-04-25 16:59:33

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [Solved] Create a dmenu custom menu

I've been using this one for a while:

#!/bin/bash
#
# a simple logout dialog
#
###

kill_apps() {
  while read -r app; do
    wmctrl -i -c "$app"
  done < <(wmctrl -l | awk '{print $1}')
}

choice_by_zenity() {
  choice=$(zenity --title="Logout $HOSTNAME" \
                  --text="Logout $HOSTNAME:" \
                  --list --radiolist \
                  --hide-column=3 --print-column=3 \
                  --column='' --column='' --column='' \
                  TRUE Logout 0 FALSE Reboot 1 FALSE Shutdown 2)
}

choice_by_dmenu() {
  if [[ -f "$HOME/.dmenurc" ]]; then
    . "$HOME/.dmenurc"
  else
    DMENU='dmenu -i'
  fi

  choice=$(echo -e "0: Logout\n1: Shutdown\n2: Reboot" | $DMENU | cut -d ':' -f 1)
}

[[ -z "$DISPLAY" ]] && exit 1

#choice_by_zenity
choice_by_dmenu

[[ -z "$choice" ]] && exit 1

# gracefully close all open apps
kill_apps

# execute the choice in background
case "$choice" in
  0) kill $(pgrep X) &      ;;
  1) sudo shutdown -r now & ;;
  2) sudo shutdown -h now & ;;
esac

Last edited by brisbin33 (2010-04-25 17:02:06)

Offline

#5 2010-04-25 18:16:57

rent0n
Member
From: Italy
Registered: 2009-10-29
Posts: 457
Website

Re: [Solved] Create a dmenu custom menu

brisbin33 wrote:

I've been using this one for a while:

#!/bin/bash
#
# a simple logout dialog
#
###

kill_apps() {
  while read -r app; do
    wmctrl -i -c "$app"
  done < <(wmctrl -l | awk '{print $1}')
}

choice_by_zenity() {
  choice=$(zenity --title="Logout $HOSTNAME" \
                  --text="Logout $HOSTNAME:" \
                  --list --radiolist \
                  --hide-column=3 --print-column=3 \
                  --column='' --column='' --column='' \
                  TRUE Logout 0 FALSE Reboot 1 FALSE Shutdown 2)
}

choice_by_dmenu() {
  if [[ -f "$HOME/.dmenurc" ]]; then
    . "$HOME/.dmenurc"
  else
    DMENU='dmenu -i'
  fi

  choice=$(echo -e "0: Logout\n1: Shutdown\n2: Reboot" | $DMENU | cut -d ':' -f 1)
}

[[ -z "$DISPLAY" ]] && exit 1

#choice_by_zenity
choice_by_dmenu

[[ -z "$choice" ]] && exit 1

# gracefully close all open apps
kill_apps

# execute the choice in background
case "$choice" in
  0) kill $(pgrep X) &      ;;
  1) sudo shutdown -r now & ;;
  2) sudo shutdown -h now & ;;
esac

Very nice!
I'm trying to make a very basic version of it, but I am probabling missing something obvious as I am only able to logout but I can't perform other actions: could you take a look at it and tell me what's wrong?

#!/bin/bash
#
# a simple dmenu session script 
# by brisbin33
#
###

DMENU='dmenu -i -b -fn -xos4-terminus-medium-r-*--12-*-*-*-*-*-iso10646-1 -nb #000000 -nf #999999 -sb #000000 -sf #31658C'
choice=$(echo -e "logout\n shutdown\n reboot\n suspend\n hibernate\n" | $DMENU | cut -f 1)

case "$choice" in
  logout) i3-msg exit    ;;
  shutdown) sudo shutdown -h now    ;;
  reboot) sudo shutdown -r now    ;;
  suspend) sudo pm-suspend    ;;
  hibernate) sudo pm-hibernate    ;;
esac

Thanks!

EDIT: fixed!

#!/bin/bash
#
# a simple dmenu session script 
#
###

DMENU='dmenu -i -b -fn -xos4-terminus-medium-r-*--12-*-*-*-*-*-iso10646-1 -nb #000000 -nf #999999 -sb #000000 -sf #31658C'
choice=$(echo -e "logout\nshutdown\nreboot\nsuspend\nhibernate" | $DMENU)

case "$choice" in
  logout) i3-msg exit & ;;
  shutdown) sudo shutdown -h now & ;;
  reboot) sudo shutdown -r now & ;;
  suspend) sudo pm-suspend & ;;
  hibernate) sudo pm-hibernate & ;;
esac

Thank you brisbin, this script is very cool! cool

Last edited by rent0n (2010-04-25 19:29:33)


rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686

Offline

#6 2010-04-26 00:08:58

sw2wolf
Member
From: China
Registered: 2009-06-08
Posts: 99
Website

Re: [Solved] Create a dmenu custom menu

%cat ~/.dmenu.mnu
/home/sw2wolf/bin/xp.sh
firefox
thunderbird
screen
evince
roxterm
gedit
gqview
vinagre
nvidia-settings
sudo shutdown -r now
sudo shutdown -h now

%cat ~/.xmonad/xmonad.hs|grep -i dmenu
dmenu  = "exe=`cat /home/sw2wolf/.dmenu.mnu | dmenu -b -fn '-*-terminus-*-r-*-*-*-*-*-*-*-*-*-*' -nb '#000000' -nf '#FFFFFF'` && eval \"exec $exe\""

In this way, i can customize the dmenu by myself.


e^(π⋅i) + 1 = 0

Offline

#7 2010-04-26 07:24:23

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] Create a dmenu custom menu

A small change to what I posted above (now it will auto-add new entries instead of having to select new)

#! /bin/bash
actions='firefox
kilall X
$(tty -s || echo xterm -e) bash -c "sudo shutdown -r now"
$(tty -s || echo xterm -e) bash -c "sudo reboot"' #mark

result=$(echo "$actions" | dmenu)
[ -z "$result" ] && exit
echo "$actions" | grep -Fxq "$result" || sed -i "s/' #mark/\n$result&/" "$0"
eval setsid setsid $result

Offline

#8 2010-04-27 21:55:11

Ogion
Member
From: Germany
Registered: 2007-12-11
Posts: 367

Re: [Solved] Create a dmenu custom menu

#!/bin/zsh
IFS=$'\t\n'
PATH=$PATH:/home/ogion/bin

mostused="firefox
i3statbar.sh
sylpheed"

$(echo $mostused | dmenu -fn fixed -nb '#100' -nf '#b9c0af' -sb '#000' -sf  '#afff2f' -i)

Just an app starting dmenu with a short list of apps, sort of a quickstartbar. I mean even with normal dmenu it is quick, but maybe i have some programs that would have long names or similar, and having only half a dozen or a dozen entries in dmenu speeds it up.  Just add a new line with the name of the program to extent tthe mostused list.
(You could also make 'aliases' for programs. Make something in the list like aa and then make the long $() to app=$(...) and then make a case statement that resolves aa to something, and maybe a few other 'aliases' and the rest *) just pass it through, and then execute it).

Dmenu's nice smile

Ogion


(my-dotfiles)
"People willing to trade their freedom for temporary security deserve neither and will lose both." - Benjamin Franklin
"Enlightenment is man's leaving his self-caused immaturity." - Immanuel Kant

Offline

#9 2022-05-06 02:01:17

Roman7
Member
Registered: 2022-04-08
Posts: 3

Re: [Solved] Create a dmenu custom menu

#!/bin/sh
program="steam
sc-controller
gimp
PureRef
transmission-gtk
pacfinder
system-monitoring-center"

result=$(echo "$program" | dmenu -i)
$result 

Offline

#10 2022-05-06 02:45:29

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Create a dmenu custom menu

Don't necrobump: https://wiki.archlinux.org/title/Genera … bumping%22

Last edited by jasonwryan (2022-05-06 02:46:11)


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#11 2022-05-06 07:54:58

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,331

Re: [Solved] Create a dmenu custom menu

Closing this 12 year old thread.

Offline

Board footer

Powered by FluxBB