Skip to content

Instantly share code, notes, and snippets.

@jdugarte
Last active June 5, 2024 23:59
Show Gist options
  • Save jdugarte/4d87b3fffabc5ef5df3025b90f29d841 to your computer and use it in GitHub Desktop.
Save jdugarte/4d87b3fffabc5ef5df3025b90f29d841 to your computer and use it in GitHub Desktop.
~/.zshrc
source ~/.zsh/antigen.zsh
alias cd..='cd ..'
alias cd...='cd ../..'
# ruby
__be() {
if [ -f "bin/$1" ]; then
"bin/$@"
else
bundle exec "$@"
fi
}
alias be="__be"
# go
export GOPATH=~/gocode
export PATH="$PATH:$GOPATH/bin"
# git
export EDITOR="mate -w"
export VISUAL="mate --wait"
__main_branch() { git remote show origin | awk '/HEAD branch/ {print $NF}'; }
__current_branch() { git symbolic-ref --short HEAD; }
__is_git_repo() {
git rev-parse --is-inside-work-tree &>/dev/null
if [ $? -ne 0 ]; then
echo "Not a git repository"
return 1
fi
}
log_branch() {
if __is_git_repo; then
git --no-pager log --oneline "$(__current_branch)" ^origin/"$(__main_branch)" --no-merges
fi
}
__parent_commit_from_branch() {
if __is_git_repo; then
local first_commit=$(log_branch | tail -1 | awk '{print $1;}')
git --no-pager log --pretty=%P -n 1 "$first_commit"
fi
}
rebase_current_branch() {
if __is_git_repo; then
local parent_commit=$(__parent_commit_from_branch)
if [ -n "$parent_commit" ]; then
git rebase -i "$parent_commit"
else
echo "Nothing to rebase"
fi
fi
}
list_local_merged_branches() {
if __is_git_repo; then
git branch --merged "$(__main_branch)" | grep -v "$(__main_branch)" | grep -v "^\\*"
fi
}
delete_local_merged_branches() {
if __is_git_repo; then
local branches=$(list_local_merged_branches)
if [ -n "$branches" ]; then
echo "The following branches will be deleted:"
echo "$branches"
read -r "choice?Proceed with deletion? (y/n): "
case "$choice" in
y|Y ) echo "$branches" | xargs -n 1 -r git branch -d;;
* ) echo "Deletion aborted";;
esac
else
echo "No local merged branches to delete"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment