From 10f590289115189b356a740ae5a7af0e5946d695 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 18 Aug 2016 22:51:58 +0100 Subject: [PATCH] gitcd --- etc/profile.d/git.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh index bac0a023..bf517098 100644 --- a/etc/profile.d/git.sh +++ b/etc/profile.d/git.sh @@ -24,27 +24,43 @@ git_cache_rm() { } gitcd() { - shell_help_noarg "Change directory to file's dirname\nUsage: $FUNCNAME GIT_ARGUMENTS" "$@" && return 1 + + shell_help_noarg "Change directory to run git commands\nUsage: $FUNCNAME FILE|DIR GIT_ARGUMENTS" "$@" && return 1 local i d dir args local pwd; pwd=$PWD #for i in $@; do while [ $# -gt 0 ]; do + i="$1" + # Replace file with realpath if [ -e "$i" ]; then i=$(realpath "$i") + + # if dir stay there + [ -d "$i" ] && i="$i/.git" + d=$(dirname "$i") - [ -z "$dir" ] && cd "$d" || return + dir="$d" fi + shell_push_arg "$i" args shift + done + [ -z "$dir" ] && echo "Can't find any file in $@" && return 1 + + cd "$dir" || return + #echo PWD=$(pwd) + eval git ${args} + cd "$pwd" -} + +} # < gitcd() git_commit_push() { git commit -a -m "$*" && git push #|| echo "Try: git push --set-upstream origin master" -- 2.47.3