You are not logged in.
I'm trying to add to my conky panel the name of the artist and title of the song that is currently playing. The only guide I could find was the below from this post on the forums (post 1757):
http://crunchbanglinux.org/forums/topic … g/page/71/
It works except it posts the name of the artist twice. My question revovles around this part of the code:
| grep artist | cut -d " " -f 3- I can't understand how cmus understands the grep part and the part after that I can't find any informaiton on what that part is doing. I've also modified what is being done here. I'm not running this as an external script but instead I'm running it inside conky itself with the following code:
&{exec echo $(cmus-remote -Q | grep artist | cut -d " " -f 3- )} - ${exec echo $(cmus-remote -Q | grep title | cut -d " " -f 3-)}Once I get this figured out I'm going to work on adding album artwork. Hopefully I can get all of this working correctly and as always, thank you so much for the help.
Last edited by linux4life88 (2012-05-06 00:06:06)
Offline
2 links using a conky + cmus google search
http://v3gard.com/2011/01/getting-cmus- … ith-conky/
and for the album art
http://kbiggs.org/2012/03/28/conky-cmus-and-album-art/
These should help
VSIDO
If you build it, they will come...
Words That Build Or Destroy
Offline
Thank you for the help VastOne. I already had found the v3gard site through a DuckDuckGo search (and recognized that this is most likely where shu got the code) but when I found it I must have missed the comments section. That helped me understand the grep part but the other part I still don't understand and the site has not explanation of the code. I was hoping someone could explain to me how that last part works.
Offline
I've finally had something of a breakthrough. I found out why the following code prints the artist name twice.
| grep artist | cut -d " " -f 3-It is because cmus-remote has two artist commands, artist and artistsort. I'm not sure what the difference is between the two but if you use only artist grep will pull the result of both of these commands. So if you use artistsort the name of the artist will only appear once. It is a start to answering my questions.
Offline
Wouldn't the -m option solve this?
grep -m 1'searchstring' file
The -m <number> option is the key to your problem. -m 1 will only show the first match, -m 2 the first 2 etc.
So this should do it
| grep -m 1 artist | cut -d " " -f 3-VSIDO
If you build it, they will come...
Words That Build Or Destroy
Offline
I saw the -m option in the grep help pages but I guess I didn't understand what arguments it needed. I now know that it is a simple as a 1 or a 2 or so on. Thank you for the help VastOne. I'm not new to programming but I am new to using bash, grep, cut ectera.
Offline
| grep artist | cut -d " " -f 3-I can't understand how cmus understands the grep part and the part after that I can't find any informaiton on what that part is doing.[..] I'm not running this as an external script but instead I'm running it inside conky itself with the following code:
&{exec echo $(cmus-remote -Q | grep artist | cut -d " " -f 3- )} - ${exec echo $(cmus-remote -Q | grep title | cut -d " " -f 3-)}
let me explain some things here.
cmus does not understand 'grep'. what happens here is that 3 separate commands are being executed, with the output of each acting as the input for the next.
let's break it down.
${exec} - a conky-command. it executes whatever comes next.
echo - simply prints something to the screen, in this case it prints it inside your conky
$() - everything inside this part is executed as a separate thing, and the result of that is what gets echoed by the 'echo' command as explained above.
cmus-remote -Q - don't know exactly what this does as i don't know cmus, but it will probably get some info about what is currently playing. however, that info is probably too much for what is needed here, as we only need the artist.
| - this symbol is a pipe. a pipe is something take takes an input and moves it somewhere else. pipes are used to get the output from one app and send it to the next. so, the output of 'cmus-remote Q' gets sent, through the pipe, into 'grep'
grep artist - grep looks for the word 'artist' inside the output of 'cmus-remote Q'. this is why VastOne gave you the suggestion of using 'grep -m1' so it will only return the first result. open a terminal and type 'man grep' for more info
cut -d " " -f 3- - this is the part you said you couldn't find any info on. open a terminal and type 'man cut' and see for yourself what is happening here.if you get confused by this, open up a terminal and just type this:
echo $(cmus-remote -Q | grep artist | cut -d " " -f 3- )you'll see the artist-name twice, as you did inside your conky. instead of echoing to your conky, it is now echoing to your screen, your terminal. now see what happens when you remove the cut-part, like this:
echo $(cmus-remote -Q | grep artist)then get smaller and see what happens when you do this:
cmus-remote -Qthat should get you on your way.
Offline
let me explain some things here.
cmus does not understand 'grep'. what happens here is that 3 separate commands are being executed, with the output of each acting as the input for the next.
let's break it down.
nice explanation...
cut -d " " -f 3- - this is the part you said you couldn't find any info on. open a terminal and type 'man cut' and see for yourself what is happening here.
(it's all in a man page...)
Last edited by 2ManyDogs (2012-05-05 23:45:51)
Be eggsalad to each other.
Offline
It is all working now as expected. Thank you rhowald for your explanaitons. I now understand what the pipes were for, I couldn't figure that out either. I finally did figure out cut was a seperate command, the cut --help did actually help once I figured this out. The cmus-remote -Q part was actually the only part of the code I really understood when I begun. It is really cool, it gives you the location of the song, how many seconds long the song is, whether something is acutally playing, artist name, song name, and so on.
I knew this command would provide me with everything I need to display info in conky, I just didn't understand any of the non conky code. Although now I do and I thank you both for the help.
${exec echo $(cmus-remote -Q | grep -m 1 artist | cut -d " " -f 3-)}
${exec echo $(cmus-remote -Q | grep title | cut -d " " -f 3-)}Offline
@2manydogs: thanks 
@linux4life: glad i could help. you might want to consider reading up on some of this stuff. it is very useful to know and you can learn the basics pretty quickly. consider spending more time inside a terminal, instead of using a GUI. check out the link in my signature that says 'bash'. it has a bunch of info on the shell (terminal) and how it works.
just telling you this so you can consider it. you don't have to, of course 
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.