From 2527d2630d966fb89e8dd794b9ba593abe2698e4 Mon Sep 17 00:00:00 2001 From: xerus2000 <27jf@pm.me> Date: Fri, 13 Nov 2020 22:40:28 +0100 Subject: [PATCH] config/git: migrate log and caching shell aliases to bins --- .config/shell/git | 19 +------------------ .local/bin/git-child | 4 ++++ .local/bin/git-rc | 4 ++++ .local/bin/git-recache | 6 ++++++ .local/bin/git-week | 4 ++++ 5 files changed, 19 insertions(+), 18 deletions(-) create mode 100755 .local/bin/git-child create mode 100755 .local/bin/git-rc create mode 100755 .local/bin/git-recache create mode 100755 .local/bin/git-week diff --git a/.config/shell/git b/.config/shell/git index dd9aca1..406b12a 100644 --- a/.config/shell/git +++ b/.config/shell/git @@ -24,7 +24,7 @@ git() { command git "$@"; } -# Log local and upstream commits side by side - useful to check before forcing an action +# Log local and upstream commits side by side - useful to check when the history has been manipulated glno() { loc="$(git l --color=always "$@")" upstream="$(git l --color=always $(git upstream) "$@")" @@ -36,23 +36,6 @@ glno() { done } -# Shortcuts -alias gcap!='git commit --all --amend --no-edit && git push --force-with-lease' -gitweek() { git my --after "$(date -d "Mon ${1:-1} weeks ago")" --before "$(date -d "Mon $(expr ${1:-1} - 1) weeks ago")" "${@:2}" } -# Find a commit that follows the given one - second argument can be used to specify the search range -gitchild() { git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head -1; } - -# Caching -gitrecache() { - git rm --cached --quiet -r ${1:-.} - git add ${1:-.} - git status -s -} -gitrestore() { - git reset -- "$@" - git checkout -- "$@" -} - # BRANCHES # Cleans up remote branches and removes branches where the remote-tracking branches got removed. alias gitrmgonebranches='git fetch -p && for branch in `git branch -vv | grep ": gone]" | cut -d" " -f3`; do git branch -D "$branch"; done' diff --git a/.local/bin/git-child b/.local/bin/git-child new file mode 100755 index 0000000..3ddc962 --- /dev/null +++ b/.local/bin/git-child @@ -0,0 +1,4 @@ +#!/bin/sh +# Find a commit that follows the given one +# Second argument can be used to specify the search range - default HEAD +git log --reverse --ancestry-path --pretty=%H $1..${2:-HEAD} | head -1 diff --git a/.local/bin/git-rc b/.local/bin/git-rc new file mode 100755 index 0000000..a2cca95 --- /dev/null +++ b/.local/bin/git-rc @@ -0,0 +1,4 @@ +#!/bin/sh +# Restores the repository version of given files +git reset -- "$@" +git checkout -- "$@" diff --git a/.local/bin/git-recache b/.local/bin/git-recache new file mode 100755 index 0000000..df3cd90 --- /dev/null +++ b/.local/bin/git-recache @@ -0,0 +1,6 @@ +#!/bin/sh +# Untracks and adds back all files (or the given path) +# Useful to remove tracked files after adding them to the gitignore +git rm --cached --quiet -r ${1:-.} +git add ${1:-.} +git status -s diff --git a/.local/bin/git-week b/.local/bin/git-week new file mode 100755 index 0000000..7e53ce7 --- /dev/null +++ b/.local/bin/git-week @@ -0,0 +1,4 @@ +#!/bin/sh +# Commits by myself throughout the current week +# Depends on git-my alias listing commits by myself +git my --after "$(date -d "Mon ${1:-1} weeks ago")" --before "$(date -d "Mon $(expr ${1:-1} - 1) weeks ago")" "${@:2}"