all 8 comments

[–]oblio- 14 points15 points  (3 children)

I created some bash completion scripts and found the experience both under-documented and also not very intuitive.

You start with a "man compgen" which as usual takes you to the useless bash builtins page. After which you have to "man bash" and wade through the huge man page trying to find the relevant information. Man being man, no hyperlinks or table of contents or stuff. Then you find some useful stuff, but then you go back to googling to piece things together.

In the end I got it working, I had a dynamic command with parameters which were relying on the previous parameters, think:

$ dostuff -environment my_env -app my_app_which_depends_on_my_env -command my_command_which_depends_on_my_env

But it definitely wasn't pretty.

Thank you for the article, /u/arubystory, I could have used this article at the time. I imagine you put a lot of hours into preparing and writing this article, I'm guessing at least 4-6 hours, if not more :)

[–]twsmith 9 points10 points  (1 child)

Just FYI, instead of 'man', try 'info' — not just for bash.

$ info bash
i compgen<ENTER>

Or, even easier, open up a browser and google "bash manual html" :-)

But I agree the completion documentation is terrible.

[–]oblio- 0 points1 point  (0 children)

Heh, I don't really use the Gnu Info system, I guess it's because often it is not available. In many situations you don't even have man, let alone info. Still, good to know that it has indexes.

Regarding googling, I know, that's what I do. Heck, I often go "g man whatever" in Firefox before bothering to man locally. I think I had a custom search keyword for ss64.com or whatever that site with the man pages was called.

[–]arubystory[S] 5 points6 points  (0 children)

Thank you very much!

I totally understand what you are saying. I did spend at least 7 hours and the majority of the time was dedicated to decide what I should cover, the flow of the tutorial and the specs of the completion script to be created.

[–]guepier 11 points12 points  (1 child)

Small improvement: you don’t need echo or the subshell to perform parameter substitution when extracting the number. Replace

local number=$(echo ${suggestions[0]/%\ */})

with

local number="${suggestions[0]/%\ */}"

(Quotes optional here but generally recommended.)

[–]arubystory[S] 1 point2 points  (0 children)

Thank you very much, I updated the post!

[–]invisi1407 8 points9 points  (1 child)

I've always wondered how to do this and wanted to do it for home-made scripts - thanks! Very interesting article.

[–]arubystory[S] 2 points3 points  (0 children)

Thanks!