#! /usr/bin/env python | |
import sys,os | |
class Bash2Py(object): __slots__ = ["val"] def __init__(self, value=''): self.val = value def setValue(self, value=None): self.val = value return value | |
def GetVariable(name, local=locals()): if name in local: return local[name] if name in globals(): return globals()[name] return None def Make(name, local=locals()): ret = GetVariable(name, local) if ret is None: ret = Bash2Py(0) globals()[name] = ret return ret | |
class Expand(object): @staticmethod def at(): if (len(sys.argv) < 2): return [] return sys.argv[1:] @staticmethod def star(in_quotes): if (in_quotes): if (len(sys.argv) < 2): return "" return " ".join(sys.argv[1:]) return Expand.at() | |
#!/bin/bash | |
# if no args | |
if [[ -z "$*" ]] ; then # get the date as "hours(12) minutes" in a single call # make a bash array with it d=( $(date "+%I %M") ) # separate hours and minutes hour=${d[0]#0} # remove leading 0 or values <10 will be interpreted as octal min=${d[1]#0} else # get the arguments passed to the script hour=${1#0} min=${2#0} fi | |
# if no args | |
if (Expand.star(1) == '' ): # get the date as "hours(12) minutes" in a single call | |
# make a bash array with it | |
Make("d").setValue("("+os.popen("date \"+%I %M\"").read().rstrip("\n")+")") # separate hours and minutes | |
Make("hour").setValue(d.val[0] ]#0) # remove leading 0 or values <10 will be interpreted as octal | |
Make("min").setValue(d.val[1] ]#0) else: # get the arguments passed to the script | |
Make("hour").setValue(sys.argv[1]#0) Make("min").setValue(sys.argv[2]#0) | |
plain=(🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛 ) | |
plain=Bash2Py("(🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛)") | |
half=(🕜 🕝 🕞 🕟 🕠 🕡 🕢 🕣 🕤 🕥 🕦 🕧 ) | |
half=Bash2Py("(🕜 🕝 🕞 🕟 🕠 🕡 🕢 🕣 🕤 🕥 🕦 🕧)") | |
# array index starts at 0 | |
hi=$((hour-1)) | |
# array index starts at 0 | |
hi=Bash2Py((hour.val - 1)) | |
if [[ $min -lt 15 ]] ; then echo -n ${plain[$hi]} elif [[ $min -lt 45 ]] ; then echo -n ${half[$hi]} else echo -n ${plain[$((hi+1))]} fi | |
if (int(min.val) < 15 ): print(plain.val[hi.val] ],end="") elif (int(min.val) < 45 ): print(half.val[hi.val] ],end="") else: print(plain.val[(hi.val + 1)] ],end="") | |