mirror of https://github.com/chubin/wttr.in
parent
b2832ceaf0
commit
1915a86dd7
@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=wttr.in services
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/home/igor/src/wttr.in/share/systemd/wttrin.sh session1
|
||||
ExecStop=/usr/bin/tmux kill-session -t session1
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SESSION_NAME=""
|
||||
SRC_DIR=/home/igor/src/wttr.in
|
||||
SERVICES_FILE=config/services/services.yaml
|
||||
|
||||
start_service() {
|
||||
local name="$1"
|
||||
local workdir="$2"
|
||||
local cmd="$3"
|
||||
|
||||
if [[ -z "$SESSION_NAME" ]]; then
|
||||
echo Unknown SESSION_NAME. Exiting >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local WINDOW_NAME="$name"
|
||||
local TEXT_TO_ENTER="cd $workdir && $cmd"
|
||||
|
||||
if ! tmux has-session -t "$SESSION_NAME" >& /dev/null; then
|
||||
tmux new-session -d -s "$SESSION_NAME"
|
||||
fi
|
||||
|
||||
# Create a new window if it doesn't exist
|
||||
tmux list-windows -t "$SESSION_NAME" | grep -q "^.\+ $WINDOW_NAME " || tmux new-window -t "$SESSION_NAME" -n "$WINDOW_NAME"
|
||||
|
||||
sleep 0.05
|
||||
|
||||
# Send text to the new window and press Enter
|
||||
tmux send-keys -t "$SESSION_NAME:$WINDOW_NAME" "$TEXT_TO_ENTER" C-m
|
||||
}
|
||||
|
||||
|
||||
main() {
|
||||
local name
|
||||
local cmd
|
||||
|
||||
if [[ -n $1 ]]; then
|
||||
SESSION_NAME=$1
|
||||
else
|
||||
echo Usage: $0 SESSION_NAME >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$SRC_DIR" || exit 1
|
||||
|
||||
set -x
|
||||
|
||||
while read -r line; do
|
||||
name=$(jq -r .name <<< "$line")
|
||||
workdir=$(jq -r .workdir <<< "$line")
|
||||
cmd=$(jq -r .command <<< "$line")
|
||||
|
||||
start_service "$name" "$workdir" "$cmd"
|
||||
done <<< "$(yq -c .services[] < "$SERVICES_FILE")"
|
||||
}
|
||||
|
||||
main "$@"
|
Loading…
Reference in new issue