diff --git a/git/.config/bash/alias.d/git-stash-push.sh b/git/.config/bash/alias.d/git-stash-push.sh deleted file mode 100644 index 9b5e4d1..0000000 --- a/git/.config/bash/alias.d/git-stash-push.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/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 4292546..23557cd 100644 --- a/git/.config/sh/alias.d/git.sh +++ b/git/.config/sh/alias.d/git.sh @@ -4,7 +4,9 @@ if ! exist git; then return 1 fi -# git alias +# print git version output and get raw version number by stripping prefix +git_version=$(git --version 2>/dev/null) +git_version="${git_version##git version }" alias g='git' @@ -18,10 +20,17 @@ alias gc='git commit -v' alias gc!='git commit -v --amend' alias gcn!='git commit -v --no-edit --amend' -alias gcm='git checkout master 2>/dev/null || git checkout main' -alias gcd='git checkout develop' -alias gcb='git checkout -b' -alias gco='git checkout' +if version_at_least 2.23 "$git_version"; then + alias gcm='git switch master 2>/dev/null || git switch main' + alias gcd='git switch develop' + alias gcb='git switch -c' + alias gco='git switch' +else + alias gcm='git checkout master 2>/dev/null || git checkout main' + alias gcd='git checkout develop' + alias gcb='git checkout -b' + alias gco='git checkout' +fi alias gd='git diff' alias gds='git diff --staged' @@ -59,7 +68,13 @@ alias grbm='git rebase master || git rebase main' alias gst='git status' -# 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' +if version_at_least 2.13 "$git_version"; then + alias gsta='git stash push' +else + alias gsta='git stash save' +fi + +unset -v git_version diff --git a/git/.config/zsh/alias.d/git-stash-push.sh b/git/.config/zsh/alias.d/git-stash-push.sh deleted file mode 100644 index 3facda6..0000000 --- a/git/.config/zsh/alias.d/git-stash-push.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env zsh -# shellcheck shell=sh - -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