Users browsing this thread: 2 Guest(s)
pfr
Nixers
While I acknowledge the following threads exist: I still think there is a need for a dedicated thread for dmenu scripts. dmenu is so widely used and is so versatile, resulting in an endless list of scripting possibilities, it would be nice to have them all in one place here on nixers.net.

Cyr4x3 had a few cool looking scripts in their recent workflow video which sparked my interest.

Feel free to drop in some helpful scripts to extend dmenu's capabilities in this thread.
The one I'm interested in at the moment is a screenshot script that also allows for editing and uploading of screenshots. I am however looking for some help to replace fb with xero's pb or just simply use curl to upload to 0x0. The thing I like most about this script is that, in addition to using xclip to copy the url to the clipboard, the upload option also sends the url through notify-send which (in gnome at least) is a clickable link.

I hope some of you have more scripts to share.

One of my most used is passmenu which is now baked into pass itself.

You've also got old mate dt over here with his bunch of scripts.
debxp and I-LeCorbeau also have a few.

I don't have anything of my own to offer up, this is purely a selfish script trawling mission.

Also feel free to mention/promote any dmenu alternatives or replacements (Philbush I'm looking at you - xmenu looks awesome), just keep any scripts in this thread dmenu specific to avoid confusion.
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival)
seninha
Long time nixers
(09-06-2021, 03:38 AM)Ramiferous Wrote: Philbush I'm looking at you - xmenu looks awesome
xmenu is more a desktop menu à la fvwm right-click menu, it's not a dmenu alternative.

For dmenu, I have my own alternative called xprompt.

The main problem with dmenu are nested instances. Suppose you have bound Alt+space to a general run-commands dmenu script. It will open dmenu and you can select, for example, "man" to open a manual. Selecting it will in turn open a new dmenu instance prompting for the manual to open.
With xprompt, you can have sub-menus in the same xprompt instance.

This video illustrates what I'm trying to say.
Xprompt can even do file completion (at the final of the video, when I use the "open" command on SICP.pdf)
prx*
Members
Hi,
very nice idea. Indeed, dmenu is extremely useful.
Here are a few scripts I use almost daily. Some are quite old, and kinda ugly when I read them now.


## Appearance
First, make sure they all share the same look :

Code:
$ cat $HOME/.dmenurc
l=15
fn="FiraCode-11"
# gruvbox
nb="#282828"
nf="#a89984"
sf="#282828"
sb="#458588"

## daddbmk/dloadbmk
Browser independent bookmarking:

Code:
#!/bin/sh
# daddbmk
# store an URL in $HOME/.bookmarks

# edit the page
bmk=$HOME/.bookmarks

# choose downloader
#D="wget -O-" # mosts linux
#D="curl -L" # with curl
D="ftp -o-"   # OpenBSD

# dmenu
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="url:"

URL=$(xclip -o | dmenu -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -p "$PROMPT")
test -z "${URL}" && exit
TITLE="$(${D} "${URL}" | grep '<title>' | \
    head -n1 | \
    sed -e 's;<title>;;' -e's;</title>;;' |\
    awk '{$1=$1};1'
)"
echo "${TITLE} ${URL}" >> "${bmk}"
sort -u "${bmk}" -o "${bmk}"

# edit bookmark
st -e $EDITOR "${bmk}"

## search engine
Code:
#!/bin/sh
#search engines with dmenu
# If any text is selected, it is directly pasted at input

#dmenu colors
test -s $HOME/.dmenurc && . $HOME/.dmenurc
# prompt
P="engine <search>:"

#DEFAULT='https://html.duckduckgo.com/html/?kh=1&q='
DEFAULT='https://duckduckgo.com/?kh=1&q='
#DEFAULT='https://www.mojeek.com/search?q='

INPUT=$(echo "duckduckgo
qwant
openstreetmap
manobsd
obsdmisc
obsdports
wiki
wikien
dic
synonyme
en2fr
fr2en
pirate
sound
image" |dmenu -i -fn $fn -nb $nb -nf $nf -sb $sb -sf $sf -p "$P")
ENGINE=$(echo $INPUT |cut -d ' ' -f 1 )
SEARCH=$(echo $INPUT |cut -d ' ' -f2- |sed 's/ /+/g')
if [ -n "$SEARCH" ]; then
   case $ENGINE in
      d | duckduckgo) RES="https://duckduckgo.com/?kh=1&kl=fr-fr&ks=m&kj=kt&ky=-1&kad=fr_FR&q=$SEARCH";;
      qwant) RES="https://www.qwant.com/?q=$SEARCH&t=all" ;;
      osm | openstreetmap ) RES="https://www.openstreetmap.org/search?query=$SEARCH"
      ;;
      obsdmisc ) RES="https://marc.info/?l=openbsd-misc&w=2&r=1&q=b&s=$SEARCH" ;;
      obsdports ) RES="https://marc.info/?l=openbsd-ports&w=2&r=1&q=b&s=$SEARCH" ;;
      manobsd ) RES="https://man.openbsd.org/$SEARCH" ;;
      wiki)  RES="http://fr.wikipedia.org/w/index.php?title=Spécial%3ARecherche&search=$SEARCH&go=Lire" ;;
      i | image ) RES="https://duckduckgo.com/?ia=images&iax=images&q=$SEARCH" ;;
      wikien | ew )  RES="http://en.wikipedia.org/w/index.php?title=Spécial%3ARecherche&search=$SEARCH&go=Lire" ;;
      dic )  RES="http://www.le-dictionnaire.com/definition.php?mot=$SEARCH" ;;
      syn | synonyme ) RES="http://www.synonymes.com/synonyme.php?mot=$SEARCH&x=0&y=0";;
      en2fr ) RES="http://www.wordreference.com/enfr/$SEARCH";;
      fr2en ) RES="http://www.wordreference.com/fren/$SEARCH";;
      pirate ) RES="https://pirateproxy.name/search.php?q=$SEARCH";;
      sound ) RES="https://soundcloud.com/search?q=$SEARCH";;
      # Le suivant eterm le choix par défaut
      * )
        SEARCH=$(echo $INPUT |cut -d ' ' -f1- |sed 's/ /+/g')
          RES="$DEFAULT$SEARCH" ;;
   esac
fi

if [ "$RES" != "" ]; then
    "$BROWSER" $RES
fi
exit
Code:
#!/bin/sh
test -s $HOME/.dmenurc && . $HOME/.dmenurc

url="$(dmenu -nb $nb -nf $nf -sb $sb -sf $sf -fn $fn -i -l $l < $HOME/.bookmarks | \
    awk '{print $NF}')"
    
if [ -n "$url" ]; then
    $BROWSER "$url"
fi
exit 0

## music player daemon
Code:
#!/bin/sh
#Gestion de mpd avec dmenu et mpc

test -s $HOME/.dmenurc && . $HOME/.dmenurc

OPTION="-sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -l $l -i"

index=`mpc playlist |nl -s ' ' |dmenu $OPTION -p "Que jouer?" |awk '{print $1}'`
if [ "$index" != "" ]; then
    mpc -q play $index
fi
exit 0;

## ssh quick start
Code:
#!/bin/sh
# run ssh session in one hosts listed in
#   $HOME/.ssh/config
#   $HOME/.ssh/known_hosts
# Require : x11/dmenu <https://tools.suckless.org/dmenu/>
# Author : prx <prx@si3t.ch>
# Licence : MIT

# term ?
TERMINAL='st'

# few options for dmenu
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="ssh host:"

C=$HOME/.ssh/config
K=$HOME/.ssh/known_hosts

HOST=$(
(awk '/Hoterm [^*]/ {print $2}' "${C}"
cut -d' ' -f 1 "${K}" |\
    cut -d',' -f1 |\
    sed -e 's;\[;;' -e 's;\];;'
) | sort -u \
| dmenu -l ${l} \
-fn "${fn}" \
-nb "${nb}" \
-nf "${nf}" \
-sb "${sb}" \
-sf "${sf}" \
-p "${PROMPT}")

if [ -n "${HOST}" ]; then
    case "${HOST}" in
        *:*) "${TERMINAL}" -e "ssh ssh://${HOST}" ;;
        *) "${TERMINAL}" -e "ssh ${HOST}" ;;
    esac
fi

exit

## manpage finder
Written at first by eol. A little modified. This one is sick.
Code:
#!/bin/sh

set -e

# TODO or not ?
# Some man page are different on different architecture
# For a simpler interface, this is not handled as only
# the last component of path is displayed in dmenu

sp="$HOME/man /usr/share/man/ /usr/local/man/ /usr/X11R6/man/"
mandb=~/.man.db
readonly sp mandb

usage() {
print -u2 "${0##*/}:
    pipe locate output from ~/.man.db as prepopulated by mk_man_db
    into dmenu. User can select one or more man page thanks to
    dmenu multiselection. Read dmenu(1) for more information ;)

    You can customize the window using the \"man\" class in ~/.Xresources
    with line such as:
        man*scrollBar: false
        man*reverseVideo: true

    -b build only mode. ~/.man.db is created or updated.
    -h Print this message."
}

mk_man_db() {
    /usr/libexec/locate.updatedb \
        --fcodes="$mandb" \
        --searchpaths="$sp"
    
}

while getopts "bh" opt; do
    case $opt in
        b)    mk_man_db
            exit 0;;
        h|*)    usage
            exit 1;;
        
    esac
done

do_need_update() {
    [[ ! -s $mandb ]] || {
        local lastdbmod lastmanpathdirsmod
        lastdbmod=$(stat -f "%m" $mandb)
        lastmanpathdirsmod=$(stat -f "%m" $sp |sort -r |sed q)
        [[ $lastdbmod < $lastmanpathdirsmod ]]
    } && mk_man_db
}

manpage_choose() {
    test -s $HOME/.dmenurc && . $HOME/.dmenurc
    locate -b -d "${mandb}" . |sed 's,.*/,,;/mandoc.db/d' \
    | dmenu -l ${l} \
    -fn "${fn}" \
    -nb "${nb}" \
    -nf "${nf}" \
    -sb "${sb}" \
    -sf "${sf}" \
    -p "Man page : " |uniq


}

manpage_show() {
IFS='
'
    local manpage=$(manpage_choose)
    [ "$manpage" ] && {
        for m in $manpage
        do
            name=${m%.([0-9]|3p)}
            section=${m##*.}
            f=$(locate -d "${mandb}" /$m |sed q)
            [ -f "$f" ] && \
                case $section {
                    0)
                        xterm -class man -T "man | $name($section)" \
                            -e less -eR "$f" &
                        ;;
                    [1-9]|3p)
                        xterm -class man -T "man | $name($section)" \
                            -e man -l "$f" &
                        ;;
                    *)
                        ;;
                }
        done
    }
}

    do_need_update
    manpage_show &

exit $?

## file search
Code:
#!/bin/sh
# search for file in $sp
test -s $HOME/.dmenurc && . $HOME/.dmenurc
#sp="$HOME /etc /bin /usr/local"
sp="$HOME"

cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
cache="$cachedir/dlocate.db"

mk_cache()
{
    /usr/libexec/locate.updatedb \
    --fcodes="$cache" \
    --searchpaths="$sp"
}

if [ -s $cache ]; then
    lastdbmod=$(stat -f "%m" $cache)
    lastspmod=$(stat -f "%m" $sp |sort -r |sed q)
    test $lastdbmod -lt $lastspmod && mk_cache
else
    mk_cache
fi

prompt="locate:"

res=$(locate -b -d "${cache}" . | dmenu \
        -l ${l} \
        -i \
        -fn "${fn}" \
        -nb "${nb}" \
        -nf "${nf}" \
        -sb "${sb}" \
        -sf "${sf}" \
        -p "${prompt}" \
)
notify-send "${res}"
test -f "${res}" && xdg-open "${res}"

## waybackmachine
Code:
#!/bin/sh
test -s $HOME/.dmenurc && . $HOME/.dmenurc
PROMPT="waybackmachine:"

url="$(xclip -o | dmenu -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -p "$PROMPT")"
test -z "${url}" && exit

$BROWSER "https://web.archive.org/save/$url"
$BROWSER "https://archive.is/?url=$url"

I also use wall setter, scrot'n'upload, note manager, but far less good as the previous mentioned.

edit : a few more explanation here (in french, sorry) : gemini://si3t.ch/Logiciel-libre/Suckless/dmenu.gmi
pfr
Nixers
(09-06-2021, 09:35 AM)phillbush Wrote: xmenu is more a desktop menu à la fvwm right-click menu, it's not a dmenu alternative.

For dmenu, I have my own alternative called xprompt.

My bad, I meant to say xprompt

(09-06-2021, 09:42 AM)prx* Wrote: I also use wall setter, scrot'n'upload,

I'd love to see these too if you wouldn't mind? Thanks for sharing those others too!
_____________________________________________________________________________________________
“Maybe you have some bird ideas... Maybe that's the best you can do.” - Terry A. Davis (R.I.P Terry & Percival)
prx*
Members
okay, here you go, but there's not much to see. :)

## dwall

Code:
#!/bin/sh
# change wallpaper

WALLDIR=$HOME/docs/img/wallpapers

test -s $HOME/.dmenurc && . $HOME/.dmenurc

prompt="wallpaper"
WALL=$(ls $WALLDIR | dmenu -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -i -p "$PWD $prompt:")
if [ -n "$WALL" ]; then
    #feh --bg-scale "$WALLDIR/$WALL"        
    #qiv -z "$WALLDIR/$WALL"
    setwall "$WALLDIR/$WALL"
    
fi
exit 0

## setwall
The previous script use setwall.
Code:
#!/bin/sh
bgcol="$(/usr/X11R6/bin/xrdb -query |grep background | cut -d':' -f2 |  tr -d [:space:])"
test $? -ne 0 && bgcol="black"
/usr/X11R6/bin/xsetroot -solid "$bgcol"

whereis xwallpaper > /dev/null
if [ $? -eq 0 ]; then
    /usr/local/bin/xwallpaper --zoom "${1}"
else
# gm has issues with xcompmgr
    /usr/local/bin/gm display -foreground "$bgcol" -window root -backdrop "${1}"
fi

exit 0

## dshot
Take a screenshot:
* Whole screen
* after 5 sec
* selection
* selection and copy in clipboard to paste image
* selection and upload using 'pixup' (curl to 0x0 or other providers if it fails)
Code:
#!/bin/sh -e

test -s $HOME/.dmenurc && . $HOME/.dmenurc

P="screenshot:"
OPTION="-l ${l} -sb ${sb} -sf ${sf} -nb ${nb} -nf ${nf} -fn ${fn} -p "${P}" "
img=/tmp/scrot-$(date +%Y%m%d%H%S).png

case $LANG in
    fr* )
        txtfull="tout l'écran"
        txtfullwait5="tout l'écran après 5 secondes"
        txtsel="sélection"
        txtselncopy="sélection et copie dans presse papier"
        txtselnup="sélection et upload"
        ;;
    * )
        txtfull="whole screen"
        txtfullwait5="whole screen after 5s"
        txtsel="select"
        txtselncopy="select and copy"
        txtselnup="select and upload"
        ;;
esac

action=$(echo "$txtfull
$txtsel
$txtselncopy
$txtselnup"| dmenu $OPTION)

case "$action" in
    "${txtfull}" )
        scrot "${img}"
    ;;
    "${txtfullwait5}" )
        scrot -d5 "${img}"
    ;;
    "${txtsel}" )
        scrot -s "${img}"
    ;;
    "${txtselncopy}" )
        scrot -s "${img}"
        xclip -selection clipboard -t "image/png" < "$img"
    ;;
    "${txtselnup}" )
        scrot -s "${img}"
        $BROWSER "$(pixup ${img})"
    ;;
esac

exit
Gorm
Registered
I have a couple of dmenu scripts I've made: dmenuwireless, which uses the perl script 'wireless' to connect me to a wireless network, and todmenu, which lets me add/remove things to/from my todo list.
pfr
Nixers
So I have recently been updating my dmenu scripts, and the one I referenced in the OP, the link to it is broken, but Its a heavily modified version of cry4x3's dmenu-scrot script:

(07-06-2021, 12:58 PM)cyr4x3 Wrote:
(06-06-2021, 10:35 PM)Ramiferous Wrote: Hey Cyr4x3, would you mind sharing your sxiv/dmenu script to set the wallpaper and also your dmenu screenshot script?

Of course, here you are:

The wallpaper thingy consists of 2 scripts really. First i launch the one i called choosebg, which just searches for images in my wallpapers folder and displays them in sxiv and from within sxiv, using sxiv's keyhandler i launch setbg, which launches a dmenu to choose how the wallpaper should be set and sets it with xwallpaper.

The dmenu screenshot script can be found over here: dmenu-scrot.sh (requires maim and xdotool).

Also, the pb cli tool that i used is this one overhere, by xero.

Here is what I use:

**[please, someone help me make this POSIX >> #!/bin/sh]**
PHP Code:
#!/usr/bin/env bash

set -o pipefail

DMENU
=${DMENU:-dmenu}
IMG_PATH=$HOME/Pictures/dumps/
UL="pb 0x0"    # pb [0x0/envs/catbox]
TIME=5000 #Seconds notification should remain visible
FILENAME=$(date +%Y-%m-%d_@_%H-%M-%S-scrot.png)

prog="1.Fullscreen
2.Delay_Fullscreen
3.Draw_Section
4.Window
5.Fullscreen_UL
6.Delay_Fullscreen_UL
7.Draw_Section_UL
8.Window_UL"

# dmenu vars set in ~/.profile
cmd=$($DMENU -l 20 -'Choose Screenshot Type' <<< "$prog")

cd $IMG_PATH
case ${cmd%% *} in

    1.Fullscreen
)           
                  
scrot -d 1 $FILENAME && notify-send -t $TIME -"Screenshot" "$(echo $IMG_PATH$FILENAME)" ;;
    
2.Delay_Fullscreen)     
                  
scrot -d 4 $FILENAME && notify-send -t $TIME -"Screenshot" "$(echo $IMG_PATH$FILENAME)" ;;
    
3.Draw_Section)            
                  
scrot -s $FILENAME && notify-send -t $TIME -"Screenshot: Section" "$(echo $IMG_PATH$FILENAME)" ;;
    
4.Window)               
                  
scrot -ub -d 1 $FILENAME && notify-send -t $TIME -"Screenshot: Window" "$(echo $IMG_PATH$FILENAME)" ;;
    
5.Fullscreen_UL)        
                  
scrot -d 1 $FILENAME && $UL $FILENAME xclip -sel clip && notify-send -t $TIME -"Screenshot Uploaded" "$(xclip -o -sel clip)" ;;
    
6.Delay_Fullscreen_UL)  
                  
scrot -d 4 $FILENAME && $UL $FILENAME xclip -sel clip && notify-send -t $TIME -"Sreenshot Uploaded" "$(xclip -o -sel clip)" ;;
    
7.Draw_Section_UL)      
                  
scrot -s $FILENAME && $UL $FILENAME xclip -sel clip && notify-send -t $TIME -"Screenshot Uploaded" "$(xclip -o -sel clip)";;
    
8.Window_UL)            
                  
scrot -ub -d 1 $FILENAME && $UL $FILENAME xclip -sel clip && notify-send -t $TIME -"Screenshot Uploaded" "$(xclip -o -sel clip)";;
    
    *)          
exec "${cmd};;
esac 
Thanks cry4x3!


My version of the pb script is pretty stripped down now:

PHP Code:
#!/bin/sh

usage () {
    
cat <<EOF

Services
0x0|nullenvs|pbcatbox|cat
Usage
pb <service> <file>

EOF
  
exit 0
}

ARG="${2:-/dev/stdin}"
UA=${UA:="Pfr_Upload_Script/1.0"}

case $
1 in
    0x0
|null)
        
curl -"$UA-sF 'file=@-' https://0x0.st < $ARG
    
;;
    
envs|pb)
        
curl -"$UA-sF 'file=@-' https://envs.sh < $ARG
    
;;
    
catbox|cat)
        
curl -"$UA-sF 'reqtype=fileupload' -'fileToUpload=@-' https://catbox.moe/user/api.php < $ARG
    
;;
    *)
        
usage
    
;;
esac 
Thanks xero!


I also still use nsxiv/key-handler for setting my wallpaper. While not a dmenu script, I just remembered that I stole this from cry4x3 around the same time so here is mine now:

PHP Code:
#!/bin/sh
#
# Dependencies: dmenu, feh, notify-send, image-magick, gimp, mediainfo, xclip

DMENU=${DMENU:-dmenu}

while 
read file
do
        case 
"$1" in

    
# Set image as wallpaper
    
"w")
        
feh --bg-scale --no-fehbg "$file&
        
printf "\tWall set\t$file>$XNOTIFY_FIFO &
        ;;

    
# Copy file to another location
    
"c")
        [ -
"$destdir] &&
            
destdir="$(sed 's/s.*#.*$//;/^s*$/d' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs |
            awk '{print $2}' |
            
$DMENU -p "Copy file(sto where?" |
            sed "
s|~|$HOME|g")"
        
[ ! -"$destdir] && notify-send -t 5000 -"$destdir" "Not a directory, cancelled" && exit
        
cp "$file" "$destdir&& notify-send -t 5000 -"Copied To" "$destdir&
        ;;

    
# Move file to another location
    
"m")
        [ -
"$destdir] &&
            
destdir="$(sed 's/\s+#.*$//; s/^\s*#//; /^\s*$/d' ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs |
            awk '{print $2}' |
            
$DMENU -p "Move file(sto where?" |
            sed "
s|~|$HOME|g")"
        
[ ! -"$destdir] && notify-send -t 5000 -"$destdir" "Not a directory, cancelled" && exit
        
mv "$file" "$destdir&& notify-send -t 5000 -"Moved To" "$destdir&
        ;;

    
# Rotate/flop image
    
"r")
        
convert -rotate 90 "$file" "$file;;
    
"R")
        
convert -rotate -90 "$file" "$file;;
    
"f")
        
convert -flop "$file" "$file;;

    
# Copy file location
    
"y")
        echo -
"$filetr -'\n' xclip -sel clip &&
            
notify-send -t 5000 -"File Location" "$(xclip -o -sel clip)"
        
;;

    
# Delete selected images, confirm using dmenu
    
"d")
        [ 
"$(printf "No\\nYes" |
            
$DMENU -p "Really delete $file?")" "Yes" ] &&
            
rm "$file&& notify-send -t 5000 -"File Deleted" "Bye Bye"
        
;;

    
# Open image in gimp
    
"g")
        if ! 
command -v gimp 2>&>/dev/null
        then
            notify
-send -t 5000 -"Gimp" "Command not found"
            
exit 1
        
else
            
gimp "$file"
        
fi
        
;;

    
# Print mediainfo to notification
    
"i")
        
notify-send -t 15000 -"Media Info" "$(mediainfo "$file")" ;;

    
# Upload image & copy url to clipboard
    
"u")
        
pb 0x0 "$file|
        
xclip -sel clip && notify-send -t 5000 -"Image Uploaded" "$(xclip -o -sel clip)"
        
;;

        
esac
done 
Thank you again, cry4x3 :)