83 lines
2.2 KiB
Bash
83 lines
2.2 KiB
Bash
# git functions
|
|
function git-branch-name() {
|
|
git rev-parse --abbrev-ref HEAD
|
|
}
|
|
function git-current-remote() {
|
|
git config branch.$(git-branch-name).remote
|
|
}
|
|
function grevs() {
|
|
git rev-list --count $1..
|
|
}
|
|
function gri() {
|
|
REVISION_COUNT=$(grevs $1)
|
|
git rebase -iS HEAD~$REVISION_COUNT
|
|
}
|
|
function gp() {
|
|
if [[ $(git-current-remote | head -c1 | wc -c) -ne 0 ]]; then
|
|
git push $(git-current-remote) $(git-branch-name)
|
|
else
|
|
git push --set-upstream origin $(git-branch-name)
|
|
fi
|
|
}
|
|
function gll() {
|
|
REMOTE=${1:-$(git-current-remote)}
|
|
git pull $REMOTE $(git-branch-name)
|
|
}
|
|
function gfp() {
|
|
git push -f origin $(git-branch-name)
|
|
}
|
|
function gfu() {
|
|
BRANCH=$(git-branch-name)
|
|
git fetch upstream $BRANCH && git merge upstream/$BRANCH
|
|
}
|
|
function gtg=() {
|
|
git tag -s $1 && gp && gp --tags
|
|
}
|
|
function git-prune-branches() {
|
|
REMOTE=$1
|
|
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep $REMOTE) | awk '{print $1}' | xargs git branch -d
|
|
}
|
|
|
|
# kubernetes functions
|
|
function k8s_ns_stuck() {
|
|
NAMESPACE=$1
|
|
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $NAMESPACE
|
|
}
|
|
function k8s_ns_nuke() {
|
|
NAMESPACE=$1
|
|
kubectl get namespace "$NAMESPACE" -o json \
|
|
| tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
|
|
| kubectl replace --raw /api/v1/namespaces/$NAMESPACE/finalize -f -
|
|
}
|
|
|
|
# other functions
|
|
function random_string() {
|
|
head /dev/urandom | LC_ALL=C tr -dc 'A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}~' | head -c $1
|
|
}
|
|
|
|
# devcontainer aliases
|
|
function devcup() {
|
|
devcontainer up --workspace-folder .
|
|
}
|
|
function devcexec() {
|
|
devcontainer exec --workspace-folder . $1
|
|
}
|
|
function devcshell() {
|
|
devcexec /usr/bin/zsh
|
|
}
|
|
|
|
# Dotfile update command(s)
|
|
function update_dotfiles() {
|
|
echo "Fetching latest dotfiles."
|
|
cd $XDG_CONFIG_HOME/dotfiles
|
|
git pull origin main > /dev/null 2>&1
|
|
sh $XDG_CONFIG_HOME/dotfiles/setup.sh > /dev/null 2>&1
|
|
nvim --headless "+Lazy! install" +qa > /dev/null 2>&1
|
|
nvim --headless "+Lazy! clean" +qa > /dev/null 2>&1
|
|
}
|
|
|
|
# Tool functions
|
|
function vide() {
|
|
neovide $1 &
|
|
}
|