about summary refs log tree commit diff stats
path: root/js/inknswitch
diff options
context:
space:
mode:
Diffstat (limited to 'js/inknswitch')
0 files changed, 0 insertions, 0 deletions
>76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
## This is a mess, and needs tidying up. Hopefully it works on linux and (free)bsd, and can be sourced repeatedly without making PATH grow each time.

export LANG=en_GB.UTF-8

if [[ $- != *i* ]]; then
    # Non-interactive shell
    return
fi

export HOSTNAME=${HOSTNAME:-$(hostname -s)}
export HOST=$HOSTNAME
export USER=${USER:-$(whoami)}

#if [[ x$SCRIPT == x ]]
#then
#    script -q typescripts/script-`date +%Y%m%d%H%M%S``tty|tr / -`-$$
#    exit
#fi

## use _ for "internal" functions, and - for those intended to be used
## interactively

do_interesting_prompt() {
    prompt_choice=$1
    # col for colour, not column
    reset_col='\[\e[0m\]'

    sif_col='\[\e[0;35m\]'
    tyr_col='\[\e[0;36m\]'
    basil_col='\[\e[0;33m\]'
    gendros_col='\[\e[1;37m\]'

    host_col=$reset_col
    # TODO make all of these unique again
    [[ "x$HOST" == "xsif" ]] && host_col=$sif_col
    [[ "x$HOST" == "xtyr" ]] && host_col=$tyr_col
    [[ "x$HOST" == "xsagacity" ]] && host_col=$tyr_col
    [[ "x$HOST" == "xwolfman" ]] && host_col=$tyr_col
    [[ "x$HOST" == "xbasil" ]] && host_col=$basil_col
    [[ "x$HOST" == "xgendros" ]] && host_col=$gendros_col
    [[ "x$HOST" == "xCHESTER" ]] && host_col=$gendros_col
    [[ "x$HOST" == "xtriton" ]] && host_col=$gendros_col

    djm_col='\[\e[0;32m\]'
    wiz_col='\[\e[1;32m\]'
    deejayem_col='\[\e[1;32m\]'

    user_col=$reset_col
    [[ "x$USER" == "xdjm" ]] && user_col=$djm_col
    [[ "x$USER" == "xwizard" ]] && user_col=$wiz_col
    [[ "x$USER" == "xdeejayem" ]] && user_col=$deejayem_col
    [[ "x$USER" == "xdavidmo" ]] && user_col=$deejayem_col

    at_col='\[\e[0;37m\]'
    [[ -n "$SSH_CLIENT" ]] && at_col='\[\e[1;33m\]'

    time_col='\[\e[0;36m\]'
    # don't clash with host_col
    [[ "x$HOST" == "xtyr" ]] && time_col='\[\e[1;33m\]'
    [[ "x$HOST" == "xsagacity" ]] && time_col='\[\e[1;33m\]'
    [[ "x$HOST" == "xwolfman" ]] && time_col='\[\e[1;33m\]'

    dir_col='\[\e[1;34m\]'
    sb_col=$reset_col # Square brackets
    rb_col='\[\e[0;32m\]' # Round brackets
    cb_col='\[\e[0;32m\]' # Curly brackets
    cn_col='\[\e[0;35m\]' # Command numbers

    # Should vaguely correspond to user_col, but emphasise whether or not
    # we're using ssh (shutting down the wrong machine is not cool)
    prompt_col='\[\e[0;32m\]'
    [[ -n "$SSH_CLIENT" ]] && prompt_col='\[\e[1;32m\]'

    # col for colour, not column (still)
    # \h on first line as well as the second, because ^R obscures the second
    if [[ $prompt_choice -eq 1 ]]; then
        export PS1="$time_col\d \t $cb_col{$host_col\h$cb_col}\n$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col]$rb_col($cn_col\#:\j:"'$?'"$rb_col)$prompt_col\$$reset_col "
    elif [[ $prompt_choice -eq 2 ]]; then
        export PS1="$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col] $time_col\d \t $rb_col($cn_col\#:\j:"'$?'"$rb_col)\n$prompt_col\$$reset_col "
    elif [[ $prompt_choice -eq 3 ]]; then
        export PS1="$sb_col[$user_col\u$at_col@$host_col\h $dir_col\w$sb_col]$rb_col($cn_col\#:\j:"'$?'"$rb_col)$prompt_col\$$reset_col "
    else
        do_interesting_prompt 2
    fi
}

do_boring_prompt() {
    export PS1='\n\d \t {\h}\n[\u@\h \w](\#)\$ '
}

if ! [ -x "$(command -v gdircolors)" ]; then
    dircolors=`type -p gdircolors`
else
    dircolors=`type -p dircolors`
fi

if [ -z ${dircolors+x} ]; then
    if [[ -f ~/.dir_colors ]]; then
        eval `$dircolors -b ~/.dir_colors`
    else
        eval `$dircolors -b /etc/DIR_COLORS`
    fi
fi
#alias ls="ls --color=no"


## PATH - TODO reduce duplication with a function
if [[ -n "${PATH/*\/usr\/local\/mpi\/openmpi\/bin:*/}" ]] ; then
    export PATH="/usr/local/mpi/openmpi/bin:$PATH"
fi

if [[ -n "${PATH/*\/usr\/local\/texlive\/2009\/bin\/i386-freebsd8:*/}" ]] ; then
    export PATH="/usr/local/texlive/2009/bin/i386-freebsd8:$PATH"
fi

if [[ -n "${PATH/*$HOME\/local\/bin:*/}" ]] ; then
    export PATH="$HOME/local/bin:$PATH"
fi

if [[ -n "${PATH/*$HOME\/.local\/bin:*/}" ]] ; then
    export PATH="$HOME/.local/bin:$PATH"
fi

if [[ -n "${PATH/*$HOME\/games:*/}" ]] ; then
    export PATH="$HOME/games:$PATH"
fi

if [[ -n "${PATH/*$HOME\/bin:*/}" ]] ; then
    export PATH="$HOME/bin:$PATH"
fi

## MANPATH
if [[ -n "${MANPATH/*\/usr\/local\/mpi\/openmpi\/man:*/}" ]] ; then
    export PATH="/usr/local/mpi/openmpi/man:$PATH"
fi

if [[ -n "${MANPATH/*$HOME\/local\/man:*/}" ]] ; then
    export PATH="$HOME/local/man:$PATH"
fi

if [[ -n "${MANPATH/*$HOME\/local\/share\/man:*/}" ]] ; then
    export PATH="$HOME/local/share/man:$PATH"
fi


# Should test to see if we're capable of being interesting or not (TODO)
do_interesting_prompt 2
#do_boring_prompt

# Change the window title of X terminals 
case $TERM in
    xterm*|rxvt*|Eterm)
        PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
        ;;
#    screen) # don't want this with tmux...
#        PROMPT_COMMAND='echo -ne "\033k${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
#        ;;
esac

[ -f /etc/bash_completion ] && source /etc/bash_completion
#[ -f /usr/local/etc/bash_completion ] && source /usr/local/etc/bash_completion
[ -f /usr/local/share/bash-completion/bash_completion.sh ] && source /usr/local/share/bash-completion/bash_completion.sh
set -C

#export PATH=${HOME}/bin:${HOME}/local/bin:${HOME}/.local/bin:$PATH
#export PATH=/usr/local/games/:$PATH
#export MPD_HOST=redacted@localhost
#export MPD_PORT=6600
#export NNTPSERVER=news.btopenworld.com
#export NNTPSERVER=news.individual.net
#export NNTPSERVER=public.teranews.com
#export NNTPSERVER=reader.news4all.se
export HOSTNAME=`hostname -s`
export HOST=$HOSTNAME
[ -f /usr/bin/vim ] && export EDITOR=/usr/bin/vim
[ -f /usr/local/bin/vim ] && export EDITOR=/usr/local/bin/vim
export PAGER=/usr/bin/less
#export PERL5LIB="${HOME}/perl/share/perl/:${HOME}/lib/perl/:${HOME}/perl5/"
export MOZ_NO_PANGO=1

alias y=yes
alias s="sudo"
alias svi="sudo vim"
alias gvi=gvim
alias vi=vim
alias viclean="rm *~"
alias vidotclean="rm .*~"
alias vibinclean="rm ~/bin/*~"
alias trunc="colrm 80"

alias pc="${HOME}/bin/pocket-cli.py"

[ -x "$(command -v wget)" ] || alias fetch="wget"
[ -f /etc/debian_version ] && alias psearch="apt-cache search"

#alias esv='diatheke -b ESV -k'
alias esv="bible esv"
alias asv="diatheke -b ASV -k"
alias niv="diatheke -b NIV -k"
alias tniv="diatheke -b TNIV -k"
alias kjv="diatheke -b KJV -k"
alias nkjv="diatheke -b NKJV -k"
alias nasb="diatheke -b NASB -k"
alias amp="diatheke -b Amp -k"
alias ylt="diatheke -b YLT -k"
alias nlt="diatheke -b NLT -k"
alias Geneva="diatheke -b Geneva1599 -k"
alias hcsb="diatheke -b HCSB -k"
alias net="diatheke -b NETfree -k"

#alias host=hostx
#alias cc_="gcc -ansi -pedantic-errors -Wall -W -Werror -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wbad-function-cast -Wredundant-decls -Wcast-qual -Wundef -Winline -Wpointer-arith -Wcast-align -Wchar-subscripts -Wshadow -Wwrite-strings"
#alias noxbell=LD_PRELOAD=$HOME/noxbell/libnoxbell.so

alias m='mpc'
alias madd='mpc add'
alias mcl='mpc clear'
alias mp='mpc play'
alias mls='mpc playlist'
alias msearch='mpc search'
# individual aliases so they can be tab completed
alias msearchalbum='mpc search album'
alias msearchartist='mpc search artist'
alias msearchcomposer='mpc search composer'
alias msearchfile='mpc search filename'
alias msearchtitle='mpc search title'
alias msearchfilename='mpc search filename'
alias mupdate='mpc update'

#source ~/bashmp.sh
keychain ~/.ssh/id_dsa
keychain ~/.ssh/id_rsa
#. ~/.keychain/${HOSTNAME}-sh-gpg
. ~/.keychain/${HOSTNAME}-sh


#if ! type tac &>/dev/null; then
if ! [ -x "$(command -v tac)" ]; then
    alias tac="sed -n '1!G;\$p;h'"
fi

shopt -s extglob

set -o noclobber
set -o vi
bind '"\e."':yank-last-arg
bind -m vi-command ".":insert-last-argument
bind -m vi-insert "\C-l.":clear-screen
bind -m vi-insert "\C-a.":beginning-of-line
bind -m vi-insert "\C-e.":end-of-line
bind -m vi-insert "\C-w.":backward-kill-word

export HISTSIZE=2000
export HISTFILESIZE=2000
export HISTCONTROL=ignorespace:ignoredups

# easily done with tail and head, but where's the fun in that?
nth-from-end() {
    n=$1
    sed -n -e :a -e "\${P;q;};N;$((n+1)),\$D;ba" ${2}
}

most-recent() {
    ls -t|head -1
}

function google () {
    w3m http://www.google.co.uk/search?q="$@";
}

function swap-lines() {
    sed -n "${1}h;${2}{p;x;p};2,3!p" ${3}
}

function maths()
{
     echo "scale=6;${@/x/*}"|bc
}

function title()
{
    wget --quiet -O- "${1}" | sed -n 's/<title>\([^<]*\)<\/title>.*/\1/p'
}

alias set_last_dir='last_dir=$(expr "`history -p !$`" : "\(.*/\)");'

# Run commands on files in the same directory as the file in !$ (old = on last directory)
old() {
    args=($@)
    command=${args[@]:0:${#args[@]}-1}
    file=${args[${#args[@]}-1]}
    last_dir=$(expr "`history -p !$`" : "\(.*/\)")
    echo ${command} ${last_dir}${file}
    ${command} ${last_dir}${file}
}

old2() {
    command=$1
    shift
    last_dir=$(expr "`history -p !$`" : "\(.*/\)")
    echo ${command} ${last_dir}${file}
    for file in $@
    do
        echo \$ ${command} ${last_dir}${file}
        ${command} ${last_dir}${file}
        echo
    done
}

#get_default_net_if()
#{
#    sudo route -n get -inet default
#}

# for use with keyboard shortcuts
x()
{
    xclip -o
}
xspeak()
{
    echo "`x`"|festival --tts
    #espeak "`x`"
}

function ag_less()
{
    ag  --color "${@}"|less -r
}

function java_run()
{
    javac "${@}"
    java "${@/.java/}"
}

# useful for aliases
function chdir()
{

    if [ $# -eq 0 ]; then
        cd -
    else
        cd $@
        pwd
    fi
}

function run_cmd()
{
    echo "${@}"
    "${@}"
}

alias gitlog="git log --since=yesterday --name-only"
alias gitlog1="git log -p -1"
alias gitfp1="git format-patch --stdout -1"
alias gitdiff="git diff origin/develop"
alias hadd='run_cmd $(history -p ^diff^add)'

alias dogs='run_cmd docker ps; run_cmd docker logs -f $(docker ps|sed 1d|awk '"'"'{print $1;}'"'"')'
alias undock='sudo umount `mount|grep -o "/var/lib/docker/aufs/mnt/[a-z0-9]*"`'
alias gp="chdir ${VIEW_DIR} ; run_cmd git pull ; chdir"


function esvapi()
{
    ref=${@// /%20}
    #wget --quiet -O- "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=$ref"|lynx -dump -stdin|sed -n 's/\[[0-9]\+\] \?//g;/^Footnotes\|References/q;p'
    wget --quiet -O- "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=$ref"|lynx -dump -stdin|sed -n '/^\s*$/d;s/\[[0-9]\+\] \?//g;p;/(ESV)$/q'
}

function bgw()
{
    bv=${1}
    shift
    ref=${@// /%20}
    wget --quiet -O- "http://www.biblegateway.com/passage/?search=${ref}&version=${bv}"|lynx -dump -stdin|sed -n "/^$@.*${bv}/,/^Footnotes/p"|grep -v "^Footnotes"
}

function dl()
{
    DAILY_LIGHT_URL="http://www.gnpcb.org/esv/mobile/devotions/daily.light/"
    #wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/Morning/,/^\s*\[[0-9]/p'|sed -n '/^\s*\[[0-9]/q;p'|less
    if [ `date +%P` == "am" ]
    then
        wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/^Morning$/,/^Evening$/p'|sed -n '/^\s*\[[0-9]/q;p'|head -n -2|less
    elif [ `date +%P`  == "pm" ]
    then
        wget --quiet -O- "${DAILY_LIGHT_URL}"|lynx -dump -stdin|sed -n '/^Evening$/,/^\s*\[[0-9]/p'|sed -n '/^\s*\[[0-9]/q;p'|head -n -1|less
    else
        echo "Neither AM nor PM!"
    fi
}

function pmp()
{
    #sed -n "/`date +'%B %-d.%p'|sed 's,AM,Morning,;s,PM,Evening,'`/,/`date --date=tomorrow +'%B %-d'`/p" rh_pmp.txt | head -n -1 | less
    if [ `date +%P` == "am" ]
    then
        #sed -n "/`date +'%B %-d.Morning'`/,/`date +'%B %-d.Evening'`/p" rh_pmp.txt | head -n -1 | tr -d '\f' | less
        xzcat rh_pmp.txt.xz | sed -n "/`date +'%B %-d.Morning'`/,/`date +'%B %-d.Evening'`/p" | head -n -1 | tr -d '\f' | less
    elif [ `date +%P` == "pm" ]
    then
        #sed -n "/`date +'%B %-d.Evening'`/,/`date --date=tomorrow +'%B %-d.Morning'`/p" rh_pmp.txt | head -n -1 | tr -d '\f' | less
        xzcat rh_pmp.txt.xz | sed -n "/`date +'%B %-d.Evening'`/,/`date --date=tomorrow +'%B %-d.Morning'`/p" | head -n -1 | tr -d '\f' | less
    else
        echo "Neither AM nor PM!"
    fi
}

function wsc()
{
    grep ^[QA]$1: wsc.txt | fold -s | col -b
}
function wscq()
{
    grep ^Q$1: wsc.txt | fold -s | col -b
}
function wsca()
{
    grep ^A$1: wsc.txt | fold -s | col -b
}

function wlc()
{
    grep ^[QA]$1: wlc.txt | fold -s | col -b
}
function wlcq()
{
    grep ^Q$1: wlc.txt | fold -s | col -b
}
function wlca()
{
    grep ^A$1: wlc.txt | fold -s | col -b
}

bible() {
    book=$1
    shift
    case $book in
    esv|niv|tniv|nasb|kjv|nkjv|nlt|hcsb|ylt|asv)
      book=${book^^*}
      ;;
    amp)
      book=${book^*}
      ;;
    net)
      book=NETfree
      ;;
    esac
    diatheke -b "${book}" -k "${*}"|grep -v '^$'|sed -e :a -e '/[0-9]: $/N;s/\([0-9][0-9]*\): \n/\1: /;ta'
}

pll() {
    bible esv $@
    bible niv $@
    bible tniv $@
    bible kjv $@
    bible nkjv $@
    bible nasb $@
    bible net $@
    bible hcsb $@
}


# cricinfo functions (check, replace_urls, add_urls, remove_urls count_urls)
function check()
{
    while read i ; do
        #wget --quiet -O- "${i}" | sed -n 's/<title>\([^|]*\).*/\1/p'
        wget --quiet -O- "${i}" | sed -n 's/<title>\([^|<]*\).*/\1/p'
    done < ${HOME}/urls.txt
}

function replace_urls()
{
    if [ $# -eq 0 ]; then
        cat >| ${HOME}/urls.txt
    else
        : >| ${HOME}/urls.txt
        for url in "$@"; do
            echo $url >> ${HOME}/urls.txt
        done
    fi
}

function add_urls()
{
    if [ $# -eq 0 ]; then
        cat >> ${HOME}/urls.txt
    else
        for url in "$@"; do
            echo $url >> ${HOME}/urls.txt
        done
    fi
}

function remove_urls()
{
    sed -i ${1}d ${HOME}/urls.txt
}

function count_urls()
{
    wc -l ${HOME}/urls.txt
}

#pgrep -f raven || screen -S rav -d -m ssh -X -R 6728:localhost:22221 wadh2045@raven.linux.ox.ac.uk
#pgrep -f ecs || screen -S ecs -d -m ssh -X -R 6728:localhost:22221 m04dm@booth1.ecs.ox.ac.uk
#pgrep -f crow || screen -S crow -d -m ssh -X -D 8080 wadh2045@crow.linux.ox.ac.uk

true

# vim: set et ts=4 tw=120 :