-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatecheck
executable file
·61 lines (55 loc) · 1.67 KB
/
datecheck
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
#!/bin/bash
# This script is a little ditty I modified to basically output something to the terminal screen every couple of seconds.
# It was origianlly developed to defeat ssh timeouts for long-running sessions.
# It relies heavily on tput and stty to get and set your terminal position, and on magic.
# If you have questions, I won't know how to answer them.
#
# Usage: me [ commmand ]
# Generally, it provides a rotating -\|/ spinner and the current date to be displayed in the upper right corner of the screen, refreshed every 3 seconds.
# You can override the default command from `date` to something else, but not that this won't work for complex commands at all.
#set -x
#set -v
ctrlc() {
tput cup "$row" "$col"
exit 0
}
getcurrent() {
# Get current position, stored in $row and $col. HORRIBLE hack, gotten from
# http://stackoverflow.com/questions/2575037/how-to-get-the-cursor-position-in-bash
exec < /dev/tty
oldstty=$(stty -g)
stty raw -echo min 0
echo -en "\033[6n" > /dev/tty
IFS=';' read -r -d R -a mypos
stty "$oldstty"
# change from one-based to zero based so they work with: tput cup $row $col
row=$((${mypos[0]:2} - 1)) # strip off the esc-[
col=$((mypos[1] - 1))
}
getposition () {
cmdchk=$($cmd)
padding=3
pos=$((cols-${#cmdchk}-padding))
}
getcurrent
i=1
sp="-\|/"
cols=$(tput cols)
cmd="date"
if [ -n "$1" ] ; then
cmd="$*"
fi
trap ctrlc SIGINT
while true ;
do
# Calculate where I want the check to be
getposition
tput cup 0 "$pos"
printf '%s' "$blanks"
tput cup 0 "$pos"
printf ' %s %s' "${sp:i++%${#sp}:1}" "$($cmd)"
blanks=$(printf ' %s %s' "${sp:i++%${#sp}:1}" "$($cmd)" | sed 's/./ /g')
sleep 3
i=$((i % ${#sp}))
done
ctrlc