Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13fe1931cd | ||
|
|
2c87b0dcfe | ||
|
|
b2b22fb674 | ||
|
|
45270e389e | ||
|
|
fee016f406 | ||
|
|
29de45e466 | ||
|
|
791b704257 | ||
|
|
e3bc11408f | ||
|
|
6f35abb4ca | ||
|
|
0eedb71d6c | ||
|
|
1eedd29546 | ||
|
|
866a7e6a2b | ||
|
|
1956a759c4 | ||
|
|
9656553974 | ||
|
|
31945fbcb5 | ||
|
|
4a8943b6b7 | ||
|
|
885e896b4a | ||
|
|
808404978e | ||
|
|
99734c7dcf | ||
|
|
f44ec4f5bd | ||
|
|
4d2a628550 | ||
|
|
193285a65d | ||
|
|
6ec2924b6b | ||
|
|
599ac11f26 | ||
|
|
728c5fbb2c | ||
|
|
0f47c5428b | ||
|
|
4865ce9b00 | ||
|
|
d6e9aece51 | ||
|
|
fd1af47233 |
No files matched your search
Generated
-21
@@ -1,21 +0,0 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
packages = ["."]
|
||||
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/nsf/termbox-go"
|
||||
packages = ["."]
|
||||
revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "8508b73787d4948edb76ccc25789c311a4ab84d4c8c0b96b267857e2e88d974e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/nsf/termbox-go"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -48,7 +47,7 @@ func (app *app) readFile(path string) {
|
||||
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
app.ui.printf("opening file: %s", err)
|
||||
app.ui.echoerrf("opening file: %s", err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
@@ -60,7 +59,7 @@ func (app *app) readFile(path string) {
|
||||
}
|
||||
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,13 +155,23 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
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!")
|
||||
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
@@ -189,6 +198,37 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
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:
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
@@ -242,40 +282,15 @@ func (app *app) loop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) exportVars() {
|
||||
var envFile string
|
||||
func (app *app) exportFiles() {
|
||||
var currFile string
|
||||
if f, err := app.nav.currFile(); err == nil {
|
||||
envFile = f.path
|
||||
currFile = f.path
|
||||
}
|
||||
|
||||
selections := app.nav.currSelections()
|
||||
currSelections := app.nav.currSelections()
|
||||
|
||||
envFiles := strings.Join(selections, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(selections) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
|
||||
os.Setenv("OPENER", envOpener)
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
exportFiles(currFile, currSelections)
|
||||
}
|
||||
|
||||
func waitKey() error {
|
||||
@@ -300,7 +315,7 @@ func waitKey() error {
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.exportVars()
|
||||
app.exportFiles()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
@@ -337,13 +352,13 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
app.ui.printf("running shell: %s", err)
|
||||
app.ui.echoerrf("running shell: %s", err)
|
||||
}
|
||||
|
||||
switch prefix {
|
||||
case "!":
|
||||
if err := waitKey(); err != nil {
|
||||
app.ui.printf("waiting key: %s", err)
|
||||
app.ui.echoerrf("waiting key: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@ import (
|
||||
)
|
||||
|
||||
func run() {
|
||||
if err := termbox.Init(); err != nil {
|
||||
log.Fatalf("initializing termbox: %s", err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
setColorMode()
|
||||
|
||||
f, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -24,21 +31,14 @@ func run() {
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
if err := termbox.Init(); err != nil {
|
||||
log.Fatalf("initializing termbox: %s", err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
setColorMode()
|
||||
|
||||
app := newApp()
|
||||
|
||||
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 {
|
||||
app.ui.printf("reading history file: %s", err)
|
||||
app.ui.echoerrf("reading history file: %s", err)
|
||||
}
|
||||
|
||||
app.loop()
|
||||
@@ -140,7 +140,7 @@ func loadFiles() (list []string, cp bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func sendRemote(cmd string) error {
|
||||
func remote(cmd string) error {
|
||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dialing to send server: %s", err)
|
||||
|
||||
+41
@@ -54,6 +54,8 @@ var (
|
||||
"mark-load",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"source",
|
||||
@@ -116,6 +118,7 @@ var (
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"errorfmt",
|
||||
"filesep",
|
||||
"ifs",
|
||||
"previewer",
|
||||
@@ -319,6 +322,44 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
return
|
||||
}
|
||||
|
||||
func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(wd)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
var longest string
|
||||
|
||||
for _, f := range files {
|
||||
if !strings.HasPrefix(f.Name(), s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, f.Name())
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, f.Name())
|
||||
} else if s != "" {
|
||||
longest = f.Name()
|
||||
}
|
||||
}
|
||||
|
||||
if longest == "" {
|
||||
longest = s
|
||||
}
|
||||
|
||||
longestAcc = []rune(longest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
@@ -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
@@ -33,7 +33,7 @@ func appendTransliterate(base, norm string, uppercase bool) {
|
||||
lenNorm := len(normRunes)
|
||||
lenBase := len(baseRunes)
|
||||
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 {
|
||||
|
||||
@@ -16,115 +16,118 @@ Reference
|
||||
|
||||
The following commands are provided by lf with default keybindings:
|
||||
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes copied/cut files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
select changes current file selection to its argument
|
||||
source reads the configuration file in its argument
|
||||
push simulates key pushes given in its argument
|
||||
delete deletes the current file or selected file(s)
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
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
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
ifs string (default '') (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default '')
|
||||
shellopts string (default '')
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default '') (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default '')
|
||||
shellopts string (default '')
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
|
||||
@@ -517,33 +520,48 @@ should not be needed for users.
|
||||
|
||||
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.
|
||||
|
||||
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 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.
|
||||
|
||||
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 %{{
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
cp -R -n $list .
|
||||
cp -R $list .
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
mv $list .
|
||||
fi
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send clear'
|
||||
}}
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
+133
-114
@@ -19,115 +19,118 @@ Reference
|
||||
|
||||
The following commands are provided by lf with default keybindings:
|
||||
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes copied/cut files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
select changes current file selection to its argument
|
||||
source reads the configuration file in its argument
|
||||
push simulates key pushes given in its argument
|
||||
delete deletes the current file or selected file(s)
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
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
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
ifs string (default '') (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default '')
|
||||
shellopts string (default '')
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default ”) (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default ”)
|
||||
shellopts string (default ”)
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
|
||||
@@ -539,34 +542,50 @@ should not be needed for users.
|
||||
|
||||
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.
|
||||
|
||||
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 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.
|
||||
|
||||
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 %{{
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
cp -R -n $list .
|
||||
cp -R $list .
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
mv $list .
|
||||
fi
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send clear'
|
||||
}}
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
+17
-12
@@ -1,13 +1,18 @@
|
||||
# Autocompletion for Fish shell
|
||||
# Put this file somewhere in $fish_complete_path
|
||||
# for example in ~/.config/fish/completions/
|
||||
# Autocompletion for fish shell.
|
||||
#
|
||||
# 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 cpuprofile -r -d 'path to the file to write the CPU profile'
|
||||
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 memprofile -r -d 'path to the file to write the memory profile'
|
||||
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 server -d 'start server (automatic)'
|
||||
complete -c lf -o version -d 'show version'
|
||||
complete -c lf -s h -d "short help"
|
||||
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 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 memprofile -r -d 'path to the file to write the memory profile'
|
||||
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 server -d 'start server (automatic)'
|
||||
complete -c lf -o version -d 'show version'
|
||||
complete -c lf -o help -d 'show help'
|
||||
+13
-9
@@ -47,20 +47,24 @@ cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
map r push :rename<space>
|
||||
|
||||
# make sure trash folder exists
|
||||
%mkdir -p ~/.trash
|
||||
# %mkdir -p ~/.trash
|
||||
|
||||
# move current file or selected files to trash folder
|
||||
# (also see 'man mv' for backup/overwrite options)
|
||||
cmd trash %set -f; mv $fx ~/.trash
|
||||
|
||||
# delete current file or selected files (prompting)
|
||||
cmd delete ${{
|
||||
set -f
|
||||
printf "$fx\n"
|
||||
printf "delete?[y/n]"
|
||||
read ans
|
||||
[ $ans = "y" ] && rm -rf $fx
|
||||
}}
|
||||
# define a custom 'delete' command
|
||||
# cmd delete ${{
|
||||
# set -f
|
||||
# printf "$fx\n"
|
||||
# printf "delete?[y/n]"
|
||||
# read ans
|
||||
# [ $ans = "y" ] && rm -rf $fx
|
||||
# }}
|
||||
|
||||
# use '<delete>' key for either 'trash' or 'delete' command
|
||||
# map <delete> trash
|
||||
# map <delete> delete
|
||||
|
||||
# extract the current file with the right command
|
||||
# (xkcd link: https://xkcd.com/1168/)
|
||||
|
||||
@@ -158,22 +158,22 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "findlen":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("findlen: %s", err)
|
||||
app.ui.echoerrf("findlen: %s", err)
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
gOpts.findlen = n
|
||||
case "period":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("period: %s", err)
|
||||
app.ui.echoerrf("period: %s", err)
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
gOpts.period = n
|
||||
@@ -186,25 +186,27 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "scrolloff":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("scrolloff: %s", err)
|
||||
app.ui.echoerrf("scrolloff: %s", err)
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
gOpts.scrolloff = n
|
||||
case "tabstop":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("tabstop: %s", err)
|
||||
app.ui.echoerrf("tabstop: %s", err)
|
||||
return
|
||||
}
|
||||
if n <= 0 {
|
||||
app.ui.print("tabstop: value should be a positive number")
|
||||
app.ui.echoerr("tabstop: value should be a positive number")
|
||||
return
|
||||
}
|
||||
gOpts.tabstop = n
|
||||
case "errorfmt":
|
||||
gOpts.errorfmt = e.val
|
||||
case "filesep":
|
||||
gOpts.filesep = e.val
|
||||
case "ifs":
|
||||
@@ -217,7 +219,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.shell = e.val
|
||||
case "sortby":
|
||||
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
|
||||
}
|
||||
switch e.val {
|
||||
@@ -240,17 +242,17 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
for _, s := range toks {
|
||||
n, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
app.ui.printf("ratios: %s", err)
|
||||
app.ui.echoerrf("ratios: %s", err)
|
||||
return
|
||||
}
|
||||
if n <= 0 {
|
||||
app.ui.print("ratios: value should be a positive number")
|
||||
app.ui.echoerr("ratios: value should be a positive number")
|
||||
return
|
||||
}
|
||||
rats = append(rats, n)
|
||||
}
|
||||
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
|
||||
}
|
||||
gOpts.ratios = rats
|
||||
@@ -260,7 +262,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
toks := strings.Split(e.val, ":")
|
||||
for _, s := range toks {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -268,7 +270,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "shellopts":
|
||||
gOpts.shellopts = strings.Split(e.val, ":")
|
||||
default:
|
||||
app.ui.printf("unknown option: %s", e.opt)
|
||||
app.ui.echoerrf("unknown option: %s", e.opt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,12 +328,12 @@ func update(app *app) {
|
||||
|
||||
if app.nav.searchBack {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -347,12 +349,12 @@ func update(app *app) {
|
||||
|
||||
if app.nav.searchBack {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -373,7 +375,7 @@ func insert(app *app, arg string) {
|
||||
if gOpts.findlen == 0 {
|
||||
switch app.nav.findSingle() {
|
||||
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:
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -388,7 +390,7 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
|
||||
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 {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -405,7 +407,7 @@ func insert(app *app, arg string) {
|
||||
if gOpts.findlen == 0 {
|
||||
switch app.nav.findSingle() {
|
||||
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:
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -420,7 +422,7 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
|
||||
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 {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -439,12 +441,12 @@ func insert(app *app, arg string) {
|
||||
|
||||
if arg == "y" {
|
||||
if err := app.nav.del(); err != nil {
|
||||
app.ui.printf("delete: %s", err)
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send load"); err != nil {
|
||||
app.ui.printf("delete: %s", err)
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
}
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-save: ":
|
||||
@@ -472,11 +474,11 @@ func insert(app *app, arg string) {
|
||||
|
||||
path, ok := app.nav.marks[arg]
|
||||
if !ok {
|
||||
app.ui.print("mark-load: no such mark")
|
||||
app.ui.echoerr("mark-load: no such mark")
|
||||
return
|
||||
}
|
||||
if err := app.nav.cd(path); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
@@ -519,7 +521,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
case "updir":
|
||||
for i := 0; i < e.count; i++ {
|
||||
if err := app.nav.updir(); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -528,14 +530,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
case "open":
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.printf("opening: %s", err)
|
||||
app.ui.echoerrf("opening: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if curr.IsDir() {
|
||||
err := app.nav.open()
|
||||
if err != nil {
|
||||
app.ui.printf("opening directory: %s", err)
|
||||
app.ui.echoerrf("opening directory: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
@@ -593,56 +595,50 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.unselect()
|
||||
case "copy":
|
||||
if err := app.nav.save(true); err != nil {
|
||||
app.ui.printf("copy: %s", err)
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("copy: %s", err)
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
}
|
||||
case "cut":
|
||||
if err := app.nav.save(false); err != nil {
|
||||
app.ui.printf("cut: %s", err)
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("cut: %s", err)
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
}
|
||||
case "paste":
|
||||
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
} else if err := app.nav.paste(); err != nil {
|
||||
app.ui.printf("paste: %s", err)
|
||||
} else if err := app.nav.paste(app.ui); err != nil {
|
||||
app.ui.echoerrf("paste: %s", err)
|
||||
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":
|
||||
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
app.nav.unselect()
|
||||
if err := sendRemote("send load"); err != nil {
|
||||
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.printf("delete: %s", err)
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.cmdPrefix = "delete?[y/N]: "
|
||||
}
|
||||
case "clear":
|
||||
if err := saveFiles(nil, false); err != nil {
|
||||
app.ui.printf("clear: %s", err)
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
return
|
||||
}
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("clear: %s", err)
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
}
|
||||
case "draw":
|
||||
case "redraw":
|
||||
@@ -653,7 +649,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
if err := app.nav.reload(); err != nil {
|
||||
app.ui.printf("reload: %s", err)
|
||||
app.ui.echoerrf("reload: %s", err)
|
||||
}
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
@@ -707,12 +703,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
for i := 0; i < e.count; i++ {
|
||||
if app.nav.searchBack {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -723,12 +719,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
for i := 0; i < e.count; i++ {
|
||||
if app.nav.searchBack {
|
||||
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
|
||||
}
|
||||
} else {
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -742,10 +738,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = "mark-load: "
|
||||
case "sync":
|
||||
if err := app.nav.sync(); err != nil {
|
||||
app.ui.printf("sync: %s", err)
|
||||
app.ui.echoerrf("sync: %s", err)
|
||||
}
|
||||
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":
|
||||
path := "~"
|
||||
if len(e.args) > 0 {
|
||||
@@ -758,7 +758,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
|
||||
if err := app.nav.cd(path); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -776,7 +776,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
case "select":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.print("select: requires an argument")
|
||||
app.ui.echoerr("select: requires an argument")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -786,7 +786,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
|
||||
if err := app.nav.sel(e.args[0]); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -805,13 +805,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
case "source":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.print("source: requires an argument")
|
||||
app.ui.echoerr("source: requires an argument")
|
||||
return
|
||||
}
|
||||
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||
case "push":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.print("push: requires an argument")
|
||||
app.ui.echoerr("push: requires an argument")
|
||||
return
|
||||
}
|
||||
log.Println("pushing keys", e.args[0])
|
||||
@@ -841,10 +841,15 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = ""
|
||||
case "cmd-complete":
|
||||
var matches []string
|
||||
if app.ui.cmdPrefix == ":" {
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||
} else {
|
||||
case "/", "?":
|
||||
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
||||
case "$", "%", "!", "&":
|
||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||
default:
|
||||
return
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
if len(matches) > 1 {
|
||||
@@ -870,7 +875,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
p.expr.eval(app, nil)
|
||||
}
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
case "$":
|
||||
log.Printf("shell: %s", s)
|
||||
@@ -904,7 +909,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = ""
|
||||
app.nav.search = s
|
||||
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 {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -919,7 +924,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = ""
|
||||
app.nav.search = s
|
||||
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 {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
@@ -1143,7 +1148,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
default:
|
||||
cmd, ok := gOpts.cmds[e.name]
|
||||
if !ok {
|
||||
app.ui.printf("command not found: %s", e.name)
|
||||
app.ui.echoerrf("command not found: %s", e.name)
|
||||
return
|
||||
}
|
||||
cmd.eval(app, e.args)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module github.com/gokcehan/lf
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
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/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs=
|
||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
@@ -26,120 +26,123 @@ You can run 'lf -help' to see descriptions of command line options.
|
||||
The following commands are provided by lf with default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
.EE
|
||||
.PP
|
||||
The following commands are provided by lf without default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes copied/cut files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
select changes current file selection to its argument
|
||||
source reads the configuration file in its argument
|
||||
push simulates key pushes given in its argument
|
||||
delete deletes the current file or selected file(s)
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
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
|
||||
.PP
|
||||
The following command line commands are provided by lf with default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
.EE
|
||||
.PP
|
||||
The following options can be used to customize the behavior of lf:
|
||||
.PP
|
||||
.EX
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\en")
|
||||
ifs string (default '') (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default '')
|
||||
shellopts string (default '')
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
|
||||
filesep string (default "\en")
|
||||
ifs string (default ”) (not exported 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")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default ”)
|
||||
shellopts string (default ”)
|
||||
.EE
|
||||
.PP
|
||||
The following variables are exported for shell commands:
|
||||
@@ -528,9 +531,11 @@ There is a 'quit' command to close client connections and quit the server:
|
||||
.PP
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
|
||||
.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
|
||||
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 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
|
||||
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
|
||||
.EX
|
||||
cmd paste %{{
|
||||
@@ -538,16 +543,16 @@ You can customize these operations by defining a 'paste' command. This is a spec
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
cp -R -n $list .
|
||||
cp -R $list .
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
mv $list .
|
||||
fi
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send clear'
|
||||
}}
|
||||
.EE
|
||||
.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
|
||||
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
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,6 +43,24 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func exportEnvVars() {
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
|
||||
os.Setenv("OPENER", envOpener)
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
cmd := detachedCommand(os.Args[0], "-server")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -132,7 +151,7 @@ func main() {
|
||||
case *showVersion:
|
||||
fmt.Println(gVersion)
|
||||
case *remoteCmd != "":
|
||||
if err := sendRemote(*remoteCmd); err != nil {
|
||||
if err := remote(*remoteCmd); err != nil {
|
||||
log.Fatalf("remote command: %s", err)
|
||||
}
|
||||
case *serverMode:
|
||||
@@ -162,6 +181,8 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
exportEnvVars()
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
@@ -133,11 +133,10 @@ func splitWord(s string) (word, rest string) {
|
||||
return
|
||||
}
|
||||
|
||||
// This function converts a size in bytes to a human readable form. For this
|
||||
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
||||
// the first significant digit is shown, otherwise it is hidden. Numbers are
|
||||
// always rounded down. For these reasons this function always show somewhat
|
||||
// smaller values but it should be fine for most human beings.
|
||||
// This function converts a size in bytes to a human readable form using metric
|
||||
// suffixes (e.g. 1K = 1000). For values less than 10 the first significant
|
||||
// digit is shown, otherwise it is hidden. Numbers are always rounded down.
|
||||
// This should be fine for most human beings.
|
||||
func humanize(size int64) string {
|
||||
if size < 1000 {
|
||||
return fmt.Sprintf("%dB", size)
|
||||
|
||||
@@ -144,13 +144,13 @@ func (dir *dir) sort() {
|
||||
// files to the first non-hidden file in the list
|
||||
if gOpts.sortType.option&hiddenSort == 0 {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
||||
if isHidden(dir.files[i]) && isHidden(dir.files[j]) {
|
||||
return i < j
|
||||
}
|
||||
return dir.files[i].Name()[0] == '.'
|
||||
return isHidden(dir.files[i])
|
||||
})
|
||||
for i, f := range dir.files {
|
||||
if f.Name()[0] != '.' {
|
||||
if !isHidden(f) {
|
||||
dir.files = dir.files[i:]
|
||||
return
|
||||
}
|
||||
@@ -188,22 +188,32 @@ func (dir *dir) sel(name string, height int) {
|
||||
}
|
||||
|
||||
type nav struct {
|
||||
dirs []*dir
|
||||
dirChan chan *dir
|
||||
regChan chan *reg
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
find string
|
||||
findBack bool
|
||||
search string
|
||||
searchBack bool
|
||||
searchInd int
|
||||
searchPos int
|
||||
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
|
||||
regChan chan *reg
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
find string
|
||||
findBack bool
|
||||
search string
|
||||
searchBack bool
|
||||
searchInd int
|
||||
searchPos int
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
@@ -271,15 +281,19 @@ func newNav(height int) *nav {
|
||||
}
|
||||
|
||||
nav := &nav{
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
copyBytesChan: make(chan int64, 1024),
|
||||
copyTotalChan: make(chan int64, 1024),
|
||||
moveCountChan: make(chan int, 1024),
|
||||
moveTotalChan: make(chan int, 1024),
|
||||
dirChan: make(chan *dir),
|
||||
regChan: make(chan *reg),
|
||||
dirCache: make(map[string]*dir),
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
}
|
||||
|
||||
nav.getDirs(wd)
|
||||
@@ -382,7 +396,7 @@ func (nav *nav) preview() {
|
||||
for i := 0; i < nav.height && buf.Scan(); i++ {
|
||||
for _, r := range buf.Text() {
|
||||
if r == 0 {
|
||||
reg.lines = []string{"\033[1mbinary\033[0m"}
|
||||
reg.lines = []string{"\033[7mbinary\033[0m"}
|
||||
nav.regChan <- reg
|
||||
return
|
||||
}
|
||||
@@ -568,28 +582,135 @@ func (nav *nav) save(cp bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) paste() error {
|
||||
list, cp, err := loadFiles()
|
||||
func (nav *nav) copyAsync(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
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(list) == 0 {
|
||||
if len(srcs) == 0 {
|
||||
return errors.New("no file in copy/cut buffer")
|
||||
}
|
||||
|
||||
dir := nav.currDir()
|
||||
dstDir := nav.currDir().path
|
||||
|
||||
cmd := pasteCommand(list, dir, cp)
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("pasting files: %s", err)
|
||||
if cp {
|
||||
go nav.copyAsync(ui, srcs, dstDir)
|
||||
} else {
|
||||
go nav.moveAsync(ui, srcs, dstDir)
|
||||
}
|
||||
|
||||
if err := saveFiles(nil, false); err != nil {
|
||||
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
||||
}
|
||||
|
||||
if err := remote("send sync"); err != nil {
|
||||
return fmt.Errorf("paste: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ var gOpts struct {
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
@@ -71,11 +72,16 @@ func init() {
|
||||
gOpts.ignoredia = false
|
||||
gOpts.smartdia = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.number = false
|
||||
gOpts.relativenumber = false
|
||||
gOpts.findlen = 1
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.ifs = ""
|
||||
gOpts.previewer = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.timefmt = time.ANSIC
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -114,31 +115,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
||||
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() {
|
||||
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||
@@ -156,3 +132,21 @@ func moveCursor(y, x int) {
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
return f.Mode()&0111 != 0
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo) bool {
|
||||
return f.Name()[0] == '.'
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := f
|
||||
envFiles := strings.Join(fs, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
+26
-28
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -36,7 +37,7 @@ var (
|
||||
|
||||
func init() {
|
||||
if envOpener == "" {
|
||||
envOpener = "start"
|
||||
envOpener = `start ""`
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
@@ -89,33 +90,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
||||
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() {
|
||||
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||
@@ -141,3 +115,27 @@ func isExecutable(f os.FileInfo) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo) bool {
|
||||
// TODO: implement
|
||||
return false
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := fmt.Sprintf(`"%s"`, f)
|
||||
|
||||
var quotedFiles []string
|
||||
for _, f := range fs {
|
||||
quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f))
|
||||
}
|
||||
envFiles := strings.Join(quotedFiles, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (win *win) printReg(reg *reg) {
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if reg.loading {
|
||||
fg = termbox.AttrBold
|
||||
fg = termbox.AttrReverse
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
return
|
||||
}
|
||||
@@ -246,17 +246,13 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
return
|
||||
}
|
||||
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if dir.loading {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "loading...")
|
||||
return
|
||||
}
|
||||
|
||||
if len(dir.files) == 0 {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "empty")
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -267,8 +263,8 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
return
|
||||
}
|
||||
|
||||
var lnwidth int = 0
|
||||
var lnformat string = ""
|
||||
var lnwidth int
|
||||
var lnformat string
|
||||
|
||||
if gOpts.number || gOpts.relativenumber {
|
||||
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] {
|
||||
fg, bg = colors.get(f)
|
||||
fg, bg := colors.get(f)
|
||||
|
||||
if lnwidth > 0 {
|
||||
var ln string
|
||||
@@ -485,13 +481,30 @@ func (ui *ui) sort() {
|
||||
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
|
||||
log.Print(msg)
|
||||
}
|
||||
|
||||
func (ui *ui) printf(format string, a ...interface{}) {
|
||||
ui.print(fmt.Sprintf(format, a...))
|
||||
func (ui *ui) echomsgf(format string, a ...interface{}) {
|
||||
ui.echomsg(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
func (ui *ui) echoerr(msg string) {
|
||||
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
|
||||
log.Printf("error: %s", msg)
|
||||
}
|
||||
|
||||
func (ui *ui) echoerrf(format string, a ...interface{}) {
|
||||
ui.echoerr(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
type reg struct {
|
||||
@@ -524,7 +537,7 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
||||
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) {
|
||||
@@ -576,7 +589,18 @@ func (ui *ui) drawStatLine(nav *nav) {
|
||||
ind := min(currDir.ind+1, tot)
|
||||
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)
|
||||
}
|
||||
@@ -769,7 +793,7 @@ func (ui *ui) pollEvent() termbox.Event {
|
||||
ev.Key = val
|
||||
} else {
|
||||
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) {
|
||||
case 0:
|
||||
ui.printf("unknown mapping: %s", string(ui.keyAcc))
|
||||
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
||||
ch <- draw
|
||||
ui.keyAcc = 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)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyAcc)]
|
||||
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)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyAcc)]
|
||||
if e, ok := expr.(*callExpr); ok {
|
||||
|
||||
Reference in new issue
Block a user