Bash Functions You Need To Use
Ever wish you could type this to create a file along with any necessary parent folders?
touch public/views/about.html
Just open up your .bash_profile file and paste in the following function
ptouch() {
for p in "$@"; do
_dir="$(dirname -- "$p")"
[ -d "$_dir" ] || mkdir -p -- "$_dir"
touch -- "$p"
done
}
now either reboot your terminal or type source ~/.bash_profile
and from now on you can type
ptouch public/views/about.html
and rejoice.
While we’re add it, add
mcd() {
mkdir -p $1
cd $1
}
so you can mcd myproject
, which creates a directory and puts you inside that directory all in one command.
Yay.