2016-08-13 12:49:04 +00:00
|
|
|
package main
|
|
|
|
|
2017-08-05 16:23:55 +00:00
|
|
|
import "time"
|
2016-11-21 20:13:33 +00:00
|
|
|
|
2018-04-18 20:08:28 +00:00
|
|
|
type sortMethod byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
naturalSort sortMethod = iota
|
|
|
|
nameSort
|
|
|
|
sizeSort
|
|
|
|
timeSort
|
|
|
|
)
|
|
|
|
|
|
|
|
type sortOption byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
dirfirstSort sortOption = 1 << iota
|
|
|
|
hiddenSort
|
|
|
|
reverseSort
|
|
|
|
)
|
|
|
|
|
|
|
|
type sortType struct {
|
|
|
|
method sortMethod
|
|
|
|
option sortOption
|
|
|
|
}
|
|
|
|
|
2016-10-01 22:14:55 +00:00
|
|
|
var gOpts struct {
|
2019-01-27 14:31:29 +00:00
|
|
|
anchorfind bool
|
|
|
|
color256 bool
|
|
|
|
dircounts bool
|
|
|
|
drawbox bool
|
|
|
|
globsearch bool
|
|
|
|
ignorecase bool
|
|
|
|
incsearch bool
|
|
|
|
preview bool
|
|
|
|
smartcase bool
|
|
|
|
ignoredia bool
|
|
|
|
smartdia bool
|
|
|
|
wrapscan bool
|
|
|
|
number bool
|
|
|
|
relativenumber bool
|
|
|
|
findlen int
|
|
|
|
period int
|
|
|
|
scrolloff int
|
|
|
|
tabstop int
|
2019-03-27 19:07:41 +00:00
|
|
|
errorfmt string
|
2019-01-27 14:31:29 +00:00
|
|
|
filesep string
|
|
|
|
ifs string
|
|
|
|
previewer string
|
|
|
|
promptfmt string
|
|
|
|
shell string
|
|
|
|
timefmt string
|
|
|
|
ratios []int
|
|
|
|
info []string
|
|
|
|
shellopts []string
|
|
|
|
keys map[string]expr
|
|
|
|
cmdkeys map[string]expr
|
|
|
|
cmds map[string]expr
|
|
|
|
sortType sortType
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-08-22 22:37:07 +00:00
|
|
|
gOpts.anchorfind = true
|
2019-01-08 19:47:41 +00:00
|
|
|
gOpts.color256 = false
|
2017-06-03 11:12:43 +00:00
|
|
|
gOpts.dircounts = false
|
2018-04-15 16:26:51 +00:00
|
|
|
gOpts.drawbox = false
|
2017-07-15 14:06:18 +00:00
|
|
|
gOpts.globsearch = false
|
2017-10-30 21:35:31 +00:00
|
|
|
gOpts.ignorecase = true
|
2018-11-24 16:02:04 +00:00
|
|
|
gOpts.incsearch = false
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.preview = true
|
2017-10-30 21:35:31 +00:00
|
|
|
gOpts.smartcase = true
|
2018-12-03 12:41:53 +00:00
|
|
|
gOpts.ignoredia = false
|
|
|
|
gOpts.smartdia = false
|
2017-03-16 13:22:42 +00:00
|
|
|
gOpts.wrapscan = true
|
2018-08-22 17:57:47 +00:00
|
|
|
gOpts.findlen = 1
|
2018-06-09 19:02:09 +00:00
|
|
|
gOpts.period = 0
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.scrolloff = 0
|
|
|
|
gOpts.tabstop = 8
|
2019-03-27 19:07:41 +00:00
|
|
|
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
2017-09-07 20:01:57 +00:00
|
|
|
gOpts.filesep = "\n"
|
2018-02-22 15:18:30 +00:00
|
|
|
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
2017-08-05 16:23:55 +00:00
|
|
|
gOpts.shell = gDefaultShell
|
2016-11-21 20:13:33 +00:00
|
|
|
gOpts.timefmt = time.ANSIC
|
2016-08-13 12:49:04 +00:00
|
|
|
gOpts.ratios = []int{1, 2, 3}
|
2017-02-04 18:33:36 +00:00
|
|
|
gOpts.info = nil
|
2018-06-26 18:14:55 +00:00
|
|
|
gOpts.shellopts = nil
|
2018-04-18 20:08:28 +00:00
|
|
|
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
gOpts.keys = make(map[string]expr)
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["k"] = &callExpr{"up", nil, 1}
|
|
|
|
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
|
|
|
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
|
|
|
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
2018-06-27 18:33:00 +00:00
|
|
|
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
|
|
|
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
|
|
|
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
|
|
|
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
2018-06-27 18:33:00 +00:00
|
|
|
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
|
|
|
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
|
|
|
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
|
|
|
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
|
|
|
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
|
|
|
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
2018-06-27 18:33:00 +00:00
|
|
|
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
2018-05-15 21:20:05 +00:00
|
|
|
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
2018-06-27 18:33:00 +00:00
|
|
|
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
|
|
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
2018-07-09 18:22:10 +00:00
|
|
|
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
2018-06-27 18:15:34 +00:00
|
|
|
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
|
|
|
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
2018-06-27 18:15:34 +00:00
|
|
|
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
|
|
|
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
|
|
|
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
|
|
|
gOpts.keys["$"] = &callExpr{"shell", nil, 1}
|
|
|
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
|
|
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
|
|
|
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
2018-08-22 17:05:22 +00:00
|
|
|
gOpts.keys["f"] = &callExpr{"find", nil, 1}
|
|
|
|
gOpts.keys["F"] = &callExpr{"find-back", nil, 1}
|
|
|
|
gOpts.keys[";"] = &callExpr{"find-next", nil, 1}
|
|
|
|
gOpts.keys[","] = &callExpr{"find-prev", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
|
|
|
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
|
|
|
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
|
|
|
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
2018-07-09 18:35:04 +00:00
|
|
|
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
|
|
|
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
2018-05-15 21:16:49 +00:00
|
|
|
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
|
|
|
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
2016-08-13 12:49:04 +00:00
|
|
|
|
2018-03-02 20:15:36 +00:00
|
|
|
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
|
|
|
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
|
|
|
gOpts.keys["zn"] = &setExpr{"info", ""}
|
|
|
|
gOpts.keys["zs"] = &setExpr{"info", "size"}
|
|
|
|
gOpts.keys["zt"] = &setExpr{"info", "time"}
|
|
|
|
gOpts.keys["za"] = &setExpr{"info", "size:time"}
|
|
|
|
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
|
|
|
|
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
|
|
|
|
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
2018-03-02 20:15:36 +00:00
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
gOpts.cmdkeys = make(map[string]expr)
|
|
|
|
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
|
|
|
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
2018-05-15 21:05:06 +00:00
|
|
|
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
2018-05-15 21:16:49 +00:00
|
|
|
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
|
|
|
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
|
|
|
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
|
|
|
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
|
|
|
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
2018-05-15 21:00:20 +00:00
|
|
|
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
2018-05-15 21:02:06 +00:00
|
|
|
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-home", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
2018-05-13 22:19:26 +00:00
|
|
|
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
2018-05-15 21:28:11 +00:00
|
|
|
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
2018-04-12 15:04:37 +00:00
|
|
|
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
|
|
|
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
|
2018-05-05 16:37:14 +00:00
|
|
|
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
|
|
|
|
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
|
2018-05-13 22:16:01 +00:00
|
|
|
gOpts.cmdkeys["<a-c>"] = &callExpr{"cmd-capitalize-word", nil, 1}
|
2018-05-13 22:25:26 +00:00
|
|
|
gOpts.cmdkeys["<a-d>"] = &callExpr{"cmd-delete-word", nil, 1}
|
2018-05-13 22:30:53 +00:00
|
|
|
gOpts.cmdkeys["<a-u>"] = &callExpr{"cmd-uppercase-word", nil, 1}
|
2018-05-13 22:38:19 +00:00
|
|
|
gOpts.cmdkeys["<a-l>"] = &callExpr{"cmd-lowercase-word", nil, 1}
|
2018-05-14 16:38:35 +00:00
|
|
|
gOpts.cmdkeys["<a-t>"] = &callExpr{"cmd-transpose-word", nil, 1}
|
2017-03-10 15:53:21 +00:00
|
|
|
|
2016-12-17 21:47:37 +00:00
|
|
|
gOpts.cmds = make(map[string]expr)
|
2018-03-02 20:15:36 +00:00
|
|
|
|
|
|
|
setDefaults()
|
2016-08-13 12:49:04 +00:00
|
|
|
}
|