comparison .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
comparison
equal deleted inserted replaced
264:bb69763716a7 265:df0b24d4fabd
1 # These items are used both in my normal shells, and available to be sourced
2 # in other connections via the shared files tunnel. This way I have a single
3 # place to set certain things that I use normally but will want to be able to
4 # use in other places as well.
5 #
6 # Note that if this is a normal shell, $DOTHOME will have been set there and
7 # will point to the normal location, but if this is a shared shell then the
8 # script that calls this needs to set that to wherever the temporary files
9 # have been deposited.
10
11 #
12 # Environment variables
13 #
14
15 [[ "$PS1" ]] && . ${DOTHOME}/bash_prompt
16
17 export PAGER=less
18 export EDITOR=vim
19 export VIMINIT="source ${DOTHOME}/.vim/vimrc"
20 export GVIMINIT="source ${DOTHOME}/.vim/gvimrc"
21 export HOST=`hostname -s`
22 export SCREENRC="${DOTHOME}/screenrc"
23
24 # Specifically, to hell with this terminal type
25 [[ $TERM =~ screen.xterm-256color ]] && export TERM=screen-256color
26
27 # Rather than have another separate file for aliases, just list them in here
28 # (while local aliases have some complicated and large functions, shared ones
29 # are pretty small anyway)
30
31 # Safe to set this here; if I'm running on a Mac it's my own machine and will
32 # have the local override for the correct arguments to 'ls'
33
34 alias ls='/bin/ls --color=auto -F'
35
36 #
37 # Shared SSH aliases
38 #
39 alias bh='ssh csesbh2.princeton.edu'
40 alias dh='ssh srhuston.net'
41 alias j='ssh joshua.srhuston.net'
42 alias x='ssh xanadu.astro.princeton.edu'
43
44 # For these, we check for a running share server, and if it exists then we
45 # pass the port through to the other side. The biggest problem with this
46 # whole thing is that I don't see a programmatic way to grab the port, so it's
47 # going to have to be a pretty simple command to pull things through, or a
48 # very ugly hack to set an environment variable with everything the script
49 # needs but the port which will have to be manual.. just no good way around it
50 # I can see.
51
52 # This variable just makes the later lines easier to read. Sets options to
53 # ignore the host keys, for times when I know that they might be different but
54 # I want to login anyway and maybe don't want to adjust the known_hosts file.
55 S_FORCE="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null"
56
57 # The tests ahead of each function are because I have 's' and 'r' aliases from
58 # before which might interfere. While I could prepend the definition with
59 # 'function' to override the error, you'd still get the wrong one when calling
60 # it because the alias would take priority. So if they exist, remove them -
61 # no harm done.
62 #
63 # I would love for this section to work; if we could get the port that gets
64 # used by the -R option before we hand off to the other side, then I could
65 # pass it somehow through and know where to connect in that shell. But even
66 # though the man page says the port is "reported to the client at run time"
67 # that appears to only be in an echo statement. So there will be an extra
68 # copy and paste step. Meanwhile, I'm keeping this here in case I find a
69 # better way in the future. This would immediately follow the function
70 # definition and the part that is left in that function would be in the else
71 # clause.
72 #
73 #if [ $# -eq 1 ]; then
74 # [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
75 # ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$1" -t "DOTSHARE_PORT=${DOTSHARE_PORT} exec bash -l"
76 #else
77 # [do as done below]
78 #fi
79
80 # I could probably clean up the echoes in each one too, maybe a function?
81 # Nesting it in a variable would be messy because of the quoting needed to get
82 # the right output...
83
84 [[ "$(type -t s)" == 'alias' ]] && unalias s
85 s() {
86 [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT= ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
87 ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$@"
88 }
89
90 [[ "$(type -t r)" == 'alias' ]] && unalias r
91 r() {
92 [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT= ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
93 ssh ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} -l root "$@"
94 }
95
96 [[ "$(type -t sf)" == 'alias' ]] && unalias sf
97 sf() {
98 [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT= ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
99 ssh ${S_FORCE} ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} "$@"
100 }
101
102 [[ "$(type -t rf)" == 'alias' ]] && unalias rf
103 rf() {
104 [[ -n $DOTSHARE_PORT ]] && echo 'ds setup: export DOTSHARE_PORT= ; eval "$(curl http://localhost:${DOTSHARE_PORT}/b)"'
105 ssh ${S_FORCE} ${DOTSHARE_PORT:+-R 0:localhost:$DOTSHARE_PORT} -l root "$@"
106 }
107
108 #
109 # Programs/utilities
110 #
111 certcheck() {
112 if [ -z "$1" ] ; then
113 echo "Usage: certcheck <hostname>[:port]"
114 echo " Defaults to port 443 if not specified."
115 return
116 fi
117 H=$1
118 [[ $1 =~ :[0-9]+$ ]] || \
119 H=$1":443"
120 echo -n Q | openssl s_client -connect $H | openssl x509 -noout -dates
121 }
122 alias rot13="tr 'a-zA-Z' 'n-za-mN-ZA-M'"
123 alias vi='vim'
124
125
126 # vim: set filetype=bash :