2

I'm trying to become comfortable with the terminal by using it as much as I can. The aspect of my computer usage where I lose most time using command line instead of the gui is when I try to find a song I am interested in.

My music folder is structured like so Music->Bands->Albums->Songs

I often forget what Album a Song is in but I always remember what Band played that song.

I don't search for the song from the Music directory because it takes too long to find a song (I have a lot of music) so I search for the song after I get to the Band directory. Right now in command line I have

# totem /home/user/Music/Red\ Hot\ Chili\ Peppers/

but I forgot what Album the Song "Dani California" is in (totem is a music player in gnome.) The quickest way for me to get around this is to get inside the Red Hot Chili Peppers folder in the file manager gui and hit ctrl+f and type "Dani California".

Is there a way I can search the contents in a directory from terminal while I'm in the middle of writing a command? Or do you have any recommendations on how I can most quickly achieve the same goal I do in the gui from the command line?

5 Answers 5

2

This is not particularly intuitive as the auto-completion is not working, but you could achieve what you want using file masks:

totem /home/user/Music/Red\ Hot\ Chili\ Peppers/*/Dani\ Ca*

Another option is use find and then make it pass the filenames it has found to totem:

find . -name "Dani Calif*" -exec totem '{}' +

Though this isn't exactly "search while you're writing a command"

0

Hitting "tab" twice should give you a list of files or directories. Then just type part of the one you want and hit "tab" to complete it.

2
  • 1
    But imagine he has 10 albums by some artist and he doesn't know which album the song is from (which is a shame, LedZeppelin, btw - Dani California is from Stadium Arcadium :) ). Using autocompletion, he would have to iterate through all the albums one by one until he finds the one. Which is what the question is about, as I understand
    – Sergey
    Sep 5, 2011 at 3:33
  • Heh, yah I know it's from stadium arcadium. I miss John so much... his high notes, followed by low notes and his emphasis on emotion and melody...
    – user784637
    Sep 5, 2011 at 5:06
0

Really interesting question. That's a pretty neat way to force yourself to use the CLI. But man, that sounds too painful for music. I don't see how I could live with the limits of Totem (vs. Banshee or Rhythmbox). I would think banning yourself from using Nautilus and gedit would go far enough to force you to use a terminal more often.

But I admire your patience and discipline. Perhaps you might want to look into a CLI/Terminal oriented music player. Here's a good review of some: http://www.linux.com/archive/feature/124907

Apologies in advance if none of them solve the particular problem you're asking about, but given the background of your question, I think you might find these options interesting nonetheless. Best of luck.

1
  • Not sure whether i should flag this as not relevant or not. But given the fact that pm is not supported, perhaps i shouldn't.
    – Mahesh
    Apr 12, 2012 at 19:29
0

The already suggested solution of metachar is great, but sometimes it could not be enough.

I use frequently more than a terminal at a time, multiplexing a single window using screen, but gnome-terminal's tabs could do the job as well (I should point out that the screen solution will work also in a ssh session or in a virtual terminal, so it is more general).

So, switching to another terminal, you can use the locate command whose results are obtained much more quickly than from find.

0

It can also be done via Bash programmable completion. I've put together a small sample script.

The script below completes a fap (find and play) command which you should define separately, for example

fap

#! /bin/sh
file="$2"
totem "$file" > /dev/null &
exit 0

Then put the following script into the /etc/bash_completion.d directory

/etc/bash_completion.d/fap

_fap()
{
    local cur prev dir i saveIFS

    COMPREPLY=()
    _get_comp_words_by_ref cur prev

    saveIFS=$IFS
    IFS=$'\n'    
    dir="$cur"
    if [ -z "$cur" ]; then
        dir="/home/user/music"
    elif ! [ -d "$cur" ]; then
        dir="`dirname "$cur"`"
    fi

    local files=$(find `dequote "$dir"` -type f -iname "*${prev}*" -printf "%p\n")
    COMPREPLY=( $( compgen -W "${files}" -- $cur ) )

    for ((i=0; i < ${#COMPREPLY[@]}; i++)); do
        _quote_readline_by_ref ${COMPREPLY[i]} COMPREPLY[i]
    done

    IFS=$saveIFS

    return 0
} &&
complete -F _fap -o nospace fap

Change the dir="/home/user/music" line accordingly (start folder for your music collection). Next source the script

. /etc/bash_completion.d/fap

Now you can use TAB completion like this

fap frozen [TAB]
fap frozen /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/09\ -\ Madonna\ -\ Frozen.mp3

or, if there are more options

$ fap girl [TAB]
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/[TAB][TAB]
/home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/04\ -\ Madonna\ -\ Candy\ Perfume\ Girl.mp3
/home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/13\ -\ Madonna\ -\ Mer\ Girl.mp3
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/0[TAB]
$ fap girl /home/user/music/MADONNA\ -\ RAY\ OF\ LIGHT/TRACKS/04\ -\ Madonna\ -\ Candy\ Perfume\ Girl.mp3
1
  • Seems interesting, let me give it a try
    – enzotib
    Sep 7, 2011 at 12:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .