You are not logged in.

#26 2011-03-21 06:37:29

xj9578cd
Member
Registered: 2011-03-21
Posts: 3

Re: Dmenu Hacking Thread

I had an idea to search the internet from DMENU like surfraw.

surfraw ixquick -browser=firefox

But incorporating the search terms into the command line is difficult. It would be nice to make some alias like "x" then one could type "x my_term" in the DMENU and open firefox with the term searched already. I use Xmonad and vimperator, and this edition to DMENu would be neat.

update:

Okay, I modified Red Dwarf's script for google uk and it works with surfraw. Still working on it. I was having trouble because I just installed on a new laptop and forgot to export my surfraw path in .bashrc (export PATH="/usr/lib/surfraw:$PATH")!  It wouldnt work until I did that.

#!/bin/bash

if [ -f $HOME/.dmenurc ]; then
  . $HOME/.dmenurc
else
  DMENU='dmenu -nb #fffab2 -nf #2d73b9 -sf green -fn '-*-courier-bold-r-*-*-12-*-*-*-*-*-*-*' -i'
fi

SS=`cat ~/.sshist | $DMENU $*`

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

surfraw ixquick -browser=firefox -new=yes "$SS"

Still working on it, to run a variable with different search engines from dmenu. For now you have to edit the script to change search engine.

Last edited by xj9578cd (2011-03-22 05:01:57)

Offline

#27 2011-05-10 03:39:26

k3ttc4r
Member
From: around somewhere
Registered: 2008-12-28
Posts: 137
Website

Re: Dmenu Hacking Thread

Got another script to control MPD. Whipped this up prettly quickly  last night, somebody wanted something like this.

First it let's you pick an artist, and after selecting one, another instance of dmenu opens wich let's you pick an album to play, or decide to play all by that artist (given your music is stored like /musicdir/artist/album).

#!/bin/bash

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

ARTIST=$( mpc ls | $DMENU )

if [[ $ARTIST == "" ]]; then
  exit 1
else
  ALBUM=$( echo -e "Play All\n$( mpc ls "$ARTIST" )" | $DMENU )

  if [[ $ALBUM == "" ]]; then
    exit 1
  else
    mpc clear
    if [[ $ALBUM == "Play All" ]]; then
      mpc add "$ARTIST"
    else
      mpc add "$ALBUM"
    fi
    mpc play
  fi
fi

exit 0

arch64   ||   github | dotshare | blog

Offline

#28 2011-05-21 14:10:59

synorgy
Member
From: $HOME
Registered: 2005-07-11
Posts: 272
Website

Re: Dmenu Hacking Thread

Actually, I've been sitting on a similar script to what k3ttc4r just posted for about a year. This SHOULD work based on any directory structure because it uses mpc find to get all files with the inputted tags. As such, it's probably quite a bit slower on very large collections. (And it's not as pretty)

I also don't use a dmenurc, but instead export the values for dmenu's configuration from my .zprofile. It's not as compact in the script, but I think it works well enough for me.

#!/bin/sh
artist=$(mpc list artist| sort -n | dmenu -fn "$DMENU_FONT" -nb "$DMENU_NORMBG" -nf "$DMENU_NORMFG" -sb "$DMENU_SELBG" -sf "$DMENU_SELFG" -i -p "ARTIST:" -l 10)

if [[ $artist = '' ]]; then
    exit
else

if [[ $(mpc list album artist "$artist" | wc -l) > 1 ]]; then
    album=$(mpc list album artist "$artist"| sort -n | dmenu -fn "$DMENU_FONT" -nb "$DMENU_NORMBG" -nf "$DMENU_NORMFG" -sb "$DMENU_SELBG" -sf    "$DMENU_SELFG" -i -p "ALBUM:" -l 3)
fi

mpc clear >> /dev/null
if [[ $album = '' ]]; then
    echo "Playlist cleared, Adding all songs available from $artist to the playlist"
    mpc find artist "$artist" | mpc add
else
    echo "Playlist cleared, Adding $artist - $album to the playlist"
    mpc find artist "$artist" album "$album" | mpc add
fi
mpc play >> /dev/null
fi
exit 0

"Unix is basically a simple operating system, but you have to be a genius to understand the simplicity." (Dennis Ritchie)

Offline

#29 2012-01-23 20:28:09

i_magnific0
Member
Registered: 2012-01-23
Posts: 9

Re: Dmenu Hacking Thread

DMENU PDF PRINTER

So here is my contribution. I was really missing an option to print pdfs with mupdf, it does not support this afaik. It uses lpstat to get the list of printers and the list of options for the one you choose, you can set as many options as you like. It finally prints the pdf with lpr.

Enjoy, please comment if you have suggestions!

#!/bin/bash
# printpdf - script
# usage: 
# printpdf file.pdf
# printpdf file1.pdf file2.pdf
# printpdf *.pdf
# by i_magnific0

COLORS=" -nb #303030 -nf khaki -sb #CCFFAA -sf #303030"
if dmenu --help 2>&1 | grep -q '\[-rs\] \[-ni\] \[-nl\] \[-xs\]'
then
        DMENU="dmenu -i -xs -rs -l 10" # vertical patch
else
        DMENU="dmenu -i" # horizontal, oh well!
fi

printer=`lpstat -p | awk '{print $2}' | $DMENU -p 'Printer:' $COLORS | perl -p -e 's/^.*?: ?//'`

set_options=`echo -e 'No\nYes' | $DMENU -p 'Set options?' $COLORS | perl -p -e 's/^.*?: ?//'`

options=""

# standard options to lpr, not in the printer lpstat -l
standard_options="page-ranges\nlandscape"

while [ $set_options == "Yes" ]; do
	custom_options=`lpoptions -d $printer -l | grep -v NotInstalled | awk '{ print $1 }' | sed 's/:\+//g'`
	option_to_set=`echo -e "$standard_options\n$custom_options" | $DMENU -p 'Option:' $COLORS | perl -p -e 's/^.*?: ?//'`
	option_value=`lpoptions -d $printer -l | grep $option_to_set | awk 'BEGIN { FS = ": " } ; { print $2 }' | sed 's/ \+/\n/g' | sed 's/*\+//g' | $DMENU -p 'Setting:' $COLORS | perl -p -e 's/^.*?: ?//'`
	option_to_set_1d=`echo $option_to_set | awk 'BEGIN { FS = "/" } ; { print $1 }'`
        if [ -z $option_value ]; then
		options=$options"-o $option_to_set_1d "
	else
		options=$options"-o $option_to_set_1d=$option_value "
	fi
	set_options=`echo -e 'No\nYes' | $DMENU -p 'Set more options?' $COLORS | perl -p -e 's/^.*?: ?//'`
done

lpr $options -P $printer $@

Offline

#30 2012-01-23 22:27:59

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

I've been using this one for many months now and I can't live without it anymore (on the computer). It was written by Dieter Plaetinck and posted somewhere here in the forums. I had to make it depend on dmenu-path-c because of changes in dmenu. Maybe someone capable can make it use stest like dmenu_run does? I'll try it myself again, maybe this time I'll succeed.
Anyways, here's this little perl
It's a drop-in replacement for dmenu_run and adds the ability to either run the application in the background (e.g. web browsers, libreoffice, etc.) or in the terminal (mutt, ranger, ncmpcpp, etc.). You'll have to tell it the first time you launch an application, if it's supposed to be run in the background or in a terminal. After that it won't ask again.

Last edited by Army (2012-01-23 22:30:17)

Offline

#31 2012-02-06 17:22:30

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

Re: Dmenu Hacking Thread

Does anyone know of a patch that adds a --height option to dmenu? Google has left me hanging so far. Guess I'll try writing my own.

Offline

#32 2012-02-06 20:10:28

stlarch
Member
From: hell
Registered: 2010-12-25
Posts: 1,265

Re: Dmenu Hacking Thread

Runiq wrote:

Does anyone know of a patch that adds a --height option to dmenu?

https://bbs.archlinux.org/viewtopic.php?id=124915

Maybe this? I haven't tried it, but was thinking of playing with it too.

Offline

#33 2012-02-06 21:11:06

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

Re: Dmenu Hacking Thread

stlarch wrote:
Runiq wrote:

Does anyone know of a patch that adds a --height option to dmenu?

https://bbs.archlinux.org/viewtopic.php?id=124915

Maybe this? I haven't tried it, but was thinking of playing with it too.

Nope, that patch is for offsets and width only, unfortunately. I'm currently working on the height patch, though, and it's almost finished. Just a few minor issues to work out.

Offline

#34 2012-02-06 22:28:40

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

Re: Dmenu Hacking Thread

Okay, it's finished and working. See here.

I'll get it to work with the Xft patch, shouldn't take more than an hour (I still don't speak C and am pretty new to coding in general).

Edit: I finished the Xft version; URL is the same as above. I love gist.

Last edited by Runiq (2012-02-06 23:17:52)

Offline

#35 2012-02-07 00:08:03

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

Re: Dmenu Hacking Thread

Runiq wrote:

Okay, it's finished and working. See here.
I'll get it to work with the Xft patch, shouldn't take more than an hour (I still don't speak C and am pretty new to coding in general).
Edit: I finished the Xft version; URL is the same as above. I love gist.

Thanks, oh my gosh, this is a great addition to the 'dmenu family'. Now, if only the y offset patch I crudely hacked (dmenu-xft package) could be incorporated, I'd be on Cloud 9!

--- dmenu-4.5/dmenu.c	2012-02-03 23:00:09.485789612 +0000
+++ dmenu-4.5/dmenu-yoffset.c	2012-02-03 23:06:55.052650108 +0000
@@ -44,6 +44,7 @@ static void usage(void);
 static char text[BUFSIZ] = "";
 static int bh, mw, mh;
 static int inputw, promptw;
+static int yoffset = 0;
 static size_t cursor = 0;
 static const char *font = NULL;
 static const char *prompt = NULL;
@@ -92,6 +93,8 @@ main(int argc, char *argv[]) {
 		/* these options take one argument */
 		else if(!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
 			lines = atoi(argv[++i]);
+		else if(!strcmp(argv[i], "-y"))
+			yoffset = atoi(argv[++i]);
 		else if(!strcmp(argv[i], "-p"))   /* adds prompt to left of input field */
 			prompt = argv[++i];
 		else if(!strcmp(argv[i], "-fn"))  /* font or font set */
@@ -578,7 +581,7 @@ setup(void) {
 					break;
 
 		x = info[i].x_org;
-		y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
+		y = info[i].y_org + (topbar ? yoffset : info[i].height - mh - yoffset);
 		mw = info[i].width;
 		XFree(info);
 	}
@@ -586,7 +589,7 @@ setup(void) {
 #endif
 	{
 		x = 0;
-		y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh;
+		y = topbar ? yoffset : DisplayHeight(dc->dpy, screen) - mh - yoffset;
 		mw = DisplayWidth(dc->dpy, screen);
 	}
 	promptw = prompt ? textw(dc, prompt) : 0;
@@ -614,7 +617,7 @@ setup(void) {
 
 void
 usage(void) {
-	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font]\n"
+	fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-y offset] [-p prompt] [-fn font]\n"
 	      "             [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
 	exit(EXIT_FAILURE);
 }

Offline

#36 2012-02-07 04:25:44

stlarch
Member
From: hell
Registered: 2010-12-25
Posts: 1,265

Re: Dmenu Hacking Thread

Thanks Runiq! The height patch works great.

Offline

#37 2012-02-07 10:37:37

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

Re: Dmenu Hacking Thread

ninian wrote:

Thanks, oh my gosh, this is a great addition to the 'dmenu family'. Now, if only the y offset patch I crudely hacked (dmenu-xft package) could be incorporated, I'd be on Cloud 9!

You might be interested in the patch stlarch posted earlier. It adds x and y offsets, a -w option to specify dmenu's width, and a -q option to hide items on empty input. I just added the missing puzzle piece, basically.

I just noticed I forgot adding the -h option to the manpage, I'll do that and then try to incorporate my patch into the qxyw one. And then pull all that into the Xft patch, if possible.

I guess it's about time I started checking out mercurial patch queues or something…

Edit: Manpages updated.

Last edited by Runiq (2012-02-07 11:26:43)

Offline

#38 2012-02-13 19:45:04

Army
Member
Registered: 2007-12-07
Posts: 1,784

Re: Dmenu Hacking Thread

Runiq wrote:

Okay, it's finished and working. See here.

I'll get it to work with the Xft patch, shouldn't take more than an hour (I still don't speak C and am pretty new to coding in general).

Edit: I finished the Xft version; URL is the same as above. I love gist.

Just a suggestion, I think it's better to use

+    bh = (line_height > dc->font.height) ? line_height : dc->font.height;

rather than

+    bh = (line_height > dc->font.height + 2) ? line_height : dc->font.height + 2;

because only this way you can really determine the real height. Me for example, I don't want those extra 2 pixels.

Offline

#39 2012-02-13 20:08:40

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

Re: Dmenu Hacking Thread

Army wrote:

Me for example, I don't want those extra 2 pixels.

Yeah, I read about your predicament in the other thread. smile

I haven't yet suggested this to the mailing list. After I wrote the patch, I found a few alternatives which added a height switch and/or similar things (the qxyw patch above, for example), and they weren't even mentioned on the "official" dmenu patch list. So I don't think I'll post this one either because it's pretty trivial.

Offline

#40 2012-03-01 00:59:10

totte
Member
Registered: 2011-08-22
Posts: 64

Re: Dmenu Hacking Thread

I've never used these tools before and have to ask - I downloaded and extracted dmenu-xft from AUR, moved into the new directory, downloaded the patch file but am completely clueless as to what I should do now? I've got both dmenu-4.5-xft.diff and dmenu-4.5-xft-height.diff but how do I combine them?

Offline

#41 2012-03-01 01:01:33

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Dmenu Hacking Thread

I don't think you need to combine them. You can apply them one after the other using the patch command. If there are any conflicts, you may need to weed through the rej files and hand patch in any failed chunks.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#42 2012-03-01 18:14:17

totte
Member
Registered: 2011-08-22
Posts: 64

Re: Dmenu Hacking Thread

Here goes:

» wget http://dl.suckless.org/tools/dmenu-4.5.tar.gz
» tar -zxvf dmenu-4.5.tar.gz
» cp dmenu-4.5-xft.diff dmenu-4.5/
» cp dmenu-4.5-xft-height.diff dmenu-4.5/
» cd dmenu-4.5
» patch < dmenu-4.5-xft.diff
patching file config.mk
patching file dmenu.1
patching file dmenu.c
patching file draw.c
patching file draw.h
» patch < dmenu-4.5-xft-height.diff
patching file dmenu.1
patching file dmenu.c
patching file draw.c
patch unexpectedly ends in middle of line
Hunk #1 succeeded at 39 with fuzz 1

I used the dmenu-4.5-xft.diff from the AUR package and the dmenu-4.5-xft-height from Runiq's gist. I don't understand what is wrong. I'm reading the man page for patch and am trying to find a tutorial on these kind of things as well as building from source... but it's rather abstract to me. Advice appreciated.

Offline

#43 2012-03-01 19:28:36

jakobm
Member
Registered: 2008-03-24
Posts: 132

Re: Dmenu Hacking Thread

totte: It is the missing eol in the file dmenu-4.5-height.diff, patch then complains about this.

Hint: If you inspect that file with vim you can see the "noeol" notification in the statusbar. Saving it will add the eol to the last line (if you have set eol which is the default). Try patching it with the saved file and the message will disappear.

Offline

#44 2012-03-01 21:02:23

totte
Member
Registered: 2011-08-22
Posts: 64

Re: Dmenu Hacking Thread

jakobm wrote:

totte: It is the missing eol in the file dmenu-4.5-height.diff, patch then complains about this.

Hint: If you inspect that file with vim you can see the "noeol" notification in the statusbar. Saving it will add the eol to the last line (if you have set eol which is the default). Try patching it with the saved file and the message will disappear.

Ahh, thank you! I followed your instructions and then ran make and make install, everything works as it should now.

Offline

#45 2012-04-16 02:36:42

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

Re: Dmenu Hacking Thread

Cross posted from this thread which inspired the idea.

Launch terminal apps from dmenu with a trivial edit to the dmenu_run script

#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
	cache=$cachedir/dmenu_run
else
	cache=$HOME/.dmenu_cache # if no xdg dir, fall back to dotfile in ~
fi
APP=$(
	IFS=:
	if stest -dqr -n "$cache" $PATH; then
		stest -flx $PATH | sort -u | tee "$cache" | dmenu "$@"
	else
		dmenu "$@" < "$cache"
	fi
)

grep -q -w "$APP" ~/.dmenu_term && urxvtc -e $APP || echo $APP | ${SHELL:-"/bin/sh"} &

I suddenly love dmenu even more.

edit: I should mention some 'instructions'.  Change the urxvtc to your terminal of choice, and create a file called .dmenu_term in your home directory with a list of programs that should start in the terminal.

edit2: Improvements added thanks to other members: beloglazov suggested -w switch to avoid substring matching, and steve__ suggested streamlining the conditional statements.

Last edited by Trilby (2012-04-16 14:16:49)


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

Offline

#46 2012-04-16 12:21:47

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Dmenu Hacking Thread

You can test the exit status of grep.

grep -q "$APP" ~/.dmenu_term && urxvtc -e $APP &
grep -q "$APP" ~/.dmenu_term && echo $APP | ${SHELL:-"/bin/sh"} &

Offline

#47 2012-04-30 10:14:01

ivoarch
Member
Registered: 2011-03-31
Posts: 436

Re: Dmenu Hacking Thread

?

Last edited by ivoarch (2012-12-05 11:59:43)


I love GnuEmacs, GnuScreen, ratpoison, and conkeror.
Github )||( Weblog

Offline

#48 2012-04-30 11:11:30

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: Dmenu Hacking Thread

ivoarch wrote:

For all who do not use wallpaper,and for those who use. smile
I created simple, stupid script to set background color whit Dmenu & Xsetroot. (more than 100 colors)

That script can be made a hundredfold smaller. wink


ᶘ ᵒᴥᵒᶅ

Offline

#49 2012-04-30 16:56:43

ivoarch
Member
Registered: 2011-03-31
Posts: 436

Re: Dmenu Hacking Thread

Sure!  roll


I love GnuEmacs, GnuScreen, ratpoison, and conkeror.
Github )||( Weblog

Offline

#50 2012-05-14 23:00:12

djp
Member
Registered: 2012-02-11
Posts: 12

Re: Dmenu Hacking Thread

A wrapper for deluge-console, to control torrents from dmenu:
EDIT: Whoops, forgot to source '.dmenurc'.  Also, this assumes the vertical patch (it would probably look terrible without it).

#!/bin/bash

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

IFS=$'\n'
torArr=( $(deluge-console info | grep -E 'Name:|State:') )
IFS=$' 	'
for (( x = 0; x < ${#torArr}; x++ )); do
  if [ $(( $x % 2 )) -eq 0 ]; then
    # Operations on "Name: "
    xp1=`expr $x + 1`
    torArr[$xp1]=`echo -e ${torArr[$xp1]} | sed 's/State: //'`
    torArr[$xp1]=`echo -e ${torArr[$xp1]} | sed 's/Downloading /D: /'`
    torArr[$xp1]=`echo -e ${torArr[$xp1]} | sed 's/Seeding /S: /'`
    name_len=${#torArr[$xp1]}
    # Operations on "Status: "
    num_spaces=1
    if [ "$name_len" -lt "$BUF_SPACE" ]; then
      num_spaces=`expr $BUF_SPACE - $name_len`
    fi
    spaces=" "
    for (( s_index = 0; s_index < $num_spaces; s_index++ )); do
      spaces="$spaces "
    done
    torArr[$x]=`echo -e ${torArr[$x]} | sed "s/Name: /$spaces/"`
    torArr[$x]="${torArr[$xp1]}${torArr[$x]}"
    if [ $x -eq 0 ]; then
      fmtTorLst=${torArr[0]}
    elif [ -n "${torArr[$x]}" ]; then
      fmtTorLst="$fmtTorLst\n${torArr[$x]}"
    fi
  else
    true
  fi
done
fmtTorLst=`echo -e "$fmtTorLst" | sort`
fmtTorLst="$fmtTorLst\n  \nReload\nExit"

selTor=`echo -e "$fmtTorLst" | $DMENU -p "Select Torrent" -l ${#torArr}`
selTor=`echo -e $selTor | sed 's/Paused//'`
selTor=`echo -e $selTor | sed 's/Queued//'`
selTor=`echo -e $selTor | sed 's/D: Down Speed: [0-9]*\.[0-9]* .iB\/s//'`
selTor=`echo -e $selTor | sed 's/\(S: \)\?Up Speed: [0-9]*\.[0-9]* .iB\/s//'`
selTor=`echo -e $selTor | sed 's/ETA: \([0-9]*[dhms] \)*//'`
selTor=`echo -e $selTor | sed 's/^ *//'`
case $selTor in
  ""|"Exit") # press esc to quit
    exit
    ;;
  Reload)
    $0
    ;;
  *)
    option_list="info\nvinfo\nhalt\nresume\npause\n  \nrm\ndel\n  \nReturn\nExit"
    opt=`echo -e "$option_list" | $DMENU -p "$selTor" -l 10`
    case $opt in
      info)
        torInfo="`deluge-console $opt $selTor | grep -v "Do Not Download"`"
        torInfo="$torInfo\n  \nReturn\nExit"
        fin_option=`echo -e ${torInfo:2:${#torInfo}} | $DMENU -l 30`
        case $fin_option in
          ""|Exit)
            exit
            ;;
          *)
            $0
            ;;
        esac
        ;;
      vinfo)
        torInfo="`deluge-console "info -v" $selTor | grep -v "Do Not Download"`"
        torInfo="$torInfo\n  \nReturn\nExit"
        fin_option=`echo -e ${torInfo:2:${#torInfo}} | $DMENU -l 30`
        case $fin_option in
          ""|Exit)
            exit
            ;;
          *)
            $0
            ;;
        esac
        ;;
      halt|resume|pause)
        deluge-console $opt $selTor
        $0
        ;;
      rm|del)
        #This should confirm for command, but I don't know how...
        deluge-console $opt $selTor
        $0
        ;;
      ""|Exit)
        exit
        ;;
      *)
        $0
        ;;
    esac
  ;;
esac

Last edited by djp (2012-05-15 14:08:00)

Offline

Board footer

Powered by FluxBB