diff --git a/MAIN.sh b/MAIN.sh index 4285d78b..f8480562 100644 --- a/MAIN.sh +++ b/MAIN.sh @@ -33,12 +33,15 @@ function __AHMYZSH__BOOT__LOADER__() { # foreachfile 'echo' '' '$(pwd)/' # ) - local SD1="${AHMYZSH}/aliases.d/000-git.sh" - if [ - "${SD1}" ]; then - ${SD1} + local SD1="${AHMYZSH}/aliases.d" + if [ -d "${SD1}" ]; then + for f in "${SD1}/"*; do + [ -f "${f}" ] && source "${f}" + done + # ${SD1} else - echo "Error loading files in '${S1}'... Directory or path can not be resolved" + echo "Error loading files in '${SD1}'... Directory or path can not be resolved" fi local S1="${CACHED_PATH}" diff --git a/aliases.d/000-git.sh b/aliases.d/000-git.sh index 816ef460..516e2246 100755 --- a/aliases.d/000-git.sh +++ b/aliases.d/000-git.sh @@ -21,8 +21,51 @@ alias pullmaster='git checkout master; git pull -S --stat --progress --signoff - # alias gitcleannext='rm -rf ./dist; rm -rf ./build; rm -f ./package.1.json; git add .; git commit -m "getting ready to build next/version"; push' # alias nextcycle='push; pullmaster; pullnext; commitpullnext; deletenext; newnext; gitcleannext; lb' -# https://github.com/ohmyzsh/ohmyzsh/blob/93c837fec8e9fe61509b9dff9e909e84f7ebe32d/LICENSE.txt -# 106 contri +# region https://github.com/ohmyzsh/ohmyzsh/blob/93c837fec8e9fe61509b9dff9e909e84f7ebe32d/plugins/git/git.plugin.zsh#L1-L293 +# Copyright (c) 2009-2020 Robby Russell and [contributors](https://github.com/ohmyzsh/ohmyzsh/contributors) +# this is the work of 106+ contributors over the last 10 years I will customize it to suit the needs of my project +# I am greatfull for all the people making opensource and free software possible... +# +# Functions +# + +# The name of the current branch +# Back-compatibility wrapper for when this function was defined here in +# the plugin, before being pulled in to core lib/git.zsh as git_current_branch() +# to fix the core -> git plugin dependency. +function current_branch() { + git_current_branch +} + +# Pretty log messages +function _git_log_prettily(){ + if ! [ -z $1 ]; then + git log --pretty=$1 + fi +} +compdef _git _git_log_prettily=git-log + +# Warn if the current branch is a WIP +function work_in_progress() { + if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then + echo "WIP!!" + fi +} + +# Check if main exists and use instead of master +function git_main_branch() { + if [[ -n "$(git branch --list main)" ]]; then + echo main + else + echo master + fi +} + +# +# Aliases +# (sorted alphabetically) +# + alias g='git' alias ga='git add' @@ -78,3 +121,203 @@ alias gdct='git describe --tags $(git rev-list --tags --max-count=1)' alias gds='git diff --staged' alias gdt='git diff-tree --no-commit-id --name-only -r' alias gdw='git diff --word-diff' + +function gdnolock() { + git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" +} +compdef _git gdnolock=git-diff + +function gdv() { git diff -w "$@" | view - } +compdef _git gdv=git-diff + +alias gf='git fetch' +alias gfa='git fetch --all --prune' +alias gfo='git fetch origin' + +alias gfg='git ls-files | grep' + +alias gg='git gui citool' +alias gga='git gui citool --amend' + +function ggf() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force origin "${b:=$1}" +} +compdef _git ggf=git-checkout +function ggfl() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force-with-lease origin "${b:=$1}" +} +compdef _git ggfl=git-checkout + +function ggl() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git pull origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git pull origin "${b:=$1}" + fi +} +compdef _git ggl=git-checkout + +function ggp() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git push origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git push origin "${b:=$1}" + fi +} +compdef _git ggp=git-checkout + +function ggpnp() { + if [[ "$#" == 0 ]]; then + ggl && ggp + else + ggl "${*}" && ggp "${*}" + fi +} +compdef _git ggpnp=git-checkout + +function ggu() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git pull --rebase origin "${b:=$1}" +} +compdef _git ggu=git-checkout + +alias ggpur='ggu' +alias ggpull='git pull origin "$(git_current_branch)"' +alias ggpush='git push origin "$(git_current_branch)"' + +alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)' +alias gpsup='git push --set-upstream origin $(git_current_branch)' + +alias ghh='git help' + +alias gignore='git update-index --assume-unchanged' +alias gignored='git ls-files -v | grep "^[[:lower:]]"' +alias git-svn-dcommit-push='git svn dcommit && git push github $(git_main_branch):svntrunk' + +alias gk='\gitk --all --branches' +alias gke='\gitk --all $(git log -g --pretty=%h)' + +alias gl='git pull' +alias glg='git log --stat' +alias glgp='git log --stat -p' +alias glgg='git log --graph' +alias glgga='git log --graph --decorate --all' +alias glgm='git log --graph --max-count=10' +alias glo='git log --oneline --decorate' +alias glol="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'" +alias glols="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --stat" +alias glod="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset'" +alias glods="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset' --date=short" +alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all" +alias glog='git log --oneline --decorate --graph' +alias gloga='git log --oneline --decorate --graph --all' +alias glp="_git_log_prettily" + +alias gm='git merge' +alias gmom='git merge origin/$(git_main_branch)' +alias gmt='git mergetool --no-prompt' +alias gmtvim='git mergetool --no-prompt --tool=vimdiff' +alias gmum='git merge upstream/$(git_main_branch)' +alias gma='git merge --abort' + +alias gp='git push' +alias gpd='git push --dry-run' +alias gpf='git push --force-with-lease' +alias gpf!='git push --force' +alias gpoat='git push origin --all && git push origin --tags' +alias gpu='git push upstream' +alias gpv='git push -v' + +alias gr='git remote' +alias gra='git remote add' +alias grb='git rebase' +alias grba='git rebase --abort' +alias grbc='git rebase --continue' +alias grbd='git rebase develop' +alias grbi='git rebase -i' +alias grbm='git rebase $(git_main_branch)' +alias grbs='git rebase --skip' +alias grev='git revert' +alias grh='git reset' +alias grhh='git reset --hard' +alias groh='git reset origin/$(git_current_branch) --hard' +alias grm='git rm' +alias grmc='git rm --cached' +alias grmv='git remote rename' +alias grrm='git remote remove' +alias grs='git restore' +alias grset='git remote set-url' +alias grss='git restore --source' +alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' +alias gru='git reset --' +alias grup='git remote update' +alias grv='git remote -v' + +alias gsb='git status -sb' +alias gsd='git svn dcommit' +alias gsh='git show' +alias gsi='git submodule init' +alias gsps='git show --pretty=short --show-signature' +alias gsr='git svn rebase' +alias gss='git status -s' +alias gst='git status' + +# use the default stash push on git 2.13 and newer +autoload -Uz is-at-least +is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')" \ + && alias gsta='git stash push' \ + || alias gsta='git stash save' + +alias gstaa='git stash apply' +alias gstc='git stash clear' +alias gstd='git stash drop' +alias gstl='git stash list' +alias gstp='git stash pop' +alias gsts='git stash show --text' +alias gstu='git stash --include-untracked' +alias gstall='git stash --all' +alias gsu='git submodule update' +alias gsw='git switch' +alias gswc='git switch -c' + +alias gts='git tag -s' +alias gtv='git tag | sort -V' +alias gtl='gtl(){ git tag --sort=-v:refname -n -l "${1}*" }; noglob gtl' + +alias gunignore='git update-index --no-assume-unchanged' +alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1' +alias gup='git pull --rebase' +alias gupv='git pull --rebase -v' +alias gupa='git pull --rebase --autostash' +alias gupav='git pull --rebase --autostash -v' +alias glum='git pull upstream $(git_main_branch)' + +alias gwch='git whatchanged -p --abbrev-commit --pretty=medium' +alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m "--wip-- [skip ci]"' + +alias gam='git am' +alias gamc='git am --continue' +alias gams='git am --skip' +alias gama='git am --abort' +alias gamscp='git am --show-current-patch' + +function grename() { + if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 old_branch new_branch" + return 1 + fi + + # Rename branch locally + git branch -m "$1" "$2" + # Rename branch in origin remote + if git push origin :"$1"; then + git push --set-upstream origin "$2" + fi +} + + +# endregion https://github.com/ohmyzsh/ohmyzsh/blob/93c837fec8e9fe61509b9dff9e909e84f7ebe32d/plugins/git/git.plugin.zsh#L1-L293