You are not logged in.
Pages: 1
Topic closed
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
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
#! /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
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)
//github/
Offline
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!
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
%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
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
#!/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
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
#!/bin/sh
program="steam
sc-controller
gimp
PureRef
transmission-gtk
pacfinder
system-monitoring-center"
result=$(echo "$program" | dmenu -i)
$result
Offline
Don't necrobump: https://wiki.archlinux.org/title/Genera … bumping%22
Last edited by jasonwryan (2022-05-06 02:46:11)
Offline
Closing this 12 year old thread.
Offline
Pages: 1
Topic closed