-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·54 lines (49 loc) · 1.31 KB
/
update.sh
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
#!/bin/bash
TIME_PREFIX="Last Updated:"
TIMESTAMP_FORMAT="%m-%d-%Y %I:%M %p"
FILE_TO_UPDATE="README.md"
GIT_BRANCH="bump"
COMMIT_MESSAGE="bump repo to top"
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
###################################
# Returns the current time in
# human readable format
###################################
function current_time() {
epoch=$(date +%s)
readable=$(date -d @$epoch +"$TIMESTAMP_FORMAT")
echo "$readable"
}
###################################
# Replaces the last line of text
# in a file with $2
#
# @param $1: The file to update
# @param $2: The new line of text
###################################
function update_last_line() {
file="$1"
new_line="$2"
head -n -1 "$file" > temp.txt ; mv temp.txt "$file"
echo "$new_line" >> "$file"
}
###################################
# Updates this repo on git and
# pushes to master
###################################
function git_update() {
git add .
git commit -m "$COMMIT_MESSAGE" --amend
git push origin "$GIT_BRANCH" --force
}
###################################
# The main function that is
# executed when the script starts
###################################
function main() {
cd "$DIR"
new_line="$TIME_PREFIX $(current_time)"
update_last_line "$FILE_TO_UPDATE" "$new_line"
git_update
}
main