Last active
May 12, 2020 09:21
-
-
Save Willshaw/f3db6120cbf4e592fe49b9f4052ab091 to your computer and use it in GitHub Desktop.
Short cut to git commit -m using folder path after httpdocs
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
# add this to your ~/.bashrc | |
# then as long as you're inside an httpdocs folder (e.g. /var/www/vhosts/example/httpdocs/my/awesome/tool) | |
# you can go like this: | |
# git add . | |
# git status (to be safe now) | |
# git_quick_commit I done some stuff | |
# | |
# and you'll get a commit message like: | |
# 45dcc35 my > awesome > tool: I done some stuff | |
# | |
# if you're in httpdocs at the time, e.g. /var/www/vhosts/example/httpdocs then it's more like this | |
# | |
# # git add . | |
# git status (you should just always be doing this right) | |
# git_quick_commit more stuff done | |
# | |
# and you'll get a commit message like: | |
# 123abc7 more stuff done | |
# quick commit message, to use everything after httpdocs | |
function git_quick_commit { | |
# this only works for something inside an httpdocs folder | |
if pwd | grep -iv "httpdocs" | |
then | |
echo 'no httpdocs found, cannot quick-commit' | |
return | |
fi | |
# we need a commit message | |
message="$@" | |
if [[ -z "$message" ]] | |
then | |
echo 'No commit message supplied' | |
return | |
fi | |
# strip everything up to and including httpdocs | |
# replace remaining / with > | |
# e.g. /var/www/vhosts/example/httpdocs/path/to/tool/ | |
# becomes path > to > tool | |
toolpath="$(pwd | sed -E "s/.*httpdocs\/?//" | sed -E "s/\// > /g")" | |
# if the tool path isn't empty, add a colon, | |
# before using all params as one string | |
# e.g. git_qucik_commit all this stuff | |
# will become "path > to > tool: all this stuff" | |
if [[ ! -z "$toolpath" ]] | |
then | |
message="$toolpath: $message" | |
fi | |
echo "Commiting with message: $message" | |
git commit -m "$message" | |
} |
actually I need to change exit
to return
to stop it closing!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
had to change
exit
toexit 1
otherwise it was closing the terminal/screen session