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

229 lines
4.1 KiB
Bash
Raw Normal View History

2023-12-07 00:24:26 +03:00
# Git push.
2023-12-07 01:44:42 +03:00
function gps() {
2023-12-07 00:24:26 +03:00
git push "${@}"
}
2024-01-11 00:32:09 +03:00
# Git push all (branches). Useful for pushing all stuff to a new remote.
function gpsa() {
git push "${1}" --tags "refs/remotes/origin/*:refs/heads/*"
}
2023-12-07 00:24:26 +03:00
# Git force push.
2023-12-07 01:44:42 +03:00
function gpsf() {
2023-12-07 00:24:26 +03:00
git push --force "${@}"
}
# Git pull.
2023-12-07 01:44:42 +03:00
function gpl() {
2023-12-07 00:24:26 +03:00
git pull "${@}"
}
# Git log.
2023-12-07 01:44:42 +03:00
function gl() {
2023-12-07 00:24:26 +03:00
git log "${@}"
}
# Git status.
2023-12-07 01:44:42 +03:00
function gs() {
2023-12-07 00:24:26 +03:00
git status "${@}"
}
# Git stash.
2023-12-07 01:44:42 +03:00
function gst() {
2023-12-07 00:24:26 +03:00
git stash "${@}"
}
# Git diff.
2023-12-07 01:44:42 +03:00
function gd() {
2023-12-07 00:24:26 +03:00
git diff "${@}"
}
# Git commit.
2023-12-07 01:44:42 +03:00
function gc() {
2023-12-07 00:24:26 +03:00
git commit -m "${@}"
}
# Git checkout.
2023-12-07 01:44:42 +03:00
function gch() {
2023-12-07 00:24:26 +03:00
git checkout "${@}"
}
# Git checkout branch.
2023-12-07 04:02:47 +03:00
# Usage: gchb <BRANCH>
2023-12-07 01:44:42 +03:00
function gchb() {
2023-12-07 00:24:26 +03:00
git checkout -b "${@}"
}
# Git branch.
2023-12-07 01:44:42 +03:00
function gb() {
2023-12-07 00:24:26 +03:00
git branch --all "${@}"
}
# Git branch delete.
2023-12-07 04:02:47 +03:00
# Usage: gbd <BRANCH>
2023-12-07 01:44:42 +03:00
function gbd() {
2023-12-07 00:24:26 +03:00
git branch -D "${@}"
}
# Git branch delete all except current.
2023-12-07 01:44:42 +03:00
function gbda() {
2023-12-07 00:24:26 +03:00
git branch | grep -v ^* | xargs git branch -D
}
# Git fetch all.
2023-12-07 01:44:42 +03:00
function gf() {
2023-12-07 00:24:26 +03:00
git fetch --all -v -p
}
# Git tag.
2023-12-07 01:44:42 +03:00
function gt() {
2023-12-07 00:24:26 +03:00
git tag "${@}"
}
# Git ignore files.
2023-12-07 01:44:42 +03:00
function gi() {
2023-12-07 00:24:26 +03:00
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
}
# Git patch create.
# Usage: gpc <FILE>
2023-12-07 01:44:42 +03:00
function gpc() {
2023-12-07 00:24:26 +03:00
git diff > "${@}"
}
# Git patch (apply).
# Usage: gp <FILE>
2023-12-07 01:44:42 +03:00
function gp() {
2023-12-07 00:24:26 +03:00
git apply "${@}"
}
2023-08-08 16:24:15 +03:00
2023-12-06 22:50:30 +03:00
# Run git garbage collection.
2023-12-07 01:44:42 +03:00
function ggc() {
2023-12-06 22:50:30 +03:00
git gc --aggressive --no-cruft --prune=now
}
2023-12-07 04:02:47 +03:00
# Preview diff while adding. Adds current dir by default.
2023-12-07 00:42:06 +03:00
# Usage: ga [FILES]
2023-12-07 01:44:42 +03:00
function ga() {
2023-12-05 21:50:45 +03:00
local target=${@}
2024-01-11 00:32:09 +03:00
2023-12-05 21:50:45 +03:00
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-12-07 04:02:47 +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-07 01:44:42 +03:00
function 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
2023-12-07 04:02:47 +03:00
# Specify git user as Dmitry Voronin with provided email.
# Usage: gu [EMAIL]
2023-12-07 01:44:42 +03:00
function 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-07 01:44:42 +03:00
function gg() {
2023-12-07 04:02:47 +03:00
local repo="${1}"
if [[ "${repo}" = "" ]]; then
help gg
return 2
fi
git clone https://git.voronind.com/voronind/"${repo}"
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-07 01:44:42 +03:00
function 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-07 01:44:42 +03:00
function _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-07 01:44:42 +03:00
function _git_origin_url() {
2023-12-05 21:50:45 +03:00
git remote get-url origin
}
# Get this dotfiles url.
2023-12-07 01:44:42 +03:00
function _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-07 01:44:42 +03:00
function _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
2023-12-07 04:02:47 +03:00
# Autocomplete with my git emails.
2023-12-07 01:44:42 +03:00
function _gu() {
2023-12-05 21:50:45 +03:00
_autocomplete_first account@voronind.com dd.voronin@fsight.ru
}
complete -F _gu gu