-
Notifications
You must be signed in to change notification settings - Fork 1
/
crontab-edit
executable file
·41 lines (38 loc) · 1.19 KB
/
crontab-edit
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
#!/bin/bash
set -e -f -u -o pipefail
# Stop git looking for a commit message when 'git pull' is run.
GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT
if [[ "$#" -eq 0 ]]; then
# Program is being run interactively: set up $EDITOR to run this program,
# then invoke `crontab -e` to trigger the else branch.
EDITOR="$0" crontab -e
else
# crontab has invoked this as an editor.
cd "${HOME}/src/private-configs"
git check-local-copy-is-clean --ignore-unpushed-commits
git pull
git push
FILENAME="crontab.${USER}.${HOSTNAME/local/lan}"
if [[ ! -f "${FILENAME}" ]]; then
touch "${FILENAME}"
fi
vimdiff "${FILENAME}" "$@"
while ! diff -u "${FILENAME}" "$@"; do
printf "Found diffs between tmp file and repo!\\n"
read -r -p "Press enter to edit again: "
vimdiff "${FILENAME}" "$@"
done
if ! git check-local-copy-is-clean; then
# Git tracks symlinks, so it does not follow them, so I need to follow them.
if [[ -L "${FILENAME}" ]]; then
git add "$(readlink "${FILENAME}")"
else
git add "${FILENAME}"
fi
EDITOR="vim" git commit --edit \
--message 'BEWARE: An empty commit message will cause the commit to fail!'
fi
git pull
git push
fi