-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogchange.sh
More file actions
executable file
·125 lines (93 loc) · 2.6 KB
/
logchange.sh
File metadata and controls
executable file
·125 lines (93 loc) · 2.6 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
filePath=${CHANGELOG_DIR}/changelog.txt
usage="$(basename "$0") [[-h|--help]|[--oops|--undo]|[ --show|--list]|--open] -- a simple interactive bash script to assist with recording information about major changes made to your system.
where:
-h|--help show this help text
--oops|--undo removes the last line added to the changelog after a confirmation prompt
--show|--list output the contents of the changelog file using the cat utility
--open open the changelog file in the kate text editor"
touch "$filePath"
removeLastLine() {
mv $filePath ${filePath}.tmp #the brackets are there to differentiate the variable from the ".tmp"
cat ${filePath}.tmp | head -n -1 > $filePath
rm ${filePath}.tmp
}
#handle undo
oops=false
for i in "$@"
do
case $i in
--oops|--undo)
oops=true
;;
--show|--list)
cat $filePath
exit 0
;;
--open)
kate $filePath &
exit 0
;;
*)
# unknown option
;;
h|--help) echo "$usage"
exit
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
if $oops
then
if [[ $(wc -l < $filePath) -ge 1 ]]
then
while [[ $(tail -n1 $filePath) == "" ]]
do
removeLastLine
done
lastEntry=
read -p "Your last line was \"$(tail -n1 $filePath)\". Really delete it? [yN]" delete
case $delete in
[Yy]* ) removeLastLine;;
*) echo "Undo Averted." ;;
esac
else
echo "$filePath is empty. Nothing to Undo"
fi
exit 0
fi
read -p "Is this a [s]ystem change or a [U]ser change?: " changeLevel
case $changeLevel in
[Ss]* ) changeLevel="System";;
[Uu]* ) changeLevel="User";;
*) changeLevel="User";;
esac
if [[ $changeLevel != "System" ]];
then
read -p "What piece of software does this change affect? (i.e. Firefox): " affectedSoftware
fi
read -p "What/Where/Why? " changeMade
read -p "Is there a link to go with this change? " link
DATE=`date '+%Y-%m-%d %H:%M'`
#build entry
entry="[$DATE $changeLevel] "
if [[ $changeLevel != "System" ]];
then
entry+="{ $affectedSoftware }: "
fi
entry+="$changeMade <$link>"
if [ -f $filePath ];
then
echo $entry >> $filePath
else
echo "changelog file not found. Is the correct environment variable set for this shell? (Check ~/.bash_aliases)"
echo "Failed to add the following log entry:"
echo "\"" + $entry + "\""
fi