I want to run some functions (which I created in ./.bash_func) in terminal with some files located somewhere. When I type the function and hit Tab Tab I want to list the files located in ./scipts like cd ./scipts Tab Tab

  • 2
    Please don't crosspost. – jasonwryan Mar 13 '15 at 18:46
  • What version of Ubuntu do you have? – Mark Plotnick Mar 13 '15 at 19:54
  • @MarkPlotnick Ubuntu-12.04-LTS-i386 – kevy Mar 13 '15 at 20:29
  • This should be closed on principle... – jasonwryan Mar 14 '15 at 1:13
  • @jasonwryan It was but I have reopened it since it is the only one of the three cross-posts that has an answer. The AU one one has been closed and the SU one is about to be. Let's keep this one open. – terdon Mar 14 '15 at 1:22

I did this once:

notes () { ... }

complete -F complete_notefiles notes

# following based on 
# http://unix.stackexchange.com/questions/77009/custom-autocomplete-deal-with-spaces-in-filenames 
complete_notefiles () {
    local cur=${COMP_WORDS[COMP_CWORD]}
    pushd ~/Documents/Notes >/dev/null
    popd >/dev/null

. ~/.bash_completion_functions 

I found that I needed to copy 3 functions from /usr/share/bash-completion/bash_completion: _filedir, _tilde, _quote_readline_by_ref

  • I couldn't find any folder named /usr/share/bash-completion/ – kevy Mar 13 '15 at 19:16
  • @VinuKevy On Ubuntu 12.04, those functions are in /etc/bash_completion . – Mark Plotnick Mar 16 '15 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.