Skip to content

How is os.openDirInEditor triggered? #4512

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

Open
ivomac opened this issue Apr 25, 2025 · 3 comments
Open

How is os.openDirInEditor triggered? #4512

ivomac opened this issue Apr 25, 2025 · 3 comments

Comments

@ivomac
Copy link

ivomac commented Apr 25, 2025

I want to be able to open directories in my terminal editor. The config option os.openDirInEditor seems to be exactly what I want, but after setting it and trying to edit a directory in lazygit, I get an error: "Cannot edit directories: you can only edit individual files".

Is this feature implemented? It would be nice to "edit" folders if openDirInEditor is defined.

@stefanhaller
Copy link
Collaborator

At the moment, the config is only used in the Worktrees panel, when pressing o on a selected worktree. It was added for this purpose when worktree support was implemented.

It would totally make sense to use it when pressing e on a directory in the files panel. Do you want to try raising a PR for this? Let me know if you need any pointers.

As far as I can see, the main challenge is around range selection; right now we check that all selected items are files, and raise an error if not. This would have to change to allow either a range selection of only files, or one of only directories, and raise an error if it's a mixture. (I don't think it's important enough to handle the case where there's a range selection of both files and directories.)

In addition, FileCommands.GetOpenDirInEditorCmdStr would have to change so that it can take a slice of paths instead of just one, similar to GetEditCmdStr.

Maybe it's easier to only support the case of a single selected directory, that's probably good enough too.

A personal note: I wouldn't find the feature very useful myself, because the only directory I ever want to open in my editor is the repo root, and this doesn't always show up in the Files panel. I have a custom command for this that calls code ..

@ivomac
Copy link
Author

ivomac commented Apr 30, 2025

A custom command is also enough for me, didn't think of that, thanks!

For consistency I could try to implement editing single directories with e, but it is not as useful now. I can't imagine editing multiple directories at once is ever needed.

It would still help to change the documentation so that the purpose of the openDirInEditor is more clear. And maybe your command could be added to the list of custom commands in the wiki?

@ivomac ivomac closed this as completed May 4, 2025
@ivomac ivomac reopened this May 4, 2025
@ivomac
Copy link
Author

ivomac commented May 4, 2025

I'm trying to understand what is the best way to implement a simple open dir if a single dir is selected. The keymapping is done here:

{
Key: opts.GetKey(opts.Config.Universal.Edit),
Handler: self.withItems(self.edit),
GetDisabledReason: self.require(self.itemsSelected(self.canEditFiles)),
Description: self.c.Tr.Edit,
Tooltip: self.c.Tr.EditFileTooltip,
DisplayOnScreen: true,
},

How would you adapt this? Maybe something like this:

{ 
	Key:               opts.GetKey(opts.Config.Universal.Edit), 
	Handler:           self.dirOrFiles, 
	GetDisabledReason: self.any(self.singleItemSelected(), self.itemsSelected(self.canEditFiles)),
	Description:       self.c.Tr.Edit, 
	Tooltip:           self.c.Tr.EditFileTooltip, 
	DisplayOnScreen:   true, 
}, 

Here self.any is a complement of self.require that returns nil at the first callback that returns nil.

Then self.dirOrFiles would call self.openDir if a single dir is given, otherwise self.withItems(self.edit) like before.

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

No branches or pull requests

2 participants