Compare commits

...

4 Commits

Author SHA1 Message Date
6db1a710c6 git: Rename zsh-autoload.sh -> external-script.sh
With the last commit 9c1e3f4679 (git:zsh-autoload: Use relative
scripts/ folder, 2025-09-12), `zsh-autoload.sh` could execute any type
of external script. Rename it to a more generic name.
2025-09-12 16:25:39 +02:00
9c1e3f4679 git:zsh-autoload: Use relative scripts/ folder
This makes it a bit more agnostic to the type of scripts being used.
2025-09-12 14:49:59 +02:00
bb7ef3769d git: Add branch-rename
Small script to rename a branch locally and on a given remote.
2025-09-12 14:35:44 +02:00
0534ec493e zsh:alias: Make sizes an anonymous function
This way one can easily redirect stderr for both commands (not just
`sort`) and specify a path. The path defaults to the current directory,
but listing each entry by globbing.
2025-09-07 21:09:11 +02:00
6 changed files with 49 additions and 21 deletions

View File

@@ -4,21 +4,22 @@
addIgnoredFile = off
detachedHead = off
[alias]
# NOTE: git-zsh-autoload (./zsh-autoload.sh) is a small wrapper that
# launches autoloadable zsh functions (.config/zsh/autoload/git/*) in
# the right directory, as shell commands in git aliases are executed
# from the top-level directory of the repository.
# NOTE: git-external-script (./external-script.sh) is a small wrapper
# that launches external scripts from the ./scripts/ collection in the
# right directory, as shell commands in git aliases are executed from
# the top-level directory of the repository.
abort = "!git-zsh-autoload abort"
abort = "!git-external-script abort"
autosquash = -c sequence.editor=/bin/true rebase -i --autosquash
autofixup= autosquash
branch-rename = "!git-external-script branch-rename"
c = commit
changes = flog HEAD...FETCH_HEAD
checkout-worktree = "!git-zsh-autoload checkout-worktree"
checkout-worktree = "!git-external-script checkout-worktree"
cow = checkout-worktree
co = checkout
commit-last-msg = "!git-zsh-autoload commit-last-msg"
continue = "!git-zsh-autoload continue"
commit-last-msg = "!git-external-script commit-last-msg"
continue = "!git-external-script continue"
cont = continue
clm = commit-last-msg
last-msg = commit-last-msg
@@ -28,21 +29,21 @@
ft = fetch-tags-only
filter-repo = !git-filter-repo
fixes = log -1 --pretty=fixes
glog = "!git-zsh-autoload glog"
https-and-ssh = "!git-zsh-autoload https-and-ssh"
glog = "!git-external-script glog"
https-and-ssh = "!git-external-script https-and-ssh"
ssh-and-https = https-and-ssh
l = log
last-changed = "!git-zsh-autoload last-changed"
last-changed = "!git-external-script last-changed"
ls = ls-files
make-fork = "!git-zsh-autoload make-fork"
make-fork = "!git-external-script make-fork"
p = push
perm-stash = "!git-zsh-autoload perm-stash"
perm-stash = "!git-external-script perm-stash"
root = rev-parse --show-toplevel
signoff = rebase --signoff
ss = stash
ssync = "!git-zsh-autoload ssync"
submodule-rm = "!git-zsh-autoload submodule-rm"
track = "!git-zsh-autoload track"
ssync = "!git-external-script ssync"
submodule-rm = "!git-external-script submodule-rm"
track = "!git-external-script track"
branches = track
[blame]
date = short

View File

@@ -2,8 +2,9 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Meant to be used in git aliases to launch an autoloadable zsh function in the
# correct directory.
# Meant to be used by git aliases to easily launch an external script from the
# ./scripts/ collection through its basename and in the correct directory (i.e.
# GIT_PREFIX).
if [ $# -eq 0 ]; then
printf >&2 "Usage: %s <function>\n" "$(basename "$0")"
@@ -12,7 +13,7 @@ fi
name="$1"
shift
BASE="${XDG_CONFIG_HOME:-$HOME/.config}/zsh/autoload/git"
BASE="$(dirname "$(realpath "$0")")/scripts"
# In git aliases, shell commands are executed from the top-level directory of
# the repo. GIT_PREFIX contains the original directory relative to the

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env zsh
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Julian Prein
#
# Rename a branch locally and on a given remote.
emulate -L zsh -o err_return -o no_unset
if (( # < 2 || # > 3 )); then
printf >&2 "Usage: %s OLD NEW [REMOTE]\n" "${0:t}"
return 1
fi
local old new remote
old="$1"
new="$2"
remote="${3:-origin}"
if ! git remote -v | awk '{ print $1 }' | uniq | grep -q "$remote"; then
printf >&2 "Remote '%s' does not exist\n" "$remote"
return 1
fi
git checkout-worktree "$old" <<EOF
git branch -m "$new" && git push -u && git push -d "$remote" "$old"
EOF

View File

@@ -128,7 +128,7 @@ fi
# Use a reasonable time format
alias date='env LC_TIME=tk_TM date'
# List human readable sizes in order
alias sizes='du -sch * | sort -h'
alias sizes='() { du -sch ${1:-*} "${@[2,-1]}" | sort -h }'
# Count number of occurrences for every line in stdin
alias count='sort | uniq -c | sort -n'
# Inspired by https://stackoverflow.com/a/54541337

View File

@@ -0,0 +1 @@
../../.config/git/external-script.sh

View File

@@ -1 +0,0 @@
../../.config/git/zsh-autoload.sh