git-annex/Utility/OSX.hs
Joey Hess 98a0a9ddff
optimise literalOsPath
Taking a ShortByteString and using OverloadedStrings should avoid it
being converted from a String.

The reason there is no IsString instance for OsPath is presumably the
bad behavior of IsString for ByteString on unicode btw. But
literalOsPath won't be used with unicode in git-annex.

Sponsored-by: unqueued
2025-01-27 16:36:29 -04:00

53 lines
1.4 KiB
Haskell

{- OSX stuff
-
- Copyright 2012 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
module Utility.OSX (
autoStartBase,
systemAutoStart,
userAutoStart,
genOSXAutoStartFile,
) where
import Common
import Utility.UserInfo
autoStartBase :: String -> OsPath
autoStartBase label = literalOsPath "Library"
</> literalOsPath "LaunchAgents"
</> toOsPath label <> literalOsPath ".plist"
systemAutoStart :: String -> OsPath
systemAutoStart label = literalOsPath "/" </> autoStartBase label
userAutoStart :: String -> IO OsPath
userAutoStart label = do
home <- myHomeDir
return $ toOsPath home </> autoStartBase label
{- Generates an OSX autostart plist file with a given label, command, and
- params to run at boot or login. -}
genOSXAutoStartFile :: String -> String -> [String] -> String
genOSXAutoStartFile label command params = unlines
[ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
, "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
, "<plist version=\"1.0\">"
, "<dict>"
, "<key>Label</key>"
, "<string>" ++ label ++ "</string>"
, "<key>ProgramArguments</key>"
, "<array>"
, unlines $ map (\v -> "<string>" ++ v ++ "</string>") (command:params)
, "</array>"
, "<key>RunAtLoad</key>"
, "<true/>"
, "</dict>"
, "</plist>"
]