Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f661344ed | ||
|
|
bfd01e5ed8 | ||
|
|
27861f06e2 | ||
|
|
cb36e87b80 | ||
|
|
30d3078559 | ||
|
|
db224f04fe | ||
|
|
afca893153 | ||
|
|
16db95707e | ||
|
|
bf39c7c63b | ||
|
|
eb8e516cfb | ||
|
|
34f39f90b2 | ||
|
|
4c6241ca42 | ||
|
|
8388b4f385 | ||
|
|
80ab2e4fc4 | ||
|
|
f071a3ae70 | ||
|
|
f3407b2d61 | ||
|
|
a5199960ed | ||
|
|
e69a229578 | ||
|
|
e815adc6a6 |
No files matched your search
@@ -137,7 +137,14 @@ func (app *app) loop() {
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
stat, err := os.Stat(gSelect)
|
||||
if err != nil {
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||
} else if stat.IsDir() {
|
||||
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||
} else {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -174,10 +181,6 @@ func (app *app) loop() {
|
||||
|
||||
log.Print("bye!")
|
||||
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
log.Printf("writing marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
}
|
||||
|
||||
@@ -199,6 +199,10 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
@@ -207,10 +211,6 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
|
||||
+10
@@ -51,13 +51,17 @@ var (
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"mark-save",
|
||||
"mark-remove",
|
||||
"mark-load",
|
||||
"rename",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"source",
|
||||
"push",
|
||||
}
|
||||
@@ -81,6 +85,9 @@ var (
|
||||
"globsearch",
|
||||
"noglobsearch",
|
||||
"globsearch!",
|
||||
"icons",
|
||||
"noicons",
|
||||
"icons!",
|
||||
"hidden",
|
||||
"nohidden",
|
||||
"hidden!",
|
||||
@@ -108,6 +115,9 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"wrapscroll",
|
||||
"nowrapscroll",
|
||||
"wrapscroll!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
|
||||
+9
-15
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var normMap map[rune]rune
|
||||
@@ -14,19 +14,17 @@ func init() {
|
||||
appendTransliterate(
|
||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||
true,
|
||||
)
|
||||
|
||||
// Vietnamese
|
||||
appendTransliterate(
|
||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||
true,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func appendTransliterate(base, norm string, uppercase bool) {
|
||||
func appendTransliterate(base, norm string) {
|
||||
normRunes := []rune(norm)
|
||||
baseRunes := []rune(base)
|
||||
|
||||
@@ -36,24 +34,20 @@ func appendTransliterate(base, norm string, uppercase bool) {
|
||||
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
||||
}
|
||||
|
||||
for i, baseRune := range baseRunes {
|
||||
normMap[baseRune] = normRunes[i]
|
||||
}
|
||||
for i := 0; i < lenBase; i++ {
|
||||
normMap[baseRunes[i]] = normRunes[i]
|
||||
|
||||
if uppercase {
|
||||
upperBase := strings.ToUpper(base)
|
||||
upperNorm := strings.ToUpper(norm)
|
||||
normRune := []rune(upperNorm)
|
||||
for i, baseRune := range []rune(upperBase) {
|
||||
normMap[baseRune] = normRune[i]
|
||||
}
|
||||
baseUpper := unicode.ToUpper(baseRunes[i])
|
||||
normUpper := unicode.ToUpper(normRunes[i])
|
||||
|
||||
normMap[baseUpper] = normUpper
|
||||
}
|
||||
}
|
||||
|
||||
// Remove diacritics and make lowercase.
|
||||
func removeDiacritics(baseString string) string {
|
||||
var normalizedRunes []rune
|
||||
for _, baseRune := range []rune(baseString) {
|
||||
for _, baseRune := range baseString {
|
||||
if normRune, ok := normMap[baseRune]; ok {
|
||||
normalizedRunes = append(normalizedRunes, normRune)
|
||||
} else {
|
||||
|
||||
@@ -37,6 +37,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -51,6 +52,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default `"`)
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
@@ -62,6 +64,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -102,6 +106,7 @@ 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)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -111,6 +116,7 @@ The following options can be used to customize the behavior of lf:
|
||||
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)
|
||||
@@ -214,14 +220,11 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file for
|
||||
read and shell commands. The difference is that prefixes are not necessary in
|
||||
the command line. Instead, different modes are provided to read corresponding
|
||||
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||
commands are only used from the command line.
|
||||
commands. These modes are mapped to the prefix keys above by default.
|
||||
|
||||
Syntax
|
||||
|
||||
@@ -583,7 +586,16 @@ Globbing supports '*' to match any sequence, '?' to match any character, and
|
||||
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||
'incsearch' option to jump to the current match at each keystroke while typing.
|
||||
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||
'cmd-escape' to cancel the search.
|
||||
'cmd-escape' to cancel the search. Alternatively, you can also map some other
|
||||
commands with 'cmap' to accept the search and execute the command immediately
|
||||
afterwards. Possible candidates are 'up', 'down' and their variants, 'updir',
|
||||
and 'open' commands. For example, you can use arrow keys to finish the search
|
||||
with the following mappings:
|
||||
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
|
||||
+17
-4
@@ -40,6 +40,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -54,6 +55,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default '"')
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
@@ -65,6 +67,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -105,6 +109,7 @@ 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)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -114,6 +119,7 @@ The following options can be used to customize the behavior of lf:
|
||||
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)
|
||||
@@ -219,14 +225,12 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file
|
||||
for read and shell commands. The difference is that prefixes are not
|
||||
necessary in the command line. Instead, different modes are provided to read
|
||||
corresponding commands. These modes are mapped to the prefix keys above by
|
||||
default. Searching commands are only used from the command line.
|
||||
default.
|
||||
|
||||
|
||||
Syntax
|
||||
@@ -608,7 +612,16 @@ pattern. Globbing supports '*' to match any sequence, '?' to match any
|
||||
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||
enable 'incsearch' option to jump to the current match at each keystroke
|
||||
while typing. In this mode, you can either use 'cmd-enter' to accept the
|
||||
search or use 'cmd-escape' to cancel the search.
|
||||
search or use 'cmd-escape' to cancel the search. Alternatively, you can also
|
||||
map some other commands with 'cmap' to accept the search and execute the
|
||||
command immediately afterwards. Possible candidates are 'up', 'down' and
|
||||
their variants, 'updir', and 'open' commands. For example, you can use arrow
|
||||
keys to finish the search with the following mappings:
|
||||
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
|
||||
+3
-3
@@ -42,9 +42,9 @@ cmd open ${{
|
||||
esac
|
||||
}}
|
||||
|
||||
# rename current file without overwrite
|
||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
map r push :rename<space>
|
||||
# define a custom 'rename' command without prompt for overwrite
|
||||
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
# map r push :rename<space>
|
||||
|
||||
# make sure trash folder exists
|
||||
# %mkdir -p ~/.trash
|
||||
|
||||
@@ -71,6 +71,12 @@ 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()
|
||||
@@ -108,10 +114,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "incsearch!":
|
||||
gOpts.incsearch = !gOpts.incsearch
|
||||
case "preview":
|
||||
if len(gOpts.ratios) < 2 {
|
||||
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||
return
|
||||
}
|
||||
gOpts.preview = true
|
||||
case "nopreview":
|
||||
gOpts.preview = false
|
||||
case "preview!":
|
||||
if len(gOpts.ratios) < 2 {
|
||||
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||
return
|
||||
}
|
||||
gOpts.preview = !gOpts.preview
|
||||
case "reverse":
|
||||
gOpts.sortType.option |= reverseSort
|
||||
@@ -143,6 +157,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "wrapscan!":
|
||||
gOpts.wrapscan = !gOpts.wrapscan
|
||||
case "wrapscroll":
|
||||
gOpts.wrapscroll = true
|
||||
case "nowrapscroll":
|
||||
gOpts.wrapscroll = false
|
||||
case "wrapscroll!":
|
||||
gOpts.wrapscroll = !gOpts.wrapscroll
|
||||
case "number":
|
||||
gOpts.number = true
|
||||
case "nonumber":
|
||||
@@ -271,31 +291,36 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.shellopts = strings.Split(e.val, ":")
|
||||
default:
|
||||
app.ui.echoerrf("unknown option: %s", e.opt)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *mapExpr) eval(app *app, args []string) {
|
||||
if e.expr == nil {
|
||||
delete(gOpts.keys, e.keys)
|
||||
return
|
||||
} else {
|
||||
gOpts.keys[e.keys] = e.expr
|
||||
}
|
||||
gOpts.keys[e.keys] = e.expr
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *cmapExpr) eval(app *app, args []string) {
|
||||
if e.cmd == "" {
|
||||
delete(gOpts.cmdkeys, e.key)
|
||||
return
|
||||
} else {
|
||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||
}
|
||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *cmdExpr) eval(app *app, args []string) {
|
||||
if e.expr == nil {
|
||||
delete(gOpts.cmds, e.name)
|
||||
return
|
||||
} else {
|
||||
gOpts.cmds[e.name] = e.expr
|
||||
}
|
||||
gOpts.cmds[e.name] = e.expr
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func splitKeys(s string) (keys []string) {
|
||||
@@ -364,6 +389,13 @@ func update(app *app) {
|
||||
}
|
||||
}
|
||||
|
||||
func normal(app *app) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
}
|
||||
|
||||
func insert(app *app, arg string) {
|
||||
switch {
|
||||
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
||||
@@ -397,10 +429,7 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case app.ui.cmdPrefix == "find-back: ":
|
||||
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||
|
||||
@@ -429,15 +458,9 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case app.ui.cmdPrefix == "delete?[y/N]: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
if arg == "y" {
|
||||
if err := app.nav.del(); err != nil {
|
||||
@@ -447,13 +470,29 @@ func insert(app *app, arg string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case strings.HasPrefix(app.ui.cmdPrefix, "replace") ||
|
||||
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
|
||||
normal(app)
|
||||
|
||||
if arg == "y" {
|
||||
if err := app.nav.rename(app.ui); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-save: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -461,11 +500,14 @@ func insert(app *app, arg string) {
|
||||
return
|
||||
}
|
||||
app.nav.marks[arg] = wd
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
app.ui.echoerrf("mark-save: %s", err)
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("mark-save: %s", err)
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-load: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -487,38 +529,73 @@ func insert(app *app, arg string) {
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
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
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("mark-remove: %s", err)
|
||||
}
|
||||
default:
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *callExpr) eval(app *app, args []string) {
|
||||
switch e.name {
|
||||
case "up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "half-up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count * app.nav.height / 2)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "page-up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count * app.nav.height)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "half-down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count * app.nav.height / 2)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "page-down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count * app.nav.height)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "updir":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
for i := 0; i < e.count; i++ {
|
||||
if err := app.nav.updir(); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
@@ -528,6 +605,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "open":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.echoerrf("opening: %s", err)
|
||||
@@ -591,8 +671,10 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "invert":
|
||||
app.nav.invert()
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "unselect":
|
||||
app.nav.unselect()
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "copy":
|
||||
if err := app.nav.save(true); err != nil {
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
@@ -601,7 +683,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "cut":
|
||||
if err := app.nav.save(false); err != nil {
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
@@ -610,7 +694,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "paste":
|
||||
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
@@ -618,12 +704,15 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.echoerrf("paste: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "delete":
|
||||
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
app.nav.unselect()
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err := app.nav.currFileOrSelections(); err != nil {
|
||||
@@ -632,6 +721,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
app.ui.cmdPrefix = "delete?[y/N]: "
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "clear":
|
||||
if err := saveFiles(nil, false); err != nil {
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
@@ -639,18 +730,24 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "draw":
|
||||
case "redraw":
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.height = app.ui.wins[0].h
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "load":
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
if err := app.nav.reload(); err != nil {
|
||||
app.ui.echoerrf("reload: %s", err)
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
case "shell":
|
||||
@@ -736,6 +833,27 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
case "mark-load":
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-load: "
|
||||
case "mark-remove":
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-remove: "
|
||||
case "rename":
|
||||
if cmd, ok := gOpts.cmds["rename"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.echoerrf("rename: %s:", err)
|
||||
return
|
||||
}
|
||||
app.ui.cmdPrefix = "rename: "
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "sync":
|
||||
if err := app.nav.sync(); err != nil {
|
||||
app.ui.echoerrf("sync: %s", err)
|
||||
@@ -803,12 +921,33 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
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
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
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
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "source":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("source: requires an argument")
|
||||
return
|
||||
}
|
||||
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "push":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("push: requires an argument")
|
||||
@@ -835,10 +974,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case "cmd-complete":
|
||||
var matches []string
|
||||
switch app.ui.cmdPrefix {
|
||||
@@ -926,6 +1062,45 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||
} else {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
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
|
||||
}
|
||||
oldPathTo := filepath.Join(wd, curr.Name())
|
||||
newPathTo := filepath.Join(wd, s)
|
||||
app.nav.renameCache = []string{oldPathTo, newPathTo}
|
||||
|
||||
if dir, _ := filepath.Split(s); dir != "" {
|
||||
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil {
|
||||
app.ui.cmdPrefix = "create path " + dir + "?[y/N]"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(newPathTo); err == nil { // file exists
|
||||
app.ui.cmdPrefix = "replace " + s + "?[y/N]"
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.nav.rename(app.ui); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
@@ -943,7 +1118,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
app.ui.cmdPrefix = ":"
|
||||
return
|
||||
}
|
||||
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||
@@ -1029,10 +1204,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if app.cmd != nil {
|
||||
app.cmd.Process.Kill()
|
||||
}
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case "cmd-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type iconMap map[string]string
|
||||
|
||||
func parseIcons() iconMap {
|
||||
if env := os.Getenv("LF_ICONS"); env != "" {
|
||||
return parseIconsEnv(env)
|
||||
}
|
||||
|
||||
defaultIcons := []string{
|
||||
"di=🗀",
|
||||
"fi=🗎",
|
||||
}
|
||||
|
||||
return parseIconsEnv(strings.Join(defaultIcons, ":"))
|
||||
}
|
||||
|
||||
func parseIconsEnv(env string) iconMap {
|
||||
icons := make(iconMap)
|
||||
|
||||
entries := strings.Split(env, ":")
|
||||
for _, entry := range entries {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
pair := strings.Split(entry, "=")
|
||||
if len(pair) != 2 {
|
||||
log.Printf("invalid $LF_ICONS entry: %s", entry)
|
||||
return icons
|
||||
}
|
||||
key, val := pair[0], pair[1]
|
||||
icons[key] = val
|
||||
}
|
||||
|
||||
return icons
|
||||
}
|
||||
|
||||
func (im iconMap) get(f *file) string {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
key = "st"
|
||||
case f.IsDir() && f.Mode()&0002 != 0:
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
key = "so"
|
||||
case f.Mode()&os.ModeCharDevice != 0:
|
||||
key = "cd"
|
||||
case f.Mode()&os.ModeDevice != 0:
|
||||
key = "bd"
|
||||
case f.Mode()&os.ModeSetuid != 0:
|
||||
key = "su"
|
||||
case f.Mode()&os.ModeSetgid != 0:
|
||||
key = "sg"
|
||||
case f.Mode().IsRegular() && f.Mode()&0111 != 0:
|
||||
key = "ex"
|
||||
default:
|
||||
key = "*" + filepath.Ext(f.Name())
|
||||
}
|
||||
|
||||
if val, ok := im[key]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im["fi"]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
return " "
|
||||
}
|
||||
@@ -47,6 +47,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -61,6 +62,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default `"`)
|
||||
.EE
|
||||
.PP
|
||||
The following commands are provided by lf without default keybindings:
|
||||
@@ -74,6 +76,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -117,6 +121,7 @@ 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)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -126,6 +131,7 @@ The following options can be used to customize the behavior of lf:
|
||||
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)
|
||||
@@ -243,11 +249,9 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
.EE
|
||||
.PP
|
||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default. Searching commands are only used from the command line.
|
||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default.
|
||||
.SH SYNTAX
|
||||
Characters from '#' to newline are comments and ignored:
|
||||
.PP
|
||||
@@ -558,7 +562,14 @@ By default, lf does not assign 'delete' command to a key to protect new users. Y
|
||||
.SH SEARCHING FILES
|
||||
There are two mechanisms implemented in lf to search a file in the current directory. Searching is the traditional method to move the selection to a file matching a given pattern. Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
|
||||
.PP
|
||||
Searching mechanism is implemented with commands 'search' (default '/'), 'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev' (default 'N'). You can enable 'globsearch' option to match with a glob pattern. Globbing supports '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. You can enable 'incsearch' option to jump to the current match at each keystroke while typing. In this mode, you can either use 'cmd-enter' to accept the search or use 'cmd-escape' to cancel the search.
|
||||
Searching mechanism is implemented with commands 'search' (default '/'), 'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev' (default 'N'). You can enable 'globsearch' option to match with a glob pattern. Globbing supports '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. You can enable 'incsearch' option to jump to the current match at each keystroke while typing. In this mode, you can either use 'cmd-enter' to accept the search or use 'cmd-escape' to cancel the search. Alternatively, you can also map some other commands with 'cmap' to accept the search and execute the command immediately afterwards. Possible candidates are 'up', 'down' and their variants, 'updir', and 'open' commands. For example, you can use arrow keys to finish the search with the following mappings:
|
||||
.PP
|
||||
.EX
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
.EE
|
||||
.PP
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'), 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default ','). You can disable 'anchorfind' option to match a pattern at an arbitrary position in the filename instead of the beginning. You can set the number of keys to match using 'findlen' option. If you set this value to zero, then the the keys are read until there is only a single match. Default values of these two options are set to jump to the first file with the given initial.
|
||||
.PP
|
||||
|
||||
@@ -82,6 +82,7 @@ type dir struct {
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortType sortType // sort method and options from last sort
|
||||
noPerm bool // whether lf has no permission to open the directory
|
||||
}
|
||||
|
||||
func newDir(path string) *dir {
|
||||
@@ -97,6 +98,7 @@ func newDir(path string) *dir {
|
||||
path: path,
|
||||
files: files,
|
||||
allFiles: files,
|
||||
noPerm: os.IsPermission(err),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +207,7 @@ type nav struct {
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
renameCache []string
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
@@ -291,6 +294,7 @@ func newNav(height int) *nav {
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
renameCache: make([]string, 2),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
@@ -445,6 +449,9 @@ func (nav *nav) up(dist int) {
|
||||
dir := nav.currDir()
|
||||
|
||||
if dir.ind == 0 {
|
||||
if gOpts.wrapscroll {
|
||||
nav.bottom()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -462,6 +469,9 @@ func (nav *nav) down(dist int) {
|
||||
maxind := len(dir.files) - 1
|
||||
|
||||
if dir.ind >= maxind {
|
||||
if gOpts.wrapscroll {
|
||||
nav.top()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -730,6 +740,30 @@ func (nav *nav) del() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) rename(ui *ui) error {
|
||||
oldPath := nav.renameCache[0]
|
||||
newPath := nav.renameCache[1]
|
||||
dir, _ := filepath.Split(newPath)
|
||||
os.MkdirAll(dir, os.ModePerm)
|
||||
|
||||
if _, err := os.Stat(newPath); err == nil { // file exists
|
||||
if err := os.Remove(newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: change selection
|
||||
if err := nav.sel(newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) sync() error {
|
||||
list, cp, err := loadFiles()
|
||||
if err != nil {
|
||||
@@ -741,7 +775,7 @@ func (nav *nav) sync() error {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
|
||||
return nil
|
||||
return nav.readMarks()
|
||||
}
|
||||
|
||||
func (nav *nav) cd(wd string) error {
|
||||
@@ -762,6 +796,9 @@ func (nav *nav) cd(wd string) error {
|
||||
}
|
||||
|
||||
func (nav *nav) sel(path string) error {
|
||||
path = strings.Replace(path, "~", gUser.HomeDir, -1)
|
||||
path = filepath.Clean(path)
|
||||
|
||||
lstat, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select: %s", err)
|
||||
@@ -785,6 +822,30 @@ func (nav *nav) sel(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) globSel(pattern string, invert bool) error {
|
||||
curDir := nav.currDir()
|
||||
anyMatches := false
|
||||
|
||||
for i := 0; i < len(curDir.files); i++ {
|
||||
match, err := filepath.Match(pattern, curDir.files[i].Name())
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("glob-select: %s", err)
|
||||
}
|
||||
if match {
|
||||
anyMatches = true
|
||||
fpath := filepath.Join(curDir.path, curDir.files[i].Name())
|
||||
if _, ok := nav.selections[fpath]; ok == invert {
|
||||
nav.toggleSelection(fpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !anyMatches {
|
||||
return fmt.Errorf("glob-select: pattern not found: %s", pattern)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findMatch(name, pattern string) bool {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
@@ -942,7 +1003,17 @@ func (nav *nav) searchPrev() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) removeMark(mark string) error {
|
||||
if _, ok := nav.marks[mark]; ok {
|
||||
delete(nav.marks, mark)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("no such mark")
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) readMarks() error {
|
||||
nav.marks = make(map[string]string)
|
||||
f, err := os.Open(gMarksPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -968,14 +1039,6 @@ func (nav *nav) readMarks() error {
|
||||
}
|
||||
|
||||
func (nav *nav) writeMarks() error {
|
||||
if len(nav.marks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := nav.readMarks(); err != nil {
|
||||
return fmt.Errorf("reading marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating data directory: %s", err)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ var gOpts struct {
|
||||
dircounts bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
incsearch bool
|
||||
preview bool
|
||||
@@ -37,6 +38,7 @@ var gOpts struct {
|
||||
ignoredia bool
|
||||
smartdia bool
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
number bool
|
||||
relativenumber bool
|
||||
findlen int
|
||||
@@ -65,6 +67,7 @@ func init() {
|
||||
gOpts.dircounts = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.icons = false
|
||||
gOpts.ignorecase = true
|
||||
gOpts.incsearch = false
|
||||
gOpts.preview = true
|
||||
@@ -72,6 +75,7 @@ func init() {
|
||||
gOpts.ignoredia = false
|
||||
gOpts.smartdia = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.wrapscroll = false
|
||||
gOpts.number = false
|
||||
gOpts.relativenumber = false
|
||||
gOpts.findlen = 1
|
||||
@@ -135,6 +139,8 @@ func init() {
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||
gOpts.keys[`"`] = &callExpr{"mark-remove", nil, 1}
|
||||
gOpts.keys[`r`] = &callExpr{"rename", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ func fileInfo(f *file, d *dir) string {
|
||||
return info
|
||||
}
|
||||
|
||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap, icons iconMap) {
|
||||
if win.w < 5 || dir == nil {
|
||||
return
|
||||
}
|
||||
@@ -251,6 +251,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
return
|
||||
}
|
||||
|
||||
if dir.noPerm {
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "permission denied")
|
||||
return
|
||||
}
|
||||
|
||||
if len(dir.files) == 0 {
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||
return
|
||||
@@ -313,6 +318,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
|
||||
s = append(s, ' ')
|
||||
|
||||
if gOpts.icons {
|
||||
s = append(s, []rune(icons.get(f))...)
|
||||
s = append(s, ' ')
|
||||
}
|
||||
|
||||
for _, r := range f.Name() {
|
||||
s = append(s, r)
|
||||
}
|
||||
@@ -367,6 +377,7 @@ type ui struct {
|
||||
keyAcc []rune
|
||||
keyCount []rune
|
||||
colors colorMap
|
||||
icons iconMap
|
||||
}
|
||||
|
||||
func getWidths(wtot int) []int {
|
||||
@@ -448,6 +459,7 @@ func newUI() *ui {
|
||||
keyChan: make(chan string, 1000),
|
||||
evChan: evChan,
|
||||
colors: parseColors(),
|
||||
icons: parseIcons(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,7 +665,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
doff := len(nav.dirs) - length
|
||||
for i := 0; i < length; i++ {
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors, ui.icons)
|
||||
}
|
||||
|
||||
switch ui.cmdPrefix {
|
||||
@@ -679,7 +691,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
preview := ui.wins[len(ui.wins)-1]
|
||||
|
||||
if f.IsDir() {
|
||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons)
|
||||
} else if f.Mode().IsRegular() {
|
||||
preview.printReg(ui.regPrev)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user