Skip to content

direnv edit: DebianAlternatives: 7323cc3:direnv/internal/cmd/cmd_edit.go#L91: {"open", "-t", "-W"}, // Opens with the default text editor on mac  #1246

@CAAHS

Description

@CAAHS

The open command is found, but the assumption this is a mac is too speculative at time in place for Linux.

To Reproduce

$ direnv edit .
direnv: $EDITOR not found.
xdg-open: unexpected option '-t'
Try 'xdg-open --help' for more information.
direnv: error exit status 1

Expected behavior

$ EDITOR=editor direnv edit .
# works

Environment

  • OS: Ubuntu 22.04
  • Shell: bash
  • Direnv version 2.25.2

Additional context

$ printenv | sed -n '/^EDITOR=/p'
# no output

// Editors contains a list of known editors and how to start them.
var Editors = [][]string{
{"subl", "-w"},
{"mate", "-w"},
{"open", "-t", "-W"}, // Opens with the default text editor on mac
{"nano"},
{"vim"},
{"emacs"},
}
func detectEditor(pathenv string) string {
for _, editor := range Editors {
if _, err := lookPath(editor[0], pathenv); err == nil {
return strings.Join(editor, " ")
}
}
return ""
}

$ namei -v `which open` | sed -nE '/^[fl]/p'
f: /usr/bin/open
l open -> /etc/alternatives/open
l   open -> /usr/bin/xdg-open
$ namei -v `which editor` | sed -nE '/^[fl]/p'
f: /usr/bin/editor
l editor -> /etc/alternatives/editor
l   editor -> /usr/bin/vim.basic
$ update-alternatives --get-selections | grep ^editor
editor                         auto     /bin/nano
$ update-alternatives --list editor
/bin/ed
/bin/nano
/usr/bin/vim.tiny
$ EDITOR=open direnv edit .
# works, but fails if .envrc does not exists

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions