}
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"