<div dir="ltr"><div>I wrote this bash function, just for no particular reason, learning I guess:</div><div><br></div><div>function lvdati () {<br>    while [[ 1 ]]; do<br>        printf '\r%(%F %T (%A))T' -1<br>        sleep 0.1<br>
    done<br>}</div><div><br></div><div>It displays the current date and time in the terminal (use Ctrl+c to terminate it) in a certain format. On my machine, it looks like this, for instance:</div><div>2014-05-24 18:58:50 (lördag)</div>
<div><br></div><div>What I don't want to happen is this:</div><div>2014-05-22 23:59:59 (torsdag)</div><div>Then a second later:</div><div>2014-05-23 00:00:00 (fredag))</div><div><br></div><div>Since ”fredag” (friday) is one character shorter than ”torsdag” (thursday), the last character of the torsdag line will still remain, won't it?</div>
<div>So I need something at the end of the string that works like Ctrl+k in the terminal (erase everything on the right side of the cursor), but how do I implement it?</div><div><br></div><div>Let's say that Ctrl+k='\k' (it isn't, but just imagine it…), then I would try:</div>
<div>function lvdati () {<br>    while [[ 1 ]]; do<br>        printf '\r%(%F %T (%A))T\k' -1<br>        sleep 0.1<br>    done<br>}</div><div><br></div><div>Suggestions (except adding one or more spaces to the string)?</div>
<div><br></div><div><br></div><div>Johnny Rosenberg</div></div>