bash: move gc to scripts

Signed-off-by: Michael Grote <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2024-06-05 20:18:01 +02:00
parent 78bda4fdb2
commit 79bea1364a
3 changed files with 29 additions and 30 deletions

View file

@ -57,36 +57,6 @@ function gcm {
git commit -s -m "$*"
fi
}
function gc {
case "$1" in
--help | -h)
cat <<EOF
Description:
"git checkout" on steroids
Usage:
gc [--help|--new-branch] [branch]
Options:
-h, --help Print this help.
-b, --new-branch Create a new Branch instead changing to an existing branch.
Author:
michael.grote@posteo.de - git.mgrote.net
EOF
;;
--new-branch | -b)
(git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') || (git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ')
;;
*)
if [ -n "$1" ] ; then
(echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) || (echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch!")
else
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') || (git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') || (git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
fi
esac
}
function gp {
git pull "$@"
}

1
scripts/gc Symbolic link
View file

@ -0,0 +1 @@
git_checkout

28
scripts/git_checkout Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
case "$1" in
--help | -h)
cat <<EOF
Description:
"git checkout" on steroids
Usage:
gc [--help|--new-branch] [branch]
Options:
-h, --help Print this help.
-b, --new-branch Create a new Branch instead changing to an existing branch.
Author:
michael.grote@posteo.de - git.mgrote.net
EOF
;;
--new-branch | -b)
(git checkout --quiet -b "$2" && git push --set-upstream "$(git remote | head -n 1)" "$2" && echo '>>> Create new branch "'"$2"'"') || (git checkout --quiet "$2" > /dev/null 2>&1 && echo '>>> Branch already exists, checking out... ')
;;
*)
if [ -n "$1" ] ; then (echo ">>> Try local checkout" && git checkout --quiet "$1" > /dev/null 2>&1) || (echo ">>> Try remote checkout" && git checkout --quiet -b "$1" origin/"$1" > /dev/null 2>&1 || echo ">>> Unkown branch! ")
else
(git checkout --quiet master > /dev/null 2>&1 && echo '>>> Try checking out master') || (git checkout --quiet main > /dev/null 2>&1 && echo '>>> Try checking out main') || (git checkout --quiet release > /dev/null 2>&1 && echo '>>> Try checking out release')
fi
esac