-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchfile.sh
executable file
·68 lines (56 loc) · 1.44 KB
/
watchfile.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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/local/bin/bash
#
# watchfile - watch file and display them & update contents
#
# ver: 0.0.1
# copyright (c) 2018 Cj-bc
# This software is released under MIT License.
watched=$1
COLOR_YELLOW=3
COLOR_GREEN=2
COLOR_BLUE=4
COLOR_WHITE=7
# get todo.txt's TODO_FILE and return file name
# @return 0 succcess
function watchfile.todofilename {
file_path=$(awk -F "\"" '/TODO_FILE/ {print $2}' ~/.todo.cfg)
echo ${file_path##*\/}
return 0
}
# echo files with color for each line(if there's configuration here)
# @param <string file_name>
# @
function watchfile.colcat {
# detect file type and chose which color to add.
case $1 in
*$(watchfile.todofilename) )
# for each line, detect priority and decide color.
while read line; do
local words=($line)
case ${words[0]} in
"(A)" ) tput setaf $COLOR_YELLOW;;
"(B)" ) tput setaf $COLOR_GREEN;;
"(C)" ) tput setaf $COLOR_BLUE;;
"(X)" ) tput setaf $COLOR_WHITE;;
* ):;;
esac
echo $line
tput sgr0
done < $1
;;
* ) cat $1
esac
}
# 1. get footprint sha256
# 2. if it's changed, clear the screen and cat the file
# 3. update the footprint
while true; do
new_sha256=$(openssl sha256 -r $watched | awk '{print $1}')
if [ "$new_sha256" != "$pre_sha256" ]; then
clear
tput cup 1 1
watchfile.colcat $watched
pre_sha256=$new_sha256
fi
sleep 0.5
done