Context
I have some functions defined in my ~/.bashrc which I'd like to turn into a Homebrew package. Currently, these functions act as custom commands on my command line:
# .bashrc
function foo() {
# do something interesting
}
# at terminal
$ foo
# => does the interesting thing
Approach
I've created a homebrew formula using brew create. My current approach is as follows:
- Move the function definitions into a separate file,
script, within a directory,brew-script - Make
brew-scriptdownloadable as a tarball,brew-script.tar.gz - Have my brew formula append text to the end of
~/.bash_profileto includescriptwhen terminal session starts
Concerns
Is modifying
.bash_profilein a brew formula bad practice? (eg. when uninstalling withbrew uninstall script, brew should somehow remove the text that was appended to.bash_profile... Parsing.bash_profiledoesn't seem very fun.)Is there a convention already established for including functions in bash scripts so that they are available from the command line?
Is it common to simply ask the user to add some text to their
.bash_profileor.bashrc?
Desired result
Should be able to install cleanly with brew and then run foo as a command:
$ brew install script
$ foo
# => does the interesting thing
(Assume the brew formula is already installed locally. I'll worry about auditing and pushing the formula to homebrew later)
brew uninstall foo. I'm trying to find a more flexible approach that allows a clean installation. The .bak file approach runs into difficulty when many modifications have been made to.bash_profileAFTER the specific modification we wish to undo. It seems to me that finding the exact parts of the file that we wish to remove involves parsing the file, which I would like to avoid as it seems error-prone.