I'm trying to add an alias to my .bash_profile
to automate cloning a GitHub repo. The cloning part is straightforward:
alias createApp 'git clone https://github.com/user/repo.git'
This allows me to execute:
createApp foo
createApp bar
How can I modify the cloning alias to cd <destination_folder> && npm install
after cloning while keeping the current behavior of accepting a custom destination folder name?
Create a shell function rather than an alias.
createApp() {
git clone https://github.com/user/repo.git "$1" &&
(cd "$1" && npm install)
}
Putting the cd
in a subshell limits it to the npm
command.
I managed to do this indirectly with the help of .gitconfig
.
in .gitconfig
:
[alias]
createApp = "!f() { git clone https://github.com/user/repo.git \"$1\" && cd \"$1\" && npm install; }; f"
in .bash_profile
:
alias createApp='git createApp'
I will keep this question open to answer whether there is a direct (or better) way to do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.