diff .shared/shared_bashrc @ 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
children 48b4f41712dc
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.shared/shared_bashrc	Wed Apr 24 16:15:40 2024 -0400
@@ -0,0 +1,126 @@
+# These items are used both in my normal shells, and available to be sourced
+# in other connections via the shared files tunnel.  This way I have a single
+# place to set certain things that I use normally but will want to be able to
+# use in other places as well.
+#
+# Note that if this is a normal shell, $DOTHOME will have been set there and
+# will point to the normal location, but if this is a shared shell then the
+# script that calls this needs to set that to wherever the temporary files
+# have been deposited.
+
+#
+# Environment variables
+#
+
+[[ "$PS1" ]] && . ${DOTHOME}/bash_prompt
+
+export PAGER=less
+export EDITOR=vim
+export VIMINIT="source ${DOTHOME}/.vim/vimrc"
+export GVIMINIT="source ${DOTHOME}/.vim/gvimrc"
+export HOST=`hostname -s`
+export SCREENRC="${DOTHOME}/screenrc"
+
+# Specifically, to hell with this terminal type
+[[ $TERM =~ screen.xterm-256color ]] && export TERM=screen-256color
+
+# Rather than have another separate file for aliases, just list them in here
+# (while local aliases have some complicated and large functions, shared ones
+# are pretty small anyway)
+
+# Safe to set this here; if I'm running on a Mac it's my own machine and will
+# have the local override for the correct arguments to 'ls'
+
+alias ls='/bin/ls --color=auto -F'
+
+#
+# Shared SSH aliases
+#
+alias bh='ssh csesbh2.princeton.edu'
+alias dh='ssh srhuston.net'
+alias j='ssh joshua.srhuston.net'
+alias x='ssh xanadu.astro.princeton.edu'
+
+# For these, we check for a running share server, and if it exists then we
+# pass the port through to the other side.  The biggest problem with this
+# whole thing is that I don't see a programmatic way to grab the port, so it's
+# going to have to be a pretty simple command to pull things through, or a
+# very ugly hack to set an environment variable with everything the script
+# needs but the port which will have to be manual.. just no good way around it
+# I can see.
+
+# This variable just makes the later lines easier to read.  Sets options to
+# ignore the host keys, for times when I know that they might be different but
+# I want to login anyway and maybe don't want to adjust the known_hosts file.
+S_FORCE="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null"
+
+# The tests ahead of each function are because I have 's' and 'r' aliases from
+# before which might interfere.  While I could prepend the definition with
+# 'function' to override the error, you'd still get the wrong one when calling
+# it because the alias would take priority.  So if they exist, remove them -
+# no harm done.
+#
+# I would love for this section to work; if we could get the port that gets
+# used by the -R option before we hand off to the other side, then I could
+# pass it somehow through and know where to connect in that shell.  But even
+# though the man page says the port is "reported to the client at run time"
+# that appears to only be in an echo statement.  So there will be an extra
+# copy and paste step.  Meanwhile, I'm keeping this here in case I find a
+# better way in the future.  This would immediately follow the function
+# definition and the part that is left in that function would be in the else
+# clause.
+#
+  #if [ $# -eq 1 ]; then
+  #  [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
+  #  ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$1" -t "DOTSHARE_PORT=${DOTSHARE_PORT} exec bash -l"
+  #else
+  #  [do as done below]
+  #fi
+
+# I could probably clean up the echoes in each one too, maybe a function?
+# Nesting it in a variable would be messy because of the quoting needed to get
+# the right output...
+
+[[ "$(type -t s)" == 'alias' ]] && unalias s
+s() {
+  [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT=  ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
+  ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$@"
+}
+
+[[ "$(type -t r)" == 'alias' ]] && unalias r
+r() {
+  [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT=  ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
+  ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} -l root "$@"
+}
+
+[[ "$(type -t sf)" == 'alias' ]] && unalias sf
+sf() {
+  [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT=  ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
+  ssh ${S_FORCE} ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$@"
+}
+
+[[ "$(type -t rf)" == 'alias' ]] && unalias rf
+rf() {
+  [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT=  ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
+  ssh ${S_FORCE} ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} -l root "$@"
+}
+
+#
+# Programs/utilities
+#
+certcheck() {
+  if [ -z "$1" ] ; then
+    echo "Usage: certcheck <hostname>[:port]"
+    echo "       Defaults to port 443 if not specified."
+    return
+  fi
+  H=$1
+  [[ $1 =~ :[0-9]+$ ]] || \
+    H=$1":443"
+  echo -n Q | openssl s_client -connect $H | openssl x509 -noout -dates
+}
+alias rot13="tr 'a-zA-Z' 'n-za-mN-ZA-M'"
+alias vi='vim'
+
+
+# vim: set filetype=bash :