0

I'm trying to extract the directory of the current playing song in Quodlibet for use in attempting to display album artwork in conky.

In QL's current file ~/.quodlibet/current there is a line that gives you the full path of the currently playing song, but I only need the directory. Is there a way I can ignore the last part of the path with grep?

For example if I had a file called /music/album/03-song.ogg, I'd only want grep to output everything before the 0 (or 1/2/3/4 for longer albums).

I've no idea if I can use this for what I need it for, but it would still be useful to know for future reference.

unor
  • 3,196
dgz
  • 1

4 Answers4

2

If the current file contains a valid path to a file, simply get its directory name:

dirname $(< ~/.quodlibet/current)

The $(< …) will read a file and substitute its contents as if it was cat.

You don't actually want to parse the file or use any regular expressions. This is likely to break if the directory name contains a "0", for example. The only reliable source of information for determining the directory is the last slash, and dirname handles just that anyway.

slhck
  • 235,242
0

You can do this by piping your grep output to sed and using regular expressions to extract the info you want.

You can read up on sed and its regular expression syntax from its manual page.

Ben Richards
  • 12,917
0

Just because I like sed :) ... love @slhck's brilliant solution!

$ echo /music/album/03-song.ogg| sed -r 's@^(.+)/.+$@\1@'
/music/album
tink
  • 2,059
0
quodlibet --print-playing "<~dirname>"
lazka
  • 101