I have some directories with music files
$ tree -d ~/Music/ /home/boffi/Music/ ├── Aldous_Harding │ ├── Aldous_Harding │ ├── Designer │ ├── Party │ └── Warm_Chris ├── Madness │ └── The_Very_Best └── Mitski ├── Be_the_Cowboy ├── Bury_Me_At_Makeout_Creek ├── Laurel_Hell ├── Lush ├── Puberty_2 ├── Retired_from_Sad,_New_Career_in_Business └── The_Land_Is_Inhospitable_and_So_Are_We and a script
$ cat ~/bin/pmd # Play Music Directories root=/home/boffi/Music/ list_of_dirs="" for dir in $@ ; do list_of_dirs=${list_of_dirs}" ${root}$dir" done list_of_files=$( find ${list_of_dirs} | shuf ) echo mpv -no-terminal -no-video ${list_of_files} $ When I cd ~/Music and use completions, then my command works as intended; when I execute it from a generic directory it does not work, as the completion (at its best) places the full path names on the command line.
How can I convince bash/readline to complete on directories/subdirectories rooted in ~/Music, without placing the full path name on the command line?
I have read autocomplete command from a certain folder and Bash autocomplete: List files and directories from other directory.
In the first case, the command take a single argument, in the second case the full path name is placed on the command line and it cannot complete on subdirectories.
Following a suggestion in a comment, I've implemented what is suggested here, but completing after pmds would list all the executables in my system, and if I execute the command anyway, I'm teletransported to ~/Music
$ pwd /home/boffi $ tail -3 .bashrc alias yt="yt-dlp -f 'bestvideo[height<=?720]+bestaudio/best' -write-sub --write-auto-sub --sub-lang 'en.*' -o" . /home/boffi/script $ cat script #!/usr/bin/bash pmds () { echo /home/boffi/Music/$1 ; } goM () { cd /home/boffi/Music ; } complete -s -F goM pmds $ . .bashrc $ pmds <TAB> Display all 6241 possibilities? (y or n) $ pmds pippo /home/boffi/Music/pippo $ pwd /home/boffi/Music $
go one-arg <tab>works just fine. If you did try it and could only complete one argument, show us the actual code you used.