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"
|
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 {
|
2017-06-03 11:12:43 +00:00
|
|
|
case "dircounts":
|
|
|
|
gOpts.dircounts = true
|
|
|
|
case "nodircounts":
|
|
|
|
gOpts.dircounts = false
|
|
|
|
case "dircounts!":
|
|
|
|
gOpts.dircounts = !gOpts.dircounts
|
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()
|
2018-04-15 16:26:51 +00:00
|
|
|
case "drawbox":
|
|
|
|
gOpts.drawbox = true
|
|
|
|
app.ui.renew()
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
case "nodrawbox":
|
|
|
|
gOpts.drawbox = false
|
|
|
|
app.ui.renew()
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
|
|
|
case "drawbox!":
|
|
|
|
gOpts.drawbox = !gOpts.drawbox
|
|
|
|
app.ui.renew()
|
|
|
|
app.nav.height = app.ui.wins[0].h
|
2017-07-15 14:06:18 +00:00
|
|
|
case "globsearch":
|
|
|
|
gOpts.globsearch = true
|
|
|
|
case "noglobsearch":
|
|
|
|
gOpts.globsearch = false
|
|
|
|
case "globsearch!":
|
|
|
|
gOpts.globsearch = !gOpts.globsearch
|
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-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
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-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
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-04-18 18:52:45 +00:00
|
|
|
app.ui.sort()
|
2017-07-15 14:18:37 +00:00
|
|
|
case "ignorecase":
|
|
|
|
gOpts.ignorecase = true
|
|
|
|
case "noignorecase":
|
|
|
|
gOpts.ignorecase = false
|
|
|
|
case "ignorecase!":
|
|
|
|
gOpts.ignorecase = !gOpts.ignorecase
|
2016-08-13 12:49:04 +00:00
|
|
|
case "preview":
|
|
|
|
gOpts.preview = true
|
|
|
|
case "nopreview":
|
|
|
|
gOpts.preview = false
|
|
|
|
case "preview!":
|
|
|
|
gOpts.preview = !gOpts.preview
|
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
|
|
|
|
case "nosmartcase":
|
|
|
|
gOpts.smartcase = false
|
|
|
|
case "smartcase!":
|
|
|
|
gOpts.smartcase = !gOpts.smartcase
|
2017-03-16 13:22:42 +00:00
|
|
|
case "wrapscan":
|
|
|
|
gOpts.wrapscan = true
|
|
|
|
case "nowrapscan":
|
|
|
|
gOpts.wrapscan = false
|
|
|
|
case "wrapscan!":
|
|
|
|
gOpts.wrapscan = !gOpts.wrapscan
|
2018-06-09 19:02:09 +00:00
|
|
|
case "period":
|
|
|
|
n, err := strconv.Atoi(e.val)
|
|
|
|
if err != nil {
|
|
|
|
app.ui.printf("period: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if n < 0 {
|
|
|
|
app.ui.print("period: value should be a non-negative number")
|
|
|
|
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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("scrolloff: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n < 0 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.print("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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("tabstop: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if n <= 0 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.print("tabstop: value should be a positive number")
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
gOpts.tabstop = n
|
2016-12-24 13:06:44 +00:00
|
|
|
case "filesep":
|
|
|
|
gOpts.filesep = e.val
|
2016-08-13 12:49:04 +00:00
|
|
|
case "ifs":
|
|
|
|
gOpts.ifs = e.val
|
2016-08-28 12:04:57 +00:00
|
|
|
case "previewer":
|
2017-08-06 08:05:46 +00:00
|
|
|
gOpts.previewer = strings.Replace(e.val, "~", gUser.HomeDir, -1)
|
2018-02-22 15:18:30 +00:00
|
|
|
case "promptfmt":
|
|
|
|
gOpts.promptfmt = e.val
|
2016-08-27 11:12:03 +00:00
|
|
|
case "shell":
|
|
|
|
gOpts.shell = e.val
|
2016-08-13 12:49:04 +00:00
|
|
|
case "sortby":
|
2016-12-02 21:45:04 +00:00
|
|
|
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
|
2017-11-22 14:30:09 +00:00
|
|
|
app.ui.print("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2018-04-18 20:08:28 +00:00
|
|
|
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
|
|
|
|
}
|
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 "timefmt":
|
|
|
|
gOpts.timefmt = 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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("ratios: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-22 14:30:09 +00:00
|
|
|
if n <= 0 {
|
|
|
|
app.ui.print("ratios: value should be a positive number")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rats = append(rats, n)
|
|
|
|
}
|
|
|
|
if gOpts.preview && len(rats) < 2 {
|
|
|
|
app.ui.print("ratios: should consist of at least two numbers when 'preview' is enabled")
|
|
|
|
return
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
gOpts.ratios = rats
|
2016-12-18 19:38:28 +00:00
|
|
|
app.ui.wins = getWins()
|
2016-11-07 21:13:37 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2017-02-04 18:33:36 +00:00
|
|
|
case "info":
|
2017-02-04 18:28:03 +00:00
|
|
|
toks := strings.Split(e.val, ":")
|
|
|
|
for _, s := range toks {
|
|
|
|
if s != "" && s != "size" && s != "time" {
|
2017-11-22 14:30:09 +00:00
|
|
|
app.ui.print("info: should consist of 'size' or 'time' separated with colon")
|
2017-02-04 18:28:03 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2017-02-04 18:33:36 +00:00
|
|
|
gOpts.info = toks
|
2016-08-13 12:49:04 +00:00
|
|
|
default:
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("unknown option: %s", e.opt)
|
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)
|
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.keys[e.keys] = e.expr
|
|
|
|
}
|
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
func (e *cmapExpr) eval(app *app, args []string) {
|
|
|
|
if e.cmd == "" {
|
|
|
|
delete(gOpts.cmdkeys, e.key)
|
|
|
|
return
|
|
|
|
}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
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)
|
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.cmds[e.name] = e.expr
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
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":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.up(e.count)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-09-08 21:04:44 +00:00
|
|
|
case "half-up":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.up(e.count * app.nav.height / 2)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-09-08 21:04:44 +00:00
|
|
|
case "page-up":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.up(e.count * app.nav.height)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-28 14:02:58 +00:00
|
|
|
case "down":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.down(e.count)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-09-08 21:04:44 +00:00
|
|
|
case "half-down":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.down(e.count * app.nav.height / 2)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-09-08 21:04:44 +00:00
|
|
|
case "page-down":
|
2018-04-12 15:04:37 +00:00
|
|
|
app.nav.down(e.count * app.nav.height)
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "updir":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
if err := app.nav.updir(); err != nil {
|
|
|
|
app.ui.printf("%s", err)
|
|
|
|
return
|
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("opening: %s", err)
|
2016-08-14 12:15:54 +00:00
|
|
|
return
|
|
|
|
}
|
2016-12-18 15:01:45 +00:00
|
|
|
|
|
|
|
if curr.IsDir() {
|
2017-11-19 18:55:13 +00:00
|
|
|
err := app.nav.open()
|
2016-12-18 15:01:45 +00:00
|
|
|
if err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("opening directory: %s", err)
|
2016-12-18 15:01:45 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
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
|
2016-08-14 12:37:22 +00:00
|
|
|
if len(app.nav.marks) != 0 {
|
|
|
|
marks := app.nav.currMarks()
|
|
|
|
path = strings.Join(marks, "\n")
|
2016-10-24 19:18:31 +00:00
|
|
|
} else if curr, err := app.nav.currFile(); err == nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
path = curr.path
|
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
|
|
|
}
|
|
|
|
|
2017-11-19 18:55:13 +00:00
|
|
|
app.quitChan <- true
|
2016-10-27 19:24:42 +00:00
|
|
|
|
2016-08-14 12:37:22 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:51:52 +00:00
|
|
|
if cmd, ok := gOpts.cmds["open-file"]; ok {
|
|
|
|
cmd.eval(app, e.args)
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
2016-08-28 14:02:58 +00:00
|
|
|
case "quit":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.quitChan <- true
|
2016-08-13 12:49:04 +00:00
|
|
|
case "top":
|
|
|
|
app.nav.top()
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-05-15 21:20:05 +00:00
|
|
|
case "bottom":
|
|
|
|
app.nav.bottom()
|
2016-12-26 20:51:59 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-08-13 12:49:04 +00:00
|
|
|
case "toggle":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
app.nav.toggle()
|
|
|
|
}
|
2017-03-10 16:00:21 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
2016-10-09 16:07:57 +00:00
|
|
|
case "invert":
|
|
|
|
app.nav.invert()
|
2017-11-25 13:15:04 +00:00
|
|
|
case "unmark":
|
|
|
|
app.nav.unmark()
|
2016-08-13 12:49:04 +00:00
|
|
|
case "yank":
|
2016-08-17 20:28:42 +00:00
|
|
|
if err := app.nav.save(true); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("yank: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-25 13:15:04 +00:00
|
|
|
app.nav.unmark()
|
2016-12-19 18:28:57 +00:00
|
|
|
if err := sendRemote("send sync"); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("yank: %s", err)
|
2016-11-10 20:25:03 +00:00
|
|
|
}
|
2016-08-13 12:49:04 +00:00
|
|
|
case "delete":
|
2016-08-17 20:28:42 +00:00
|
|
|
if err := app.nav.save(false); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("delete: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2017-11-25 13:15:04 +00:00
|
|
|
app.nav.unmark()
|
2016-12-19 18:28:57 +00:00
|
|
|
if err := sendRemote("send sync"); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("delete: %s", err)
|
2016-11-10 20:25:03 +00:00
|
|
|
}
|
2016-11-06 15:09:18 +00:00
|
|
|
case "put":
|
2017-09-10 14:14:50 +00:00
|
|
|
if cmd, ok := gOpts.cmds["put"]; ok {
|
|
|
|
cmd.eval(app, e.args)
|
|
|
|
} else if err := app.nav.put(); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("put: %s", err)
|
2016-08-13 12:49:04 +00:00
|
|
|
return
|
|
|
|
}
|
2018-04-15 15:18:39 +00:00
|
|
|
app.nav.renew()
|
2016-12-19 19:00:50 +00:00
|
|
|
if err := sendRemote("send sync"); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("put: %s", err)
|
2016-12-19 19:00:50 +00:00
|
|
|
}
|
2016-12-19 18:53:47 +00:00
|
|
|
case "clear":
|
|
|
|
if err := saveFiles(nil, false); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("clear: %s", err)
|
2016-12-19 18:53:47 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := sendRemote("send sync"); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("clear: %s", err)
|
2016-12-19 18:53:47 +00:00
|
|
|
}
|
2018-04-12 18:48:32 +00:00
|
|
|
case "draw":
|
2018-01-29 15:12:59 +00:00
|
|
|
case "redraw":
|
|
|
|
app.ui.sync()
|
|
|
|
app.ui.renew()
|
2018-04-15 15:18:39 +00:00
|
|
|
app.nav.height = app.ui.wins[0].h
|
2018-01-29 15:08:51 +00:00
|
|
|
case "reload":
|
2016-08-24 09:34:54 +00:00
|
|
|
app.ui.sync()
|
2016-08-13 12:49:04 +00:00
|
|
|
app.ui.renew()
|
2018-01-29 15:08:51 +00:00
|
|
|
app.nav.reload()
|
2017-11-19 18:55:13 +00:00
|
|
|
case "read":
|
|
|
|
app.ui.cmdPrefix = ":"
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "$"
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-pipe":
|
2018-03-26 18:22:18 +00:00
|
|
|
app.ui.cmdPrefix = "%"
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-wait":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "!"
|
2018-03-27 18:23:34 +00:00
|
|
|
case "shell-async":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = "&"
|
|
|
|
case "search":
|
|
|
|
app.ui.cmdPrefix = "/"
|
|
|
|
case "search-back":
|
|
|
|
app.ui.cmdPrefix = "?"
|
|
|
|
case "search-next":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
if err := app.nav.searchNext(); err != nil {
|
|
|
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
|
|
|
return
|
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
case "search-prev":
|
2018-04-12 15:04:37 +00:00
|
|
|
for i := 0; i < e.count; i++ {
|
|
|
|
if err := app.nav.searchPrev(); err != nil {
|
|
|
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
|
|
|
return
|
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("sync: %s", err)
|
2016-11-08 21:39:39 +00:00
|
|
|
}
|
2016-08-28 14:02:58 +00:00
|
|
|
case "echo":
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.msg = strings.Join(e.args, " ")
|
2016-08-28 14:02:58 +00:00
|
|
|
case "cd":
|
|
|
|
path := "~"
|
|
|
|
if len(e.args) > 0 {
|
|
|
|
path = e.args[0]
|
|
|
|
}
|
|
|
|
if err := app.nav.cd(path); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("%s", err)
|
2016-08-28 14:02:58 +00:00
|
|
|
return
|
|
|
|
}
|
2016-09-15 13:16:03 +00:00
|
|
|
app.ui.loadFile(app.nav)
|
2016-12-02 22:05:49 +00:00
|
|
|
app.ui.loadFileInfo(app.nav)
|
2018-03-27 17:47:17 +00:00
|
|
|
case "select":
|
|
|
|
if len(e.args) != 1 {
|
|
|
|
app.ui.print("select: requires an argument")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err := app.nav.find(e.args[0]); err != nil {
|
|
|
|
app.ui.printf("%s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
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 {
|
|
|
|
app.ui.print("push: requires an argument")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Println("pushing keys", e.args[0])
|
|
|
|
for _, key := range splitKeys(e.args[0]) {
|
|
|
|
app.ui.keyChan <- key
|
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
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(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
|
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
app.ui.cmdPrefix = ""
|
2018-05-15 21:05:06 +00:00
|
|
|
case "cmd-complete":
|
2016-12-15 09:26:06 +00:00
|
|
|
var matches []string
|
2017-11-19 18:55:13 +00:00
|
|
|
if app.ui.cmdPrefix == ":" {
|
2018-05-15 21:05:06 +00:00
|
|
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
2016-12-15 09:26:06 +00:00
|
|
|
} else {
|
2018-05-15 21:05:06 +00:00
|
|
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
|
|
|
app.ui.draw(app.nav)
|
|
|
|
if len(matches) > 1 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = listMatches(matches)
|
2016-12-15 09:26:06 +00:00
|
|
|
} else {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
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...))
|
2016-12-15 09:26:06 +00:00
|
|
|
if len(s) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
switch app.ui.cmdPrefix {
|
2016-12-15 09:26:06 +00:00
|
|
|
case ":":
|
|
|
|
log.Printf("command: %s", s)
|
|
|
|
p := newParser(strings.NewReader(s))
|
|
|
|
for p.parse() {
|
|
|
|
p.expr.eval(app, nil)
|
|
|
|
}
|
|
|
|
if p.err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("%s", p.err)
|
2016-12-15 09:26:06 +00:00
|
|
|
}
|
2018-05-20 17:38:18 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-15 09:26:06 +00:00
|
|
|
case "$":
|
|
|
|
log.Printf("shell: %s", s)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
|
|
app.ui.cmdPrefix = ""
|
2018-03-26 18:22:18 +00:00
|
|
|
case "%":
|
|
|
|
log.Printf("shell-pipe: %s", s)
|
|
|
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
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-03-26 18:22:18 +00:00
|
|
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-15 09:26:06 +00:00
|
|
|
case "&":
|
|
|
|
log.Printf("shell-async: %s", s)
|
2018-03-26 18:22:18 +00:00
|
|
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
2018-05-20 17:38:18 +00:00
|
|
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-15 09:26:06 +00:00
|
|
|
case "/":
|
|
|
|
log.Printf("search: %s", s)
|
2016-12-23 15:58:24 +00:00
|
|
|
app.nav.search = s
|
2017-07-15 14:06:18 +00:00
|
|
|
if err := app.nav.searchNext(); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
2017-07-15 14:06:18 +00:00
|
|
|
} else {
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-05-20 17:38:18 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
2016-12-15 09:26:06 +00:00
|
|
|
case "?":
|
|
|
|
log.Printf("search-back: %s", s)
|
2016-12-23 15:58:24 +00:00
|
|
|
app.nav.search = s
|
2017-07-15 14:06:18 +00:00
|
|
|
if err := app.nav.searchPrev(); err != nil {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
2017-07-15 14:06:18 +00:00
|
|
|
} else {
|
|
|
|
app.ui.loadFile(app.nav)
|
|
|
|
app.ui.loadFileInfo(app.nav)
|
|
|
|
}
|
2018-05-20 17:38:18 +00:00
|
|
|
app.ui.cmdPrefix = ""
|
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 {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
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]
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = cmd.prefix
|
|
|
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
app.ui.menuBuf = nil
|
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]
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdPrefix = cmd.prefix
|
|
|
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
app.ui.menuBuf = nil
|
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:]
|
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]
|
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
|
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-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
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
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...)
|
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-04-03 19:56:38 +00:00
|
|
|
case "cmd-interrupt":
|
|
|
|
if app.cmd != nil {
|
|
|
|
app.cmd.Process.Kill()
|
|
|
|
}
|
|
|
|
app.ui.menuBuf = nil
|
|
|
|
app.ui.cmdAccLeft = nil
|
|
|
|
app.ui.cmdAccRight = nil
|
|
|
|
app.ui.cmdPrefix = ""
|
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
|
|
|
|
}
|
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc == nil {
|
|
|
|
return
|
2018-05-05 16:37:14 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
ind := loc[0] + 1
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
|
|
|
app.ui.cmdAccRight = 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
|
|
|
|
}
|
|
|
|
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
|
|
|
if locs == nil {
|
|
|
|
return
|
2018-05-05 16:37:14 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
ind := locs[len(locs)-1][1] - 1
|
|
|
|
app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...)
|
|
|
|
app.ui.cmdAccLeft = 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])
|
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ind = loc[0] + 1
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
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
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ind := loc[0] + 1
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
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
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ind := loc[0] + 1
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
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
|
|
|
|
}
|
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc == nil {
|
|
|
|
return
|
2018-05-13 22:38:19 +00:00
|
|
|
}
|
2018-05-20 17:30:41 +00:00
|
|
|
ind := loc[0] + 1
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
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 {
|
|
|
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
|
|
|
if loc != nil {
|
2018-05-14 16:38:35 +00:00
|
|
|
ind := loc[0] + 1
|
|
|
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
|
|
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
|
|
|
}
|
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
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
acc = append(acc, app.ui.cmdAccLeft[:beg1]...)
|
|
|
|
acc = append(acc, app.ui.cmdAccLeft[beg2:end2]...)
|
|
|
|
acc = append(acc, app.ui.cmdAccLeft[end1:beg2]...)
|
|
|
|
acc = append(acc, app.ui.cmdAccLeft[beg1:end1]...)
|
|
|
|
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
2018-05-14 16:38:35 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
app.ui.cmdAccLeft = acc
|
2016-08-13 12:49:04 +00:00
|
|
|
default:
|
|
|
|
cmd, ok := gOpts.cmds[e.name]
|
|
|
|
if !ok {
|
2017-11-19 18:55:13 +00:00
|
|
|
app.ui.printf("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) {
|
2016-08-13 12:49:04 +00:00
|
|
|
for _, expr := range e.exprs {
|
|
|
|
expr.eval(app, nil)
|
|
|
|
}
|
|
|
|
}
|