You are not logged in.

#176 2013-08-29 21:09:24

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: Dmenu Hacking Thread

Just pipe your text into dmenu, e.g.:

acpi | dmenu

If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#177 2013-08-29 21:35:31

madprops
Member
Registered: 2012-05-26
Posts: 26

Re: Dmenu Hacking Thread

awesome!

Offline

#178 2013-08-29 21:47:39

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

Re: Dmenu Hacking Thread

madprops wrote:

I was wondering how it would be possible to show some information as soon as opening dmenu, without entering any text. Like battery state, date, cpu, mem etc. I think that would be nice.

Just pipe whatever information you want to dmenu, then set the right number of lines.  Or if it's just something short, use it as the prompt - that's all built in.  Do these not work for you?

EDIT: too slow.

Last edited by Trilby (2013-08-29 21:47:55)


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

Offline

#179 2013-08-29 22:21:31

madprops
Member
Registered: 2012-05-26
Posts: 26

Re: Dmenu Hacking Thread

Cool, what i'm trying to figure out now is if I could show this information without it being highlighted.

Offline

#180 2013-08-29 22:24:03

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

Re: Dmenu Hacking Thread

Just change the highlighting colors to be the same as the default colors.

Why do you want to use dmenu for this though?


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

Offline

#181 2013-08-29 22:36:21

madprops
Member
Registered: 2012-05-26
Posts: 26

Re: Dmenu Hacking Thread

I want to use dmenu as a launcher as well so that wouldn't be ideal. 

Show information upon starting an as soon as I type something filter the executable list.

Actually I just realized piping won't work because it removes all applications, I could bind it I guess.

Last edited by madprops (2013-08-29 22:38:14)

Offline

#182 2013-08-29 22:42:24

Unia
Member
From: Stockholm, Sweden
Registered: 2010-03-30
Posts: 2,486
Website

Re: Dmenu Hacking Thread

You want the information in the same instance as the one that launches your applications? That won't work.


If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres

Offline

#183 2013-08-30 09:04:48

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

Re: Dmenu Hacking Thread

It can work, edit the script you use and let it execute acpi before the rest.

{ acpi; ls /usr/bin/; } | dmenu

Offline

#184 2013-09-03 09:42:16

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

Re: Dmenu Hacking Thread

dmenu_run is a script that comes with dmenu that lists the executables. If you incorporate Procyon's idea into a new version of it, you get the cache as well.


"...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

#185 2013-09-03 10:30:41

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

Re: Dmenu Hacking Thread

Use dmenu -p (prompt) in dmenu_run or wherever. | dmenu -p "$(acpi)"

Offline

#186 2013-09-05 09:10:45

chickenPie4tea
Member
Registered: 2012-08-21
Posts: 309

Re: Dmenu Hacking Thread

Dmenu expert needed - ok maybe not expert..

skanky wrote dedit

 #!/bin/sh
#
# d-edit: Use dmenu to open and edit a file from a given list.

# Global variables:
#FILES=${1:-"/home/boo/.config/dmenu/edit-list"}

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

EDITOR=xfw
# Show list of options
choice=$(awk '{print $1}' $FILES | $DMENU -p "File to edit:")

if [ $choice ]; then
    # use eval as get vim error is use awk's system
    eval $(awk '/'$choice'/ && NF == 2 {printf("'$EDITOR' %s",$2); exit}
                /'$choice'/ && NF == 3 {printf("%s %s",$3,$2); exit}' $FILES)
fi

How would I get it so that I dont have to use a list that I have to edit but just to look in a particular folder only used for text files like "/home/boo/text-files/
--------------
by the way this guy has a few handy dmenu things like a wget script
http://www.uzbl.org/wiki/dm-dm

Last edited by chickenPie4tea (2013-09-05 09:22:29)


You can like linux without becoming a fanatic!

Offline

#187 2013-09-05 09:42:15

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

Re: Dmenu Hacking Thread

Substitute the

choice=$(awk '{print $1}' $FILES | $DMENU -p "File to edit:")

with

choice=$(ls -1 /home/boo/text/files | $DMENU -p "File to edit:")

You could put the path in a variable (in which case quote it - and $FILES above should be quoted).


"...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

#188 2013-09-05 10:09:18

chickenPie4tea
Member
Registered: 2012-08-21
Posts: 309

Re: Dmenu Hacking Thread

Thanks for the very quick reply!
I now get the files listed but when i choose one it doesnt open

#!/bin/sh
#
# d-edit: Use dmenu to open and edit a file from a given list.

# Global variables:
#FILES=${1:-"/home/boo/.config/dmenu/edit-list"}
FILES=${1:-"/home/boo/text-files/*.txt"}

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

EDITOR=xfw
# Show list of options
#choice=$(awk '{print $1}' $FILES | $DMENU -p "File to edit:")
choice=$(ls -1 /home/boo/text-files | $DMENU -p "File to edit:")

if [ $choice ]; then
    # use eval as get vim error is use awk's system
    eval $(awk '/'$choice'/ && NF == 2 {printf("'$EDITOR' %s",$2); exit}
                /'$choice'/ && NF == 3 {printf("%s %s",$3,$2); exit}' $FILES)
fi

You can like linux without becoming a fanatic!

Offline

#189 2013-09-05 10:41:41

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

Re: Dmenu Hacking Thread

chickenPie4tea wrote:

Thanks for the very quick reply!
I now get the files listed but when i choose one it doesnt open

#!/bin/sh
#
# d-edit: Use dmenu to open and edit a file from a given list.

# Global variables:
#FILES=${1:-"/home/boo/.config/dmenu/edit-list"}
FILES=${1:-"/home/boo/text-files/*.txt"}

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

EDITOR=xfw
# Show list of options
#choice=$(awk '{print $1}' $FILES | $DMENU -p "File to edit:")
choice=$(ls -1 /home/boo/text-files | $DMENU -p "File to edit:")

if [ $choice ]; then
    # use eval as get vim error is use awk's system
    eval $(awk '/'$choice'/ && NF == 2 {printf("'$EDITOR' %s",$2); exit}
                /'$choice'/ && NF == 3 {printf("%s %s",$3,$2); exit}' $FILES)
fi

Sorry, my bad. I forgot about the action of opening the file.

Replace the "if choice" section with:

if [ "$choice" ]; then
    $EDITOR "${FILES}/${choice}"
fi

You also need to change the path in the choice= line to "$FILES".

EDIT: Aaaah! sorry that will only work if you drop the *.txt from the FILES initialisation.
Hold on...

Last edited by skanky (2013-09-05 10:43:14)


"...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

#190 2013-09-05 10:46:33

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

Re: Dmenu Hacking Thread

This should work - though I've not had time to test it.

#!/bin/sh
#
# d-edit: Use dmenu to open and edit a file from a given list.

# Global variables:
#FILES=${1:-"/home/boo/.config/dmenu/edit-list"}
FILES=${1:-"/home/boo/text-files/"}

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

EDITOR=xfw
# Show list of options
#choice=$(awk '{print $1}' $FILES | $DMENU -p "File to edit:")
choice=$(ls -1 "${FILES}*.txt" | $DMENU -p "File to edit:")

if [ $choice ]; then
    $EDITOR ${FILES}/${choice}
fi

I'm sure some could improve on it (I probably could a bit as I'm not happy about the *.txt in the ls command).


"...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

#191 2013-09-05 11:25:23

chickenPie4tea
Member
Registered: 2012-08-21
Posts: 309

Re: Dmenu Hacking Thread

Great, it's working now
It didn't at first but I just dropped the *.txt part as there are only text files in that folder anyway.
I find it very handy for note taking on various subjects - I just have all my notes in one folder and can now access them with a nice menu - thanks!


You can like linux without becoming a fanatic!

Offline

#192 2013-09-05 11:56:23

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

Re: Dmenu Hacking Thread

chickenPie4tea wrote:

Great, it's working now
It didn't at first but I just dropped the *.txt part as there are only text files in that folder anyway.
I find it very handy for note taking on various subjects - I just have all my notes in one folder and can now access them with a nice menu - thanks!

No problem. Sorry I messed it up first time round.


"...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

#193 2013-09-25 23:14:02

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

Re: Dmenu Hacking Thread

Edit: fyr has been updated to also launch applications from desktop files and handle names with embedded spaces.
It has now been added as an AUR package.

Inspired by Ghost1227 this is a launcher menu which allows you to execute (=), add (+) or delete (-)  application symlinks stored in the ~/.fyrd directory. To start it off, press Enter and the '=' will change to a '+'; now type in the name of your application, (say) leafpad, and then Enter to save the symlink to /usr/bin/leafpad. When fyr is run again, 'leafpad' appears in the menu. Repeat as necessary. The action symbols '=', '+' and '-' just go around in a cycle.

#!/bin/bash
# fyr: Application launcher by ninian @ 25/09/13

emsg() {
notify-send -u critical "Fyr error" "$*" &
}

apadd() {
cmd=$(command -v $app)
if [[ -z $cmd ]]; then emsg Application \'$app\' not found on PATH; return 1
  else
  if [[ -L $fyrd/$app ]]; then emsg Launcher \'$app\' already exists; return 1
  else
    [[ -d $fyrd ]] || mkdir -p $fyrd
    ln -s $cmd $fyrd/$app; return 0
  fi
fi
}

apdel() {
if [[ -L $fyrd/$app ]]; then rm -f $fyrd/$app; return 0
else emsg Launcher \'$app\' not found; return 1
fi
}

fyrd="$HOME/.fyr"
act="="
while true; do
  app=$((echo "$act"; ls $fyrd) | dmenu -i -p 'Application')
  case "$app"x in
    "$act"x) case "$act" in
               '=') act='+' ;;
               '+') act='-' ;;
               '-') act='=' ;;
             esac  ;;
          x) exit  ;;
          *) break ;;
  esac
done

case "$act" in
  '=') exec $app ;;
  '+') apadd     ;;
  '-') apdel     ;;
esac

Also, inspired by Gullible Jones I think this is about as efficient as can be done to execute any command from all the installed desktop files:

#!/bin/sh
# deskexec: Displays menu of commands from all desktop files and executes selection
# By ninian @ 28/09/13

eval exec "$(find $HOME/.local/share/applications /usr/{local/,}share/applications -name '*.desktop' -print0 \
   | xargs -0 awk 'sub(/^Exec=/,"")+gsub(/\s%[fFuU]/,"")' \
   | dmenu -i -p Exec)"

Edit: script updated to handle commands with embedded spaces

Last edited by ninian (2013-09-28 22:14:44)

Offline

#194 2013-10-01 18:02:48

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

Re: Dmenu Hacking Thread

Hello guys, do you have any hint about what to change to make dmenu_run start gajim?

If I start dmenu_run from terminal and then type gajim in it, gajim will start, but if I start dmenu_run with a shortcut (not from terminal), gajim won't start. As a workaround, I can start gajim from dmenu_run with urxvt -e gajim, but then I will have an extra terminal opened. Any suggestions are welcome.

/usr/bin/gajim looks similar to this

#!/bin/sh
cd "/usr/lib/python2.7/site-package/gajim"
exec "python2" -OO gajim.py "$@"

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

Offline

#195 2013-10-01 19:49:40

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

Re: Dmenu Hacking Thread

I'm guessing gajim.py relies on an environment variable setting.

Where is the shortcut for dmenu_run defined?  If it's in your window manager, how do you start your window manager?


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

Offline

#196 2013-10-01 20:44:20

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

Re: Dmenu Hacking Thread

Trilby wrote:

I'm guessing gajim.py relies on an environment variable setting.

Where is the shortcut for dmenu_run defined?  If it's in your window manager, how do you start your window manager?

I'm using 2bwm, so the shortcut is defined in config.h file of the 2bwm, the shortcut should call /usr/bin/dmenu_run. I start my window manager from .xinitrc:

#!/bin/sh
# ~/.xinitrc

# some generic commands

2bwm &
exec urxvt

I have the same issue with starting gajim via gmrun as well.

When I run dmenu_run from shortcut, my pstree has this branch:

...urxvt---2bwm---dmenu_run---dmenu_run---dmenu

When I start dmenu_run from terminal, then pstree has this branch:

...urxvt---2bwm---urxvt---bash---dmenu_run---dmenu_run---dmenu

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

Offline

#197 2013-10-01 22:09:09

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

Re: Dmenu Hacking Thread

Yup, I'm pretty sure that is an environment variable issue.

What runs your xinitrc?  Is it some systemd user service or display manager, or do you log in to the tty then run startx/xinit?  If it's the latter I'm likely wrong, as loging in to a tty would source all the same files to set environment variables that your terminal sessions do.

Last edited by Trilby (2013-10-01 22:10:01)


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

Offline

#198 2013-10-02 01:53:53

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

Re: Dmenu Hacking Thread

Trilby wrote:

Yup, I'm pretty sure that is an environment variable issue.

What runs your xinitrc?  Is it some systemd user service or display manager, or do you log in to the tty then run startx/xinit?  If it's the latter I'm likely wrong, as loging in to a tty would source all the same files to set environment variables that your terminal sessions do.

I'm using the latter approach, so I just log in to the tty and then run startx.


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

Offline

#199 2013-10-02 02:25:54

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

Re: Dmenu Hacking Thread

Hmm, sorry then, that suggests my suspicion was wrong.  To double check, you could compare the output of `env` from the tty right before starting x, and from a terminal emulator within X.  but if that's how you're starting X there shouldn't be any differences.


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

Offline

#200 2013-10-03 00:09:41

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

Re: Dmenu Hacking Thread

Trilby wrote:

Hmm, sorry then, that suggests my suspicion was wrong.  To double check, you could compare the output of `env` from the tty right before starting x, and from a terminal emulator within X.  but if that's how you're starting X there shouldn't be any differences.

No, don't be sorry, I really appreciate your help. The output of env isn't exactly the same, but I don't see any difference what should really matter. I run env from my urxvt terminal and from gajim starting script (/usr/bin/gajim) started by dmenu_run, here is the diff of results.

# diff env-gajim env-urxvt
2d1
< XDG_SESSION_ID=1
3a3
> XDG_SESSION_ID=1
4a5
> TERM=rxvt-unicode-256color
6c7
< TERM=linux
---
> WINDOWID=14680075
10d10
< PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl
11a12
> PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl
14,15c15
< HOME=/home/peta
< XDG_SEAT=seat0
---
> COLORFGBG=15;default
16a17,19
> XDG_SEAT=seat0
> HOME=/home/peta
> TERMINFO=/usr/share/terminfo
20d22
< DISPLAY=:0
21a24,25
> DISPLAY=:0
> COLORTERM=rxvt

I forgot to mention, that I slightly changed my dmenu_run script, so programs started by dmenu_run aren't dmenu_run's children. Anyway, the problem with running gajim from it was there even with the original version.


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

Offline

Board footer

Powered by FluxBB