#!/bin/bash

# omarchy:summary=Launch the default editor selected via Omarchy defaults.
# omarchy:args=<path>

editor_file="$HOME/.local/state/omarchy/defaults/editor"
editor="nvim"

if [[ -f $editor_file ]]; then
  read -r editor <"$editor_file"
fi

[[ -n $editor ]] || editor="nvim"
omarchy-cmd-present "$editor" || editor="nvim"

case "${editor##*/}" in
nvim | vim | nano | micro | hx | helix | fresh)
  exec omarchy-launch-tui "$editor" "$@"
  ;;
*)
  exec setsid uwsm-app -- "$editor" "$@"
  ;;
esac
