Last active
February 13, 2021 01:12
-
-
Save secf00tprint/3b7f36cd51d176b8b2b1e6b18f05ab02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -> Git | |
# gcw | |
# sets local username + email in repo | |
# Usage: gcw git-repo-to-clone | |
git_clone_wrapper() { | |
last_arg="${@: -1}" | |
last_arg_ending="${last_arg: -4}" | |
# Based on https://www.git-scm.com/docs/git-clone last argument can be a specific directory to save into | |
# so checking if the last argument is a git repo: | |
if [ "$last_arg_ending" != ".git" ] | |
then | |
if [ $# -eq 1 ] | |
then | |
echo "no git url defined" | |
exit | |
fi | |
repo_arg="${@: -2}" | |
else | |
repo_arg="${@: -1}" | |
fi | |
git clone "$@" | |
python - << EOF | |
import os | |
from urlparse import urlparse | |
result = urlparse("$last_arg") | |
git_repo_full = result.path.rpartition('/')[2] # get last element | |
git_repo_dir = git_repo_full.split('.')[0] | |
os.chdir(os.getcwd()+'/'+git_repo_dir) | |
os.system ('git config --local user.name "Firstname Lastname"') | |
os.system ('git config --local user.email "myname@specific_domain.tld"') | |
EOF | |
} | |
alias gcw='git_clone_wrapper' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment