Compare commits

30 Commits
r9 ... r11
Author SHA1 Message Date
Gokcehan 1956a759c4 cleanup 2019-03-04 00:05:29 +03:00
Gokcehan 9656553974 cleanup 2019-03-03 22:29:34 +03:00
Gokcehan 31945fbcb5 update doc 2019-03-03 22:12:33 +03:00
Gokcehan 4a8943b6b7 cleanup 2019-03-02 16:49:02 +03:00
Gokcehan 885e896b4a check existing move operation before quit 2019-03-01 17:45:47 +03:00
Gokcehan 808404978e show move progress in the ruler 2019-03-01 17:44:50 +03:00
Gokcehan 99734c7dcf increase copy buffer size 2019-03-01 04:01:33 +03:00
Gokcehan f44ec4f5bd use reverse attribute for preview messages 2019-03-01 03:51:14 +03:00
Gokcehan 4d2a628550 log copy and move errors 2019-02-28 22:04:57 +03:00
Gokcehan 193285a65d add 'echomsg' and 'echoerr' commands for logging 2019-02-28 21:58:14 +03:00
Gokcehan 6ec2924b6b show copy progress in the ruler 2019-02-28 21:04:38 +03:00
Gokcehan 599ac11f26 cleanup 2019-02-26 21:27:04 +03:00
Gokcehan 728c5fbb2c check if src and dst are the same file before move 2019-02-26 21:25:34 +03:00
Gokcehan 0f47c5428b load directories after copy/move 2019-02-26 21:04:51 +03:00
Gokcehan 4865ce9b00 implement builtin move operation
Related #61 and #113
2019-02-26 20:32:30 +03:00
Gokcehan d6e9aece51 implement builtin copy operation
Related #61 and #113
2019-02-26 20:12:13 +03:00
Gokcehan fd1af47233 initialize termbox before logging
Related #138
2019-02-18 14:18:02 +03:00
Gokcehan 184762d83a remove background colors from defaults 2019-02-10 20:45:34 +03:00
Gokcehan 27f104b3e6 select first argument on startup
Related #101
2019-02-10 19:48:49 +03:00
Gokcehan 35930924a7 disable normal commands in cmap
Related #68
2019-02-10 19:28:14 +03:00
Gokcehan 4a1388a5c7 read configuration after initialization 2019-02-09 00:55:11 +03:00
Gokcehan 92e994ebf6 Revert "only echo when the output pauses in shell-pipe"
This reverts commit dd6a85f480.
2019-02-09 00:48:23 +03:00
Gokcehan 245db502cc execute multiple commands with command flag
Related #135
2019-02-08 19:54:04 +03:00
Gokcehan ca95bcf1d8 add shell prefixes to history 2019-02-08 19:19:28 +03:00
Gokcehan dd6a85f480 only echo when the output pauses in shell-pipe 2019-02-08 19:06:37 +03:00
Gokcehan db8f535b61 cleanup 2019-02-07 00:36:15 +03:00
Gokcehan 52be0b3aab handle shell-pipe prompts properly
Related #137
2019-02-07 00:34:42 +03:00
Gokcehan bd889a9e06 make 'delete' command prompting
Related #113
2019-02-06 15:56:41 +03:00
Gokcehan 951529ebc0 make read commands work when typed manually 2019-02-06 15:07:31 +03:00
Daniel Lewan 0fc14e3b2d add option to execute command on server initialization (#135) 2019-02-06 14:56:06 +03:00
17 changed files with 649 additions and 350 deletions

No files matched your search

+70 -5
View File
@@ -48,7 +48,7 @@ func (app *app) readFile(path string) {
f, err := os.Open(path) f, err := os.Open(path)
if err != nil { if err != nil {
app.ui.printf("opening file: %s", err) app.ui.echoerrf("opening file: %s", err)
return return
} }
defer f.Close() defer f.Close()
@@ -60,7 +60,7 @@ func (app *app) readFile(path string) {
} }
if p.err != nil { if p.err != nil {
app.ui.printf("%s", p.err) app.ui.echoerrf("%s", p.err)
} }
} }
@@ -136,9 +136,43 @@ func (app *app) loop() {
clientChan := app.ui.readExpr() clientChan := app.ui.readExpr()
serverChan := readExpr() serverChan := readExpr()
if gSelect != "" {
go func() {
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
}()
}
for _, path := range gConfigPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
app.readFile(path)
}
}
if gCommand != "" {
p := newParser(strings.NewReader(gCommand))
for p.parse() {
p.expr.eval(app, nil)
}
if p.err != nil {
app.ui.echoerrf("%s", p.err)
}
}
for { for {
select { select {
case <-app.quitChan: case <-app.quitChan:
if app.nav.copyTotal > 0 {
app.ui.echoerr("quit: copy operation in progress")
continue
}
if app.nav.moveTotal > 0 {
app.ui.echoerr("quit: move operation in progress")
continue
}
log.Print("bye!") log.Print("bye!")
if err := app.nav.writeMarks(); err != nil { if err := app.nav.writeMarks(); err != nil {
@@ -165,6 +199,37 @@ func (app *app) loop() {
} }
return return
case n := <-app.nav.copyBytesChan:
app.nav.copyBytes += n
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
app.nav.copyUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.copyTotalChan:
app.nav.copyTotal += n
if n < 0 {
app.nav.copyBytes += n
}
if app.nav.copyTotal == 0 {
app.nav.copyUpdate = 0
}
app.ui.draw(app.nav)
case n := <-app.nav.moveCountChan:
app.nav.moveCount += n
if app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {
app.nav.moveUpdate = 0
app.ui.draw(app.nav)
}
case n := <-app.nav.moveTotalChan:
app.nav.moveTotal += n
if n < 0 {
app.nav.moveCount += n
}
if app.nav.moveTotal == 0 {
app.nav.moveUpdate = 0
}
app.ui.draw(app.nav)
case d := <-app.nav.dirChan: case d := <-app.nav.dirChan:
prev, ok := app.nav.dirCache[d.path] prev, ok := app.nav.dirCache[d.path]
if ok { if ok {
@@ -313,13 +378,13 @@ func (app *app) runShell(s string, args []string, prefix string) {
} }
if err != nil { if err != nil {
app.ui.printf("running shell: %s", err) app.ui.echoerrf("running shell: %s", err)
} }
switch prefix { switch prefix {
case "!": case "!":
if err := waitKey(); err != nil { if err := waitKey(); err != nil {
app.ui.printf("waiting key: %s", err) app.ui.echoerrf("waiting key: %s", err)
} }
} }
@@ -328,12 +393,12 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix { switch prefix {
case "%": case "%":
go func() {
app.cmd = cmd app.cmd = cmd
app.cmdOutBuf = nil app.cmdOutBuf = nil
app.ui.msg = "" app.ui.msg = ""
app.ui.cmdPrefix = ">" app.ui.cmdPrefix = ">"
go func() {
reader := bufio.NewReader(out) reader := bufio.NewReader(out)
for { for {
b, err := reader.ReadByte() b, err := reader.ReadByte()
+10 -16
View File
@@ -14,6 +14,13 @@ import (
) )
func run() { func run() {
if err := termbox.Init(); err != nil {
log.Fatalf("initializing termbox: %s", err)
}
defer termbox.Close()
setColorMode()
f, err := os.Create(gLogPath) f, err := os.Create(gLogPath)
if err != nil { if err != nil {
panic(err) panic(err)
@@ -24,27 +31,14 @@ func run() {
log.Print("hi!") log.Print("hi!")
if err := termbox.Init(); err != nil {
log.Fatalf("initializing termbox: %s", err)
}
defer termbox.Close()
setColorMode()
app := newApp() app := newApp()
for _, path := range gConfigPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
app.readFile(path)
}
}
if err := app.nav.readMarks(); err != nil { if err := app.nav.readMarks(); err != nil {
app.ui.printf("reading marks file: %s", err) app.ui.echoerrf("reading marks file: %s", err)
} }
if err := app.readHistory(); err != nil { if err := app.readHistory(); err != nil {
app.ui.printf("reading history file: %s", err) app.ui.echoerrf("reading history file: %s", err)
} }
app.loop() app.loop()
@@ -146,7 +140,7 @@ func loadFiles() (list []string, cp bool, err error) {
return return
} }
func sendRemote(cmd string) error { func remote(cmd string) error {
c, err := net.Dial(gSocketProt, gSocketPath) c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil { if err != nil {
return fmt.Errorf("dialing to send server: %s", err) return fmt.Errorf("dialing to send server: %s", err)
+11 -11
View File
@@ -51,25 +51,25 @@ func parseColors() colorMap {
return parseColorsBSD(env) return parseColorsBSD(env)
} }
// default values from dircolors // default values from dircolors with removed background colors
defaultColors := []string{ defaultColors := []string{
// "rs=0", // "rs=0",
"di=01;34", "di=01;34",
"ln=01;36", "ln=01;36",
// "mh=00", // "mh=00",
"pi=40;33", "pi=33", // "pi=40;33",
"so=01;35", "so=01;35",
"do=01;35", "do=01;35",
"bd=40;33;01", "bd=33;01", // "bd=40;33;01",
"cd=40;33;01", "cd=33;01", // "cd=40;33;01",
"or=40;31;01", "or=31;01", // "or=40;31;01",
// "mi=00", // "mi=00",
"su=37;41", "su=01;32", // "su=37;41",
"sg=30;43", "sg=01;32", // "sg=30;43",
"ca=30;41", // "ca=30;41",
"tw=30;42", "tw=01;34", // "tw=30;42",
"ow=34;42", "ow=01;34", // "ow=34;42",
"st=37;44", "st=01;34", // "st=37;44",
"ex=01;32", "ex=01;32",
} }
+2
View File
@@ -54,6 +54,8 @@ var (
"mark-load", "mark-load",
"sync", "sync",
"echo", "echo",
"echomsg",
"echoerr",
"cd", "cd",
"select", "select",
"source", "source",
+128
View File
@@ -0,0 +1,128 @@
package main
import (
"fmt"
"io"
"os"
"path/filepath"
)
func copySize(srcs []string) (int64, error) {
var total int64
for _, src := range srcs {
_, err := os.Stat(src)
if os.IsNotExist(err) {
return total, fmt.Errorf("src does not exist: %q", src)
}
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("walk: %s", err)
}
total += info.Size()
return nil
})
if err != nil {
return total, err
}
}
return total, nil
}
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
buf := make([]byte, 4096)
r, err := os.Open(src)
if err != nil {
return err
}
defer r.Close()
w, err := os.Create(dst)
if err != nil {
return err
}
for {
n, err := r.Read(buf)
if err != nil && err != io.EOF {
w.Close()
os.Remove(dst)
return err
}
if n == 0 {
break
}
if _, err := w.Write(buf[:n]); err != nil {
return err
}
nums <- int64(n)
}
if err := w.Close(); err != nil {
os.Remove(dst)
return err
}
if err := os.Chmod(dst, info.Mode()); err != nil {
os.Remove(dst)
return err
}
return nil
}
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
nums = make(chan int64, 1024)
errs = make(chan error, 1024)
go func() {
for _, src := range srcs {
dst := filepath.Join(dstDir, filepath.Base(src))
_, err := os.Stat(dst)
if !os.IsNotExist(err) {
var newPath string
for i := 1; !os.IsNotExist(err); i++ {
newPath = fmt.Sprintf("%s.~%d~", dst, i)
_, err = os.Stat(newPath)
}
dst = newPath
}
filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
errs <- fmt.Errorf("walk: %s", err)
return nil
}
rel, err := filepath.Rel(src, path)
if err != nil {
errs <- fmt.Errorf("relative: %s", err)
return nil
}
newPath := filepath.Join(dst, rel)
if info.IsDir() {
if err := os.MkdirAll(newPath, info.Mode()); err != nil {
errs <- fmt.Errorf("mkdir: %s", err)
}
nums <- info.Size()
} else {
if err := copyFile(path, newPath, info, nums); err != nil {
errs <- fmt.Errorf("copy: %s", err)
}
}
return nil
})
}
close(errs)
}()
return nums, errs
}
+1 -1
View File
@@ -33,7 +33,7 @@ func appendTransliterate(base, norm string, uppercase bool) {
lenNorm := len(normRunes) lenNorm := len(normRunes)
lenBase := len(baseRunes) lenBase := len(baseRunes)
if lenNorm != lenBase { if lenNorm != lenBase {
panic("Base and normalized strings have differend lenght: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant lenght 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, baseRune := range baseRunes {
+39 -28
View File
@@ -56,13 +56,15 @@ The following commands are provided by lf without default keybindings:
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronizes copied/cut files with server sync synchronize copied/cut files with server
echo prints its arguments to the message line echo print arguments to the message line
cd changes working directory to its argument echomsg same as echo but logging
select changes current file selection to its argument echoerr same as echomsg but red color
source reads the configuration file in its argument cd change working directory to the argument
push simulates key pushes given in its argument select change current file selection to the argument
delete deletes the current file or selected file(s) source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
The following command line commands are provided by lf with default The following command line commands are provided by lf with default
keybindings: keybindings:
@@ -517,33 +519,48 @@ should not be needed for users.
File Operations File Operations
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For lf uses its own builtin copy and move operations by default. These are
this purpose, when you 'copy' a file, it doesn't actually copy the file on the implemented as asynchronous operations and progress is shown in the bottom
disk, but only records its name to memory. The actual file operation takes ruler. These commands do not overwrite existing files or directories with the
place when you 'paste' in which case the 'cp' command is used. Similarly the same name. Instead, a suffix that is compatible with '--backup=numbered' option
'mv' command is used for 'cut' followed by 'paste'. 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.
You can customize these operations by defining a 'paste' command. This is a File operations can be performed on the current selected file or alternatively
special command that is called when it is defined instead of the builtin on multiple files by marking them first. When you 'copy' a file, lf doesn't
implementation. The default behavior is similar to the following command: 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.
You can customize copy and move operations by defining a 'paste' command. This
is a special command that is called when it is defined instead of the builtin
implementation. You can use the following example as a starting point:
cmd paste %{{ cmd paste %{{
load=$(lf -remote 'load') load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
cp -R -n $list . cp -R $list .
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv -n $list . mv $list .
fi fi
lf -remote 'send load' lf -remote 'send load'
lf -remote 'send clear' lf -remote 'send clear'
}} }}
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' Some useful things to be considered are to use the backup ('--backup') and/or
commands if they support it (i.e. GNU implementation), change the command type preserve attributes ('-a') options with 'cp' and 'mv' commands if they support
to asynchronous, or use 'rsync' command with progress bar option for copying it (i.e. GNU implementation), change the command type to asynchronous, or use
and feed the progress to the client periodically with remote 'echo' calls. 'rsync' command with progress bar option for copying and feed the progress to
the client periodically with remote 'echo' calls.
By default, lf does not assign 'delete' command to a key to protect new users. By default, lf does not assign 'delete' command to a key to protect new users.
You can customize file deletion by defining a 'delete' command. You can also You can customize file deletion by defining a 'delete' command. You can also
@@ -565,13 +582,7 @@ 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. Alternatively, you can also map some other 'cmd-escape' to cancel the search.
commands with 'cmap' to accept the search and execute the command immediately
afterwards. For example, you can use arrow keys to finish the search with the
following mappings:
cmap <up> up
cmap <down> down
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
+45 -33
View File
@@ -59,13 +59,15 @@ The following commands are provided by lf without default keybindings:
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronizes copied/cut files with server sync synchronize copied/cut files with server
echo prints its arguments to the message line echo print arguments to the message line
cd changes working directory to its argument echomsg same as echo but logging
select changes current file selection to its argument echoerr same as echomsg but red color
source reads the configuration file in its argument cd change working directory to the argument
push simulates key pushes given in its argument select change current file selection to the argument
delete deletes the current file or selected file(s) source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
The following command line commands are provided by lf with default The following command line commands are provided by lf with default
keybindings: keybindings:
@@ -119,15 +121,15 @@ The following options can be used to customize the behavior of lf:
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
filesep string (default "\n") filesep string (default "\n")
ifs string (default '') (not exported if empty) ifs string (default ”) (not exported if empty)
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")
shell string (default 'sh') shell string (default 'sh')
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') ratios string (default '1:2:3')
info string (default '') info string (default ”)
shellopts string (default '') shellopts string (default ”)
The following variables are exported for shell commands: The following variables are exported for shell commands:
@@ -539,34 +541,50 @@ should not be needed for users.
File Operations File Operations
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For lf uses its own builtin copy and move operations by default. These are
this purpose, when you 'copy' a file, it doesn't actually copy the file on implemented as asynchronous operations and progress is shown in the bottom
the disk, but only records its name to memory. The actual file operation ruler. These commands do not overwrite existing files or directories with
takes place when you 'paste' in which case the 'cp' command is used. the same name. Instead, a suffix that is compatible with '--backup=numbered'
Similarly the 'mv' command is used for 'cut' followed by 'paste'. 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.
You can customize these operations by defining a 'paste' command. This is a File operations can be performed on the current selected file or
special command that is called when it is defined instead of the builtin alternatively on multiple files by marking them first. When you 'copy' a
implementation. The default behavior is similar to the following command: 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.
You can customize copy and move operations by defining a 'paste' command.
This is a special command that is called when it is defined instead of the
builtin implementation. You can use the following example as a starting
point:
cmd paste %{{ cmd paste %{{
load=$(lf -remote 'load') load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
cp -R -n $list . cp -R $list .
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv -n $list . mv $list .
fi fi
lf -remote 'send load' lf -remote 'send load'
lf -remote 'send clear' lf -remote 'send clear'
}} }}
Some useful things are to use the backup option ('--backup') with 'cp' and Some useful things to be considered are to use the backup ('--backup')
'mv' commands if they support it (i.e. GNU implementation), change the and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if
command type to asynchronous, or use 'rsync' command with progress bar they support it (i.e. GNU implementation), change the command type to
option for copying and feed the progress to the client periodically with asynchronous, or use 'rsync' command with progress bar option for copying
remote 'echo' calls. and feed the progress to the client periodically with remote 'echo' calls.
By default, lf does not assign 'delete' command to a key to protect new By default, lf does not assign 'delete' command to a key to protect new
users. You can customize file deletion by defining a 'delete' command. You users. You can customize file deletion by defining a 'delete' command. You
@@ -589,13 +607,7 @@ 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. Alternatively, you can also search or use 'cmd-escape' to cancel the search.
map some other commands with 'cmap' to accept the search and execute the
command immediately afterwards. For example, you can use arrow keys to
finish the search with the following mappings:
cmap <up> up
cmap <down> down
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
+9 -4
View File
@@ -1,7 +1,12 @@
# Autocompletion for Fish shell # Autocompletion for fish shell.
# Put this file somewhere in $fish_complete_path #
# for example in ~/.config/fish/completions/ # You may put this file to a directory in $fish_complete_path variable:
#
# mkdir -p ~/.config/fish/completions
# ln -s "/path/to/lf.fish" ~/.config/fish/completions
#
complete -c lf -o command -r -d 'command to execute on client initialization'
complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile' complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'
complete -c lf -o doc -d 'show documentation' complete -c lf -o doc -d 'show documentation'
complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)' complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'
@@ -10,4 +15,4 @@ complete -c lf -o remote -x -d 'send remote command to server'
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)' complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
complete -c lf -o server -d 'start server (automatic)' complete -c lf -o server -d 'start server (automatic)'
complete -c lf -o version -d 'show version' complete -c lf -o version -d 'show version'
complete -c lf -s h -d "short help" complete -c lf -o help -d 'show help'
+96 -88
View File
@@ -158,22 +158,22 @@ func (e *setExpr) eval(app *app, args []string) {
case "findlen": case "findlen":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
app.ui.printf("findlen: %s", err) app.ui.echoerrf("findlen: %s", err)
return return
} }
if n < 0 { if n < 0 {
app.ui.print("findlen: value should be a non-negative number") app.ui.echoerr("findlen: value should be a non-negative number")
return return
} }
gOpts.findlen = n gOpts.findlen = n
case "period": case "period":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
app.ui.printf("period: %s", err) app.ui.echoerrf("period: %s", err)
return return
} }
if n < 0 { if n < 0 {
app.ui.print("period: value should be a non-negative number") app.ui.echoerr("period: value should be a non-negative number")
return return
} }
gOpts.period = n gOpts.period = n
@@ -186,22 +186,22 @@ func (e *setExpr) eval(app *app, args []string) {
case "scrolloff": case "scrolloff":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
app.ui.printf("scrolloff: %s", err) app.ui.echoerrf("scrolloff: %s", err)
return return
} }
if n < 0 { if n < 0 {
app.ui.print("scrolloff: value should be a non-negative number") app.ui.echoerr("scrolloff: value should be a non-negative number")
return return
} }
gOpts.scrolloff = n gOpts.scrolloff = n
case "tabstop": case "tabstop":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
app.ui.printf("tabstop: %s", err) app.ui.echoerrf("tabstop: %s", err)
return return
} }
if n <= 0 { if n <= 0 {
app.ui.print("tabstop: value should be a positive number") app.ui.echoerr("tabstop: value should be a positive number")
return return
} }
gOpts.tabstop = n gOpts.tabstop = n
@@ -217,7 +217,7 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.shell = e.val gOpts.shell = e.val
case "sortby": case "sortby":
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" { if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
app.ui.print("sortby: value should either be 'natural', 'name', 'size' or 'time'") app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size' or 'time'")
return return
} }
switch e.val { switch e.val {
@@ -240,17 +240,17 @@ func (e *setExpr) eval(app *app, args []string) {
for _, s := range toks { for _, s := range toks {
n, err := strconv.Atoi(s) n, err := strconv.Atoi(s)
if err != nil { if err != nil {
app.ui.printf("ratios: %s", err) app.ui.echoerrf("ratios: %s", err)
return return
} }
if n <= 0 { if n <= 0 {
app.ui.print("ratios: value should be a positive number") app.ui.echoerr("ratios: value should be a positive number")
return return
} }
rats = append(rats, n) rats = append(rats, n)
} }
if gOpts.preview && len(rats) < 2 { if gOpts.preview && len(rats) < 2 {
app.ui.print("ratios: should consist of at least two numbers when 'preview' is enabled") app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
return return
} }
gOpts.ratios = rats gOpts.ratios = rats
@@ -260,7 +260,7 @@ func (e *setExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
if s != "" && s != "size" && s != "time" { if s != "" && s != "size" && s != "time" {
app.ui.print("info: should consist of 'size' or 'time' separated with colon") app.ui.echoerr("info: should consist of 'size' or 'time' separated with colon")
return return
} }
} }
@@ -268,7 +268,7 @@ func (e *setExpr) eval(app *app, args []string) {
case "shellopts": case "shellopts":
gOpts.shellopts = strings.Split(e.val, ":") gOpts.shellopts = strings.Split(e.val, ":")
default: default:
app.ui.printf("unknown option: %s", e.opt) app.ui.echoerrf("unknown option: %s", e.opt)
} }
} }
@@ -326,12 +326,12 @@ func update(app *app) {
if app.nav.searchBack { if app.nav.searchBack {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.printf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return return
} }
} else { } else {
if err := app.nav.searchNext(); err != nil { if err := app.nav.searchNext(); err != nil {
app.ui.printf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return return
} }
} }
@@ -347,12 +347,12 @@ func update(app *app) {
if app.nav.searchBack { if app.nav.searchBack {
if err := app.nav.searchNext(); err != nil { if err := app.nav.searchNext(); err != nil {
app.ui.printf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return return
} }
} else { } else {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.printf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return return
} }
} }
@@ -373,7 +373,7 @@ func insert(app *app, arg string) {
if gOpts.findlen == 0 { if gOpts.findlen == 0 {
switch app.nav.findSingle() { switch app.nav.findSingle() {
case 0: case 0:
app.ui.printf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
case 1: case 1:
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -388,7 +388,7 @@ func insert(app *app, arg string) {
} }
if !app.nav.findNext() { if !app.nav.findNext() {
app.ui.printf("find: pattern not found: %s", app.nav.find) app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -405,7 +405,7 @@ func insert(app *app, arg string) {
if gOpts.findlen == 0 { if gOpts.findlen == 0 {
switch app.nav.findSingle() { switch app.nav.findSingle() {
case 0: case 0:
app.ui.printf("find-back: pattern not found: %s", app.nav.find) app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
case 1: case 1:
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -420,7 +420,7 @@ func insert(app *app, arg string) {
} }
if !app.nav.findPrev() { if !app.nav.findPrev() {
app.ui.printf("find-back: pattern not found: %s", app.nav.find) app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
} else { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -431,6 +431,22 @@ func insert(app *app, arg string) {
app.ui.cmdAccLeft = nil app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil app.ui.cmdAccRight = nil
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
case app.ui.cmdPrefix == "delete?[y/N]: ":
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
if arg == "y" {
if err := app.nav.del(); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
app.nav.unselect()
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
}
}
case app.ui.cmdPrefix == "mark-save: ": case app.ui.cmdPrefix == "mark-save: ":
app.ui.menuBuf = nil app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil app.ui.cmdAccLeft = nil
@@ -456,11 +472,11 @@ func insert(app *app, arg string) {
path, ok := app.nav.marks[arg] path, ok := app.nav.marks[arg]
if !ok { if !ok {
app.ui.print("mark-load: no such mark") app.ui.echoerr("mark-load: no such mark")
return return
} }
if err := app.nav.cd(path); err != nil { if err := app.nav.cd(path); err != nil {
app.ui.printf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
@@ -475,12 +491,6 @@ func insert(app *app, arg string) {
} }
func (e *callExpr) eval(app *app, args []string) { func (e *callExpr) eval(app *app, args []string) {
if app.ui.cmdPrefix != "" && e.name != "redraw" && !strings.HasPrefix(e.name, "cmd-") {
app.ui.menuBuf = nil
app.ui.cmdAccLeft = nil
app.ui.cmdAccRight = nil
app.ui.cmdPrefix = ""
}
switch e.name { switch e.name {
case "up": case "up":
app.nav.up(e.count) app.nav.up(e.count)
@@ -509,7 +519,7 @@ func (e *callExpr) eval(app *app, args []string) {
case "updir": case "updir":
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.printf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
} }
@@ -518,14 +528,14 @@ func (e *callExpr) eval(app *app, args []string) {
case "open": case "open":
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
if err != nil { if err != nil {
app.ui.printf("opening: %s", err) app.ui.echoerrf("opening: %s", err)
return return
} }
if curr.IsDir() { if curr.IsDir() {
err := app.nav.open() err := app.nav.open()
if err != nil { if err != nil {
app.ui.printf("opening directory: %s", err) app.ui.echoerrf("opening directory: %s", err)
return return
} }
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
@@ -542,11 +552,8 @@ func (e *callExpr) eval(app *app, args []string) {
defer out.Close() defer out.Close()
var path string var path string
if len(app.nav.selections) != 0 { if list, err := app.nav.currFileOrSelections(); err == nil {
selections := app.nav.currSelections() path = strings.Join(list, "\n")
path = strings.Join(selections, "\n")
} else if curr, err := app.nav.currFile(); err == nil {
path = curr.path
} else { } else {
return return
} }
@@ -586,53 +593,50 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.unselect() app.nav.unselect()
case "copy": case "copy":
if err := app.nav.save(true); err != nil { if err := app.nav.save(true); err != nil {
app.ui.printf("copy: %s", err) app.ui.echoerrf("copy: %s", err)
return return
} }
app.nav.unselect() app.nav.unselect()
if err := sendRemote("send sync"); err != nil { if err := remote("send sync"); err != nil {
app.ui.printf("copy: %s", err) app.ui.echoerrf("copy: %s", err)
} }
case "cut": case "cut":
if err := app.nav.save(false); err != nil { if err := app.nav.save(false); err != nil {
app.ui.printf("cut: %s", err) app.ui.echoerrf("cut: %s", err)
return return
} }
app.nav.unselect() app.nav.unselect()
if err := sendRemote("send sync"); err != nil { if err := remote("send sync"); err != nil {
app.ui.printf("cut: %s", err) app.ui.echoerrf("cut: %s", err)
} }
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)
} else if err := app.nav.paste(); err != nil { } else if err := app.nav.paste(app.ui); err != nil {
app.ui.printf("paste: %s", err) app.ui.echoerrf("paste: %s", err)
return return
} }
if err := sendRemote("send load"); err != nil {
app.ui.printf("paste: %s", err)
}
if err := sendRemote("send sync"); err != nil {
app.ui.printf("paste: %s", err)
}
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)
} else if err := app.nav.deleteFiles(); err != nil { app.nav.unselect()
app.ui.printf("delete: %s", err) if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
}
} else {
if _, err := app.nav.currFileOrSelections(); err != nil {
app.ui.echoerrf("delete: %s", err)
return return
} }
app.nav.unselect() app.ui.cmdPrefix = "delete?[y/N]: "
if err := sendRemote("send load"); err != nil {
app.ui.printf("delete: %s", err)
} }
case "clear": case "clear":
if err := saveFiles(nil, false); err != nil { if err := saveFiles(nil, false); err != nil {
app.ui.printf("clear: %s", err) app.ui.echoerrf("clear: %s", err)
return return
} }
if err := sendRemote("send sync"); err != nil { if err := remote("send sync"); err != nil {
app.ui.printf("clear: %s", err) app.ui.echoerrf("clear: %s", err)
} }
case "draw": case "draw":
case "redraw": case "redraw":
@@ -643,7 +647,7 @@ func (e *callExpr) eval(app *app, args []string) {
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.printf("reload: %s", err) app.ui.echoerrf("reload: %s", err)
} }
case "read": case "read":
app.ui.cmdPrefix = ":" app.ui.cmdPrefix = ":"
@@ -697,12 +701,12 @@ func (e *callExpr) eval(app *app, args []string) {
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if app.nav.searchBack { if app.nav.searchBack {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.printf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return return
} }
} else { } else {
if err := app.nav.searchNext(); err != nil { if err := app.nav.searchNext(); err != nil {
app.ui.printf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return return
} }
} }
@@ -713,12 +717,12 @@ func (e *callExpr) eval(app *app, args []string) {
for i := 0; i < e.count; i++ { for i := 0; i < e.count; i++ {
if app.nav.searchBack { if app.nav.searchBack {
if err := app.nav.searchNext(); err != nil { if err := app.nav.searchNext(); err != nil {
app.ui.printf("search-back: %s: %s", err, app.nav.search) app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
return return
} }
} else { } else {
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.printf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
return return
} }
} }
@@ -732,10 +736,14 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.cmdPrefix = "mark-load: " app.ui.cmdPrefix = "mark-load: "
case "sync": case "sync":
if err := app.nav.sync(); err != nil { if err := app.nav.sync(); err != nil {
app.ui.printf("sync: %s", err) app.ui.echoerrf("sync: %s", err)
} }
case "echo": case "echo":
app.ui.msg = strings.Join(e.args, " ") app.ui.echo(strings.Join(e.args, " "))
case "echomsg":
app.ui.echomsg(strings.Join(e.args, " "))
case "echoerr":
app.ui.echoerr(strings.Join(e.args, " "))
case "cd": case "cd":
path := "~" path := "~"
if len(e.args) > 0 { if len(e.args) > 0 {
@@ -748,7 +756,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if err := app.nav.cd(path); err != nil { if err := app.nav.cd(path); err != nil {
app.ui.printf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
@@ -766,7 +774,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
case "select": case "select":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.print("select: requires an argument") app.ui.echoerr("select: requires an argument")
return return
} }
@@ -776,7 +784,7 @@ func (e *callExpr) eval(app *app, args []string) {
} }
if err := app.nav.sel(e.args[0]); err != nil { if err := app.nav.sel(e.args[0]); err != nil {
app.ui.printf("%s", err) app.ui.echoerrf("%s", err)
return return
} }
@@ -795,13 +803,13 @@ func (e *callExpr) eval(app *app, args []string) {
} }
case "source": case "source":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.print("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))
case "push": case "push":
if len(e.args) != 1 { if len(e.args) != 1 {
app.ui.print("push: requires an argument") app.ui.echoerr("push: requires an argument")
return return
} }
log.Println("pushing keys", e.args[0]) log.Println("pushing keys", e.args[0])
@@ -853,37 +861,37 @@ func (e *callExpr) eval(app *app, args []string) {
switch app.ui.cmdPrefix { switch app.ui.cmdPrefix {
case ":": case ":":
log.Printf("command: %s", s) log.Printf("command: %s", s)
app.ui.cmdPrefix = ""
app.cmdHistory = append(app.cmdHistory, cmdItem{":", s})
p := newParser(strings.NewReader(s)) p := newParser(strings.NewReader(s))
for p.parse() { for p.parse() {
p.expr.eval(app, nil) p.expr.eval(app, nil)
} }
if p.err != nil { if p.err != nil {
app.ui.printf("%s", p.err) app.ui.echoerrf("%s", p.err)
} }
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
app.ui.cmdPrefix = ""
case "$": case "$":
log.Printf("shell: %s", s) log.Printf("shell: %s", s)
app.runShell(s, nil, app.ui.cmdPrefix)
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
app.cmdHistory = append(app.cmdHistory, cmdItem{"$", s})
app.runShell(s, nil, "$")
case "%": case "%":
log.Printf("shell-pipe: %s", s) log.Printf("shell-pipe: %s", s)
app.runShell(s, nil, app.ui.cmdPrefix) app.cmdHistory = append(app.cmdHistory, cmdItem{"%", s})
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s}) app.runShell(s, nil, "%")
case ">": case ">":
io.WriteString(app.cmdIn, s+"\n") io.WriteString(app.cmdIn, s+"\n")
app.cmdOutBuf = nil app.cmdOutBuf = nil
case "!": case "!":
log.Printf("shell-wait: %s", s) log.Printf("shell-wait: %s", s)
app.runShell(s, nil, app.ui.cmdPrefix)
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
app.cmdHistory = append(app.cmdHistory, cmdItem{"!", s})
app.runShell(s, nil, "!")
case "&": case "&":
log.Printf("shell-async: %s", s) log.Printf("shell-async: %s", s)
app.runShell(s, nil, app.ui.cmdPrefix)
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
app.ui.cmdPrefix = "" app.ui.cmdPrefix = ""
app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s})
app.runShell(s, nil, "&")
case "/": case "/":
if gOpts.incsearch { if gOpts.incsearch {
last := app.nav.currDir() last := app.nav.currDir()
@@ -891,14 +899,14 @@ func (e *callExpr) eval(app *app, args []string) {
last.pos = app.nav.searchPos last.pos = app.nav.searchPos
} }
log.Printf("search: %s", s) log.Printf("search: %s", s)
app.ui.cmdPrefix = ""
app.nav.search = s app.nav.search = s
if err := app.nav.searchNext(); err != nil { if err := app.nav.searchNext(); err != nil {
app.ui.printf("search: %s: %s", err, app.nav.search) app.ui.echoerrf("search: %s: %s", err, app.nav.search)
} else { } else {
app.ui.loadFile(app.nav) app.ui.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
app.ui.cmdPrefix = ""
case "?": case "?":
if gOpts.incsearch { if gOpts.incsearch {
last := app.nav.currDir() last := app.nav.currDir()
@@ -906,14 +914,14 @@ func (e *callExpr) eval(app *app, args []string) {
last.pos = app.nav.searchPos last.pos = app.nav.searchPos
} }
log.Printf("search-back: %s", s) log.Printf("search-back: %s", s)
app.ui.cmdPrefix = ""
app.nav.search = s app.nav.search = s
if err := app.nav.searchPrev(); err != nil { if err := app.nav.searchPrev(); err != nil {
app.ui.printf("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.loadFile(app.nav)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
} }
app.ui.cmdPrefix = ""
default: default:
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix) log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
} }
@@ -1133,7 +1141,7 @@ func (e *callExpr) eval(app *app, args []string) {
default: default:
cmd, ok := gOpts.cmds[e.name] cmd, ok := gOpts.cmds[e.name]
if !ok { if !ok {
app.ui.printf("command not found: %s", e.name) app.ui.echoerrf("command not found: %s", e.name)
return return
} }
cmd.eval(app, e.args) cmd.eval(app, e.args)
+21 -22
View File
@@ -68,13 +68,15 @@ The following commands are provided by lf without default keybindings:
.EX .EX
draw draw the ui draw draw the ui
load load modified files and directories load load modified files and directories
sync synchronizes copied/cut files with server sync synchronize copied/cut files with server
echo prints its arguments to the message line echo print arguments to the message line
cd changes working directory to its argument echomsg same as echo but logging
select changes current file selection to its argument echoerr same as echomsg but red color
source reads the configuration file in its argument cd change working directory to the argument
push simulates key pushes given in its argument select change current file selection to the argument
delete deletes the current file or selected file(s) source read the configuration file in the argument
push simulate key pushes given in the argument
delete remove the current file or selected file(s)
.EE .EE
.PP .PP
The following command line commands are provided by lf with default keybindings: The following command line commands are provided by lf with default keybindings:
@@ -131,15 +133,15 @@ The following options can be used to customize the behavior of lf:
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
filesep string (default "\en") filesep string (default "\en")
ifs string (default '') (not exported if empty) ifs string (default ”) (not exported if empty)
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")
shell string (default 'sh') shell string (default 'sh')
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') ratios string (default '1:2:3')
info string (default '') info string (default ”)
shellopts 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:
@@ -528,9 +530,11 @@ 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 the underlying 'cp' and 'mv' shell commands for file operations. For this purpose, when you 'copy' a file, it doesn't actually copy the file on the disk, but only records its name to memory. The actual file operation takes place when you 'paste' in which case the 'cp' command is used. Similarly the 'mv' command is used for 'cut' followed by 'paste'. 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.
.PP .PP
You can customize these operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. The default behavior is similar to the following command: File operations can be performed on the current selected file or alternatively on multiple files by marking 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
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
.PP .PP
.EX .EX
cmd paste %{{ cmd paste %{{
@@ -538,27 +542,22 @@ You can customize these operations by defining a 'paste' command. This is a spec
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
cp -R -n $list . cp -R $list .
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv -n $list . mv $list .
fi fi
lf -remote 'send load' lf -remote 'send load'
lf -remote 'send clear' lf -remote 'send clear'
}} }}
.EE .EE
.PP .PP
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls. Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
.PP .PP
By default, lf does not assign 'delete' command to a key to protect new users. You can customize file deletion by defining a 'delete' command. You can also assign a key to this command if you like. An example command to move selected files to a trash folder and remove files completely after a prompt are provided in the example configuration file. By default, lf does not assign 'delete' command to a key to protect new users. You can customize file deletion by defining a 'delete' command. You can also assign a key to this command if you like. An example command to move selected files to a trash folder and remove files completely after a prompt are provided in the example configuration file.
.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. Alternatively, you can also map some other commands with 'cmap' to accept the search and execute the command immediately afterwards. For example, you can use arrow keys to finish the search with the following mappings: 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.
.PP
.EX
cmap <up> up
cmap <down> down
.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
+10 -7
View File
@@ -25,6 +25,8 @@ var (
gSocketPath string gSocketPath string
gLogPath string gLogPath string
gServerLogPath string gServerLogPath string
gSelect string
gCommand string
gVersion string gVersion string
) )
@@ -103,6 +105,11 @@ func main() {
"", "",
"path to the file to write selected files on open (to use as open file dialog)") "path to the file to write selected files on open (to use as open file dialog)")
flag.StringVar(&gCommand,
"command",
"",
"command to execute on client initialization")
flag.Parse() flag.Parse()
gSocketProt = gDefaultSocketProt gSocketProt = gDefaultSocketProt
@@ -125,7 +132,7 @@ func main() {
case *showVersion: case *showVersion:
fmt.Println(gVersion) fmt.Println(gVersion)
case *remoteCmd != "": case *remoteCmd != "":
if err := sendRemote(*remoteCmd); err != nil { if err := remote(*remoteCmd); err != nil {
log.Fatalf("remote command: %s", err) log.Fatalf("remote command: %s", err)
} }
case *serverMode: case *serverMode:
@@ -149,13 +156,9 @@ func main() {
os.Exit(2) os.Exit(2)
} }
case 1: case 1:
dir := flag.Arg(0) gSelect = flag.Arg(0)
if err := os.Chdir(dir); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(2)
}
default: default:
fmt.Fprintf(os.Stderr, "only single directory is allowed\n") fmt.Fprintf(os.Stderr, "only single file or directory is allowed\n")
os.Exit(2) os.Exit(2)
} }
+4 -5
View File
@@ -133,11 +133,10 @@ func splitWord(s string) (word, rest string) {
return return
} }
// This function converts a size in bytes to a human readable form. For this // This function converts a size in bytes to a human readable form using metric
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10 // suffixes (e.g. 1K = 1000). For values less than 10 the first significant
// the first significant digit is shown, otherwise it is hidden. Numbers are // digit is shown, otherwise it is hidden. Numbers are always rounded down.
// always rounded down. For these reasons this function always show somewhat // This should be fine for most human beings.
// smaller values but it should be fine for most human beings.
func humanize(size int64) string { func humanize(size int64) string {
if size < 1000 { if size < 1000 {
return fmt.Sprintf("%dB", size) return fmt.Sprintf("%dB", size)
+162 -57
View File
@@ -189,6 +189,16 @@ func (dir *dir) sel(name string, height int) {
type nav struct { type nav struct {
dirs []*dir dirs []*dir
copyBytes int64
copyTotal int64
copyUpdate int
moveCount int
moveTotal int
moveUpdate int
copyBytesChan chan int64
copyTotalChan chan int64
moveCountChan chan int
moveTotalChan chan int
dirChan chan *dir dirChan chan *dir
regChan chan *reg regChan chan *reg
dirCache map[string]*dir dirCache map[string]*dir
@@ -271,6 +281,10 @@ func newNav(height int) *nav {
} }
nav := &nav{ nav := &nav{
copyBytesChan: make(chan int64, 1024),
copyTotalChan: make(chan int64, 1024),
moveCountChan: make(chan int, 1024),
moveTotalChan: make(chan int, 1024),
dirChan: make(chan *dir), dirChan: make(chan *dir),
regChan: make(chan *reg), regChan: make(chan *reg),
dirCache: make(map[string]*dir), dirCache: make(map[string]*dir),
@@ -382,7 +396,7 @@ func (nav *nav) preview() {
for i := 0; i < nav.height && buf.Scan(); i++ { for i := 0; i < nav.height && buf.Scan(); i++ {
for _, r := range buf.Text() { for _, r := range buf.Text() {
if r == 0 { if r == 0 {
reg.lines = []string{"\033[1mbinary\033[0m"} reg.lines = []string{"\033[7mbinary\033[0m"}
nav.regChan <- reg nav.regChan <- reg
return return
} }
@@ -550,80 +564,158 @@ func (nav *nav) unselect() {
nav.selectionInd = 0 nav.selectionInd = 0
} }
// effectiveSelection is a pure function that returns the selected files's paths.
// In case the user has not selected a file it returns the file on the user's cursor.
// If the function can't return a selection it returns an error.
func (nav *nav) effectiveSelection() (list []string, err error) {
if len(nav.selections) == 0 {
curr, err := nav.currFile()
if err != nil {
return nil, errors.New("no file selected")
}
return []string{curr.path}, nil
}
return nav.currSelections(), nil
}
func (nav *nav) save(cp bool) error { func (nav *nav) save(cp bool) error {
if len(nav.selections) == 0 { list, err := nav.currFileOrSelections()
curr, err := nav.currFile()
if err != nil { if err != nil {
return errors.New("no file selected") return err
} }
if err := saveFiles([]string{curr.path}, cp); err != nil { if err := saveFiles(list, cp); err != nil {
return err return err
} }
nav.saves = make(map[string]bool) nav.saves = make(map[string]bool)
nav.saves[curr.path] = cp for _, f := range list {
} else {
selections := nav.currSelections()
if err := saveFiles(selections, cp); err != nil {
return err
}
nav.saves = make(map[string]bool)
for f := range nav.selections {
nav.saves[f] = cp nav.saves[f] = cp
} }
}
return nil return nil
} }
func (nav *nav) paste() error { func (nav *nav) copyAsync(ui *ui, srcs []string, dstDir string) {
list, cp, err := loadFiles() echo := &callExpr{"echoerr", []string{""}, 1}
_, err := os.Stat(dstDir)
if os.IsNotExist(err) {
echo.args[0] = err.Error()
ui.exprChan <- echo
return
}
total, err := copySize(srcs)
if err != nil {
echo.args[0] = err.Error()
ui.exprChan <- echo
return
}
nav.copyTotalChan <- total
nums, errs := copyAll(srcs, dstDir)
errCount := 0
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 err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
echo := &callExpr{"echoerr", []string{""}, 1}
_, err := os.Stat(dstDir)
if os.IsNotExist(err) {
echo.args[0] = err.Error()
ui.exprChan <- echo
return
}
nav.moveTotalChan <- len(srcs)
errCount := 0
for _, src := range srcs {
nav.moveCountChan <- 1
srcStat, err := os.Stat(src)
if err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
continue
}
dst := filepath.Join(dstDir, filepath.Base(src))
dstStat, err := os.Stat(dst)
if os.SameFile(srcStat, dstStat) {
errCount++
echo.args[0] = fmt.Sprintf("[%d] rename %s %s: source and destination are the same file", errCount, src, dst)
ui.exprChan <- echo
continue
} else if !os.IsNotExist(err) {
var newPath string
for i := 1; !os.IsNotExist(err); i++ {
newPath = fmt.Sprintf("%s.~%d~", dst, i)
_, err = os.Stat(newPath)
}
dst = newPath
}
if err := os.Rename(src, dst); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
nav.moveTotalChan <- -len(srcs)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
func (nav *nav) paste(ui *ui) error {
srcs, cp, err := loadFiles()
if err != nil { if err != nil {
return err return err
} }
if len(list) == 0 { if len(srcs) == 0 {
return errors.New("no file in copy/cut buffer") return errors.New("no file in copy/cut buffer")
} }
dir := nav.currDir() dstDir := nav.currDir().path
cmd := pasteCommand(list, dir, cp) if cp {
go nav.copyAsync(ui, srcs, dstDir)
if err := cmd.Run(); err != nil { } else {
return fmt.Errorf("pasting files: %s", err) go nav.moveAsync(ui, srcs, dstDir)
} }
if err := saveFiles(nil, false); err != nil { if err := saveFiles(nil, false); err != nil {
return fmt.Errorf("clearing copy/cut buffer: %s", err) return fmt.Errorf("clearing copy/cut buffer: %s", err)
} }
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
}
return nil return nil
} }
// deleteFiles deletes the user's selected files func (nav *nav) del() error {
// it returns an error if no files are selected or if the OS fails to delete a file list, err := nav.currFileOrSelections()
func (nav *nav) deleteFiles() error {
list, err := nav.effectiveSelection()
if err != nil { if err != nil {
return err return err
@@ -850,19 +942,6 @@ func (nav *nav) searchPrev() error {
return nil return nil
} }
func (nav *nav) currDir() *dir {
return nav.dirs[len(nav.dirs)-1]
}
func (nav *nav) currFile() (*file, error) {
last := nav.dirs[len(nav.dirs)-1]
if len(last.files) == 0 {
return nil, fmt.Errorf("empty directory")
}
return last.files[last.ind], nil
}
func (nav *nav) readMarks() error { func (nav *nav) readMarks() error {
f, err := os.Open(gMarksPath) f, err := os.Open(gMarksPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
@@ -923,6 +1002,19 @@ func (nav *nav) writeMarks() error {
return nil return nil
} }
func (nav *nav) currDir() *dir {
return nav.dirs[len(nav.dirs)-1]
}
func (nav *nav) currFile() (*file, error) {
last := nav.dirs[len(nav.dirs)-1]
if len(last.files) == 0 {
return nil, fmt.Errorf("empty directory")
}
return last.files[last.ind], nil
}
type indexedSelections struct { type indexedSelections struct {
paths []string paths []string
indices []int indices []int
@@ -947,3 +1039,16 @@ func (nav *nav) currSelections() []string {
sort.Sort(indexedSelections{paths: paths, indices: indices}) sort.Sort(indexedSelections{paths: paths, indices: indices})
return paths return paths
} }
func (nav *nav) currFileOrSelections() (list []string, err error) {
if len(nav.selections) == 0 {
curr, err := nav.currFile()
if err != nil {
return nil, errors.New("no file selected")
}
return []string{curr.path}, nil
}
return nav.currSelections(), nil
}
-25
View File
@@ -114,31 +114,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
return exec.Command(gOpts.shell, args...) return exec.Command(gOpts.shell, args...)
} }
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
var sh string
var args []string
if cp {
sh = "cp"
args = append(args, "-R")
} else {
sh = "mv"
}
// XXX: POSIX standard states that -i flag shall do nothing when the
// response is not affirmative. Since this command is run with a nil
// stdin, it should not give an affirmative answer and in return this
// command should not overwrite existing files. Our intention here is
// to use the standard -i flag in place of non-standard -n flag to
// avoid overwrites.
args = append(args, "-i")
args = append(args, list...)
args = append(args, dir.path)
return exec.Command(sh, args...)
}
func setDefaults() { func setDefaults() {
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`} gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`} gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
-27
View File
@@ -89,33 +89,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
return exec.Command(gOpts.shell, args...) return exec.Command(gOpts.shell, args...)
} }
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
var args []string
sh := "robocopy"
if !cp {
args = []string{"/move"}
}
for _, f := range list {
stat, err := os.Stat(f)
if err != nil {
log.Printf("getting file information: %s", err)
continue
}
base := filepath.Base(f)
dest := filepath.Dir(f)
if stat.IsDir() {
exec.Command(sh, append(args, f, filepath.Join(dir.path, base))...).Run()
} else {
exec.Command(sh, append(args, dest, dir.path, base)...).Run()
}
}
// TODO: return 0 on success
return exec.Command(sh, args...)
}
func setDefaults() { func setDefaults() {
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"} gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"} gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
+41 -21
View File
@@ -182,7 +182,7 @@ func (win *win) printReg(reg *reg) {
fg, bg := termbox.ColorDefault, termbox.ColorDefault fg, bg := termbox.ColorDefault, termbox.ColorDefault
if reg.loading { if reg.loading {
fg = termbox.AttrBold fg = termbox.AttrReverse
win.print(2, 0, fg, bg, "loading...") win.print(2, 0, fg, bg, "loading...")
return return
} }
@@ -246,17 +246,13 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
return return
} }
fg, bg := termbox.ColorDefault, termbox.ColorDefault
if dir.loading { if dir.loading {
fg = termbox.AttrBold win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "loading...")
win.print(2, 0, fg, bg, "loading...")
return return
} }
if len(dir.files) == 0 { if len(dir.files) == 0 {
fg = termbox.AttrBold win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
win.print(2, 0, fg, bg, "empty")
return return
} }
@@ -267,8 +263,8 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
return return
} }
var lnwidth int = 0 var lnwidth int
var lnformat string = "" var lnformat string
if gOpts.number || gOpts.relativenumber { if gOpts.number || gOpts.relativenumber {
lnwidth = 1 lnwidth = 1
@@ -279,7 +275,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
} }
for i, f := range dir.files[beg:end] { for i, f := range dir.files[beg:end] {
fg, bg = colors.get(f) fg, bg := colors.get(f)
if lnwidth > 0 { if lnwidth > 0 {
var ln string var ln string
@@ -485,13 +481,30 @@ func (ui *ui) sort() {
ui.dirPrev.sel(name, ui.wins[0].h) ui.dirPrev.sel(name, ui.wins[0].h)
} }
func (ui *ui) print(msg string) { func (ui *ui) echo(msg string) {
ui.msg = msg
}
func (ui *ui) echof(format string, a ...interface{}) {
ui.echo(fmt.Sprintf(format, a...))
}
func (ui *ui) echomsg(msg string) {
ui.msg = msg ui.msg = msg
log.Print(msg) log.Print(msg)
} }
func (ui *ui) printf(format string, a ...interface{}) { func (ui *ui) echomsgf(format string, a ...interface{}) {
ui.print(fmt.Sprintf(format, a...)) ui.echomsg(fmt.Sprintf(format, a...))
}
func (ui *ui) echoerr(msg string) {
ui.msg = fmt.Sprintf("\033[7;31;47m%s\033[0m", msg)
log.Printf("error: %s", msg)
}
func (ui *ui) echoerrf(format string, a ...interface{}) {
ui.echoerr(fmt.Sprintf(format, a...))
} }
type reg struct { type reg struct {
@@ -524,7 +537,7 @@ func (ui *ui) loadFileInfo(nav *nav) {
return return
} }
ui.msg = fmt.Sprintf("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt)) ui.echof("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
} }
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
@@ -576,7 +589,18 @@ func (ui *ui) drawStatLine(nav *nav) {
ind := min(currDir.ind+1, tot) ind := min(currDir.ind+1, tot)
acc := string(ui.keyCount) + string(ui.keyAcc) acc := string(ui.keyCount) + string(ui.keyAcc)
ruler := fmt.Sprintf("%s %d/%d", acc, ind, tot) var progress string
if nav.copyTotal > 0 {
percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal))
progress += fmt.Sprintf(" [%d%%]", percentage)
}
if nav.moveTotal > 0 {
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
}
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
ui.msgWin.printRight(0, fg, bg, ruler) ui.msgWin.printRight(0, fg, bg, ruler)
} }
@@ -769,7 +793,7 @@ func (ui *ui) pollEvent() termbox.Event {
ev.Key = val ev.Key = val
} else { } else {
ev.Key = termbox.KeyEsc ev.Key = termbox.KeyEsc
ui.printf("unknown key: %s", key) ui.echoerrf("unknown key: %s", key)
} }
} }
} }
@@ -821,7 +845,7 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
switch len(binds) { switch len(binds) {
case 0: case 0:
ui.printf("unknown mapping: %s", string(ui.keyAcc)) ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
ch <- draw ch <- draw
ui.keyAcc = nil ui.keyAcc = nil
ui.keyCount = nil ui.keyCount = nil
@@ -834,8 +858,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
log.Printf("converting command count: %s", err) log.Printf("converting command count: %s", err)
} }
count = c count = c
} else {
count = 1
} }
expr := gOpts.keys[string(ui.keyAcc)] expr := gOpts.keys[string(ui.keyAcc)]
if e, ok := expr.(*callExpr); ok { if e, ok := expr.(*callExpr); ok {
@@ -857,8 +879,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
log.Printf("converting command count: %s", err) log.Printf("converting command count: %s", err)
} }
count = c count = c
} else {
count = 1
} }
expr := gOpts.keys[string(ui.keyAcc)] expr := gOpts.keys[string(ui.keyAcc)]
if e, ok := expr.(*callExpr); ok { if e, ok := expr.(*callExpr); ok {