dotfiles/.config/shell/git

74 lines
1.9 KiB
Text
Raw Normal View History

2020-06-03 12:26:15 +02:00
# Tools
alias g="git"
2020-03-08 20:18:49 +01:00
y() {
local unignore="$XDG_CONFIG_HOME/yadm/unignore"
test -r "$unignore" && cat "$unignore" | while read f; do eval ls -d $f; done | yadm add --intent-to-add --pathspec-from-file=-
test "$#" -eq 0 && yadm s || yadm "$@"
}
yc() {
local folder="$(test -e "${1:-$PWD}" && realpath "${1:-$PWD}" || echo "$XDG_CONFIG_HOME/$1")"
echo "${folder#$HOME\/.}:" >/tmp/yc-msg
yadm commit -v --template /tmp/yc-msg ${@:2} -- "$folder*"
}
gcn() {
local root="$(git rev-parse --show-toplevel)"
if test "$root" = "$DATA"
then
2021-11-11 12:15:41 +01:00
if test $# -eq 0 || test -e "$1"
then
fulldir="$(realpath ${1:-$PWD})"
2022-05-03 11:21:04 +02:00
dir="${fulldir#$root/?-}"
else
dir="box/$1"
2022-05-03 11:21:04 +02:00
fulldir="$root/2-$dir"
fi
else
fulldir="$(realpath ${1:-$PWD})"
dir="${fulldir#$root/}"
fi
echo "$dir: " >/tmp/gcn-msg
git add $fulldir
git moves -q
git commit -v --template /tmp/gcn-msg ${@:2} #-- $fulldir
}
2020-06-26 23:25:53 +02:00
# if in home or under XDG_CONFIG_HOME and not within a git directory, replace git by yadm
git() {
case "$1" in
2022-01-05 18:42:20 +01:00
(reset) test "$2" = "--hard" && return 66;;
(config) ;;
(clone) ;;
(*) case "$PWD" in
($HOME|$XDG_CONFIG_HOME|$LAST_YADM)
yadm "$@"
2022-01-05 18:42:20 +01:00
return $?
;;
($XDG_CONFIG_HOME*|$HOME/.local*)
if ! command git rev-parse --show-toplevel &>/dev/null; then
export LAST_YADM="$PWD"
yadm "$@"
return $?
fi;;
esac;;
esac
2022-01-05 18:42:20 +01:00
command git "$@"
}
2020-11-13 12:49:24 +01:00
# BRANCHES
2020-06-03 12:26:15 +02:00
# Remove list of tags local & remote
2020-03-08 20:18:49 +01:00
gitrmtag() {
declare -a refs
local index=1
for tag in $@; do refs[index++]=":refs/tags/$tag"; done
git push origin "${refs[@]}" && git tag -d "$@"
2020-03-08 20:18:49 +01:00
}
2020-06-03 12:26:15 +02:00
# Rename a tag
2020-03-08 20:18:49 +01:00
gitretag() {
git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1
2020-03-08 20:18:49 +01:00
}
2020-06-03 12:26:15 +02:00
# Testing
2021-02-16 13:08:56 +01:00
gittestcommit() { touch file$((++i)) && git add 'file*' && git commit -m "Create file$i"; }