You are not logged in.

#201 2013-10-04 00:26:25

mrinx
Member
From: Richmond, VA
Registered: 2013-08-01
Posts: 87
Website

Re: Dmenu Hacking Thread

I'm starting to be off-topic here, but I'll post my solution anyway in case that somebody else has similar problem. As a workaround, I wrote a short script. I believe there is more elegant solution, but this works for me:

/usr/bin/gajim-run

#!/bin/bash
urxvt -e nohup gajim &

English isn't my first language.
Is Arch Linux user called archer? Where are our bows and arrows?

Offline

#202 2013-10-04 17:13:32

cris9288
Member
Registered: 2013-01-07
Posts: 348

Re: Dmenu Hacking Thread

I'm not much of a bash scripter, but I've put together a few simple scripts inspired by this thread. I'd appreciate any pointers on how I could improve my scripting skills. Hope someone finds these useful/not terrible:

mpd quick play

#!/bin/bash

if [ -f $HOME/.dmenurc ];then
   source $HOME/.dmenurc
   DMENU="$DMENU -p 'MPD Quick Play'"
else
   DMENU="dmenu -i -p 'MPD Quick Play'"
fi

mpc -q clear;

RESULTS=$(mpc listall | eval $DMENU)

if [ $? -eq 0 ]; then
   mpc -q add "$RESULTS";
   mpc -q play
fi

exit

add and play a song, artist, or album from mpd. I might figure out a way of making "mpc clear" an optional flag

#!/bin/bash

mpc -q clear

if [ -f $HOME/.dmenurc ]; then
   source $HOME/.dmenurc
   DMENU="$DMENU -p 'MPD add'"
else
   DMENU="dmenu -i"
fi

QUERY_TYPES="artist
album
title"

QUERY_TYPE=$(echo "$QUERY_TYPES" | eval $DMENU)

if [ $? -eq 0 ]; then
   RESULTS=$( mpc -q list "$QUERY_TYPE" | eval $DMENU )
   if [ $? -eq 0 ]; then
      mpc -q findadd "$QUERY_TYPE" "$RESULTS"
      mpc -q play
   fi
fi

edit frequently edited files

#!/bin/bash


if [ -f $HOME/.dmenurc ];then
   source  $HOME/.dmenurc
   DMENU="$DMENU -p 'System Configuration'"
else
   DMENU="dmenu -i -p 'System Configuration'"
fi

FILE=$(cat $HOME/.dmenu_editrc | eval $DMENU)

if [ $? -eq 0 ]; then
   OWNER=$(stat -c %U $FILE)

   if [ "$OWNER" == "root" ];then
      urxvtc -e sudo vim $FILE
   else
      urxvtc -e vim $FILE
   fi
fi

simple session menu

#!/bin/bash

if [ -f $HOME/.dmenurc ];then
   source $HOME/.dmenurc
   DMENU="$DMENU -p 'Session Menu'"
else
   DMENU="dmenu -i -p 'Session Menu'"
fi

CMD=$(echo "logout
poweroff
suspend
reboot" | eval $DMENU)


if [ $? -eq 0 ]; then
   if [ "$CMD" == logout ];then
      i3 exit
   else
      systemctl $CMD
   fi
fi

Offline

#203 2013-10-05 01:43:11

dz
Member
Registered: 2013-08-21
Posts: 16

Re: Dmenu Hacking Thread

mrinx wrote:

I'm starting to be off-topic here, but I'll post my solution anyway in case that somebody else has similar problem. As a workaround, I wrote a short script. I believe there is more elegant solution, but this works for me:

/usr/bin/gajim-run

#!/bin/bash
urxvt -e nohup gajim &

My guess is that dmenu_run is running from /bin/sh, but urxvt uses your login shell, which has a different PATH or doesn't have the function defined.

Offline

#204 2013-10-08 15:35:11

mrinx
Member
From: Richmond, VA
Registered: 2013-08-01
Posts: 87
Website

Re: Dmenu Hacking Thread

dz wrote:

My guess is that dmenu_run is running from /bin/sh, but urxvt uses your login shell, which has a different PATH or doesn't have the function defined.

I wish it was so simple. I guess it's a bug in gajim, I want to report it later (it's just driving me crazy, that I need to have bigillion different accounts for reporting bugs). The gajim actually starts even from dmenu_run, but then it just exits (no window appears). PATH should be the same, as I already checked it before.


English isn't my first language.
Is Arch Linux user called archer? Where are our bows and arrows?

Offline

#205 2013-10-08 15:46:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,422
Website

Re: Dmenu Hacking Thread

FWIW, I just tried out gajim and I could not replicate this problem - it works as expected here whether launched from a terminal, from interrobang (was curious if my launcher worked better than dmenu), and from dmenu_run.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#206 2013-10-08 16:25:48

mrinx
Member
From: Richmond, VA
Registered: 2013-08-01
Posts: 87
Website

Re: Dmenu Hacking Thread

Trilby wrote:

FWIW, I just tried out gajim and I could not replicate this problem - it works as expected here whether launched from a terminal, from interrobang (was curious if my launcher worked better than dmenu), and from dmenu_run.

May I just ask, how you start your dmenu_run?


English isn't my first language.
Is Arch Linux user called archer? Where are our bows and arrows?

Offline

#207 2013-10-08 17:51:36

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,422
Website

Re: Dmenu Hacking Thread

Either from a terminal, or from a keybinding - it worked either way for me.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#208 2013-10-09 21:15:48

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: Dmenu Hacking Thread

goa is a new Bash script which uses dmenu to open files with any desktop application or executable available on the system (in standard locations and $PATH).
wink

Offline

#209 2013-10-11 12:23:45

mrinx
Member
From: Richmond, VA
Registered: 2013-08-01
Posts: 87
Website

Re: Dmenu Hacking Thread

Trilby wrote:

Either from a terminal, or from a keybinding - it worked either way for me.

I gave up and installed xkeybindings to control my shortcuts and everything works now, there was probably some problem with interthread communication (or something related to passing SIGCHLD). Thank you for your help smile


English isn't my first language.
Is Arch Linux user called archer? Where are our bows and arrows?

Offline

#210 2013-11-05 19:23:11

joksnet
Member
From: Paris, France
Registered: 2010-11-21
Posts: 5

Re: Dmenu Hacking Thread

I made a new version of `dmenu_recent` that will not populate commands and will add them the first time you use it.

#!/bin/sh
#
# Copyright (C)  2013  Juan M Martínez
# Based on dmenu_recent by Mina Nagy
# Based on code by Dieter Plaetinck
#

MAX_RECENT=199

DMENU="dmenu $DMENU_OPTIONS"
if [[ -f "$HOME/.dmenurc" ]]; then
        . $HOME/.dmenurc
fi

if [[ -z "$TERMINAL" ]]; then
        if which i3-sensitive-terminal &> /dev/null; then
                TERMINAL='i3-sensitive-terminal -e'
        else
                TERMINAL='xterm -e'
        fi
fi

CACHEDIR=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$CACHEDIR" ]; then
        CACHE=$CACHEDIR/dmenu_recent
else
        CACHE=$HOME/.dmenu_recent
fi

touch $CACHE

CMDS=""
while read LINE; do
        CMDS="$CMDS${LINE:2}\n"
done < "$CACHE"

RET=$(echo -e "$CMDS" | $DMENU "$@")
CMD=${RET%% *}

[[ -z "$CMD" ]] && exit
which "$CMD" &> /dev/null || exit

if TMP=$(grep "$CMD" "$CACHE"); then
        TYPE=${TMP:0:1}
        CMD="$TMP"
else
        TYPE=$(echo -e "X\nT" | $DMENU -p '404. Type:')
        CMD="$TYPE:$CMD"
fi

echo "$CMD" > "$CACHE~"
grep -vx "$CMD" "$CACHE" | head -n $MAX_RECENT >> "$CACHE~"
mv "$CACHE~" "$CACHE"

[[ "$TYPE" = "X" ]] && ${SHELL:-"/bin/sh"} -c "$RET"
[[ "$TYPE" = "T" ]] && ${SHELL:-"/bin/sh"} -c "$TERMINAL $RET"

Improvements welcome.


Juan Manuel

Offline

#211 2013-11-24 09:21:41

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Dmenu Hacking Thread

I adapted Army's wrapper for locate to suit my needs:

#!/bin/bash

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

input="$(xsel -o | $DMENU -p "file search:")"
[[ -z "$input" || $? -ne 0 ]] && exit 1

result="$(echo "$input" | locate -e -i -r "$input")"
while [[ -z "$result" ]]; do
    input="$($DMENU -p "[1] file search:" <&- )"
    [[ -z "$input" || $? -ne 0 ]] && exit 1
    result="$(echo "$input" | locate -e -i -r "$input")"
done
result="$(echo "$result" | sed -e 's,'"${HOME}"',~,g' | $DMENU -l 8 -p "search result:")"

if [[ "$result" && $? -eq 0 ]]; then
    result="$(echo "$result" | sed -e 's,^~/,'"${HOME}/"',g')"
    if [[ -f "$result" ]]; then
	xdg-open "$result"
    elif [[ -d "$result" ]]; then
	urxvt -e ranger "$result"
    fi
fi

This allows for a new search when nothing has been found and the presented paths get shorter by substituting $HOME with ~ in the GUI.
Also when selecting a directory, then ranger is chosen to "open" it instead of xdg-open. (Actually I don't remember if xdg-open cares for directories...) This is quite neat: when browsing the results of the search I may choose to open the directory containing a file by pressing TAB, deleting the basename and pressing Shift-Return.

I bound the script to Mod4+F1, it's a very useful little helper.

Last edited by ball (2013-11-24 09:30:30)

Offline

#212 2013-11-24 10:35:58

sekret
Member
Registered: 2013-07-22
Posts: 283

Re: Dmenu Hacking Thread

Quick question: Isn't

input="$(xsel -o | $DMENU -p "file search:")"
[[ -z "$input" || $? -ne 0 ]] && exit 1

the same as

input="$(xsel -o | $DMENU -p "file search:")" || exit 1

?

But a nice script indeed!

Offline

#213 2013-11-24 10:57:03

ball
Member
From: Germany
Registered: 2011-12-23
Posts: 164

Re: Dmenu Hacking Thread

@sekret: Yeah probably, thanks :-D (I don't really know any bash...)

Offline

#214 2013-12-03 04:58:40

bb010g
Member
Registered: 2012-08-08
Posts: 16
Website

Re: Dmenu Hacking Thread

One liner to set your PulseAudio volume and mute/unmute with dmenu and ponymix (I have it mapped to mod-v in xmonad):

dmenu -p 'Set volume %:' <<< "$(ponymix get-volume)"$'\n'"mute" | sed -n '/^[1-9]\?[0-9]$\|100\|^mute$/{s/[1-9]\?[0-9]\|100/ponymix set-volume &/ep; s/mute/ponymix toggle/ep; q}; q1'

(Sorry if you've seen this before, but I somehow missed this thread when I was looking for it (derp))


date '+%A, %B %d, %Y %T' | pig | figlet | cowsay -n

Offline

#215 2013-12-06 07:46:46

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

Re: Dmenu Hacking Thread

Is someone sourcing custom aliases and functions to run with dmenu and can show me how he did it?

Offline

#216 2014-01-02 06:41:04

likytau
Member
Registered: 2012-09-02
Posts: 142

Re: Dmenu Hacking Thread

orschiro wrote:

Is someone sourcing custom aliases and functions to run with dmenu and can show me how he did it?

Aliases cannot be directly executed in that way AFAICS.
Functions work like any normal command.

Consider this:

#!/bin/sh
foo ()
{
  echo fooed
}

alias bar='echo barred'

WHICH=$(echo -e foo\\nbar |dmenu)
$WHICH

foo succeeds, bar fails.
This is true whether they reside in an external file that you source, or not.

Offline

#217 2014-01-02 07:47:28

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

Re: Dmenu Hacking Thread

@likytau

Thanks. I was looking for a solution that allows me to store aliases and functions in an external file.

The solution I came up with is a simple script which replaces the default "dmenu_run".

I added the customised script to the AUR: https://aur.archlinux.org/packages/dmenu-aliases/

Offline

#218 2014-01-13 01:29:59

kniren
Member
Registered: 2011-10-12
Posts: 40

Re: Dmenu Hacking Thread

Inspired by cris9288's scripts, I decided to do some improvements over them. This is the result, dmpd. Where you can select the music of your library and play it by artist, album or title. If called with the argument --control, you get access to the interface to control mpd through dmenu, being able to play, pause, go to the next song, etc.

#!/bin/bash
# ------------------------------------------------------------------
#
#     Scripts/dmpd
#     Description: Search your MPD library and control it through dmenu 
#     Author: Alex Sánchez <kniren@gmail.com>
#
# ------------------------------------------------------------------

# Check the existence of .dmenurc and sources it. This file contains the OPTIONS
# variable, for example:
#
#   OPTIONS='-i -h 20 -fn profont-8 -sb #c90c25 -nb #000000'
#
# Call the script with '--control' to open the mpd control dmenu, where you can
# play, pause, stop, go the next song, etc.

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


if [[ $# -ne 0 ]]; then
    if [[ "$1" == "--control" ]]; then
        QUERY_TYPES='Play
Pause
Next
Previous
Stop
Add
'
        while true
        do
            PROMPT="MPD"
            SELECT=$(echo "$QUERY_TYPES" | $DMENU"$PROMPT" )
            case "$SELECT" in
                "Play")
                    mpc play
                    ;;
                "Pause")
                    mpc pause
                    ;;
                "Next")
                    mpc next
                    ;;
                "Previous")
                    mpc prev
                    ;;
                "Stop")
                    mpc stop
                    ;;
                "Add")
                    break
                    ;;
                *)
                    exit 1
                    ;;
            esac
        done
    fi
fi

QUERY_TYPES='Artist
Album
Title'

while true
do
    PROMPT="Search Music"
    QUERY_TYPE=$(echo "$QUERY_TYPES" | $DMENU"$PROMPT" )

    ERR=$?
    case "$QUERY_TYPE" in
        "Artist" |"Album" | "Title")
            ;;
        *)
            exit 1
            ;;
    esac

    if [ $ERR -eq 0 ]; then
        PROMPT=$QUERY_TYPE
        RESULTS=$( mpc -q list "$QUERY_TYPE" | $DMENU"$PROMPT" )
        ERR=$?
        MATCH=$( mpc -q list "$QUERY_TYPE" | grep "$RESULTS")
        if [[ -z "$MATCH" ]]; then
            exit 1
        fi
        if [ $ERR -eq 0 ]; then
            if [ $QUERY_TYPE = "Artist" ]; then
                ALBUM=$( echo -e "/Play All\n$( mpc ls "$RESULTS" )" | awk -F "/" '{print $2;}' | $DMENU"$RESULTS" )
                ERR=$?
                if [ $ERR -eq 1 ]; then
                    continue 
                fi
                if [ "$ALBUM" != "Play All"  ]; then
                    MATCH=$( mpc ls "$RESULTS" | grep "$ALBUM")
                    if [[ -z "$MATCH" ]]; then
                        exit 1
                    fi
                    QUERY_TYPE="Album"
                    RESULTS="$ALBUM"
                fi
            fi
            mpc -q clear
            mpc -q findadd "$QUERY_TYPE" "$RESULTS"
            mpc -q play
            exit 0
        fi
    else
        exit 1
    fi
done

Also available on https://github.com/kniren/Scripts/blob/master/dmpd


Archlinux :: Xmonad
dotfiles | deviantart

Offline

#219 2014-01-28 00:56:08

AnSnarkista
Member
Registered: 2013-04-17
Posts: 14

Re: Dmenu Hacking Thread

I am using dmenu_recent and I think is awesome! But I don't understand the difference between "terminal" and "terminal_hold", and it is maybe because I have changed the terminal to lxterminal, and something is wrong there. I don't have any skills on scripting, I am trying changing code in a VBox...but I can't get the point.

Thanks a lot for that script!

Offline

#220 2014-01-28 06:07:38

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

Re: Dmenu Hacking Thread

@AnSnarkista

I am hearing about dmenu_recent for the first time. Can you point me to more information?

Offline

#221 2014-01-28 08:02:57

ninian
Member
From: United Kingdom
Registered: 2008-02-24
Posts: 726
Website

Re: Dmenu Hacking Thread

orschiro wrote:

@AnSnarkista

I am hearing about dmenu_recent for the first time. Can you point me to more information?

For my fyr launcher, I implemented ordering of the menu by either usage frequency or recency. If you are interested in the code, have a look at the bottom of the fyr script, in the section headed 'Menu of fyr's own launchers'.
wink

Offline

#222 2014-01-28 09:29:34

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Dmenu Hacking Thread

AnSnarkista wrote:

I am using dmenu_recent and I think is awesome! But I don't understand the difference between "terminal" and "terminal_hold", and it is maybe because I have changed the terminal to lxterminal, and something is wrong there. I don't have any skills on scripting, I am trying changing code in a VBox...but I can't get the point.

Thanks a lot for that script!

terminal_hold doesn't close the terminal window when the application ends - terminal on its own will close when the application ends.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#223 2014-01-28 09:30:47

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Dmenu Hacking Thread

orschiro wrote:

@AnSnarkista

I am hearing about dmenu_recent for the first time. Can you point me to more information?

There's two versions further up this thread. I haven't tried the second version, so can't comment on that one, but use the earlier version with success.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#224 2014-01-29 03:53:28

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Dmenu Hacking Thread

made a pavucontrol equivalent in dmenu. (you can move clients to sinks and set volume for input-sinks)

#!/bin/bash

source $HOME/.config/teiler/config

function dmenu_t () {
    if [ "$dmenu_trans" == "1" ]; then
        dmenu -o 0.9 -l 20 -fn "$font" -nf "$nf" -nb "$nb" -sf "$sf" -sb "$sb"
    else
        dmenu -l 20 -fn "$font" -nf "$nf" -nb "$nb" -sf "$sf" -sb "$sb"
    fi
}


case $1 in
    -vol)
        shift
        client=$(pacmd list-sink-inputs | grep -E 'client:|index:' | awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }'| awk '{print $2" "substr($0, index($0,$5))}' | dmenu_t -p "Clients:" $@)
        levels="0
10
20
30
40
50
60
70
80
90
100"
        volume=$(echo "$levels"|dmenu_t -p "Volume:" $@)
        set_vol=$(echo "scale=1; $volume / 100 * 65536" | bc)
        bla=$(echo $client | awk '{print $1}')
        blub=$(echo ${set_vol%.*})
        pacmd set-sink-input-volume $bla $blub

    ;;
    -sink)
        shift
        source $HOME/.config/teiler/config
        client=$(pacmd list-sink-inputs | grep -E 'client:|index:' | awk 'NR % 2 == 1 { o=$0 ; next } { print o " " $0 }'| awk '{print $2" "substr($0, index($0,$5))}' | dmenu_t -p "Clients:" $@)
        sink=$(pacmd list-sinks | grep name: | awk 'gsub(">$","")' | cut -c 9- | dmenu_t -p "Sink" $@)
        pacmd move-sink-input $(echo "$client" | awk '{print $1}') $(echo $sink)
    ;;
    *)
esac

the sourced config:

#Choose 0 if your dmenu has no transparency support
dmenu_trans=0

#Font that is used for dmenu
font="PragmataPro-10"

#Foreground color for dmenu/dzen2
nf="#a0a0a0"

#background color for dmenu/dzen2
nb="#000000"

#foreground active color for dmenu/dzen2
sf="#FFFFFF"

#background active color for dmenu/dzen2
sb="#0C73C2"

He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

#225 2014-01-29 03:55:24

Rasi
Member
From: Germany
Registered: 2007-08-14
Posts: 1,914
Website

Re: Dmenu Hacking Thread

And my very simple mpd script. You can add/insert/replace albums or tracks.

#!/bin/bash
source $HOME/.config/dplay/config
function dmenu_t () {
    if [ "$dmenu_trans" == "1" ]; then
        dmenu -o 0.9 -i -l 20 -fn "$font" -nf "$nf" -nb "$nb" -sf "$sf" -sb "$sb"
    else
        dmenu -i -l 20 -fn "$font" -nf "$nf" -nb "$nb" -sf "$sf" -sb "$sb"
    fi
}

case $1 in
    -a)
     ALBUM=$(echo -e "$(mpc list album)" | dmenu_t -p "$2 Album:");
     if [[ "$ALBUM" = "" ]]
         then echo "no selection made"
     else
         if [[ $2 == replace ]]
           then mpc clear
                mpc find album "$ALBUM" | mpc add && mpc play;
         elif [[ $2 == insert ]]
            then mpc find album "$ALBUM" | mpc insert;
         else mpc find album "$ALBUM" | mpc add;
         fi
     fi
;;
    -t)
     TRACK=$(echo -e "$(mpc listall)" | dmenu_t -p "$2 Track:");
     if [[ "$TRACK" = "" ]]
         then echo "no selection made"
     else
         if [[ $2 == replace ]]
           then mpc clear
                mpc add "$TRACK" && mpc play;
         elif [[ $2 == insert ]]
           then mpc insert "$TRACK";
         else mpc add "$TRACK";
         fi
     fi
;;
*)
esac

Last edited by Rasi (2014-01-29 04:03:54)


He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.

Douglas Adams

Offline

Board footer

Powered by FluxBB