-
Notifications
You must be signed in to change notification settings - Fork 533
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
base: main
Are you sure you want to change the base?
Add feature to open folder from terminal command #577
Conversation
There was a problem hiding this 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/
?
src/bin/edit/main.rs
Outdated
else if arg == "."{ | ||
state.wants_file_picker=StateFilePicker::Open; | ||
state.file_picker_pending_dir = DisplayablePathBuf::from_path(env::current_dir()?); | ||
return Ok(false); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Right now it just picks up the first argument. I'd be happy with that. Tried playing around with the |
src/bin/edit/main.rs
Outdated
state.wants_file_picker=StateFilePicker::Open; | ||
state.file_picker_pending_dir = DisplayablePathBuf::from_path(p); | ||
return Ok(false); |
There was a problem hiding this comment.
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
. 🙂
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Introduce an argument that triggers the file picker to open immediately in the current directory when using
edit .
command in terminalAddresses issue #543 feature request to open a folder.