You are not logged in.

#251 2014-02-26 19:22:34

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

Re: Dmenu Hacking Thread

sekret wrote:

Nice addition! Although I don't need such a feature, since I like everything in my music collection wink

What I'd like to include is sorting by genre -> artist -> album. I don't see how this is possible with mpc. Do you happen to have any idea?

GENRE="$(mpc list genre | sort -f | dmenu -p "Select Genre:")";
if [ "$GENRE" = "" ]; then exit; fi


ARTISTS="$(mpc list artist genre "$GENRE" | sort -f|dmenu -p "Artists")";


if [ "$ARTISTS" = "" ]; then exit
else
ALBUM="$(mpc list album artist "$ARTISTS" | dmenu -p "Albums")";
if [ "$ALBUM" = "" ]; then exit
else
mpc clear && mpc find artist "$ARTISTS" album "$ALBUM" | mpc add
fi
fi

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

#252 2014-02-27 10:15:31

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

Re: Dmenu Hacking Thread

Thanks a lot! Really nice of you! Looks like I haven't been digging into mpc enough wink

I cleaned up the code a bit, as far as I know it does exactly the same. I'm not the best hacker (actually I'm not really a hacker), so correct me if I'm wrong

GENRE="$(mpc list genre | sort -f | dmenu -p "Select Genre:")" || exit
ARTISTS="$(mpc list artist genre "$GENRE" | sort -f|dmenu -p "Artists")" || exit
ALBUM="$(mpc list album artist "$ARTISTS" | dmenu -p "Albums")" || exit
mpc clear && mpc find artist "$ARTISTS" album "$ALBUM" | mpc add

Last edited by sekret (2014-02-27 10:19:46)

Offline

#253 2014-03-07 02:59:54

jaredanderson
Member
Registered: 2013-04-06
Posts: 18

Re: Dmenu Hacking Thread

hey I want to modify this script to be able to open directories and list the files inside the directories. not sure where to start other than there needs to be an if statement on selecting a file vs a directory

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

# Global variables:
FILES=${1:-"/home/jared/code/dotfiles"}
DMENU='dmenu -l -i'
EDITOR='urxvtc -e vim'
# Show list of options
choice=$(ls -a "${FILES}" | $DMENU -p "File to edit:")

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

any ideas?

Offline

#254 2014-03-07 09:50:29

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

Re: Dmenu Hacking Thread

jaredanderson wrote:

hey I want to modify this script to be able to open directories and list the files inside the directories. not sure where to start other than there needs to be an if statement on selecting a file vs a directory

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

# Global variables:
FILES=${1:-"/home/jared/code/dotfiles"}
DMENU='dmenu -l -i'
EDITOR='urxvtc -e vim'
# Show list of options
choice=$(ls -a "${FILES}" | $DMENU -p "File to edit:")

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

any ideas?

You need to use -d and -f to test for directory and file. These tests will need to be on the contents of "choice".
See this page for the gory details: http://mywiki.wooledge.org/BashGuide/Te … nditionals

That site is well worth a read through and used as a reference.


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

#255 2014-03-07 10:00:42

Unia
Member
From: The Netherlands
Registered: 2010-03-30
Posts: 2,469
Website

Re: Dmenu Hacking Thread

I have a small file manager for dmenu here:

#!/bin/bash

file=1
while [ "$file" ]; do
	file=$(ls -1 --group-directories-first | /usr/bin/dmenu -l 10 -p "Blader: $(basename $(pwd))")
	if [ -e "$file" ]; then
		owd=$(pwd)
		if [ -d "$file" ]; then
			cd "$file"
		else [ -f "$file" ]
			if which xdg-open &> /dev/null; then
				exec xdg-open "$owd/$file" &
				unset file
			fi
		fi
	fi
done

It is a stripped done version of (I think) wintervenom's script. I'll try to find the source.

EDIT: Original announcement: https://bbs.archlinux.org/viewtopic.php?id=66662&p=1
Code: http://muhas.ru/files/linux/dmenfm/dmenfm

Last edited by Unia (2014-03-07 10:03:33)


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

#256 2014-03-09 06:09:50

jaredanderson
Member
Registered: 2013-04-06
Posts: 18

Re: Dmenu Hacking Thread

It is funny when you realize there is a name for what you are trying to do and you have already seen it done. somehow I didn't connect what I was trying to do with a file manager and I am not sure why. Well I followed skanky's lead to see if I could make the script I needed. It worked but it was sloppy and not very good. So I looked at wintervenom's but that thing is huge so I just decided to use your's (Unia). and it is beautiful. I just changed the flag after ls to -a so I could see "dot" files. I also made it so it displayed as one line and added a cd command at the beginning so it would start in a different directory.

Offline

#257 2014-03-18 00:26:38

Earnestly
Member
Registered: 2011-08-18
Posts: 798

Re: Dmenu Hacking Thread

So I made this project called Taverner (I'm going with an innkeeper theme, just roll with it for now). 

Taverner (Github) uses dmenu to display a list of games and such with adjacent cover art, e.g.
screenshot.png

And then launches whatever you select.  Handy!

The menu itself is completely generated... and this is where we move from "dmenu" to "have-mercy-make-the-bash-stop".

You can pretty easily add entries, remove them, based on templates and all that fun stuff although at the moment I just throw up your editor with a selected template and let you get on with it, at least, for now.

It was a fun little project, though mostly created for my niece who likes to play random video games and while I'm not completely happy with the logic, it's a fairly robust script, for bash at any rate.

Ta o/

edit: Oh, the name was inspired by all the old school RPGs such as Dungeons and Dragons which seem to always start you off at an Inn.

Last edited by Earnestly (2014-03-18 00:44:14)

Offline

#258 2014-03-18 02:11:13

jasonwryan
Forum & Wiki Admin
From: .nz
Registered: 2009-05-09
Posts: 18,056
Website

Re: Dmenu Hacking Thread

Earnestly wrote:

                fi # Ouch
            fi # Ooph
        fi # Pow
    done # Ow! Score: 5 total levels of indentation, you lose

smile


Arch + dwm   •   Mercurial repos  •   Github

Registered Linux User #482438

Online

#259 2014-03-18 03:03:30

Earnestly
Member
Registered: 2011-08-18
Posts: 798

Re: Dmenu Hacking Thread

Hehe, I fixed that.

It always looks like someone might trip and fall down the indents, like a flight of stairs with an unfortunate end. 
A good reason to keep them to a minimum! tongue

Offline

#260 2014-03-25 19:05:46

bout10bucks
Member
Registered: 2009-09-11
Posts: 25

Re: Dmenu Hacking Thread

Some games don't work well with "ondemand" CPU frequency scaling, and I can never remember to switch profiles until in game (too late). So dcpu-gov:

#!/bin/bash

current=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
available=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors | sed 's/ /\n/g')
gov=$(printf "$available" | dmenu -p "Please select a CPU governor, [$current] is active:")

if [[ -z $gov ]]; then
	exit
else
	sudo -A cpupower frequency-set -g $gov
fi

with the dmenu sudo else where in this thread, I can switch profiles in game

Offline

#261 2014-03-26 15:44:59

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

Re: Dmenu Hacking Thread

I think it's nicer to do it like this

available=$(sed 's/ /\n/g' /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)

Nice idea!

Offline

#262 2014-03-26 16:02:13

Earnestly
Member
Registered: 2011-08-18
Posts: 798

Re: Dmenu Hacking Thread

Using sed here is far worse than cat, even though cat is wrong too.

What you're really after is something like this:

# read the first line in file and store it in variable 'available'
read -r available < /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

Instead of all these useless forks, subshells and abused cats.
Please try to learn bash when you get a chance.

Edit: Note that you are only checking cpu0 which may or may not be reliable.

Last edited by Earnestly (2014-03-26 16:06:09)

Offline

#263 2014-03-30 18:26:02

jonlorusso
Member
Registered: 2013-12-29
Posts: 7

Re: Dmenu Hacking Thread

Ok, perhaps there's a post, or script in this thread that answers this question, but I'll just ask explicitly.

I'm trying to implement an alt-tab-style window switcher.  I grab a list of windowid's from xprop, then get a list of window names again via xprop.  However AFAIK selecting a window via window name is not possible.

Is there anyway to display one value in dmenu, but output another value (eg., display window name, but output the corresponding windowid) ?

thanks!

EDIT: Just found this: https://github.com/orschiro/dmenu-scrip … nning_apps

Last edited by jonlorusso (2014-03-31 00:21:45)

Offline

#264 2014-03-31 19:16:46

Earnestly
Member
Registered: 2011-08-18
Posts: 798

Re: Dmenu Hacking Thread

I want to express how bad the shell scripting is in this thread but I don't seem to have the words or enthusiasm to be nice about it.

As for displaying "one value" while outputting another sounds very similar to this idea of "arrays", "keys" and "values".  Even bash has support, albeit basic, for this programming structure.

E.g.

# Tell bash to declare the variable "array" as an associative array, otherwise
# it treats it like a normal indexed array
declare -A array 
array=(["Hello World"]="foobar")


# Print each (!) key seperated with a \n and shove it to dmenu.  Since the
# selected result of dmenu is a string on stdout, we can store this value in a
# variable for later use called "selection" in this example
selection="$(printf '%s\n' "${!array[@]}" | dmenu)"

# => User sees "Hello World" in dmenu

# If the user selected nothing then $selection will be null
if [[ -z "$selection" ]]; then
    # Just exit if nothing was selected
    exit
fi

# Otherwise pass the array in but this time use the selection as the key to
# index the value
printf '%s\n' "${array[$selection]}"

# => foobar

Edit: Half these scripts are not even *bash* but broken sh scripts, the quoting is generally missing which is dangerous under bash due to IFS and in general quite a miserable experience to read.  Of course it's just bash right?  That's not a real programming language so why should anyone care about doing it correctly as long as it (seems to) work, right.

Last edited by Earnestly (2014-03-31 19:21:05)

Offline

#265 2014-03-31 19:22:21

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

Re: Dmenu Hacking Thread

@Earnestly

Amongst other advantages, I therefore created the scripts-collection to have a structured repo with high quality scripts to which everyone can contribute with improvements.

Offline

#266 2014-03-31 19:29:14

Earnestly
Member
Registered: 2011-08-18
Posts: 798

Re: Dmenu Hacking Thread

Start by reading the Bash Guide and Bash Pitfalls if you actually care instead of placing the burden on others.

PS: If the website isn't mywiki.wooledge or bash-hackers.org, they're probably (dangerously) wrong.  Otherwise check out #bash on freenode.

Last edited by Earnestly (2014-03-31 19:30:45)

Offline

#267 2014-04-10 00:02:55

jtgd
Member
From: San Jose, CA
Registered: 2013-06-23
Posts: 31

Re: Dmenu Hacking Thread

I'm having a problem with dmenu.
I am using find to get a list of files and then using dmenu to select one.
It works fine when I invoke it normally from the shell on the machine, but the problem is when I invoke it from an ssh session.
It displays the menu normally, but the keys don't work.
Cursor down echos ^[[B and Escape echos ^[ to the console but they do nothing to dmenu.
It's as if dmenu is not actually reading the keyboard.

I don't know how dmenu reads the keys since it reads stdin for the list, but I assume it's reading /dev/tty or something.
I see this problem when I log in via ConnectBot on my Android device or even when looping back with ssh on the machine.

Is this a known issue with dmenu and ssh, and is there a workaround?
Thanks.


Arch + i3 + uzbl

Offline

#268 2014-04-10 09:25:18

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

Re: Dmenu Hacking Thread

I can't help specifically with the issue, but you could try slmenu instead: https://aur.archlinux.org/packages/slmenu-hg/


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

#269 2014-04-11 02:32:55

jtgd
Member
From: San Jose, CA
Registered: 2013-06-23
Posts: 31

Re: Dmenu Hacking Thread

skanky wrote:

I can't help specifically with the issue, but you could try slmenu instead: https://aur.archlinux.org/packages/slmenu-hg/

Thanks skanky, that's a very nice thing to know.  I may use slmenu as well as dmenu in places.

It appears my problem has nothing whatsoever to do with dmenu.
I think it's more of a ConnectBot problem which I will bring up with the developers.
When I tried to run xterm and then slmenu, the keyboard input would not to go the xterm either.
But when I run mplayer the keys control it so, I don't get it.


Arch + i3 + uzbl

Offline

#270 2014-05-26 04:07:24

jpolcol
Member
Registered: 2014-05-14
Posts: 9

Re: Dmenu Hacking Thread

Hey fellow dmenu lovers/hackers!

I recently published my hacks as a package on the AUR called HyperMenu, which is entirely dmenu-based. Here is the description:

HyperMenu is a multi-purpose, dmenu-based utility that features a TODO list manager, note manager, calculator, applications menu, system menu, weather menu, and a GTK2 theme switcher.

I'm planning on adding a dictionary menu, as well as packaging and cleaning up a dmenu-based RSS reader.

All contributions, ideas, or suggestions are more than welcome. I'm always looking to improve my code.

Thread:
https://bbs.archlinux.org/viewtopic.php … 6#p1418026

AUR page:
https://aur.archlinux.org/packages/hypermenu-git/

GIT repo:
https://bitbucket.org/jpolcol/hypermenu

Offline

#271 2014-08-11 18:36:44

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

Re: Dmenu Hacking Thread

A little bookmark organiser for dmenu/rofi
**edit** now with firefox importer

https://github.com/carnager/robot

Last edited by Rasi (2014-08-17 18:19:36)


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

#272 2014-08-20 09:01:53

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

Re: Dmenu Hacking Thread

@Rasi

Bookmarks for quick navigation of directories or also for files?

Offline

#273 2014-08-20 09:23:16

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

Re: Dmenu Hacking Thread

no, this is about browser bookmarks
I thought the "firefox-importer" gave that hint away smile

Last edited by Rasi (2014-08-20 09:23:38)


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

#274 2014-11-16 14:02:48

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

Re: Dmenu Hacking Thread

Rasi wrote:

made a nearly full blown mpd client.

Features:

Add/insert/replace album
Add/insert/replace track
Browse Library by Artist > Album (stole that function somewhere) tongue
Add Random album
Add X random tracks
Show current Playlist and select song to play
Add/insert/replae album/track by currently playing artist
Toggle various mpd settings (single, consume, repeat, random, replaygain, volume, outputs)
Lookup artist/album on allmusic.com (using surfraw)
search for lyrics of currently playing song (using surfraw)

Rate albums
Load albums by rating

enable/disable scrobbling
add/remove current artist to scrobbling blacklist

http://git.53280.de/carnager/scripts/tree/mpdMenu

and the needed lastfm thing for the last 2 options: (would love help on cleaning this monster up)

http://git.53280.de/carnager/scripts/tree/lastfm

Was interested to try it but the link is dead, that's the internet for you
Edit, thanks to orschiro in the post below

Last edited by chickenPie4tea (2014-11-17 12:18:19)


You can like linux without becoming a fanatic!

Offline

#275 2014-11-16 14:15:04

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

Re: Dmenu Hacking Thread

@chickenPie4tea

It has been rewritten: https://github.com/carnager/clerk

Offline

Board footer

Powered by FluxBB