config/git: modernize some stuff & add aur helper

This commit is contained in:
xeruf 2021-09-08 15:58:22 +02:00
parent 7da569a59d
commit 27b93aed3e
11 changed files with 36 additions and 84 deletions

View File

@ -24,6 +24,8 @@
ff = only
[checkout]
defaultRemote = origin
[init]
defaultBranch = main
[diff]
tool = nvim
@ -77,7 +79,7 @@
[alias]
fzf = !fzf --preview='git diff HEAD --color=always -- {}' --tiebreak=end,index --multi
fzs = !cut -z -c2- | git fzf --read0 -d' ' --nth=2.. --preview='test {1} != \\? && git diff --color HEAD -- {2..} | $(git config interactive.diffFilter) || diff --color=always -u /dev/null {2..}' | cut -c3-
fzs = !cut -z -c2- | git fzf --read0 -d' ' --nth=2.. --bind='alt-enter:execute(nvim {2..})' --preview='test {1} != \\? && git diff --color HEAD -- {2..} | $(git config interactive.diffFilter) || diff --color=always -u /dev/null {2..}' | cut -c3-
# GET INFO
s = !git stl && git stb
@ -85,12 +87,11 @@
stb = status --short --branch
sv = --paginate status -v
svv = --paginate status -vv
sf = !git status --porcelain --no-renames -z | sed -z 's/^\\(\\w\\) / \\1/' | git fzs | git commit -v --pathspec-from-file=-
r = remote -v
b = branch -vv
ba = b -a
main = !cat $(git rev-parse --git-dir)/refs/remotes/origin/HEAD | cut -d'/' -f4
main = !cat "$(git rev-parse --git-path refs/remotes/origin/HEAD)" | cut -d'/' -f4
sw = switch
sc = switch -c
@ -107,7 +108,6 @@
dir = rev-parse --git-dir
curbranch = symbolic-ref --short HEAD
upstream = !git rev-parse --abbrev-ref --symbolic-full-name @{upstream} || git rev-parse --abbrev-ref --symbolic-full-name @{push} || echo origin/$(git curbranch)
#dir = !git root | sed 's/$/\\/.git/' | grep --color=never "/" # grep ensures a proper exit status on fail
lg = log --pretty=tformat:'%C(auto)%h%d %s %Cgreen(%cd) %Cblue<%an>%Creset' --date=human --graph
lgu = lg HEAD @{push}
@ -130,7 +130,8 @@
a = add -u
aa = add -u .
ap = add -p
af = !git status --porcelain --no-renames -z | grep -v '^\\w ' -z | git fzs | git -c advice.addEmptyPathspec=false add --verbose --pathspec-from-file=-
af = !git status --porcelain --no-renames --untracked-files=all -z | grep -v '^\\w ' -z | git fzs git -c advice.addEmptyPathspec=false add --verbose --pathspec-from-file=-
sf = !git status --porcelain --no-renames -z | sed -z 's/^\\(\\w\\) / \\1/' | git fzs >/tmp/git-sf && git -c advice.addEmptyPathspec=false add --intent-to-add --pathspec-from-file=/tmp/git-sf && git commit --only -v --pathspec-from-file=/tmp/git-sf
c = commit -v
cad = !git diff-tree --no-commit-id --name-only -r HEAD | git commit -v --amend --pathspec-from-file=- # Amend commit with all already changed files
@ -180,5 +181,3 @@
[includeIf "gitdir:~/data/.git"]
path = "config-data"
[init]
defaultBranch = main

View File

@ -63,15 +63,7 @@ gitretag() {
git push origin refs/tags/${1}:refs/tags/${2} :refs/tags/$1 && git tag -d $1
}
# Repo management {{{
gitinit() {
git init -b main
git add .
git commit -m "First strike"
gitorigin "$@"
git push
}
# Open or select a project
project() {
cd $projects_dir
if [ -d $2 ]
@ -80,8 +72,6 @@ project() {
fi
}
# }}}
# Rewriting history {{{
# gets the AuthorDate of a given committish

19
.local/bin/scripts/git-aur Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh -e
command=$1
shift
case $command in
(clone)
cd "$DATA/2-standards/dev/aur"
git -c init.defaultBranch=master clone ssh://aur@aur.archlinux.org/$1.git
cd "$1"
echo '*' > .gitignore
exec $SHELL;;
(create)
git add -f .gitignore PKGBUILD .SRCINFO
git commit -m "Create package" "$@"
git aur push --amend;;
(push) makepkg --printsrcinfo > .SRCINFO
git commit -v -a "$@"
git push;;
esac

7
.local/bin/scripts/git-create Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# Create a new repo, commit and push
git init
git add .
git commit -m "First strike"
git origin "$@"
git push

View File

@ -3,5 +3,5 @@
# With no argument it switches to the default branch and deletes the current branch.
branch=${1:-$(git curbranch)}
echo "${@:-$branch}" | sed 's/\([^ ]\+\)/\1@{push}/g' | xargs git rev-parse --abbrev-ref --revs-only | sed 's/\// /' | xargs --no-run-if-empty git push -d
test -n "$1" || git checkout main || git checkout master || git checkout $(cat "$(git rev-parse --git-path "refs/remotes/origin/HEAD")" | sed 's|.*/||')
test -n "$1" || git checkout main || git checkout master || git checkout $(cat "$(git rev-parse --git-path refs/remotes/origin/HEAD)" | sed 's|.*/||')
git branch -D "${@:-$branch}"

View File

@ -1,3 +1,3 @@
#!/bin/sh
# Save HEAD commit hash to "snap" file in git dir
echo Snapped $(git rev-parse HEAD | tee "$(git rev-parse --git-dir)/${1:-snap}")
echo Snapped $(git rev-parse HEAD | tee "$(git rev-parse --git-path ${1:-snap})")

View File

@ -1,3 +1,3 @@
#!/bin/sh
# Hard reset HEAD to commit in "snap"-file
git reset --keep $(cat "$(git rev-parse --git-dir)/${1:-snap}")
git reset --keep $(cat "$(git rev-parse --git-path ${1:-snap})")

View File

@ -1,22 +0,0 @@
#!/bin/sh
# Query local syncthing REST API
test $# -eq 0 && echo "Usage: st <command> [args...]" && exit 1
subscript="$(which "$(basename $0)-$1" 2>/dev/null)"
if test -f "$subscript"
then shift && $subscript "$@"
else
apikey=$(grep apikey $XDG_CONFIG_HOME/syncthing/config.xml | cut -d '>' -f2 | cut -d '<' -f1)
case "$1" in
(browse|completion|file|ignores|need|status)
for arg in "${@:2}"
do case "$arg" in ([0-9]) depth=$arg;; (*) path="$arg";; esac
done
query=$(echo "db/$1?folder=$(expr "${path%%/*}" \& "$path" \| data)
$(expr levels \& "$1" = "browse" \| page)=${depth:-1}
$(case "$path" in (*/*) echo "$(expr "prefix" \& "$1" = "browse" \| "$1")=${path#*/}";; esac)" |
tr -d ' ' | paste -s -d'&');;
(*) query="$1";;
esac
shift
curl --silent -H 'Content-Type: application/json' -H "X-API-Key: $apikey" "http://localhost:8384/rest/$query" "$@" | bat --style=numbers -l json
fi

View File

@ -1,26 +0,0 @@
#!/bin/sh
stats() {
stat --format '%.10y %n %sB - birth %.10w' "$@"
}
test "$1" = "-q" && quick=-q && shift
if test "$#" -gt 0
then
orig="$(st-unarchive "$1")"
if test -n "$quick"
then stats "$orig" "$1"
else
( stats "$orig" "$1"; dif "$orig" "$@" ) |
less --RAW-CONTROL-CHARS --quit-on-intr --quit-if-one-screen
test "$?" -eq "2" && exit 1
echo "y|r to restore, n|d to delete, m to merge"
read reply
case "$reply" in
(y|r) st-restore "$1";;
(n|d) rm -v "$1";;
(m) touch /tmp/empty && git merge-file "$orig" /tmp/empty "$1" && nvim "$orig" && rm "$1";;
esac
fi
else
find "$DATA/2-standards/notes/journal" -name "intentions*sync-conflict*" -exec sh -c 'basename {} | cut -d. -f1 | xargs -i% jrnl % --import --file {}' \; -delete
find -name '.stfolder' -prune -o -name '*sync-conflict*' -exec st-diff $quick '{}' \;
fi

View File

@ -1,2 +0,0 @@
#!/bin/sh
mv "$1" "$(st-unarchive "$1")"

View File

@ -1,13 +0,0 @@
#!/bin/sh
echo "$1" |
sed 's|\.sync/Archive/\(.\+\)\.[[:digit:]]\+|\1|;
s|\.sync/Archive/||;
s|\.stversions/\(.*\)~[[:digit:]]\+-[[:digit:]]\+|\1|;
s|\.sync-conflict-[[:digit:]]\+-[[:digit:]]\+-[[:alnum:]]\+||'
# TESTING
# echo "1-projects/.sync/Archive/meetings.1.txt
# 1-projects/.sync/Archive/meetings.txt
# data/.stversions/meeting~2020-01
# meeting.sync-conflict-2021-1925-P5K
# meeting.sync-conflict-2021-1925-PRK.txt" |