allow defining a custom rename command
This commit is contained in:
parent
bfd01e5ed8
commit
9f661344ed
@ -42,9 +42,9 @@ cmd open ${{
|
||||
esac
|
||||
}}
|
||||
|
||||
# rename current file without overwrite
|
||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
map r push :rename<space>
|
||||
# define a custom 'rename' command without prompt for overwrite
|
||||
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
# map r push :rename<space>
|
||||
|
||||
# make sure trash folder exists
|
||||
# %mkdir -p ~/.trash
|
||||
|
33
eval.go
33
eval.go
@ -470,7 +470,10 @@ func insert(app *app, arg string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case strings.HasPrefix(app.ui.cmdPrefix, "replace") ||
|
||||
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
|
||||
@ -481,8 +484,13 @@ func insert(app *app, arg string) {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
case app.ui.cmdPrefix == "mark-save: ":
|
||||
normal(app)
|
||||
|
||||
@ -829,14 +837,23 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-remove: "
|
||||
case "rename":
|
||||
if curr, err := app.nav.currFile(); err != nil {
|
||||
if cmd, ok := gOpts.cmds["rename"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.echoerrf("rename: %s:", err)
|
||||
return
|
||||
} else {
|
||||
}
|
||||
app.ui.cmdPrefix = "rename: "
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "sync":
|
||||
if err := app.nav.sync(); err != nil {
|
||||
app.ui.echoerrf("sync: %s", err)
|
||||
@ -1076,8 +1093,16 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
|
||||
if err := app.nav.rename(app.ui); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
default:
|
||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||
|
6
nav.go
6
nav.go
@ -751,16 +751,16 @@ func (nav *nav) rename(ui *ui) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
nav.renew()
|
||||
|
||||
// TODO: change selection
|
||||
if err := nav.sel(newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
ui.loadFile(nav)
|
||||
ui.loadFileInfo(nav)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user