Created
September 4, 2012 11:57
-
-
Save rhizoome/3620588 to your computer and use it in GitHub Desktop.
Connect to remote host and take your tmux.conf and vimrc to the host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Connect to remote host and take your tmux.conf and vimrc to the host | |
# | |
# Connect: | |
# rmux $HOST | |
# Run tmux: | |
# tmux ... | |
# Run vim: | |
# vi ... | |
# Attach tmux session: | |
# tmuc [id] ... | |
# Attach first session: | |
# tmuk | |
RMUXID="ganwell-$1" | |
VIMRC="$HOME/bin/vimrc" | |
TMUXCONF="$HOME/.tmux.conf" | |
HOST="$1" | |
# will ask for password here | |
ssh -X -C -NfM -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$HOST" | |
# uses existing connection, doesn't ask for password | |
scp -q -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$VIMRC" "$HOST":"/tmp/$RMUXID-vimrc" | |
scp -q -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$TMUXCONF" "$HOST":"/tmp/$RMUXID-tmux" | |
ssh -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$HOST" \ | |
"cat > '/tmp/$RMUXID-init'" <<EOFSCPT | |
echo Setting up rmux | |
VISUAL=vi | |
if [ -e /etc/profile ]; then | |
source /etc/profile | |
fi | |
if [ -e "\$HOME/.profile" ]; then | |
source "\$HOME/.profile" | |
fi | |
if [ -e "\$HOME/.bash_profile" ]; then | |
source "\$HOME/.bash_profile" | |
fi | |
chmod 755 "/tmp/$RMUXID-tmux-start" | |
alias tmux="/tmp/$RMUXID-tmux-start" | |
alias tmuc="/tmp/$RMUXID-tmux-start attach -t" | |
alias tmuk="/tmp/$RMUXID-tmux-start attach" | |
if [ "\$TMUX" == "" ]; then | |
echo tmux sessions: | |
tmux ls 2> /dev/null | |
echo >> "/tmp/$RMUXID-tmux" | |
echo "set-option -g default-command \"bash --rcfile '/tmp/$RMUXID-init' -i\"" >> "/tmp/$RMUXID-tmux" | |
fi | |
LC_ALL="$LC_ALL" | |
LANG="$LANG" | |
alias vi='vim -u "/tmp/$RMUXID-vimrc"' | |
alias vim='vim -u "/tmp/$RMUXID-vimrc"' | |
EOFSCPT | |
ssh -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$HOST" \ | |
"cat > '/tmp/$RMUXID-tmux-start'" <<EOFSCPT | |
#!/bin/bash | |
if [ "\$1" == "attach" ]; then | |
if [ -e \$HOME/.rmux/attach ]; then | |
\$HOME/.rmux/attach | |
fi | |
fi | |
if [ -e "\$HOME/tmux-bin" ]; then | |
\$HOME/tmux-bin -f "/tmp/$RMUXID-tmux" "\$@" | |
else | |
if [ -e /opt/csw/bin/tmux ]; then | |
/opt/csw/bin/tmux -f "/tmp/$RMUXID-tmux" "\$@" | |
else | |
tmux -f "/tmp/$RMUXID-tmux" "\$@" | |
fi | |
fi | |
if [ "\$1" == "attach" ]; then | |
if [ -e \$HOME/.rmux/detach ]; then | |
\$HOME/.rmux/detach | |
fi | |
fi | |
echo out > /tmp/info | |
EOFSCPT | |
ssh -X -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$HOST" -t \ | |
"bash --rcfile '/tmp/$RMUXID-init' -i" | |
# Be nice and cleanup | |
ssh -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' "$HOST" rm -f "/tmp/$RMUXID-vimrc" "/tmp/$RMUXID-tmux" "/tmp/$RMUXID-tmux-start" "/tmp/$RMUXID-init" | |
# close the connection | |
ssh -o 'ControlPath=~/.ssh/cm/%r@%h:%p.conn' -O exit "$HOST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment