- Commit
- b52ad63f802a85a4a9ae7f93f5ffb540ffb5b665
- Parent
- 475ade52c6004bb936a370941803226b9abbc3ee
- Author
- Pablo <pablo-escobar@riseup.net>
- Date
Modified the update command to fit git's syntax
A simple configuration manager
Modified the update command to fit git's syntax
2 files changed, 39 insertions, 29 deletions
diff --git a/config b/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
diff --git a/config.1 b/config.1 @@ -26,7 +26,7 @@ config \- A simple configuration manager. .SH "SYNOPSIS" .sp -\fBconfig\fP update (\-e|\-\-edit|MESSAGE) +\fBconfig\fP update [\-e|\-\-edit] [-m MESSAGE]... .sp \fBconfig\fP add FILE... .sp @@ -46,10 +46,12 @@ The config(1) command uses a bare Git repository to track dotfiles. .sp \fBupdate\fP .RS 4 -Add the current changes, commit and push to all remotes. If the \fI\-e\fP -or \fI\-\-edit\fP options are specified than config(1) uses \fI$EDITOR\fP to get the -commit message. Otherwise, the following arguments are used for the commit -message. +Add the current changes, commit and push to all remotes. If the \fI\-e\fP or +\fI\-\-edit\fP options are specified, or if no arguments are passed, config(1) +uses \fI$EDITOR\fP to get the commit message. In this case, further arguments +are ignored. If one or more messages are specified via the \fI\-m\fP option, +this messages are passed to \fIgit\fP directly. Note that the +\fI\-e\fP/\fI\-\-edit\fP and \fI\-m\fP options are mutually excluding. .RE .sp \fBadd\fP