From 8175aeaa4014eb48241e3489e27e40cd7dbe05ef Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 4 May 2023 22:21:38 +0200 Subject: [PATCH] gitf_pulish --- etc/profile.d/git.sh | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/etc/profile.d/git.sh b/etc/profile.d/git.sh index ece725d5..db6de9d6 100644 --- a/etc/profile.d/git.sh +++ b/etc/profile.d/git.sh @@ -7,6 +7,7 @@ which git > /dev/null || return 0 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 @@ -32,13 +33,17 @@ EOF [ "$#" == "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() { @@ -52,31 +57,32 @@ EOF ;; 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 @@ -84,8 +90,8 @@ EOF 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" -- 2.47.3