Skip to content

Commit 4ab18da

Browse files
committed
Add mosh wrapper
1 parent 831d92d commit 4ab18da

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

zsh/custom/utils.zsh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ fix-kde-hard() {
6767
kwin_wayland --replace &
6868
}
6969

70+
mosh() {
71+
local HOST="${1:?Usage: $0 HOST [mosh args...]}"
72+
shift || true
73+
74+
# Ask ssh what it would do after config expansion.
75+
# ssh -G prints: "remotecommand <value>" (empty if none; may also be absent on some versions)
76+
local RC="$(ssh -G -- "$HOST" 2>/dev/null | awk 'tolower($1)=="remotecommand" { $1=""; sub(/^ /,""); print; exit }')"
77+
78+
local MOSH_PATH="$(whence -p mosh)"
79+
# These may also be necessary:
80+
# -T -o ClearAllForwardings=yes
81+
local MOSH_SSH_OPTIONS="-o ExitOnForwardFailure=no -o ForwardAgent=no"
82+
# If RemoteCommand is non-empty, override it for the SSH that mosh uses.
83+
if [[ -n "${RC}" ]]; then
84+
"${MOSH_PATH}" --ssh="ssh ${MOSH_OPTIONS} -o RemoteCommand=none -o RequestTTY=no" -- "${HOST}" "$@"
85+
else
86+
"${MOSH_PATH}" --ssh="ssh ${MOSH_OPTIONS}" -- "${HOST}" "$@"
87+
fi
88+
}
89+
7090
pdfsearch() {
7191
# https://stackoverflow.com/questions/4643438/how-to-search-contents-of-multiple-pdf-files
7292
if [ $# -ne 2 ]; then
@@ -149,8 +169,7 @@ close-chats() {
149169
retry_until() {
150170
# From:
151171
# https://gitlab.com/drjaska-projects/configs/zsh/-/blob/master/.zshrc
152-
if [ "$2" = "" ]
153-
then
172+
if [ "$2" = "" ]; then
154173
echo "Usage: $0 sleeptime command"
155174
fi
156175

0 commit comments

Comments
 (0)