You are not logged in.

#1 2009-09-14 13:32:28

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Dmenu Hacking Thread

Couldn't find anything like this on the forums, so I thought, why not create it. ITT: Clever little script thingies that utilize dmenu in some way or another.

Thank brisbin33 for this.

Unfortunately I don't have anything to contribute yet sad

Last edited by Runiq (2009-09-14 14:53:23)

Offline

#2 2009-09-14 14:40:46

bl1nk
Member
Registered: 2008-07-29
Posts: 57
Website

Re: Dmenu Hacking Thread

#!/bin/bash
mpc play `mpc playlist | dmenu -b -i -nb '#040404' -nf '#525252' -sf '#ffa0ff' -sb '#000000' -h 700 -w 1000 -x 50 -y 50 -fn '-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*' -p "Find:" | cut -d')' -f1`

A simple dmenu playlist smile It needs the vertical patches for dmenu.

Offline

#3 2009-09-14 14:54:06

Andrwe
Member
From: Leipzig/Germany
Registered: 2009-06-17
Posts: 322
Website

Re: Dmenu Hacking Thread

Hi,

a friend and me, we have written a dmenu-based mpd-control called dmmpdc.
It uses dmenu with vertical patch, mpc and notify-send.
You can add songs and albums to the playlist, remove and play songs from playlist and see the status of your mpd.
Because it is enough for us how it is now, the songs should be stored in a specific order which should look like this:

/path/to/musicdir/subdir1/subdir2/subdir3/song.ogg
for me it is e.g.:
/music/genre/artist/album/title.ogg

The usage is very simple and made for keybind usage, just enter: script function (e.g.: script add_album)

#!/bin/bash

DMENU="dmenu -i -nb #000 -nf #7af -sb #000 -sf #fff -x 0 -y 32'"
MPD_HOST='localhost'
MPD_PORT='6600'
MUSIC_DIR=/my/music/dir/

function add_track
{
    ALBUM="$1"
    TRACK=$(echo -e "..\n$(mpc ls "$(grep "$ALBUM" /tmp/newalbum.$$ | awk -F / '{print $1}' | sort -f | uniq)/$ALBUM" | awk -F / '{print $4}')" | ${DMENU} -p "Find: " -l 30 -w 640)
    [ "${TRACK}" == ".." ] && add_album
    if [ "${TRACK}" != ".." ]
    then 
        mpc add "$(grep "${ALBUM}" /tmp/newalbum.$$ | awk -F / '{print $1}' |sort -f | uniq)/${ALBUM}/${TRACK}"
        MORE=$(echo -e "add more\nexit" | ${DMENU} -l 3 -w 100)
        [ "$MORE" == "add more" ] && add_track "${ALBUM}"    
    fi
    rm /tmp/newalbum.$$
    return
}

function add_album
{
    ALBUM=$(mpc listall | awk -F / '{print $2" - " $3}'| grep -v mp3 | sort -f | uniq | ${DMENU} -p "DmMpdC Find: " -l 30 -w 640 | sed -e 's#\ \-\ #\/#')
    echo "-${RANDOM}-"
    [ -z "$ALBUM" ] && return
    MODE=$(echo -e "add\nreplace\nopen" | ${DMENU} -l 4 -w 70)
    mpc listall | grep "$ALBUM" > /tmp/newalbum.$$
    [ $MODE == "replace" ] && mpc clear
    j=$(wc -l /tmp/newalbum.$$ | awk '{print $1}')
    J=$(( $j + 1 ))
    for ((i=1; i<J; i++))
    do
        [ $MODE == "add" -o $MODE == "replace" ] && mpc add "$( sed -n "${i}p" /tmp/newalbum.$$)" > /dev/null
    done
    [ $MODE == "open" ] && add_track "$ALBUM"
    [ $MODE == "replace" ] && mpc play 1
    rm /tmp/newalbum.$$
}

function select_track
{
    TRACK=$(mpc playlist | ${DMENU} -p "Find: " -l 30 -w 400 | cut -c 2- - | sed -r s/"\).*$"/""/)
    [ -z "$TRACK" ] && return
    MODE=$(echo -e "play\nremove" | ${DMENU} -l 2 -w 100)
    [ $MODE == "play" ] && mpc play "$TRACK"
    [ $MODE == "remove" ] &&  mpc del "$TRACK"
}

function toggle_random
{
    MRANDOM=$(mpc | grep random | awk '{print $5}')
    if [ "${MRANDOM}" == "off" ]
    then
        mpc random on
        notify-send -u low -t 1500 "MPD" "Shuffle switched on"
    else
        mpc random off
        notify-send -u low -t 1500 "MPD" "Shuffle switched off"
    fi
}

function mpd_status
{
    notify-send -u low -t 4000 "MPD" "<b>$(mpc --format '%artist% - %album% - %title%'| head -n 1)</b>
$(mpc | head -n 3 | tail -n 2)"
}

$1

Last edited by Andrwe (2009-09-14 14:55:05)

Offline

#4 2009-09-14 15:13:38

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Dmenu Hacking Thread

In honor of Brisbin33, Here's his code for launching dmenu with a frequency-of-use based caching feature.  It uses .dmenurc, which contains the dmenu command with the arguments you want so it can be sourced with multiple instances (uses) of dmenu.

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
  . $HOME/.dmenurc
else
  DMENU='dmenu -i'
fi

TERMI='urxvt -e bash -lic'
CACHE="$HOME/.dmenu_cache_recent"

touch $CACHE
MOST_USED=$(LC_ALL="C"; sort $CACHE | uniq -c | sort -r | colrm 1 8)
RUN=$( (echo "$MOST_USED"; dmenu_path | grep -vxF "$MOST_USED") | $DMENU) && \n(echo $RUN; head -n99 $CACHE) > $CACHE.$$ && \nmv $CACHE.$$ $CACHE

case $RUN in
    *\;) $TERMI ${RUN/;/} & ;;
    *)   $RUN &             ;;
esac

exit 0

.dmenurc:

# makes dmenu identical across all scripts by sourcing this file
# aur/dmenu-vertical-xft required for xft fonts

DMENU='dmenu -i -fn xft:Inconsolata-10 -r -x 0 -y 17 -nb #303030 -nf #909090 -sb #909090 -sf #303030'

What would be really cool is generalizing the caching script so any use of dmenu could use it (have different caches) -- for example -- normal dmenu, snippy, mpc playlist launcher.

Scott

Offline

#5 2009-09-14 15:32:37

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

Re: Dmenu Hacking Thread

well, i seem to be all over this thread smile.

anyways, here's my mpd script as linked to in the OP.  hope no one minds the cross-post.

it can accept search parameters or 'all' to put up the whole playlist (i.e. when launched via keybinding).

and of course, it uses my patented $HOME/.dmenurc idea.

example:
  msearch a love supreme
  msearch led zeppelin
  msearch all

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
  . $HOME/.dmenurc
else
  DMENU='dmenu -i'
fi

if [ "$*" = "all" ]; then
  mpc --no-status play $(mpc playlist --format '%title% by %artist%' | cut -c 2- | sed 's/)/ -/g' | $DMENU | awk '{print $1}')
else
  mpc --no-status play $(mpc playlist --format '%title% by %artist% #| %album%' | cut -c 2- | sed 's/)/ -/g' | grep -i "$*" | cut -d '|' -f 1 | $DMENU | awk '{print $1}')
fi

and in the interest of full disclosure, the launch script posted by firecat was a slight variation on b3n's bash version of o_no_hu's launch.py python script found here.

Offline

#6 2009-09-14 15:56:59

SpeedVin
Member
From: Poland
Registered: 2009-04-29
Posts: 955

Re: Dmenu Hacking Thread

Here is a script for go up option:

alias up='cd "$(ls -d */ | dmenu -fn glisp -nb "#100" -nf "#b9c0af" -sb "#000" -sf "#afff2f" -i)"'

You could rmove -d */ and change cd with rm and this alias script with delate following files.
It's really simple wink


Shell Scripter | C/C++/Python/Java Coder | ZSH

Offline

#7 2009-09-14 18:17:21

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Dmenu Hacking Thread

I picked this up somewhere in the wild...a netcfg profile selector:

#!/bin/sh

nf='#888888'
nb='#2a2a2a'
sf='#ffffff'
sb='#2a2a2a'
font='-*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*'
dmenucmd="dmenu -fn $font -nb $nb -nf $nf -sb $sb -sf $sf"

netprof=`ls -1 /etc/network.d | $dmenucmd $*` 
if [ "x$netprof" != "x" ]; then
    /usr/bin/sudo /usr/bin/netcfg2 -a
    /usr/bin/sudo /usr/bin/netcfg2 $netprof
fi

thayer williams ~ cinderwick.ca

Offline

#8 2009-09-14 19:04:54

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

Re: Dmenu Hacking Thread

Here is my launcher script again. Start with some entries in ~/.dddmenu, anything new entered will be added.

#!/bin/dash
newentry=$( dmenu -xs -i -l 5 -rs -ni -p ":" < ~/.dddmenu)
[ -z "$newentry" ] && exit
[ -z "$( (cat ~/.dddmenu; echo "$newentry") | sort | uniq -d)" ] && echo "$newentry" >> ~/.dddmenu
eval setsid setsid $newentry

Offline

#9 2009-09-14 19:32:49

Andrwe
Member
From: Leipzig/Germany
Registered: 2009-06-17
Posts: 322
Website

Re: Dmenu Hacking Thread

I want to add dmenfm.
For all who doesn't know it it's a filemanager based on dmenu and can be found in aur.
Although I don't have written it I think it should be mentioned here and with adding some options you can easily get a vertical version of it.

Offline

#10 2009-10-28 11:22:09

Ghost1227
Forum Fellow
From: Omaha, NE, USA
Registered: 2008-04-21
Posts: 1,422
Website

Re: Dmenu Hacking Thread

Here's my crappy addition to the collection. I wanted a script that would allow me to include only certain apps in dmenu's list... here's what I came up with.

#!/bin/bash

addlauncher() {
    if [[ -z $app ]]; then
        echo "dmlauncher: error: missing required argument"
        return 1
    fi

    if which $app &>/dev/null; then
        if [[ -L $HOME/.dmlcache/$ln ]]; then
            echo "dmlauncher: error: \"$link\" launcher already exists"
            return 1
        else
            ln -s $(which $app) $HOME/.dmlcache/$link
            return 0
        fi
    else
        echo "dmlauncher: error: \"$link\" not found in \$PATH"
        return 1
    fi
}

dellauncher() {
    if [[ -L $HOME/.dmlcache/$app ]]; then
        rm -f $HOME/.dmlcache/$app
        return 0
    else
        echo "dmlauncher: error: \"$app\" launcher not found"
        return 1
    fi
}

usage() {
    echo "usage: dmlauncher [-a <program>] || [-d <program>] ||"
    echo "       [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]"
    echo "       [-p <prompt>] [-sb <color>] [-sf <color>] [-v]"
    return 0
}

dmlrun() {
    exe=`ls $HOME/.dmlcache | dmenu $opt` && exec $exe
}

case "$1" in
    '-a'|'--add')
    app=$2
    if [ ! -z $3 ]; then
        link=$3
    else
        link=$app
    fi
    addlauncher
    ;;
    '-d'|'--del')
    app=$2
    dellauncher
    ;;
    '-h'|'--help')
    usage
    ;;
    *)
    opt=$@
    dmlrun
    ;;
esac

Last edited by Ghost1227 (2009-10-28 18:35:08)


.:[My Blog] || [My GitHub]:.

Offline

#11 2009-10-29 18:47:59

abijr
Member
Registered: 2008-05-18
Posts: 71

Re: Dmenu Hacking Thread

Is it possible to make a dmenu calculator?
For something like Alt-C  | 8 * 5 |  = 40
?
Or is it better to use another app?

Offline

#12 2009-10-29 19:05:01

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

Re: Dmenu Hacking Thread

@abijr:

xsel -o | dmenu -p Calculate: | xargs echo | bc 2>&1 | dmenu -p Answer: | xsel -i

edit: added selection clipboard and start with xsel -o (instead of just echo), so if you run it multiple times you can continue with the last answer (press TAB), and added relaying bc's error messages.

Last edited by Procyon (2009-10-29 19:12:43)

Offline

#13 2009-10-30 00:02:05

abijr
Member
Registered: 2008-05-18
Posts: 71

Re: Dmenu Hacking Thread

@Procyon
Thanks, I tried right away...
It's just that I can't get it to work... sad
It's supposed to get the input from selection and output the results to clipboard, right?
Anyways I run the script with no selection and input
8*5 TAB (or RETURN)
and nothing happens....

Edit:

This works ok:

xsel -o | dmenu -p Calculate: | xargs echo | calc -p | xargs dmenu -p

Last edited by abijr (2009-10-30 00:25:10)

Offline

#14 2009-10-30 01:22:29

abijr
Member
Registered: 2008-05-18
Posts: 71

Re: Dmenu Hacking Thread

I got it!
Hope it works for you guys like it did for me... smile

#!/bin/bash
 
CM1=`xsel -o`
CM2=`echo $CM1 | dmenu -p Calc: | calc -p`
echo $CM2 | xsel -i | echo $CM2 | dmenu -p Ans:

Offline

#15 2010-03-07 13:02:52

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 681
Website

Re: Dmenu Hacking Thread

Google search with History.  I bind it to my keyboards search button

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
  . $HOME/.dmenurc
else
  DMENU='dmenu -i'
fi

GS=`cat ~/.gshist | $DMENU $*`

if grep -q "$GS" "$HOME/.gshist" ; then
    echo already exists in history
else
    echo $GS >> ~/.gshist
fi

firefox -new-window http://www.google.co.uk/search?q="$GS"

Offline

#16 2010-06-18 14:19:01

djpohly
Member
Registered: 2007-08-14
Posts: 24

Re: Dmenu Hacking Thread

I like to use dmenu as a general-purpose input dialog for things.  This is a simple password-prompt suitable for use with sudo's askpass.  Mostly self-explanatory.

~/bin/dpass

#! /bin/sh
dmenu -p "$1" -fa 'Consolas:size=10' -nf '#204a87' -nb '#204a87' -sf black -sb '#babdb6' <&- && echo

<&- closes stdin and gives us an easy empty dmenu. && echo is because dmenu doesn't output with a newline, which sudo expects. FG and BG colors are the same so your password doesn't show (though a -S "secure" option in dmenu might be nice). Now you can do something nifty like... root dmenu!

in xmonad.hs:

, (modm .|. shiftMask, xK_r), spawn $ "exe=`dmenu_path | dmenu` && eval \"exec sudo -A $exe\"")

in .xinitrc:

export SUDO_ASKPASS="$HOME/bin/dpass"

Have fun!

(N.B.: if you use xcompmgr or cairo-compmgr with any map/unmap effects, it can cause the second dmenu to be invisible.  You can add a sleep statement to the top of ~/bin/dpass and tweak the time parameter until the password prompt shows up.)

Offline

#17 2010-07-29 06:23:37

supulton
Member
Registered: 2008-12-31
Posts: 58

Re: Dmenu Hacking Thread

firecat53 wrote:

In honor of Brisbin33, Here's his code for launching dmenu with a frequency-of-use based caching feature.  It uses .dmenurc, which contains the dmenu command with the arguments you want so it can be sourced with multiple instances (uses) of dmenu.

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
  . $HOME/.dmenurc
else
  DMENU='dmenu -i'
fi

TERMI='urxvt -e bash -lic'
CACHE="$HOME/.dmenu_cache_recent"

touch $CACHE
MOST_USED=$(LC_ALL="C"; sort $CACHE | uniq -c | sort -r | colrm 1 8)
RUN=$( (echo "$MOST_USED"; dmenu_path | grep -vxF "$MOST_USED") | $DMENU) && \n(echo $RUN; head -n99 $CACHE) > $CACHE.$$ && \nmv $CACHE.$$ $CACHE

case $RUN in
    *\;) $TERMI ${RUN/;/} & ;;
    *)   $RUN &             ;;
esac

exit 0

.dmenurc:

# makes dmenu identical across all scripts by sourcing this file
# aur/dmenu-vertical-xft required for xft fonts

DMENU='dmenu -i -fn xft:Inconsolata-10 -r -x 0 -y 17 -nb #303030 -nf #909090 -sb #909090 -sf #303030'

What would be really cool is generalizing the caching script so any use of dmenu could use it (have different caches) -- for example -- normal dmenu, snippy, mpc playlist launcher.

Scott

you'll want to use "sort -nr" as opposed to "sort -r", since it will handle cases over 10. smile

Offline

#18 2010-08-07 13:01:54

botzoboy
Member
From: Romania/Deutschland
Registered: 2010-02-03
Posts: 90

Re: Dmenu Hacking Thread

I found this dmenu script http://urukrama.pastebin.com/f74ca72ac from urukrama blog but I can't make it to work. Is anyone nice with bash skils to make this work. thanks!

Offline

#19 2010-08-07 14:15:57

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

Re: Dmenu Hacking Thread

Well for starters, you'll need to change the "/home/urukrama/" to whatever your home folder is. Thenhave a look at the editor, "mousepad". Have you installed it? Maybe you want another editor.
(Further you probably won't have all those applications installed, so having a script to start an editor with their config files does not make too much sense,, unless you'll edit those lines a lot and make your own list of files you regularly want to edit.)

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

#20 2010-08-07 14:30:15

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

Re: Dmenu Hacking Thread

Using some dmenu scripts along with clipbored (a clipboard manager running as a daemon), (http://github.com/trapd00r/clipbored), like http://github.com/trapd00r/clipbored/bl … /dmenuclip and http://github.com/trapd00r/clipbored/bl … ts/dmenurl .

Offline

#21 2010-08-07 17:33:48

botzoboy
Member
From: Romania/Deutschland
Registered: 2010-02-03
Posts: 90

Re: Dmenu Hacking Thread

Can't get it to work. Anyway thanks!

Offline

#22 2010-08-09 18:46:26

tlvince
Member
Registered: 2010-07-06
Posts: 68
Website

Re: Dmenu Hacking Thread

Inspired by this thread, I've put together dmenu-tools which aims to be a consistent suite of dmenu-powered scripts. Since dmenu is so flexible, the goal is to open it up as community-driven repository, so please let me know what you think.

@botzoboy: check out dmenu-edit.  My "edit-list" looks like this:

~/.bashrc
~/.Xdefaults
~/.Xmodmap
~/.xinitrc
~/.nanorc
~/.xmonad/xmonad.hs
~/.config/openbox/rc.xml
/etc/rc.conf

Offline

#23 2010-08-09 20:40:43

botzoboy
Member
From: Romania/Deutschland
Registered: 2010-02-03
Posts: 90

Re: Dmenu Hacking Thread

Nice work tlvince:
Thanks!

Offline

#24 2010-12-14 05:02:22

Digit
Member
Registered: 2008-04-28
Posts: 71

Re: Dmenu Hacking Thread

more bits n bobs from around the forum.

https://bbs.archlinux.org/viewtopic.php?id=95345 clipbored - daemon that collects all X clipboard buffers - use w dmenu   ... as fundamentally handy as dcalculator, thnx.
https://bbs.archlinux.org/viewtopic.php?id=62299 HAL Storage Devices Mount Script (dmenu)  ... nothing fancy or fun, just plain useful.
https://bbs.archlinux.org/viewtopic.php?id=49904 "dmenu help!!"   ... has some useful scripts and other links.
https://bbs.archlinux.org/viewtopic.php?id=61017 controlling mpd via dmenu   ... has some other stuff on this not yet mentioned in this thread.
https://bbs.archlinux.org/viewtopic.php?id=86222 Clutter Dmenu   ... idk... thought i'd include it for posterity n whatever.
https://bbs.archlinux.org/viewtopic.php?id=90492 size dmenu  ... and some other helpful tips
https://bbs.archlinux.org/viewtopic.php?id=95984 create a dmenu custom menu  ... mmm, sounds nice. smile

i'm still getting to grips with making my own, but for the most part, it seems if u know a little bash, you're already more than half way there to being able to fiddle about to make your dmenu do all sorts of tricks. 
... still havnt quite figured out how to change the colour of anything but the default yet though.   fun trying for my preference of colours in dcalculator though.  ^_^


fave quote of the mo': "Man's reach should exceed his grasp, else what's a heaven for." - Robert Browning

Offline

#25 2010-12-30 09:25:52

Digit
Member
Registered: 2008-04-28
Posts: 71

Re: Dmenu Hacking Thread

i was trying to figure out how to make a dmenus rss script... but i think i'm lacking too many pieces of the jigsaw to make a proper job of it yet, so i thought i'd ask...  anyone got any ideas how that might be achieved?  rss through dmenu?


fave quote of the mo': "Man's reach should exceed his grasp, else what's a heaven for." - Robert Browning

Offline

Board footer

Powered by FluxBB