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 --full-name"
+alias git_root="git rev-parse --show-toplevel"
gitf() {
case "$@" in
[ "$#" == "0" ] && echo "Args CMD missing" 2>&1 && return 1
- declare cmd="cd "$(dirname "$file")" && $*"
- cmd="whoami && pwd && $cmd"
+ declare pwd="$(pwd)"
+
+ declare cmd="cd \"$(dirname "$file")\" && cd \"\$(git_root)\" && $*"
+ cmd="$cmd && echo && echo user=\$(whoami) root=\$(pwd)"
if [ "$owner" != "$(id -un)" ]; then
su - "$owner" -c "$cmd"
else
eval "$cmd"
fi
+
+ cd "$pwd"
}
gitf_publish() {
;;
esac
- declare file="${1:?Args 1: file is missing}"
#exec echo $file
if [ "$1" != "_gitf" ]
then
- gitf "$file" gitf_publish _gitf "$(realpath "$file")"
+ gitf "$1" gitf_publish _gitf "$(realpath "$1")"
return
fi
shift
+ declare file="${1:?Args 1: file is missing}"
#
# Commit
#
declare comment
+ declare default="${file##$(git_root)/}"
if [ -n "$(git status --porcelain "$file")" ]
then
- read -p "Your comment (default: $file): " comment
- [ -z "$comment" ] && comment="$file"
- echo git commit -m "$comment" "$file"
+ read -p "Your comment (default: $default): " comment
+ [ -z "$comment" ] && comment="$default"
+ git commit -m "$comment" "$file"
fi
#
# Push
#
- echo git push
+ git push
#
# Merging
if [ $(git branch | wc -l) -gt 1 ]
then
case "$(git_branch)" in
- master) git branch | grep ' testing$' && echo git_merge_to testing;;
- testing) echo git_merge_to master;;
+ master) git branch | grep ' testing$' && git_merge_to testing;;
+ testing) git_merge_to master;;
esac
else
echo "Only one branch no merging"