From 053e34dd47096315a564a689df337b7b5a3ecf42 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 8 Mar 2016 23:52:38 +0000 Subject: [PATCH] Add gitcd --- etc/profile.d/git.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh index ed51e1a2..aa78945d 100644 --- a/etc/profile.d/git.sh +++ b/etc/profile.d/git.sh @@ -5,6 +5,30 @@ alias git_grep="git grep --color=auto" alias git_ls_tree="git ls-tree --full-tree -r HEAD" alias git_ls_files="git ls-files" +gitcd() { + shell_help_noarg "Change directory to file's dirname\nUsage: $FUNCNAME 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") + 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 + echo $dir + echo git ${args} + cd "$pwd" +} + git_commit_push() { git commit -a -m "$*" && git push #|| echo "Try: git push --set-upstream origin master" } -- 2.47.3