dotfiles/.config/shell/git

60 lines
1.5 KiB
Plaintext
Raw Normal View History

2020-06-03 10:26:15 +00:00
# Tools
alias g="git"
2020-03-08 19:18:49 +00: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 11:15:41 +00:00
if test $# -eq 0 || test -e "$1"
then
fulldir="$(realpath ${1:-$PWD})"
2022-05-03 09:21:04 +00:00
dir="${fulldir#$root/?-}"
else
dir="box/$1"
2022-05-03 09:21:04 +00: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 21:25:53 +00:00
# if in home or under XDG_CONFIG_HOME and not within a git directory, replace git by yadm
git() {
case "$1" in
2024-07-27 09:22:30 +00:00
(config|clone|journal) ;;
2022-01-05 17:42:20 +00:00
(*) case "$PWD" in
($HOME|$XDG_CONFIG_HOME|$LAST_YADM)
yadm "$@"
2022-01-05 17:42:20 +00: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 17:42:20 +00:00
command git "$@"
}
2020-03-08 19:18:49 +00:00
2020-06-03 10:26:15 +00:00
# Testing
2021-02-16 12:08:56 +00:00
gittestcommit() { touch file$((++i)) && git add 'file*' && git commit -m "Create file$i"; }