|
@@ -1,39 +1,38 @@
|
|
|
#!/bin/zsh
|
|
#!/bin/zsh
|
|
|
-
|
|
|
|
|
-function dc() {
|
|
|
|
|
- # Set up completion on first call
|
|
|
|
|
|
|
+_dc_git_commit_push() {
|
|
|
|
|
+ # Setup completion on first call
|
|
|
if [[ -z "$_dc_completion_setup" ]]; then
|
|
if [[ -z "$_dc_completion_setup" ]]; then
|
|
|
compdef _dc_completion dc 2>/dev/null
|
|
compdef _dc_completion dc 2>/dev/null
|
|
|
_dc_completion_setup=1
|
|
_dc_completion_setup=1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+ # Help message
|
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
|
- echo "Usage: dc [commit_message]"
|
|
|
|
|
- echo "Quickly commit all changes and push to remote"
|
|
|
|
|
|
|
+ echo "Usage: ${0} [commit_message]"
|
|
|
|
|
+ echo "Quickly commit${2:+ all} changes and push to remote"
|
|
|
echo "If no message provided, uses timestamp-based message"
|
|
echo "If no message provided, uses timestamp-based message"
|
|
|
return 0
|
|
return 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+ # Check if in git repo
|
|
|
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
|
echo "Error: Not in a git repository" >&2
|
|
echo "Error: Not in a git repository" >&2
|
|
|
return 1
|
|
return 1
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
+ # Check for changes
|
|
|
if [[ -z $(git status --porcelain) ]]; then
|
|
if [[ -z $(git status --porcelain) ]]; then
|
|
|
echo "No changes to commit"
|
|
echo "No changes to commit"
|
|
|
return 0
|
|
return 0
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
- git add .
|
|
|
|
|
|
|
+ # Add all changes if requested
|
|
|
|
|
+ [[ -n "$2" ]] && git add .
|
|
|
|
|
|
|
|
- local commit_msg
|
|
|
|
|
- if [[ -n "$1" ]]; then
|
|
|
|
|
- commit_msg="$1"
|
|
|
|
|
- else
|
|
|
|
|
- local timestamp=$(date +"%Y-%m-%d %H:%M:%S")
|
|
|
|
|
- commit_msg="dev: automated commit - ${timestamp}"
|
|
|
|
|
- fi
|
|
|
|
|
|
|
+ # Set commit message
|
|
|
|
|
+ local commit_msg="${1:-dev: automated commit - $(date +"%Y-%m-%d %H:%M:%S")}"
|
|
|
|
|
|
|
|
|
|
+ # Commit and push
|
|
|
if git commit -m "$commit_msg" --no-gpg-sign; then
|
|
if git commit -m "$commit_msg" --no-gpg-sign; then
|
|
|
if git push &>/dev/null; then
|
|
if git push &>/dev/null; then
|
|
|
echo "Committed and pushed successfully"
|
|
echo "Committed and pushed successfully"
|
|
@@ -47,6 +46,14 @@ function dc() {
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function dc() {
|
|
|
|
|
+ _dc_git_commit_push "$1"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function dca() {
|
|
|
|
|
+ _dc_git_commit_push "$1" "add"
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function nu() {
|
|
function nu() {
|
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
|
echo "Usage: nu [commit_message]"
|
|
echo "Usage: nu [commit_message]"
|