<commit_before>package main

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

// `direnv edit [PATH_TO_RC]`
var CmdEdit = &Cmd{
	Name:   "edit",
	Desc:   `Opens PATH_TO_RC or the current .envrc or a new .envrc into an $EDITOR and allow the file to be loaded afterwards.`,
	Args:   []string{"[PATH_TO_RC]"},
	NoWait: true,
	Fn: func(env Env, args []string) (err error) {
		var config *Config
		var rcPath string
		var foundRC *RC

		if config, err = LoadConfig(env); err != nil {
			return
		}

		if len(args) > 1 {
			rcPath = args[1]
		} else {
			foundRC = config.FindRC()
			if foundRC != nil {
				rcPath = foundRC.path
			} else {
				rcPath = ".envrc"
			}
		}

		editor := env["EDITOR"]
		if editor == "" {
			err = fmt.Errorf("$EDITOR not found.")
			return
		}

		cmd := exec.Command(editor, rcPath)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		if err = cmd.Run(); err != nil {
			return
		}

		foundRC = FindRC(rcPath, config.AllowDir())
		if foundRC != nil {
			foundRC.Allow()
		}

		return
	},
}
<commit_msg>Change the `direnv edit` logic a bit.<commit_after>package main

import (
	"fmt"
	"os"
	"os/exec"
	"path/filepath"
)

// `direnv edit [PATH_TO_RC]`
var CmdEdit = &Cmd{
	Name: "edit",
	Desc: `Opens PATH_TO_RC or the current .envrc into an $EDITOR and allow
  the file to be loaded afterwards.`,
	Args:   []string{"[PATH_TO_RC]"},
	NoWait: true,
	Fn: func(env Env, args []string) (err error) {
		var config *Config
		var rcPath string
		var foundRC *RC

		if config, err = LoadConfig(env); err != nil {
			return
		}

		if len(args) > 1 {
			rcPath = args[1]
			fi, _ := os.Stat(rcPath)
			if fi != nil && fi.IsDir() {
				rcPath = filepath.Join(rcPath, ".envrc")
			}
		} else {
			foundRC = config.FindRC()
			if foundRC == nil {
				return fmt.Errorf(".envrc not found. Use `direnv edit .` to create a new envrc in the current directory.")
			}
			rcPath = foundRC.path
		}

		editor := env["EDITOR"]
		if editor == "" {
			err = fmt.Errorf("$EDITOR not found.")
			return
		}

		cmd := exec.Command(editor, rcPath)
		cmd.Stdin = os.Stdin
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		if err = cmd.Run(); err != nil {
			return
		}

		foundRC = FindRC(rcPath, config.AllowDir())
		if foundRC != nil {
			foundRC.Allow()
		}

		return
	},
}

{'fraction_non_alphanumeric': 0.1474835886214442, 'fraction_numerical': 0.00175054704595186, 'mean_word_length': 2.7847682119205297, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2516898', 'n_tokens_mistral': 994, 'n_tokens_neox': 881, 'n_words': 247}