~wrm/dotfiles

f0dc804d36d6538ff9bac8af4e32a3210a2826b0 — +wrm 2 months ago da55858
shell: Add git aliases generating script
3 files changed, 40 insertions(+), 14 deletions(-)

M .config/shell/aliasrc
A .config/shell/git-aliases.sh
M .config/shell/profile
M .config/shell/aliasrc => .config/shell/aliasrc +1 -14
@@ 30,17 30,4 @@ alias startx="startx ${XDG_CONFIG_HOME}/x11/xinitrc"
alias yt="youtube-dl --add-metadata -i"
alias yta="yt -x -f bestaudio/best"

# TODO Auto gen these in profile for g, g~, etc.
alias g="git"
alias gs="git status"
alias ga="git add"
alias gc="git commit -S"
alias gm="git merge -S"
alias gd="git diff"
alias gr="git rebase"
alias gb="git branch"
alias gl="git log --show-signature"
alias gsl="git shortlog"
alias grl="git reflog"

alias g~="git --git-dir=$HOME/git/dotfiles/ --work-tree=$HOME"
. "${XDG_CONFIG_HOME}/shell/git-aliases"

A .config/shell/git-aliases.sh => .config/shell/git-aliases.sh +36 -0
@@ 0,0 1,36 @@
#!/bin/sh

# Writes useful git aliases to stdout.

set -- 'g' 'git' 'g~' 'git\ --git-dir="$HOME\/git\/dotfiles\/"\ --work-tree="$HOME"'

subcommands="
s status
a add
c commit
r rebase
d diff
dt difftool

ch checkout
b branch
m merge
mt mergetool

l log --show-signature
sl shortlog
rl reflog"

# I've spent almost 20 minutes on this, and no, I really couldn't think of a
# better way to express this loop.
for _ in seq $(($# / 2)); do
	short=$1
	shift
	long=$1
	shift
	echo "alias $short='$long'" | tr -d '\\'
	echo "$subcommands" | sed s/" "/"='$long "/ | while read rhs; do
		[ -n "$rhs" ] && printf "alias %s%s'\n" "$short" "$rhs"
	done
	echo ""
done

M .config/shell/profile => .config/shell/profile +3 -0
@@ 12,6 12,9 @@ export XDG_CACHE_HOME="$HOME/.cache"
export PATH="${PATH}:$HOME/.local/bin"
export ENV="${XDG_CONFIG_HOME}/shell/shellrc"

# Generate special aliases
"${XDG_CONFIG_HOME}/shell/git-aliases.sh" > "${XDG_CONFIG_HOME}/shell/git-aliases"

# Uses \$ to delay expansion until string is actually shown.
# _ps1_dir is a function defined in $ENV.
export PS1="${USER}@$(cat /etc/hostname):\$(_ps1_dir)$ "