DannyBen / alf

Bash Alias Generator and Manager
MIT License
90 stars 5 forks source link

Feature Request: completion #28

Closed planetceres closed 4 years ago

planetceres commented 4 years ago

This is a handy utility! Would be even better if this had bash completion like opcode. Any chance of that getting added as a feature?

Thanks for sharing it.

DannyBen commented 4 years ago

Well, I feel that with alf it is much less necessary than opcode, since:

  1. opcode is on a per project basis, so completion helps you remember what you have
  2. alf was designed so that you can make short intuitive shortcuts. if it needs completion, it is too long.

However, I am open to it.

DannyBen commented 4 years ago

Hey - I think this can be easily achieved, by doing this:

I can make alf generate also append completion commands to the end of the result (which normally goes into ~/.bash_aliases.

Something like this will be appended for each command:

complete -W "SUBCOMMANDS" COMMAND

So, for an alf configuration like this:

g: git
  s: status
  co: checkout
  new: checkout -b

the completion line will look like this:

complete -W "s co new" g

Thoughts?

I will try to implement it.

DannyBen commented 4 years ago

If you want, you can try the alf script from the add/completion branch

It will append completion commands to the end of the generated bash_aliases script.

You can see it by running

$ alf generate

or save it by running

$ alf save && source ~/.bash_aliases

It adds completion to subcommands. Completion for main commands is automatically enabled by bash

Is this what you meant?

planetceres commented 4 years ago

This is great! Exactly what I was asking for.

DannyBen commented 4 years ago

Great. It is released already in master.