<commit_before>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

package main

import (
	"fmt"
	"os/exec"
	"regexp"
	"strings"

	"github.com/carlosbrando/lunchy/agents"
)

func (c *Command) status() error {
	cmd := exec.Command("launchctl", "list")

	out, err := cmd.Output()
	if err != nil {
		return err
	}

	output := strings.Split(string(out), "\n")

	agents, err := agents.Find(c.pattern)
	if err != nil {
		return err
	}

	for _, line := range output {
		for _, agent := range agents {
			matched, err := regexp.MatchString(agent.Name, line)
			if err != nil {
				return err
			}

			if matched {
				fmt.Println(line)
			}
		}
	}

	return nil
}<commit_msg>Make it better than the original version.<commit_after>// Copyright 2013 <NAME>. All rights reserved.
// Use of this source code is governed by a MIT license
// that can be found in the LICENSE file.

package main

import (
	"fmt"
	"os/exec"
	"regexp"
	"strings"

	"github.com/carlosbrando/lunchy/agents"
)

var headerPrinted bool = false

// printHeader prints the header if it was not printed before.
func printHeader(header string) {
	if !headerPrinted {
		fmt.Println(header)
		headerPrinted = true
	}
}

func (c *Command) status() error {
	cmd := exec.Command("launchctl", "list")

	out, err := cmd.Output()
	if err != nil {
		return err
	}

	output := strings.Split(string(out), "\n")

	agents, err := agents.Find(c.pattern)
	if err != nil {
		return err
	}

	for _, line := range output {
		for _, agent := range agents {
			matched, err := regexp.MatchString(agent.Name, line)
			if err != nil {
				return err
			}

			if matched {
				printHeader(output[0])
				fmt.Println(line)
			}
		}
	}

	return nil
}
{'fraction_non_alphanumeric': 0.13175675675675674, 'fraction_numerical': 0.005067567567567568, 'mean_word_length': 3.057077625570776, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '1582839', 'n_tokens_mistral': 683, 'n_tokens_neox': 606, 'n_words': 195}