Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write_scrollback_file:open to use $EDITOR #2504

Open
NishantJoshi00 opened this issue Oct 26, 2024 · 7 comments
Open

write_scrollback_file:open to use $EDITOR #2504

NishantJoshi00 opened this issue Oct 26, 2024 · 7 comments

Comments

@NishantJoshi00
Copy link

The write_scrollback_file:open command opens the scrollback in my OS default text editor.
Going through the code:

ghostty/src/Surface.zig

Lines 4184 to 4190 in ffc4c6e

switch (write_action) {
.open => try internal_os.open(self.alloc, path),
.paste => self.io.queueMessage(try termio.Message.writeReq(
self.alloc,
path,
), .unlocked),
}

It does seem to be the intended behavior, but would it be possible to instead open it in $EDITOR. In my case neovim.

@NishantJoshi00 NishantJoshi00 changed the title [FEAT]: write_scrollback_file:open to use $EDITOR feature: write_scrollback_file:open to use $EDITOR Oct 26, 2024
@mitchellh
Copy link
Contributor

Related: #2111

@mitchellh mitchellh changed the title feature: write_scrollback_file:open to use $EDITOR write_scrollback_file:open to use $EDITOR Oct 27, 2024
@mitchellh
Copy link
Contributor

As a design for this feature: I don't think this needs a new enum value for write_scrollback_file. I think we can default open to use EDITOR if it's set and fallback to open if it's not set. I think the rules can likely be slightly more complex than that but that could be the general idea.

The original idea behind using open was that we avoided a broken terminal situation; you could edit your config even if your config made Ghostty unusable for some reason. I think in practice this hasn't been a real issue since Ghostty is fairly resilient to configuration issues.

@grimm26
Copy link

grimm26 commented Dec 28, 2024

@NishantJoshi00 I also use neovim and you just need a desktop file to set filetypes for neovim and then set it as the default.

❯ cat ~/.local/share/applications/nvim.desktop
[Desktop Entry]
Name=Neovim
Categories=Utility;TextEditor;
Comment=Neovim Text Editor
Exec=nvim %F
Icon=gvim
Keywords=Text;editor;
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
StartupNotify=false
Terminal=true
Type=Application

Then set nvim as the default for plain text (assuming linux):

❯ xdg-mime default nvim.desktop text/plain

@ttys3
Copy link

ttys3 commented Dec 28, 2024

I think using xdg-open is good

@xulongwu4
Copy link

@NishantJoshi00 I also use neovim and you just need a desktop file to set filetypes for neovim and then set it as the default.

❯ cat ~/.local/share/applications/nvim.desktop
[Desktop Entry]
Name=Neovim
Categories=Utility;TextEditor;
Comment=Neovim Text Editor
Exec=nvim %F
Icon=gvim
Keywords=Text;editor;
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
StartupNotify=false
Terminal=true
Type=Application

Then set nvim as the default for plain text (assuming linux):

❯ xdg-mime default nvim.desktop text/plain

@grimm26 You suggestion seems to only work when the current ghostty terminal instance is spawned by another terminal instance? This is also mentioned in this issue: #3334 (comment)

@grimm26
Copy link

grimm26 commented Dec 30, 2024

@grimm26 You suggestion seems to only work when the current ghostty terminal instance is spawned by another terminal instance? This is also mentioned in this issue: #3334 (comment)

Very strange. This was working when I launch ghostty from the panel (Mint Linux 22), not from within another terminal. I had launched ghostty from another terminal previously in the same X session. Maybe I was using the same ghostty session?

I rebooted to start fresh and write_scrollback_file action did NOT work in ghostty started from the panel.
The other funny thing is that the open_config action does work.

@ScriptAlchemist
Copy link

I decided to look at the code and see if I can make the required edit. I found the open command in the os/open.zig after digging around for a bit. It seems adding the $EDITOR check there would be quick and simple

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants