Skip to content

Instantly share code, notes, and snippets.

@syphoxy
Created September 21, 2022 07:22
Show Gist options
  • Save syphoxy/9b9f4755c33ca716ffade7090fd16ac9 to your computer and use it in GitHub Desktop.
Save syphoxy/9b9f4755c33ca716ffade7090fd16ac9 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
if pidof sway >/dev/null 2>&1; then
echo 'sway is already running. exiting.' >&2
exit 1
fi
readonly XDG_CONFIG_HOME="$HOME/.config"
readonly LOG_FILE="$XDG_CONFIG_HOME/sway/log"
if [[ -f $LOG_FILE ]]; then
log_file_last_modified="$(stat -c %Y "$LOG_FILE")"
printf 'existing session log already found at %s.\n' "$LOG_FILE"
printf 'preserving previous session log at %s.%s.\n' "$LOG_FILE" "$log_file_last_modified"
echo
mv -v "$LOG_FILE" "${LOG_FILE}.${log_file_last_modified}"
fi
(printenv; sway) >"$LOG_FILE" 2>&1
echo 'sway exited.'
echo
printf 'session log is available at %s.\n' "$LOG_FILE"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment