added functions for rename branch and switch remote (origin) and completion

This commit is contained in:
Manuel Manhart 2024-03-26 23:40:27 +01:00
parent b3136b4d32
commit 9a08154085
4 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,9 @@
parseArgs_switchRemote() {
echo "Switching remote to $1"
if [ -z "$1" ]; then
echo "ERROR: Argument remote url is missing"
help switchRemote
else
REMOTE_URL=$1
fi
}

View File

@ -0,0 +1,9 @@
renameBranch() {
local newBranchName=main
local currentBranchName=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$1" ]; then
newBranchName=$1
fi
echo "Renaming $currentBranchName to $newBranchName"
git branch -m $currentBranchName $newBranchName
}

View File

@ -0,0 +1,8 @@
switchRemote() {
local remote=origin
local remoteUrl=$REMOTE_URL
local branch=main
git remote remove $remote
git remote add $remote $remoteUrl
}

View File

@ -5,7 +5,7 @@ _gt-completion()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
prevPrev="${COMP_WORDS[COMP_CWORD-2]}" prevPrev="${COMP_WORDS[COMP_CWORD-2]}"
opts="mind pullAndMerge help config" opts="mind renameBranch switchRemote pullAndMerge help config"
config="print set init" config="print set init"
# TODO check if this is still the most efficient way to list help options # TODO check if this is still the most efficient way to list help options