view .bash_aliases @ 197:954d25f20123

Removing toodledo stuff (no longer used)
author Steve Huston <huston@srhuston.net>
date Wed, 30 Sep 2020 10:54:00 -0400
parents 1d13f4ed76f5
children 6e7913283c7a
line wrap: on
line source

# $Id$

# Aliases are read from this file; no real reason to separate them out except
# for readability.

# Some settings which are architecture dependent
case `uname` in
  Darwin)
    # DARWIN is used for the SSHFS mounts below
    DARWIN="yes"

    # The 'stat' and 'date' commands are here since the syntax of the commands
    # is different between Linux and Mac OS X.  If this is run elsewhere, the
    # eval will be false and the test not done below, so it's safe to not
    # bother checking for zero-length variables on the test - it just won't
    # run the hg incoming, so you won't be prompted if there's newer files
    # available in your repository.  These are safe to export since they're
    # the commands to be evaulated, not the output - you're storing how to get
    # the answer, not the answer itself.

    # Also note, the full paths are stored since GNU coreutils might be
    # installed; while that would tend to make things "easier" since the GNU
    # one is the same as the Linux ones below, it can't be guaranteed.
    # Instead of checking for the presence of /opt/local/bin/ls (or gls) it's
    # easier to point directly to the one you know *is* installed.

    DFSTAT="/usr/bin/stat -f %m -t %s $HOME/.dotfilets"
    MDATE="/bin/date -v -1m +%s"

    alias ls='/bin/ls -FG'

    VNCVIEWER="open vnc://"
    ;;

  Linux)
    # See above for a description of these four
    DFSTAT="/usr/bin/stat -c %Y $HOME/.dotfilets"
    MDATE="/bin/date -d \"1 month ago\" +%s"

    alias ls='/bin/ls --color=auto -F'

    VNCVIEWER="vncviewer Shared=1 Fullcolor=1 "
    ;;
esac

# Export some of those above for the benefit of future shells
export DFSTAT MDATE

# SSH aliases
alias bh='ssh csesbh2.princeton.edu'
alias dh='ssh srhuston.net'
alias j='ssh joshua.srhuston.net'
alias keys='ssh-add $HOME/.ssh/*.pvt'
alias r='ssh -l root'
alias rf='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null -l root'
alias rbh='ssh -t csesbh2.princeton.edu screen -raAx csesbh2'
alias rj='ssh -t joshua.srhuston.net screen -raAx'
alias rx='ssh -t xanadu.astro.princeton.edu screen -raAx'
alias roc='ssh zenoss@rocinante'
alias s=ssh
alias sf='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null'
t() {
  T_HOST=xanadu.astro.princeton.edu
  if [ -n "$2" ] ; then
    T_HOST=$2
  fi
  ssh -t $T_HOST "ssh $1"
}
alias x='ssh xanadu.astro.princeton.edu'

# SSH key signing with Vault for administration
cert() {
  export VAULT_ADDR='https://ajax.rc.princeton.edu:8200'
  ssh-add -d $HOME/.ssh/rc_vault_key-cert.pub > /dev/null 2>&1
  if vault login -method=radius username=vi-srh; then
    vault write -field=signed_key ssh-client-signer/sign/root public_key=@$HOME/.ssh/rc_vault_key.pub > $HOME/.ssh/rc_vault_key-cert.pub
    ssh-add -t 36000 $HOME/.ssh/rc_vault_key
  else
    echo Failed to login to vault, aborting
  fi
}

# Proxying/tunneling - predominantly for my Mac laptop
proxy() {
  PROXY_HOST=${PROXY_HOST:-xanadu.astro.princeton.edu}
  PROXY_PORT=${PROXY_PORT:-8888}
  ssh -D $PROXY_PORT -f -C -q $PROXY_HOST 'sleep 15'
  /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
    --proxy-server="socks5://127.0.0.1:$PROXY_PORT" \
    --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" \
    --user-data-dir="/Users/huston/Library/Application Support/Google/Chrome/ProxiedProfile" > /dev/null 2>&1 &
  history -s ssh -O cancel -D $PROXY_PORT $PROXY_HOST
  echo Cancel command added to history
}

# Remote desktop/VNC
eval "alias milton='ssh -L9930:milton:5900 -f joshua.srhuston.net \"sleep 5\"; ${VNCVIEWER}localhost:9930 &'"
# Xanadu VMs
eval "alias xvm='ssh -L9909:localhost:5909 -f xanadu.astro.princeton.edu \"sleep 300\"; ${VNCVIEWER}localhost:9909 &'"
eval "alias cygnus='ssh -L9910:localhost:5910 -f xanadu.astro.princeton.edu \"sleep 300\"; ${VNCVIEWER}localhost:9910 &'"
eval "alias syrinx='ssh -L9911:localhost:5911 -f xanadu.astro.princeton.edu \"sleep 300\"; ${VNCVIEWER}localhost:9911 &'"
eval "alias lyra='ssh -L9912:localhost:5912 -f xanadu.astro.princeton.edu \"sleep 300\"; ${VNCVIEWER}localhost:9912 &'"

# Programs
alias atari='atari800 -height 800 -width 600'
alias base64='openssl enc -a'
alias irssi-test='irssi --home=$HOME/irssi-test/'
alias pine='alpine'
alias ret='screen -raAx'
alias rot13="tr 'a-zA-Z' 'n-za-mN-ZA-M'"
alias tops='unset STY; screen -c .screenrc.pbstops -S pbstop'
tt () {
  OPTS="-G"
  if [ -e ${HOME}/.tt/${1}.tin ] ; then
    OPTS="${OPTS} ${HOME}/.tt/${1}.tin"
    shift
  fi
  tt++ ${OPTS} $@
}
alias vi='vim'

# SSHFS mounts
# The $DARWIN check fills in a nice volname if this is a Mac
alias junkpile="sshfs -oreconnect${DARWIN:+,volname=Junkpile} srhuston.net:junkpile $HOME/junkpile"
alias sdh="sshfs -oreconnect${DARWIN:+,volname=srhuston.net} srhuston.net: $HOME/srhuston.net"
alias sj="sshfs -oreconnect${DARWIN:+,volname=Joshua} joshua.srhuston.net: $HOME/joshua"
alias sx="sshfs -oreconnect${DARWIN:+,volname=Xanadu} xanadu.astro.princeton.edu: $HOME/xanadu"
alias vw="sshfs -oreconnect${DARWIN:+,volname=VW} vw.math.princeton.edu: $HOME/vw"
alias tmu="sshfs -oreconnect${DARWIN:+,volname=tomenet-user} joshua.srhuston.net:Installs/tomenet/lib/user $HOME/Installs/tomenet/lib/user"

# LDAP/host tools
alias ldm="ldapmodify -Q -Y GSSAPI -c"
alias ldsloop='while true; do read; clear; lds "$REPLY"; done'
alias hostmaster='ssh -x -a huston@arizona.princeton.edu /usr/oit/bin/hostinfo'

lds () {
  QUERY="$1"
  shift
  OPTS=""
  [[ "$1" =~ ^- ]] && {
    OPTS="$1"
    shift
  }
  ldapsearch -Q -Y GSSAPI -LLL $OPTS "($QUERY)" $@
}

ldsauth () {
  QUERY="$1"
  shift
  OPTS=""
  [[ "$1" =~ ^- ]] && {
    OPTS="$1"
    shift
  }
  ldapsearch -LLL -Z -W -D cn=DrAdmin,dc=astro,dc=princeton,dc=edu $OPTS -x "($QUERY)" $@
}

ldapsync() {
  for H in ldap ldap2 ldap3 ; do
    echo -ne $H":\t"
    ldapsearch -LLL -h $H.astro.princeton.edu -x -s base '(objectclass=*)' contextCSN | egrep -v '^($|dn)' | sed 's/contextCSN: //'
  done
  echo -ne "now:\t"
  date -u +%Y%m%d%H%M%S
}

# Other
alias condor_check="ls -lat /u/condor/hosts/*/log/MasterLog"
alias slurp="wget -r -l1 -np -nd -A.mp3"
alias zulu="date -u +%Y%m%d%H%M%SZ"

# Other Functions

mc-backup() { 
  pushd ~/Dropbox/Saves/minecraft/saves;
  if [ -d $1 ]; then
    tar cvf - $1 | bzip2 > ../$1_`date +%Y%m%d%H%M%S`.tar.bz2;
  fi;
  popd
}

tock() {
  while true ; do
    if [ `date +%S` -gt 42 ] ; then
      if [ `date +%S` -lt 47 ] ; then
        afplay /System/Library/Sounds/Pop.aiff &
      fi
    fi
    sleep 1
  done > /dev/null 2>&1
}

TOhtml() {
  OUTDIR=`mktemp -d TOHTML.XXXXXX`
  for F in `hg locate` ; do 
    if [ -d $F ] ; then 
      continue
    fi

    # Files to ignore from the list
    case $F in
      .vim/plugin/gnupg.vim | \
      .vim/syntax/syslog.vim| \
      .vim/syntax/yum.vim   \
      )
        continue
        ;;
      *)
        ;;
    esac

    OUT=`echo $F | sed -e 's/^\.//' -e 's,.*/,,'`
    vim -e +TOhtml "+w ${OUTDIR}/${OUT}.html" +qa\! $F
  done
  echo Files stored in $OUTDIR
}

hgs() {
  # We assume here that if the host is a Mac, we're going to open the
  # connection automatically, otherwise we echo the URL to the terminal to be
  # opened
  ROOT=`hg root`
  if [ "$1" == "end" -a -e $ROOT/.hg/hgserve-PID ] ; then
    kill `cat $ROOT/.hg/hgserve-PID`
    rm $ROOT/.hg/hgserve-PID
  else
    if [ -e $ROOT/.hg/hgserve-PID ] ; then
      P=`cat $ROOT/.hg/hgserve-PID`
      URL=`lsof -n -p $P | grep LISTEN | awk '{print $9}'`
    else
      URL=`hg serve -a localhost -d -p 0 --pid-file $ROOT/.hg/hgserve-PID | sed 's#.*bound to \(.*\))#\1#'`
    fi
    if [ -z "$DARWIN" ] ; then
      echo hg serve on http://$URL/
    else
      open http://$URL/
    fi
  fi
}

# vim: set filetype=sh :