bash: Fix git stash alias setting

Fixed bash alias loading for additional modules by loading both general
sh aliases as well as individual bash aliases.

Moved git stash push/save aliasing to split between bash/zsh shell since
zsh can check for the correct version of git to invoke push command
(only part of git since 2.13) and bash simply falls back to save.
This commit is contained in:
Marty Oehme 2021-07-07 10:24:04 +02:00
parent 226c4b5f0d
commit bb9030f885
Signed by: Marty
GPG key ID: B7538B8F50A1C800
4 changed files with 35 additions and 17 deletions

View file

@ -16,5 +16,12 @@ if [ -d "$CONFDIR/sh/alias.d" ]; then
done done
unset _alias unset _alias
fi fi
if [ -d "$CONFDIR/bash/alias.d" ]; then
for _alias in "$CONFDIR/bash/alias.d"/*.sh; do
. "$_alias"
done
unset _alias
fi
alias ls='ls --color=auto' alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ ' PS1='[\u@\h \W]\$ '

View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
if ! exist git; then
return 1
fi
# while zsh can detect versions, bash
# in shells other than zsh, simply fall back to save
alias gsta='git stash save'

View file

@ -59,19 +59,7 @@ alias grbm='git rebase master || git rebase main'
alias gst='git status' alias gst='git status'
# if git is at least version 2.13, we can use git stash push # stash push/save is handled differently by zsh/bash
# in shells other than zsh, simply fall back to save
case "$(ps -cp "$$" -o command="")" in
*zsh*)
autoload -Uz is-at-least
if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then
alias gsta='git stash push'
else
alias gsta='git stash save'
fi
;;
*) alias gsta='git stash save' ;;
esac
alias gstp='git stash pop' alias gstp='git stash pop'
alias gstl='git stash list' alias gstl='git stash list'
alias gstL='git stash list --stat' alias gstL='git stash list --stat'

View file

@ -0,0 +1,14 @@
#!/usr/bin/env zsh
if ! exist git; then
return 1
fi
# git alias
# if git is at least version 2.13, we can use git stash push
autoload -Uz is-at-least
if is-at-least 2.13 "$(git --version 2>/dev/null | awk '{print $3}')"; then
alias gsta='git stash push'
else
alias gsta='git stash save'
fi