Sublime Forum

Custom editor not running

#1

Sublime Merge v2071
Machine: MacBook Pro 2021/macOS 12.3.1

My settings:

{
  	"theme": "Merge Dark.sublime-theme",
	"editor_argument_format": "${file}:${line}",
	"editor_path": "/Users/nivekmai/bin/opener",
	"side_bar_layout": "locations_as_column",
	"render_commit_dialog_message_at_top": true,
}

/Users/nivekmai/bin/opener file:

#!/usr/bin/env python

import os
import sys

print("here")
with open("/Users/nivekmai/test.txt", "a") as file1:
    file1.write("here\n")

if len(sys.argv) != 2:
    raise Exception("Must supply file:path as argument")

pathData = sys.argv[1]

print("here2")
with open("/Users/nivekmai/test.txt", "a") as file1:
    file1.write("here2\n")


if "local/project1" in pathData:
    os.system('/usr/local/bin/webstorm ' + pathData)
elif "src/project2" in pathData:
    os.system('/usr/local/bin/studio ' + pathData)
else:
    os.system('/Users/nivekmai/bin/subl ' + pathData)

Running my opener in terminal works fine:

/Users/nivekmai/bin/opener /Users/nivekmai/code/local/project1/foo.txt:5

or

 opener /Users/nivekmai/code/local/project1/foo.txt:5

Both properly open the file in webstorm, and write “here\nhere2” to ~/test.txt.

However using right click menu and “Open in Editor” doesn’t appear to do anything, no output is logged in the console (ctrl+`) nor is the test file written to.

As a sanity check, I also attempted to set editor_path to /usr/bin/vim (from which vim), and it doesn’t open in vim.

Removing the editor_path config does properly open in Sublime Text, but it doesn’t respect my default application settings (e.g. I changed .java to open in Android Studio, double clicking in finder properly opens studio, but “Open in Editor” still opens in Sublime Text, even after restart).

Did I misconfigure something?

0 Likes

#2

Hi @nivekmai,

Thanks for reaching out!

I’ve attempted to reproduce this behaviour on my end with no luck.
When you have a spare moment, could you share your Sublime Merge debug information?

  1. Open Sublime Merge
  2. Open one of the repositories mentioned above
  3. Via the Sublime Merge application menu, select Help > Debug Information
  4. Paste the information here
    • Before sharing this information, take a moment to redact anything that you consider confidential such as Git user information, confidential file paths, remote repository information etc

Additionally, could you confirm that you have a shortcut called subl located in /Users/nivekmai/bin/?

It’s also worth noting that the above vim config will not work, as the editor is currently assumed to be a graphical application. If you set the editor_path to the output of which subl, does the Open in Editor command operate as expected?

Thanks,
- Dylan

0 Likes

#3

Hi @djohnston,

I can confirm I have subl in /Users/nivekmai/bin/, and also that which subl points to that:

> ls -la `which subl`
lrwxr-xr-x  1 nivekmai  staff  62 May  6 16:04 /Users/nivekmai/bin/subl -> /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl

Here’s my debug output:

=== App Version Information ===
Build: 2071

=== Git Version Information ===
Using Git: git (system)
git version 2.31.1
PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:[redacted]:[redacted]/bin:[redacted]/bin/[redacted]:/opt/[redacted]/scripts:/opt/homebrew/bin:/usr/local/munki:/opt/[redacted]/hg/bin (from shell)
environment variables loaded using: /bin/zsh -l

=== Browse Page Information ===
HEAD: 85dc2633239c58c65a5c290d9ff8c3d814e5f4f7
Is in merge: 0
Is in cherry_pick: 0
Is in rebase: 0
Is in revert: 0

=== Git Status Information ===

=== Our Status Information ===

=== Git Config Information ===
alias.b=branch
alias.co=checkout
alias.d=diff --no-ext-diff
alias.fixup=!f() { TARGET=$(git rev-parse $1); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f
alias.k=!gitk --all&
alias.lg=!git lg1
alias.lg1=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
alias.lg2=log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
alias.lg3=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
alias.lp=log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
alias.sl=log --graph --full-history --all --color --pretty=tformat:%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s%x20%x1b[33m(%an)%x1b[0m
blame.ignorerevsfile=.git-blame-ignore-revs
branch.autosetupmerge=true
branch.autosetuprebase=always
branch.master.merge=refs/heads/master
branch.master.rebase=true
branch.master.remote=origin
color.ui=auto
commit.template=[redacted]
commit.verbose=true
core.bare=false
core.editor=vi
core.excludesfile=/Users/nivekmai/.gitignore_global
core.filemode=true
core.hookspath=./scripts/hooks
core.ignorecase=true
core.logallrefupdates=true
core.pager=diff-so-fancy | less --tabs=1,5 -R
core.precomposeunicode=true
core.repositoryformatversion=0
credential.helper=osxkeychain
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
fetch.prune=true
fetch.tags=true
http.sslcainfo=/etc/ssl/cert.pem
mergetool.sourcetree.cmd=/Users/nivekmai/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
pull.rebase=true
push.default=matching
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=ssh://[redacted]
[redacted submodule information]
user.email=[redacted]
user.name=[redacted]

=== Our Config Information ===
Git Config Path Information
Using config path: /etc/gitconfig
Using config path: /Users/nivekmai/.config/git/config
Using config path: /Users/nivekmai/.gitconfig
Using config path: /Users/nivekmai/[redacted]/.git/config

Our config output is different to the Git config output
alias.b=branch
alias.co=checkout
alias.d=diff --no-ext-diff
alias.fixup=!f() { TARGET=$(git rev-parse $1); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f
alias.k=!gitk --all&
alias.lg=!git lg1
alias.lg1=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
alias.lg2=log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
alias.lg3=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
alias.lp=log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
alias.sl=log --graph --full-history --all --color --pretty=tformat:%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s%x20%x1b[33m(%an)%x1b[0m
blame.ignorerevsfile=.git-blame-ignore-revs
branch.autosetupmerge=true
branch.autosetuprebase=always
branch.master.merge=refs/heads/master
branch.master.rebase=true
branch.master.remote=origin
color.ui=auto
commit.template=/Users/nivekmai/local/[redacted]
commit.verbose=true
core.bare=false
core.editor=vi
core.excludesfile=/Users/nivekmai/.gitignore_global
core.filemode=true
core.hookspath=./scripts/hooks
core.ignorecase=true
core.logallrefupdates=true
core.pager=diff-so-fancy | less --tabs=1,5 -R
core.precomposeunicode=true
core.repositoryformatversion=0
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
fetch.prune=true
fetch.tags=true
mergetool.sourcetree.cmd=/Users/nivekmai/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
pull.rebase=true
push.default=matching
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=ssh://[redacted]
[redacted submodule information]
user.email=[redacted]
user.name=[redacted]

=== Git Attributes Information ===
git check_attr --all output

=== Our Modified Files Newline Normalisation and EOL Information ===

=== Our Modified Files Flag Information ===
Ignoring symlinks: 0
0 Likes

#4

Hopefully we can figure out what’s happening, but in the meantime, I’ve discovered a workaround as a modification from https://forum.sublimetext.com/t/view-in-editor-to-view-a-specific-revision-menu-items/57605:

In Packages/User/File.sublime-menu:

[
    {
        "caption": "Open in Editor (workaround)…",
        "command": "git",
        "args": { "argv": ["smerge-open-in-editor", "$working_dir/$file", "1"] }
    }
]

and Packages/User/Diff Context.sublime-menu:

[
    {
        "caption": "Open in Editor (workaround)…",
        "command": "git",
        "args": { "argv": ["smerge-open-in-editor", "$working_dir/$path", "$line"] }
    }
]

Then in ~/.gitconfig:

[alias]
    smerge-open-in-editor = "!f() { /Users/nivekmai/bin/opener \"$1:$2\"; }; f"

NOTE: env vars are not loaded, so you need the full path here (e.g. just opener in the command whined that it couldn’t find it, even though it’s in my $PATH)

And now, I have an extra menu item which provides my desired functionality:
image

0 Likes

#5

Hi @nivekmai,

Thanks for the additional information!

I’ve been unable to track down the cause of this issue, but I’ve added some extra error logging to the open_in_editor command in the next Sublime Merge build. Once this is available, we should be able to track down the cause of this issue.

Thank you for your patience while we get this resolved.

Kind regards,
- Dylan

2 Likes

Open in editor... command stopped working
#6

@djohnston Here’s the debug output from the latest version:

=== App Version Information ===
Build: 2074

=== Git Version Information ===
Using Git: /Applications/Sublime Merge.app/Contents/Resources/Git/bin/git (bundled)
git version 2.35.3
PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/usr/local/munki (from shell)
environment variables loaded using: /bin/zsh -l

=== Browse Page Information ===
HEAD: cb150270d04d5537e0c0ad1cf32f1a757206256c
Is in merge: 0
Is in cherry_pick: 0
Is in rebase: 0
Is in revert: 0

=== Git Status Information ===
 M path/to/project/file1
 M path/to/project/file2
 M path/to/project/file3

=== Our Status Information ===
 M path/to/project/file1
 M path/to/project/file2
 M path/to/project/file3

=== Git Config Information ===
alias.b=branch
alias.co=checkout
alias.d=diff --no-ext-diff
alias.fixup=!f() { TARGET=$(git rev-parse $1); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f
alias.k=!gitk --all&
alias.lg=!git lg1
alias.lg1=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all
alias.lg2=log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all
alias.lg3=log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
alias.lp=log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
alias.sl=log --graph --full-history --all --color --pretty=tformat:%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s%x20%x1b[33m(%an)%x1b[0m
alias.smerge-open-in-editor=!f() { /Users/nivekmai/bin/opener "$1:$2"; }; f
blame.ignorerevsfile=tools/git/ignore-revs
branch.autosetuprebase=always
branch.master.merge=refs/heads/master
branch.master.rebase=true
branch.master.remote=origin
color.ui=auto
commit.template=tools/git-commit-template.txt
core.bare=false
core.editor=vi
core.excludesfile=/Users/nivekmai/.gitignore_global
core.filemode=true
core.fsmonitor=tools/git/hooks/query-watchman
core.ignorecase=true
core.logallrefupdates=true
core.pager=diff-so-fancy | less --tabs=1,5 -R
core.precomposeunicode=true
core.repositoryformatversion=0
core.untrackedcache=true
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
pull.rebase=true
push.default=matching
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=ssh://[redacted]
submodule.app/infra/smax/mocks.active=true
user.email=[redacted]
user.name=[redacted]

=== Our Config Information ===
Git Config Path Information
Using config path: /etc/gitconfig
Using config path: /Users/nivekmai/.config/git/config
Using config path: /Users/nivekmai/.gitconfig
Using config path: /Users/nivekmai/src/android/.git/config

Our config output is identical to the Git config output

=== Git Attributes Information ===
git check_attr --all output
path/to/project/file1
path/to/project/file2
path/to/project/file3

=== Our Modified Files Newline Normalisation and EOL Information ===
path/to/project/file1: unspecified - native
path/to/project/file2: unspecified - native
path/to/project/file3: unspecified - native

=== Our Modified Files Flag Information ===
Ignoring symlinks: 0
path/to/project/file1: Working - Normal File : Index - Normal File
path/to/project/file2: Working - Normal File : Index - Normal File
path/to/project/file3: Working - Normal File : Index - Normal File

Note: sublime merge was hanging on any git action until I switched to the bundled git binary.

Now when I attempt to set my opener script as the default editor, I get:

ERROR: env: python: No such file or directory

in the console output.

0 Likes

#7

Hi @nivekmai,

Thanks for providing this information!

Could you share the output of which python from the terminal?

Thanks,
- Dylan

0 Likes

#8

That’s /opt/homebrew/bin/python. I tried changing my opener script to start with $!/opt/homebrew/bin/python, but it didn’t fix it.

0 Likes

#9

If you change the script to use #!/usr/bin/env python3 does the error resolve?

0 Likes

#10

Nope, still has the same error:

ERROR: env: python: No such file or directory

(I do have a python3 installed, which python3 is /usr/local/bin/python3)

0 Likes