214 lines
3.5 KiB
Bash
214 lines
3.5 KiB
Bash
# Git push.
|
|
gps() {
|
|
git push "${@}"
|
|
}
|
|
|
|
# Git force push.
|
|
gpsf() {
|
|
git push --force "${@}"
|
|
}
|
|
|
|
# Git pull.
|
|
gpl() {
|
|
git pull "${@}"
|
|
}
|
|
|
|
# Git log.
|
|
gl() {
|
|
git log "${@}"
|
|
}
|
|
|
|
# Git status.
|
|
gs() {
|
|
git status "${@}"
|
|
}
|
|
|
|
# Git stash.
|
|
gst() {
|
|
git stash "${@}"
|
|
}
|
|
|
|
# Git diff.
|
|
gd() {
|
|
git diff "${@}"
|
|
}
|
|
|
|
# Git commit.
|
|
gc() {
|
|
git commit -m "${@}"
|
|
}
|
|
|
|
# Git checkout.
|
|
gch() {
|
|
git checkout "${@}"
|
|
}
|
|
|
|
# Git checkout branch.
|
|
gchb() {
|
|
git checkout -b "${@}"
|
|
}
|
|
|
|
# Git branch.
|
|
gb() {
|
|
git branch --all "${@}"
|
|
}
|
|
|
|
# Git branch delete.
|
|
gbd() {
|
|
git branch -D "${@}"
|
|
}
|
|
|
|
# Git branch delete all except current.
|
|
gbda() {
|
|
git branch | grep -v ^* | xargs git branch -D
|
|
}
|
|
|
|
# Git fetch all.
|
|
gf() {
|
|
git fetch --all -v -p
|
|
}
|
|
|
|
# Git tag.
|
|
gt() {
|
|
git tag "${@}"
|
|
}
|
|
|
|
# Git ignore files.
|
|
gi() {
|
|
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
|
|
}
|
|
|
|
# Git patch create.
|
|
# Usage: gpc <FILE>
|
|
gpc() {
|
|
git diff > "${@}"
|
|
}
|
|
|
|
# Git patch (apply).
|
|
# Usage: gp <FILE>
|
|
gp() {
|
|
git apply "${@}"
|
|
}
|
|
|
|
# Run git garbage collection.
|
|
ggc() {
|
|
git gc --aggressive --no-cruft --prune=now
|
|
}
|
|
|
|
# Preview diff while adding. adds current dir by default.
|
|
# Usage: ga [FILES]
|
|
ga() {
|
|
local target=${@}
|
|
|
|
if [[ "${target}" = "" ]]; then
|
|
target="."
|
|
fi
|
|
|
|
git diff ${target}
|
|
git add ${target}
|
|
}
|
|
|
|
# rebase by X commits or from root. when COUNT is 0 - rebase from root. default is 2.
|
|
# usage: gr [COMMIT COUNT]
|
|
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
|
|
}
|
|
|
|
# specify git user as Dmitry Voronin with provided email.
|
|
# usage: gu [EMAIL]
|
|
gu() {
|
|
local name="Dmitry Voronin"
|
|
local email="${1}"
|
|
|
|
if [[ "${name}" = "" || "${email}" = "" ]]; then
|
|
echo "usage: gu [EMAIL]"
|
|
return 2
|
|
fi
|
|
|
|
git config user.name "${name}"
|
|
git config user.email "${email}"
|
|
}
|
|
|
|
# Get my git repo.
|
|
# Usage: gg <REPO>
|
|
gg() {
|
|
git clone https://git.voronind.com/voronind/"${1}"
|
|
}
|
|
|
|
# See diff for a specific commit.
|
|
# Usage: gdc <COMMITHASH>
|
|
gdc() {
|
|
git diff "${1}^!"
|
|
}
|
|
|
|
# Show current branch.
|
|
_git_current_branch() {
|
|
git branch --show-current 2> /dev/null
|
|
}
|
|
|
|
# Show origin's url.
|
|
_git_origin_url() {
|
|
git remote get-url origin
|
|
}
|
|
|
|
# Get this dotfiles url.
|
|
_git_dotfiles_url() {
|
|
echo 'https://git.voronind.com/voronind/linux.git'
|
|
}
|
|
|
|
# Check if current git repo is this dotfiles.
|
|
_git_is_dotfiles() {
|
|
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
|
|
local dir="${PWD}"
|
|
|
|
while [[ "${dir}" != "" ]]; do
|
|
if [[ -d "${dir}/.git" ]]; then
|
|
if [[ "${dir}" = "${HOME}" ]] || [[ "${dir}" = "$(realpath ${HOME})" ]]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
fi
|
|
|
|
dir="${dir%/*}"
|
|
done
|
|
}
|
|
|
|
# autocomplete.
|
|
_completion_loader git &> /dev/null
|
|
__git_complete gps _git_push &> /dev/null
|
|
__git_complete gpsf _git_push &> /dev/null
|
|
__git_complete gpl _git_pull &> /dev/null
|
|
__git_complete gl _git_log &> /dev/null
|
|
__git_complete gs _git_status &> /dev/null
|
|
__git_complete gst _git_stash &> /dev/null
|
|
__git_complete gd _git_diff &> /dev/null
|
|
__git_complete gdc _git_diff &> /dev/null
|
|
__git_complete gc _git_commit &> /dev/null
|
|
__git_complete gch _git_checkout &> /dev/null
|
|
__git_complete gchb _git_checkout &> /dev/null
|
|
__git_complete gb _git_branch &> /dev/null
|
|
__git_complete gbd _git_branch &> /dev/null
|
|
__git_complete gf _git_fetch &> /dev/null
|
|
__git_complete gt _git_tag &> /dev/null
|
|
__git_complete gp _git_apply &> /dev/null
|
|
__git_complete ga _git_add &> /dev/null
|
|
|
|
_gu() {
|
|
_autocomplete_first account@voronind.com dd.voronin@fsight.ru
|
|
}
|
|
|
|
complete -F _gu gu
|