You are not logged in.
Nice addition! Although I don't need such a feature, since I like everything in my music collection
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
Thanks a lot! Really nice of you! Looks like I haven't been digging into mpc enough
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
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
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
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
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
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.
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
fi # Ouch
fi # Ooph
fi # Pow
done # Ow! Score: 5 total levels of indentation, you lose
Offline
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!
Offline
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
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
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
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
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
@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
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
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 + awesome
Offline
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
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 + awesome
Offline
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
Offline
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
no, this is about browser bookmarks
I thought the "firefox-importer" gave that hint away
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
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)
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 ratingenable/disable scrobbling
add/remove current artist to scrobbling blacklisthttp://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)
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
@chickenPie4tea
It has been rewritten: https://github.com/carnager/clerk
Offline