2

tl;dr: Is there a way to use an existing auto completion function to also auto complete arguments to an alias or short function.

Auto completion in bash is great but does not mix well with aliases and utility functions.

For example, let us say I often call an executable myexec with some arguments always there:

myexec --arg1=val1 --arg2 foo
myexec --arg1=val1 --arg2 bar
myexec --arg1=val1 --arg2 foobaz
...

To make my life easier I can create an alias: alias myalias='myexec --arg1=val1 --arg2', but then I will lose order completion for the arguments that varies from time to time (foo, bar, etc.)

Problem 1: Alias

Is there a way where I can make the auto completion on myalias act as though I have written myexec --arg1=val1 --arg2, that is, these two commands should produce the same output:

# Theese should provide identical completion
myalias foo[tab]
myexec --arg1=val1 --arg2 foo[tab]

Problem 2: Function

Is there a way to do the same for function, for example:

function myfun {
  cd ../..
  myexec --arg1=val1 --arg2 $@
  cd some/dir
}
# Theese should provide identical completion
myfun foo[tab]
myexec --arg1=val1 --arg2 foo[tab]

I have taking a look at this great introduction and on the man page, but I do not have experience enough to derive a solution from that.

Thanks a bunch for your help :)

1
  • Or switch to zsh. zsh completes with aliases just fine.
    – muru
    Jan 18, 2016 at 11:59

0

Browse other questions tagged .