Update launch-in-tmux to avoid some error messages
If tmux wasn't already running it would output an error but still work. The new approach will suppress that since we're not concerned if it's already running or not, just whether the desired session is. Modified the live macOS args to support connecting to the HW-Diags session remotely (more easily at least).
This commit is contained in:
parent
50e4164bf8
commit
cce8651e00
1 changed files with 43 additions and 43 deletions
|
|
@ -5,23 +5,23 @@
|
||||||
# Live macOS env workaround
|
# Live macOS env workaround
|
||||||
tmux_args=()
|
tmux_args=()
|
||||||
if [[ -e "/.wk-live-macos" ]]; then
|
if [[ -e "/.wk-live-macos" ]]; then
|
||||||
tmux_args=(-f "/etc/tmux.conf" -S "$(mktemp).socket")
|
tmux_args=(-f "/etc/tmux.conf" -S "/Volumes/RAM_Disk/.tmux.socket")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function ask() {
|
function ask() {
|
||||||
while :; do
|
while :; do
|
||||||
read -p "$1 [Y/N] " -r answer
|
read -p "$1 [Y/N] " -r answer
|
||||||
if echo "$answer" | grep -Eiq '^(y|yes|sure)$'; then
|
if echo "$answer" | grep -Eiq '^(y|yes|sure)$'; then
|
||||||
return 0
|
return 0
|
||||||
elif echo "$answer" | grep -Eiq '^(n|no|nope)$'; then
|
elif echo "$answer" | grep -Eiq '^(n|no|nope)$'; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function err () {
|
function err () {
|
||||||
echo "$0:" "$@" >&2
|
echo "$0:" "$@" >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function launch_in_tmux() {
|
function launch_in_tmux() {
|
||||||
|
|
@ -31,44 +31,44 @@ function launch_in_tmux() {
|
||||||
[[ -n "${TMUX_CMD:-}" ]] || return $(err "Required variable missing (TMUX_CMD)")
|
[[ -n "${TMUX_CMD:-}" ]] || return $(err "Required variable missing (TMUX_CMD)")
|
||||||
|
|
||||||
# Check for running session
|
# Check for running session
|
||||||
if tmux "${tmux_args[@]}" list-session | grep -q "$SESSION_NAME"; then
|
if tmux "${tmux_args[@]}" list-session 2>&1 | grep -q "$SESSION_NAME"; then
|
||||||
echo "WARNING: tmux session $SESSION_NAME already exists."
|
echo "WARNING: tmux session $SESSION_NAME already exists."
|
||||||
echo ""
|
echo ""
|
||||||
if ask "Connect to current session?"; then
|
if ask "Connect to current session?"; then
|
||||||
if [[ -n "${TMUX:-}" ]]; then
|
if [[ -n "${TMUX:-}" ]]; then
|
||||||
# Running inside TMUX, switch to session
|
# Running inside TMUX, switch to session
|
||||||
tmux "${tmux_args[@]}" switch-client -t "$SESSION_NAME"
|
tmux "${tmux_args[@]}" switch-client -t "$SESSION_NAME"
|
||||||
if ! jobs %% >/dev/null 2>&1; then
|
if ! jobs %% >/dev/null 2>&1; then
|
||||||
# No running jobs, try exiting abandoned tmux session
|
# No running jobs, try exiting abandoned tmux session
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Running outside TMUX, attach to session
|
|
||||||
tmux "${tmux_args[@]}" attach-session -t "$SESSION_NAME"
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
elif ask "Kill current session and start new session?"; then
|
|
||||||
tmux "${tmux_args[@]}" kill-session -t "$SESSION_NAME" || \
|
|
||||||
die "Failed to kill session: $SESSION_NAME"
|
|
||||||
else
|
else
|
||||||
echo "Aborted."
|
# Running outside TMUX, attach to session
|
||||||
return 1
|
tmux "${tmux_args[@]}" attach-session -t "$SESSION_NAME"
|
||||||
fi
|
fi
|
||||||
|
return 0
|
||||||
|
elif ask "Kill current session and start new session?"; then
|
||||||
|
tmux "${tmux_args[@]}" kill-session -t "$SESSION_NAME" || \
|
||||||
|
die "Failed to kill session: $SESSION_NAME"
|
||||||
|
else
|
||||||
|
echo "Aborted."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start session
|
# Start session
|
||||||
if [[ -n "${TMUX:-}" ]]; then
|
if [[ -n "${TMUX:-}" ]]; then
|
||||||
# Running inside TMUX, save current session/window names
|
# Running inside TMUX, save current session/window names
|
||||||
ORIGINAL_SESSION_NAME="$(tmux "${tmux_args[@]}" display-message -p '#S')"
|
ORIGINAL_SESSION_NAME="$(tmux "${tmux_args[@]}" display-message -p '#S')"
|
||||||
ORIGINAL_WINDOW_NAME="$(tmux "${tmux_args[@]}" display-message -p '#W')"
|
ORIGINAL_WINDOW_NAME="$(tmux "${tmux_args[@]}" display-message -p '#W')"
|
||||||
tmux "${tmux_args[@]}" rename-session "$SESSION_NAME"
|
tmux "${tmux_args[@]}" rename-session "$SESSION_NAME"
|
||||||
tmux "${tmux_args[@]}" rename-window "$WINDOW_NAME"
|
tmux "${tmux_args[@]}" rename-window "$WINDOW_NAME"
|
||||||
"$TMUX_CMD" "$@"
|
"$TMUX_CMD" "$@"
|
||||||
# Restore previous session/window names
|
# Restore previous session/window names
|
||||||
tmux "${tmux_args[@]}" rename-session "${ORIGINAL_SESSION_NAME}"
|
tmux "${tmux_args[@]}" rename-session "${ORIGINAL_SESSION_NAME}"
|
||||||
tmux "${tmux_args[@]}" rename-window "${ORIGINAL_WINDOW_NAME}"
|
tmux "${tmux_args[@]}" rename-window "${ORIGINAL_WINDOW_NAME}"
|
||||||
else
|
else
|
||||||
# Running outside TMUX, start/attach to session
|
# Running outside TMUX, start/attach to session
|
||||||
tmux "${tmux_args[@]}" new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$TMUX_CMD" "$@"
|
tmux "${tmux_args[@]}" new-session -s "$SESSION_NAME" -n "$WINDOW_NAME" "$TMUX_CMD" "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue