<commit_before>package utils

import (
	"fmt"
	"os"
	"os/exec"

	"github.com/kardianos/osext"
)

const template = `<?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>local.dlite</string>
		<key>ProgramArguments</key>
		<array>
		  <string>/usr/bin/sudo</string>
		  <string>%s</string>
			<string>daemon</string>
		</array>
		<key>RunAtLoad</key>
		<true/>
  </dict>
</plist>
`

func CreateAgent() error {
	path, err := osext.Executable()
	if err != nil {
		return err
	}

	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	file, err := os.Create(filePath)
	if err != nil {
		return err
	}

	plist := fmt.Sprintf(template, path)
	_, err = file.WriteString(plist)
	if err != nil {
		return err
	}

	return changePermissions(filePath)
}

func RemoveAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	return os.RemoveAll(filePath)
}

func StopAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	err := exec.Command("launchctl", "stop", "local.dlite").Run()
	if err != nil {
		return err
	}

	return exec.Command("launchctl", "unload", filePath).Run()
}

func StartAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	err := exec.Command("launchctl", "load", filePath).Run()
	if err != nil {
		return err
	}

	return exec.Command("launchctl", "start", "local.dlite").Run()
}
<commit_msg>make sure launchagents dir exists, see #74<commit_after>package utils

import (
	"fmt"
	"os"
	"os/exec"

	"github.com/kardianos/osext"
)

const template = `<?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>local.dlite</string>
		<key>ProgramArguments</key>
		<array>
		  <string>/usr/bin/sudo</string>
		  <string>%s</string>
			<string>daemon</string>
		</array>
		<key>RunAtLoad</key>
		<true/>
  </dict>
</plist>
`

func CreateAgent() error {
	path, err := osext.Executable()
	if err != nil {
		return err
	}

	fileDir := os.ExpandEnv("$HOME/Library/LaunchAgents")
	err = os.MkdirAll(fileDir, 0755)
	if err != nil {
		return err
	}

	err = changePermissions(fileDir)
	if err != nil {
		return err
	}

	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	file, err := os.Create(filePath)
	if err != nil {
		return err
	}

	plist := fmt.Sprintf(template, path)
	_, err = file.WriteString(plist)
	if err != nil {
		return err
	}

	return changePermissions(filePath)
}

func RemoveAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	return os.RemoveAll(filePath)
}

func StopAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	err := exec.Command("launchctl", "stop", "local.dlite").Run()
	if err != nil {
		return err
	}

	return exec.Command("launchctl", "unload", filePath).Run()
}

func StartAgent() error {
	filePath := os.ExpandEnv("$HOME/Library/LaunchAgents/local.dlite.plist")
	err := exec.Command("launchctl", "load", filePath).Run()
	if err != nil {
		return err
	}

	return exec.Command("launchctl", "start", "local.dlite").Run()
}

{'fraction_non_alphanumeric': 0.18208778173190984, 'fraction_numerical': 0.0071174377224199285, 'mean_word_length': 4.095166163141994, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 2, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5954351', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1266, 'n_words': 243}