Skip to content
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

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var (
"cd",
"select",
"delete",
"mkdir",
"rename",
"source",
"push",
Expand Down
6 changes: 6 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following commands are provided by lf:
cd
select
delete (modal)
mkdir (modal)
rename (modal) (default 'r')
source
push
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The following commands are provided by lf:
cd
select
delete (modal)
mkdir (modal)
rename (modal) (default 'r')
source
push
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down