💾 Archived View for darknesscode.xyz › notes › dmenu.gmi captured on 2022-06-03 at 22:45:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-05)

-=-=-=-=-=-=-

dmenu examples

dmenu is a powerful tool, you can work with demnu in different ways. For example to run scripts, like a file manager, to take little notes or ideas.

Here are some examples to show what **dmenu** can do

Like File Manager

This little dmenu script than I use it to open and edit my scripts

#!/bin/sh

lines=10
terminal="urxvt"
path="$HOME/Documents/myScripts"

find -L $path | sed 's/ /\\ /g' | sort -f | dmenu -i -b -l $lines -p " Edit Script : " | xargs -I {} $terminal -e vim "{}"

I use the same script for different directories, I just change the path to a different directory.

Or maybe you want the full home directory

#!/bin/sh

lines=10
terminal="urxvt"
path="$HOME"

find -L $path | sed 's/ /\\ /g' | sort -f | dmenu -i -b -l $lines -p " Edit Script : " | xargs -I {} $terminal -e vim "{}"

To Run Scripts

Let's say that you want to push some files to a home/remote server or connect it via ssh, in this example I use ssh and rsync

#!/bin/bash

font="-fn Noto-11"

terminal="urxvt"

declare options=("homeServer
remoteServer
remoteServerSsh
pushGemini
pushWeb")

choice=$(
	echo -e "${options[@]}" |
	dmenu -i -b -p ' Open Program : ' $font
)

case "$choice" in
	quit) echo "Program terminated." && exit 1 ;;
	homeServer)	exec $terminal -e ssh -t user@000.000.000.000 'tmux new-session -d;
		tmux rename-window "Home Server";
		tmux new-window ranger;
		tmux rename-window "Files";
		tmux new-window ranger ~/Downloads;
		tmux rename-window "Downloads";
		tmux -2 attach-session -d' ;;
	remoteServer) exec $terminal -e ssh -t user@000.000.000.000 'tmux new-session -d;
		tmux rename-window "Terminal";
		tmux new-window ranger ~/app;
		tmux rename-window "Web App";
		tmux new-window ranger ~/app/Controllers;
		tmux rename-window "Controllers & Models";
		tmux new-window ranger ~/app/Views;
		tmux rename-window "Views";
		tmux -2 attach-session -d' ;;
	remoteServerSsh) exec $terminal -e ssh user@000.000.000.000 ;;
	pushGemini) exec $terminal -e rsync -azP ~/Documents/websites/gemini/* user@domain.xxx:/home/gemini/gmi.capsule ;;
	pushWed) exec $terminal -e rsync -azP ~/Documents/websites/web/public/* user@domain.xxx:~/var/www/domain.xxx ;;
	*) exit 1 ;;
esac

"$choice"

This is just a very simple example of how dmenu can be use to automated your work flow. The options are endless to work with dmenu, the example below is to reboot/shutdown you computer using dwm

#!/bin/bash

font="-fn 'Noto-11'"

declare options=("Cancel
Lock-Screen
Exit
Shutdown
Reboot
Suspend
Hibernate
Hybrid-Sleep
Suspen-Hibernate")

choice=$(
	echo -e "${options[@]}" |
	dmenu -i -p 'Select an Option: ' $font
)

case "$choice" in
	Cancel)	exit 1 ;;
	Lock-Screen)	blurlock ;;
	Exit)		kill -TERM $(pidof -s dwm) ;;
	Shutdown)	systemctl poweroff ;;
	Reboot)		systemctl reboot ;;
	Suspend)	systemctl suspend ;;
	*) exit 1 ;;
esac

"$choice"

The last two are almost the same structure but they do different process.

Another example, this one is to add torrents to my home server. It use tremc, notify to connect to the server and add the torrent

#!/bin/sh

font="-fn Noto-11"

feed="$(printf "%s" | dmenu $font -b -p ' Paste Magnet URL: ')" || exit 1

tremc -- $feed && notify-send "Torrent Added!!!" || notify-send "Holy C*** It Did'n Work!"

You can pip into dmenu almost what ever you want, play around with it!

Check suckless.org for more scripts

----------

Home

Linux

Notes

MicroLog

----------

© DarknessCode