This commit is contained in:
Gokcehan committed 2020-06-11 04:11:40 +03:00
1 parent 99cee56d6e
commit 0e3910652a
10 files changed
+140 -138

No files matched your search

+1 -1
View File
@@ -8,9 +8,9 @@ import (
"os"
"os/exec"
"os/signal"
"syscall"
"path/filepath"
"strings"
"syscall"
"time"
)
+17 -17
View File
@@ -31,13 +31,11 @@ var (
"copy",
"cut",
"paste",
"delete",
"clear",
"draw",
"redraw",
"load",
"reload",
"read",
"rename",
"shell",
"shell-pipe",
"shell-wait",
@@ -53,7 +51,8 @@ var (
"mark-save",
"mark-remove",
"mark-load",
"rename",
"draw",
"load",
"sync",
"echo",
"echomsg",
@@ -64,6 +63,7 @@ var (
"glob-unselect",
"source",
"push",
"delete",
}
gOptWords = []string{
@@ -85,12 +85,12 @@ var (
"globsearch",
"noglobsearch",
"globsearch!",
"icons",
"noicons",
"icons!",
"hidden",
"nohidden",
"hidden!",
"icons",
"noicons",
"icons!",
"ignorecase",
"noignorecase",
"ignorecase!",
@@ -100,9 +100,15 @@ var (
"incsearch",
"noincsearch",
"incsearch!",
"number",
"nonumber",
"number!",
"preview",
"nopreview",
"preview!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"reverse",
"noreverse",
"reverse!",
@@ -118,28 +124,22 @@ var (
"wrapscroll",
"nowrapscroll",
"wrapscroll!",
"number",
"nonumber",
"number!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"findlen",
"period",
"scrolloff",
"tabstop",
"errorfmt",
"filesep",
"hiddenfiles",
"ifs",
"info",
"previewer",
"promptfmt",
"ratios",
"shell",
"shellopts",
"sortby",
"timefmt",
"ratios",
"info",
"shellopts",
"hiddenfiles",
}
)
+7 -7
View File
@@ -106,35 +106,35 @@ The following options can be used to customize the behavior of lf:
dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off)
icons boolean (default off)
ignorecase boolean (default on)
ignoredia boolean (default off)
incsearch boolean (default off)
number boolean (default off)
preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off)
smartcase boolean (default on)
smartdia boolean (default off)
wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off)
relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match)
period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0)
tabstop integer (default 8)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
ratios string (default '1:2:3')
shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
hiddenfiles string (default '.*')
The following variables are exported for shell commands:
+7 -6
View File
@@ -109,34 +109,35 @@ The following options can be used to customize the behavior of lf:
dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off)
icons boolean (default off)
ignorecase boolean (default on)
ignoredia boolean (default off)
incsearch boolean (default off)
number boolean (default off)
preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off)
smartcase boolean (default on)
smartdia boolean (default off)
wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off)
relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match)
period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0)
tabstop integer (default 8)
errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
ratios string (default '1:2:3')
shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
The following variables are exported for shell commands:
+71 -67
View File
@@ -71,12 +71,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.globsearch = false
case "globsearch!":
gOpts.globsearch = !gOpts.globsearch
case "icons":
gOpts.icons = true
case "noicons":
gOpts.icons = false
case "icons!":
gOpts.icons = !gOpts.icons
case "hidden":
gOpts.sortType.option |= hiddenSort
app.nav.sort()
@@ -95,6 +89,12 @@ func (e *setExpr) eval(app *app, args []string) {
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav)
case "icons":
gOpts.icons = true
case "noicons":
gOpts.icons = false
case "icons!":
gOpts.icons = !gOpts.icons
case "ignorecase":
gOpts.ignorecase = true
case "noignorecase":
@@ -113,6 +113,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.incsearch = false
case "incsearch!":
gOpts.incsearch = !gOpts.incsearch
case "number":
gOpts.number = true
case "nonumber":
gOpts.number = false
case "number!":
gOpts.number = !gOpts.number
case "preview":
if len(gOpts.ratios) < 2 {
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
@@ -127,6 +133,12 @@ func (e *setExpr) eval(app *app, args []string) {
return
}
gOpts.preview = !gOpts.preview
case "relativenumber":
gOpts.relativenumber = true
case "norelativenumber":
gOpts.relativenumber = false
case "relativenumber!":
gOpts.relativenumber = !gOpts.relativenumber
case "reverse":
gOpts.sortType.option |= reverseSort
app.nav.sort()
@@ -163,18 +175,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscroll = false
case "wrapscroll!":
gOpts.wrapscroll = !gOpts.wrapscroll
case "number":
gOpts.number = true
case "nonumber":
gOpts.number = false
case "number!":
gOpts.number = !gOpts.number
case "relativenumber":
gOpts.relativenumber = true
case "norelativenumber":
gOpts.relativenumber = false
case "relativenumber!":
gOpts.relativenumber = !gOpts.relativenumber
case "findlen":
n, err := strconv.Atoi(e.val)
if err != nil {
@@ -229,14 +229,67 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.errorfmt = e.val
case "filesep":
gOpts.filesep = e.val
case "hiddenfiles":
toks := strings.Split(e.val, ":")
for _, s := range toks {
if s == "" {
app.ui.echoerrf("hiddenfiles: glob should be non-empty")
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()
app.ui.loadFile(app.nav)
case "ifs":
gOpts.ifs = e.val
case "info":
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "", "size", "time", "atime", "ctime":
default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
return
}
}
gOpts.info = toks
case "previewer":
gOpts.previewer = replaceTilde(e.val)
case "promptfmt":
gOpts.promptfmt = e.val
case "ratios":
toks := strings.Split(e.val, ":")
var rats []int
for _, s := range toks {
n, err := strconv.Atoi(s)
if err != nil {
app.ui.echoerrf("ratios: %s", err)
return
}
if n <= 0 {
app.ui.echoerr("ratios: value should be a positive number")
return
}
rats = append(rats, n)
}
if gOpts.preview && len(rats) < 2 {
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
return
}
gOpts.ratios = rats
app.ui.wins = getWins()
app.ui.loadFile(app.nav)
case "shell":
gOpts.shell = e.val
case "shellopts":
gOpts.shellopts = strings.Split(e.val, ":")
case "sortby":
switch e.val {
case "natural":
@@ -261,55 +314,6 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.sort()
case "timefmt":
gOpts.timefmt = e.val
case "ratios":
toks := strings.Split(e.val, ":")
var rats []int
for _, s := range toks {
n, err := strconv.Atoi(s)
if err != nil {
app.ui.echoerrf("ratios: %s", err)
return
}
if n <= 0 {
app.ui.echoerr("ratios: value should be a positive number")
return
}
rats = append(rats, n)
}
if gOpts.preview && len(rats) < 2 {
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
return
}
gOpts.ratios = rats
app.ui.wins = getWins()
app.ui.loadFile(app.nav)
case "info":
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "", "size", "time", "atime", "ctime":
default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
return
}
}
gOpts.info = toks
case "shellopts":
gOpts.shellopts = strings.Split(e.val, ":")
case "hiddenfiles":
toks := strings.Split(e.val, ":")
for _, s := range toks {
_, 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()
app.ui.loadFile(app.nav)
default:
app.ui.echoerrf("unknown option: %s", e.opt)
return
+7 -6
View File
@@ -121,34 +121,35 @@ The following options can be used to customize the behavior of lf:
dirfirst boolean (default on)
drawbox boolean (default off)
globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off)
icons boolean (default off)
ignorecase boolean (default on)
ignoredia boolean (default off)
incsearch boolean (default off)
number boolean (default off)
preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off)
smartcase boolean (default on)
smartdia boolean (default off)
wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off)
relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match)
period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0)
tabstop integer (default 8)
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty)
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
ratios string (default '1:2:3')
shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3')
info string (default '')
shellopts string (default '')
.EE
.PP
The following variables are exported for shell commands:
+7 -7
View File
@@ -13,6 +13,13 @@ import (
func isRoot(name string) bool { return filepath.Dir(name) == name }
func replaceTilde(s string) string {
if strings.HasPrefix(s, "~") {
s = strings.Replace(s, "~", gUser.HomeDir, 1)
}
return s
}
func runeSliceWidth(rs []rune) int {
w := 0
for _, r := range rs {
@@ -207,13 +214,6 @@ func max(a, b int) int {
return b
}
func replaceTilde(s string) string {
if strings.HasPrefix(s, "~") {
s = strings.Replace(s, "~", gUser.HomeDir, 1)
}
return s
}
// We don't need no generic code
// We don't need no type control
// No dark templates in compiler
+12 -12
View File
@@ -35,15 +35,15 @@ var gOpts struct {
globsearch bool
icons bool
ignorecase bool
incsearch bool
preview bool
smartcase bool
ignoredia bool
incsearch bool
number bool
preview bool
relativenumber bool
smartcase bool
smartdia bool
wrapscan bool
wrapscroll bool
number bool
relativenumber bool
findlen int
period int
scrolloff int
@@ -56,9 +56,9 @@ var gOpts struct {
shell string
timefmt string
ratios []int
hiddenfiles []string
info []string
shellopts []string
hiddenfiles []string
keys map[string]expr
cmdkeys map[string]expr
cmds map[string]expr
@@ -73,15 +73,15 @@ func init() {
gOpts.globsearch = false
gOpts.icons = false
gOpts.ignorecase = true
gOpts.incsearch = false
gOpts.preview = true
gOpts.smartcase = true
gOpts.ignoredia = false
gOpts.incsearch = false
gOpts.number = false
gOpts.preview = true
gOpts.relativenumber = false
gOpts.smartcase = true
gOpts.smartdia = false
gOpts.wrapscan = true
gOpts.wrapscroll = false
gOpts.number = false
gOpts.relativenumber = false
gOpts.findlen = 1
gOpts.period = 0
gOpts.scrolloff = 0
@@ -94,9 +94,9 @@ func init() {
gOpts.shell = gDefaultShell
gOpts.timefmt = time.ANSIC
gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = []string{".*"}
gOpts.info = nil
gOpts.shellopts = nil
gOpts.hiddenfiles = []string{".*"}
gOpts.sortType = sortType{naturalSort, dirfirstSort}
gOpts.keys = make(map[string]expr)
+9 -13
View File
@@ -133,14 +133,11 @@ func isExecutable(f os.FileInfo) bool {
return f.Mode()&0111 != 0
}
func isHidden(f os.FileInfo, path string) (hidden bool) {
func isHidden(f os.FileInfo, path string) bool {
hidden := false
for _, pattern := range gOpts.hiddenfiles {
if len(pattern) == 0 {
continue
}
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if pattern[0] == '!' && matched {
if strings.HasPrefix(pattern, "!") && matched {
hidden = false
} else if matched {
hidden = true
@@ -150,17 +147,16 @@ func isHidden(f os.FileInfo, path string) (hidden bool) {
}
func matchPattern(pattern, name, path string) bool {
matchStr := name
s := name
if pattern[0] == '~' {
pattern = gUser.HomeDir + strings.TrimPrefix(pattern, "~")
}
if pattern[0] == filepath.Separator {
matchStr = filepath.Join(path, name)
pattern = replaceTilde(pattern)
if filepath.IsAbs(pattern) {
s = filepath.Join(path, name)
}
// pattern errors are checked when 'hiddenfiles' option is set
matched, _ := filepath.Match(pattern, matchStr)
matched, _ := filepath.Match(pattern, s)
return matched
}
+2 -2
View File
@@ -114,9 +114,9 @@ func isExecutable(f os.FileInfo) bool {
return false
}
func isHidden(f os.FileInfo, path string) (hidden bool) {
func isHidden(f os.FileInfo, path string) bool {
// TODO: implement
return hidden
return false
}
func exportFiles(f string, fs []string) {