This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A gevent-based script that copies input to output, but interrupts every second to paint the current time at the top of the screen. | |
May change the time format with an optional argument. | |
Time format is as per the date(1) command, as well as the following escapes: | |
\e -> ESC character | |
\t -> Tab | |
\\ -> Literal \ | |
For example, you could color your time output bold blue with the argument '\e[1;34m%X\e[m' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A python library of constants and utility functions for using ANSI terminal escapes. | |
Example usage: | |
>>> import escapes as e | |
>>> print e.FORECOLOUR(e.RED) + "this is red" + e.UNFORMAT | |
""" | |
ESC = "\033" # escape character for terminal | |
CSI = ESC + "[" # Control Sequence Initiator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
import sys | |
def with_argv(fn): | |
"""Decorator that wraps your 'main' function, giving it some automatic behaviour. | |
The resulting function should not be passed any args. | |
Command line arguments are interpreted as follows: | |
The first argument is the program name, it is dropped (you can still access it with sys.argv[0]). | |
If an argument has form '--key=value', main's kwargs are updated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import termios | |
import sys | |
from itertools import count | |
class TermAttrs(object): | |
def __init__(self, attrs, fd=None, when=termios.TCSANOW): | |
"""A context manager for changing terminal attrs. | |
fd defaults to stdin. | |
attrs must be a 7-element iterable as taken by tcsetattr. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ "$#" -lt 2 ]; then | |
echo "USAGE: $0 TIME COMMAND {ARGS}" | |
echo "Run COMMAND with ARGS at specified TIME." | |
echo "TIME may be given in any form understood by date(1)" | |
exit 2 | |
fi | |
duestr="$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prefixes current PS1 with a blank space | |
# This blank space changes to a ! character if any command | |
# given in the ALERTS array exits non-zero. | |
# (additionally, a ? character is an error state - this shouldn't happen) | |
# Tip: ALERTS may be appended to thusly: ALERTS+=('mycommand myarg') | |
# Note: Commands in ALERTS are run every time PS1 is printed. | |
# However, if any command fails (indicates an alert), no further commands will be run. | |
declare -a ALERTS[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USAGE="$0 [FORMAT]" | |
FORMAT="${1:-%T}" | |
while sleep 1; do | |
clear | |
echo | |
banner "`date "+$FORMAT"`" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USAGE="$0 [TIMESPEC] | |
A speaking clock that says the time once every TIMESPEC. | |
For example, \"$0 1 hour\" would speak at the boundary of every hour, | |
while \"$0 15 minutes\" would speak four times as often. | |
In technical terms, the time is reported when time since epoch is divisible by TIMESPEC. | |
TIMESPEC defaults to 1 hour. | |
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLACK=30 | |
GRAY="$BLACK;1" | |
RED=31 | |
BOLDRED="$RED;1" | |
GREEN=32 | |
BOLDGREEN="$GREEN;1" | |
YELLOW=33 | |
BOLDYELLOW="$YELLOW;1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USAGE="$0 TIMESPEC [COMMAND {ARGS}] | |
Do a banner-style countdown starting from TIMESPEC. | |
TIMESPEC should be either integer seconds, or in one of the forms: | |
XXm XXmXX XXmXXs XX:XX | |
For example: 10m, 10m00, 10m0s, 10:00 or 600 are all ways of saying 10 minutes. | |
If given, COMMAND will be run with ARGS once the timer has completed. | |
" |
OlderNewer