2016-08-13 12:49:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-04-03 19:22:58 +00:00
|
|
|
"io"
|
2016-08-13 12:49:04 +00:00
|
|
|
"log"
|
2016-08-14 12:15:54 +00:00
|
|
|
"os"
|
2018-07-17 16:45:31 +00:00
|
|
|
"path/filepath"
|
2016-08-13 12:49:04 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2018-06-09 19:02:09 +00:00
|
|
|
"time"
|
2018-05-13 22:16:01 +00:00
|
|
|
"unicode"
|
2016-09-18 16:21:24 +00:00
|
|
|
"unicode/utf8"
|
2016-08-13 12:49:04 +00:00
|
|
|
)
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *setExpr) eval(app *app, args []string) {
|
2016-08-13 12:49:04 +00:00
|
|
|
switch e.opt {
|
2018-08-22 22:37:07 +00:00
|
|
|
case "anchorfind":
|
|
|
|
gOpts.anchorfind = true
|
|
|
|
case "noanchorfind":
|
|
|
|
gOpts.anchorfind = false
|
|
|
|
case "anchorfind!":
|
|
|
|
gOpts.anchorfind = !gOpts.anchorfind
|
2021-05-19 18:55:19 +00:00
|
|
|
case "autoquit":
|
|
|
|
gOpts.autoquit = true
|
|
|
|
case "noautoquit":
|
|
|
|
gOpts.autoquit = false
|
|
|
|
case "autoquit!":
|
|
|
|
gOpts.autoquit = !gOpts.autoquit
|
2021-08-01 14:00:10 +00:00
|
|
|
case "dircache":
|
|
|
|
gOpts.dircache = true
|
|
|
|
case "nodircache":
|
|
|
|
gOpts.dircache = false
|
|
|
|
case "dircache!":
|
|
|
|
gOpts.dircache = !gOpts.dircache
|
2017-06-03 11:12:43 +00:00
|
|
|
case "dircounts":
|
|
|
|
gOpts.dircounts = true
|
|
|
|
case "nodircounts":
|
|
|
|
gOpts.dircounts = false
|
|
|
|
case "dircounts!":
|
|
|
|
gOpts.dircounts = !gOpts.dircounts
|
2021-07-31 13:10:25 +00:00
|
|
|
case "dironly":
|
|
|
|
gOpts.dironly = true
|
|
|
|
app.nav.sort()
|
|
|
|
app.nav.position()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
case "nodironly":
|
|
|
|
gOpts.dironly = false
|
|
|
|
app.nav.sort()
|
|
|
|
app.nav.position()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
case "dironly!":
|
|
|
|
gOpts.dironly = !gOpts.dironly
|
|
|
|
app.nav.sort()
|
|
|
|
app.nav.position()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-11-21 20:13:33 +00:00
|
|
|
case "dirfirst":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option |= dirfirstSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2016-11-21 20:13:33 +00:00
|
|
|
case "nodirfirst":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option &= ^dirfirstSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2016-11-21 20:13:33 +00:00
|
|
|
case "dirfirst!":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option ^= dirfirstSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2021-12-25 17:49:30 +00:00
|
|
|
case "dirtyfiles":
|
|
|
|
toks := strings.Split(e.val, ":")
|
|
|
|
for _, s := range toks {
|
|
|
|
if s == "" {
|
|
|
|
app.ui.echoerr("dirtyfiles: glob should be non-empty")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err := filepath.Match(s, "a")
|
|
|
|
if err != nil {
|
|
|
|
app.ui.echoerrf("dirtyfiles: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gOpts.dirtyfiles = toks
|
|
|
|
app.nav.sort()
|
|
|
|
app.nav.position()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-04-15 16:26:51 +00:00
|
|
|
case "drawbox":
|
|
|
|
gOpts.drawbox = true
|
|
|
|
app.ui.renew()
|
2021-04-25 13:47:10 +00:00
|
|
|
if app.nav.height != app.ui.wins[0].h {
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
app.nav.regCache = make(map[string]*reg)
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-04-15 16:26:51 +00:00
|
|
|
case "nodrawbox":
|
|
|
|
gOpts.drawbox = false
|
|
|
|
app.ui.renew()
|
2021-04-25 13:47:10 +00:00
|
|
|
if app.nav.height != app.ui.wins[0].h {
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
app.nav.regCache = make(map[string]*reg)
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-04-15 16:26:51 +00:00
|
|
|
case "drawbox!":
|
|
|
|
gOpts.drawbox = !gOpts.drawbox
|
|
|
|
app.ui.renew()
|
2021-04-25 13:47:10 +00:00
|
|
|
if app.nav.height != app.ui.wins[0].h {
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
app.nav.regCache = make(map[string]*reg)
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:06:18 +00:00
|
|
|
case "globsearch":
|
|
|
|
gOpts.globsearch = true
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:06:18 +00:00
|
|
|
case "noglobsearch":
|
|
|
|
gOpts.globsearch = false
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:06:18 +00:00
|
|
|
case "globsearch!":
|
|
|
|
gOpts.globsearch = !gOpts.globsearch
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "hidden":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option |= hiddenSort
|
2017-11-30 20:11:37 +00:00
|
|
|
app.nav.sort()
|
2018-06-16 13:27:39 +00:00
|
|
|
app.nav.position()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "nohidden":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option &= ^hiddenSort
|
2017-11-30 20:11:37 +00:00
|
|
|
app.nav.sort()
|
2018-06-16 13:27:39 +00:00
|
|
|
app.nav.position()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "hidden!":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option ^= hiddenSort
|
2017-11-30 20:11:37 +00:00
|
|
|
app.nav.sort()
|
2018-06-16 13:27:39 +00:00
|
|
|
app.nav.position()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2020-06-11 01:11:40 +00:00
|
|
|
case "icons":
|
|
|
|
gOpts.icons = true
|
|
|
|
case "noicons":
|
|
|
|
gOpts.icons = false
|
|
|
|
case "icons!":
|
|
|
|
gOpts.icons = !gOpts.icons
|
2017-07-15 14:18:37 +00:00
|
|
|
case "ignorecase":
|
|
|
|
gOpts.ignorecase = true
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2021-08-21 13:40:24 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:18:37 +00:00
|
|
|
case "noignorecase":
|
|
|
|
gOpts.ignorecase = false
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2021-08-21 13:40:24 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:18:37 +00:00
|
|
|
case "ignorecase!":
|
|
|
|
gOpts.ignorecase = !gOpts.ignorecase
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2021-08-21 13:40:24 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-12-03 12:41:53 +00:00
|
|
|
case "ignoredia":
|
|
|
|
gOpts.ignoredia = true
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2018-12-03 12:41:53 +00:00
|
|
|
case "noignoredia":
|
|
|
|
gOpts.ignoredia = false
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2018-12-03 12:41:53 +00:00
|
|
|
case "ignoredia!":
|
|
|
|
gOpts.ignoredia = !gOpts.ignoredia
|
2020-11-06 17:10:15 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2021-08-21 13:40:24 +00:00
|
|
|
case "incfilter":
|
|
|
|
gOpts.incfilter = true
|
|
|
|
case "noincfilter":
|
|
|
|
gOpts.incfilter = false
|
|
|
|
case "incfilter!":
|
|
|
|
gOpts.incfilter = !gOpts.incfilter
|
2018-11-24 16:02:04 +00:00
|
|
|
case "incsearch":
|
|
|
|
gOpts.incsearch = true
|
|
|
|
case "noincsearch":
|
|
|
|
gOpts.incsearch = false
|
|
|
|
case "incsearch!":
|
|
|
|
gOpts.incsearch = !gOpts.incsearch
|
2021-01-29 16:36:27 +00:00
|
|
|
case "mouse":
|
|
|
|
if !gOpts.mouse {
|
|
|
|
gOpts.mouse = true
|
|
|
|
app.ui.screen.EnableMouse()
|
|
|
|
}
|
|
|
|
case "nomouse":
|
|
|
|
if gOpts.mouse {
|
|
|
|
gOpts.mouse = false
|
|
|
|
app.ui.screen.DisableMouse()
|
|
|
|
}
|
|
|
|
case "mouse!":
|
|
|
|
if gOpts.mouse {
|
|
|
|
gOpts.mouse = false
|
|
|
|
app.ui.screen.DisableMouse()
|
|
|
|
} else {
|
|
|
|
gOpts.mouse = true
|
|
|
|
app.ui.screen.EnableMouse()
|
|
|
|
}
|
2020-06-11 01:11:40 +00:00
|
|
|
case "number":
|
|
|
|
gOpts.number = true
|
|
|
|
case "nonumber":
|
|
|
|
gOpts.number = false
|
|
|
|
case "number!":
|
|
|
|
gOpts.number = !gOpts.number
|
2016-08-13 12:49:04 +00:00
|
|
|
case "preview":
|
2019-06-12 13:45:40 +00:00
|
|
|
if len(gOpts.ratios) < 2 {
|
|
|
|
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.preview = true
|
|
|
|
case "nopreview":
|
|
|
|
gOpts.preview = false
|
|
|
|
case "preview!":
|
2019-06-12 13:45:40 +00:00
|
|
|
if len(gOpts.ratios) < 2 {
|
|
|
|
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.preview = !gOpts.preview
|
2020-06-11 01:11:40 +00:00
|
|
|
case "relativenumber":
|
|
|
|
gOpts.relativenumber = true
|
|
|
|
case "norelativenumber":
|
|
|
|
gOpts.relativenumber = false
|
|
|
|
case "relativenumber!":
|
|
|
|
gOpts.relativenumber = !gOpts.relativenumber
|
2016-12-26 20:49:18 +00:00
|
|
|
case "reverse":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option |= reverseSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2016-12-26 20:49:18 +00:00
|
|
|
case "noreverse":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option &= ^reverseSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2016-12-26 20:49:18 +00:00
|
|
|
case "reverse!":
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType.option ^= reverseSort
|
2017-11-18 19:06:30 +00:00
|
|
|
app.nav.sort()
|
2018-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2017-07-15 14:46:22 +00:00
|
|
|
case "smartcase":
|
|
|
|
gOpts.smartcase = true
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:46:22 +00:00
|
|
|
case "nosmartcase":
|
|
|
|
gOpts.smartcase = false
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:46:22 +00:00
|
|
|
case "smartcase!":
|
|
|
|
gOpts.smartcase = !gOpts.smartcase
|
2021-08-21 13:40:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-12-03 12:41:53 +00:00
|
|
|
case "smartdia":
|
|
|
|
gOpts.smartdia = true
|
|
|
|
case "nosmartdia":
|
|
|
|
gOpts.smartdia = false
|
|
|
|
case "smartdia!":
|
|
|
|
gOpts.smartdia = !gOpts.smartdia
|
2021-04-06 15:57:23 +00:00
|
|
|
case "waitmsg":
|
|
|
|
gOpts.waitmsg = e.val
|
2017-03-16 13:22:42 +00:00
|
|
|
case "wrapscan":
|
|
|
|
gOpts.wrapscan = true
|
|
|
|
case "nowrapscan":
|
|
|
|
gOpts.wrapscan = false
|
|
|
|
case "wrapscan!":
|
|
|
|
gOpts.wrapscan = !gOpts.wrapscan
|
2019-05-12 14:21:45 +00:00
|
|
|
case "wrapscroll":
|
|
|
|
gOpts.wrapscroll = true
|
|
|
|
case "nowrapscroll":
|
|
|
|
gOpts.wrapscroll = false
|
|
|
|
case "wrapscroll!":
|
|
|
|
gOpts.wrapscroll = !gOpts.wrapscroll
|
2018-08-22 17:57:47 +00:00
|
|
|
case "findlen":
|
|
|
|
n, err := strconv.Atoi(e.val)
|
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("findlen: %s", err)
|
2018-08-22 17:57:47 +00:00
|
|
|
return
|
|
|
|
}
|
2018-08-22 22:29:59 +00:00
|
|
|
if n < 0 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("findlen: value should be a non-negative number")
|
2018-08-22 17:57:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gOpts.findlen = n
|
2018-06-09 19:02:09 +00:00
|
|
|
case "period":
|
|
|
|
n, err := strconv.Atoi(e.val)
|
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("period: %s", err)
|
2018-06-09 19:02:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n < 0 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("period: value should be a non-negative number")
|
2018-06-09 19:02:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gOpts.period = n
|
|
|
|
if n == 0 {
|
|
|
|
app.ticker.Stop()
|
|
|
|
} else {
|
|
|
|
app.ticker.Stop()
|
|
|
|
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
case "scrolloff":
|
|
|
|
n, err := strconv.Atoi(e.val)
|
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("scrolloff: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n < 0 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("scrolloff: value should be a non-negative number")
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gOpts.scrolloff = n
|
|
|
|
case "tabstop":
|
|
|
|
n, err := strconv.Atoi(e.val)
|
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("tabstop: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n <= 0 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("tabstop: value should be a positive number")
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gOpts.tabstop = n
|
2019-03-27 19:07:41 +00:00
|
|
|
case "errorfmt":
|
|
|
|
gOpts.errorfmt = e.val
|
2016-12-24 13:06:44 +00:00
|
|
|
case "filesep":
|
|
|
|
gOpts.filesep = e.val
|
2020-06-11 01:11:40 +00:00
|
|
|
case "hiddenfiles":
|
|
|
|
toks := strings.Split(e.val, ":")
|
|
|
|
for _, s := range toks {
|
|
|
|
if s == "" {
|
2020-07-19 21:44:37 +00:00
|
|
|
app.ui.echoerr("hiddenfiles: glob should be non-empty")
|
2020-06-11 01:11:40 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err := filepath.Match(s, "a")
|
|
|
|
if err != nil {
|
|
|
|
app.ui.echoerrf("hiddenfiles: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gOpts.hiddenfiles = toks
|
|
|
|
app.nav.sort()
|
|
|
|
app.nav.position()
|
|
|
|
app.ui.sort()
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "ifs":
|
|
|
|
gOpts.ifs = e.val
|
2020-06-11 01:11:40 +00:00
|
|
|
case "info":
|
2020-10-27 00:05:10 +00:00
|
|
|
if e.val == "" {
|
|
|
|
gOpts.info = nil
|
|
|
|
return
|
|
|
|
}
|
2020-06-11 01:11:40 +00:00
|
|
|
toks := strings.Split(e.val, ":")
|
|
|
|
for _, s := range toks {
|
|
|
|
switch s {
|
2020-10-27 00:05:10 +00:00
|
|
|
case "size", "time", "atime", "ctime":
|
2020-06-11 01:11:40 +00:00
|
|
|
default:
|
|
|
|
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gOpts.info = toks
|
2016-08-28 12:04:57 +00:00
|
|
|
case "previewer":
|
2020-06-07 17:53:25 +00:00
|
|
|
gOpts.previewer = replaceTilde(e.val)
|
2020-12-24 13:13:20 +00:00
|
|
|
case "cleaner":
|
|
|
|
gOpts.cleaner = replaceTilde(e.val)
|
2018-02-22 15:18:30 +00:00
|
|
|
case "promptfmt":
|
|
|
|
gOpts.promptfmt = e.val
|
2016-08-13 12:49:04 +00:00
|
|
|
case "ratios":
|
|
|
|
toks := strings.Split(e.val, ":")
|
|
|
|
var rats []int
|
|
|
|
for _, s := range toks {
|
2017-11-22 14:30:09 +00:00
|
|
|
n, err := strconv.Atoi(s)
|
2016-08-13 12:49:04 +00:00
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("ratios: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-22 14:30:09 +00:00
|
|
|
if n <= 0 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("ratios: value should be a positive number")
|
2017-11-22 14:30:09 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
rats = append(rats, n)
|
|
|
|
}
|
|
|
|
if gOpts.preview && len(rats) < 2 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
|
2017-11-22 14:30:09 +00:00
|
|
|
return
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
gOpts.ratios = rats
|
2020-09-01 12:42:44 +00:00
|
|
|
app.ui.wins = getWins(app.ui.screen)
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2020-06-11 01:11:40 +00:00
|
|
|
case "shell":
|
|
|
|
gOpts.shell = e.val
|
2021-04-04 15:23:14 +00:00
|
|
|
case "shellflag":
|
|
|
|
gOpts.shellflag = e.val
|
2018-06-26 18:14:55 +00:00
|
|
|
case "shellopts":
|
2021-02-21 16:21:06 +00:00
|
|
|
if e.val == "" {
|
|
|
|
gOpts.shellopts = nil
|
|
|
|
return
|
|
|
|
}
|
2018-06-26 18:14:55 +00:00
|
|
|
gOpts.shellopts = strings.Split(e.val, ":")
|
2020-06-11 01:11:40 +00:00
|
|
|
case "sortby":
|
|
|
|
switch e.val {
|
|
|
|
case "natural":
|
|
|
|
gOpts.sortType.method = naturalSort
|
|
|
|
case "name":
|
|
|
|
gOpts.sortType.method = nameSort
|
|
|
|
case "size":
|
|
|
|
gOpts.sortType.method = sizeSort
|
|
|
|
case "time":
|
|
|
|
gOpts.sortType.method = timeSort
|
|
|
|
case "ctime":
|
|
|
|
gOpts.sortType.method = ctimeSort
|
|
|
|
case "atime":
|
|
|
|
gOpts.sortType.method = atimeSort
|
|
|
|
case "ext":
|
|
|
|
gOpts.sortType.method = extSort
|
|
|
|
default:
|
|
|
|
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'")
|
|
|
|
return
|
2020-06-11 00:14:45 +00:00
|
|
|
}
|
2020-06-11 00:16:24 +00:00
|
|
|
app.nav.sort()
|
|
|
|
app.ui.sort()
|
2020-06-11 01:11:40 +00:00
|
|
|
case "timefmt":
|
|
|
|
gOpts.timefmt = e.val
|
2020-07-18 00:08:25 +00:00
|
|
|
case "truncatechar":
|
2020-07-19 21:44:37 +00:00
|
|
|
if runeSliceWidth([]rune(e.val)) != 1 {
|
|
|
|
app.ui.echoerr("truncatechar: value should be a single character")
|
2020-07-19 18:28:06 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-07-18 00:08:25 +00:00
|
|
|
gOpts.truncatechar = e.val
|
2016-08-13 12:49:04 +00:00
|
|
|
default:
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("unknown option: %s", e.opt)
|
2019-06-26 14:52:29 +00:00
|
|
|
return
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *mapExpr) eval(app *app, args []string) {
|
2016-09-02 18:32:11 +00:00
|
|
|
if e.expr == nil {
|
|
|
|
delete(gOpts.keys, e.keys)
|
2019-06-26 14:52:29 +00:00
|
|
|
} else {
|
|
|
|
gOpts.keys[e.keys] = e.expr
|
2016-09-02 18:32:11 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
func (e *cmapExpr) eval(app *app, args []string) {
|
2021-08-25 15:28:47 +00:00
|
|
|
if e.expr == nil {
|
2017-03-10 15:53:21 +00:00
|
|
|
delete(gOpts.cmdkeys, e.key)
|
2019-06-26 14:52:29 +00:00
|
|
|
} else {
|
2021-08-25 15:28:47 +00:00
|
|
|
gOpts.cmdkeys[e.key] = e.expr
|
2017-03-10 15:53:21 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2017-03-10 15:53:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *cmdExpr) eval(app *app, args []string) {
|
2016-09-02 18:32:11 +00:00
|
|
|
if e.expr == nil {
|
|
|
|
delete(gOpts.cmds, e.name)
|
2019-06-26 14:52:29 +00:00
|
|
|
} else {
|
|
|
|
gOpts.cmds[e.name] = e.expr
|
2016-09-02 18:32:11 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 14:11:56 +00:00
|
|
|
func preChdir(app *app) {
|
|
|
|
if cmd, ok := gOpts.cmds["pre-cd"]; ok {
|
|
|
|
cmd.eval(app, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-20 19:01:47 +00:00
|
|
|
func onChdir(app *app) {
|
|
|
|
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
|
|
|
cmd.eval(app, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-18 16:21:24 +00:00
|
|
|
func splitKeys(s string) (keys []string) {
|
|
|
|
for i := 0; i < len(s); {
|
2018-05-20 17:30:41 +00:00
|
|
|
r, w := utf8.DecodeRuneInString(s[i:])
|
|
|
|
if r != '<' {
|
2016-09-18 16:21:24 +00:00
|
|
|
keys = append(keys, s[i:i+w])
|
|
|
|
i += w
|
|
|
|
} else {
|
|
|
|
j := i + w
|
2018-05-20 17:30:41 +00:00
|
|
|
for r != '>' && j < len(s) {
|
|
|
|
r, w = utf8.DecodeRuneInString(s[j:])
|
2016-09-18 16:21:24 +00:00
|
|
|
j += w
|
|
|
|
}
|
|
|
|
keys = append(keys, s[i:j])
|
|
|
|
i = j
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-24 16:02:04 +00:00
|
|
|
func update(app *app) {
|
2020-10-14 16:42:44 +00:00
|
|
|
// Remove the current menu buffer
|
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.menuSelected = -2
|
|
|
|
|
2018-11-24 16:02:04 +00:00
|
|
|
switch {
|
|
|
|
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
|
|
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
|
|
|
|
2020-07-19 23:47:33 +00:00
|
|
|
dir := app.nav.currDir()
|
2021-01-29 15:27:27 +00:00
|
|
|
old := dir.ind
|
2020-07-19 23:47:33 +00:00
|
|
|
dir.ind = app.nav.searchInd
|
|
|
|
dir.pos = app.nav.searchPos
|
2018-11-24 16:02:04 +00:00
|
|
|
|
2021-01-29 15:27:27 +00:00
|
|
|
if _, err := app.nav.searchNext(); err != nil {
|
2020-07-04 00:32:05 +00:00
|
|
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-11-24 16:02:04 +00:00
|
|
|
}
|
|
|
|
case gOpts.incsearch && app.ui.cmdPrefix == "?":
|
|
|
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
|
|
|
|
2020-07-19 23:47:33 +00:00
|
|
|
dir := app.nav.currDir()
|
2021-01-29 15:27:27 +00:00
|
|
|
old := dir.ind
|
2020-07-19 23:47:33 +00:00
|
|
|
dir.ind = app.nav.searchInd
|
|
|
|
dir.pos = app.nav.searchPos
|
2018-11-24 16:02:04 +00:00
|
|
|
|
2021-01-29 15:27:27 +00:00
|
|
|
if _, err := app.nav.searchPrev(); err != nil {
|
2020-07-04 00:32:05 +00:00
|
|
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-11-24 16:02:04 +00:00
|
|
|
}
|
2021-08-21 13:40:24 +00:00
|
|
|
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
|
|
|
|
filter := string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
|
|
|
|
|
|
|
if err := app.nav.setFilter(strings.Split(filter, " ")); err != nil {
|
|
|
|
app.ui.echoerrf("filter: %s", err)
|
|
|
|
} else if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-11-24 16:02:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-29 15:28:29 +00:00
|
|
|
func restartIncCmd(app *app) {
|
|
|
|
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
app.nav.searchInd = dir.ind
|
|
|
|
app.nav.searchPos = dir.pos
|
|
|
|
update(app)
|
|
|
|
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
app.nav.prevFilter = dir.filter
|
|
|
|
update(app)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-17 09:57:51 +00:00
|
|
|
func resetIncCmd(app *app) {
|
2021-08-29 15:28:29 +00:00
|
|
|
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
dir.pos = app.nav.searchPos
|
|
|
|
if dir.ind != app.nav.searchInd {
|
|
|
|
dir.ind = app.nav.searchInd
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
|
|
|
} else if gOpts.incfilter && app.ui.cmdPrefix == "filter: " {
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
|
|
|
app.nav.setFilter(app.nav.prevFilter)
|
|
|
|
if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 17:21:24 +00:00
|
|
|
func normal(app *app) {
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
|
|
|
|
2019-05-14 17:21:24 +00:00
|
|
|
app.ui.menuBuf = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.menuSelected = -2
|
|
|
|
|
2019-05-14 17:21:24 +00:00
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.cmdTmp = nil
|
2019-05-14 17:21:24 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
|
|
|
}
|
|
|
|
|
2018-08-22 22:29:59 +00:00
|
|
|
func insert(app *app, arg string) {
|
2018-11-24 16:02:04 +00:00
|
|
|
switch {
|
|
|
|
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
update(app)
|
2021-08-21 13:40:24 +00:00
|
|
|
case gOpts.incfilter && app.ui.cmdPrefix == "filter: ":
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
update(app)
|
2018-11-24 16:02:04 +00:00
|
|
|
case app.ui.cmdPrefix == "find: ":
|
2018-08-22 22:29:59 +00:00
|
|
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
|
|
|
|
|
|
|
if gOpts.findlen == 0 {
|
|
|
|
switch app.nav.findSingle() {
|
|
|
|
case 0:
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
|
2018-08-22 22:29:59 +00:00
|
|
|
case 1:
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-08-22 22:29:59 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
default:
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if len(app.nav.find) < gOpts.findlen {
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, found := app.nav.findNext(); !found {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-08-22 22:29:59 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2018-11-24 16:02:04 +00:00
|
|
|
case app.ui.cmdPrefix == "find-back: ":
|
2018-08-22 22:29:59 +00:00
|
|
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
|
|
|
|
|
|
|
if gOpts.findlen == 0 {
|
|
|
|
switch app.nav.findSingle() {
|
|
|
|
case 0:
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
|
2018-08-22 22:29:59 +00:00
|
|
|
case 1:
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-08-22 22:29:59 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
default:
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if len(app.nav.find) < gOpts.findlen {
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, found := app.nav.findPrev(); !found {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-08-22 22:29:59 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2019-07-23 19:33:43 +00:00
|
|
|
case strings.HasPrefix(app.ui.cmdPrefix, "delete"):
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2019-02-06 12:56:41 +00:00
|
|
|
|
|
|
|
if arg == "y" {
|
2019-12-02 11:27:58 +00:00
|
|
|
if err := app.nav.del(app.ui); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("delete: %s", err)
|
2019-02-06 12:56:41 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
app.nav.unselect()
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("delete: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2019-02-06 12:56:41 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-07-21 17:40:57 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2019-02-06 12:56:41 +00:00
|
|
|
}
|
2020-07-16 21:28:32 +00:00
|
|
|
case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
|
2019-07-20 16:31:19 +00:00
|
|
|
normal(app)
|
|
|
|
|
|
|
|
if arg == "y" {
|
2019-08-12 11:52:27 +00:00
|
|
|
if err := app.nav.rename(); err != nil {
|
2019-07-20 16:31:19 +00:00
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2019-07-21 17:40:57 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-07-21 17:40:57 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2019-07-20 16:31:19 +00:00
|
|
|
}
|
2020-07-16 21:46:46 +00:00
|
|
|
case strings.HasPrefix(app.ui.cmdPrefix, "create"):
|
2020-07-16 21:28:32 +00:00
|
|
|
normal(app)
|
|
|
|
|
|
|
|
if arg == "y" {
|
|
|
|
if err := os.MkdirAll(filepath.Dir(app.nav.renameNewPath), os.ModePerm); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := app.nav.rename(); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2020-07-16 21:28:32 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2020-07-16 21:28:32 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-11-24 16:02:04 +00:00
|
|
|
case app.ui.cmdPrefix == "mark-save: ":
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2018-08-22 22:29:59 +00:00
|
|
|
|
2021-07-09 13:34:45 +00:00
|
|
|
app.nav.marks[arg] = app.nav.currDir().path
|
2019-06-25 18:38:34 +00:00
|
|
|
if err := app.nav.writeMarks(); err != nil {
|
|
|
|
app.ui.echoerrf("mark-save: %s", err)
|
|
|
|
}
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
if err := app.nav.sync(); err != nil {
|
|
|
|
app.ui.echoerrf("mark-save: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := remote("send sync"); err != nil {
|
|
|
|
app.ui.echoerrf("mark-save: %s", err)
|
|
|
|
}
|
2019-06-25 18:38:34 +00:00
|
|
|
}
|
2018-11-24 16:02:04 +00:00
|
|
|
case app.ui.cmdPrefix == "mark-load: ":
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2018-08-22 22:29:59 +00:00
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("getting current directory: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
path, ok := app.nav.marks[arg]
|
|
|
|
if !ok {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("mark-load: no such mark")
|
2018-08-22 22:29:59 +00:00
|
|
|
return
|
|
|
|
}
|
2021-08-23 14:11:56 +00:00
|
|
|
|
|
|
|
if wd != path {
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
2021-08-23 14:11:56 +00:00
|
|
|
preChdir(app)
|
|
|
|
}
|
|
|
|
|
2018-08-22 22:29:59 +00:00
|
|
|
if err := app.nav.cd(path); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("%s", err)
|
2018-08-22 22:29:59 +00:00
|
|
|
return
|
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-08-22 22:29:59 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
|
|
|
|
if wd != path {
|
|
|
|
app.nav.marks["'"] = wd
|
2021-08-29 15:28:29 +00:00
|
|
|
restartIncCmd(app)
|
2020-03-20 19:01:47 +00:00
|
|
|
onChdir(app)
|
2018-08-22 22:29:59 +00:00
|
|
|
}
|
2019-06-25 18:38:34 +00:00
|
|
|
case app.ui.cmdPrefix == "mark-remove: ":
|
|
|
|
normal(app)
|
|
|
|
if err := app.nav.removeMark(arg); err != nil {
|
|
|
|
app.ui.echoerrf("mark-remove: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := app.nav.writeMarks(); err != nil {
|
|
|
|
app.ui.echoerrf("mark-remove: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
if err := app.nav.sync(); err != nil {
|
|
|
|
app.ui.echoerrf("mark-remove: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := remote("send sync"); err != nil {
|
|
|
|
app.ui.echoerrf("mark-remove: %s", err)
|
|
|
|
}
|
2019-06-25 18:38:34 +00:00
|
|
|
}
|
2018-08-22 22:29:59 +00:00
|
|
|
default:
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *callExpr) eval(app *app, args []string) {
|
2016-08-13 12:49:04 +00:00
|
|
|
switch e.name {
|
|
|
|
case "up":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.up(e.count) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-09-08 21:04:44 +00:00
|
|
|
case "half-up":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.up(e.count * app.nav.height / 2) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-09-08 21:04:44 +00:00
|
|
|
case "page-up":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.up(e.count * app.nav.height) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-08-28 14:02:58 +00:00
|
|
|
case "down":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.down(e.count) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-09-08 21:04:44 +00:00
|
|
|
case "half-down":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.down(e.count * app.nav.height / 2) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-09-08 21:04:44 +00:00
|
|
|
case "page-down":
|
2021-01-18 18:30:52 +00:00
|
|
|
if app.nav.down(e.count * app.nav.height) {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
case "updir":
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
2021-08-23 14:11:56 +00:00
|
|
|
preChdir(app)
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
if err := app.nav.updir(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("%s", err)
|
2018-04-12 15:04:37 +00:00
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2021-08-29 15:28:29 +00:00
|
|
|
restartIncCmd(app)
|
2020-03-20 19:01:47 +00:00
|
|
|
onChdir(app)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "open":
|
2016-12-18 15:01:45 +00:00
|
|
|
curr, err := app.nav.currFile()
|
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("opening: %s", err)
|
2016-08-14 12:15:54 +00:00
|
|
|
return
|
|
|
|
}
|
2016-12-18 15:01:45 +00:00
|
|
|
|
|
|
|
if curr.IsDir() {
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
2021-08-23 14:11:56 +00:00
|
|
|
preChdir(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
err := app.nav.open()
|
2016-12-18 15:01:45 +00:00
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("opening directory: %s", err)
|
2016-12-18 15:01:45 +00:00
|
|
|
return
|
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-12-18 15:01:45 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2021-08-29 15:28:29 +00:00
|
|
|
restartIncCmd(app)
|
2020-03-20 19:01:47 +00:00
|
|
|
onChdir(app)
|
2016-08-14 12:37:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if gSelectionPath != "" {
|
|
|
|
out, err := os.Create(gSelectionPath)
|
|
|
|
if err != nil {
|
2016-08-17 20:00:16 +00:00
|
|
|
log.Printf("opening selection file: %s", err)
|
2016-10-27 19:24:42 +00:00
|
|
|
return
|
2016-08-14 12:37:22 +00:00
|
|
|
}
|
|
|
|
defer out.Close()
|
|
|
|
|
2016-10-24 19:18:31 +00:00
|
|
|
var path string
|
2019-02-06 12:56:41 +00:00
|
|
|
if list, err := app.nav.currFileOrSelections(); err == nil {
|
|
|
|
path = strings.Join(list, "\n")
|
2016-10-24 19:18:31 +00:00
|
|
|
} else {
|
|
|
|
return
|
2016-08-14 12:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = out.WriteString(path)
|
|
|
|
if err != nil {
|
2016-08-17 20:00:16 +00:00
|
|
|
log.Printf("writing selection file: %s", err)
|
2016-08-14 12:37:22 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 01:23:03 +00:00
|
|
|
app.quitChan <- struct{}{}
|
2016-10-27 19:24:42 +00:00
|
|
|
|
2016-08-14 12:37:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-06-28 18:20:43 +00:00
|
|
|
if cmd, ok := gOpts.cmds["open"]; ok {
|
2016-08-24 21:51:52 +00:00
|
|
|
cmd.eval(app, e.args)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
2016-08-28 14:02:58 +00:00
|
|
|
case "quit":
|
2020-12-27 01:23:03 +00:00
|
|
|
app.quitChan <- struct{}{}
|
2016-08-13 12:49:04 +00:00
|
|
|
case "top":
|
2021-01-18 22:47:09 +00:00
|
|
|
if app.nav.top() {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-05-15 21:20:05 +00:00
|
|
|
case "bottom":
|
2021-01-18 22:47:09 +00:00
|
|
|
if app.nav.bottom() {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
case "toggle":
|
2020-07-14 16:28:01 +00:00
|
|
|
if len(e.args) == 0 {
|
|
|
|
app.nav.toggle()
|
|
|
|
} else {
|
2020-07-19 23:47:33 +00:00
|
|
|
dir := app.nav.currDir()
|
2020-07-14 16:28:01 +00:00
|
|
|
for _, path := range e.args {
|
2021-08-25 15:57:17 +00:00
|
|
|
path = replaceTilde(path)
|
2020-07-19 23:22:31 +00:00
|
|
|
if !filepath.IsAbs(path) {
|
2020-07-19 23:47:33 +00:00
|
|
|
path = filepath.Join(dir.path, path)
|
2020-07-19 23:22:31 +00:00
|
|
|
}
|
|
|
|
if _, err := os.Lstat(path); !os.IsNotExist(err) {
|
2020-07-14 16:28:01 +00:00
|
|
|
app.nav.toggleSelection(path)
|
|
|
|
} else {
|
2020-07-19 23:22:31 +00:00
|
|
|
app.ui.echoerrf("toggle: %s", err)
|
2020-07-14 16:28:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-09 16:07:57 +00:00
|
|
|
case "invert":
|
|
|
|
app.nav.invert()
|
2018-07-09 18:22:10 +00:00
|
|
|
case "unselect":
|
|
|
|
app.nav.unselect()
|
2018-06-27 18:15:34 +00:00
|
|
|
case "copy":
|
2016-08-17 20:28:42 +00:00
|
|
|
if err := app.nav.save(true); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("copy: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-09 18:22:10 +00:00
|
|
|
app.nav.unselect()
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
if err := app.nav.sync(); err != nil {
|
|
|
|
app.ui.echoerrf("copy: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := remote("send sync"); err != nil {
|
|
|
|
app.ui.echoerrf("copy: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2016-11-10 20:25:03 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-06-27 18:15:34 +00:00
|
|
|
case "cut":
|
2016-08-17 20:28:42 +00:00
|
|
|
if err := app.nav.save(false); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("cut: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-09 18:22:10 +00:00
|
|
|
app.nav.unselect()
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
if err := app.nav.sync(); err != nil {
|
|
|
|
app.ui.echoerrf("cut: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := remote("send sync"); err != nil {
|
|
|
|
app.ui.echoerrf("cut: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2016-11-10 20:25:03 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-06-27 18:15:34 +00:00
|
|
|
case "paste":
|
|
|
|
if cmd, ok := gOpts.cmds["paste"]; ok {
|
2017-09-10 14:14:50 +00:00
|
|
|
cmd.eval(app, e.args)
|
2019-02-26 17:12:13 +00:00
|
|
|
} else if err := app.nav.paste(app.ui); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("paste: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-12-29 17:14:20 +00:00
|
|
|
case "delete":
|
|
|
|
if cmd, ok := gOpts.cmds["delete"]; ok {
|
|
|
|
cmd.eval(app, e.args)
|
2019-02-06 12:56:41 +00:00
|
|
|
app.nav.unselect()
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("delete: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2019-02-06 12:56:41 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-07-19 23:47:33 +00:00
|
|
|
list, err := app.nav.currFileOrSelections()
|
2019-07-23 19:33:43 +00:00
|
|
|
if err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("delete: %s", err)
|
2019-02-06 12:56:41 +00:00
|
|
|
return
|
|
|
|
}
|
2019-07-23 19:33:43 +00:00
|
|
|
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2020-07-19 23:47:33 +00:00
|
|
|
if len(list) == 1 {
|
|
|
|
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
|
2019-07-23 19:33:43 +00:00
|
|
|
} else {
|
2020-07-19 23:47:33 +00:00
|
|
|
app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] "
|
2019-07-23 19:33:43 +00:00
|
|
|
}
|
2018-12-29 17:14:20 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-12-19 18:53:47 +00:00
|
|
|
case "clear":
|
|
|
|
if err := saveFiles(nil, false); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("clear: %s", err)
|
2016-12-19 18:53:47 +00:00
|
|
|
return
|
|
|
|
}
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
if err := app.nav.sync(); err != nil {
|
|
|
|
app.ui.echoerrf("clear: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := remote("send sync"); err != nil {
|
|
|
|
app.ui.echoerrf("clear: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2016-12-19 18:53:47 +00:00
|
|
|
}
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-04-12 18:48:32 +00:00
|
|
|
case "draw":
|
2018-01-29 15:12:59 +00:00
|
|
|
case "redraw":
|
|
|
|
app.ui.renew()
|
2020-09-01 12:42:44 +00:00
|
|
|
app.ui.screen.Sync()
|
2021-04-14 11:49:41 +00:00
|
|
|
if app.nav.height != app.ui.wins[0].h {
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
app.nav.regCache = make(map[string]*reg)
|
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-06-15 13:33:54 +00:00
|
|
|
case "load":
|
|
|
|
app.nav.renew()
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-01-29 15:08:51 +00:00
|
|
|
case "reload":
|
2018-07-30 17:56:57 +00:00
|
|
|
if err := app.nav.reload(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("reload: %s", err)
|
2018-07-30 17:56:57 +00:00
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2017-11-19 18:55:13 +00:00
|
|
|
case "read":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = ":"
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "$"
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-pipe":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.ui.cmdPrefix = "%"
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-wait":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "!"
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-async":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "&"
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 17:05:22 +00:00
|
|
|
case "find":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2018-08-22 17:05:22 +00:00
|
|
|
app.ui.cmdPrefix = "find: "
|
2018-08-22 22:55:50 +00:00
|
|
|
app.nav.findBack = false
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 17:05:22 +00:00
|
|
|
case "find-back":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2018-08-22 17:05:22 +00:00
|
|
|
app.ui.cmdPrefix = "find-back: "
|
2018-08-22 22:55:50 +00:00
|
|
|
app.nav.findBack = true
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 17:05:22 +00:00
|
|
|
case "find-next":
|
2021-01-29 15:27:27 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
2018-08-22 17:05:22 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
2018-08-22 22:55:50 +00:00
|
|
|
if app.nav.findBack {
|
|
|
|
app.nav.findPrev()
|
|
|
|
} else {
|
|
|
|
app.nav.findNext()
|
|
|
|
}
|
2018-08-22 17:05:22 +00:00
|
|
|
}
|
2021-01-29 15:27:27 +00:00
|
|
|
if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-08-22 17:05:22 +00:00
|
|
|
case "find-prev":
|
2021-01-29 15:27:27 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
2018-08-22 17:05:22 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
2018-08-22 22:55:50 +00:00
|
|
|
if app.nav.findBack {
|
|
|
|
app.nav.findNext()
|
|
|
|
} else {
|
|
|
|
app.nav.findPrev()
|
|
|
|
}
|
2018-08-22 17:05:22 +00:00
|
|
|
}
|
2021-01-29 15:27:27 +00:00
|
|
|
if old != dir.ind {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
case "search":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "/"
|
2020-07-19 23:47:33 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
app.nav.searchInd = dir.ind
|
|
|
|
app.nav.searchPos = dir.pos
|
2018-08-22 22:55:50 +00:00
|
|
|
app.nav.searchBack = false
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2017-11-19 18:55:13 +00:00
|
|
|
case "search-back":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "?"
|
2020-07-19 23:47:33 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
app.nav.searchInd = dir.ind
|
|
|
|
app.nav.searchPos = dir.pos
|
2018-08-22 22:55:50 +00:00
|
|
|
app.nav.searchBack = true
|
2020-07-19 22:09:54 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2017-11-19 18:55:13 +00:00
|
|
|
case "search-next":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
2018-08-22 22:55:50 +00:00
|
|
|
if app.nav.searchBack {
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, err := app.nav.searchPrev(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 22:55:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, err := app.nav.searchNext(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 22:55:50 +00:00
|
|
|
}
|
2018-04-12 15:04:37 +00:00
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
|
|
|
case "search-prev":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
2018-08-22 22:55:50 +00:00
|
|
|
if app.nav.searchBack {
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, err := app.nav.searchNext(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 22:55:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-01-29 15:27:27 +00:00
|
|
|
if moved, err := app.nav.searchPrev(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-08-22 22:55:50 +00:00
|
|
|
}
|
2018-04-12 15:04:37 +00:00
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
2021-08-21 13:40:24 +00:00
|
|
|
case "filter":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2021-08-21 13:40:24 +00:00
|
|
|
app.ui.cmdPrefix = "filter: "
|
|
|
|
dir := app.nav.currDir()
|
|
|
|
app.nav.prevFilter = dir.filter
|
|
|
|
if len(e.args) == 0 {
|
|
|
|
app.ui.cmdAccLeft = []rune(strings.Join(dir.filter, " "))
|
|
|
|
} else {
|
|
|
|
app.ui.cmdAccLeft = []rune(strings.Join(e.args, " "))
|
|
|
|
}
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
case "setfilter":
|
|
|
|
log.Printf("filter: %s", e.args)
|
|
|
|
if err := app.nav.setFilter(e.args); err != nil {
|
|
|
|
app.ui.echoerrf("filter: %s", err)
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-07-09 18:35:04 +00:00
|
|
|
case "mark-save":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2018-07-09 18:35:04 +00:00
|
|
|
app.ui.cmdPrefix = "mark-save: "
|
|
|
|
case "mark-load":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2018-07-09 18:35:04 +00:00
|
|
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
|
|
|
app.ui.cmdPrefix = "mark-load: "
|
2019-06-25 18:38:34 +00:00
|
|
|
case "mark-remove":
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2019-06-25 18:38:34 +00:00
|
|
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
|
|
|
app.ui.cmdPrefix = "mark-remove: "
|
2019-07-20 16:31:19 +00:00
|
|
|
case "rename":
|
2019-07-21 17:40:57 +00:00
|
|
|
if cmd, ok := gOpts.cmds["rename"]; ok {
|
|
|
|
cmd.eval(app, e.args)
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2019-07-21 17:40:57 +00:00
|
|
|
}
|
2019-07-20 16:31:19 +00:00
|
|
|
} else {
|
2019-07-21 17:40:57 +00:00
|
|
|
curr, err := app.nav.currFile()
|
|
|
|
if err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s:", err)
|
|
|
|
return
|
|
|
|
}
|
2021-08-29 15:28:29 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
normal(app)
|
2019-07-20 16:31:19 +00:00
|
|
|
app.ui.cmdPrefix = "rename: "
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
|
|
|
|
}
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-07-21 17:40:57 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-11-08 21:39:39 +00:00
|
|
|
case "sync":
|
2016-11-10 20:43:54 +00:00
|
|
|
if err := app.nav.sync(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("sync: %s", err)
|
2016-11-08 21:39:39 +00:00
|
|
|
}
|
2016-08-28 14:02:58 +00:00
|
|
|
case "echo":
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echo(strings.Join(e.args, " "))
|
|
|
|
case "echomsg":
|
|
|
|
app.ui.echomsg(strings.Join(e.args, " "))
|
|
|
|
case "echoerr":
|
|
|
|
app.ui.echoerr(strings.Join(e.args, " "))
|
2016-08-28 14:02:58 +00:00
|
|
|
case "cd":
|
|
|
|
path := "~"
|
|
|
|
if len(e.args) > 0 {
|
|
|
|
path = e.args[0]
|
|
|
|
}
|
2018-07-17 16:45:31 +00:00
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("getting current directory: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 15:57:17 +00:00
|
|
|
path = replaceTilde(path)
|
2021-08-23 14:11:56 +00:00
|
|
|
if !filepath.IsAbs(path) {
|
|
|
|
path = filepath.Join(wd, path)
|
|
|
|
} else {
|
|
|
|
path = filepath.Clean(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wd != path {
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
2021-08-23 14:11:56 +00:00
|
|
|
preChdir(app)
|
|
|
|
}
|
|
|
|
|
2016-08-28 14:02:58 +00:00
|
|
|
if err := app.nav.cd(path); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("%s", err)
|
2016-08-28 14:02:58 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-17 16:45:31 +00:00
|
|
|
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-07-17 16:45:31 +00:00
|
|
|
|
|
|
|
if wd != path {
|
|
|
|
app.nav.marks["'"] = wd
|
2021-08-29 15:28:29 +00:00
|
|
|
restartIncCmd(app)
|
2020-03-20 19:01:47 +00:00
|
|
|
onChdir(app)
|
2018-07-17 16:45:31 +00:00
|
|
|
}
|
2018-03-27 17:47:17 +00:00
|
|
|
case "select":
|
|
|
|
if len(e.args) != 1 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("select: requires an argument")
|
2018-03-27 17:47:17 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-17 16:45:31 +00:00
|
|
|
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("getting current directory: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-08-25 15:57:17 +00:00
|
|
|
path := filepath.Dir(replaceTilde(e.args[0]))
|
2021-08-23 14:11:56 +00:00
|
|
|
if !filepath.IsAbs(path) {
|
|
|
|
path = filepath.Join(wd, path)
|
|
|
|
} else {
|
|
|
|
path = filepath.Clean(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
if wd != path {
|
2021-08-29 15:28:29 +00:00
|
|
|
resetIncCmd(app)
|
2021-08-23 14:11:56 +00:00
|
|
|
preChdir(app)
|
|
|
|
}
|
|
|
|
|
2018-08-22 17:05:22 +00:00
|
|
|
if err := app.nav.sel(e.args[0]); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("%s", err)
|
2018-03-27 17:47:17 +00:00
|
|
|
return
|
|
|
|
}
|
2018-07-17 16:45:31 +00:00
|
|
|
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2018-03-27 17:47:17 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-07-17 16:45:31 +00:00
|
|
|
|
|
|
|
if wd != path {
|
|
|
|
app.nav.marks["'"] = wd
|
2021-08-29 15:28:29 +00:00
|
|
|
restartIncCmd(app)
|
2020-03-20 19:01:47 +00:00
|
|
|
onChdir(app)
|
2018-07-17 16:45:31 +00:00
|
|
|
}
|
2019-06-20 15:17:47 +00:00
|
|
|
case "glob-select":
|
|
|
|
if len(e.args) != 1 {
|
|
|
|
app.ui.echoerr("glob-select: requires a pattern to match")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := app.nav.globSel(e.args[0], false); err != nil {
|
|
|
|
app.ui.echoerrf("%s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
case "glob-unselect":
|
|
|
|
if len(e.args) != 1 {
|
|
|
|
app.ui.echoerr("glob-unselect: requires a pattern to match")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := app.nav.globSel(e.args[0], true); err != nil {
|
|
|
|
app.ui.echoerrf("%s", err)
|
|
|
|
return
|
|
|
|
}
|
2018-06-28 14:13:43 +00:00
|
|
|
case "source":
|
|
|
|
if len(e.args) != 1 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("source: requires an argument")
|
2018-06-28 14:13:43 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-07 17:53:25 +00:00
|
|
|
app.readFile(replaceTilde(e.args[0]))
|
2019-06-26 14:52:29 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-09-18 16:21:24 +00:00
|
|
|
case "push":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(e.args) != 1 {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerr("push: requires an argument")
|
2018-05-20 17:30:41 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Println("pushing keys", e.args[0])
|
2020-09-04 18:25:19 +00:00
|
|
|
for _, val := range splitKeys(e.args[0]) {
|
|
|
|
app.ui.keyChan <- val
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
|
|
|
case "cmd-insert":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(e.args) == 0 {
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2020-10-14 16:42:44 +00:00
|
|
|
|
|
|
|
// Reset the completition menu as in bash/vim
|
|
|
|
// and update the pertinent variables
|
|
|
|
if app.ui.menuBuf != nil {
|
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.menuSelected = -2
|
|
|
|
}
|
|
|
|
|
2018-08-22 22:29:59 +00:00
|
|
|
insert(app, e.args[0])
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-escape":
|
2018-04-03 19:22:58 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2018-05-15 21:05:06 +00:00
|
|
|
case "cmd-complete":
|
2016-12-15 09:26:06 +00:00
|
|
|
var matches []string
|
2019-03-13 22:20:06 +00:00
|
|
|
switch app.ui.cmdPrefix {
|
|
|
|
case ":":
|
2018-05-15 21:05:06 +00:00
|
|
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
2019-03-13 22:20:06 +00:00
|
|
|
case "/", "?":
|
|
|
|
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
|
|
|
case "$", "%", "!", "&":
|
2018-05-15 21:05:06 +00:00
|
|
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
2019-03-13 22:20:06 +00:00
|
|
|
default:
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2020-10-14 16:42:44 +00:00
|
|
|
|
|
|
|
app.ui.draw(app.nav)
|
|
|
|
|
|
|
|
// If there are no multiple matches
|
|
|
|
// we do not need to show the list of matches
|
|
|
|
if len(matches) <= 1 {
|
|
|
|
app.ui.menuBuf = nil
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if b, err := listMatches(app.ui.screen, matches); err != nil {
|
|
|
|
app.ui.echoerrf("cmd-complete: %s", err)
|
|
|
|
} else {
|
|
|
|
app.ui.menuBuf = b
|
|
|
|
}
|
|
|
|
case "cmd-menu-complete":
|
|
|
|
var target []rune
|
|
|
|
|
|
|
|
// target will store the current menu query
|
|
|
|
// note that, as we will store the current selected value
|
|
|
|
// in cmdAccLeft, we can not call the complete function with its
|
|
|
|
// value, as it is already a final completition result
|
|
|
|
if app.ui.menuBuf == nil {
|
|
|
|
target = app.ui.cmdAccLeft
|
|
|
|
app.ui.cmdTmp = app.ui.cmdAccLeft
|
|
|
|
} else {
|
|
|
|
target = app.ui.cmdTmp
|
|
|
|
}
|
|
|
|
|
|
|
|
var matches []string
|
|
|
|
switch app.ui.cmdPrefix {
|
|
|
|
case ":":
|
|
|
|
matches, app.ui.cmdAccLeft = completeCmd(target)
|
|
|
|
case "/", "?":
|
|
|
|
matches, app.ui.cmdAccLeft = completeFile(target)
|
|
|
|
case "$", "%", "!", "&":
|
|
|
|
matches, app.ui.cmdAccLeft = completeShell(target)
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
app.ui.draw(app.nav)
|
|
|
|
|
|
|
|
if len(matches) > 1 {
|
|
|
|
step := 1
|
|
|
|
|
|
|
|
// Check if the tab-selecttion was inited
|
|
|
|
if app.ui.menuSelected == -2 {
|
|
|
|
app.ui.menuSelected = -1
|
|
|
|
} else {
|
|
|
|
app.ui.menuSelected = mod(app.ui.menuSelected+step, len(matches))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := listMatchesMenu(app.ui, matches); err != nil {
|
|
|
|
app.ui.echoerrf("cmd-menu-complete: %s", err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.menuSelected = -2
|
|
|
|
}
|
|
|
|
case "cmd-menu-complete-back":
|
|
|
|
var target []rune
|
|
|
|
|
|
|
|
if app.ui.menuBuf == nil {
|
|
|
|
target = app.ui.cmdAccLeft
|
|
|
|
app.ui.cmdTmp = app.ui.cmdAccLeft
|
|
|
|
} else {
|
|
|
|
target = app.ui.cmdTmp
|
|
|
|
}
|
|
|
|
|
|
|
|
var matches []string
|
|
|
|
switch app.ui.cmdPrefix {
|
|
|
|
case ":":
|
|
|
|
matches, app.ui.cmdAccLeft = completeCmd(target)
|
|
|
|
case "/", "?":
|
|
|
|
matches, app.ui.cmdAccLeft = completeFile(target)
|
|
|
|
case "$", "%", "!", "&":
|
|
|
|
matches, app.ui.cmdAccLeft = completeShell(target)
|
|
|
|
default:
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-15 09:26:06 +00:00
|
|
|
app.ui.draw(app.nav)
|
2020-10-14 16:42:44 +00:00
|
|
|
|
2016-12-15 09:26:06 +00:00
|
|
|
if len(matches) > 1 {
|
2020-10-14 16:42:44 +00:00
|
|
|
step := -1
|
|
|
|
|
|
|
|
// Check if the tab-selecttion was inited
|
|
|
|
if app.ui.menuSelected == -2 {
|
|
|
|
app.ui.menuSelected = -1
|
|
|
|
} else {
|
|
|
|
app.ui.menuSelected = mod(app.ui.menuSelected+step, len(matches))
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := listMatchesMenu(app.ui, matches); err != nil {
|
|
|
|
app.ui.echoerrf("cmd-menu-complete-back: %s", err)
|
|
|
|
}
|
2016-12-15 09:26:06 +00:00
|
|
|
} else {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.menuSelected = -2
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
|
|
|
case "cmd-enter":
|
2017-11-19 18:55:13 +00:00
|
|
|
s := string(append(app.ui.cmdAccLeft, app.ui.cmdAccRight...))
|
2021-08-21 13:40:24 +00:00
|
|
|
if len(s) == 0 && app.ui.cmdPrefix != "filter: " {
|
2016-12-15 09:26:06 +00:00
|
|
|
return
|
|
|
|
}
|
2020-10-14 16:42:44 +00:00
|
|
|
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.menuSelected = -2
|
|
|
|
|
2021-04-13 17:32:01 +00:00
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.cmdTmp = nil
|
|
|
|
|
2017-11-19 18:55:13 +00:00
|
|
|
switch app.ui.cmdPrefix {
|
2016-12-15 09:26:06 +00:00
|
|
|
case ":":
|
|
|
|
log.Printf("command: %s", s)
|
2019-02-06 12:01:16 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2019-02-08 16:19:28 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{":", s})
|
2016-12-15 09:26:06 +00:00
|
|
|
p := newParser(strings.NewReader(s))
|
|
|
|
for p.parse() {
|
|
|
|
p.expr.eval(app, nil)
|
|
|
|
}
|
|
|
|
if p.err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("%s", p.err)
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
|
|
|
case "$":
|
|
|
|
log.Printf("shell: %s", s)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2019-02-08 16:19:28 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"$", s})
|
2019-02-06 12:01:16 +00:00
|
|
|
app.runShell(s, nil, "$")
|
2018-03-26 18:22:18 +00:00
|
|
|
case "%":
|
|
|
|
log.Printf("shell-pipe: %s", s)
|
2019-02-08 16:19:28 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"%", s})
|
2019-02-06 12:01:16 +00:00
|
|
|
app.runShell(s, nil, "%")
|
2018-04-03 19:22:58 +00:00
|
|
|
case ">":
|
|
|
|
io.WriteString(app.cmdIn, s+"\n")
|
2018-04-06 15:57:57 +00:00
|
|
|
app.cmdOutBuf = nil
|
2016-12-15 09:26:06 +00:00
|
|
|
case "!":
|
|
|
|
log.Printf("shell-wait: %s", s)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2019-02-08 16:19:28 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"!", s})
|
2019-02-06 12:01:16 +00:00
|
|
|
app.runShell(s, nil, "!")
|
2016-12-15 09:26:06 +00:00
|
|
|
case "&":
|
|
|
|
log.Printf("shell-async: %s", s)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2019-02-08 16:19:28 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s})
|
2019-02-06 12:01:16 +00:00
|
|
|
app.runShell(s, nil, "&")
|
2016-12-15 09:26:06 +00:00
|
|
|
case "/":
|
2021-01-29 15:27:27 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
2018-11-24 16:02:04 +00:00
|
|
|
if gOpts.incsearch {
|
2020-07-19 23:47:33 +00:00
|
|
|
dir.ind = app.nav.searchInd
|
|
|
|
dir.pos = app.nav.searchPos
|
2018-11-24 16:02:04 +00:00
|
|
|
}
|
2016-12-15 09:26:06 +00:00
|
|
|
log.Printf("search: %s", s)
|
2019-02-06 12:01:16 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-23 15:58:24 +00:00
|
|
|
app.nav.search = s
|
2021-01-29 15:27:27 +00:00
|
|
|
if _, err := app.nav.searchNext(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if old != dir.ind {
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:06:18 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2016-12-15 09:26:06 +00:00
|
|
|
case "?":
|
2021-01-29 15:27:27 +00:00
|
|
|
dir := app.nav.currDir()
|
|
|
|
old := dir.ind
|
2018-11-24 16:02:04 +00:00
|
|
|
if gOpts.incsearch {
|
2020-07-19 23:47:33 +00:00
|
|
|
dir.ind = app.nav.searchInd
|
|
|
|
dir.pos = app.nav.searchPos
|
2018-11-24 16:02:04 +00:00
|
|
|
}
|
2016-12-15 09:26:06 +00:00
|
|
|
log.Printf("search-back: %s", s)
|
2019-02-06 12:01:16 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-23 15:58:24 +00:00
|
|
|
app.nav.search = s
|
2021-01-29 15:27:27 +00:00
|
|
|
if _, err := app.nav.searchPrev(); err != nil {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
2021-01-29 15:27:27 +00:00
|
|
|
} else if old != dir.ind {
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2017-07-15 14:06:18 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2021-08-21 13:40:24 +00:00
|
|
|
case "filter: ":
|
|
|
|
log.Printf("filter: %s", s)
|
|
|
|
app.ui.cmdPrefix = ""
|
|
|
|
if err := app.nav.setFilter(strings.Split(s, " ")); err != nil {
|
|
|
|
app.ui.echoerrf("filter: %s", err)
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2021-04-13 17:32:01 +00:00
|
|
|
case "find: ":
|
|
|
|
app.ui.cmdPrefix = ""
|
|
|
|
if moved, found := app.nav.findNext(); !found {
|
|
|
|
app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
|
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
|
|
|
case "find-back: ":
|
|
|
|
app.ui.cmdPrefix = ""
|
|
|
|
if moved, found := app.nav.findPrev(); !found {
|
|
|
|
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
|
|
|
|
} else if moved {
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2019-07-20 16:31:19 +00:00
|
|
|
case "rename: ":
|
|
|
|
app.ui.cmdPrefix = ""
|
|
|
|
if curr, err := app.nav.currFile(); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
} else {
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("getting current directory: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2020-06-17 02:17:00 +00:00
|
|
|
|
|
|
|
oldPath := filepath.Join(wd, curr.Name())
|
2020-07-16 21:46:46 +00:00
|
|
|
|
2021-08-25 15:57:17 +00:00
|
|
|
newPath := filepath.Clean(replaceTilde(s))
|
2020-07-16 21:46:46 +00:00
|
|
|
if !filepath.IsAbs(newPath) {
|
|
|
|
newPath = filepath.Join(wd, newPath)
|
|
|
|
}
|
2020-06-17 02:17:00 +00:00
|
|
|
|
|
|
|
if oldPath == newPath {
|
2019-12-17 22:39:02 +00:00
|
|
|
return
|
|
|
|
}
|
2020-06-17 02:17:00 +00:00
|
|
|
|
|
|
|
app.nav.renameOldPath = oldPath
|
|
|
|
app.nav.renameNewPath = newPath
|
2019-07-20 16:31:19 +00:00
|
|
|
|
2020-07-16 21:28:32 +00:00
|
|
|
newDir := filepath.Dir(newPath)
|
|
|
|
if _, err := os.Stat(newDir); os.IsNotExist(err) {
|
2020-07-16 23:17:24 +00:00
|
|
|
app.ui.cmdPrefix = "create '" + newDir + "' ? [y/N] "
|
2020-07-16 21:28:32 +00:00
|
|
|
return
|
2019-07-20 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 17:50:48 +00:00
|
|
|
oldStat, err := os.Lstat(oldPath)
|
2020-06-17 02:17:00 +00:00
|
|
|
if err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-12 17:50:48 +00:00
|
|
|
if newStat, err := os.Lstat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {
|
2020-07-16 23:17:24 +00:00
|
|
|
app.ui.cmdPrefix = "replace '" + newPath + "' ? [y/N] "
|
2019-07-20 16:31:19 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-12 11:52:27 +00:00
|
|
|
if err := app.nav.rename(); err != nil {
|
2019-07-20 16:31:19 +00:00
|
|
|
app.ui.echoerrf("rename: %s", err)
|
2019-07-21 17:40:57 +00:00
|
|
|
return
|
2019-07-20 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 20:38:05 +00:00
|
|
|
if gSingleMode {
|
|
|
|
app.nav.renew()
|
|
|
|
app.ui.loadFile(app.nav, true)
|
|
|
|
} else {
|
|
|
|
if err := remote("send load"); err != nil {
|
|
|
|
app.ui.echoerrf("rename: %s", err)
|
|
|
|
return
|
|
|
|
}
|
2019-07-21 17:40:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 14:01:29 +00:00
|
|
|
app.ui.loadFile(app.nav, true)
|
2019-07-21 17:40:57 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2019-07-20 16:31:19 +00:00
|
|
|
}
|
2016-12-15 09:26:06 +00:00
|
|
|
default:
|
2017-11-19 18:55:13 +00:00
|
|
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
case "cmd-history-next":
|
2018-05-20 17:42:19 +00:00
|
|
|
if app.ui.cmdPrefix == "" || app.ui.cmdPrefix == ">" {
|
2018-04-03 20:12:53 +00:00
|
|
|
return
|
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
if app.cmdHistoryInd > 0 {
|
|
|
|
app.cmdHistoryInd--
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
if app.cmdHistoryInd == 0 {
|
2019-05-17 15:52:58 +00:00
|
|
|
app.ui.menuBuf = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.menuSelected = -2
|
2019-05-17 15:52:58 +00:00
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
2020-10-14 16:42:44 +00:00
|
|
|
app.ui.cmdTmp = nil
|
2019-05-17 15:52:58 +00:00
|
|
|
app.ui.cmdPrefix = ":"
|
2017-05-15 09:30:50 +00:00
|
|
|
return
|
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
2021-08-29 15:28:29 +00:00
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = cmd.prefix
|
|
|
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
2018-05-15 21:16:49 +00:00
|
|
|
case "cmd-history-prev":
|
2018-05-20 17:42:19 +00:00
|
|
|
if app.ui.cmdPrefix == ">" {
|
|
|
|
return
|
|
|
|
}
|
2018-04-03 20:12:53 +00:00
|
|
|
if app.ui.cmdPrefix == "" {
|
2018-05-15 21:16:49 +00:00
|
|
|
app.cmdHistoryInd = 0
|
2018-04-03 20:12:53 +00:00
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
if app.cmdHistoryInd == len(app.cmdHistory) {
|
2017-11-19 18:55:13 +00:00
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-15 21:16:49 +00:00
|
|
|
app.cmdHistoryInd++
|
|
|
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
2021-08-29 15:28:29 +00:00
|
|
|
normal(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = cmd.prefix
|
|
|
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-delete":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
case "cmd-delete-back":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) == 0 {
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-left":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) == 0 {
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccRight = append([]rune{app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]}, app.ui.cmdAccRight...)
|
|
|
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-right":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
2018-05-15 21:00:20 +00:00
|
|
|
case "cmd-home":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
|
|
|
app.ui.cmdAccLeft = nil
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-end":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
|
|
|
app.ui.cmdAccRight = nil
|
2018-05-15 21:02:06 +00:00
|
|
|
case "cmd-delete-home":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) == 0 {
|
|
|
|
return
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
|
|
|
app.ui.cmdAccLeft = nil
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2017-11-19 18:55:13 +00:00
|
|
|
case "cmd-delete-end":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
|
|
|
app.ui.cmdAccRight = nil
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-13 22:19:26 +00:00
|
|
|
case "cmd-delete-unix-word":
|
2017-11-19 18:55:13 +00:00
|
|
|
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdYankBuf = []rune(string(app.ui.cmdAccLeft)[ind:])
|
|
|
|
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-15 21:28:11 +00:00
|
|
|
case "cmd-yank":
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2016-12-15 09:26:06 +00:00
|
|
|
case "cmd-transpose":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) < 2 {
|
|
|
|
return
|
2016-09-18 16:21:24 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-04-03 19:56:38 +00:00
|
|
|
case "cmd-interrupt":
|
|
|
|
if app.cmd != nil {
|
|
|
|
app.cmd.Process.Kill()
|
|
|
|
}
|
2019-05-14 17:21:24 +00:00
|
|
|
normal(app)
|
2018-05-05 16:37:14 +00:00
|
|
|
case "cmd-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc == nil {
|
|
|
|
return
|
2018-05-05 16:37:14 +00:00
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-05-05 16:37:14 +00:00
|
|
|
case "cmd-word-back":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
locs := reWordBeg.FindAllStringSubmatchIndex(string(app.ui.cmdAccLeft), -1)
|
2018-05-20 17:30:41 +00:00
|
|
|
if locs == nil {
|
|
|
|
return
|
2018-05-05 16:37:14 +00:00
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := locs[len(locs)-1][3]
|
2018-06-15 21:13:33 +00:00
|
|
|
old := app.ui.cmdAccRight
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccRight = append([]rune{}, []rune(string(app.ui.cmdAccLeft)[ind:])...)
|
2018-06-15 21:13:33 +00:00
|
|
|
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
|
2018-05-13 22:16:01 +00:00
|
|
|
case "cmd-capitalize-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ind := 0
|
|
|
|
for ; ind < len(app.ui.cmdAccRight) && unicode.IsSpace(app.ui.cmdAccRight[ind]); ind++ {
|
|
|
|
}
|
|
|
|
if ind >= len(app.ui.cmdAccRight) {
|
|
|
|
return
|
2018-05-13 22:16:01 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind = loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-13 22:25:26 +00:00
|
|
|
case "cmd-delete-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
2018-05-13 22:25:26 +00:00
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-13 22:30:53 +00:00
|
|
|
case "cmd-uppercase-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
2018-05-13 22:30:53 +00:00
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight)[:ind]))...)
|
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-13 22:38:19 +00:00
|
|
|
case "cmd-lowercase-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc == nil {
|
|
|
|
return
|
2018-05-13 22:38:19 +00:00
|
|
|
}
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight)[:ind]))...)
|
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2018-05-14 16:38:35 +00:00
|
|
|
case "cmd-transpose-word":
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccLeft) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
locs := reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
|
|
|
if len(locs) < 2 {
|
|
|
|
return
|
|
|
|
}
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
if len(app.ui.cmdAccRight) > 0 {
|
2019-12-23 13:00:10 +00:00
|
|
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
2018-05-20 17:30:41 +00:00
|
|
|
if loc != nil {
|
2019-12-23 13:00:10 +00:00
|
|
|
ind := loc[3]
|
2019-12-22 23:35:32 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
|
|
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
2018-05-14 16:38:35 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
}
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
locs = reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
beg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]
|
|
|
|
beg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
var acc []rune
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2019-12-22 23:35:32 +00:00
|
|
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[:beg1])...)
|
|
|
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg2:end2])...)
|
|
|
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end1:beg2])...)
|
|
|
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg1:end1])...)
|
|
|
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end2:])...)
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = acc
|
2018-11-24 16:02:04 +00:00
|
|
|
update(app)
|
2016-08-13 12:49:04 +00:00
|
|
|
default:
|
|
|
|
cmd, ok := gOpts.cmds[e.name]
|
|
|
|
if !ok {
|
2019-02-28 18:58:14 +00:00
|
|
|
app.ui.echoerrf("command not found: %s", e.name)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
cmd.eval(app, e.args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *execExpr) eval(app *app, args []string) {
|
2017-11-19 18:55:13 +00:00
|
|
|
switch e.prefix {
|
2016-08-13 12:49:04 +00:00
|
|
|
case "$":
|
|
|
|
log.Printf("shell: %s -- %s", e, args)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.runShell(e.value, args, e.prefix)
|
|
|
|
case "%":
|
|
|
|
log.Printf("shell-pipe: %s -- %s", e, args)
|
|
|
|
app.runShell(e.value, args, e.prefix)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "!":
|
|
|
|
log.Printf("shell-wait: %s -- %s", e, args)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.runShell(e.value, args, e.prefix)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "&":
|
|
|
|
log.Printf("shell-async: %s -- %s", e, args)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.runShell(e.value, args, e.prefix)
|
2016-08-13 12:49:04 +00:00
|
|
|
default:
|
2017-11-19 18:55:13 +00:00
|
|
|
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
func (e *listExpr) eval(app *app, args []string) {
|
2020-07-03 15:29:55 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
for _, expr := range e.exprs {
|
|
|
|
expr.eval(app, nil)
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
}
|