Skip to content

Instantly share code, notes, and snippets.

@hzbd
Last active November 21, 2021 05:13
Show Gist options
  • Save hzbd/5e388698197cc791d01572d251aa63c8 to your computer and use it in GitHub Desktop.
Save hzbd/5e388698197cc791d01572d251aa63c8 to your computer and use it in GitHub Desktop.
git lazy bash demo.
#!/bin/bash
#
# Usage:
# gitlazy -c <commit-message> -p <branch>
#
set +x
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LIGHTGRAY='\033[0;37m'
DARKGRAY='\033[1;30m'
LIGHTRED='\033[1;31m'
LIGHTGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
LIGHTPURPLE='\033[1;35m'
LIGHTCYAN='\033[1;36m'
WHITE='\033[1;37m'
function show_usage (){
if [ ! -z "${1}" ];then
echo -e "${LIGHTRED}Invalid argument: \`${1}\`${NOCOLOR}"
fi
echo -e "Usage: `basename $0` ${GREEN}-c <commit-message> -p ${YELLOW}<branch>${NOCOLOR}";
exit 1;
}
function git_status (){
echo -e "${LIGHTPURPLE}+--------------------+";
echo -e "${ORANGE}=> ${GREEN}git status${NOCOLOR}";
git status -s -b;
}
function git_add (){
echo -e "${ORANGE}=> ${GREEN}git add . -A${NOCOLOR}";
git add . -A;
}
function git_commit (){
echo -e "${ORANGE}=> ${GREEN}git commit -a -m \"$@\" ${NOCOLOR}";
git commit -a -m "`echo $@`" || echo -e "${LIGHTRED}No changes to commit${NOCOLOR}";
}
function git_push (){
echo -e "${ORANGE}=> ${GREEN}git push origin "$1"${NOCOLOR}";
git push origin "$1"
}
function git_done (){
echo -e "${ORANGE}=> ${GREEN}ok";
echo -e "${LIGHTPURPLE}+--------------------+";
}
if [ $# -lt 1 ];then
show_usage
exit 0
fi
while [ ! -z "${1}" ]; do
case "${1}" in
--commit|-c)
shift
git_status
git_add
git_commit ${1}
;;
--push|-p)
shift
git_push ${1}
;;
--help|*|-h)
show_usage $@
;;
esac
shift
git_done
done
@hzbd
Copy link
Author

hzbd commented Nov 21, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment