From bb9030f88538423ef13430dddb77d5cb7d5d6d4d Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Wed, 7 Jul 2021 10:24:04 +0200 Subject: [PATCH] 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. --- bash/.bashrc | 15 +++++++++++---- git/.config/bash/alias.d/git-stash-push.sh | 9 +++++++++ git/.config/sh/alias.d/git.sh | 14 +------------- git/.config/zsh/alias.d/git-stash-push.sh | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 17 deletions(-) create mode 100644 git/.config/bash/alias.d/git-stash-push.sh create mode 100644 git/.config/zsh/alias.d/git-stash-push.sh diff --git a/bash/.bashrc b/bash/.bashrc index 7b0c083..28ee5e6 100644 --- a/bash/.bashrc +++ b/bash/.bashrc @@ -11,10 +11,17 @@ CONFDIR="${XDG_CONFIG_HOME:-$HOME/.config}" [ -f "$CONFDIR/sh/alias" ] && source "$CONFDIR/sh/alias" # load additional aliases if [ -d "$CONFDIR/sh/alias.d" ]; then - for _alias in "$CONFDIR/sh/alias.d"/*.sh; do - . "$_alias" - done - unset _alias + for _alias in "$CONFDIR/sh/alias.d"/*.sh; do + . "$_alias" + done + unset _alias 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' PS1='[\u@\h \W]\$ ' diff --git a/git/.config/bash/alias.d/git-stash-push.sh b/git/.config/bash/alias.d/git-stash-push.sh new file mode 100644 index 0000000..9b5e4d1 --- /dev/null +++ b/git/.config/bash/alias.d/git-stash-push.sh @@ -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' diff --git a/git/.config/sh/alias.d/git.sh b/git/.config/sh/alias.d/git.sh index 86c93cc..4292546 100644 --- a/git/.config/sh/alias.d/git.sh +++ b/git/.config/sh/alias.d/git.sh @@ -59,19 +59,7 @@ alias grbm='git rebase master || git rebase main' alias gst='git status' -# if git is at least version 2.13, we can use git stash push -# 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 +# stash push/save is handled differently by zsh/bash alias gstp='git stash pop' alias gstl='git stash list' alias gstL='git stash list --stat' diff --git a/git/.config/zsh/alias.d/git-stash-push.sh b/git/.config/zsh/alias.d/git-stash-push.sh new file mode 100644 index 0000000..9519ea4 --- /dev/null +++ b/git/.config/zsh/alias.d/git-stash-push.sh @@ -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