I have lots of functions in my bashrc, but for newly created ones I often forget the name of the function.
So for example, when I have defined this function in my .bashrc:
function gitignore-unstaged
{
### Description:
# creates a gitignore file with every file currently not staged/commited.
# (except the gitingore file itself)
### Args: -
git ls-files --others | grep --invert-match '.gitignore' > ./.gitignore
}
And I would like to have another function which prints out the definition of the function like:
$ grepfunctions "gitignore"
function gitignore-unstaged
{
### Description:
# creates a gitignore file with every file currently not staged/commited.
# (except the gitingore file itself)
### Args: -
git ls-files --others | grep --invert-match '.gitignore' > ./.gitignore
}
But instead of matching for "gitignore" I want it to match every string between funtction and }, so $ grepfunctions "###" and $ grepfunctions "creates" should output the exact same thing. That's also the reason, why declare -f and such don't solve the problem.
What I have tried
- I can't use grep
I know, that
sed -n -e '/gitignore-unstaged/,/^}/p' ~/.bashrcprints out what i want - butsed -n -e '/creates/,/^}/p' ~/.bashrcnot. Instead, I receive:# creates a gitignore file with every file currently not staged/commited. # (except the gitingore file itself) ### Args: - git ls-files --others | grep --invert-match '.gitignore' > ./.gitignore }The function name and the first
{are cut out, which is not what I want.
How can I print out the complete function declaration of any function which has a specific string inside it? Of course, other tools than sed are also allowed.
type -f functionname?. 1) i sometimes don't know the exact function name. 2) Sometimes, i don't know anything from the function name, just something from the body.functionand the last}of this particular function.