-
Notifications
You must be signed in to change notification settings - Fork 329
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
Add native 'mkdir' command. #1179
Conversation
You can't use Does this have an advantage over |
@ilyagr oops my bad, forgot about that one haha! I went ahead and changed the keybind! With the It also makes it more consistent, everyone will be using the same implementation, and if they don't like something about it they can always override it with a custom command. |
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 for the pull request! I have a couple more suggestions:
- It would be good to link the original issue so that it gets closed automatically.
- You might want to update the wiki section afterwards to encourage others to use this new feature.
doc.go
Outdated
@@ -435,6 +436,11 @@ A custom 'delete' command can be defined to override this default. | |||
Rename the current file using the builtin method. | |||
A custom 'rename' command can be defined to override this default. | |||
|
|||
mkdir (modal) (default 'n') |
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.
This should be changed to a
as well:
mkdir (modal) (default 'n') | |
mkdir (modal) (default 'a') |
And remember to run go generate
again so the changes are reflected.
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.
Oops! Completely forgot about that line haha
Everything should be good to go now. If the feature gets merged I'll make sure to update the wiki. |
eval.go
Outdated
@@ -2284,7 +2328,7 @@ func (e *callExpr) eval(app *app, args []string) { | |||
switch app.ui.cmdPrefix { | |||
case "!", "$", "%", "&": | |||
app.ui.cmdPrefix = ":" | |||
case ">", "rename: ": | |||
case ">", "rename: ", "mkdir: ": |
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.
Sorry, one more comment from me.
This will prevent the user from using backspace to 'cancel' out a mkdir
command (i.e. pressing backspace when the input line looks like mkdir: |
. I think it's better to allow the user to do this, similar to other commands like find
and mark-save
.
rename
is different because it prefills the line with the original filename, and users will generally press and hold backspace to delete the original filename, see #1052 for more details.
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 also thought about that but decided to leave it because I wasn't sure.
eval.go
Outdated
app.ui.loadFile(app, true) | ||
} else { | ||
if err := remote("send load"); err != nil { | ||
app.ui.echoerrf("rename: %s", err) |
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 went through the code one last time, just in case, I think this is a copy/paste error:
app.ui.echoerrf("rename: %s", err) | |
app.ui.echoerrf("mkdir: %s", err) |
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's right, fixed.
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 am approving this PR, however I am not the project owner so I cannot merge this, and we will have to wait.
Thanks once again for your changes! 😃
Edit: |
@bluesuncat is it really the default in many applications? To be fair I've never seen F7 used for creating new directories, if anything I've seen and used more a for that purpose. But I see no downside on changing it from a to F7 whatsoever |
I haven't used any other terminal file managers myself, but after some quick research I found that To me, it looks like a tradeoff - Another option would be to just leave this unmapped by default, and a default keybinding can always be added later. |
Right, although I don't mind if the keybind gets changed from a to F7, I feel that a is also more intuitive, I chose a because it means Leaving it unmapped is also a viable option, |
Another thing to consider is that both If there are no plans to implement 'rename append' in |
I did not follow the discussion but what is the advantage over having a native command vs. adding it to lfrc? On advantage of lfrc is that you can modify it however you like, e.g. I prefer to cd into the new directory:
|
Changing the default to be unmapped sounds good to me as well. One thing to point out here is that for an application like lf that users heavily customize, having as few default key mappings as possible is probably best, especially for keys that are easy to reach and that may already be used by custom commands. |
@laktak Yeah you can modify it however you like, and that functionality won't go away. Most users are familiar with their file manager software being able to create new directories by default, but lf is missing that feature. With it being built-in users won't have to setup an external command inside their lfrc. This is also more consistent, as everyone will get the same functionality. If they don't like the default behavior they can always override it with a custom command. |
@bluesuncat Yeah, leaving the command unmapped by default seems to be the best solution. |
Random piece of trivia: I believe this ultimately comes from https://en.wikipedia.org/wiki/Norton_Commander. Or, at least, if Norton Commander copied it from somewhere, I don't know what that would be. If you're on Windows, the best successor to Norton Commander AFAIK is https://www.farmanager.com/index.php?l=en. You're welcome to try it out, but make sure to return to using |
As a side note, when using |
Thanks, this answers my question from the very beginning of the thread. I think it should be more than a side note; you should put this in the the PR description. I'm guessing that if you modify @laktak's suggestion from #1179 (comment), changing I personally don't have a preference on whether this PR goes in or not. Having it work out of the box is useful, but having a snippet in the wiki/docs might also be good enough. |
This is something I had not realised that existed earlier, but I think it's worth mentioning this part of the FAQ:
I am now leaning towards the idea of not introducing any new code if it can be achieved through configuration. BTW there already is an example
Because creating a directory is a fairly common operation, perhaps it can be added to the |
I didn't know about that on the FAQ! But wouldn't this also apply to the 'rename' command? Renaming is also a trivial operation, yet it still is a built in feature. I find that to be contradicting of the philosophy in the FAQ. I agree that the example |
yue |
@zSnails That is a good point. I checked the commit history, it looks like the In any case, because |
One possible difference with +1 on adding mkdir to lfrc.example if this pr doesn't go in. We can add a mapping there too. Another advantage of this pr, by the way, is that it works on Windows. I forget how one creates directories with cmd.exe (it's been a while since I used Windows), though I'm sure there's a way. |
Yeah, I mentioned that when I updated the PR earlier today.
As far as I know, lf is not tied to any specific shell, and you can choose the shell of your preference using the It's convenient when there's a consistent way of doing something across different shells. It saves time and avoids the hassle of constantly adjusting your settings when switching between them. Also, it promotes uniformity and helps prevent errors that can arise from varying configurations. |
I would like to join the discussion because this will likely determine our decisions in the future when we get similar patches for
If I remember correctly, we had requests for a builtin The second aspect of this patch is to have a default keybinding this operation. If you ask me, the current state of this patch is the worst possible scenario. Modal commands are useful but they can be confusing for new users as they are usually only meant to be used with a keybinding. We will likely have users trying to type |
All of those are valid points. I guess we're better off just dropping the PR altogether. Also regarding the default keybind, the patch originally introduced the a keybind for this reason, as I felt it made sense to have a default keybind to the command. |
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.
The more I think about this, the more I believe this PR represents a step in the wrong direction. If this PR gets merged, users will invariably request other similar commands (e.g. touch
, chmod
, ln
as stated above) to be implemented builtins as well. This not only adds bloat and maintenance burden to the code, but also steers lf
in a direction where it becomes a tool that replaces the shell, rather than one that works seamlessly with the shell.
I was going to suggest that this be added to the lfrc.example
file to demonstrate how to use push
, but I see that there's already an example in there:
Lines 48 to 50 in 27ab67a
# define a custom 'rename' command without prompt for overwrite | |
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1 | |
# map r push :rename<space> |
That example should be sufficient for users to work out how to implement a mkdir
mapping, and if not then it is also mentioned in the wiki. We can also leave it up to users to decide on what key they want to use, since I'm not sure if we ever settled on a being a suitable default.
I think the best thing to do would be to close this PR, and also the related issue. Don't think that your effort has been wasted - if anything the discussion that has taken place here is very valuable in terms of the direction that lf
should take. 🙂
EDIT: I am not actually sure how to 'unapprove' a PR now that I have approved it, perhaps it's too late?
BTW the |
@joelim-work adding it to the Non-Features section of the readme sounds like a good idea, it might be good for preventing future PRs for things like these!
As far as I know the PR can still be closed, I don't know if closing it will close the related issue though. |
I actually think that I also think that implementing |
@zSnails I'm quite certain the linked issue will only be closed if the PR is merged, not if the PR is closed. @ilyagr By "Non-Features" I meant |
I have now added a list of such commands to the non-features section in the readme which should prevent similar patches in the future. I am also thinking of recycling the discussion here to add something about this to the FAQ for what it is worth. Thank you all for the feedback. I am generally not too happy to make changes to the example configuration though it is not specifically related to #1188 . The issue with the example configuration is that its purpose is still ill-defined and I am the one to be blamed for this. If anything, I think maybe we should get rid of it altogether or make it even more minimal by getting rid of everything but the most fundamentals (shell options and openers comes to mind). I think there is value in having a fully-featured configuration file though I'm not sure if the example configuration is appropriate for that as these things are quite opinionated by nature. At some point I thought maybe we could add a wiki page for users to share their dotfiles and/or link it from readme. It might as well be a separate project on its own similar to how oh-my-zsh or vim distributions work. I'm not sure if there is enough interest for such things though. |
Adds a
mkdir
command to allow the user to quickly create directories.When using
$mkdir
the screen will flicker, and the newly created directory will not be selected by default, this can cause confusion as trying to find the directory within a big directory could be an eyesore.To address this the user might want to create a custom command, however, users who lack the technical knowledge or just want something quick might find this cumbersome at worst.
Another issue one might encounter is that the behavior of the
mkdir
command might vary across operating systems.This PR attempts to solve these issues.
By having a built in command everyone will have the same functionality out of the box.
You can still override the command, so users who've created their own command can still use it.
closes #887