dotfiles

My personal dotfiles 💠️

commit d629ec37ac5ef8fb4a76e6c2fc3d857ac7df8e9d
parent 8607bbb2ed5de37f93b9a58dc3c8c5f864398c2f
Author: Pablo <pablo-escobar@riseup.net>
Date:   Tue, 17 Aug 2021 20:16:36 -0300

Updated the config script

Updates on the dedicated repository for the script are comming

Diffstat:
M.local/bin/config | 56++++++++++++++++++++++++++++++++------------------------
1 file changed, 32 insertions(+), 24 deletions(-)
diff --git a/.local/bin/config b/.local/bin/config
@@ -43,42 +43,50 @@ call_git()
 case "$1" in
   # Commit and push updates to all remotes
   update)
-    commit_msg_file="$(mktemp)"
-
     # Add the relevant files to the repo
     xargs git --git-dir="$dotfiles_repo" --work-tree="$HOME" add \
       < "$dotfiles_list"
 
     shift
 
-    while [ $# -gt 0 ]
-    do
-      case "$1" in
-        # Edit the commit message directly
-        -e|--edit)
-          printf '' > "$commit_msg_file"
-          $EDITOR "$commit_msg_file" 
-          break
-          ;;
-
-        # Append messages to the temporary file
-        *)
-          printf '%s\n\n' "$1" >> "$commit_msg_file"
-          shift
-          ;;
-      esac
-    done
-
-    # Commit the changes
-    call_git commit -F "$commit_msg_file" || exit $?
+    case "$1" in
+      # Edit the commit message from a file
+      -e|--edit|'')
+        # Create a temporary file to store the commit message
+        commit_msg_file="$(mktemp)"
+        touch "$commit_msg_file"
+
+        # Open the editor and edit the message
+        $EDITOR "$commit_msg_file" 
+        if call_git commit -F "$commit_msg_file" 
+        then
+          # Remove the temporary file
+          rm "$commit_msg_file"
+        else
+          # Remove the temporary file and exit with an error
+          rm "$commit_msg_file"
+          exit 1
+        fi
+        ;;
+
+      # Use to commit messages specified with -m
+      -m)
+        call_git commit "$@" || exit $?
+        ;;
+
+      # Print an error message and exit with an error
+      *)
+        printf "Unknown option: '%s'\nSee config(1)\n" "$1"
+        exit 1
+        ;;
+    esac
 
     # Push the changes to all remotes
-    for remote in $(call_git remote -v | awk '/(push)/ { print $1 }' | uniq)
+    for remote in "$(call_git remote -v | awk '/(push)/ { print $1 }' | uniq)"
     do
       call_git push "$remote" master
     done
 
-    rm "$commit_msg_file"
     ;;
 
   # Add files to the list of files