Skip to content

Add feature to open folder from terminal command #577

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

four-poetic-drew
Copy link

Introduce an argument that triggers the file picker to open immediately in the current directory when using edit . command in terminal

Addresses issue #543 feature request to open a folder.

Copy link
Contributor

@deadalusai deadalusai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the application should do if the user specifies a number of directory path arguments - perhaps use only the first or last one.

E.g. edit ./foo/ ./file.txt ./bar/

  • Open one buffer for file.txt
  • Launch file picker on foo/?
  • Launch file picker on bar/?

Comment on lines 242 to 246
else if arg == "."{
state.wants_file_picker=StateFilePicker::Open;
state.file_picker_pending_dir = DisplayablePathBuf::from_path(env::current_dir()?);
return Ok(false);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking for . specifically, you could instead check to see if arg represents a directory path?

E.g. below where we filter out directories, something like:

if p.is_dir() {
    state.wants_file_picker = StateFilePicker::Open;
    state.file_picker_pending_dir = DisplayablePathBuf::from_path(p);
    ...
}
else {
    paths.push(p);
}

This would allow you to type something like edit ., or edit ./src, etc.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks. Have updated. Seems to work sensibly:

edit . -> opens current folder
edit ./src -> opens src
edit <file> -> still opens file correctly
edit <folder> -> opens folder in current directory

@four-poetic-drew
Copy link
Author

I'm not sure what the application should do if the user specifies a number of directory path arguments - perhaps use only the first or last one.

E.g. edit ./foo/ ./file.txt ./bar/

  • Open one buffer for file.txt
  • Launch file picker on foo/?
  • Launch file picker on bar/?

Right now it just picks up the first argument. I'd be happy with that.

Tried playing around with the code command with vscode and couldn't really spot what it was doing -> think the open last workspace features were interfering.

@four-poetic-drew four-poetic-drew changed the title Add argument "." to open file picker immediately Add feature to open folder from terminal command Jul 12, 2025
Comment on lines 246 to 248
state.wants_file_picker=StateFilePicker::Open;
state.file_picker_pending_dir = DisplayablePathBuf::from_path(p);
return Ok(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure about early-returning here as we may miss non-directory arguments that we still need to open as documents. I'll think about it some more and probably merge it even in the current state. But I'd encourage you to try and restructure the code to make this possible.

More importantly, please run cargo fmt. 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have run cargo fmt now.

Am I correct in understanding that the non-directory argument you refer to means desired behaviour running edit file.txt opens the file.txt file?

I think currently it still does that as the return isn't reached if p.is_dir() does not return true. Instead it goes into the else block of paths.push(p) as it did before.

Happy to try to restructure the code, just not sure I understand correctly the ask.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I meant what happens if you run edit /path/ file.txt. Should it open file.txt and also open the file picker? I think so.

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

Successfully merging this pull request may close these issues.

3 participants