diff --git a/complete.go b/complete.go index 1dcd7736..8d3fd4be 100644 --- a/complete.go +++ b/complete.go @@ -55,6 +55,7 @@ var ( "cd", "select", "delete", + "mkdir", "rename", "source", "push", diff --git a/doc.go b/doc.go index 155908f6..63c889dd 100644 --- a/doc.go +++ b/doc.go @@ -56,6 +56,7 @@ The following commands are provided by lf: cd select delete (modal) + mkdir (modal) rename (modal) (default 'r') source push @@ -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) + +Create a new directory using the builtin method. +A custom 'mkdir' command can be defined to override this default. + source Read the configuration file given in the argument. diff --git a/docstring.go b/docstring.go index 979f85d6..5f45288e 100644 --- a/docstring.go +++ b/docstring.go @@ -59,6 +59,7 @@ The following commands are provided by lf: cd select delete (modal) + mkdir (modal) rename (modal) (default 'r') source push @@ -453,6 +454,11 @@ 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) + +Create a new directory using the builtin method. A custom 'mkdir' command can be +defined to override this default. + source Read the configuration file given in the argument. diff --git a/eval.go b/eval.go index bcc1807e..4e201d21 100644 --- a/eval.go +++ b/eval.go @@ -1894,6 +1894,30 @@ func (e *callExpr) eval(app *app, args []string) { normal(app) app.ui.menuBuf = listMarks(app.nav.marks) app.ui.cmdPrefix = "mark-remove: " + case "mkdir": + if !app.nav.init { + return + } + if cmd, ok := gOpts.cmds["mkdir"]; ok { + cmd.eval(app, e.args) + if gSingleMode { + app.nav.renew() + app.ui.loadFile(app, true) + } else { + if err := remote("send load"); err != nil { + app.ui.echoerrf("mkdir: %s", err) + return + } + } + } else { + if app.ui.cmdPrefix == ">" { + return + } + normal(app) + app.ui.cmdPrefix = "mkdir: " + } + app.ui.loadFile(app, true) + app.ui.loadFileInfo(app.nav) case "rename": if !app.nav.init { return @@ -2179,6 +2203,23 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.loadFile(app, true) app.ui.loadFileInfo(app.nav) } + case "mkdir: ": + app.ui.cmdPrefix = "" + app.nav.mkdirPath = filepath.Clean(replaceTilde(s)) + if err := app.nav.mkdir(); err != nil { + app.ui.echoerrf("mkdir: %s", err) + return + } + if gSingleMode { + app.nav.renew() + app.ui.loadFile(app, false) + app.ui.loadFileInfo(app.nav) + } else { + if err := remote("send load"); err != nil { + app.ui.echoerrf("mkdir: %s", err) + return + } + } case "rename: ": app.ui.cmdPrefix = "" if curr, err := app.nav.currFile(); err != nil { diff --git a/lf.1 b/lf.1 index 30414c4f..1bc1355b 100644 --- a/lf.1 +++ b/lf.1 @@ -71,6 +71,7 @@ The following commands are provided by lf: cd select delete (modal) + mkdir (modal) rename (modal) (default 'r') source push @@ -522,6 +523,12 @@ Remove the current file or selected file(s). A custom 'delete' command can be de .PP Rename the current file using the builtin method. A custom 'rename' command can be defined to override this default. .PP +.EX + mkdir (modal) +.EE +.PP +Create a new directory using the builtin method. A custom 'mkdir' command can be defined to override this default. +.PP .EX source .EE diff --git a/nav.go b/nav.go index faf1b880..1c876180 100644 --- a/nav.go +++ b/nav.go @@ -376,6 +376,7 @@ type nav struct { marks map[string]string renameOldPath string renameNewPath string + mkdirPath string selections map[string]int tags map[string]string selectionInd int @@ -1434,6 +1435,22 @@ func (nav *nav) del(app *app) error { return nil } +func (nav *nav) mkdir() error { + mkdirPath, err := filepath.Abs(nav.mkdirPath) + + if err != nil { + return err + } + + if err := os.MkdirAll(mkdirPath, os.ModePerm); err != nil { + return err + } + + nav.sel(mkdirPath) + + return nil +} + func (nav *nav) rename() error { oldPath := nav.renameOldPath newPath := nav.renameNewPath