{-# LANGUAGE OverloadedStrings #-}

module Lib
    ( ror
    ) where

import Turtle
import qualified Data.Map as Map
import Data.Maybe

-- rofi -show window -filter Chromium
-- getDistro :: Shell Line
-- getDistro = do
--   fstat <- stat "/etc/os-release"
--   case isRegularFile fstat of
--     True -> do
--       archMatch <- grep "NAME=\"Arch Linux\"" $ input "/etc/os-release"
--       if len archMatch > 0
        
--     _ -> do
--       return "foo"

-- getWmClass :: Text -> Shell Text
-- getWmClass app = do
--   v <- getDistro
--   if v == "foo"
--     then return "chromium"
--     else return "foo"


argparser :: Parser Text
argparser = argText "application to run or raise e.g. emacs.Emacs" "app"

ror :: IO ()
ror = do
  app <- options "run or raise an application" argparser

  let apps = Map.fromList [
        ("Navigator.Firefox", "firefox"),
        ("emacs.Emacs", "emacs"),
        ("terminator.Terminator", "terminator"),
        ("chromium.Chromium", "chromium"),
        ("xfce4-terminal.Xfce4-terminal", "xfce4-terminal"),
        ("st.tabbed", "tabbed -c -n st -r 2 -p s+1 st -w '' -f 'Iosevka-11'")]

  let appMatch = Map.lookup app apps

  case appMatch of
    Nothing -> die (app <> " not found.")
    _ -> sh $ shell ("wmctrl -x -a " <> app) empty .||. shell (fromJust appMatch) empty
