Last active
August 27, 2021 07:20
-
-
Save fboes/4e404de6b0a2056922707eb708aedfe8 to your computer and use it in GitHub Desktop.
fboes' personal `.bash_alias`. See https://www.digitalocean.com/community/tutorials/an-introduction-to-useful-bash-aliases-and-functions
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
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]:\[\033[00;95m\]$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo -)\[\033[00m\]\$ ' | |
export PS1 | |
alias la="ls -lah" | |
# Put me in `.bash_aliases`, works like an alias. | |
# See https://stackoverflow.com/a/7131683 | |
export DEFAULT_DOCKER_SERVICE=web | |
_docker() { | |
case "${1}" in | |
"up") | |
FILE=""; | |
if [[ "${2}" ]]; then | |
FILE="-f docker-compose.${2:-test}.yml" | |
fi | |
docker-compose ${FILE} up -d | |
;; | |
"test") | |
docker-compose -f docker-compose.test.yml up | |
;; | |
"stop") | |
docker-compose stop | |
;; | |
"ssh") | |
docker-compose exec ${2:-${DEFAULT_DOCKER_SERVICE}} ${3:-/bin/bash --login} | |
;; | |
"exec") | |
docker-compose exec ${3:-${DEFAULT_DOCKER_SERVICE}} ${2:-/bin/bash --login} | |
;; | |
*) | |
echo "Usage:" | |
echo -e " \e[94m_docker COMMAND [\$1] [\$2]\e[0m" | |
echo | |
echo "Commands:" | |
echo -e " \e[94mup\e[0m Run 'docker-compose(.override).yml' or docker-compose.\e[1m\$1\e[0m.yml daemonized" | |
echo -e " \e[94mtest\e[0m Run 'docker-compose.test.yml'" | |
echo -e " \e[94mstop\e[0m Stop Docker images launched via 'docker-compose'" | |
echo -e " \e[94mssh\e[0m Open shell or execute \e[1m\$2\e[0m in '${DEFAULT_DOCKER_SERVICE}' or \e[1m\$1\e[0m" | |
echo -e " \e[94mexec\e[0m Open shell or execute \e[1m\$1\e[0m in '${DEFAULT_DOCKER_SERVICE}' or \e[1m\$2\e[0m" | |
;; | |
esac | |
} | |
# Put me in `.bash_aliases`, works like an alias. | |
git-merge-to() { | |
TARGET_BRANCH=preview | |
if [[ "${1}" ]]; then | |
TARGET_BRANCH=${1} | |
fi | |
FEATURE_BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') | |
if [[ ! "${FEATURE_BRANCH}" ]]; then | |
echo -e "\e[91mERROR\e[0m: No git branch found" | |
return 4 | |
fi | |
if [[ "${FEATURE_BRANCH}" =~ ^(main|master|develop|preview)$ ]]; then | |
echo -e "\e[91mERROR\e[0m: Branch ${FEATURE_BRANCH} is not a mergable branch" | |
git branch | |
return 2 | |
fi | |
if [[ "${FEATURE_BRANCH}" == "${TARGET_BRANCH}" ]]; then | |
echo -e "\e[91mERROR\e[0m: Branches are identical" | |
return 3 | |
fi | |
echo -en "Merge branch \e[94m${FEATURE_BRANCH}\e[0m into \e[94m${TARGET_BRANCH}\e[0m? [yn] " | |
read CONFIRM | |
if [[ ! "${CONFIRM}" =~ ^(y|Y|yes|Yes)$ ]]; then | |
echo "Cancelled" | |
return 1 | |
fi | |
git push | |
git checkout ${TARGET_BRANCH} | |
git pull | |
git merge ${FEATURE_BRANCH} --no-edit | |
git push | |
git checkout ${FEATURE_BRANCH} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment