#!/bin/bash

# restart instantWM from cli

# setup runtime dir variable 
RTD="$(instantruntimedir)"
RTD=${RTD:-'/tmp/instantos'}

if ! [ -e "$RTD"/wmpid ]; then
    if pgrep instantwm; then
        pkill instantwm
        exit
    fi
else
    WMPID="$(cat "$RTD"/wmpid)"
    if kill -0 "$WMPID"; then
        kill "$WMPID"
        rm "$RTD"/wmpid
        exit
    fi
fi

echo "no running window manager found"
