summaryrefslogtreecommitdiff
path: root/bin/ssh-and-tmux
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-06-21 17:53:01 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-06-21 17:53:57 -0700
commit6c61332e7051291f50952992086210909cb19674 (patch)
treeaba002438f2740216ff4c38e3c6d35fa55e3e49a /bin/ssh-and-tmux
parent6ee710e12d13ef8874a4b7b7a2529c0ee7de827c (diff)
downloaddotfiles-6c61332e7051291f50952992086210909cb19674.tar.gz
ssh-and-tmux: fix '-c $HOME' when attaching to containers
Diffstat (limited to 'bin/ssh-and-tmux')
-rwxr-xr-xbin/ssh-and-tmux18
1 files changed, 11 insertions, 7 deletions
diff --git a/bin/ssh-and-tmux b/bin/ssh-and-tmux
index cd66ecc2..2d9f683d 100755
--- a/bin/ssh-and-tmux
+++ b/bin/ssh-and-tmux
@@ -49,25 +49,29 @@ session="${2:-default}"
if printf '%s\0' "${mosh_hosts[@]}" \
| grep -Fxqz "$host"; then use_mosh=true; else use_mosh=false; fi
+if [ -n "$container_name" ]; then
+ home="\\\$HOME"
+ display_host="$container_name"
+else
+ home="\$HOME"
+ display_host="$host"
+fi
+
# Go via a login shell such that if there is no root tmux daemon yet, it ends
# up with a PATH as though the first tmux session were launched from an
# interactive shell. This affects launching programs directly from tmux
# (e.g. my C-\ e binding) for *all* sessions.
#
# mosh does execvp directly so for simplicity we assume remote SHELL is bash.
-cmd="tmux new-session -A -c \$HOME -s $session"
+cmd=$(printf "tmux new-session -A -c %s -s $session" $home)
if $use_mosh; then
cmd=(bash -l -c "$cmd")
else
cmd=(\$SHELL -l -c "\"$cmd\"")
fi
-if [ -n "$container_name" ]; then
- display_host="$container_name"
- cmd=($(printf "$container_cmd" "$container_name") -- "${cmd[@]}")
-else
- display_host="$host"
-fi
+[ -n "$container_name" ] \
+ && cmd=($(printf "$container_cmd" "$container_name") -- "${cmd[@]}")
if $use_mosh; then
mosh "$host" -- "${cmd[@]}"