WizardKit/.bin/Scripts/hw-diags
2Shirt d9a9ce0a86
Allow hw-diags to reattach to the tmux session
* The option to kill the current session and start a new was left in place
2018-09-12 18:56:39 -06:00

46 lines
1.1 KiB
Bash
Executable file

#!/bin/bash
#
## Wizard Kit: HW Diagnostics - Menu Launcher
SESSION_NAME="hw-diags"
WINDOW_NAME="Hardware Diagnostics"
MENU="hw-diags-menu"
function ask() {
while :; do
read -p "$1 [Y/N] " -r answer
if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then
return 0
elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then
return 1
fi
done
}
die () {
echo "$0:" "$@" >&2
exit 1
}
# Check for running session
if tmux list-session | grep -q "$SESSION_NAME"; then
echo "WARNING: tmux session $SESSION_NAME already exists."
echo ""
if ask "Connect to current session?"; then
# Do nothing, the command below will attach/connect
echo ""
elif ask "Kill current session and start new session?"; then
tmux kill-session -t "$SESSION_NAME" || \
die "Failed to kill session: $SESSION_NAME"
else
echo "Aborted."
echo ""
echo -n "Press Enter to exit... "
read -r
exit 0
fi
fi
# Start session
tmux new-session -A -s "$SESSION_NAME" -n "$WINDOW_NAME" "$MENU" $*