-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotup.sh
More file actions
executable file
·77 lines (61 loc) · 1.35 KB
/
dotup.sh
File metadata and controls
executable file
·77 lines (61 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
set -e
usage() {
cat << EOF
Usage: dotup "{commit message}"
Commit and push changes in dotfiles repository
Assume ~/dotfiles is dotfiles directory managed by git
Options:
-h, --help Show this help message
-d, --dry-run Dry run
Example:
dotup "Update tmux config"
dotup --dry-run
EOF
exit 0
}
DRY_RUN=0
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
usage
;;
-d|--dry-run)
DRY_RUN=1
shift
;;
*)
COMMIT_MSG="$@"
break
;;
esac
done
DOTFILES_DIR="${HOME}/dotfiles"
if [ ! -d "${DOTFILES_DIR}" ]; then
echo "Error: dotfiles directory ${DOTFILES_DIR} does not exist." >&2
exit 1
fi
cd "${DOTFILES_DIR}"
if [ ! -d .git ]; then
echo "Error: ${DOTFILES_DIR} is not a git repository" >&2
exit 1
fi
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit. Exiting."
exit 0
fi
if [ "$DRY_RUN" -eq 1 ]; then
echo "Dry run: changes to be commited:"
echo "--------------------------------"
git --no-pager diff
exit 0
fi
if [ -z "${COMMIT_MSG}" ]; then
echo "input commit message: [message][return]"
read COMMIT_MSG
fi
echo "Commit message: ${COMMIT_MSG}"
git add .
git commit -m "${COMMIT_MSG}"
git push
echo "Successfully updated dotfiles changes!"