47 lines
1.4 KiB
Bash
Executable File
47 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
export TMUX_SESSION="app-tmux-$APP_NAME"
|
|
|
|
case "$2" in
|
|
-h|--help|"")
|
|
echo "commands:"
|
|
echo " exec execute tmux with commands"
|
|
echo " stat show the status"
|
|
echo;
|
|
echo "args:"
|
|
echo " -h, --help show the help documentation"
|
|
echo " -v, --version show the version"
|
|
;;
|
|
-v|--version)
|
|
echo "v0.0.1"
|
|
;;
|
|
stat)
|
|
CURR_TMUX_SESSION=$(tmux list-session 2>&1 | grep "$TMUX_SESSION")
|
|
if [ -z "$CURR_TMUX_SESSION" ]; then
|
|
echo "tmux session [$TMUX_SESSION] not exists."
|
|
else
|
|
echo "tmux session [$TMUX_SESSION] => $CURR_TMUX_SESSION"
|
|
tmux attach -t $TMUX_SESSION
|
|
fi
|
|
;;
|
|
exec)
|
|
CURR_TMUX_SESSION=$(tmux list-session 2>&1 | grep "$TMUX_SESSION")
|
|
if [ -n "$CURR_TMUX_SESSION" ]; then
|
|
echo "tmux session [$TMUX_SESSION] => $CURR_TMUX_SESSION"
|
|
tmux attach -t $TMUX_SESSION
|
|
else
|
|
echo "starting..."
|
|
tmux new-session -d -s "$TMUX_SESSION"
|
|
sleep 3
|
|
if [ -n "$TMUX_COMMAND" ]; then
|
|
tmux send-keys -t "$TMUX_SESSION" "$TMUX_COMMAND" Enter
|
|
fi
|
|
tmux attach -t "$TMUX_SESSION"
|
|
fi
|
|
;;
|
|
*)
|
|
echo "Invalid command: ${@:2}"
|
|
;;
|
|
esac
|
|
|