@@ -0,0 +1 @@ | |||
http://imgs.xkcd.com/comics/trolley_problem.png |
@@ -0,0 +1,39 @@ | |||
#!/bin/sh | |||
# ANSI Color -- use these variables to easily have different color | |||
# and format output. Make sure to output the reset sequence after | |||
# colors (f = foreground, b = background), and use the 'off' | |||
# feature for anything you turn on. | |||
initializeANSI() | |||
{ | |||
esc="" | |||
blackf="${esc}[30m"; redf="${esc}[31m"; greenf="${esc}[32m" | |||
yellowf="${esc}[33m" bluef="${esc}[34m"; purplef="${esc}[35m" | |||
cyanf="${esc}[36m"; whitef="${esc}[37m" | |||
blackb="${esc}[40m"; redb="${esc}[41m"; greenb="${esc}[42m" | |||
yellowb="${esc}[43m" blueb="${esc}[44m"; purpleb="${esc}[45m" | |||
cyanb="${esc}[46m"; whiteb="${esc}[47m" | |||
boldon="${esc}[1m"; boldoff="${esc}[22m" | |||
italicson="${esc}[3m"; italicsoff="${esc}[23m" | |||
ulon="${esc}[4m"; uloff="${esc}[24m" | |||
invon="${esc}[7m"; invoff="${esc}[27m" | |||
reset="${esc}[0m" | |||
} | |||
# note in this first use that switching colors doesn't require a reset | |||
# first - the new color overrides the old one. | |||
initializeANSI | |||
cat << EOF | |||
${redf}โโโโ${reset} ${boldon}${redf}โโ${reset} ${greenf}โโโโ${reset} ${boldon}${greenf}โโ${reset} ${yellowf}โโโโ${reset} ${boldon}${yellowf}โโ${reset} ${bluef}โโโโ${reset} ${boldon}${bluef}โโ${reset} ${purplef}โโโโ${reset} ${boldon}${purplef}โโ${reset} ${cyanf}โโโโ${reset} ${boldon}${cyanf}โโ${reset} | |||
${redf}โโ โ ${reset} ${boldon}${redf}โโ${reset} ${greenf}โโ โ ${reset} ${boldon}${greenf}โโ${reset} ${yellowf}โโ โ ${reset} ${boldon}${yellowf}โโ${reset} ${bluef}โโ โ ${reset} ${boldon}${bluef}โโ${reset} ${purplef}โโ โ ${reset} ${boldon}${purplef}โโ${reset} ${cyanf}โโ โ ${reset} ${boldon}${cyanf}โโ${reset} | |||
${redf}โโ ${reset}${boldon}${redf}โโโโ${reset} ${greenf}โโ ${reset}${boldon}${greenf}โโโโ${reset} ${yellowf}โโ ${reset}${boldon}${yellowf}โโโโ${reset} ${bluef}โโ ${reset}${boldon}${bluef}โโโโ${reset} ${purplef}โโ ${reset}${boldon}${purplef}โโโโ${reset} ${cyanf}โโ ${reset}${boldon}${cyanf}โโโโ${reset} | |||
EOF |
@@ -0,0 +1,227 @@ | |||
# All numeric values are in hexadecimal | |||
# Use TAB or EQUAL sign to separate name from value | |||
# | |||
# Key configuration (all numbers are in hexadecimal!) | |||
# | |||
# Keys values are in the format YXXX where Y is the device number. 0 means | |||
# keyborad and XXX is the SDL define for the desired key (read SDL_keysym.h). | |||
# | |||
# If Y is greater than 0, it means joystick number Y-1 and it uses the | |||
# following format for XXX: | |||
# | |||
# - if XXX < 20, XXX is the axis number multiplied by 2. An even number means | |||
# movement to the negative side (on the X axis, it means left). An odd | |||
# number means movement to the positive side (on the X axis, it mean | |||
# right). For the Y axis, negative means up and positive means down. | |||
# X axis is usally axis number 0 and Y is axis number 1. | |||
# - if 20 >= XXX > 30, then XXX is the HAT number multiplied by 4 plus the | |||
# direction: 0 for up, 1 for down, 2 for right and 3 for left. Example: | |||
# 0021 is HAT 0 down, 0026 is HAT 1 right. | |||
# - if 80 >= XXX > 100, XXX is the joystick button number (XXX-080). | |||
# | |||
# Default key configuration is (value in parenthesis): | |||
# | |||
# Left Left Arrow (0114) | |||
# Right Right Arrow (0113) | |||
# Up Up Arrow (0111) | |||
# Down Down Arrow (0112) | |||
# A Z (007a) | |||
# B X (0078) | |||
# L A (0061) | |||
# R S (0073) | |||
# Start ENTER (000d) | |||
# Select BACKSPACE (0008) | |||
# Speed up SPACE (0020) | |||
# Capture F12 (0125) | |||
# | |||
#Joy0_Left=0114 | |||
#Joy0_Right=0113 | |||
#Joy0_Up=0111 | |||
#Joy0_Down=0112 | |||
#Joy0_A=0131 | |||
#Joy0_B=013f | |||
#Joy0_L=0061 | |||
#Joy0_R=0073 | |||
#Joy0_Start=000d | |||
#Joy0_Select=012f | |||
#Joy0_Speed=0020 | |||
#Joy0_Capture=0125 | |||
Joy0_Left=1000 | |||
Joy0_Right=1001 | |||
Joy0_Up=1002 | |||
Joy0_Down=1003 | |||
Joy0_A=1080 | |||
Joy0_B=1081 | |||
Joy0_L=0061 | |||
Joy0_R=0073 | |||
Joy0_Start=1087 | |||
Joy0_Select=1086 | |||
Joy0_Speed=1004 | |||
Joy0_Capture=0125 | |||
# Motion support keys. Same format as above | |||
# | |||
# Default keys are (value in parenthesis): | |||
# | |||
# Left Numeric Pad 4 (0104) | |||
# Right Numeric Pad 6 (0106) | |||
# Up Numeric Pad 8 (0108) | |||
# Down Numeric Pad 2 (0102) | |||
# | |||
Motion_Left=0104 | |||
Motion_Right=0106 | |||
Motion_Up=0108 | |||
Motion_Down=0102 | |||
# Frame skip setting. Allowed values are from 0 to 5 only. | |||
frameSkip=2 | |||
# Gameboy Frame skip setting. Allowed values are from 0 to 5 only. | |||
gbFrameSkip=0 | |||
# Video setting. 0=1x, 1=2x, 2=3x, 3=4x. | |||
video=1 | |||
# Use fullscreen mode. 0=false, any other value means true | |||
fullScreen=0 | |||
# Disables MMX support | |||
disableMMX=1 | |||
# Use bios file. 0=false, any other value means true | |||
useBios=0 | |||
# Bios file full path and name (ZIP not supported) | |||
biosFile=none | |||
# Filter to use. 0=no filter, 1=TV Mode, 2=2xSaI, 3=Super 2xSaI, 4=Super Eagle | |||
# 5=Pixelate, 6=Motion Blur, 7=AdvanceMAME Scale2x, 8=Simple 2x, | |||
# 9=Bilinear, A=Bilinear Plus, B=hq2x, C=lq2x | |||
filter=0 | |||
# Disable status messages. 0=false, any other value means true | |||
disableStatus=0 | |||
# Enable Gameboy border. 0=false, any other value means true | |||
borderOn=0 | |||
# Gameboy emulator type. 0=automatic, 1=CGB/GBC, 2=SGB, 3=GB, 4=GBA, 5=SGB2 | |||
emulatorType=1 | |||
# Enable washed colors. 0=false, any other value means true | |||
colorOption=1 | |||
# Directories. Not setting one them makes the file go the rom directory. | |||
# Save state directory | |||
#saveDir= | |||
# Screen shot Capture directory | |||
#captureDir= | |||
# Battery directory | |||
#batteryDir= | |||
# Screen capture format | |||
# 0=PNG, anything else for BMP | |||
captureFormat=0 | |||
# Sound quality | |||
# 1=44 Khz, 2=22Khz, 4=11Khz | |||
soundQuality=2 | |||
# Sound Echo | |||
# 0=false, anything else for true | |||
soundEcho=0 | |||
# Sound Low pass filter | |||
# 0=false, anything else for true | |||
soundLowPass=0 | |||
# Sound reverse stereo | |||
# 0=false, anything else for true | |||
soundReverse=0 | |||
# Remove GBA intros (not supported anymore) | |||
# 0=false, anything else for true | |||
# removeIntros=0 | |||
# Save Type | |||
# 0=automatic, 1=EEPROM, 2=SRAM, 3=Flash, 4=EEPROM+Sensor, 5=NONE | |||
saveType=0 | |||
# Flash size | |||
# 0=64K Flash, 1=128K Flash | |||
flashSize=1 | |||
# Sound volume | |||
# 0=1x, 1=2x, 2=3x, 3=4x | |||
soundVolume=0 | |||
# Interframe blending | |||
# 0=none, 1=motion blur, 2=smart | |||
ifbType=0 | |||
# Show emulation speed | |||
# 0=none, 1=percentage, 2=detailed | |||
showSpeed=1 | |||
# Show speed in transparent mode | |||
# 0=normal, anything else for transparent | |||
showSpeedTransparent=1 | |||
# Enable/Disable auto frameskip | |||
# 0=disable, anything else to enable | |||
autoFrameSkip=0 | |||
# Sets the desired throttle | |||
# 0=disable, 5...1000 valid throttle speeds | |||
throttle=200 | |||
# Pauses the emulator when the window is inactive | |||
# 0=disable, anything else to enable | |||
pauseWhenInactive=1 | |||
# Enables AGBPrint support | |||
# 0=disable, anything else to enable | |||
agbPrint=0 | |||
# Enables GBA RTC support | |||
# 0=disable, anything else to enable | |||
rtcEnabled=0 | |||
# Sound OFF flag | |||
# 0=sound on, anything else turns off sound | |||
soundOff=1 | |||
# Sound Enable | |||
# Controls which channels are enabled: (add values) | |||
# 1 - Channel 1 | |||
# 2 - Channel 2 | |||
# 4 - Channel 3 | |||
# 8 - Channel 4 | |||
# 100 - DirectSound A | |||
# 200 - DirectSound B | |||
# 30f=all enabled, 0=mute all | |||
soundEnable=0 | |||
# Controls automatic SGB border | |||
# 0=disable, anything else enables automatic SGB border display | |||
borderAutomatic=0 | |||
# Skip bios code | |||
# 0=disable, anything else skips BIOS code | |||
skipBios=0 | |||
# The interval between the rewind saves | |||
# Minimum of 0 seconds to disable rewind support, | |||
# Maximum of 60 minutes. Value in seconds (hexadecimal numbers) | |||
rewindTimer=0 | |||
# Enable enhanced save type detection | |||
# 0=disable, anything else to enable (no longer used) | |||
#enhancedDetection=1 |
@@ -0,0 +1,12 @@ | |||
#!/bin/bash | |||
PROCESS=trayer | |||
number=$(pidof trayer) | |||
if [ $number -gt 0 ] | |||
then | |||
kill $number | |||
else | |||
trayer --edge top --align right --widthtype request --heighttype pixel \ | |||
--height 22 --expand true --tint 0x242424 --transparent true \ | |||
--alpha 0 & | |||
fi |
@@ -0,0 +1,46 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - compress/extract archives by extension. | |||
# | |||
### | |||
if [ -z "$1" ]; then | |||
printf "usage: archive [ -x ] [ file, ... ]\n" >&2 | |||
exit 1 | |||
fi | |||
case "$1" in | |||
-x|--extract) | |||
shift | |||
for archive; do | |||
case "$archive" in | |||
*.tbz2|*.tar.bz2) tar xvjf "$archive" ;; | |||
*.tgz|*.tar.gz) tar xvzf "$archive" ;; | |||
*.tar) tar xvf "$archive" ;; | |||
*.gz) gunzip "$archive" ;; | |||
*.bz2) bunzip2 "$archive" ;; | |||
*.zip) unzip "$archive" ;; | |||
*.rar) unrar x "$archive" ;; | |||
*.Z) uncompress "$archive" ;; | |||
*.7z) 7z x "$archive" ;; | |||
*) | |||
printf "%s: unknown extension\n" "$archive" >&2 | |||
exit 1 | |||
;; | |||
esac | |||
done | |||
;; | |||
*) | |||
target="$1"; shift | |||
case "$target" in | |||
*.tbz2|*.tar.bz2) tar cvpjf "$target" "$@" ;; | |||
*.tgz|*.tar.gz) tar cvpzf "$target" "$@" ;; | |||
*.gz) cat "$@" | gzip > "$target" ;; | |||
*.bz2) cat "$@" | bzip2 > "$target" ;; | |||
*.zip) zip -r "$target" "$@" ;; | |||
*) $0 "$target.tar.gz" "$target" "$@" ;; | |||
esac | |||
;; | |||
esac |
@@ -0,0 +1,10 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - stupid simple, feature-less aur installer. | |||
# | |||
### | |||
packages='https://aur.archlinux.org/packages' | |||
package_url=$(printf "$1" | sed "s%^\(..\).*%$packages/\1/&/&.tar.gz%") | |||
curl -# "$package_url" | tar fxz - && | |||
(cd "./$1" && makepkg -i -r -s) && rm -rf "./$1" |
@@ -0,0 +1,6 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - open mutt in a new terminal. | |||
# | |||
### | |||
cower -u | wc -l |
@@ -0,0 +1,43 @@ | |||
#!/bin/bash | |||
# | |||
# Backup script | |||
# | |||
# Format: YEAR MONTH DAY | |||
DATE=$(date +%Y%m%d) | |||
INCLUDE1="/home/shaggy/.vimrc /home/shaggy/.abook /home/shaggy/.calcurse /home/shaggy/.colors" | |||
INCLUDE2="/home/shaggy/.config/bspwm /home/shaggy/.config/dwb /home/shaggy/.config/htop /home/shaggy/.config/mpd" | |||
INCLUDE3="/home/shaggy/.config/mps-youtube /home/shaggy/.config/mpv /home/shaggy/.config/Mumble /home/shaggy/.config/qutebrowser" | |||
INCLUDE4="/home/shaggy/.config/ranger /home/shaggy/.config/sxhkd /home/shaggy/.config/sxiv /home/shaggy/.config/wmfs" | |||
INCLUDE5="/home/shaggy/.config/youtube-viewer /home/shaggy/.cortex /home/shaggy/.fonts /home/shaggy/.fluxbox" | |||
INCLUDE6="/home/shaggy/.irssi /home/shaggy/.i3 /home/shaggy/.mpv /home/shaggy/.mutt /home/shaggy/.muttrc" | |||
INCLUDE7="/home/shaggy/.nano /home/shaggy/.ncmpcpp /home/shaggy/.newsbeuter /home/shaggy/.offlineimap" | |||
INCLUDE8="/home/shaggy/.ssh /home/shaggy/.themes /home/shaggy/.turses /home/shaggy/.password-store" | |||
INCLUDE9="/home/shaggy/.vim /home/shaggy/.weechat /home/shaggy/scripts /home/shaggy/.aliasrc" | |||
INCLUDE10="/home/shaggy/.cliweather /home/shaggy/.conkyrc /home/shaggy/.gitconfig /home/shaggy/.goobook_cache" | |||
INCLUDE11="/home/shaggy/.msmtprc /home/shaggy/.nanorc /home/shaggy/.netrc /home/shaggy/.offlineimaprc" | |||
INCLUDE12="/home/shaggy/.notmuch-config /home/shaggy/.Xdefaults /home/shaggy/.xinitrc /home/shaggy/.xprofile" | |||
INCLUDE13="/home/shaggy/.zshrc /home/shaggy/.zsh_history /home/shaggy/.screenrc" | |||
INCLUDE14="/home/shaggy/scripts /home/shaggy/private" | |||
BACKUPDIRARCH=/riddlebox/Dropbox/backups/archconfigs/ | |||
# Target file | |||
TARTARGET="/riddlebox/Dropbox/backups/backup-$DATE.tar.gz" | |||
TARTARGETMAIL="/riddlebox/Dropbox/backups/backupmail-$DATE.tar.gz" | |||
#tar -czvf $TARTARGET $MYSQLTARGET /home/code/bots /var/config /var/system | |||
tar -czvf $TARTARGETMAIL /home/shaggy/Maildir | |||
tar -czvf $TARTARGET /home/shaggy/bin $INCLUDE1 $INCLUDE2 $INCLUDE3 $INCLUDE4 $INCLUDE5 $INCLUDE6 $INCLUDE7 $INCLUDE8 $INCLUDE9 $INCLUDE10 $INCLUDE11 $INCLUDE12 $INCLUDE13 $INCLUDE14 | |||
nice -n 19 rsync --archive --force --delete --progress --compress /etc $BACKUPDIRARCH | |||
@@ -0,0 +1,7 @@ | |||
#!/bin/zsh | |||
BACKUPDIR=/riddlebox/Dropbox/backups/ | |||
nice -n 19 rsync --archive --force --delete --progress --compress /etc $BACKUPDIR | |||
# rsync --archive --force --delete --progress --compress /usr $BACKUPDIR | |||
#rsync --archive --force --delete --progress --compress /var $BACKUPDIR |
@@ -0,0 +1,16 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - perform a backup via tarsnap. | |||
# | |||
### | |||
die() { printf "%s\n" "$*" >&2; exit 1; } | |||
[ $UID -eq 0 ] || die 'You must be root' | |||
which tarsnap >/dev/null || die 'You must install tarsnap' | |||
timestamp="$(date +%Y%m%d.%H:%M:%S)" | |||
tarsnap "$@" \ | |||
--keyfile /root/tarsnap.key \ | |||
--cachedir /usr/local/tarsnap-cache \ | |||
-c -f "backup-$timestamp" /root /home /etc /srv |
@@ -0,0 +1,44 @@ | |||
#!/bin/sh | |||
# | |||
# dtch - (c) wtfpl 2014 | |||
# fetch info and print to stdout | |||
clock () { | |||
date '+%H.%M' | |||
} | |||
volume() { | |||
amixer get PCM | sed -n 's/^.*\[\([0-9]\+\)%.*$/\1/p' | uniq | |||
} | |||
cpu() { | |||
LINE=`ps -eo pcpu | grep -vE '^\s*(0.0|%CPU)' | sed -n '1h;$!H;$g;s/\n/ +/gp'` | |||
bc <<< $LINE | |||
} | |||
ram() { | |||
read t f <<< `grep -E 'Mem(Total|Free)' /proc/meminfo | awk '{print $2}'` | |||
bc <<< "scale=2; 100 - $f / $t * 100" | cut -d. -f1 | |||
} | |||
#nowplaying() { | |||
# cur=`mpc current` | |||
# test "$1" = "scroll" && PARSER='skroll -n20 -d0.5 -r' || PARSER='cat' | |||
# test -n "$cur" && $PARSER <<< $cur || echo "- stopped -" | |||
#} | |||
music() { | |||
echo -n $(test -z "$(mpc current)" || mpc current -f "%title%") | |||
} | |||
while :; do | |||
buf="" | |||
buf="${buf} MPD: $(music) -" | |||
buf="${buf} VOL: $(volume)%% -" | |||
buf="${buf} CLK: $(clock) -" | |||
buf="${buf} RAM: $(ram)%% -" | |||
buf="${buf} CPU: $(cpu)%%" | |||
echo $buf | |||
sleep 1 | |||
done |
@@ -0,0 +1,24 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2014 - adjust backlight brightness. Must be run as root. | |||
# | |||
### | |||
directory=/sys/class/backlight/intel_backlight | |||
cur=$(cat "$directory"/brightness) | |||
max=$(cat "$directory"/max_brightness) | |||
amt=$((max/10)) | |||
val=$cur | |||
case "$1" in | |||
u) val=$((cur+amt)) ;; | |||
d) val=$((cur-amt)) ;; | |||
m) val=$max ;; | |||
*) { printf "usage: bl [u|d|m]\n" >&2; exit 64; } ;; | |||
esac | |||
# Bounds check | |||
[ $val -gt $max ] && val=$max | |||
[ $val -lt 0 ] && val=0 | |||
echo $val > "$directory"/brightness |
@@ -0,0 +1,20 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - burn an ISO to CD/DVD. | |||
# | |||
### | |||
device=/dev/sr0 | |||
case $1 in | |||
-h|--help) | |||
printf "usage: burn [-c] <file.iso>\n" | |||
exit | |||
;; | |||
-c|--cd) | |||
shift | |||
cdrecord -v speed=48 dev=$device "$1" | |||
;; | |||
*) | |||
growisofs -dvd-compat -Z $device="$1" | |||
;; | |||
esac |
@@ -0,0 +1,18 @@ | |||
#!/bin/sh | |||
# | |||
# pbrisbin 2014 - install "system" Haskell packages. | |||
# | |||
### | |||
set -e | |||
if [ "$1" = 'clear' ]; then | |||
rm -fr \ | |||
~/.ghc \ | |||
~/.cabal/bin/* \ | |||
~/.cabal/packages/*/* \ | |||
fi | |||
cd # avoid accidental sandbox installation | |||
cabal update | |||
cabal install cabal-install --avoid-reinstalls | |||
cabal install hi msu pandoc xmonad xmonad-contrib --avoid-reinstalls |
@@ -0,0 +1,10 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - perform simple math via bc or awk. | |||
# | |||
### | |||
if which bc &>/dev/null; then | |||
printf "scale=10; %s\n" "$*" | bc -l | |||
else | |||
printf "BEGIN { print %s }\n" "$*" | awk -f - | |||
fi |
@@ -0,0 +1,7 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - open my remote chat session in a new terminal. | |||
# | |||
### | |||
urxvtc -title chat -n chat -e \ | |||
ssh -t pbrisbin.com "bash -ilc 'screen -R -D -S irc weechat'" |
@@ -0,0 +1 @@ | |||
Subproject commit fb8de089ebdcc619edf3b22b991f4b020200a815 |
@@ -0,0 +1,137 @@ | |||
#!/usr/bin/env python2 | |||
from xml.dom.minidom import parseString | |||
try: | |||
from urllib.request import urlopen | |||
except ImportError: | |||
from urllib import urlopen | |||
try: | |||
from urllib.parse import urlencode | |||
except ImportError: | |||
from urllib import urlencode | |||
from sys import argv, exit, stderr, stdout | |||
import os.path | |||
import datetime | |||
VERSION = '.01' | |||
URL = 'http://www.aaronfoltz.com' | |||
YAHOO_API_KEY = 'dj0yJmk9TEdTT09FNVp6MWlhJmQ9WVdrOVpsaGhVbEZTTmpJbWNHbzlOalUyT0RNMk1qWXkmcz1jb25zdW1lcnNlY3JldCZ4PTkw' | |||
WOEID_URL = 'http://where.yahooapis.com/v1/places.q({0})?' | |||
YAHOO_API_URL = 'http://weather.yahooapis.com/forecastrss?' | |||
def main(): | |||
try: | |||
# Forecast option | |||
if "-f" in argv[1]: | |||
# See if there is a zip with the argument | |||
try: | |||
place = argv[2] | |||
getForecast(place) | |||
# If no zip is provided, get it from the geolocation service | |||
except IndexError: | |||
place = getPlace() | |||
getForecast(place) | |||
# Else there isn't an option there, it must be a zip code if anything | |||
else: | |||
try: | |||
place = argv[1] | |||
getCurrent(place) | |||
# No arguments are provided, get the place from the geolocation service | |||
except IndexError: | |||
place = getPlace() | |||
getCurrent(place) | |||
except IndexError: | |||
place = getPlace() | |||
getCurrent(place) | |||
def getCurrent(place): | |||
woeid = getWOEID(place) | |||
# Call to get the weather | |||
api = YAHOO_API_URL + urlencode({'w': woeid}) | |||
dom = parseString(urlopen(api).read()) | |||
# Get the necessary DOM elements | |||
location = dom.getElementsByTagName('yweather:location')[0] | |||
currentConditions = dom.getElementsByTagName('yweather:condition')[0] | |||
atmosphere = dom.getElementsByTagName('yweather:atmosphere')[0] | |||
wind = dom.getElementsByTagName('yweather:wind')[0] | |||
print('Location: %s, %s' % (location.getAttribute("city"), location.getAttribute("region"))) | |||
print('Condition: %s' % currentConditions.getAttribute("text")) | |||
print('Temperature: %sF/%sC' % (currentConditions.getAttribute("temp"), fahToCel(currentConditions.getAttribute("temp")))) | |||
print('Humidity: %s' % atmosphere.getAttribute('humidity') + "%") | |||
print('Wind: %s mph %s' % (wind.getAttribute("speed"), degToCompass(wind.getAttribute("direction")))) | |||
def getForecast(place): | |||
woeid = getWOEID(place) | |||
# Call to get the weather | |||
api = YAHOO_API_URL + urlencode({'w': woeid}) | |||
dom = parseString(urlopen(api).read()) | |||
# Get the necessary DOM elements | |||
forecasts = dom.getElementsByTagName('yweather:forecast') | |||
# Print info for each forecast day | |||
for day in forecasts: | |||
print('Day: %s' % datetime.datetime.strptime(day.getAttribute('date'), '%d %b %Y').strftime('%A, %B %d, %Y')) | |||
print('\tHigh: %sF/%sC' % (day.getAttribute("high"), fahToCel(day.getAttribute("high")))) | |||
print('\tLow: %sF/%sC' % (day.getAttribute("low"), fahToCel(day.getAttribute("low")))) | |||
print('\tCondition: %s' % day.getAttribute('text')) | |||
# Retrives zip code if not entered | |||
def getPlace(): | |||
import re | |||
path = "%s/.cliweather" % os.getenv("HOME") | |||
if os.path.exists(path): | |||
try: | |||
f = open(path, 'r') | |||
return f.read() | |||
except: | |||
print "Could not load .cliweather" | |||
# Get the geoip information | |||
geoip = urlopen('http://api.ipinfodb.com/v3/ip-city/?key=29e619f84fd83f32c4987573a4ccc11fd59b268234aa50c1289230f1fff0dbd2').read() | |||
# The returned value is perfectly fine | |||
if re.match("OK;;", geoip): | |||
# regex to get the zip code | |||
expression = "OK;;([^;]+;){5}(\w+)" | |||
result = re.search(expression, geoip) | |||
# return the zip code from the returned data | |||
return result.group(2) | |||
# Make a call to Yahoo's API to get the WOEID given a zip code | |||
def getWOEID(place): | |||
# Make the call to the API to return the XML with WOEID | |||
api = (WOEID_URL + urlencode({'appid': YAHOO_API_KEY})).format(place) | |||
dom = parseString(urlopen(api).read()) | |||
# Return parsed WOEID | |||
return dom.getElementsByTagName('woeid')[0].firstChild.data | |||
# Convert Fah to Cel | |||
def fahToCel(value): | |||
return '{0:.0f}'.format((100.0/(212-32)) * (int(value) - 32)) | |||
# From http://stackoverflow.com/questions/7490660/converting-wind-direction-in-angles-to-text-words | |||
def degToCompass(num): | |||
num = int(num) | |||
val=int((num / 22.5) + .5) | |||
arr=["N","NNE","NE","ENE","E","ESE", "SE", "SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"] | |||
return arr[(val % 16)] | |||
if __name__ == "__main__": | |||
main() |
@@ -0,0 +1,22 @@ | |||
#!/bin/sh | |||
#echo "{\"version\":1}" | |||
#echo "[[] ," | |||
echo "{\"version\": 1}" | |||
echo "[" | |||
echo "[]" | |||
FG='#FFF' | |||
BG='#1c1c23' | |||
FONT='-*-ProFont-*-*-*-*-11-*-*-*-*-*-*-*' | |||
#conky -c ~/.i3/conkydzen | dzen2 -fg $FG -bg $BG -fn $FONT -x 500 -y 2 -w 3000 -ta r -xs 1 | |||
conky | dzen2 -x '500' -e '' -fg '#CCCACA' -bg '#242424' -ta r -fn '-*-dejavu sans-*-r-normal-*-13-120-*-*-*-*-iso8859-*' -y 0 -h 20 -p | |||
#conky -c ~/bin/conkyi3bar.sh | dzen2 -fg $FG -bg $BG -fn $FONT -x 500 -y 2 -w 3000 -ta r -xs 1 | |||
#conky -c ~/bin/conkyi3bar.sh | dzen2 -x '500' -e '' -fg '#CCCACA' -bg '#242424' -ta r -fn '-*-inconsolata-*-r-normal-*-12-120-*-*-*-*-iso8859-*' -y 0 -h 20 -p | |||
#conky -c /riddlebox/Downloads/conkytest | dzen2 -x '500' -e '' -fg '#CCCACA' -bg '#242424' -ta r -fn '-*-inconsolata-*-r-normal-*-12-120-*-*-*-*-iso8859-*' -y 0 -h 20 -p & | |||
exit 0 |
@@ -0,0 +1,51 @@ | |||
## Conky config i3; dkeg; 2013 ## | |||
out_to_x no | |||
own_window no | |||
out_to_console yes | |||
background no | |||
max_text_width 0 | |||
update_interval 3.0 | |||
total_run_times 0 | |||
short_units yes | |||
if_up_strictness address | |||
#use_spacer left | |||
override_utf8_locale no | |||
# set to 1 to disable averaging | |||
cpu_avg_samples 4 | |||
border_inner_margin 0 | |||
border_outer_margin 0 | |||
#old color | |||
#28c3c5 | |||
TEXT | |||
[ | |||
{"full_text":"mail","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${execpi 60 python ~/bin/gmail.py}","color":${if_match ${execpi 60 python ~/bin/gmail.py}>1}"\#cc5555"${else}"\#eeeeee"${endif},"separator":false,"separator_block_width":10 },\ | |||
\ | |||
{"full_text":"hd","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${fs_free /home}","color":"\#eeeeee","separator":false,"separator_block_width":10},\ | |||
\ | |||
{"full_text":"ram","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${memperc}%","color":${if_match ${memperc}>20}"\#cc5555"${else}"\#eeeeee"${endif},"separator":false,"separator_block_width":10 },\ | |||
\ | |||
{"full_text":"cpu","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${cpu}%","color":${if_match ${cpu}>10}"\#cc5555"${else}"\#eeeeee"${endif},"separator":false,"separator_block_width":10},\ | |||
\ | |||
{"full_text":"bat","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${memperc}","color":"\#eeeeee","separator":false,"separator_block_width":10},\ | |||
\ | |||
{"full_text":"net","color":"\#888888","separator":false,"separator_block_width":3},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${if_up wlan0}w ${wireless_bitrate wlan0}${else}${if_up eth0}e ${upspeedf eth0} up ${downspeedf eth0} dwn${else}{null}${endif}${endif}","color":"\#eeeeee","separator":false,"separator_block_width":10},\ | |||
{"full_text":"ยป","color":"\#FFFFFF","separator":false,"separator_block_width":10},\ | |||
\ | |||
{"full_text":"${time %a %d.%m}","color":"\#eeeeee","separator":false,"separator_block_width":10},\ | |||
{"full_text":"${time %H:%M} ","color":"\#eeeeee"}\ | |||
], |
@@ -0,0 +1,28 @@ | |||
#!/bin/sh | |||
# | |||
# z3bra - (c) wtfpl 2014 | |||
usage () { | |||
cat <<EOF | |||
usage: $(basename $0) [-hp] | |||
-h : print help | |||
-p : percentage of cpu used (default) | |||
-n : number of running processes | |||
EOF | |||
} | |||
cpuperc () { | |||
LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |sed -n '1h;$!H;$g;s/\n/ +/gp'` | |||
echo "`echo $LINE | bc`%" | |||
} | |||
cpunumb() { | |||
ls /proc | grep -oE '^[0-9]*$' | wc -w | |||
} | |||
case $1 in | |||
-h) usage;; | |||
-n) cpunumb;; | |||
*) cpuperc;; | |||
esac |
@@ -0,0 +1,135 @@ | |||
/* cpubar - ascii cpu usage bar, best used with dzen | |||
* | |||
* Copyright (C) 2007 by Robert Manea, <rob dot manea at gmail dot com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* (at your option) any later version | |||
* | |||
* This program is distributed in the hope that it will be useful, but | |||
* WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |||
* USA | |||
* | |||
* What you look for is \r it is Carriage Return. | |||
* Makes the carriage go back to the beginning of the line. | |||
* Or use \n as it will go down one line. | |||
* | |||
* Compile it with: | |||
* gcc cpubar.c -o cpubar | |||
* | |||
*/ | |||
#include<stdio.h> | |||
#include<stdlib.h> | |||
#include<unistd.h> | |||
#include<string.h> | |||
void pbar (double, int, char); | |||
struct cpu_info { | |||
unsigned long long user; | |||
unsigned long long system; | |||
unsigned long long idle; | |||
unsigned long long iowait; | |||
} ncpu, ocpu; | |||
void | |||
pbar(double perc, int maxc, char sym) { | |||
int i, rp; | |||
double l; | |||
l = perc * ((double)maxc / 100); | |||
if( (int)(perc + 0.5) >= (int)perc) | |||
rp = (int)(perc + 0.5); | |||
else | |||
rp = (int)perc; | |||
printf("CPU: %3d%% [", rp); | |||
for(i=0; i < (int)l; i++) | |||
printf("%c", sym); | |||
for(; i < maxc; i++) | |||
printf(" "); | |||
printf("]\r"); | |||
fflush(stdout); | |||
} | |||
int | |||
main(int argc, char *argv[]) | |||
{ | |||
int i; | |||
double total; | |||
struct cpu_info mcpu; | |||
FILE *statfp; | |||
char buf[256]; | |||
/* defaults */ | |||
int maxchars=25; | |||
int ival=1; | |||
char psym='='; | |||
for(i=1; i < argc; i++) { | |||
if(!strncmp(argv[i], "-c", 3)) { | |||
if(++i < argc) | |||
maxchars = atoi(argv[i]); | |||
} | |||
else if(!strncmp(argv[i], "-s", 3)) { | |||
if(++i < argc) | |||
psym = argv[i][0]; | |||
} | |||
else if(!strncmp(argv[i], "-i", 3)) { | |||
if(++i < argc) | |||
ival = atoi(argv[i]); | |||
} | |||
else { | |||
printf("usage: cpubar [-c <charcount>] [-s <symbol>] [-i <interval>]\n"); | |||
return EXIT_FAILURE; | |||
} | |||
} | |||
if(!(statfp = fopen("/proc/stat", "r"))) { | |||
printf("cpubar: error opening '/proc/stat'\n"); | |||
return EXIT_FAILURE; | |||
} | |||
while(1) { | |||
rewind(statfp); | |||
while(fgets(buf, sizeof buf, statfp)) { | |||
if(!strncmp(buf, "cpu ", 4)) { | |||
unsigned long long unice; | |||
double myload; | |||
/* linux >= 2.6 */ | |||
if((sscanf(buf, "cpu %llu %llu %llu %llu %llu", | |||
&ncpu.user, &unice, &ncpu.system, &ncpu.idle, &ncpu.iowait)) < 5) { | |||
printf("cpubar: wrong field count in /proc/stat\n"); | |||
return EXIT_FAILURE; | |||
} | |||
ncpu.user += unice; | |||
mcpu.user = ncpu.user - ocpu.user; | |||
mcpu.system = ncpu.system - ocpu.system; | |||
mcpu.idle = ncpu.idle - ocpu.idle; | |||
mcpu.iowait = ncpu.iowait - ocpu.iowait; | |||
total = (mcpu.user + mcpu.system + mcpu.idle + mcpu.iowait) / 100.0; | |||
myload = (mcpu.user + mcpu.system + mcpu.iowait) / total; | |||
pbar(myload, maxchars, psym); | |||
ocpu = ncpu; | |||
} | |||
} | |||
sleep(ival); | |||
} | |||
return EXIT_SUCCESS; | |||
} |
@@ -0,0 +1,198 @@ | |||
/* dbar - ascii percentage meter | |||
* | |||
* Copyright (C) 2007 by Robert Manea, <rob dot manea at gmail dot com> | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* (at your option) any later version | |||
* | |||
* This program is distributed in the hope that it will be useful, but | |||
* WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |||
* USA | |||
* | |||
* Compile with: | |||
* gcc dbar.c -o dbar | |||
* | |||
*/ | |||
/* | |||
dbar lets you define static 0% and 100% marks or you can define these | |||
marks dynamically at runtime. Static and dynamic marks can be mixed, | |||
in this case the value specified at runtime will have a higher priority. | |||
You can specify ranges of numbers, negative, positive or ranges with a | |||
negative min value and positive max value. | |||
All numbers are treated as double precision floating point, i.e. the | |||
input is NOT limited to integers. | |||
Options: | |||
-max : Value to be considered 100% (default: 100) | |||
-min : Value to be considered 0% (default: 0 ) | |||
-w : Number of charcaters to be | |||
considered 100% in the meter (default: 25 ) | |||
-s : Symbol represeting the | |||
percentage value in the meter (default: = ) | |||
-l : label to be prepended to | |||
the bar (default: '' ) | |||
-nonl: no new line, don't put | |||
'\n' at the end of the bar (default: do print '\n') | |||
Usage examples: | |||
1) Static 100% mark or single value input: | |||
echo 25 | dbar -m 100 -l Sometext | |||
Output: Sometext 25% [====== ] | |||
2) If your 100% mark changes dynamically or 2-values input: | |||
echo "50 150" | dbar | |||
^ ^ | |||
| |__ max. value | |||
| | |||
|__ value to display | |||
Output: 33% [======== ] | |||
3) If your value range is not between [0, maxval] or 3-values input: | |||
echo "50 -25 150" | dbar | |||
^ ^ ^ | |||
| | |__ max. value 100% mark | |||
| | | |||
| |_____ min. value 0% mark | |||
| | |||
|________ value to display | |||
Output: 43% [=========== ] | |||
4) Multiple runs: | |||
for i in 2 20 50 75 80; do echo $i; sleep 1; done | dbar | dzen2 | |||
Output: Find out yourself. | |||
*/ | |||
#include<stdio.h> | |||
#include<stdlib.h> | |||
#include<unistd.h> | |||
#include<string.h> | |||
#define MAXLEN 512 | |||
static void pbar (const char*, double, int, char, int); | |||
static void | |||
pbar(const char* label, double perc, int maxc, char sym, int pnl) { | |||
int i, rp; | |||
double l; | |||
l = perc * ((double)maxc / 100); | |||
if((int)(l + 0.5) >= (int)l) | |||
l = l + 0.5; | |||
if((int)(perc + 0.5) >= (int)perc) | |||
rp = (int)(perc + 0.5); | |||
else | |||
rp = (int)perc; | |||
if(label) | |||
printf("%s %3d%% [", label, rp); | |||
else | |||
printf("%3d%% [", rp); | |||
for(i=0; i < (int)l; i++) | |||
if(i == maxc) { | |||
putchar('>'); | |||
break; | |||
} else | |||
putchar(sym); | |||
for(; i < maxc; i++) | |||
putchar(' '); | |||
printf("]%s", pnl ? "\n" : ""); | |||
fflush(stdout); | |||
} | |||
int | |||
main(int argc, char *argv[]) | |||
{ | |||
int i, nv; | |||
double val; | |||
char aval[MAXLEN], *endptr; | |||
/* defaults */ | |||
int maxchars = 25; | |||
double minval = 0; | |||
double maxval = 100.0; | |||
char psym = '='; | |||
int print_nl = 1; | |||
const char *label = NULL; | |||
for(i=1; i < argc; i++) { | |||
if(!strncmp(argv[i], "-w", 3)) { | |||
if(++i < argc) | |||
maxchars = atoi(argv[i]); | |||
} | |||
else if(!strncmp(argv[i], "-s", 3)) { | |||
if(++i < argc) | |||
psym = argv[i][0]; | |||
} | |||
else if(!strncmp(argv[i], "-max", 5)) { | |||
if(++i < argc) { | |||
maxval = strtod(argv[i], &endptr); | |||
if(*endptr) { | |||
fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); | |||
return EXIT_FAILURE; | |||
} | |||
} | |||
} | |||
else if(!strncmp(argv[i], "-min", 5)) { | |||
if(++i < argc) { | |||
minval = strtod(argv[i], &endptr); | |||
if(*endptr) { | |||
fprintf(stderr, "dbar: '%s' incorrect number format", argv[i]); | |||
return EXIT_FAILURE; | |||
} | |||
} | |||
} | |||
else if(!strncmp(argv[i], "-l", 3)) { | |||
if(++i < argc) | |||
label = argv[i]; | |||
} | |||
else if(!strncmp(argv[i], "-nonl", 6)) { | |||
print_nl = 0; | |||
} | |||
else { | |||
fprintf(stderr, "usage: dbar [-w <characters>] [-s <symbol>] [-min <minvalue>] [-max <maxvalue>] [-l <string>] [-nonl]\n"); | |||
return EXIT_FAILURE; | |||
} | |||
} | |||
while(fgets(aval, MAXLEN, stdin)) { | |||
nv = sscanf(aval, "%lf %lf %lf", &val, &minval, &maxval); | |||
if(nv == 2) { | |||
maxval = minval; | |||
minval = 0; | |||
} | |||
pbar(label, (100*(val-minval))/(maxval-minval), maxchars, psym, print_nl); | |||
} | |||
return EXIT_SUCCESS; | |||
} | |||
@@ -0,0 +1,6 @@ | |||
#!/bin/bash | |||
# Set maildirs | |||
maildirs="$HOME/Maildir/*/INBOX/new/" | |||
find $maildirs -type f | wc -l | |||
exit 0 |
@@ -0,0 +1,46 @@ | |||
#!/bin/bash | |||
# | |||
# ANSI color scheme script by pfh | |||
# | |||
# Initializing mod by lolilolicon from Archlinux | |||
# | |||
f=3 b=4 | |||
for j in f b; do | |||
for i in {0..7}; do | |||
printf -v $j$i %b "\e[${!j}${i}m" | |||
done | |||
done | |||
bld=$'\e[1m' | |||
rst=$'\e[0m' | |||
inv=$'\e[7m' | |||
cat << EOF | |||
${f1} โ-----${bld}โ ${rst}${f2} โ-----${bld}โ${rst} ${f3} โ-----${bld}โ${rst} ${f4} โ-----${bld}โ${rst} ${f5} โ-----${bld}โ${rst} ${f6} โ-----${bld}โ${rst} | |||
${f1} โ---${bld}โ${rst} ${f2} โ---${bld}โ${rst} ${f3} โ---${bld}โ${rst} ${f4} โ---${bld}โ${rst} ${f5} โ---${bld}โ${rst} ${f6} โ---${bld}โ${rst} | |||
${f1} โ-${bld}โ${rst} ${f2} โ-${bld}โ${rst} ${f3} โ-${bld}โ${rst} ${f4} โ-${bld}โ${rst} ${f5} โ-${bld}โ${rst} ${f6} โ-${bld}โ${rst} | |||
${f1} โ${rst} ${f2} โ${rst} ${f3} โ${rst} ${f4} โ${rst} ${f5} โ${rst} ${f6} โ${rst} | |||
${f1}${bld} โ-${rst}${f1}โ${rst} ${f2}${bld} โ_${rst}${f2}โ${rst} ${f3}${bld} โ-${rst}${f3}โ${rst} ${f4}${bld} โ-${rst}${f4}โ${rst} ${f5}${bld} โ-${rst}${f5}โ${rst} ${f6}${bld} โ-${rst}${f6}โ${rst} | |||
${f1}${bld} โ---${rst}${f1}โ${rst} ${f2}${bld} โ---${rst}${f2}โ${rst} ${f3}${bld} โ---${rst}${f3}โ${rst} ${f4}${bld} โ---${rst}${f4}โ${rst} ${f5}${bld} โ---${rst}${f5}โ${rst} ${f6}${bld} โ---${rst}${f6}โ${rst} | |||
${f1}${bld} โ-----${rst}${f1}โ${rst} ${f2}${bld} โ-----${rst}${f2}โ${rst} ${f3}${bld} โ-----${rst}${f3}โ${rst} ${f4}${bld} โ-----${rst}${f4}โ${rst} ${f5}${bld} โ-----${rst}${f5}โ${rst} ${f6}${bld} โ-----${rst}${f6}โ${rst} | |||
${f1}${bld} โ---${rst}${f1}โ${rst} ${f2}${bld} โ---${rst}${f2}โ${rst} ${f3}${bld} โ---${rst}${f3}โ${rst} ${f4}${bld} โ---${rst}${f4}โ${rst} ${f5}${bld} โ---${rst}${f5}โ${rst} ${f6}${bld} โ---${rst}${f6}โ${rst} | |||
${f1}${bld} โ-${rst}${f1}โ${rst} ${f2}${bld} โ-${rst}${f2}โ${rst} ${f3}${bld} โ-${rst}${f3}โ${rst} ${f4}${bld} โ-${rst}${f4}โ${rst} ${f5}${bld} โ-${rst}${f5}โ${rst} ${f6}${bld} โ-${rst}${f6}โ${rst} | |||
${f1}${bld} โ${rst} ${f2}${bld} โ${rst} ${f3}${bld}โ${rst} ${f4}${bld} โ${rst} ${f5}${bld} โ${rst} ${f6}${bld} โ${rst} | |||
${f1} โ-${bld}โ${rst} ${f2} โ-${bld}โ${rst} ${f3} โ-${bld}โ${rst} ${f4} โ-${bld}โ${rst} ${f5} โ-${bld}โ${rst} ${f6} โ-${bld}โ${rst} | |||
${f1} โ---${bld}โ${rst} ${f2} โ---${bld}โ${rst} ${f3} โ---${bld}โ${rst} ${f4} โ---${bld}โ${rst} ${f5} โ---${bld}โ${rst} ${f6} โ---${bld}โ${rst} | |||
${f1} โ-----${bld}โ ${rst}${f2} โ-----${bld}โ${rst} ${f3} โ-----${bld}โ${rst} ${f4} โ-----${bld}โ${rst} ${f5} โ-----${bld}โ${rst} ${f6} โ-----${bld}โ${rst} | |||
${f1} โ---${bld}โ${rst} ${f2} โ---${bld}โ${rst} ${f3} โ---${bld}โ${rst} ${f4} โ---${bld}โ${rst} ${f5} โ---${bld}โ${rst} ${f6} โ---${bld}โ${rst} | |||
${f1} โ-${bld}โ${rst} ${f2} โ-${bld}โ${rst} ${f3} โ-${bld}โ${rst} ${f4} โ-${bld}โ${rst} ${f5} โ-${bld}โ${rst} ${f6} โ-${bld}โ${rst} | |||
${f1} โ${rst} ${f2}โ${rst} ${f3} โ${rst} ${f4} โ${rst} ${f5} โ${rst} ${f6} โ${rst} | |||
${f1}${bld} โ-${rst}${f1}โ${rst} ${f2}${bld} โ_${rst}${f2}โ${rst} ${f3}${bld} โ-${rst}${f3}โ${rst} ${f4}${bld} โ-${rst}${f4}โ${rst} ${f5}${bld} โ-${rst}${f5}โ${rst} ${f6}${bld} โ-${rst}${f6}โ${rst} | |||
${f1}${bld} โ---${rst}${f1}โ${rst} ${f2}${bld} โ---${rst}${f2}โ${rst} ${f3}${bld} โ---${rst}${f3}โ${rst} ${f4}${bld} โ---${rst}${f4}โ${rst} ${f5}${bld} โ---${rst}${f5}โ${rst} ${f6}${bld} โ---${rst}${f6}โ${rst} | |||
${f1}${bld} โ-----${rst}${f1}โ${rst} ${f2}${bld} โ-----${rst}${f2}โ${rst} ${f3}${bld} โ-----${rst}${f3}โ${rst} ${f4}${bld} โ-----${rst}${f4}โ${rst} ${f5}${bld} โ-----${rst}${f5}โ${rst} ${f6}${bld} โ-----${rst}${f6}โ${rst} | |||
${f1}${bld} โ---${rst}${f1}โ${rst} ${f2}${bld} โ---${rst}${f2}โ${rst} ${f3}${bld} โ---${rst}${f3}โ${rst} ${f4}${bld} โ---${rst}${f4}โ${rst} ${f5}${bld} โ---${rst}${f5}โ${rst} ${f6}${bld} โ---${rst}${f6}โ${rst} | |||
${f1}${bld} โ-${rst}${f1}โ${rst} ${f2}${bld} โ-${rst}${f2}โ${rst} ${f3}${bld} โ-${rst}${f3}โ${rst} ${f4}${bld} โ-${rst}${f4}โ${rst} ${f5}${bld} โ-${rst}${f5}โ${rst} ${f6}${bld} โ-${rst}${f6}โ${rst} | |||
${f1}${bld} โ${rst} ${f2}${bld} โ${rst} ${f3}${bld} โ${rst} ${f4}${bld} โ${rst} ${f5}${bld} โ${rst} ${f6}${bld} โ${rst} | |||
${f1} โ-${bld}โ${rst} ${f2} โ-${bld}โ${rst} ${f3} โ-${bld}โ${rst} ${f4} โ-${bld}โ${rst} ${f5} โ-${bld}โ${rst} ${f6} โ-${bld}โ${rst} | |||
${f1} โ---${bld}โ${rst} ${f2} โ---${bld}โ${rst} ${f3} โ---${bld}โ${rst} ${f4} โ---${bld}โ${rst} ${f5} โ---${bld}โ${rst} ${f6} โ---${bld}โ${rst} | |||
${f1} โ-----${bld}โ ${rst}${f2} โ-----${bld}โ${rst} ${f3} โ-----${bld}โ${rst} ${f4} โ-----${bld}โ${rst} ${f5} โ-----${bld}โ${rst} ${f6} โ-----${bld}โ${rst} | |||
EOF |
@@ -0,0 +1,22 @@ | |||
#!/bin/bash | |||
STATUS=$(dropbox status) | |||
if [ "$STATUS" == "Dropbox isn't running!" ]; then | |||
START=$(dropbox start) | |||
fi | |||
COUNT_DONE=1 | |||
while true | |||
do | |||
STATUS=$(dropbox status) | |||
if [ "$STATUS" == "Up to date" ]; then | |||
COUNT_DONE=`expr $COUNT_DONE + 1` | |||
if [ $COUNT_DONE -gt 10 ] | |||
then | |||
STOP=$(dropbox stop) | |||
break; | |||
fi | |||
fi | |||
done | |||
exit 0 |
@@ -0,0 +1,15 @@ | |||
#!/bin/bash | |||
# | |||
# pop-up calendar for dzen | |||
# (c) 2007, by Robert Maneaq | |||
# mods 2012, by arpinux | |||
TODAY=$(expr `date +'%d'` + 0) | |||
MONTH=`date +'%m'` | |||
YEAR=`date +'%Y'` | |||
(echo '^fg(green)'`date +'%A, %H:%M'`; \ | |||
echo ' day:'`date +'%j'`' - week:'`date +'%U'`; \ | |||
echo; cal | sed -re "s/(^|[ ])($TODAY)($|[ ])/\1^fg(red)\2^fg()^bg()\3/"; \ | |||
[ $MONTH -eq 12 ] && YEAR=`expr $YEAR + 1`; cal `expr \( $MONTH + 1 \) % 12` $YEAR; \ | |||
sleep 60) | dzen2 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-iso10646-*' -x 760 -y 20 -h 14 -w 125 -l 18 -e 'onstart=uncollapse;button1=togglecollapse;button3=exit' |
@@ -0,0 +1,6 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - open mutt in a new terminal. | |||
# | |||
### | |||
urxvtc -title filemanager -n filemanager -e ranger |
@@ -0,0 +1,136 @@ | |||
#!/usr/bin/python2 | |||
# | |||
# pbrisbin 2014 - access Google Contacts for mutt's query_command. | |||
# | |||
# Originally script by Jim Karsten <jimkarsten@gmail.com>. Modified by Pat | |||
# Brisbin <pbrisbin@gmail.com> to do a lot less and handle arguments | |||
# differently. | |||
# | |||
# Usage: | |||
# | |||
# gcontacts <account> <password-command> <keyword>, ... | |||
# | |||
# Example Mutt Usage: | |||
# | |||
# set query_command = "echo; gcontacts foo@gmail.com 'echo SuperSecret' '%s'" | |||
# | |||
### | |||
import re | |||
import sys | |||
import subprocess | |||
import gdata.contacts | |||
import gdata.contacts.service | |||
P_REL = re.compile(r'^http://schemas.google.com/g/2005#(.*)$') | |||
class Contacts(): | |||
def __init__(self, gd_client): | |||
self.gd_client = gd_client | |||
self.query = gdata.contacts.service.ContactsQuery() | |||
self.query.max_results = 999999 | |||
self.feed = gd_client.GetContactsFeed(self.query.ToUri()) | |||
self.contacts = [] | |||
self.filtered_contacts = [] | |||
def get(self): | |||
for entry in self.feed.entry: | |||
contact = Contact(entry) | |||
self.contacts.append(contact) | |||
def filter(self, keyword): | |||
for contact in self.contacts: | |||
if contact.is_match(keyword=keyword): | |||
self.filtered_contacts.append(contact) | |||
def print_contacts(self): | |||
printable_item = [] | |||
for contact in self.filtered_contacts: | |||
emails = contact.emails | |||
if not emails: | |||
emails = [{'address': 'n/a', 'rel':'n/a'}] | |||
for email_addr in emails: | |||
sortable_name = contact.name or contact.organization or '' | |||
c = {'email': email_addr['address'], 'name': sortable_name, | |||
'other_info': email_addr['rel'], 'contact': contact} | |||
printable_item.append(c) | |||
cmp_fn = lambda x, y: cmp(x['name'].lower(), y['name'].lower()) | |||
for count, printable in enumerate(sorted(printable_item, cmp=cmp_fn)): | |||
contact = printable['contact'] | |||
print "{email}\t{name}\t{info}".format( | |||
email=printable['email'], name=contact.fullname, | |||
info=printable['other_info']) | |||
class Contact(): | |||
def __init__(self, entry): | |||
self.entry = entry | |||
self.name = self.entry.title.text or None | |||
self.organization = None | |||
if self.entry.organization and self.entry.organization.org_name: | |||
self.organization = self.entry.organization.org_name.text or None | |||
self.parse_emails() | |||
self.set_fullname() | |||
def is_match(self, keyword): | |||
match = False | |||
for email_addr in self.emails: | |||
if re.search(keyword, email_addr['address'], re.IGNORECASE): | |||
match = True | |||
if self.name: | |||
if re.search(keyword, self.name, re.IGNORECASE): | |||
match = True | |||
if self.organization: | |||
if re.search(keyword, self.organization, re.IGNORECASE): | |||
match = True | |||
return match | |||
def parse_emails(self): | |||
self.emails = [] | |||
for email_addr in self.entry.email: | |||
rel = 'other' | |||
if email_addr.rel: | |||
match = P_REL.match(email_addr.rel) | |||
if match: | |||
rel = match.group(1) | |||
self.emails.append({'address': email_addr.address, 'rel': rel}) | |||
def set_fullname(self): | |||
if self.name and self.organization: | |||
self.fullname = "{name} ({org})".format(name=self.name, | |||
org=self.organization) | |||
elif self.organization: | |||
self.fullname = "{org}".format(org=self.organization) | |||
elif self.name: | |||
self.fullname = "{name}".format(name=self.name) | |||
else: | |||
self.fullname = 'n/a' | |||
if __name__ == '__main__': | |||
if len(sys.argv) < 4: | |||
print >> sys.stderr, "usage: gcontacts <email> <password-command> <keyword>, ..." | |||
quit(64) | |||
email, command = sys.argv[1:3] | |||
keyword = ' '.join(sys.argv[3:]) | |||
password = subprocess.check_output(command.split(' ')) | |||
gd_client = gdata.contacts.service.ContactsService() | |||
gd_client.email = email | |||
gd_client.password = password | |||
gd_client.source = 'dm-contacts-1' | |||
gd_client.ProgrammaticLogin() | |||
contact_set = Contacts(gd_client) | |||
contact_set.get() | |||
contact_set.filter(keyword) | |||
contact_set.print_contacts() |
@@ -0,0 +1,19 @@ | |||
#!/usr/bin/env bash | |||
# | |||
# pbrisbin 2013 - generates and outputs a script which, when run, would | |||
# install all packages currently installed on the system. This, combined | |||
# with a restoration of /etc and /home, should constitute an acceptable | |||
# system recovery. | |||
# | |||
### | |||
cat << EOF | |||
#!/usr/bin/env sh | |||
echo '$(pacman -Qqe | grep -v "$(pacman -Qqm)")' | sudo pacman -Syu --needed - | |||
curl 'https://aur.archlinux.org/packages/au/aurget/aurget.tar.gz' | tar fxz - \\ | |||
&& (cd ./aurget && makepkg -i) && rm -r ./aurget | |||
echo '$(pacman -Qqem)' | xargs /bin/aurget -S | |||
EOF |
@@ -0,0 +1,53 @@ | |||
#!/usr/bin/env python | |||
# | |||
# pbrisbin 2013 - retreive passwords by email address from ~/.netrc. | |||
# Unlike typical netrc usage, this allows you to store credentials under | |||
# the domain of the email address, rather than the hostname of the IMAP | |||
# server (which may be the same for multiple sets of credentials). | |||
# | |||
# Example ~/.netrc: | |||
# | |||
# machine gmail.com | |||
# login pbrisbin@gmail.com | |||
# password supersecret | |||
# | |||
# machine thoughtbot.com | |||
# login pat@thoughtbot.com | |||
# password othersecret | |||
# | |||
# Usage: | |||
# | |||
# $ getnetrc pbrisbin@gmail.com | |||
# supersecret | |||
# | |||
# $ getnetrc pat@thoughtbot.com | |||
# othersecret | |||
# | |||
### | |||
import netrc | |||
import sys | |||
def get_password(email_address): | |||
try: | |||
net_rc = netrc.netrc() | |||
except IOError: | |||
return None | |||
try: | |||
domain = email_address.split('@', 2)[1] | |||
except: | |||
return None | |||
for host in net_rc.hosts.keys(): | |||
if host == domain: | |||
login, _, password = net_rc.authenticators(host) | |||
if login == email_address: | |||
return password | |||
return None | |||
if __name__ == '__main__': | |||
pw = get_password(sys.argv[1]) | |||
if pw: print(pw) |
@@ -0,0 +1,12 @@ | |||
#!/bin/sh | |||
# | |||
# pbrisbin 2014 - details: | |||
# | |||
# - http://blog.adamspiers.org/2014/10/05/managing-your-github-notifications-inbox-with-mutt/ | |||
# - https://github.com/aspiers/mutt.pub/blob/master/bin/read-github-notification | |||
# | |||
### | |||
beacon_re='https://github\.com/notifications/beacon/.*\.gif' | |||
beacon_url="$(tr -d '\n' | grep -o "$beacon_re")" | |||
[ -n "$beacon_url" ] && curl --silent "$beacon_url" >/dev/null & |
@@ -0,0 +1,22 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2013 - record screen area as a gif. Requires ffcast (for | |||
# xrectsel) and byzanz (for the actual recording). | |||
# | |||
### | |||
set -e | |||
out="${1:-out.gif}" | |||
if [ -e "$out" ]; then | |||
printf "%s exists. removing...\n" "$out" >&2 | |||
rm "$out" | |||
fi | |||
tmp=temp.gif | |||
geometry_args="$(xrectsel "--x=%x --y=%y --width=%w --height=%h")" | |||
trap "convert -loop 0 '$tmp' '$out' && rm '$tmp'" EXIT | |||
printf "Recording %s. Press ^C when done.\n" ./"$out" | |||
byzanz-record -d 3600 $geometry_args "$tmp" # word-splitting intended |
@@ -0,0 +1,45 @@ | |||
#!/bin/bash | |||
if [[ ! -f "$1" ]]; then | |||
echo "Usage: ./glyphs [font.bdf]" | |||
exit 1 | |||
fi | |||
fast_chr() { | |||
local __octal | |||
local __char | |||
printf -v __octal '%03o' "$1" | |||
printf -v __char \\$__octal | |||
REPLY="$__char" | |||
} | |||
unichr() { | |||
local c=$1 # ordinal of char | |||
local l=0 # byte ctr | |||
local o=63 # ceiling | |||
local p=128 # accum. bits | |||
local s='' # output string | |||
if (( c < 0x80 )); then | |||
fast_chr "$c" | |||
printf '%s' "$REPLY" | |||
return | |||
fi | |||
while (( c > o )); do | |||
fast_chr $(( t = 0x80 | c & 0x3f )) | |||
s="$REPLY$s" | |||
(( c >>= 6, l++, p += o+1, o>>=1 )) | |||
done | |||
fast_chr $((t = p | c)) | |||
printf '%s%s' "$REPLY" "$s" | |||
} | |||
## test harness | |||
for i in \ | |||
$(grep -E '^ENCODING' "$1" | | |||
sed -e 's/ENCODING//' | | |||
tr -d '\n'); do | |||
unichr "$i" | |||
done |
@@ -0,0 +1,6 @@ | |||
#!/bin/bash | |||
# Set maildirs | |||
maildirs="$HOME/Maildir/gmail/INBOX/new/" | |||
find $maildirs -type f | wc -l | |||
exit 0 |
@@ -0,0 +1,22 @@ | |||
#!/usr/bin/env sh | |||
# | |||
# pbrisbin 2014 - called directly from /etc/acpi/handler.sh | |||
# | |||
### | |||
bin="$(dirname "$0")" | |||
case "$1" in | |||
battery) "$bin"/runx "$bin"/osb ;; | |||
button/screenlock) "$bin"/runx slock ;; | |||
video/brightnessdown) "$bin"/bl d ;; | |||
video/brightnessup) "$bin"/bl u ;; | |||
# Mic mute | |||
button/f20) amixer sset Capture toggle ;; | |||
# Ignored events | |||
ac_adapter|*/volume*|*/mute) : ;; | |||
ibm/hotkey|thermal_zone) : ;; | |||
*) "$bin"/runx notify-send -i 'emblem-important' 'ACPI action' "$*" ;; | |||
esac |
@@ -0,0 +1,19 @@ | |||
#!/usr/bin/env bash | |||
# | |||
# pbrisbin 2013 - wrap handbrake to handle commonly needed scenarios. | |||
# | |||
### | |||
if (( $# < 2 )); then | |||
printf "usage: hb [rip <name>|convert <file>] [options]\n" >&2 | |||
exit 1 | |||
fi | |||
case "$1" in | |||
rip) src='/dev/sr0' | |||
dst="$2.m4v" ;; | |||
convert) src="$2" | |||
dst="$(basename "${src%.*}").m4v" ;; | |||
esac | |||
shift 2 | |||
HandBrakeCLI -Z "High Profile" "$@" -i "$src" -o "/mnt/media/Movies/$dst" |
@@ -0,0 +1,24 @@ | |||
#!/bin/sh | |||
# | |||
# pbrisbin 2014 - smart cabal sdist/upload wrapper. Reads credentials from | |||
# ~/.netrc so they don't have to be in ~/.cabal/config or entered each time. | |||
# | |||
### | |||
name="$(sed '/^[Nn]ame: *\([^ ]*\)/!d; s//\1/' *.cabal)" | |||
version="$(sed '/^[Vv]ersion: *\([^ ]*\)/!d; s//\1/' *.cabal)" | |||
credentials() { | |||
python <<EOF | |||
import netrc | |||
(u, _, p) = netrc.netrc().authenticators('hackage.haskell.org') | |||
print(u) | |||
print(p) | |||
EOF | |||
} | |||
cabal sdist && | |||
credentials | cabal upload "dist/$name-$version.tar.gz" && | |||
git tag -s -m v"$version" v"$version" && | |||
git push && git push --tags |
@@ -0,0 +1,20 @@ | |||
#!/bin/sh | |||
# | |||
# pbrisbin 2014 - browse local haskell documentation. | |||
# | |||
### | |||
if [ -z "$1" ]; then | |||
printf "usage: hdocs <identifier>\n" | |||
exit 64 | |||
fi | |||
package="$(printf "%s" "$*" | sed 's/[ .]/-/g; s/.*/\L&/g')" | |||
package_glob="*/$package-*/html/index.html" | |||
if [ -e "$PWD/.cabal-sandbox" ]; then | |||
docs_directory="$PWD/.cabal-sandbox/share/doc" | |||
else | |||
docs_directory="$HOME/.cabal/share/doc" | |||
fi | |||
find "$docs_directory" -wholename "$package_glob" -exec $BROWSER {} + |
@@ -0,0 +1,36 @@ | |||
#!/bin/sh | |||
# | |||
# pbrisbin 2014 - Generate a package skeleton using hi and a custom template, | |||
# then execute some additional setup. | |||
# | |||
### | |||
set -e | |||
info() { printf "==> %s\n" "$*"; } | |||
if [ $# -lt 2 ]; then | |||
printf "usage: hi-setup <module> <package> [hi options]\n" >&2 | |||
exit 64 | |||
fi | |||
module="$1" | |||
package="$2" | |||
shift 2 | |||
info "Generating package skeleton..." | |||
hi \ | |||
--module-name "$module" \ | |||
--package-name "$package" \ | |||
--author 'Pat Brisbin' \ | |||
--email 'pbrisbin@gmail.com' \ | |||
--repository gh:pbrisbin/hi-hspec "$@" | |||
rm ./README.md | |||
cd "$package" | |||
info "Initializing sandbox..." | |||
cabal sandbox init | |||
cabal install --enable-tests --dependencies-only -j4 | |||
info "Done." |
@@ -0,0 +1,35 @@ | |||
#!/usr/bin/env ruby | |||
# | |||
# pbrisbin 2013 - smartly update haskell ctags. | |||
# | |||
### | |||
class Ctags | |||
def initialize(tags) | |||
@tags = tags || 'tags' | |||
@module = find_module or exit 1 | |||
end | |||
def run | |||
system(%{ echo ":ctags #{@tags}" | cabal exec ghci -- -v0 '#{@module}' }) | |||
end | |||
private | |||
def find_module | |||
Dir.glob(module_glob, File::FNM_CASEFOLD).first | |||
end | |||
def module_glob | |||
File.join('**', "{#{module_name},main}.hs") | |||
end | |||
def module_name | |||
File.join(*project_directory.split('-')) | |||
end | |||
def project_directory | |||
File.basename(ENV['PWD']) | |||
end | |||
end | |||
Ctags.new(ARGV.first).run |
@@ -0,0 +1,595 @@ | |||
#!/usr/bin/env python | |||
""" icdiff.py | |||
Author: Jeff Kaufman, derived from difflib.HtmlDiff | |||
License: This code is usable under the same open terms as the rest of | |||
python. See: http://www.python.org/psf/license/ | |||
""" | |||
import os | |||
import sys | |||
import errno | |||
import difflib | |||
import optparse | |||
import re | |||
import filecmp | |||
import unicodedata | |||
color_codes = { | |||
"red": '\033[0;31m', | |||
"green": '\033[0;32m', | |||
"yellow": '\033[0;33m', | |||
"blue": '\033[0;34m', | |||
"magenta": '\033[0;35m', | |||
"cyan": '\033[0;36m', | |||
"none": '\033[m', | |||
"red_bold": '\033[1;31m', | |||
"green_bold": '\033[1;32m', | |||
"yellow_bold": '\033[1;33m', | |||
"blue_bold": '\033[1;34m', | |||
"magenta_bold": '\033[1;35m', | |||
"cyan_bold": '\033[1;36m', | |||
} | |||
class ConsoleDiff(object): | |||
"""Console colored side by side comparison with change highlights. | |||
Based on difflib.HtmlDiff | |||
This class can be used to create a text-mode table showing a side | |||
by side, line by line comparison of text with inter-line and | |||
intra-line change highlights in ansi color escape sequences as | |||
intra-line change highlights in ansi color escape sequences as | |||
read by xterm. The table can be generated in either full or | |||
contextual difference mode. | |||
To generate the table, call make_table. | |||
Usage is the almost the same as HtmlDiff except only make_table is | |||
implemented and the file can be invoked on the command line. | |||
Run:: | |||
python icdiff.py --help | |||
for command line usage information. | |||
""" | |||
def __init__(self, tabsize=8, wrapcolumn=None, linejunk=None, | |||
charjunk=difflib.IS_CHARACTER_JUNK, cols=80, | |||
line_numbers=False, | |||
show_all_spaces=False, | |||
highlight=False, | |||
no_bold=False): | |||
"""ConsoleDiff instance initializer | |||
Arguments: | |||
tabsize -- tab stop spacing, defaults to 8. | |||
wrapcolumn -- column number where lines are broken and wrapped, | |||
defaults to None where lines are not wrapped. | |||
linejunk, charjunk -- keyword arguments passed into ndiff() (used by | |||
ConsoleDiff() to generate the side by side differences). See | |||
ndiff() documentation for argument default values and descriptions. | |||
""" | |||
self._tabsize = tabsize | |||
self.line_numbers = line_numbers | |||
self.cols = cols | |||
self.show_all_spaces = show_all_spaces | |||
self.highlight = highlight | |||
self.no_bold = no_bold | |||
if wrapcolumn is None: | |||
if not line_numbers: | |||
wrapcolumn = self.cols // 2 - 2 | |||
else: | |||
wrapcolumn = self.cols // 2 - 10 | |||
self._wrapcolumn = wrapcolumn | |||
self._linejunk = linejunk | |||
self._charjunk = charjunk | |||
def _tab_newline_replace(self, fromlines, tolines): | |||
"""Returns from/to line lists with tabs expanded and newlines removed. | |||
Instead of tab characters being replaced by the number of spaces | |||
needed to fill in to the next tab stop, this function will fill | |||
the space with tab characters. This is done so that the difference | |||
algorithms can identify changes in a file when tabs are replaced by | |||
spaces and vice versa. At the end of the table generation, the tab | |||
characters will be replaced with a space. | |||
""" | |||
def expand_tabs(line): | |||
# hide real spaces | |||
line = line.replace(' ', '\0') | |||
# expand tabs into spaces | |||
line = line.expandtabs(self._tabsize) | |||
# relace spaces from expanded tabs back into tab characters | |||
# (we'll replace them with markup after we do differencing) | |||
line = line.replace(' ', '\t') | |||
return line.replace('\0', ' ').rstrip('\n') | |||
fromlines = [expand_tabs(line) for line in fromlines] | |||
tolines = [expand_tabs(line) for line in tolines] | |||
return fromlines, tolines | |||
def _display_len(self, s): | |||
# Handle wide characters like chinese. | |||
def width(c): | |||
if type(c) == type(u"") and unicodedata.east_asian_width(c) == 'W': | |||
return 2 | |||
return 1 | |||
return sum(width(c) for c in s) | |||
def _split_line(self, data_list, line_num, text): | |||
"""Builds list of text lines by splitting text lines at wrap point | |||
This function will determine if the input text line needs to be | |||
wrapped (split) into separate lines. If so, the first wrap point | |||
will be determined and the first line appended to the output | |||
text line list. This function is used recursively to handle | |||
the second part of the split line to further split it. | |||
""" | |||
# if blank line or context separator, just add it to the output list | |||
if not line_num: | |||
data_list.append((line_num, text)) | |||
return | |||
# if line text doesn't need wrapping, just add it to the output list | |||
size = self._display_len(text) | |||
if (size <= self._wrapcolumn) or ((size - (text.count('\0') * 3)) <= self._wrapcolumn): | |||
data_list.append((line_num, text)) | |||
return | |||
# scan text looking for the wrap point, keeping track if the wrap | |||
# point is inside markers | |||
i = 0 | |||
n = 0 | |||
mark = '' | |||
while n < self._wrapcolumn and i < size: | |||
if text[i] == '\0': | |||
i += 1 | |||
mark = text[i] | |||
i += 1 | |||
elif text[i] == '\1': | |||
i += 1 | |||
mark = '' | |||
else: | |||
i += 1 | |||
n += self._display_len(text[i]) | |||
# wrap point is inside text, break it up into separate lines | |||
line1 = text[:i] | |||
line2 = text[i:] | |||
# if wrap point is inside markers, place end marker at end of first | |||
# line and start marker at beginning of second line because each | |||
# line will have its own table tag markup around it. | |||
if mark: | |||
line1 = line1 + '\1' | |||
line2 = '\0' + mark + line2 | |||
# tack on first line onto the output list | |||
data_list.append((line_num, line1)) | |||
# use this routine again to wrap the remaining text | |||
self._split_line(data_list, '>', line2) | |||
def _line_wrapper(self, diffs): | |||
"""Returns iterator that splits (wraps) mdiff text lines""" | |||
# pull from/to data and flags from mdiff iterator | |||
for fromdata, todata, flag in diffs: | |||
# check for context separators and pass them through | |||
if flag is None: | |||
yield fromdata, todata, flag | |||
continue | |||
(fromline, fromtext), (toline, totext) = fromdata, todata | |||
# for each from/to line split it at the wrap column to form | |||
# list of text lines. | |||
fromlist, tolist = [], [] | |||
self._split_line(fromlist, fromline, fromtext) | |||
self._split_line(tolist, toline, totext) | |||
# yield from/to line in pairs inserting blank lines as | |||
# necessary when one side has more wrapped lines | |||
while fromlist or tolist: | |||
if fromlist: | |||
fromdata = fromlist.pop(0) | |||
else: | |||
fromdata = ('', ' ') | |||
if tolist: | |||
todata = tolist.pop(0) | |||
else: | |||
todata = ('', ' ') | |||
yield fromdata, todata, flag | |||
def _collect_lines(self, diffs): | |||
"""Collects mdiff output into separate lists | |||
Before storing the mdiff from/to data into a list, it is converted | |||
into a single line of text with console markup. | |||
""" | |||
fromlist, tolist, flaglist = [], [], [] | |||
# pull from/to data and flags from mdiff style iterator | |||
for fromdata, todata, flag in diffs: | |||
try: | |||
# store HTML markup of the lines into the lists | |||
fromlist.append(self._format_line(0, flag, *fromdata)) | |||
tolist.append(self._format_line(1, flag, *todata)) | |||
except TypeError: | |||
# exceptions occur for lines where context separators go | |||
fromlist.append(None) | |||
tolist.append(None) | |||
flaglist.append(flag) | |||
return fromlist, tolist, flaglist | |||
def _format_line(self, side, flag, linenum, text): | |||
"""Returns HTML markup of "from" / "to" text lines | |||
side -- 0 or 1 indicating "from" or "to" text | |||
flag -- indicates if difference on line | |||
linenum -- line number (used for line number column) | |||
text -- line text to be marked up | |||
""" | |||
try: | |||
lid = '%d' % linenum | |||
except TypeError: | |||
# handle blank lines where linenum is '>' or '' | |||
lid = '' | |||
text = text.rstrip() | |||
if not self.line_numbers: | |||
return text | |||
return '%s %s' % (self._rpad(lid, 8), text) | |||
def _real_len(self, s): | |||
l = 0 | |||
in_esc = False | |||
prev = ' ' | |||
for c in s.replace('\0+', "").replace('\0-', "").replace('\0^', "").replace('\1', "").replace('\t', ' '): | |||
if in_esc: | |||
if c == "m": | |||
in_esc = False | |||
else: | |||
if c == "[" and prev == "\033": | |||
in_esc = True | |||
l -= 1 # we counted prev when we shouldn't have | |||
else: | |||
l += self._display_len(c) | |||
prev = c | |||
#print("len '%s' is %d." % (s, l)) | |||
return l | |||
def _rpad(self, s, field_width): | |||
return self._pad(s, field_width) + s | |||
def _pad(self, s, field_width): | |||
return " " * (field_width - self._real_len(s)) | |||
def _lpad(self, s, field_width): | |||
target = s + self._pad(s, field_width) | |||
#if self._real_len(target) != field_width: | |||
# print("Warning: bad line %r is not of length %d" % (target, field_width)) | |||
return target | |||
def _convert_flags(self, fromlist, tolist, flaglist, context, numlines): | |||
"""Makes list of "next" links""" | |||
# all anchor names will be generated using the unique "to" prefix | |||
# process change flags, generating middle column of next anchors/links | |||
next_id = [''] * len(flaglist) | |||
next_href = [''] * len(flaglist) | |||
num_chg, in_change = 0, False | |||
last = 0 | |||
toprefix = '' | |||
for i, flag in enumerate(flaglist): | |||
if flag: | |||
if not in_change: | |||
in_change = True | |||
last = i | |||
# at the beginning of a change, drop an anchor a few lines | |||
# (the context lines) before the change for the previous | |||
# link | |||
i = max([0, i - numlines]) | |||
next_id[i] = ' id="difflib_chg_%s_%d"' % (toprefix, num_chg) | |||
# at the beginning of a change, drop a link to the next | |||
# change | |||
num_chg += 1 | |||
next_href[last] = '<a href="#difflib_chg_%s_%d">n</a>' % ( | |||
toprefix, num_chg) | |||
else: | |||
in_change = False | |||
# check for cases where there is no content to avoid exceptions | |||
if not flaglist: | |||
flaglist = [False] | |||
next_id = [''] | |||
next_href = [''] | |||
last = 0 | |||
if context: | |||
fromlist = ['No Differences Found'] | |||
tolist = fromlist | |||
else: | |||
fromlist = tolist = ['Empty File'] | |||
# if not a change on first line, drop a link | |||
if not flaglist[0]: | |||
next_href[0] = '<a href="#difflib_chg_%s_0">f</a>' % toprefix | |||
# redo the last link to link to the top | |||
next_href[last] = '<a href="#difflib_chg_%s_top">t</a>' % (toprefix) | |||
return fromlist, tolist, flaglist, next_href, next_id | |||
def make_table(self, fromlines, tolines, fromdesc='', todesc='', context=False, | |||
numlines=5): | |||
"""Returns table of side by side comparison with change highlights | |||
Arguments: | |||
fromlines -- list of "from" lines | |||
tolines -- list of "to" lines | |||
fromdesc -- "from" file column header string | |||
todesc -- "to" file column header string | |||
context -- set to True for contextual differences (defaults to False | |||