2

I have several functions in my ~/.bash_profile named pg_dump_[dbname]_[envname] so I would like to enter

type pg_dump [tab]

(or some other command besides type) for bash to show the definitino of that function. Is this a builtin for osx that I am missing how to use or is there a third party to do this?

3
  • As far as I can see this works out of the box for me. Which version of bash are you using?
    – nohillside
    Oct 10, 2021 at 12:23
  • 1
    @nohillside I messed up the question: I had intended to ask about showing the definition of the function. The title of the question and the contents have been updated. My bad. Oct 10, 2021 at 12:26
  • 1
    You can add some auto completion by using COMPREPLY, COMP_WORDS and COMP_CWORD example here.
    – Ptit Xav
    Oct 10, 2021 at 14:11

1 Answer 1

1

If you are using ksh/bash/zsh, you want:

$ typeset -f name_of_the_function

That will display the definition.

3
  • My question is about how to get automatic listing of the function names. Yes typeset -f can show the definition- but so does type itself: but it seems neither one can use tab completion to find the available functions meeting a prefix Oct 10, 2021 at 18:57
  • Yes, type shows the function definition, but only in bash. The shell should already be completing the defined functions when they are first on the command line. If you are expecting them to be completed as an argument to some other command, ksh won't do that. Bash or zsh, you'd have to write your own completion logic to change what the shell tries to complete against post first entry on the command line. Oct 10, 2021 at 19:16
  • ok upvoted for the info since it applies to other shells (useful for other folks) Oct 10, 2021 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .