clock with timer, folderflat with custom character and as-is

This commit is contained in:
Ville Rantanen
2015-11-12 10:54:12 +02:00
parent 9e9fc69571
commit aa7de42890
2 changed files with 84 additions and 24 deletions

View File

@@ -4,25 +4,61 @@ function help() {
echo "Files in subfolders will be renamed / -> _" echo "Files in subfolders will be renamed / -> _"
echo "Empty folders are removed" echo "Empty folders are removed"
echo " -f to force action " echo " -f to force action "
echo " -n to move files as is, i.e. not include path names in new name "
echo " -p C Replace path separator / with character C "
} }
function helpexit() { function helpexit() {
help help
exit exit
} }
[[ -z "$1" ]] && {
function preview() {
echo ""
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' | head ); do
[[ "$NO_PATH" = "1" ]] && {
echo "$f => " .
} || {
echo "$f =>" "${f//\//$SEP}"
}
done
echo "..."
}
function flat() {
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' ); do
[[ "$NO_PATH" = "1" ]] && {
mv -iv "$f" .
} || {
mv -iv "$f" "${f//\//$SEP}"
}
done
find . -depth -type d -empty -delete
}
SEP="_"
FORCE=0
while getopts fhnp: opt
do case "$opt" in
f)
FORCE=1
;;
h)
helpexit
;;
n)
NO_PATH=1
;;
p)
SEP=$OPTARG
;;
esac
done
IFS=$'\n'
[[ "$FORCE" = "0" ]] && {
help help
preview
echo "Are you sure? Break with ctrl-c" echo "Are you sure? Break with ctrl-c"
read i read i
} }
[[ "$1" = "-h" ]] && helpexit flat
IFS=$'\n'
for f in $( find . -mindepth 2 -type f -path '*.*' -printf %P'\n' );
do mv -iv "$f" "$( echo $f | sed s,[/],_,g )"
done
find . -depth -type d -empty -delete

View File

@@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import curses import curses
import os,sys import os,sys
import time import time,datetime
import math import math
import signal import signal
from optparse import OptionParser from optparse import OptionParser
@@ -30,12 +30,12 @@ def drawcircle(win,cy,cx,r):
saddstr(win,dy,dx,'.') saddstr(win,dy,dx,'.')
return return
def drawline(win,cy,cx,a,r,char): def drawline(win,cy,cx,a,s,r,char):
prec=2 prec=2
for l in range(r*prec): for l in range(r*prec):
if l>1: if l>s:
ly=int(round(cy-float(l)*math.cos(a)/prec)) ly=int(round(cy-float(l)*math.cos(a)/prec))
lx=int(round(cx+1.8*float(l)*math.sin(a)/prec)) lx=int(round(cx+2.0*float(l)*math.sin(a)/prec))
saddstr(win,ly,lx,char) saddstr(win,ly,lx,char)
return return
@@ -96,10 +96,18 @@ def readinput(win):
except: except:
return "" return ""
return "" return ""
class timer_struct:
""" Class for storing timer. """
def __init__(self,h,m,s):
self.tm_hour=int(h)
self.tm_min=int(m)
self.tm_sec=int(s)
def main(): def main():
stdscr=curses.initscr() stdscr=curses.initscr()
curses.curs_set(0) curses.curs_set(0)
start_t=time.time()
try: try:
#rows,columns = termsize() #rows,columns = termsize()
while (1): while (1):
@@ -107,16 +115,30 @@ def main():
cy,cx,r = centerpoint(rows,columns) cy,cx,r = centerpoint(rows,columns)
stdscr.clear() stdscr.clear()
t=time.localtime() t=time.localtime()
alphas=math.pi*float(t.tm_sec)/30.0 if options.timer:
alpham=math.pi*float(t.tm_min)/30.0 + alphas/60.0 t_new=time.time()-start_t
alphah=math.pi*float(t.tm_hour)/6.0 + alpham/12.0 t_m, t_s = divmod(t_new, 60)
t_h, t_m = divmod(t_m, 60)
else:
t_s=float(t.tm_sec)
t_m=float(t.tm_min)
t_h=float(t.tm_hour)
alphas=math.pi*t_s/30.0
alpham=math.pi*t_m/30.0 + alphas/60.0
alphah=math.pi*t_h/6.0 + alpham/12.0
if options.seconds: if options.seconds:
drawline(stdscr,cy,cx,alphas,r/2,'s') drawline(stdscr,cy,cx,alphas,1,r/2,'s')
drawline(stdscr,cy,cx,alpham,int(round(r*0.8)/2),'m') drawline(stdscr,cy,cx,alpham,1,int(round(r*0.8)/2),'m')
drawline(stdscr,cy,cx,alphah,int(round(r*0.5)/2),'HH') drawline(stdscr,cy,cx,alphah,1,int(round(r*0.5)/2),'HH')
stdscr.addstr(cy,cx,'o') stdscr.addstr(cy,cx,'o')
drawcircle(stdscr,cy,cx,r/2) drawcircle(stdscr,cy,cx,r/2)
drawdigital(stdscr,1,1,t) for h in range(12):
drawline(stdscr,cy,cx,math.pi*h/6.0,r,1+r/2,'O')
if options.timer:
drawdigital(stdscr,1,1,timer_struct(t_h,t_m,t_s))
drawdigital(stdscr,7,1,t)
else:
drawdigital(stdscr,1,1,t)
stdscr.refresh() stdscr.refresh()
#time.sleep(options.refresh) #time.sleep(options.refresh)
signal.signal(signal.SIGALRM, readinput) signal.signal(signal.SIGALRM, readinput)
@@ -144,6 +166,8 @@ parser.add_option("-s",action="store_true",dest="seconds",default=False,
help="Show seconds [%default]") help="Show seconds [%default]")
parser.add_option("-r",type="int",dest="refresh",default=3, parser.add_option("-r",type="int",dest="refresh",default=3,
help="Refresh rate in seconds [%default]") help="Refresh rate in seconds [%default]")
parser.add_option("-t",action="store_true",dest="timer",default=False,
help="Timer instead of current time [%default]")
global options global options
(options,args)=parser.parse_args() (options,args)=parser.parse_args()