Skip to content

Commit

Permalink
add git aliases from ohmyzsh to customize it
Browse files Browse the repository at this point in the history
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)

TAnks to those who have contributed to fix those 20+ issues:

ohmyzsh/ohmyzsh#1790
ohmyzsh/ohmyzsh#3535
ohmyzsh/ohmyzsh#3682
ohmyzsh/ohmyzsh#3962
ohmyzsh/ohmyzsh#3972
ohmyzsh/ohmyzsh#3977
ohmyzsh/ohmyzsh#3991
ohmyzsh/ohmyzsh#4085
ohmyzsh/ohmyzsh#4727
ohmyzsh/ohmyzsh#5130
ohmyzsh/ohmyzsh#5179
ohmyzsh/ohmyzsh#5362
ohmyzsh/ohmyzsh#5442
ohmyzsh/ohmyzsh#6329
ohmyzsh/ohmyzsh#6793
ohmyzsh/ohmyzsh#7682
ohmyzsh/ohmyzsh#7716
ohmyzsh/ohmyzsh#7754
ohmyzsh/ohmyzsh#867
ohmyzsh/ohmyzsh#9103
ohmyzsh/ohmyzsh#9114

and those who help develop
theses aliases and function
whith theses Pull 40+ Requests:

ohmyzsh/ohmyzsh#2790
ohmyzsh/ohmyzsh#3167
ohmyzsh/ohmyzsh#4304
ohmyzsh/ohmyzsh#4751
ohmyzsh/ohmyzsh#4830
ohmyzsh/ohmyzsh#4993
ohmyzsh/ohmyzsh#5025
ohmyzsh/ohmyzsh#5178
ohmyzsh/ohmyzsh#5271
ohmyzsh/ohmyzsh#5287
ohmyzsh/ohmyzsh#5306
ohmyzsh/ohmyzsh#5307
ohmyzsh/ohmyzsh#5390
ohmyzsh/ohmyzsh#5417
ohmyzsh/ohmyzsh#5433
ohmyzsh/ohmyzsh#5511
ohmyzsh/ohmyzsh#5591
ohmyzsh/ohmyzsh#5643
ohmyzsh/ohmyzsh#5729
ohmyzsh/ohmyzsh#5844
ohmyzsh/ohmyzsh#5849
ohmyzsh/ohmyzsh#5871
ohmyzsh/ohmyzsh#6006
ohmyzsh/ohmyzsh#6031
ohmyzsh/ohmyzsh#6059
ohmyzsh/ohmyzsh#6079
ohmyzsh/ohmyzsh#6297
ohmyzsh/ohmyzsh#6378
ohmyzsh/ohmyzsh#6789
ohmyzsh/ohmyzsh#6791
ohmyzsh/ohmyzsh#6893
ohmyzsh/ohmyzsh#7064
ohmyzsh/ohmyzsh#7472
ohmyzsh/ohmyzsh#7556
ohmyzsh/ohmyzsh#7629
ohmyzsh/ohmyzsh#7630
ohmyzsh/ohmyzsh#7724
ohmyzsh/ohmyzsh#7841
ohmyzsh/ohmyzsh#8089
ohmyzsh/ohmyzsh#8563
ohmyzsh/ohmyzsh#8617
ohmyzsh/ohmyzsh#8622
ohmyzsh/ohmyzsh#8697
ohmyzsh/ohmyzsh#8902
ohmyzsh/ohmyzsh#8935
ohmyzsh/ohmyzsh#8957
ohmyzsh/ohmyzsh#9049
Signed-off-by: Benjamin Vincent (Luxcium) <luxcium@neb401.com>
  • Loading branch information
Luxcium committed Sep 20, 2020
1 parent 7a9f0e1 commit 8766dc6
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 6 deletions.
11 changes: 7 additions & 4 deletions MAIN.sh
Expand Up @@ -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}"
Expand Down
247 changes: 245 additions & 2 deletions aliases.d/000-git.sh
Expand Up @@ -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'
Expand Down Expand Up @@ -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

0 comments on commit 8766dc6

Please sign in to comment.