Compare commits

42 Commits
Author SHA1 Message Date
Gokcehan 2b445aa205 update doc 2020-07-26 00:29:50 +03:00
Gokcehan d2414f7580 escape key disables key binding lookup
Related #361
2020-07-26 00:24:04 +03:00
Gokcehan 8be63a9c83 cleanup 2020-07-22 01:55:21 +03:00
Alexey Yerin c630293cc2 Print message in status line after copying/moving (#427)
* Print message in status line after copying/moving

* Print message only when there's no errors

* Don't print number of copied files

* Fix error handling

* Send message to channel instead of direct ui.echo
2020-07-22 01:53:02 +03:00
Gokcehan 9c891307f3 cleanup 2020-07-20 02:47:33 +03:00
Gokcehan 9539daf8df handle relative paths in 'toggle' command 2020-07-20 02:22:31 +03:00
Gokcehan 7174b7e307 handle broken links with 'select' command
Related #201
2020-07-20 02:15:30 +03:00
Gokcehan 6d1a840587 handle unicode characters in 'push' command
Related #250
2020-07-20 01:36:22 +03:00
Gokcehan 490a4a9d07 clear previous errors in prompting commands
Related #185
2020-07-20 01:09:54 +03:00
Gokcehan a6544757db cleanup 2020-07-20 00:44:37 +03:00
Gokcehan f8daa60b31 expand '%w' in 'promptfmt' with a trailing slash
Related #421
2020-07-20 00:19:42 +03:00
Alexey Yerin 3b49e1a2b6 Add check for truncatechar (#420)
* Add check for truncatechar

When value is longer than 1 character, it throws an error

* Use runeSliceWidth instead of len
2020-07-19 21:28:06 +03:00
Alexey Yerin d0cd181eb6 Ability to customize filename truncating (#417)
* Add truncatechar option

* Add ability to set truncatechar via `set` command

* Add completion for truncatechar option

* Actually use truncatechar option when truncating

* Add truncatechar option to docs
2020-07-18 03:08:25 +03:00
Gokcehan 9880104c12 quote filenames in prompts 2020-07-17 02:17:24 +03:00
Gokcehan ffdcb71897 make select work properly with loading directories
Related #370
2020-07-17 02:12:10 +03:00
Gokcehan 707d927788 handle abs paths in rename 2020-07-17 00:46:46 +03:00
Gokcehan 0a22e7c5c8 check reg and dir while loading 2020-07-17 00:33:37 +03:00
Gokcehan 2f056ad359 select new file after rename
Related #197
2020-07-17 00:28:32 +03:00
Gokcehan e7fb56391f remove redundant parameter in ui renew 2020-07-16 23:17:11 +03:00
Gokcehan 3e36500901 check modtime/sorting again when dirs are updated
Related #338
2020-07-16 23:13:40 +03:00
gotroyb127 f2e3c7a0ce shell-async commands now don't create zombie processes (#407) 2020-07-14 19:44:13 +03:00
gotroyb127 75e59cdd08 'toggle' command now toggles selection on its arguments when at least one (#409)
* 'toggle' command now toggles selection on its arguments when given and some cleanup

* update doc
2020-07-14 19:28:01 +03:00
Doron Behar 001ee5bfae Update termbox related modules to fix #392 (#404) 2020-07-11 22:28:34 +03:00
Gokcehan e1b939bf7c skip trailing spaces in scanner
Related #301
2020-07-04 04:07:01 +03:00
Gokcehan ce4ea6ea53 start server process in home directory
Related #287
2020-07-04 03:41:37 +03:00
Gokcehan 45552cf809 use correct search directions with incsearch
Related #284
2020-07-04 03:32:05 +03:00
Gokcehan c937dab9e9 remove hidden cursor movement
Related #22 and #381
2020-07-04 01:21:07 +03:00
Gokcehan 1119ba0d25 expand tab characters to spaces 2020-07-04 01:08:35 +03:00
Gokcehan 83a6e506d2 implement hidden option in windows 2020-07-04 00:41:12 +03:00
Gokcehan bc2a80fd6e handle cross-device linking in windows 2020-07-04 00:16:16 +03:00
Gokcehan e2bf773f3b fallback to copy-del for cross-device linking
Related #151
2020-07-03 21:42:13 +03:00
gotroyb127 4d3e1cfd6e added a count field to listExpr and toggle now ignores count (#394) 2020-07-03 18:29:55 +03:00
Gokcehan fd73a53f84 update doc
Related #352 and #386
2020-06-17 06:35:28 +03:00
Ivan Podmazov cbb559346d fix toggle behaviour (#352) (#386) 2020-06-17 06:17:30 +03:00
Gokcehan 5d1136abfe keep the destination file before rename
Related #343
2020-06-17 05:19:16 +03:00
Gokcehan 0e3910652a cleanup 2020-06-11 04:11:40 +03:00
Gokcehan 99cee56d6e reload directories when 'hiddenfiles' is changed 2020-06-11 03:16:24 +03:00
Gokcehan 25e487cc51 check pattern errors when 'hiddenfiles' is set 2020-06-11 03:14:45 +03:00
Adam Abrams 72facea2a0 add hiddenFiles option (#372)
* add hiddenFiles option

* harden and improve syntax

* refactor name and add to docs
2020-06-11 02:52:15 +03:00
wedensandwedens 8933a3eafe show symlink destination (#374)
Co-authored-by: wedens <kirill.wedens@gmail.com>
2020-06-09 02:38:46 +03:00
gotroyb127 41e0bb32cd fix tilde expansion and numbering (#373)
* Fixed issue #346 and changed the format of numbers when both relativenumber and number are set.

* Fixed issue #349 (incorrect replacement of '~' with user's home direcotry).

* Changed where appropriate so that tilde replacements happens correctly.

* Added a function to replace tilde with user's home directory, only when it should.

* Renamed ReplaceTilde to replaceTilde so that it won't get exported and removed some ';' at the end of some lines.
2020-06-07 20:53:25 +03:00
Provessor c49140ab36 Properly handle SIGHUP and SIGTERM (#305)
* Properly handle SIGHUP, SIGINT and SIGTERM

* Do not handle SIGINT

* Cancel current copy/move/delete operation

* Better cancel current operation
2020-04-13 19:32:42 +03:00
19 changed files with 602 additions and 382 deletions

No files matched your search

+31 -8
View File
@@ -7,8 +7,10 @@ import (
"log" "log"
"os" "os"
"os/exec" "os/exec"
"os/signal"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"time" "time"
) )
@@ -34,11 +36,24 @@ func newApp() *app {
ui := newUI() ui := newUI()
nav := newNav(ui.wins[0].h) nav := newNav(ui.wins[0].h)
quitChan := make(chan bool, 1)
osChan := make(chan os.Signal, 1)
signal.Notify(osChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
go func() {
<-osChan
nav.copyTotalChan <- -nav.copyTotal
nav.moveTotalChan <- -nav.moveTotal
nav.deleteTotalChan <- -nav.deleteTotal
quitChan <- true
return
}()
return &app{ return &app{
ui: ui, ui: ui,
nav: nav, nav: nav,
ticker: new(time.Ticker), ticker: new(time.Ticker),
quitChan: make(chan bool, 1), quitChan: quitChan,
} }
} }
@@ -137,10 +152,10 @@ func (app *app) loop() {
if gSelect != "" { if gSelect != "" {
go func() { go func() {
stat, err := os.Stat(gSelect) lstat, err := os.Lstat(gSelect)
if err != nil { if err != nil {
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1} app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
} else if stat.IsDir() { } else if lstat.IsDir() {
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1} app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
} else { } else {
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1} app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
@@ -197,9 +212,7 @@ func (app *app) loop() {
} }
defer f.Close() defer f.Close()
dir := app.nav.currDir() _, err = f.WriteString(app.nav.currDir().path)
_, err = f.WriteString(dir.path)
if err != nil { if err != nil {
log.Printf("writing last dir file: %s", err) log.Printf("writing last dir file: %s", err)
} }
@@ -253,6 +266,8 @@ func (app *app) loop() {
} }
app.ui.draw(app.nav) app.ui.draw(app.nav)
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
app.nav.checkDir(d)
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {
d.ind = prev.ind d.ind = prev.ind
@@ -281,6 +296,8 @@ func (app *app) loop() {
app.ui.draw(app.nav) app.ui.draw(app.nav)
case r := <-app.nav.regChan: case r := <-app.nav.regChan:
app.nav.checkReg(r)
app.nav.regCache[r.path] = r app.nav.regCache[r.path] = r
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
@@ -307,8 +324,8 @@ func (app *app) loop() {
func (app *app) exportFiles() { func (app *app) exportFiles() {
var currFile string var currFile string
if f, err := app.nav.currFile(); err == nil { if curr, err := app.nav.currFile(); err == nil {
currFile = f.path currFile = curr.path
} }
currSelections := app.nav.currSelections() currSelections := app.nav.currSelections()
@@ -414,5 +431,11 @@ func (app *app) runShell(s string, args []string, prefix string) {
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
app.ui.exprChan <- &callExpr{"load", nil, 1} app.ui.exprChan <- &callExpr{"load", nil, 1}
}() }()
case "&":
go func() {
if err := cmd.Wait(); err != nil {
log.Printf("running shell: %s", err)
}
}()
} }
} }
+19 -17
View File
@@ -31,13 +31,11 @@ var (
"copy", "copy",
"cut", "cut",
"paste", "paste",
"delete",
"clear", "clear",
"draw",
"redraw", "redraw",
"load",
"reload", "reload",
"read", "read",
"rename",
"shell", "shell",
"shell-pipe", "shell-pipe",
"shell-wait", "shell-wait",
@@ -53,7 +51,8 @@ var (
"mark-save", "mark-save",
"mark-remove", "mark-remove",
"mark-load", "mark-load",
"rename", "draw",
"load",
"sync", "sync",
"echo", "echo",
"echomsg", "echomsg",
@@ -64,6 +63,7 @@ var (
"glob-unselect", "glob-unselect",
"source", "source",
"push", "push",
"delete",
} }
gOptWords = []string{ gOptWords = []string{
@@ -85,12 +85,12 @@ var (
"globsearch", "globsearch",
"noglobsearch", "noglobsearch",
"globsearch!", "globsearch!",
"icons",
"noicons",
"icons!",
"hidden", "hidden",
"nohidden", "nohidden",
"hidden!", "hidden!",
"icons",
"noicons",
"icons!",
"ignorecase", "ignorecase",
"noignorecase", "noignorecase",
"ignorecase!", "ignorecase!",
@@ -100,9 +100,15 @@ var (
"incsearch", "incsearch",
"noincsearch", "noincsearch",
"incsearch!", "incsearch!",
"number",
"nonumber",
"number!",
"preview", "preview",
"nopreview", "nopreview",
"preview!", "preview!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"reverse", "reverse",
"noreverse", "noreverse",
"reverse!", "reverse!",
@@ -118,27 +124,23 @@ var (
"wrapscroll", "wrapscroll",
"nowrapscroll", "nowrapscroll",
"wrapscroll!", "wrapscroll!",
"number",
"nonumber",
"number!",
"relativenumber",
"norelativenumber",
"relativenumber!",
"findlen", "findlen",
"period", "period",
"scrolloff", "scrolloff",
"tabstop", "tabstop",
"errorfmt", "errorfmt",
"filesep", "filesep",
"hiddenfiles",
"ifs", "ifs",
"info",
"previewer", "previewer",
"promptfmt", "promptfmt",
"ratios",
"shell", "shell",
"shellopts",
"sortby", "sortby",
"timefmt", "timefmt",
"ratios", "truncatechar",
"info",
"shellopts",
} }
) )
@@ -224,7 +226,7 @@ func matchExec(s string) (matches []string, longest string) {
} }
func matchFile(s string) (matches []string, longest string) { func matchFile(s string) (matches []string, longest string) {
dir := strings.Replace(s, "~", gUser.HomeDir, -1) dir := replaceTilde(s)
if !filepath.IsAbs(dir) { if !filepath.IsAbs(dir) {
wd, err := os.Getwd() wd, err := os.Getwd()
+2 -2
View File
@@ -86,12 +86,12 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
for _, src := range srcs { for _, src := range srcs {
dst := filepath.Join(dstDir, filepath.Base(src)) dst := filepath.Join(dstDir, filepath.Base(src))
_, err := os.Stat(dst) _, err := os.Lstat(dst)
if !os.IsNotExist(err) { if !os.IsNotExist(err) {
var newPath string var newPath string
for i := 1; !os.IsNotExist(err); i++ { for i := 1; !os.IsNotExist(err); i++ {
newPath = fmt.Sprintf("%s.~%d~", dst, i) newPath = fmt.Sprintf("%s.~%d~", dst, i)
_, err = os.Stat(newPath) _, err = os.Lstat(newPath)
} }
dst = newPath dst = newPath
} }
+15 -13
View File
@@ -27,7 +27,6 @@ The following commands are provided by lf with default keybindings:
quit (default 'q') quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle (default '<space>')
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
copy (default 'y') copy (default 'y')
@@ -64,6 +63,7 @@ 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
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect 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
@@ -106,34 +106,36 @@ 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)
icons boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
number boolean (default off)
preview boolean (default on) preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off) reverse boolean (default off)
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) wrapscroll boolean (default off)
number 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)
period integer (default 0) (zero to disable periodic loading) period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty) ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty) previewer string (default '') (not filtered if empty)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
ratios string (default '1:2:3')
shell string (default 'sh') shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural') sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006') timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3') truncatechar string (default '~')
info string (default '')
shellopts string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -178,6 +180,7 @@ The following additional keybindings are provided by default:
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd ~ map gh cd ~
map <space> :toggle; down
The following keybindings to applications are provided by default: The following keybindings to applications are provided by default:
@@ -534,11 +537,10 @@ in GNU cp is added to the new files or directories. Only file modes are
preserved and all other attributes are ignored including ownership, timestamps, preserved and all other attributes are ignored including ownership, timestamps,
context, links, and xattr. Special files such as character and block devices, context, links, and xattr. Special files such as character and block devices,
named pipes, and sockets are skipped and links are followed. Moving is named pipes, and sockets are skipped and links are followed. Moving is
performed using the rename operation of the underlying OS. This can fail to performed using the rename operation of the underlying OS. For cross-device
move files between different partitions when it needs to copy files. For these moving, lf falls back to copying and then deletes the original files if there
cases, users are expected to explicitly copy files and then delete the old ones are no errors. Operation errors are shown in the message line as well as the
manually. Operation errors are shown in the message line as well as the log log file and they do not preemptively finish the corresponding file operation.
file and they do not preemptively finish the corresponding file operation.
File operations can be performed on the current selected file or alternatively File operations can be performed on the current selected file or alternatively
on multiple files by selecting them first. When you 'copy' a file, lf doesn't on multiple files by selecting them first. When you 'copy' a file, lf doesn't
@@ -713,7 +715,7 @@ other command:
GIT_PS1_SHOWUNTRACKEDFILES=auto GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true git=$(__git_ps1 " (%s)") || true
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m" fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f$git\033[0m"
lf -remote "send $id set promptfmt \"$fmt\"" lf -remote "send $id set promptfmt \"$fmt\""
}} }}
+14 -12
View File
@@ -30,7 +30,6 @@ The following commands are provided by lf with default keybindings:
quit (default 'q') quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle (default '<space>')
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
copy (default 'y') copy (default 'y')
@@ -67,6 +66,7 @@ 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
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect 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
@@ -109,34 +109,36 @@ 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)
icons boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
number boolean (default off)
preview boolean (default on) preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off) reverse boolean (default off)
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) wrapscroll boolean (default off)
number 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)
period integer (default 0) (zero to disable periodic loading) period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
errorfmt string (default "\033[7;31;47m%s\033[0m") errorfmt string (default "\033[7;31;47m%s\033[0m")
filesep string (default "\n") filesep string (default "\n")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty) ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty) previewer string (default '') (not filtered if empty)
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m") promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
ratios string (default '1:2:3')
shell string (default 'sh') shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural') sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006') timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3') truncatechar string (default '~')
info string (default '')
shellopts string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -181,6 +183,7 @@ The following additional keybindings are provided by default:
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd ~ map gh cd ~
map <space> :toggle; down
The following keybindings to applications are provided by default: The following keybindings to applications are provided by default:
@@ -557,10 +560,9 @@ option in GNU cp is added to the new files or directories. Only file modes
are preserved and all other attributes are ignored including ownership, are preserved and all other attributes are ignored including ownership,
timestamps, context, links, and xattr. Special files such as character and timestamps, context, links, and xattr. Special files such as character and
block devices, named pipes, and sockets are skipped and links are followed. block devices, named pipes, and sockets are skipped and links are followed.
Moving is performed using the rename operation of the underlying OS. This Moving is performed using the rename operation of the underlying OS. For
can fail to move files between different partitions when it needs to copy cross-device moving, lf falls back to copying and then deletes the original
files. For these cases, users are expected to explicitly copy files and then files if there are no errors. Operation errors are shown in the message line
delete the old ones manually. Operation errors are shown in the message line
as well as the log file and they do not preemptively finish the as well as the log file and they do not preemptively finish the
corresponding file operation. corresponding file operation.
@@ -745,7 +747,7 @@ define any other command:
GIT_PS1_SHOWUNTRACKEDFILES=auto GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true git=$(__git_ps1 " (%s)") || true
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m" fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f$git\033[0m"
lf -remote "send $id set promptfmt \"$fmt\"" lf -remote "send $id set promptfmt \"$fmt\""
}} }}
+179 -120
View File
@@ -71,12 +71,6 @@ 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()
@@ -95,6 +89,12 @@ func (e *setExpr) eval(app *app, args []string) {
app.nav.position() app.nav.position()
app.ui.sort() app.ui.sort()
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
case "icons":
gOpts.icons = true
case "noicons":
gOpts.icons = false
case "icons!":
gOpts.icons = !gOpts.icons
case "ignorecase": case "ignorecase":
gOpts.ignorecase = true gOpts.ignorecase = true
case "noignorecase": case "noignorecase":
@@ -113,6 +113,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.incsearch = false gOpts.incsearch = false
case "incsearch!": case "incsearch!":
gOpts.incsearch = !gOpts.incsearch gOpts.incsearch = !gOpts.incsearch
case "number":
gOpts.number = true
case "nonumber":
gOpts.number = false
case "number!":
gOpts.number = !gOpts.number
case "preview": case "preview":
if len(gOpts.ratios) < 2 { if len(gOpts.ratios) < 2 {
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'") app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
@@ -127,6 +133,12 @@ func (e *setExpr) eval(app *app, args []string) {
return return
} }
gOpts.preview = !gOpts.preview gOpts.preview = !gOpts.preview
case "relativenumber":
gOpts.relativenumber = true
case "norelativenumber":
gOpts.relativenumber = false
case "relativenumber!":
gOpts.relativenumber = !gOpts.relativenumber
case "reverse": case "reverse":
gOpts.sortType.option |= reverseSort gOpts.sortType.option |= reverseSort
app.nav.sort() app.nav.sort()
@@ -163,18 +175,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.wrapscroll = false gOpts.wrapscroll = false
case "wrapscroll!": case "wrapscroll!":
gOpts.wrapscroll = !gOpts.wrapscroll gOpts.wrapscroll = !gOpts.wrapscroll
case "number":
gOpts.number = true
case "nonumber":
gOpts.number = false
case "number!":
gOpts.number = !gOpts.number
case "relativenumber":
gOpts.relativenumber = true
case "norelativenumber":
gOpts.relativenumber = false
case "relativenumber!":
gOpts.relativenumber = !gOpts.relativenumber
case "findlen": case "findlen":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
@@ -229,14 +229,67 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.errorfmt = e.val gOpts.errorfmt = e.val
case "filesep": case "filesep":
gOpts.filesep = e.val gOpts.filesep = e.val
case "hiddenfiles":
toks := strings.Split(e.val, ":")
for _, s := range toks {
if s == "" {
app.ui.echoerr("hiddenfiles: glob should be non-empty")
return
}
_, err := filepath.Match(s, "a")
if err != nil {
app.ui.echoerrf("hiddenfiles: %s", err)
return
}
}
gOpts.hiddenfiles = toks
app.nav.sort()
app.nav.position()
app.ui.sort()
app.ui.loadFile(app.nav)
case "ifs": case "ifs":
gOpts.ifs = e.val gOpts.ifs = e.val
case "info":
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "", "size", "time", "atime", "ctime":
default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
return
}
}
gOpts.info = toks
case "previewer": case "previewer":
gOpts.previewer = strings.Replace(e.val, "~", gUser.HomeDir, -1) gOpts.previewer = replaceTilde(e.val)
case "promptfmt": case "promptfmt":
gOpts.promptfmt = e.val gOpts.promptfmt = e.val
case "ratios":
toks := strings.Split(e.val, ":")
var rats []int
for _, s := range toks {
n, err := strconv.Atoi(s)
if err != nil {
app.ui.echoerrf("ratios: %s", err)
return
}
if n <= 0 {
app.ui.echoerr("ratios: value should be a positive number")
return
}
rats = append(rats, n)
}
if gOpts.preview && len(rats) < 2 {
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
return
}
gOpts.ratios = rats
app.ui.wins = getWins()
app.ui.loadFile(app.nav)
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
case "shellopts":
gOpts.shellopts = strings.Split(e.val, ":")
case "sortby": case "sortby":
switch e.val { switch e.val {
case "natural": case "natural":
@@ -261,41 +314,13 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.sort() app.ui.sort()
case "timefmt": case "timefmt":
gOpts.timefmt = e.val gOpts.timefmt = e.val
case "ratios": case "truncatechar":
toks := strings.Split(e.val, ":") if runeSliceWidth([]rune(e.val)) != 1 {
var rats []int app.ui.echoerr("truncatechar: value should be a single character")
for _, s := range toks {
n, err := strconv.Atoi(s)
if err != nil {
app.ui.echoerrf("ratios: %s", err)
return
}
if n <= 0 {
app.ui.echoerr("ratios: value should be a positive number")
return
}
rats = append(rats, n)
}
if gOpts.preview && len(rats) < 2 {
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
return return
} }
gOpts.ratios = rats
app.ui.wins = getWins() gOpts.truncatechar = e.val
app.ui.loadFile(app.nav)
case "info":
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "", "size", "time", "atime", "ctime":
default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
return
}
}
gOpts.info = toks
case "shellopts":
gOpts.shellopts = strings.Split(e.val, ":")
default: default:
app.ui.echoerrf("unknown option: %s", e.opt) app.ui.echoerrf("unknown option: %s", e.opt)
return return
@@ -360,20 +385,13 @@ func update(app *app) {
case gOpts.incsearch && app.ui.cmdPrefix == "/": case gOpts.incsearch && app.ui.cmdPrefix == "/":
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
last := app.nav.currDir() dir := app.nav.currDir()
last.ind = app.nav.searchInd dir.ind = app.nav.searchInd
last.pos = app.nav.searchPos dir.pos = app.nav.searchPos
if app.nav.searchBack { if err := app.nav.searchNext(); err != nil {
if err := app.nav.searchPrev(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search)
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) return
return
}
} else {
if err := app.nav.searchNext(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
}
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
@@ -381,20 +399,13 @@ func update(app *app) {
case gOpts.incsearch && app.ui.cmdPrefix == "?": case gOpts.incsearch && app.ui.cmdPrefix == "?":
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight) app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
last := app.nav.currDir() dir := app.nav.currDir()
last.ind = app.nav.searchInd dir.ind = app.nav.searchInd
last.pos = app.nav.searchPos dir.pos = app.nav.searchPos
if app.nav.searchBack { if err := app.nav.searchPrev(); err != nil {
if err := app.nav.searchNext(); err != nil { app.ui.echoerrf("search: %s: %s", err, app.nav.search)
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search) return
return
}
} else {
if err := app.nav.searchPrev(); err != nil {
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return
}
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
@@ -488,8 +499,7 @@ func insert(app *app, arg string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "replace") || case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
normal(app) normal(app)
if arg == "y" { if arg == "y" {
@@ -504,6 +514,25 @@ func insert(app *app, arg string) {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
case strings.HasPrefix(app.ui.cmdPrefix, "create"):
normal(app)
if arg == "y" {
if err := os.MkdirAll(filepath.Dir(app.nav.renameNewPath), os.ModePerm); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
if err := app.nav.rename(); 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: ":
normal(app) normal(app)
@@ -679,17 +708,25 @@ 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 "toggle": case "toggle":
for i := 0; i < e.count; i++ { if len(e.args) == 0 {
app.nav.toggle() app.nav.toggle()
} else {
dir := app.nav.currDir()
for _, path := range e.args {
if !filepath.IsAbs(path) {
path = filepath.Join(dir.path, path)
}
if _, err := os.Lstat(path); !os.IsNotExist(err) {
app.nav.toggleSelection(path)
} else {
app.ui.echoerrf("toggle: %s", err)
}
}
} }
app.ui.loadFile(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)
@@ -730,16 +767,16 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
} else { } else {
fileOrSelections, err := app.nav.currFileOrSelections() list, err := app.nav.currFileOrSelections()
if err != nil { if err != nil {
app.ui.echoerrf("delete: %s", err) app.ui.echoerrf("delete: %s", err)
return return
} }
if selections := len(fileOrSelections); selections == 1 { if len(list) == 1 {
app.ui.cmdPrefix = "delete " + fileOrSelections[0] + " [y/N]? " app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
} else { } else {
app.ui.cmdPrefix = "delete " + strconv.Itoa(selections) + " items [y/N]? " app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] "
} }
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
@@ -771,20 +808,27 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "read": case "read":
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
app.ui.loadFileInfo(app.nav)
case "shell": case "shell":
app.ui.cmdPrefix = "$" app.ui.cmdPrefix = "$"
app.ui.loadFileInfo(app.nav)
case "shell-pipe": case "shell-pipe":
app.ui.cmdPrefix = "%" app.ui.cmdPrefix = "%"
app.ui.loadFileInfo(app.nav)
case "shell-wait": case "shell-wait":
app.ui.cmdPrefix = "!" app.ui.cmdPrefix = "!"
app.ui.loadFileInfo(app.nav)
case "shell-async": case "shell-async":
app.ui.cmdPrefix = "&" app.ui.cmdPrefix = "&"
app.ui.loadFileInfo(app.nav)
case "find": case "find":
app.ui.cmdPrefix = "find: " app.ui.cmdPrefix = "find: "
app.nav.findBack = false app.nav.findBack = false
app.ui.loadFileInfo(app.nav)
case "find-back": case "find-back":
app.ui.cmdPrefix = "find-back: " app.ui.cmdPrefix = "find-back: "
app.nav.findBack = true app.nav.findBack = true
app.ui.loadFileInfo(app.nav)
case "find-next": case "find-next":
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if app.nav.findBack { if app.nav.findBack {
@@ -807,16 +851,18 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "search": case "search":
app.ui.cmdPrefix = "/" app.ui.cmdPrefix = "/"
last := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = last.ind app.nav.searchInd = dir.ind
app.nav.searchPos = last.pos app.nav.searchPos = dir.pos
app.nav.searchBack = false app.nav.searchBack = false
app.ui.loadFileInfo(app.nav)
case "search-back": case "search-back":
app.ui.cmdPrefix = "?" app.ui.cmdPrefix = "?"
last := app.nav.currDir() dir := app.nav.currDir()
app.nav.searchInd = last.ind app.nav.searchInd = dir.ind
app.nav.searchPos = last.pos app.nav.searchPos = dir.pos
app.nav.searchBack = true app.nav.searchBack = true
app.ui.loadFileInfo(app.nav)
case "search-next": case "search-next":
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if app.nav.searchBack { if app.nav.searchBack {
@@ -953,7 +999,6 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
app.ui.loadFileInfo(app.nav)
case "glob-unselect": case "glob-unselect":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.echoerr("glob-unselect: requires a pattern to match") app.ui.echoerr("glob-unselect: requires a pattern to match")
@@ -963,13 +1008,12 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("%s", err) app.ui.echoerrf("%s", err)
return 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(replaceTilde(e.args[0]))
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "push": case "push":
if len(e.args) != 1 { if len(e.args) != 1 {
@@ -990,9 +1034,9 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") { if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
last := app.nav.currDir() dir := app.nav.currDir()
last.ind = app.nav.searchInd dir.ind = app.nav.searchInd
last.pos = app.nav.searchPos dir.pos = app.nav.searchPos
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -1060,9 +1104,9 @@ func (e *callExpr) eval(app *app, args []string) {
app.runShell(s, nil, "&") app.runShell(s, nil, "&")
case "/": case "/":
if gOpts.incsearch { if gOpts.incsearch {
last := app.nav.currDir() dir := app.nav.currDir()
last.ind = app.nav.searchInd dir.ind = app.nav.searchInd
last.pos = app.nav.searchPos dir.pos = app.nav.searchPos
} }
log.Printf("search: %s", s) log.Printf("search: %s", s)
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
@@ -1075,9 +1119,9 @@ func (e *callExpr) eval(app *app, args []string) {
} }
case "?": case "?":
if gOpts.incsearch { if gOpts.incsearch {
last := app.nav.currDir() dir := app.nav.currDir()
last.ind = app.nav.searchInd dir.ind = app.nav.searchInd
last.pos = app.nav.searchPos dir.pos = app.nav.searchPos
} }
log.Printf("search-back: %s", s) log.Printf("search-back: %s", s)
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
@@ -1098,22 +1142,35 @@ func (e *callExpr) eval(app *app, args []string) {
log.Printf("getting current directory: %s", err) log.Printf("getting current directory: %s", err)
return return
} }
oldPathTo := filepath.Join(wd, curr.Name())
newPathTo := filepath.Join(wd, s) oldPath := filepath.Join(wd, curr.Name())
if oldPathTo == newPathTo {
newPath := filepath.Clean(s)
if !filepath.IsAbs(newPath) {
newPath = filepath.Join(wd, newPath)
}
if oldPath == newPath {
return return
} }
app.nav.renameCache = []string{oldPathTo, newPathTo}
if dir, _ := filepath.Split(s); dir != "" { app.nav.renameOldPath = oldPath
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil { app.nav.renameNewPath = newPath
app.ui.cmdPrefix = "create path " + dir + "?[y/N]"
return newDir := filepath.Dir(newPath)
} if _, err := os.Stat(newDir); os.IsNotExist(err) {
app.ui.cmdPrefix = "create '" + newDir + "' ? [y/N] "
return
} }
if _, err := os.Stat(newPathTo); err == nil { // file exists oldStat, err := os.Stat(oldPath)
app.ui.cmdPrefix = "replace " + s + "?[y/N]" if err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
if newStat, err := os.Stat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {
app.ui.cmdPrefix = "replace '" + newPath + "' ? [y/N] "
return return
} }
@@ -1373,7 +1430,9 @@ func (e *execExpr) eval(app *app, args []string) {
} }
func (e *listExpr) eval(app *app, args []string) { func (e *listExpr) eval(app *app, args []string) {
for _, expr := range e.exprs { for i := 0; i < e.count; i++ {
expr.eval(app, nil) for _, expr := range e.exprs {
expr.eval(app, nil)
}
} }
} }
+26 -14
View File
@@ -158,25 +158,37 @@ var gEvalTests = []struct {
{ {
":set ratios 1:2:3", ":set ratios 1:2:3",
[]string{":", "set", "ratios", "1:2:3", "\n", "\n"}, []string{":", "set", "ratios", "1:2:3", "\n", "\n"},
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}}, []expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
}, },
{ {
":set ratios 1:2:3\nset hidden", ":set ratios 1:2:3\nset hidden",
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"}, []string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}}, []expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
}, },
{ {
":set ratios 1:2:3;", ":set ratios 1:2:3;",
[]string{":", "set", "ratios", "1:2:3", ";", "\n"}, []string{":", "set", "ratios", "1:2:3", ";", "\n"},
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}}, []expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
}, },
{ {
":set ratios 1:2:3;\nset hidden", ":set ratios 1:2:3;\nset hidden",
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"}, []string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}}, []expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
},
{
"set ratios 1:2:3\n set hidden",
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
},
{
"set ratios 1:2:3 \nset hidden",
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
}, },
{ {
@@ -194,13 +206,13 @@ var gEvalTests = []struct {
{ {
"map gh :cd ~", "map gh :cd ~",
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"}, []string{"map", "gh", ":", "cd", "~", "\n", "\n"},
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}}, []expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
}, },
{ {
"map gh :cd ~;", "map gh :cd ~;",
[]string{"map", "gh", ":", "cd", "~", ";", "\n"}, []string{"map", "gh", ":", "cd", "~", ";", "\n"},
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}}, []expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
}, },
{ {
@@ -236,13 +248,13 @@ var gEvalTests = []struct {
{ {
"map u :usage", "map u :usage",
[]string{"map", "u", ":", "usage", "\n", "\n"}, []string{"map", "u", ":", "usage", "\n", "\n"},
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}}, []expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
}, },
{ {
"map u :usage;", "map u :usage;",
[]string{"map", "u", ":", "usage", ";", "\n"}, []string{"map", "u", ":", "usage", ";", "\n"},
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}}, []expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
}, },
{ {
@@ -266,13 +278,13 @@ var gEvalTests = []struct {
{ {
"map r :push :rename<space>", "map r :push :rename<space>",
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"}, []string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}}}}, []expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}, 1}}},
}, },
{ {
"map r :push :rename<space> ; set hidden", "map r :push :rename<space> ; set hidden",
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"}, []string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}}}}, []expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}, 1}}},
}, },
{ {
@@ -296,13 +308,13 @@ var gEvalTests = []struct {
{ {
"map ss :set sortby size; set info size", "map ss :set sortby size; set info size",
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", "\n", "\n"}, []string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", "\n", "\n"},
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}}, []expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
}, },
{ {
"map ss :set sortby size; set info size;", "map ss :set sortby size; set info size;",
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", ";", "\n"}, []string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", ";", "\n"},
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}}, []expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
}, },
{ {
@@ -320,7 +332,7 @@ var gEvalTests = []struct {
"gohome", &listExpr{[]expr{ "gohome", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1}, &callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""}, &setExpr{"hidden", ""},
}}, }, 1},
}}, }},
}, },
@@ -339,7 +351,7 @@ var gEvalTests = []struct {
"gh", &listExpr{[]expr{ "gh", &listExpr{[]expr{
&callExpr{"cd", []string{"~"}, 1}, &callExpr{"cd", []string{"~"}, 1},
&setExpr{"hidden", ""}, &setExpr{"hidden", ""},
}}, }, 1},
}}, }},
}, },
+2 -2
View File
@@ -3,7 +3,7 @@ module github.com/gokcehan/lf
go 1.12 go 1.12
require ( require (
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05 github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14
github.com/mattn/go-runewidth v0.0.4 github.com/mattn/go-runewidth v0.0.9
gopkg.in/djherbis/times.v1 v1.2.0 gopkg.in/djherbis/times.v1 v1.2.0
) )
+4
View File
@@ -4,7 +4,11 @@ github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c h1:qvLYQAhDC
github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk= github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05 h1:pmXx7j8+mmkFJB2+qoB1C/Mz8SWvMlHTxSWOptJrr7E= github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05 h1:pmXx7j8+mmkFJB2+qoB1C/Mz8SWvMlHTxSWOptJrr7E=
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk= github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14 h1:KKPl27Vj3HRF384G7jW7K8uCRv0Ks+GuAOkGsz4qWAs=
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM= gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8= gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
+12 -9
View File
@@ -37,7 +37,6 @@ The following commands are provided by lf with default keybindings:
quit (default 'q') quit (default 'q')
top (default 'gg' and '<home>') top (default 'gg' and '<home>')
bottom (default 'G' and '<end>') bottom (default 'G' and '<end>')
toggle (default '<space>')
invert (default 'v') invert (default 'v')
unselect (default 'u') unselect (default 'u')
copy (default 'y') copy (default 'y')
@@ -76,6 +75,7 @@ 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
toggle toggle the selection of the current file or its arguments
glob-select select files that match the given glob glob-select select files that match the given glob
glob-unselect unselect 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
@@ -121,34 +121,36 @@ 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)
icons boolean (default off)
ignorecase boolean (default on) ignorecase boolean (default on)
ignoredia boolean (default off) ignoredia boolean (default off)
incsearch boolean (default off) incsearch boolean (default off)
number boolean (default off)
preview boolean (default on) preview boolean (default on)
relativenumber boolean (default off)
reverse boolean (default off) reverse boolean (default off)
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) wrapscroll boolean (default off)
number 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)
period integer (default 0) (zero to disable periodic loading) period integer (default 0) (zero to disable periodic loading)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
errorfmt string (default "\e033[7;31;47m%s\e033[0m") errorfmt string (default "\e033[7;31;47m%s\e033[0m")
filesep string (default "\en") filesep string (default "\en")
hiddenfiles string (default '.*')
ifs string (default '') (not exported if empty) ifs string (default '') (not exported if empty)
info string (default '')
previewer string (default '') (not filtered if empty) previewer string (default '') (not filtered if empty)
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m") promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
ratios string (default '1:2:3')
shell string (default 'sh') shell string (default 'sh')
shellopts string (default '')
sortby string (default 'natural') sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006') timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3') truncatechar string (default '~')
info string (default '')
shellopts string (default '')
.EE .EE
.PP .PP
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -201,6 +203,7 @@ The following additional keybindings are provided by default:
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd ~ map gh cd ~
map <space> :toggle; down
.EE .EE
.PP .PP
The following keybindings to applications are provided by default: The following keybindings to applications are provided by default:
@@ -538,7 +541,7 @@ There is a 'quit' command to close client connections and quit the server:
.PP .PP
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users. Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
.SH FILE OPERATIONS .SH FILE OPERATIONS
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. This can fail to move files between different partitions when it needs to copy files. For these cases, users are expected to explicitly copy files and then delete the old ones manually. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation. lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. For cross-device moving, lf falls back to copying and then deletes the original files if there are no errors. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
.PP .PP
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file. File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
.PP .PP
@@ -652,7 +655,7 @@ There is a special command 'on-cd' that runs a shell command when it is defined
GIT_PS1_SHOWUNTRACKEDFILES=auto GIT_PS1_SHOWUNTRACKEDFILES=auto
GIT_PS1_SHOWUPSTREAM=auto GIT_PS1_SHOWUPSTREAM=auto
git=$(__git_ps1 " (%s)") || true git=$(__git_ps1 " (%s)") || true
fmt="\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f$git\e033[0m" fmt="\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w\e033[0m\e033[1m%f$git\e033[0m"
lf -remote "send $id set promptfmt \e"$fmt\e"" lf -remote "send $id set promptfmt \e"$fmt\e""
}} }}
.EE .EE
+1
View File
@@ -63,6 +63,7 @@ func exportEnvVars() {
func startServer() { func startServer() {
cmd := detachedCommand(os.Args[0], "-server") cmd := detachedCommand(os.Args[0], "-server")
cmd.Dir = gUser.HomeDir
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
log.Printf("starting server: %s", err) log.Printf("starting server: %s", err)
} }
+7
View File
@@ -13,6 +13,13 @@ import (
func isRoot(name string) bool { return filepath.Dir(name) == name } func isRoot(name string) bool { return filepath.Dir(name) == name }
func replaceTilde(s string) string {
if strings.HasPrefix(s, "~") {
s = strings.Replace(s, "~", gUser.HomeDir, 1)
}
return s
}
func runeSliceWidth(rs []rune) int { func runeSliceWidth(rs []rune) int {
w := 0 w := 0
for _, r := range rs { for _, r := range rs {
+172 -122
View File
@@ -28,6 +28,7 @@ const (
type file struct { type file struct {
os.FileInfo os.FileInfo
linkState linkState linkState linkState
linkTarget string
path string path string
dirCount int dirCount int
accessTime time.Time accessTime time.Time
@@ -56,6 +57,7 @@ func readdir(path string) ([]*file, error) {
} }
var linkState linkState var linkState linkState
var linkTarget string
if lstat.Mode()&os.ModeSymlink != 0 { if lstat.Mode()&os.ModeSymlink != 0 {
stat, err := os.Stat(fpath) stat, err := os.Stat(fpath)
@@ -65,6 +67,10 @@ func readdir(path string) ([]*file, error) {
} else { } else {
linkState = broken linkState = broken
} }
linkTarget, err = os.Readlink(fpath)
if err != nil {
return files, err
}
} }
ts := times.Get(lstat) ts := times.Get(lstat)
@@ -85,6 +91,7 @@ func readdir(path string) ([]*file, error) {
files = append(files, &file{ files = append(files, &file{
FileInfo: lstat, FileInfo: lstat,
linkState: linkState, linkState: linkState,
linkTarget: linkTarget,
path: fpath, path: fpath,
dirCount: -1, dirCount: -1,
accessTime: at, accessTime: at,
@@ -197,13 +204,13 @@ func (dir *dir) sort() {
// files to the first non-hidden file in the list // files to the first non-hidden file in the list
if gOpts.sortType.option&hiddenSort == 0 { if gOpts.sortType.option&hiddenSort == 0 {
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if isHidden(dir.files[i]) && isHidden(dir.files[j]) { if isHidden(dir.files[i], dir.path) && isHidden(dir.files[j], dir.path) {
return i < j return i < j
} }
return isHidden(dir.files[i]) return isHidden(dir.files[i], dir.path)
}) })
for i, f := range dir.files { for i, f := range dir.files {
if !isHidden(f) { if !isHidden(f, dir.path) {
dir.files = dir.files[i:] dir.files = dir.files[i:]
return return
} }
@@ -263,7 +270,8 @@ 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 renameOldPath string
renameNewPath string
selections map[string]int selections map[string]int
selectionInd int selectionInd int
height int height int
@@ -278,43 +286,46 @@ type nav struct {
func (nav *nav) loadDir(path string) *dir { func (nav *nav) loadDir(path string) *dir {
d, ok := nav.dirCache[path] d, ok := nav.dirCache[path]
if !ok { if !ok {
d := &dir{loading: true, loadTime: time.Now(), path: path, sortType: gOpts.sortType}
nav.dirCache[path] = d
go func() { go func() {
d := newDir(path) d := newDir(path)
d.sort() d.sort()
d.ind, d.pos = 0, 0 d.ind, d.pos = 0, 0
nav.dirChan <- d nav.dirChan <- d
}() }()
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
nav.dirCache[path] = d
return d return d
} }
s, err := os.Stat(d.path) nav.checkDir(d)
return d
}
func (nav *nav) checkDir(dir *dir) {
s, err := os.Stat(dir.path)
if err != nil { if err != nil {
return d log.Printf("getting directory info: %s", err)
return
} }
switch { switch {
case s.ModTime().After(d.loadTime): case s.ModTime().After(dir.loadTime):
dir.loading = true
dir.loadTime = time.Now()
go func() { go func() {
d.loadTime = time.Now() nd := newDir(dir.path)
nd := newDir(path)
nd.sort() nd.sort()
nd.sel(d.name(), nav.height)
nav.dirChan <- nd nav.dirChan <- nd
}() }()
case d.sortType != gOpts.sortType: case dir.sortType != gOpts.sortType:
dir.loading = true
go func() { go func() {
d.loading = true dir.sort()
name := d.name() dir.loading = false
d.sort() nav.dirChan <- dir
d.sel(name, nav.height)
d.loading = false
nav.dirChan <- d
}() }()
} }
return d
} }
func (nav *nav) getDirs(wd string) { func (nav *nav) getDirs(wd string) {
@@ -352,7 +363,6 @@ 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,
@@ -365,27 +375,15 @@ func newNav(height int) *nav {
func (nav *nav) renew() { func (nav *nav) renew() {
for _, d := range nav.dirs { for _, d := range nav.dirs {
go func(d *dir) { nav.checkDir(d)
s, err := os.Stat(d.path)
if err != nil {
log.Printf("getting directory info: %s", err)
return
}
if d.loadTime.After(s.ModTime()) {
return
}
d.loadTime = time.Now()
nd := newDir(d.path)
nd.sort()
nav.dirChan <- nd
}(d)
} }
for m := range nav.selections { for m := range nav.selections {
if _, err := os.Stat(m); os.IsNotExist(err) { if _, err := os.Lstat(m); os.IsNotExist(err) {
delete(nav.selections, m) delete(nav.selections, m)
} }
} }
if len(nav.selections) == 0 { if len(nav.selections) == 0 {
nav.selectionInd = 0 nav.selectionInd = 0
} }
@@ -424,6 +422,8 @@ func (nav *nav) preview() {
return return
} }
reg := &reg{loadTime: time.Now(), path: curr.path}
var reader io.Reader var reader io.Reader
if len(gOpts.previewer) != 0 { if len(gOpts.previewer) != 0 {
@@ -451,8 +451,6 @@ func (nav *nav) preview() {
reader = f reader = f
} }
reg := &reg{loadTime: time.Now(), path: curr.path}
buf := bufio.NewScanner(reader) buf := bufio.NewScanner(reader)
for i := 0; i < nav.height && buf.Scan(); i++ { for i := 0; i < nav.height && buf.Scan(); i++ {
@@ -476,25 +474,29 @@ func (nav *nav) preview() {
func (nav *nav) loadReg(path string) *reg { func (nav *nav) loadReg(path string) *reg {
r, ok := nav.regCache[path] r, ok := nav.regCache[path]
if !ok { if !ok {
go nav.preview() r := &reg{loading: true, loadTime: time.Now(), path: path}
r := &reg{loading: true, path: path}
nav.regCache[path] = r nav.regCache[path] = r
return r
}
s, err := os.Stat(r.path)
if err != nil {
return r
}
if s.ModTime().After(r.loadTime) {
r.loadTime = time.Now()
go nav.preview() go nav.preview()
return r
} }
nav.checkReg(r)
return r return r
} }
func (nav *nav) checkReg(reg *reg) {
s, err := os.Stat(reg.path)
if err != nil {
return
}
if s.ModTime().After(reg.loadTime) {
reg.loadTime = time.Now()
go nav.preview()
}
}
func (nav *nav) sort() { func (nav *nav) sort() {
for _, d := range nav.dirs { for _, d := range nav.dirs {
name := d.name() name := d.name()
@@ -615,14 +617,12 @@ func (nav *nav) toggle() {
} }
nav.toggleSelection(curr.path) nav.toggleSelection(curr.path)
nav.down(1)
} }
func (nav *nav) invert() { func (nav *nav) invert() {
last := nav.currDir() dir := nav.currDir()
for _, f := range last.files { for _, f := range dir.files {
path := filepath.Join(last.path, f.Name()) path := filepath.Join(dir.path, f.Name())
nav.toggleSelection(path) nav.toggleSelection(path)
} }
} }
@@ -694,6 +694,10 @@ loop:
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo ui.exprChan <- echo
} }
if errCount == 0 {
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mCopied successfully\033[0m"}, 1}
}
} }
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) { func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
@@ -732,15 +736,54 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
var newPath string var newPath string
for i := 1; !os.IsNotExist(err); i++ { for i := 1; !os.IsNotExist(err); i++ {
newPath = fmt.Sprintf("%s.~%d~", dst, i) newPath = fmt.Sprintf("%s.~%d~", dst, i)
_, err = os.Stat(newPath) _, err = os.Lstat(newPath)
} }
dst = newPath dst = newPath
} }
if err := os.Rename(src, dst); err != nil { if err := os.Rename(src, dst); err != nil {
errCount++ if errCrossDevice(err) {
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) total, err := copySize([]string{src})
ui.exprChan <- echo if err != nil {
echo.args[0] = err.Error()
ui.exprChan <- echo
continue
}
nav.copyTotalChan <- total
nums, errs := copyAll([]string{src}, dstDir)
oldCount := errCount
loop:
for {
select {
case n := <-nums:
nav.copyBytesChan <- n
case err, ok := <-errs:
if !ok {
break loop
}
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
nav.copyTotalChan <- -total
if errCount == oldCount {
if err := os.RemoveAll(src); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
} else {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
} }
} }
@@ -751,6 +794,10 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo ui.exprChan <- echo
} }
if errCount == 0 {
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
}
} }
func (nav *nav) paste(ui *ui) error { func (nav *nav) paste(ui *ui) error {
@@ -817,26 +864,26 @@ func (nav *nav) del(ui *ui) error {
} }
func (nav *nav) rename() error { func (nav *nav) rename() error {
oldPath := nav.renameCache[0] oldPath := nav.renameOldPath
newPath := nav.renameCache[1] newPath := nav.renameNewPath
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 { if err := os.Rename(oldPath, newPath); err != nil {
return err return err
} }
// TODO: change selection lstat, err := os.Lstat(newPath)
if err := nav.sel(newPath); err != nil { if err != nil {
return err return err
} }
dir := nav.loadDir(filepath.Dir(newPath))
if dir.loading {
dir.files = append(dir.files, &file{FileInfo: lstat})
}
dir.sel(lstat.Name(), nav.height)
return nil return nil
} }
@@ -855,7 +902,7 @@ func (nav *nav) sync() error {
} }
func (nav *nav) cd(wd string) error { func (nav *nav) cd(wd string) error {
wd = strings.Replace(wd, "~", gUser.HomeDir, -1) wd = replaceTilde(wd)
wd = filepath.Clean(wd) wd = filepath.Clean(wd)
if !filepath.IsAbs(wd) { if !filepath.IsAbs(wd) {
@@ -872,10 +919,10 @@ 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 = replaceTilde(path)
path = filepath.Clean(path) path = filepath.Clean(path)
lstat, err := os.Stat(path) lstat, err := os.Lstat(path)
if err != nil { if err != nil {
return fmt.Errorf("select: %s", err) return fmt.Errorf("select: %s", err)
} }
@@ -889,35 +936,38 @@ func (nav *nav) sel(path string) error {
base := filepath.Base(path) base := filepath.Base(path)
last := nav.dirs[len(nav.dirs)-1] last := nav.dirs[len(nav.dirs)-1]
if last.loading { if last.loading {
last.files = append(last.files, &file{FileInfo: lstat}) last.files = append(last.files, &file{FileInfo: lstat})
} else {
last.sel(base, nav.height)
} }
last.sel(base, nav.height)
return nil return nil
} }
func (nav *nav) globSel(pattern string, invert bool) error { func (nav *nav) globSel(pattern string, invert bool) error {
curDir := nav.currDir() dir := nav.currDir()
anyMatches := false anyMatched := false
for i := 0; i < len(curDir.files); i++ { for i := 0; i < len(dir.files); i++ {
match, err := filepath.Match(pattern, curDir.files[i].Name()) matched, err := filepath.Match(pattern, dir.files[i].Name())
if err != nil { if err != nil {
return fmt.Errorf("glob-select: %s", err) return fmt.Errorf("glob-select: %s", err)
} }
if match { if matched {
anyMatches = true anyMatched = true
fpath := filepath.Join(curDir.path, curDir.files[i].Name()) fpath := filepath.Join(dir.path, dir.files[i].Name())
if _, ok := nav.selections[fpath]; ok == invert { if _, ok := nav.selections[fpath]; ok == invert {
nav.toggleSelection(fpath) nav.toggleSelection(fpath)
} }
} }
} }
if !anyMatches {
if !anyMatched {
return fmt.Errorf("glob-select: pattern not found: %s", pattern) return fmt.Errorf("glob-select: pattern not found: %s", pattern)
} }
return nil return nil
} }
@@ -945,9 +995,9 @@ func findMatch(name, pattern string) bool {
func (nav *nav) findSingle() int { func (nav *nav) findSingle() int {
count := 0 count := 0
index := 0 index := 0
last := nav.currDir() dir := nav.currDir()
for i := 0; i < len(last.files); i++ { for i := 0; i < len(dir.files); i++ {
if findMatch(last.files[i].Name(), nav.find) { if findMatch(dir.files[i].Name(), nav.find) {
count++ count++
if count > 1 { if count > 1 {
return count return count
@@ -956,27 +1006,27 @@ func (nav *nav) findSingle() int {
} }
} }
if count == 1 { if count == 1 {
if index > last.ind { if index > dir.ind {
nav.down(index - last.ind) nav.down(index - dir.ind)
} else { } else {
nav.up(last.ind - index) nav.up(dir.ind - index)
} }
} }
return count return count
} }
func (nav *nav) findNext() bool { func (nav *nav) findNext() bool {
last := nav.currDir() dir := nav.currDir()
for i := last.ind + 1; i < len(last.files); i++ { for i := dir.ind + 1; i < len(dir.files); i++ {
if findMatch(last.files[i].Name(), nav.find) { if findMatch(dir.files[i].Name(), nav.find) {
nav.down(i - last.ind) nav.down(i - dir.ind)
return true return true
} }
} }
if gOpts.wrapscan { if gOpts.wrapscan {
for i := 0; i < last.ind; i++ { for i := 0; i < dir.ind; i++ {
if findMatch(last.files[i].Name(), nav.find) { if findMatch(dir.files[i].Name(), nav.find) {
nav.up(last.ind - i) nav.up(dir.ind - i)
return true return true
} }
} }
@@ -985,17 +1035,17 @@ func (nav *nav) findNext() bool {
} }
func (nav *nav) findPrev() bool { func (nav *nav) findPrev() bool {
last := nav.currDir() dir := nav.currDir()
for i := last.ind - 1; i >= 0; i-- { for i := dir.ind - 1; i >= 0; i-- {
if findMatch(last.files[i].Name(), nav.find) { if findMatch(dir.files[i].Name(), nav.find) {
nav.up(last.ind - i) nav.up(dir.ind - i)
return true return true
} }
} }
if gOpts.wrapscan { if gOpts.wrapscan {
for i := len(last.files) - 1; i > last.ind; i-- { for i := len(dir.files) - 1; i > dir.ind; i-- {
if findMatch(last.files[i].Name(), nav.find) { if findMatch(dir.files[i].Name(), nav.find) {
nav.down(i - last.ind) nav.down(i - dir.ind)
return true return true
} }
} }
@@ -1025,25 +1075,25 @@ func searchMatch(name, pattern string) (matched bool, err error) {
} }
func (nav *nav) searchNext() error { func (nav *nav) searchNext() error {
last := nav.currDir() dir := nav.currDir()
for i := last.ind + 1; i < len(last.files); i++ { for i := dir.ind + 1; i < len(dir.files); i++ {
matched, err := searchMatch(last.files[i].Name(), nav.search) matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil { if err != nil {
return err return err
} }
if matched { if matched {
nav.down(i - last.ind) nav.down(i - dir.ind)
return nil return nil
} }
} }
if gOpts.wrapscan { if gOpts.wrapscan {
for i := 0; i < last.ind; i++ { for i := 0; i < dir.ind; i++ {
matched, err := searchMatch(last.files[i].Name(), nav.search) matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil { if err != nil {
return err return err
} }
if matched { if matched {
nav.up(last.ind - i) nav.up(dir.ind - i)
return nil return nil
} }
} }
@@ -1052,25 +1102,25 @@ func (nav *nav) searchNext() error {
} }
func (nav *nav) searchPrev() error { func (nav *nav) searchPrev() error {
last := nav.currDir() dir := nav.currDir()
for i := last.ind - 1; i >= 0; i-- { for i := dir.ind - 1; i >= 0; i-- {
matched, err := searchMatch(last.files[i].Name(), nav.search) matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil { if err != nil {
return err return err
} }
if matched { if matched {
nav.up(last.ind - i) nav.up(dir.ind - i)
return nil return nil
} }
} }
if gOpts.wrapscan { if gOpts.wrapscan {
for i := len(last.files) - 1; i > last.ind; i-- { for i := len(dir.files) - 1; i > dir.ind; i-- {
matched, err := searchMatch(last.files[i].Name(), nav.search) matched, err := searchMatch(dir.files[i].Name(), nav.search)
if err != nil { if err != nil {
return err return err
} }
if matched { if matched {
nav.down(i - last.ind) nav.down(i - dir.ind)
return nil return nil
} }
} }
@@ -1144,12 +1194,12 @@ func (nav *nav) currDir() *dir {
} }
func (nav *nav) currFile() (*file, error) { func (nav *nav) currFile() (*file, error) {
last := nav.dirs[len(nav.dirs)-1] dir := nav.dirs[len(nav.dirs)-1]
if len(last.files) == 0 { if len(dir.files) == 0 {
return nil, fmt.Errorf("empty directory") return nil, fmt.Errorf("empty directory")
} }
return last.files[last.ind], nil return dir.files[dir.ind], nil
} }
type indexedSelections struct { type indexedSelections struct {
+22 -18
View File
@@ -35,15 +35,15 @@ var gOpts struct {
globsearch bool globsearch bool
icons bool icons bool
ignorecase bool ignorecase bool
incsearch bool
preview bool
smartcase bool
ignoredia bool ignoredia bool
incsearch bool
number bool
preview bool
relativenumber bool
smartcase bool
smartdia bool smartdia bool
wrapscan bool wrapscan bool
wrapscroll bool wrapscroll bool
number bool
relativenumber bool
findlen int findlen int
period int period int
scrolloff int scrolloff int
@@ -55,7 +55,9 @@ var gOpts struct {
promptfmt string promptfmt string
shell string shell string
timefmt string timefmt string
truncatechar string
ratios []int ratios []int
hiddenfiles []string
info []string info []string
shellopts []string shellopts []string
keys map[string]expr keys map[string]expr
@@ -72,15 +74,15 @@ func init() {
gOpts.globsearch = false gOpts.globsearch = false
gOpts.icons = false gOpts.icons = false
gOpts.ignorecase = true gOpts.ignorecase = true
gOpts.incsearch = false
gOpts.preview = true
gOpts.smartcase = true
gOpts.ignoredia = false gOpts.ignoredia = false
gOpts.incsearch = false
gOpts.number = false
gOpts.preview = true
gOpts.relativenumber = false
gOpts.smartcase = true
gOpts.smartdia = false gOpts.smartdia = false
gOpts.wrapscan = true gOpts.wrapscan = true
gOpts.wrapscroll = false gOpts.wrapscroll = false
gOpts.number = false
gOpts.relativenumber = false
gOpts.findlen = 1 gOpts.findlen = 1
gOpts.period = 0 gOpts.period = 0
gOpts.scrolloff = 0 gOpts.scrolloff = 0
@@ -89,10 +91,12 @@ func init() {
gOpts.filesep = "\n" gOpts.filesep = "\n"
gOpts.ifs = "" gOpts.ifs = ""
gOpts.previewer = "" gOpts.previewer = ""
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m" gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f\033[0m"
gOpts.shell = gDefaultShell gOpts.shell = gDefaultShell
gOpts.timefmt = time.ANSIC gOpts.timefmt = time.ANSIC
gOpts.truncatechar = "~"
gOpts.ratios = []int{1, 2, 3} gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = []string{".*"}
gOpts.info = nil gOpts.info = nil
gOpts.shellopts = nil gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort} gOpts.sortType = sortType{naturalSort, dirfirstSort}
@@ -118,7 +122,7 @@ func init() {
gOpts.keys["<home>"] = &callExpr{"top", nil, 1} gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
gOpts.keys["G"] = &callExpr{"bottom", nil, 1} gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1} gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1} gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
gOpts.keys["v"] = &callExpr{"invert", nil, 1} gOpts.keys["v"] = &callExpr{"invert", nil, 1}
gOpts.keys["u"] = &callExpr{"unselect", nil, 1} gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
gOpts.keys["y"] = &callExpr{"copy", nil, 1} gOpts.keys["y"] = &callExpr{"copy", nil, 1}
@@ -153,12 +157,12 @@ func init() {
gOpts.keys["zs"] = &setExpr{"info", "size"} gOpts.keys["zs"] = &setExpr{"info", "size"}
gOpts.keys["zt"] = &setExpr{"info", "time"} gOpts.keys["zt"] = &setExpr{"info", "time"}
gOpts.keys["za"] = &setExpr{"info", "size:time"} gOpts.keys["za"] = &setExpr{"info", "size:time"}
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}} gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}, 1}
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}} gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}} gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1}
gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}} gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1}
gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}} gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1}
gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}} gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1}
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1} gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
gOpts.cmdkeys = make(map[string]expr) gOpts.cmdkeys = make(map[string]expr)
+31 -6
View File
@@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"syscall"
) )
var ( var (
@@ -125,16 +126,40 @@ func setDefaults() {
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1} gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
} }
func moveCursor(y, x int) {
fmt.Printf("\033[%d;%dH", y, x)
}
func isExecutable(f os.FileInfo) bool { func isExecutable(f os.FileInfo) bool {
return f.Mode()&0111 != 0 return f.Mode()&0111 != 0
} }
func isHidden(f os.FileInfo) bool { func isHidden(f os.FileInfo, path string) bool {
return f.Name()[0] == '.' hidden := false
for _, pattern := range gOpts.hiddenfiles {
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
if strings.HasPrefix(pattern, "!") && matched {
hidden = false
} else if matched {
hidden = true
}
}
return hidden
}
func matchPattern(pattern, name, path string) bool {
s := name
pattern = replaceTilde(pattern)
if filepath.IsAbs(pattern) {
s = filepath.Join(path, name)
}
// pattern errors are checked when 'hiddenfiles' option is set
matched, _ := filepath.Match(pattern, s)
return matched
}
func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
} }
func exportFiles(f string, fs []string) { func exportFiles(f string, fs []string) {
+14 -8
View File
@@ -98,11 +98,6 @@ func setDefaults() {
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1} gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
} }
func moveCursor(y, x int) {
// TODO: implement
return
}
func isExecutable(f os.FileInfo) bool { func isExecutable(f os.FileInfo) bool {
exts := strings.Split(envPathExt, string(filepath.ListSeparator)) exts := strings.Split(envPathExt, string(filepath.ListSeparator))
for _, e := range exts { for _, e := range exts {
@@ -114,9 +109,20 @@ func isExecutable(f os.FileInfo) bool {
return false return false
} }
func isHidden(f os.FileInfo) bool { func isHidden(f os.FileInfo, path string) bool {
// TODO: implement ptr, err := syscall.UTF16PtrFromString(filepath.Join(path, f.Name()))
return false if err != nil {
return false
}
attrs, err := syscall.GetFileAttributes(ptr)
if err != nil {
return false
}
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
}
func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == 17
} }
func exportFiles(f string, fs []string) { func exportFiles(f string, fs []string) {
+2 -1
View File
@@ -114,6 +114,7 @@ func (e *execExpr) String() string {
type listExpr struct { type listExpr struct {
exprs []expr exprs []expr
count int
} }
func (e *listExpr) String() string { func (e *listExpr) String() string {
@@ -265,7 +266,7 @@ func (p *parser) parseExpr() expr {
s.scan() s.scan()
result = &listExpr{exprs} result = &listExpr{exprs, 1}
case tokenPrefix: case tokenPrefix:
var expr string var expr string
+1 -4
View File
@@ -177,9 +177,6 @@ scan:
s.tok = string(s.buf[beg:s.off]) s.tok = string(s.buf[beg:s.off])
s.cmd = false s.cmd = false
s.sem = true s.sem = true
case s.chr == '\r':
s.next()
goto scan
case s.chr == '\n': case s.chr == '\n':
if s.sem { if s.sem {
s.typ = tokenSemicolon s.typ = tokenSemicolon
@@ -196,7 +193,7 @@ scan:
} }
goto scan goto scan
case isSpace(s.chr): case isSpace(s.chr):
for !s.eof && isSpace(s.chr) { for !s.eof && isSpace(s.chr) && s.chr != '\n' {
s.next() s.next()
} }
goto scan goto scan
+48 -26
View File
@@ -153,7 +153,11 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Att
i += w - 1 i += w - 1
if r == '\t' { if r == '\t' {
x += gOpts.tabstop - (x-off)%gOpts.tabstop s := gOpts.tabstop - (x-off)%gOpts.tabstop
for i := 0; i < s && x+i < win.w; i++ {
termbox.SetCell(win.x+x+i, win.y+y, ' ', fg, bg)
}
x += s
} else { } else {
x += runewidth.RuneWidth(r) x += runewidth.RuneWidth(r)
} }
@@ -275,6 +279,9 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
if gOpts.number || gOpts.relativenumber { if gOpts.number || gOpts.relativenumber {
lnwidth = 1 lnwidth = 1
if gOpts.number && gOpts.relativenumber {
lnwidth++
}
for j := 10; j < len(dir.files); j *= 10 { for j := 10; j < len(dir.files); j *= 10 {
lnwidth++ lnwidth++
} }
@@ -287,13 +294,18 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
if lnwidth > 0 { if lnwidth > 0 {
var ln string var ln string
if gOpts.number && (!gOpts.relativenumber || i == dir.pos) { if gOpts.number && (!gOpts.relativenumber) {
ln = fmt.Sprintf(lnformat, i+1+beg) ln = fmt.Sprintf(lnformat, i+1+beg)
} else if gOpts.relativenumber { } else if gOpts.relativenumber {
if i < dir.pos { switch {
case i < dir.pos:
ln = fmt.Sprintf(lnformat, dir.pos-i) ln = fmt.Sprintf(lnformat, dir.pos-i)
} else { case i > dir.pos:
ln = fmt.Sprintf(lnformat, i-dir.pos) ln = fmt.Sprintf(lnformat, i-dir.pos)
case gOpts.number:
ln = fmt.Sprintf(fmt.Sprintf("%%%d.d ", lnwidth-1), i+1+beg)
default:
ln = ""
} }
} }
@@ -333,7 +345,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
if w > win.w-3 { if w > win.w-3 {
s = runeSliceWidthRange(s, 0, win.w-4) s = runeSliceWidthRange(s, 0, win.w-4)
s = append(s, '~') s = append(s, []rune(gOpts.truncatechar)...)
} else { } else {
for i := 0; i < win.w-3-w; i++ { for i := 0; i < win.w-3-w; i++ {
s = append(s, ' ') s = append(s, ' ')
@@ -344,10 +356,10 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
if len(info) > 0 && win.w-2 > 2*len(info) { if len(info) > 0 && win.w-2 > 2*len(info) {
if win.w-2 > w+len(info) { if win.w-2 > w+len(info) {
s = runeSliceWidthRange(s, 0, win.w-3-len(info)) s = runeSliceWidthRange(s, 0, win.w-3-len(info)-lnwidth)
} else { } else {
s = runeSliceWidthRange(s, 0, win.w-4-len(info)) s = runeSliceWidthRange(s, 0, win.w-4-len(info)-lnwidth)
s = append(s, '~') s = append(s, []rune(gOpts.truncatechar)...)
} }
for _, r := range info { for _, r := range info {
s = append(s, r) s = append(s, r)
@@ -551,18 +563,27 @@ func (ui *ui) loadFileInfo(nav *nav) {
return return
} }
ui.echof("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt)) var linkTarget string
if curr.linkTarget != "" {
linkTarget = " -> " + curr.linkTarget
}
ui.echof("%v %4s %v%s", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt), linkTarget)
} }
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault fg, bg := termbox.ColorDefault, termbox.ColorDefault
pwd := nav.currDir().path pwd := nav.currDir().path
nohome := strings.TrimPrefix(pwd, gUser.HomeDir)
if len(nohome) < len(pwd) { if strings.HasPrefix(pwd, gUser.HomeDir) {
pwd = "~/" + nohome pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
}
sep := string(filepath.Separator)
if !strings.HasSuffix(pwd, sep) {
pwd += sep
} }
pwd = filepath.Clean(pwd)
var fname string var fname string
curr, err := nav.currFile() curr, err := nav.currFile()
@@ -577,9 +598,11 @@ func (ui *ui) drawPromptLine(nav *nav) {
prompt = strings.Replace(prompt, "%f", fname, -1) prompt = strings.Replace(prompt, "%f", fname, -1)
if printLength(strings.Replace(prompt, "%w", pwd, -1)) > ui.promptWin.w { if printLength(strings.Replace(prompt, "%w", pwd, -1)) > ui.promptWin.w {
sep := string(filepath.Separator)
names := strings.Split(pwd, sep) names := strings.Split(pwd, sep)
for i := range names { for i := range names {
if names[i] == "" {
continue
}
r, _ := utf8.DecodeRuneInString(names[i]) r, _ := utf8.DecodeRuneInString(names[i])
names[i] = string(r) names[i] = string(r)
if printLength(strings.Replace(prompt, "%w", strings.Join(names, sep), -1)) <= ui.promptWin.w { if printLength(strings.Replace(prompt, "%w", strings.Join(names, sep), -1)) <= ui.promptWin.w {
@@ -597,12 +620,12 @@ func (ui *ui) drawPromptLine(nav *nav) {
func (ui *ui) drawStatLine(nav *nav) { func (ui *ui) drawStatLine(nav *nav) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault fg, bg := termbox.ColorDefault, termbox.ColorDefault
currDir := nav.currDir() dir := nav.currDir()
ui.msgWin.print(0, 0, fg, bg, ui.msg) ui.msgWin.print(0, 0, fg, bg, ui.msg)
tot := len(currDir.files) tot := len(dir.files)
ind := min(currDir.ind+1, tot) ind := min(dir.ind+1, tot)
acc := string(ui.keyCount) + string(ui.keyAcc) acc := string(ui.keyCount) + string(ui.keyAcc)
var progress string var progress string
@@ -694,13 +717,13 @@ func (ui *ui) draw(nav *nav) {
} }
if gOpts.preview { if gOpts.preview {
f, err := nav.currFile() curr, err := nav.currFile()
if err == nil { if err == nil {
preview := ui.wins[len(ui.wins)-1] preview := ui.wins[len(ui.wins)-1]
if f.IsDir() { if curr.IsDir() {
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons) preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons)
} else if f.Mode().IsRegular() { } else if curr.Mode().IsRegular() {
preview.printReg(ui.regPrev) preview.printReg(ui.regPrev)
} }
} }
@@ -730,11 +753,6 @@ func (ui *ui) draw(nav *nav) {
} }
termbox.Flush() termbox.Flush()
if ui.cmdPrefix == "" {
// leave the cursor at the beginning of the current file for screen readers
moveCursor(ui.wins[woff+length-1].y+nav.dirs[doff+length-1].pos+1, ui.wins[woff+length-1].x+1)
}
} }
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) { func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
@@ -796,7 +814,7 @@ func (ui *ui) pollEvent() termbox.Event {
case key := <-ui.keyChan: case key := <-ui.keyChan:
ev := termbox.Event{Type: termbox.EventKey} ev := termbox.Event{Type: termbox.EventKey}
if len(key) == 1 { if utf8.RuneCountInString(key) == 1 {
ev.Ch, _ = utf8.DecodeRuneInString(key) ev.Ch, _ = utf8.DecodeRuneInString(key)
} else { } else {
switch { switch {
@@ -852,6 +870,8 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
ch <- draw ch <- draw
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
ui.menuBuf = nil
return
} }
ui.keyAcc = append(ui.keyAcc, []rune(val)...) ui.keyAcc = append(ui.keyAcc, []rune(val)...)
} }
@@ -882,6 +902,8 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
expr := gOpts.keys[string(ui.keyAcc)] expr := gOpts.keys[string(ui.keyAcc)]
if e, ok := expr.(*callExpr); ok { if e, ok := expr.(*callExpr); ok {
e.count = count e.count = count
} else if e, ok := expr.(*listExpr); ok {
e.count = count
} }
ch <- expr ch <- expr
ui.keyAcc = nil ui.keyAcc = nil