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/.config/bash/module/git.sh

137 lines
3 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 gbda="git branch | grep -v ^* | xargs 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"
2023-10-30 03:49:10 +03:00
# alias to preview diff while adding. adds current dir by default.
# usage: ga [FILES]
2023-12-05 23:56:04 +03:00
ga() {
2023-12-05 21:50:45 +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-12-05 23:56:04 +03:00
gr() {
2023-12-05 21:50:45 +03:00
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-09-30 07:20:31 +03:00
}
2023-10-12 13:06:34 +03:00
# specify git user as Dmitry Voronin with provided email.
# usage: gu [EMAIL]
2023-12-05 23:56:04 +03:00
gu() {
2023-12-05 21:50:45 +03:00
local name="Dmitry Voronin"
local email="${1}"
2023-10-12 13:06:34 +03:00
2023-12-05 21:50:45 +03:00
if [[ "${name}" = "" || "${email}" = "" ]]; then
echo "usage: gu [EMAIL]"
return 2
fi
2023-10-12 13:06:34 +03:00
2023-12-05 21:50:45 +03:00
git config user.name "${name}"
git config user.email "${email}"
2023-10-12 13:06:34 +03:00
}
2023-11-18 06:11:37 +03:00
# Get my git repo.
# Usage: gg <REPO>
2023-12-05 23:56:04 +03:00
gg() {
2023-12-05 21:50:45 +03:00
git clone https://git.voronind.com/voronind/"${1}"
2023-11-18 06:11:37 +03:00
}
2023-11-28 02:17:25 +03:00
# See diff for a specific commit.
# Usage: gdc <COMMITHASH>
2023-12-05 23:56:04 +03:00
gdc() {
2023-12-05 21:50:45 +03:00
git diff "${1}^!"
2023-11-28 02:17:25 +03:00
}
2023-11-27 21:18:55 +03:00
# Show current branch.
2023-12-05 23:56:04 +03:00
_git_current_branch() {
2023-12-05 21:50:45 +03:00
git branch --show-current 2> /dev/null
2023-11-27 21:18:55 +03:00
}
# Show origin's url.
2023-12-05 23:56:04 +03:00
_git_origin_url() {
2023-12-05 21:50:45 +03:00
git remote get-url origin
}
# Get this dotfiles url.
2023-12-05 23:56:04 +03:00
_git_dotfiles_url() {
2023-12-05 21:50:45 +03:00
echo 'https://git.voronind.com/voronind/linux.git'
}
# Check if current git repo is this dotfiles.
2023-12-05 23:56:04 +03:00
_git_is_dotfiles() {
2023-12-05 21:50:45 +03:00
# [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]]
local dir="${PWD}"
2023-12-05 21:50:45 +03:00
while [[ "${dir}" != "" ]]; do
if [[ -d "${dir}/.git" ]]; then
if [[ "${dir}" = "${HOME}" ]] || [[ "${dir}" = "$(realpath ${HOME})" ]]; then
2023-12-05 21:50:45 +03:00
return 0
else
return 1
fi
fi
dir="${dir%/*}"
done
}
2023-10-23 03:31:00 +03:00
# autocomplete.
2023-12-05 23:56:04 +03:00
_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
2023-11-04 23:12:41 +03:00
__git_complete gchb _git_checkout &> /dev/null
2023-12-05 23:56:04 +03:00
__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() {
2023-12-05 21:50:45 +03:00
_autocomplete_first account@voronind.com dd.voronin@fsight.ru
}
complete -F _gu gu