Mercurial > index.cgi > dotfiles
comparison .bash_aliases @ 265:df0b24d4fabd
Think I'm ready to check this all in now; shared dotfiles that can be "sent"
through an SSH connection to be used and cleaned up when finished.
| author | Steve Huston <huston@srhuston.net> |
|---|---|
| date | Wed, 24 Apr 2024 16:15:40 -0400 |
| parents | b00e6b403896 |
| children | 48b4f41712dc |
comparison
equal
deleted
inserted
replaced
| 264:bb69763716a7 | 265:df0b24d4fabd |
|---|---|
| 1 # Aliases are read from this file; no real reason to separate them out except | 1 # Aliases are read from this file; no real reason to separate them out except |
| 2 # for readability. | 2 # for readability. |
| 3 | 3 |
| 4 # | |
| 4 # Some settings which are architecture dependent | 5 # Some settings which are architecture dependent |
| 6 # | |
| 5 case `uname` in | 7 case `uname` in |
| 6 Darwin) | 8 Darwin) |
| 7 # DARWIN is used for the SSHFS mounts below | 9 # DARWIN is used for the SSHFS mounts below |
| 8 DARWIN="yes" | 10 DARWIN="yes" |
| 9 | 11 |
| 39 | 41 |
| 40 VNCVIEWER="vncviewer Shared=1 Fullcolor=1 " | 42 VNCVIEWER="vncviewer Shared=1 Fullcolor=1 " |
| 41 ;; | 43 ;; |
| 42 esac | 44 esac |
| 43 | 45 |
| 46 # | |
| 44 # Export some of those above for the benefit of future shells | 47 # Export some of those above for the benefit of future shells |
| 48 # | |
| 45 export DFSTAT MDATE | 49 export DFSTAT MDATE |
| 46 | 50 |
| 47 # SSH aliases | 51 # |
| 48 alias bh='ssh csesbh2.princeton.edu' | 52 # Create a service that can share files through to places we ssh to from here. |
| 53 # This should be pretty light, rooted in the $DOTHOME directory (see ~/.bashrc | |
| 54 # for information) and removed when we either request it or the shell exits. | |
| 55 # | |
| 56 ds() { | |
| 57 | |
| 58 PIDFILE=${DOTHOME}/.dotshare-PID | |
| 59 | |
| 60 # If we want to kill an existing server, let's do that first. | |
| 61 if [ "$1" == "end" -a -e $PIDFILE ]; then | |
| 62 kill `cat $PIDFILE` | |
| 63 unset DOTSHARE_PID DOTSHARE_PORT | |
| 64 echo "Server terminated" | |
| 65 return 0 | |
| 66 fi | |
| 67 | |
| 68 # Let's check if things exist and we can just use them as-is | |
| 69 if [ -e $PIDFILE ]; then | |
| 70 DOTSHARE_PID=`cat $PIDFILE` | |
| 71 DOTSHARE_PORT=`lsof -n -p $DOTSHARE_PID | grep LISTEN | awk '{print $9}' | sed 's/.*://'` | |
| 72 if [ -z $DOTSHARE_PORT ]; then | |
| 73 echo "Server PIDfile found but couldn't get a port, aborting" | |
| 74 return 255 | |
| 75 fi | |
| 76 echo "Existing server ${DOTSHARE_PID} listening on ${DOTSHARE_PORT}, setting environment" | |
| 77 export DOTSHARE_PID DOTSHARE_PORT | |
| 78 return 0 | |
| 79 fi | |
| 80 | |
| 81 # Nothing exists, so we need to make one; first, which python do we have | |
| 82 if hash python3 > /dev/null 2>&1 ; then | |
| 83 # Python 3.9 also accepts '-d' for a directory | |
| 84 serv_cmd="python3 -m http.server --bind localhost 0" | |
| 85 elif hash python > /dev/null 2>&1 ; then | |
| 86 # I think nothing else where I'd run this will need this one | |
| 87 serv_cmd="python -m SimpleHTTPServer 0" | |
| 88 else | |
| 89 echo "No python found, cannot start share server." | |
| 90 return 255 | |
| 91 fi | |
| 92 | |
| 93 # Spawning this in a subshell because the process won't go away and we want | |
| 94 # to background it, but we also want to set a trap around the whole thing, | |
| 95 # and we need to 'cd' to somewhere else to start it since older versions | |
| 96 # can't be passed a different path to serve. So there's some hacks here, | |
| 97 # but I don't think they're avoidable for the moment. Once Joshua and | |
| 98 # Xanadu have Python 3.9 at least, I can rework this whole thing. | |
| 99 ( | |
| 100 cd $DOTHOME | |
| 101 $serv_cmd > /dev/null 2>&1 & | |
| 102 P=$! | |
| 103 echo $P > ${DOTHOME}/.dotshare-PID | |
| 104 trap "kill $P 2>/dev/null; rm -f $PIDFILE; unset DOTSHARE_PID DOTSHARE_PORT" 0 | |
| 105 wait | |
| 106 ) & | |
| 107 disown %+ | |
| 108 | |
| 109 # Give it a moment to collect its thoughts... | |
| 110 sleep 1 | |
| 111 DOTSHARE_PID=`cat $PIDFILE` | |
| 112 DOTSHARE_PORT=`lsof -n -p $DOTSHARE_PID | grep LISTEN | awk '{print $9}' | sed 's/.*://'` | |
| 113 echo "Server PID $DOTSHARE_PID ready on port $DOTSHARE_PORT" | |
| 114 export DOTSHARE_PID DOTSHARE_PORT | |
| 115 } | |
| 116 | |
| 117 # | |
| 118 # SSH aliases/functions | |
| 119 # | |
| 49 cert() { | 120 cert() { |
| 50 # SSH key signing with Vault for administration | 121 # SSH key signing with Vault for administration |
| 51 export VAULT_ADDR='https://ajax.rc.princeton.edu:8200' | 122 export VAULT_ADDR='https://ajax.rc.princeton.edu:8200' |
| 52 ssh-add -d $HOME/.ssh/rc_vault_key-cert.pub > /dev/null 2>&1 | 123 ssh-add -d $HOME/.ssh/rc_vault_key-cert.pub > /dev/null 2>&1 |
| 53 if vault login -method=radius username=vi-srh; then | 124 if vault login -method=radius username=vi-srh; then |
| 55 ssh-add -t 36000 $HOME/.ssh/rc_vault_key | 126 ssh-add -t 36000 $HOME/.ssh/rc_vault_key |
| 56 else | 127 else |
| 57 echo Failed to login to vault, aborting | 128 echo Failed to login to vault, aborting |
| 58 fi | 129 fi |
| 59 } | 130 } |
| 60 alias dh='ssh srhuston.net' | 131 |
| 61 alias j='ssh joshua.srhuston.net' | 132 # I rename my keys from the standard so they're easy to glob on a commandline |
| 62 alias keys='ssh-add $HOME/.ssh/*.pvt' | 133 alias keys='ssh-add $HOME/.ssh/*.pvt' |
| 63 alias r='ssh -l root' | 134 |
| 64 alias rf='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null -l root' | 135 # |
| 136 # These are for reattaching screen sessions, only useful on bastion systems | |
| 137 # | |
| 65 alias rbh='ssh -t csesbh2.princeton.edu screen -raAx csesbh2' | 138 alias rbh='ssh -t csesbh2.princeton.edu screen -raAx csesbh2' |
| 66 alias rj='ssh -t joshua.srhuston.net screen -raAx' | 139 alias rj='ssh -t joshua.srhuston.net screen -raAx' |
| 67 alias rx='ssh -t xanadu.astro.princeton.edu screen -raAx' | 140 alias rx='ssh -t xanadu.astro.princeton.edu screen -raAx' |
| 68 alias s=ssh | 141 |
| 69 alias sf='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null' | |
| 70 t() { | 142 t() { |
| 71 # Tunneling SSH - a simple 't hostname' will tunnel to xanadu and then | 143 # Tunneling SSH - a simple 't hostname' will tunnel to xanadu and then |
| 72 # connect to hostname, while 't hostname tunnelhost' will connect to | 144 # connect to hostname, while 't hostname tunnelhost' will connect to |
| 73 # tunnelhost and then hostname | 145 # tunnelhost and then hostname |
| 146 # Today (2024/03/30) I don't remember the last time I used this; retire? | |
| 74 T_HOST=xanadu.astro.princeton.edu | 147 T_HOST=xanadu.astro.princeton.edu |
| 75 if [ -n "$2" ] ; then | 148 if [ -n "$2" ] ; then |
| 76 T_HOST=$2 | 149 T_HOST=$2 |
| 77 fi | 150 fi |
| 78 ssh -t $T_HOST "ssh $1" | 151 ssh -t $T_HOST "ssh $1" |
| 79 } | 152 } |
| 80 alias x='ssh xanadu.astro.princeton.edu' | 153 |
| 81 | |
| 82 # Proxying/tunneling - predominantly for my Mac laptop | |
| 83 proxy() { | 154 proxy() { |
| 84 local PROXY_HOST PROXY_PORT PROXY_PATH PROXY_UMOUNT | 155 # Proxying/tunneling - predominantly for my Mac laptop |
| 156 local PROXY_HOST PROXY_PORT PROXY_PATH PROXY_UMOUNT PROXY_CMD | |
| 157 # We set a simple command to run over the proxy for normal connections, | |
| 158 # which we know will be multiplexed and stay active. If you're using a | |
| 159 # manual host for something, you'll want to use a "sleep 30" or something to | |
| 160 # keep the shell open long enough for the proxy to be used, or maybe even | |
| 161 # longer if you plan on disconnecting and reconnecting over time. | |
| 162 PROXY_CMD=${PROXY_CMD:-hostname} | |
| 85 case $1 in | 163 case $1 in |
| 86 home) | 164 home) |
| 87 if [ "$HOST" != "gallifrey" ] ; then | 165 if [ "$HOST" != "gallifrey" ] ; then |
| 88 echo "Not on gallifrey, no need for this" | 166 echo "Not on gallifrey, no need for this" |
| 89 return | 167 return |
| 128 # In theory you need to have a job stay on the remote host for the | 206 # In theory you need to have a job stay on the remote host for the |
| 129 # forwarding to stay open. However if you're using persistent/shared | 207 # forwarding to stay open. However if you're using persistent/shared |
| 130 # connections then the port stays open anyway. We still need a command | 208 # connections then the port stays open anyway. We still need a command |
| 131 # though, and 'hostname' returns quickly as well as giving a visual output | 209 # though, and 'hostname' returns quickly as well as giving a visual output |
| 132 # that you connected to the right place. | 210 # that you connected to the right place. |
| 133 ssh -D $PROXY_PORT -f -C -q $PROXY_HOST 'hostname' | 211 ssh -D $PROXY_PORT -f -C -q $PROXY_HOST "$PROXY_CMD" |
| 134 ( | 212 ( |
| 135 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \ | 213 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \ |
| 136 --proxy-server="socks5://127.0.0.1:$PROXY_PORT" \ | 214 --proxy-server="socks5://127.0.0.1:$PROXY_PORT" \ |
| 137 --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" \ | 215 --host-resolver-rules="MAP * 0.0.0.0 , EXCLUDE localhost" \ |
| 138 --user-data-dir="${PROXY_PATH}" > /dev/null 2>&1 | 216 --user-data-dir="${PROXY_PATH}" > /dev/null 2>&1 |
| 142 # ssh -O cancel -D $PROXY_PORT $PROXY_HOST | 220 # ssh -O cancel -D $PROXY_PORT $PROXY_HOST |
| 143 ) & | 221 ) & |
| 144 disown %+ | 222 disown %+ |
| 145 } | 223 } |
| 146 | 224 |
| 147 # Remote desktop/VNC | 225 # |
| 226 # Remote desktop/VNC - definitely outdated and maybe no longer useful? | |
| 227 # | |
| 148 eval "alias milton='ssh -L9930:milton:5900 -f joshua.srhuston.net \"sleep 5\"; ${VNCVIEWER}localhost:9930 &'" | 228 eval "alias milton='ssh -L9930:milton:5900 -f joshua.srhuston.net \"sleep 5\"; ${VNCVIEWER}localhost:9930 &'" |
| 149 | 229 |
| 230 # | |
| 150 # Programs | 231 # Programs |
| 232 # | |
| 151 alias atari='atari800 -height 800 -width 600' | 233 alias atari='atari800 -height 800 -width 600' |
| 152 alias base64='openssl enc -a' | 234 alias base64='openssl enc -a' |
| 153 alias irssi-test='irssi --home=$HOME/irssi-test/' | 235 alias irssi-test='irssi --home=$HOME/irssi-test/' |
| 154 alias pine='alpine' | 236 alias pine='alpine' |
| 155 alias ret='screen -raAx' | 237 alias ret='screen -raAx' |
| 156 alias rot13="tr 'a-zA-Z' 'n-za-mN-ZA-M'" | |
| 157 tt () { | 238 tt () { |
| 158 OPTS="-G" | 239 OPTS="-G" |
| 159 if [ -e ${HOME}/.tt/${1}.tin ] ; then | 240 if [ -e ${HOME}/.tt/${1}.tin ] ; then |
| 160 OPTS="${OPTS} ${HOME}/.tt/${1}.tin" | 241 OPTS="${OPTS} ${HOME}/.tt/${1}.tin" |
| 161 shift | 242 shift |
| 162 fi | 243 fi |
| 163 tt++ ${OPTS} $@ | 244 tt++ ${OPTS} $@ |
| 164 } | 245 } |
| 165 alias vi='vim' | 246 |
| 166 | 247 # |
| 167 # SSHFS mounts | 248 # SSHFS mounts |
| 168 # The $DARWIN check fills in a nice volname if this is a Mac | 249 # The $DARWIN check fills in a nice volname if this is a Mac |
| 250 # | |
| 169 alias junkpile="sshfs -oreconnect${DARWIN:+,volname=Junkpile} srhuston.net:junkpile $HOME/junkpile" | 251 alias junkpile="sshfs -oreconnect${DARWIN:+,volname=Junkpile} srhuston.net:junkpile $HOME/junkpile" |
| 170 alias sdh="sshfs -oreconnect${DARWIN:+,volname=srhuston.net} srhuston.net: $HOME/srhuston.net" | 252 alias sdh="sshfs -oreconnect${DARWIN:+,volname=srhuston.net} srhuston.net: $HOME/srhuston.net" |
| 171 alias sj="sshfs -oreconnect${DARWIN:+,volname=Joshua} joshua.srhuston.net: $HOME/joshua" | 253 alias sj="sshfs -oreconnect${DARWIN:+,volname=Joshua} joshua.srhuston.net: $HOME/joshua" |
| 172 alias sx="sshfs -oreconnect${DARWIN:+,volname=Xanadu} xanadu.astro.princeton.edu: $HOME/xanadu" | 254 alias sx="sshfs -oreconnect${DARWIN:+,volname=Xanadu} xanadu.astro.princeton.edu: $HOME/xanadu" |
| 173 alias vw="sshfs -oreconnect${DARWIN:+,volname=VW} vw.math.princeton.edu: $HOME/vw" | 255 alias vw="sshfs -oreconnect${DARWIN:+,volname=VW} vw.math.princeton.edu: $HOME/vw" |
| 174 alias tmu="sshfs -oreconnect${DARWIN:+,volname=tomenet-user} joshua.srhuston.net:Installs/tomenet/lib/user $HOME/Installs/tomenet/lib/user" | 256 alias tmu="sshfs -oreconnect${DARWIN:+,volname=tomenet-user} joshua.srhuston.net:Installs/tomenet/lib/user $HOME/Installs/tomenet/lib/user" |
| 175 | 257 |
| 258 # | |
| 176 # LDAP/host tools | 259 # LDAP/host tools |
| 260 # | |
| 177 alias ldm="ldapmodify -Q -Y GSSAPI -c" | 261 alias ldm="ldapmodify -Q -Y GSSAPI -c" |
| 178 alias ldsloop='while true; do read; clear; lds "$REPLY"; done' | 262 alias ldsloop='while true; do read; clear; lds "$REPLY"; done' |
| 179 | |
| 180 lds () { | 263 lds () { |
| 181 QUERY="$1" | 264 QUERY="$1" |
| 182 shift | 265 shift |
| 183 OPTS="" | 266 OPTS="" |
| 184 [[ "$1" =~ ^- ]] && { | 267 [[ "$1" =~ ^- ]] && { |
| 186 shift | 269 shift |
| 187 } | 270 } |
| 188 ldapsearch -Q -Y GSSAPI -LLL $OPTS "($QUERY)" $@ | 271 ldapsearch -Q -Y GSSAPI -LLL $OPTS "($QUERY)" $@ |
| 189 } | 272 } |
| 190 | 273 |
| 274 # | |
| 191 # Other | 275 # Other |
| 192 alias slurp="wget -r -l1 -np -nd -A.mp3" | 276 # |
| 193 alias zulu="date -u +%Y%m%d%H%M%SZ" | |
| 194 | |
| 195 # Other Functions | |
| 196 | |
| 197 certcheck() { | |
| 198 if [ -z "$1" ] ; then | |
| 199 echo "Usage: certcheck <hostname>[:port]" | |
| 200 echo " Defaults to port 443 if not specified." | |
| 201 return | |
| 202 fi | |
| 203 H=$1 | |
| 204 [[ $1 =~ :[0-9]+$ ]] || \ | |
| 205 H=$1":443" | |
| 206 echo -n Q | openssl s_client -connect $H | openssl x509 -noout -dates | |
| 207 } | |
| 208 | |
| 209 mc-backup() { | |
| 210 pushd ~/Dropbox/Saves/minecraft/saves; | |
| 211 if [ -d $1 ]; then | |
| 212 tar cvf - $1 | bzip2 > ../$1_`date +%Y%m%d%H%M%S`.tar.bz2; | |
| 213 fi; | |
| 214 popd | |
| 215 } | |
| 216 | |
| 217 TOhtml() { | |
| 218 OUTDIR=${1:-`mktemp -d TOHTML.XXXXXX`} | |
| 219 ROOT=`hg root` | |
| 220 | |
| 221 echo "<HTML><HEAD><TITLE>My dotfiles</TITLE></HEAD><BODY><UL>" > $OUTDIR/index.html | |
| 222 | |
| 223 for F in `hg locate` ; do | |
| 224 | |
| 225 # Files to ignore from the list | |
| 226 case $F in | |
| 227 .vim/*) | |
| 228 continue | |
| 229 ;; | |
| 230 *) | |
| 231 ;; | |
| 232 esac | |
| 233 | |
| 234 D=`echo $F | grep "/" | sed 's/\/[^\/]*$//'` | |
| 235 if [ $D ] ; then | |
| 236 mkdir -p $OUTDIR/$D | |
| 237 fi | |
| 238 | |
| 239 vim -n -e +TOhtml "+w ${OUTDIR}/${F}.html" +qa\! $ROOT/$F | |
| 240 echo "<LI><A href=${F}.html>$F</A></LI>" >> $OUTDIR/index.html | |
| 241 done | |
| 242 echo "</UL></BODY></HTML>" >> $OUTDIR/index.html | |
| 243 echo Files stored in $OUTDIR | |
| 244 } | |
| 245 | |
| 246 hgs() { | 277 hgs() { |
| 278 # Creates a hg server in the current repo and connects to it automatically. | |
| 247 # We assume here that if the host is a Mac, we're going to open the | 279 # We assume here that if the host is a Mac, we're going to open the |
| 248 # connection automatically, otherwise we echo the URL to the terminal to be | 280 # connection automatically, otherwise we echo the URL to the terminal to be |
| 249 # opened | 281 # opened |
| 250 ROOT=`hg root` | 282 ROOT=`hg root` |
| 251 if [ "$1" == "end" -a -e $ROOT/.hg/hgserve-PID ] ; then | 283 if [ "$1" == "end" -a -e $ROOT/.hg/hgserve-PID ] ; then |
| 263 else | 295 else |
| 264 open http://$URL/ | 296 open http://$URL/ |
| 265 fi | 297 fi |
| 266 fi | 298 fi |
| 267 } | 299 } |
| 268 | 300 mc-backup() { |
| 269 # vim: set filetype=sh : | 301 # Definitely time to rework this one - I don't even use Dropbox anymore! |
| 302 # Keeping it here for now just for the syntax, but this is probably no | |
| 303 # longer worth keeping either. | |
| 304 pushd ~/Dropbox/Saves/minecraft/saves; | |
| 305 if [ -d $1 ]; then | |
| 306 tar cvf - $1 | bzip2 > ../$1_`date +%Y%m%d%H%M%S`.tar.bz2; | |
| 307 fi; | |
| 308 popd | |
| 309 } | |
| 310 alias slurp="wget -r -l1 -np -nd -A.mp3" | |
| 311 alias zulu="date -u +%Y%m%d%H%M%SZ" | |
| 312 TOhtml() { | |
| 313 # Since I moved to hosting the hg repo, this is less useful to share things. | |
| 314 # But still a nice bit of code and worth keeping I think. Needs a rework to | |
| 315 # match the new style of the dotfile repo as of 2024/03/30 (splitting out | |
| 316 # shared configs, etc) | |
| 317 OUTDIR=${1:-`mktemp -d TOHTML.XXXXXX`} | |
| 318 ROOT=`hg root` | |
| 319 | |
| 320 echo "<HTML><HEAD><TITLE>My dotfiles</TITLE></HEAD><BODY><UL>" > $OUTDIR/index.html | |
| 321 | |
| 322 for F in `hg locate` ; do | |
| 323 | |
| 324 # Files to ignore from the list | |
| 325 case $F in | |
| 326 .vim/*) | |
| 327 continue | |
| 328 ;; | |
| 329 *) | |
| 330 ;; | |
| 331 esac | |
| 332 | |
| 333 D=`echo $F | grep "/" | sed 's/\/[^\/]*$//'` | |
| 334 if [ $D ] ; then | |
| 335 mkdir -p $OUTDIR/$D | |
| 336 fi | |
| 337 | |
| 338 vim -n -e +TOhtml "+w ${OUTDIR}/${F}.html" +qa\! $ROOT/$F | |
| 339 echo "<LI><A href=${F}.html>$F</A></LI>" >> $OUTDIR/index.html | |
| 340 done | |
| 341 echo "</UL></BODY></HTML>" >> $OUTDIR/index.html | |
| 342 echo Files stored in $OUTDIR | |
| 343 } | |
| 344 | |
| 345 # vim: set filetype=bash : |
