Compare commits

19 Commits
Author SHA1 Message Date
Gokcehan 9f661344ed allow defining a custom rename command 2019-07-21 20:40:57 +03:00
Juris Arturs Majors bfd01e5ed8 draft rename (#197)
*  basic structure

* working rename, without making dir's and selection change

* mkdirAll if necessary

* updated TODO's

* rename with replace prompting

* path prompt and moved functionality to nav.rename()

* renewing now (no set period is needed)

* documentation, keybidning change, load file info after renaming

* go generate
2019-07-20 19:31:19 +03:00
Juris Arturs Majors 27861f06e2 correct message for folders that lf has no permission for (#203) 2019-07-20 15:44:20 +03:00
Andrew Rabert cb36e87b80 Use symlink color for directories (#195)
Resolves https://github.com/gokcehan/lf/issues/156
2019-07-02 12:43:53 +03:00
Juris Arturs Majors 30d3078559 Error clear (#192)
* reset ui msg string

* loadfileinfo after prompts too

* removed legacy from previous pr...
2019-06-30 18:53:45 +03:00
Gokcehan db224f04fe add icon support
Related #158 and #164
2019-06-28 18:08:11 +03:00
Gokcehan afca893153 clear error message on succesful commands
Related #185 and #187
2019-06-26 17:52:29 +03:00
Juris Arturs Majors 16db95707e Mark clear (#190)
* markclear

* Revert "markclear"

This reverts commit 5e3a188618.

* Revert "Revert "markclear""

This reverts commit a7a3bfebbf.

* markclear with arguments

* docs

* reverted some whitepsace

* some inline comments

* additional error handling

* wrong argument case

* consider case when argument specified clears all marks

* code cleanup and removed readMarks from writeMarks

* indentation :/

* discussed changes implemnted

* return readMarks error in sync()

* remove reset marks
2019-06-25 21:38:34 +03:00
Juris Arturs Majors bf39c7c63b glob-select implementation (#184)
* glob-select logical implementation

* documentation

* indentation

* indentation

* indentation

* save

* merge glob selects

* check if selected before toggling

* glob-unselect

* identation ...

* return early
2019-06-20 18:17:47 +03:00
ath3 eb8e516cfb Check ratios before enabling preview (#174) 2019-06-12 16:45:40 +03:00
Alexandr Bruyako 34f39f90b2 remove unused "uppercase" param of appendTransliterate(), improve readability (#172) 2019-05-27 19:39:38 +03:00
Gokcehan 4c6241ca42 clean path before select
Related #167
2019-05-18 18:21:16 +03:00
Gokcehan 8388b4f385 Revert "do not cd when select on directory"
This reverts commit f071a3ae70.

Related #167
2019-05-18 18:20:58 +03:00
Gokcehan 80ab2e4fc4 cd if first argument is a directory
Related #167
2019-05-18 17:51:32 +03:00
Gokcehan f071a3ae70 do not cd when select on directory
Related #167
2019-05-17 21:48:19 +03:00
David Pedersen f3407b2d61 Remain in command mode after cmd-history-next (#168) 2019-05-17 18:52:58 +03:00
Gokcehan a5199960ed update documentation 2019-05-14 20:27:16 +03:00
Gokcehan e69a229578 allow movement commands in cmap
Related #68
2019-05-14 20:21:24 +03:00
David Pedersen e815adc6a6 Add Wrap Scroll functionality. Fixes #126 (#166) 2019-05-12 17:21:45 +03:00
13 changed files with 471 additions and 87 deletions

No files matched your search

+8 -5
View File
@@ -137,7 +137,14 @@ func (app *app) loop() {
if gSelect != "" { if gSelect != "" {
go func() { 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!") log.Print("bye!")
if err := app.nav.writeMarks(); err != nil {
log.Printf("writing marks file: %s", err)
}
if err := app.writeHistory(); err != nil { if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err) log.Printf("writing history file: %s", err)
} }
+4 -4
View File
@@ -199,6 +199,10 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
var key string var key string
switch { 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: case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
key = "tw" key = "tw"
case f.IsDir() && f.Mode()&os.ModeSticky != 0: case f.IsDir() && f.Mode()&os.ModeSticky != 0:
@@ -207,10 +211,6 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
key = "ow" key = "ow"
case f.IsDir(): case f.IsDir():
key = "di" key = "di"
case f.linkState == working:
key = "ln"
case f.linkState == broken:
key = "or"
case f.Mode()&os.ModeNamedPipe != 0: case f.Mode()&os.ModeNamedPipe != 0:
key = "pi" key = "pi"
case f.Mode()&os.ModeSocket != 0: case f.Mode()&os.ModeSocket != 0:
+10
View File
@@ -51,13 +51,17 @@ var (
"search-next", "search-next",
"search-prev", "search-prev",
"mark-save", "mark-save",
"mark-remove",
"mark-load", "mark-load",
"rename",
"sync", "sync",
"echo", "echo",
"echomsg", "echomsg",
"echoerr", "echoerr",
"cd", "cd",
"select", "select",
"glob-select",
"glob-unselect",
"source", "source",
"push", "push",
} }
@@ -81,6 +85,9 @@ var (
"globsearch", "globsearch",
"noglobsearch", "noglobsearch",
"globsearch!", "globsearch!",
"icons",
"noicons",
"icons!",
"hidden", "hidden",
"nohidden", "nohidden",
"hidden!", "hidden!",
@@ -108,6 +115,9 @@ var (
"wrapscan", "wrapscan",
"nowrapscan", "nowrapscan",
"wrapscan!", "wrapscan!",
"wrapscroll",
"nowrapscroll",
"wrapscroll!",
"number", "number",
"nonumber", "nonumber",
"number!", "number!",
+9 -15
View File
@@ -2,7 +2,7 @@ package main
import ( import (
"strconv" "strconv"
"strings" "unicode"
) )
var normMap map[rune]rune var normMap map[rune]rune
@@ -14,19 +14,17 @@ func init() {
appendTransliterate( appendTransliterate(
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ", "ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa", "eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
true,
) )
// Vietnamese // Vietnamese
appendTransliterate( appendTransliterate(
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ", "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd", "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
true,
) )
} }
func appendTransliterate(base, norm string, uppercase bool) { func appendTransliterate(base, norm string) {
normRunes := []rune(norm) normRunes := []rune(norm)
baseRunes := []rune(base) 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 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 { for i := 0; i < lenBase; i++ {
normMap[baseRune] = normRunes[i] normMap[baseRunes[i]] = normRunes[i]
}
if uppercase { baseUpper := unicode.ToUpper(baseRunes[i])
upperBase := strings.ToUpper(base) normUpper := unicode.ToUpper(normRunes[i])
upperNorm := strings.ToUpper(norm)
normRune := []rune(upperNorm) normMap[baseUpper] = normUpper
for i, baseRune := range []rune(upperBase) {
normMap[baseRune] = normRune[i]
}
} }
} }
// Remove diacritics and make lowercase. // Remove diacritics and make lowercase.
func removeDiacritics(baseString string) string { func removeDiacritics(baseString string) string {
var normalizedRunes []rune var normalizedRunes []rune
for _, baseRune := range []rune(baseString) { for _, baseRune := range baseString {
if normRune, ok := normMap[baseRune]; ok { if normRune, ok := normMap[baseRune]; ok {
normalizedRunes = append(normalizedRunes, normRune) normalizedRunes = append(normalizedRunes, normRune)
} else { } else {
+17 -5
View File
@@ -37,6 +37,7 @@ The following commands are provided by lf with default keybindings:
redraw (default '<c-l>') redraw (default '<c-l>')
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') read (default ':')
rename (default 'r')
shell (default '$') shell (default '$')
shell-pipe (default '%') shell-pipe (default '%')
shell-wait (default '!') shell-wait (default '!')
@@ -51,6 +52,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (default 'm')
mark-load (default "'") mark-load (default "'")
mark-remove (default `"`)
The following commands are provided by lf without default keybindings: 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 echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection 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 source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) 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) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
@@ -111,6 +116,7 @@ The following options can be used to customize the behavior of lf:
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off) number boolean (default off)
relativenumber boolean (default off) relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match) 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-pipe shell command running with the ui
! shell-wait shell command waiting for key press ! shell-wait shell command waiting for key press
& shell-async shell command running asynchronously & 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 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 read and shell commands. The difference is that prefixes are not necessary in
the command line. Instead, different modes are provided to read corresponding 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. These modes are mapped to the prefix keys above by default.
commands are only used from the command line.
Syntax 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 '[...]' or '[^...] to match character sets or ranges. You can enable
'incsearch' option to jump to the current match at each keystroke while typing. '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 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'), Finding mechanism is implemented with commands 'find' (default 'f'),
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
+17 -4
View File
@@ -40,6 +40,7 @@ The following commands are provided by lf with default keybindings:
redraw (default '<c-l>') redraw (default '<c-l>')
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') read (default ':')
rename (default 'r')
shell (default '$') shell (default '$')
shell-pipe (default '%') shell-pipe (default '%')
shell-wait (default '!') shell-wait (default '!')
@@ -54,6 +55,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (default 'm')
mark-load (default "'") mark-load (default "'")
mark-remove (default '"')
The following commands are provided by lf without default keybindings: 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 echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection 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 source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) 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) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
@@ -114,6 +119,7 @@ The following options can be used to customize the behavior of lf:
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off) number boolean (default off)
relativenumber boolean (default off) relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match) 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-pipe shell command running with the ui
! shell-wait shell command waiting for key press ! shell-wait shell command waiting for key press
& shell-async shell command running asynchronously & 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 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 for read and shell commands. The difference is that prefixes are not
necessary in the command line. Instead, different modes are provided to read necessary in the command line. Instead, different modes are provided to read
corresponding commands. These modes are mapped to the prefix keys above by corresponding commands. These modes are mapped to the prefix keys above by
default. Searching commands are only used from the command line. default.
Syntax 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 character, and '[...]' or '[^...] to match character sets or ranges. You can
enable 'incsearch' option to jump to the current match at each keystroke 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 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'), Finding mechanism is implemented with commands 'find' (default 'f'),
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
+3 -3
View File
@@ -42,9 +42,9 @@ cmd open ${{
esac esac
}} }}
# rename current file without overwrite # define a custom 'rename' command without prompt for overwrite
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1 # cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
map r push :rename<space> # map r push :rename<space>
# make sure trash folder exists # make sure trash folder exists
# %mkdir -p ~/.trash # %mkdir -p ~/.trash
+207 -35
View File
@@ -71,6 +71,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.globsearch = false gOpts.globsearch = false
case "globsearch!": case "globsearch!":
gOpts.globsearch = !gOpts.globsearch gOpts.globsearch = !gOpts.globsearch
case "icons":
gOpts.icons = true
case "noicons":
gOpts.icons = false
case "icons!":
gOpts.icons = !gOpts.icons
case "hidden": case "hidden":
gOpts.sortType.option |= hiddenSort gOpts.sortType.option |= hiddenSort
app.nav.sort() app.nav.sort()
@@ -108,10 +114,18 @@ func (e *setExpr) eval(app *app, args []string) {
case "incsearch!": case "incsearch!":
gOpts.incsearch = !gOpts.incsearch gOpts.incsearch = !gOpts.incsearch
case "preview": 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 gOpts.preview = true
case "nopreview": case "nopreview":
gOpts.preview = false gOpts.preview = false
case "preview!": 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 gOpts.preview = !gOpts.preview
case "reverse": case "reverse":
gOpts.sortType.option |= reverseSort gOpts.sortType.option |= reverseSort
@@ -143,6 +157,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscan = false gOpts.wrapscan = false
case "wrapscan!": case "wrapscan!":
gOpts.wrapscan = !gOpts.wrapscan gOpts.wrapscan = !gOpts.wrapscan
case "wrapscroll":
gOpts.wrapscroll = true
case "nowrapscroll":
gOpts.wrapscroll = false
case "wrapscroll!":
gOpts.wrapscroll = !gOpts.wrapscroll
case "number": case "number":
gOpts.number = true gOpts.number = true
case "nonumber": case "nonumber":
@@ -271,31 +291,36 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.shellopts = strings.Split(e.val, ":") gOpts.shellopts = strings.Split(e.val, ":")
default: default:
app.ui.echoerrf("unknown option: %s", e.opt) app.ui.echoerrf("unknown option: %s", e.opt)
return
} }
app.ui.loadFileInfo(app.nav)
} }
func (e *mapExpr) eval(app *app, args []string) { func (e *mapExpr) eval(app *app, args []string) {
if e.expr == nil { if e.expr == nil {
delete(gOpts.keys, e.keys) 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) { func (e *cmapExpr) eval(app *app, args []string) {
if e.cmd == "" { if e.cmd == "" {
delete(gOpts.cmdkeys, e.key) 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) { func (e *cmdExpr) eval(app *app, args []string) {
if e.expr == nil { if e.expr == nil {
delete(gOpts.cmds, e.name) 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) { 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) { func insert(app *app, arg string) {
switch { switch {
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"): case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
@@ -397,10 +429,7 @@ func insert(app *app, arg string) {
} }
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case app.ui.cmdPrefix == "find-back: ": case app.ui.cmdPrefix == "find-back: ":
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight) 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 normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case app.ui.cmdPrefix == "delete?[y/N]: ": case app.ui.cmdPrefix == "delete?[y/N]: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
if arg == "y" { if arg == "y" {
if err := app.nav.del(); err != nil { if err := app.nav.del(); err != nil {
@@ -447,13 +470,29 @@ func insert(app *app, arg string) {
app.nav.unselect() app.nav.unselect()
if err := remote("send load"); err != nil { if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err) 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: ": case app.ui.cmdPrefix == "mark-save: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
@@ -461,11 +500,14 @@ func insert(app *app, arg string) {
return return
} }
app.nav.marks[arg] = wd 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: ": case app.ui.cmdPrefix == "mark-load: ":
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
@@ -487,38 +529,73 @@ func insert(app *app, arg string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd 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: default:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...) app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
} }
app.ui.loadFileInfo(app.nav)
} }
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
switch e.name { switch e.name {
case "up": case "up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count) app.nav.up(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-up": case "half-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height / 2) app.nav.up(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-up": case "page-up":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.up(e.count * app.nav.height) app.nav.up(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "down": case "down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count) app.nav.down(e.count)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "half-down": case "half-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height / 2) app.nav.down(e.count * app.nav.height / 2)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "page-down": case "page-down":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
app.nav.down(e.count * app.nav.height) app.nav.down(e.count * app.nav.height)
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "updir": case "updir":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if err := app.nav.updir(); err != nil { if err := app.nav.updir(); err != nil {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
@@ -528,6 +605,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "open": case "open":
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
normal(app)
}
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
if err != nil { if err != nil {
app.ui.echoerrf("opening: %s", err) app.ui.echoerrf("opening: %s", err)
@@ -591,8 +671,10 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "invert": case "invert":
app.nav.invert() app.nav.invert()
app.ui.loadFileInfo(app.nav)
case "unselect": case "unselect":
app.nav.unselect() app.nav.unselect()
app.ui.loadFileInfo(app.nav)
case "copy": case "copy":
if err := app.nav.save(true); err != nil { if err := app.nav.save(true); err != nil {
app.ui.echoerrf("copy: %s", err) app.ui.echoerrf("copy: %s", err)
@@ -601,7 +683,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.unselect() app.nav.unselect()
if err := remote("send sync"); err != nil { if err := remote("send sync"); err != nil {
app.ui.echoerrf("copy: %s", err) app.ui.echoerrf("copy: %s", err)
return
} }
app.ui.loadFileInfo(app.nav)
case "cut": case "cut":
if err := app.nav.save(false); err != nil { if err := app.nav.save(false); err != nil {
app.ui.echoerrf("cut: %s", err) app.ui.echoerrf("cut: %s", err)
@@ -610,7 +694,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.unselect() app.nav.unselect()
if err := remote("send sync"); err != nil { if err := remote("send sync"); err != nil {
app.ui.echoerrf("cut: %s", err) app.ui.echoerrf("cut: %s", err)
return
} }
app.ui.loadFileInfo(app.nav)
case "paste": case "paste":
if cmd, ok := gOpts.cmds["paste"]; ok { if cmd, ok := gOpts.cmds["paste"]; ok {
cmd.eval(app, e.args) cmd.eval(app, e.args)
@@ -618,12 +704,15 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("paste: %s", err) app.ui.echoerrf("paste: %s", err)
return return
} }
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
case "delete": case "delete":
if cmd, ok := gOpts.cmds["delete"]; ok { if cmd, ok := gOpts.cmds["delete"]; ok {
cmd.eval(app, e.args) cmd.eval(app, e.args)
app.nav.unselect() app.nav.unselect()
if err := remote("send load"); err != nil { if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err) app.ui.echoerrf("delete: %s", err)
return
} }
} else { } else {
if _, err := app.nav.currFileOrSelections(); err != nil { 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.cmdPrefix = "delete?[y/N]: "
} }
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
case "clear": case "clear":
if err := saveFiles(nil, false); err != nil { if err := saveFiles(nil, false); err != nil {
app.ui.echoerrf("clear: %s", err) 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 { if err := remote("send sync"); err != nil {
app.ui.echoerrf("clear: %s", err) app.ui.echoerrf("clear: %s", err)
return
} }
app.ui.loadFileInfo(app.nav)
case "draw": case "draw":
case "redraw": case "redraw":
app.ui.sync() app.ui.sync()
app.ui.renew() app.ui.renew()
app.nav.height = app.ui.wins[0].h app.nav.height = app.ui.wins[0].h
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
case "load": case "load":
app.nav.renew() app.nav.renew()
case "reload": case "reload":
if err := app.nav.reload(); err != nil { if err := app.nav.reload(); err != nil {
app.ui.echoerrf("reload: %s", err) app.ui.echoerrf("reload: %s", err)
} }
app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav)
case "read": case "read":
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
case "shell": case "shell":
@@ -736,6 +833,27 @@ func (e *callExpr) eval(app *app, args []string) {
case "mark-load": case "mark-load":
app.ui.menuBuf = listMarks(app.nav.marks) app.ui.menuBuf = listMarks(app.nav.marks)
app.ui.cmdPrefix = "mark-load: " 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": case "sync":
if err := app.nav.sync(); err != nil { if err := app.nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err) app.ui.echoerrf("sync: %s", err)
@@ -803,12 +921,33 @@ func (e *callExpr) eval(app *app, args []string) {
if wd != path { if wd != path {
app.nav.marks["'"] = wd 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": case "source":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.echoerr("source: requires an argument") app.ui.echoerr("source: requires an argument")
return return
} }
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1)) app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
app.ui.loadFileInfo(app.nav)
case "push": case "push":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.echoerr("push: requires an argument") 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.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case "cmd-complete": case "cmd-complete":
var matches []string var matches []string
switch app.ui.cmdPrefix { switch app.ui.cmdPrefix {
@@ -926,6 +1062,45 @@ func (e *callExpr) eval(app *app, args []string) {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
} else { } 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.loadFile(app.nav)
app.ui.loadFileInfo(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.menuBuf = nil
app.ui.cmdAccLeft = nil app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil app.ui.cmdAccRight = nil
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ":"
return return
} }
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd] cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
@@ -1029,10 +1204,7 @@ func (e *callExpr) eval(app *app, args []string) {
if app.cmd != nil { if app.cmd != nil {
app.cmd.Process.Kill() app.cmd.Process.Kill()
} }
app.ui.menuBuf = nil normal(app)
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
case "cmd-word": case "cmd-word":
if len(app.ui.cmdAccRight) == 0 { if len(app.ui.cmdAccRight) == 0 {
return return
+88
View File
@@ -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 " "
}
+15 -4
View File
@@ -47,6 +47,7 @@ The following commands are provided by lf with default keybindings:
redraw (default '<c-l>') redraw (default '<c-l>')
reload (default '<c-r>') reload (default '<c-r>')
read (default ':') read (default ':')
rename (default 'r')
shell (default '$') shell (default '$')
shell-pipe (default '%') shell-pipe (default '%')
shell-wait (default '!') shell-wait (default '!')
@@ -61,6 +62,7 @@ The following commands are provided by lf with default keybindings:
search-prev (default 'N') search-prev (default 'N')
mark-save (default 'm') mark-save (default 'm')
mark-load (default "'") mark-load (default "'")
mark-remove (default `"`)
.EE .EE
.PP .PP
The following commands are provided by lf without default keybindings: 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 echoerr same as echomsg but red color
cd change working directory to the argument cd change working directory to the argument
select change current file selection 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 source read the configuration file in the argument
push simulate key pushes given in the argument push simulate key pushes given in the argument
delete remove the current file or selected file(s) 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) dirfirst boolean (default on)
drawbox boolean (default off) drawbox boolean (default off)
globsearch boolean (default off) globsearch boolean (default off)
icons boolean (default off)
hidden boolean (default off) hidden boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
@@ -126,6 +131,7 @@ The following options can be used to customize the behavior of lf:
smartcase boolean (default on) smartcase boolean (default on)
smartdia boolean (default off) smartdia boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
wrapscroll boolean (default off)
number boolean (default off) number boolean (default off)
relativenumber boolean (default off) relativenumber boolean (default off)
findlen integer (default 1) (zero to prompt until single match) 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-pipe shell command running with the ui
! shell-wait shell command waiting for key press ! shell-wait shell command waiting for key press
& shell-async shell command running asynchronously & shell-async shell command running asynchronously
/ search search file in current directory
? search-back search file in the reverse order
.EE .EE
.PP .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 .SH SYNTAX
Characters from '#' to newline are comments and ignored: Characters from '#' to newline are comments and ignored:
.PP .PP
@@ -558,7 +562,14 @@ By default, lf does not assign 'delete' command to a key to protect new users. Y
.SH SEARCHING FILES .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. 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 .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 .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. 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 .PP
+72 -9
View File
@@ -82,6 +82,7 @@ type dir struct {
files []*file // displayed files in directory including or excluding hidden ones files []*file // displayed files in directory including or excluding hidden ones
allFiles []*file // all files in directory including hidden ones (same array as files) allFiles []*file // all files in directory including hidden ones (same array as files)
sortType sortType // sort method and options from last sort 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 { func newDir(path string) *dir {
@@ -97,6 +98,7 @@ func newDir(path string) *dir {
path: path, path: path,
files: files, files: files,
allFiles: files, allFiles: files,
noPerm: os.IsPermission(err),
} }
} }
@@ -205,6 +207,7 @@ type nav struct {
regCache map[string]*reg regCache map[string]*reg
saves map[string]bool saves map[string]bool
marks map[string]string marks map[string]string
renameCache []string
selections map[string]int selections map[string]int
selectionInd int selectionInd int
height int height int
@@ -291,6 +294,7 @@ func newNav(height int) *nav {
regCache: make(map[string]*reg), regCache: make(map[string]*reg),
saves: make(map[string]bool), saves: make(map[string]bool),
marks: make(map[string]string), marks: make(map[string]string),
renameCache: make([]string, 2),
selections: make(map[string]int), selections: make(map[string]int),
selectionInd: 0, selectionInd: 0,
height: height, height: height,
@@ -445,6 +449,9 @@ func (nav *nav) up(dist int) {
dir := nav.currDir() dir := nav.currDir()
if dir.ind == 0 { if dir.ind == 0 {
if gOpts.wrapscroll {
nav.bottom()
}
return return
} }
@@ -462,6 +469,9 @@ func (nav *nav) down(dist int) {
maxind := len(dir.files) - 1 maxind := len(dir.files) - 1
if dir.ind >= maxind { if dir.ind >= maxind {
if gOpts.wrapscroll {
nav.top()
}
return return
} }
@@ -730,6 +740,30 @@ func (nav *nav) del() error {
return nil 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 { func (nav *nav) sync() error {
list, cp, err := loadFiles() list, cp, err := loadFiles()
if err != nil { if err != nil {
@@ -741,7 +775,7 @@ func (nav *nav) sync() error {
nav.saves[f] = cp nav.saves[f] = cp
} }
return nil return nav.readMarks()
} }
func (nav *nav) cd(wd string) error { 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 { func (nav *nav) sel(path string) error {
path = strings.Replace(path, "~", gUser.HomeDir, -1)
path = filepath.Clean(path)
lstat, err := os.Stat(path) lstat, err := os.Stat(path)
if err != nil { if err != nil {
return fmt.Errorf("select: %s", err) return fmt.Errorf("select: %s", err)
@@ -785,6 +822,30 @@ func (nav *nav) sel(path string) error {
return nil 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 { func findMatch(name, pattern string) bool {
if gOpts.ignorecase { if gOpts.ignorecase {
lpattern := strings.ToLower(pattern) lpattern := strings.ToLower(pattern)
@@ -942,7 +1003,17 @@ func (nav *nav) searchPrev() error {
return nil 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 { func (nav *nav) readMarks() error {
nav.marks = make(map[string]string)
f, err := os.Open(gMarksPath) f, err := os.Open(gMarksPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil
@@ -968,14 +1039,6 @@ func (nav *nav) readMarks() error {
} }
func (nav *nav) writeMarks() 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 { if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %s", err) return fmt.Errorf("creating data directory: %s", err)
} }
+6
View File
@@ -30,6 +30,7 @@ var gOpts struct {
dircounts bool dircounts bool
drawbox bool drawbox bool
globsearch bool globsearch bool
icons bool
ignorecase bool ignorecase bool
incsearch bool incsearch bool
preview bool preview bool
@@ -37,6 +38,7 @@ var gOpts struct {
ignoredia bool ignoredia bool
smartdia bool smartdia bool
wrapscan bool wrapscan bool
wrapscroll bool
number bool number bool
relativenumber bool relativenumber bool
findlen int findlen int
@@ -65,6 +67,7 @@ func init() {
gOpts.dircounts = false gOpts.dircounts = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.globsearch = false gOpts.globsearch = false
gOpts.icons = false
gOpts.ignorecase = true gOpts.ignorecase = true
gOpts.incsearch = false gOpts.incsearch = false
gOpts.preview = true gOpts.preview = true
@@ -72,6 +75,7 @@ func init() {
gOpts.ignoredia = false gOpts.ignoredia = false
gOpts.smartdia = false gOpts.smartdia = false
gOpts.wrapscan = true gOpts.wrapscan = true
gOpts.wrapscroll = false
gOpts.number = false gOpts.number = false
gOpts.relativenumber = false gOpts.relativenumber = false
gOpts.findlen = 1 gOpts.findlen = 1
@@ -135,6 +139,8 @@ func init() {
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1} gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1} gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
gOpts.keys["'"] = &callExpr{"mark-load", 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-n>"] = &callExpr{"cmd-history-next", nil, 1}
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1} gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
+15 -3
View File
@@ -241,7 +241,7 @@ func fileInfo(f *file, d *dir) string {
return info 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 { if win.w < 5 || dir == nil {
return return
} }
@@ -251,6 +251,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
return return
} }
if dir.noPerm {
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "permission denied")
return
}
if len(dir.files) == 0 { if len(dir.files) == 0 {
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty") win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
return return
@@ -313,6 +318,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
s = append(s, ' ') s = append(s, ' ')
if gOpts.icons {
s = append(s, []rune(icons.get(f))...)
s = append(s, ' ')
}
for _, r := range f.Name() { for _, r := range f.Name() {
s = append(s, r) s = append(s, r)
} }
@@ -367,6 +377,7 @@ type ui struct {
keyAcc []rune keyAcc []rune
keyCount []rune keyCount []rune
colors colorMap colors colorMap
icons iconMap
} }
func getWidths(wtot int) []int { func getWidths(wtot int) []int {
@@ -448,6 +459,7 @@ func newUI() *ui {
keyChan: make(chan string, 1000), keyChan: make(chan string, 1000),
evChan: evChan, evChan: evChan,
colors: parseColors(), colors: parseColors(),
icons: parseIcons(),
} }
} }
@@ -653,7 +665,7 @@ func (ui *ui) draw(nav *nav) {
doff := len(nav.dirs) - length doff := len(nav.dirs) - length
for i := 0; i < length; i++ { 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 { switch ui.cmdPrefix {
@@ -679,7 +691,7 @@ func (ui *ui) draw(nav *nav) {
preview := ui.wins[len(ui.wins)-1] preview := ui.wins[len(ui.wins)-1]
if f.IsDir() { 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() { } else if f.Mode().IsRegular() {
preview.printReg(ui.regPrev) preview.printReg(ui.regPrev)
} }