Define assh function to connect with autossh
and .bashrc
when the remote does not have a RemoteCommand specified
This commit is contained in:
parent
843cd752db
commit
c6d6ca0e04
2 changed files with 16 additions and 2 deletions
3
.bashrc
3
.bashrc
|
@ -146,8 +146,7 @@ if ! shopt -oq posix; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Customizations
|
# Customizations
|
||||||
|
if [ -f ~/.profile ] && [ -z "${SSH_CONNECTION}" ]; then
|
||||||
if [ -f ~/.profile ]; then
|
|
||||||
. ~/.profile
|
. ~/.profile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
15
.zshrc
15
.zshrc
|
@ -70,6 +70,21 @@ if [ -z "${SUDO_USER}" ] && [ -z "${SSH_CONNECTION}" ] && [ -z "${TERM_PROGRAM}"
|
||||||
tmux new -A -s local_tmux
|
tmux new -A -s local_tmux
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Define a function to use autossh with a custom bashrc
|
||||||
|
function assh() {
|
||||||
|
remote_file=$(mktemp)
|
||||||
|
if $(ssh "$@" "cat > ${remote_file}" < ~/.bashrc > /dev/null 2>&1); then
|
||||||
|
# Successfully copied bashrc to the remote. Source it upon ssh
|
||||||
|
autossh -t "$@" "bash --rcfile ${remote_file}; rm ${remote_file}"
|
||||||
|
else
|
||||||
|
# SSH Config specifies a RemoteCommand; connect normally
|
||||||
|
autossh "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# Use ssh completion for autossh
|
||||||
|
compdef autossh=ssh
|
||||||
|
compdef assh=ssh
|
||||||
|
|
||||||
# Custom dircolors
|
# Custom dircolors
|
||||||
[ -f ~/.dircolors ] && eval "$(dircolors ~/.dircolors)"
|
[ -f ~/.dircolors ] && eval "$(dircolors ~/.dircolors)"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue