This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.linux/bash/module/git.sh

103 lines
2.1 KiB
Bash
Raw Normal View History

2023-08-08 16:24:15 +03:00
# short aliases.
alias gps="git push"
2023-10-14 02:09:58 +03:00
alias gpsf="git push --force"
2023-08-08 16:24:15 +03:00
alias gpl="git pull"
alias gl="git log"
alias gs="git status"
alias gst="git stash"
alias gd="git diff"
alias gc="git commit -m"
alias gch="git checkout"
alias gchb="git checkout -b"
2023-10-23 04:54:33 +03:00
alias gb="git branch --all"
alias gbd="git branch -D"
alias gf="git fetch --all -v -p"
2023-08-08 16:24:15 +03:00
alias gt="git tag"
alias gi="git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached"
alias gpc="git diff >"
alias gp="git apply"
# get current git tag.
git_tag()
{
git log | grep commit -m1 | sed -e "s/.*\ //g" | cut -c 1-11;
}
2023-10-30 03:49:10 +03:00
# alias to preview diff while adding. adds current dir by default.
# usage: ga [FILES]
2023-08-08 16:24:15 +03:00
ga()
{
2023-10-30 03:49:10 +03:00
local target=${@}
if [[ "${target}" = "" ]]; then
target="."
fi
git diff ${target}
git add ${target}
2023-08-08 16:24:15 +03:00
}
2023-09-30 07:20:31 +03:00
2023-10-30 03:49:10 +03:00
# rebase by X commits or from root. when COUNT is 0 - rebase from root. default is 2.
# usage: gr [COMMIT COUNT]
2023-09-30 07:20:31 +03:00
gr()
{
local base="${1}"
# rebase last 2 commits by default.
if [[ "${base}" = "" ]]; then
base="2"
fi
# if 0, rebase from root. else from specified base.
if [[ "${base}" = "0" ]]; then
git rebase -i --root
else
git rebase -i HEAD~${base}
fi
}
2023-10-12 13:06:34 +03:00
# specify git user as Dmitry Voronin with provided email.
# usage: gu [EMAIL]
2023-10-12 13:06:34 +03:00
gu()
{
local name="Dmitry Voronin"
local email="${1}"
2023-10-12 13:06:34 +03:00
if [[ "${name}" = "" || "${email}" = "" ]]; then
echo "usage: gu [EMAIL]"
2023-10-12 13:06:34 +03:00
return 1
fi
git config user.name "${name}"
git config user.email "${email}"
}
2023-10-23 03:31:00 +03:00
# autocomplete.
# if is a fix for rsync.
if [[ $- = *i* ]]; then
_completion_loader git
__git_complete gps _git_push
__git_complete gpsf _git_push
__git_complete gpl _git_pull
__git_complete gl _git_log
__git_complete gs _git_status
__git_complete gst _git_stash
__git_complete gd _git_diff
__git_complete gc _git_commit
__git_complete gch _git_checkout
__git_complete gchb _git_checkout
__git_complete gb _git_branch
__git_complete gbd _git_branch
__git_complete gf _git_fetch
__git_complete gt _git_tag
__git_complete gp _git_apply
__git_complete ga _git_add
fi
_gu()
{
2023-10-30 03:49:10 +03:00
_autocomplete_first account@voronind.com dd.voronin@fsight.ru
}
complete -F _gu gu