Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
228a20ffd1 | ||
|
|
8979e2b260 | ||
|
|
6a286673ce | ||
|
|
4c89535e18 | ||
|
|
88749a3da1 | ||
|
|
cf79726d21 | ||
|
|
50dd374f77 | ||
|
|
1460f49b3e | ||
|
|
969dee3621 | ||
|
|
36798b4c24 | ||
|
|
7a3bd15903 | ||
|
|
76c85d9459 | ||
|
|
355075cf75 | ||
|
|
1186bf6382 | ||
|
|
61442f8880 | ||
|
|
ec512dfe31 | ||
|
|
f248ce77a1 | ||
|
|
3c8b5a5630 | ||
|
|
b608682580 | ||
|
|
ab6549679b | ||
|
|
5e9580500c | ||
|
|
ebf3bcc76b | ||
|
|
f1f28018a6 | ||
|
|
b40ebdcb33 | ||
|
|
4f5b4e6dbf | ||
|
|
4f02cf47c7 | ||
|
|
eab7b61846 | ||
|
|
658af50006 | ||
|
|
bc0000f274 | ||
|
|
24f01f4988 | ||
|
|
d25faf7186 | ||
|
|
e36b1b0484 | ||
|
|
1d95991054 | ||
|
|
fa45a8b649 | ||
|
|
1c8def356d | ||
|
|
25c2f037cb | ||
|
|
143de6e7eb | ||
|
|
2b445aa205 | ||
|
|
d2414f7580 | ||
|
|
8be63a9c83 | ||
|
|
c630293cc2 | ||
|
|
9c891307f3 | ||
|
|
9539daf8df | ||
|
|
7174b7e307 | ||
|
|
6d1a840587 | ||
|
|
490a4a9d07 | ||
|
|
a6544757db | ||
|
|
f8daa60b31 | ||
|
|
3b49e1a2b6 | ||
|
|
d0cd181eb6 | ||
|
|
9880104c12 | ||
|
|
ffdcb71897 | ||
|
|
707d927788 | ||
|
|
0a22e7c5c8 | ||
|
|
2f056ad359 | ||
|
|
e7fb56391f | ||
|
|
3e36500901 | ||
|
|
f2e3c7a0ce | ||
|
|
75e59cdd08 | ||
|
|
001ee5bfae | ||
|
|
e1b939bf7c | ||
|
|
ce4ea6ea53 | ||
|
|
45552cf809 | ||
|
|
c937dab9e9 | ||
|
|
1119ba0d25 | ||
|
|
83a6e506d2 | ||
|
|
bc2a80fd6e | ||
|
|
e2bf773f3b | ||
|
|
4d3e1cfd6e | ||
|
|
fd73a53f84 | ||
|
|
cbb559346d | ||
|
|
5d1136abfe | ||
|
|
0e3910652a | ||
|
|
99cee56d6e | ||
|
|
25e487cc51 | ||
|
|
72facea2a0 | ||
|
|
8933a3eafe | ||
|
|
41e0bb32cd | ||
|
|
c49140ab36 | ||
|
|
933b49d095 | ||
|
|
c5d05b7683 | ||
|
|
9c1836c18b | ||
|
|
6693709f36 | ||
|
|
17949fc25a | ||
|
|
3c5abbbc5d | ||
|
|
e0747fa2f9 | ||
|
|
b0064df32c | ||
|
|
74eab96637 | ||
|
|
d63e7a2076 | ||
|
|
d5f989f373 | ||
|
|
f76bf30f65 | ||
|
|
8327505398 | ||
|
|
74ef9fcd83 | ||
|
|
0482340d5e | ||
|
|
7a4d1cc275 | ||
|
|
cd396605da | ||
|
|
c43026d1e2 | ||
|
|
7b89126e04 | ||
|
|
ff4c36565c | ||
|
|
cfc9e355b3 | ||
|
|
bc33f3154a | ||
|
|
9991a40e87 | ||
|
|
41339a9e5a | ||
|
|
9515bd73d0 | ||
|
|
d13cc79bc4 | ||
|
|
bba32beb8a | ||
|
|
50ac367626 | ||
|
|
3b34b20cb8 | ||
|
|
6982ffe4cf | ||
|
|
488bf9f6b6 | ||
|
|
2ab866d474 | ||
|
|
9f661344ed | ||
|
|
bfd01e5ed8 | ||
|
|
27861f06e2 | ||
|
|
cb36e87b80 | ||
|
|
30d3078559 | ||
|
|
db224f04fe | ||
|
|
afca893153 | ||
|
|
16db95707e | ||
|
|
bf39c7c63b | ||
|
|
eb8e516cfb | ||
|
|
34f39f90b2 | ||
|
|
4c6241ca42 | ||
|
|
8388b4f385 | ||
|
|
80ab2e4fc4 | ||
|
|
f071a3ae70 | ||
|
|
f3407b2d61 | ||
|
|
a5199960ed | ||
|
|
e69a229578 | ||
|
|
e815adc6a6 | ||
|
|
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
+5
-2
@@ -1,8 +1,11 @@
|
||||
language: go
|
||||
install:
|
||||
- go get github.com/nsf/termbox-go
|
||||
|
||||
go:
|
||||
- 1.15.x
|
||||
|
||||
before_deploy:
|
||||
- gen/xbuild.sh
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
|
||||
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 @@
|
||||
[](https://travis-ci.org/gokcehan/lf)
|
||||
[](https://goreportcard.com/report/github.com/gokcehan/lf)
|
||||
[](https://godoc.org/github.com/gokcehan/lf)
|
||||
[](https://gitter.im/lf-fm/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
|
||||
> This is a work in progress. Use at your own risk.
|
||||
|
||||
@@ -42,13 +41,25 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tut
|
||||
|
||||
## Installation
|
||||
|
||||
See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages.
|
||||
|
||||
See [releases](https://github.com/gokcehan/lf/releases) for pre-built binaries.
|
||||
|
||||
If you like to build from the source:
|
||||
If you like to build from the source on unix:
|
||||
|
||||
go get -u github.com/gokcehan/lf
|
||||
env CGO_ENABLED=0 GO111MODULE=on go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
|
||||
See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maintained packages.
|
||||
On windows `cmd`:
|
||||
|
||||
set CGO_ENABLED=0
|
||||
set GO111MODULE=on
|
||||
go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
|
||||
On windows `powershell`:
|
||||
|
||||
$env:CGO_ENABLED = '0'
|
||||
$env:GO111MODULE = 'on'
|
||||
go get -u -ldflags="-s -w" github.com/gokcehan/lf
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
@@ -7,10 +7,13 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
type cmdItem struct {
|
||||
@@ -31,15 +34,28 @@ type app struct {
|
||||
cmdHistoryInd int
|
||||
}
|
||||
|
||||
func newApp() *app {
|
||||
ui := newUI()
|
||||
func newApp(screen tcell.Screen) *app {
|
||||
ui := newUI(screen)
|
||||
nav := newNav(ui.wins[0].h)
|
||||
|
||||
quitChan := make(chan bool, 1)
|
||||
|
||||
osChan := make(chan os.Signal, 1)
|
||||
signal.Notify(osChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-osChan
|
||||
nav.copyTotalChan <- -nav.copyTotal
|
||||
nav.moveTotalChan <- -nav.moveTotal
|
||||
nav.deleteTotalChan <- -nav.deleteTotal
|
||||
quitChan <- true
|
||||
return
|
||||
}()
|
||||
|
||||
return &app{
|
||||
ui: ui,
|
||||
nav: nav,
|
||||
ticker: new(time.Ticker),
|
||||
quitChan: make(chan bool, 1),
|
||||
quitChan: quitChan,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +64,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 +76,7 @@ func (app *app) readFile(path string) {
|
||||
}
|
||||
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +93,12 @@ func (app *app) readHistory() error {
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
toks := strings.SplitN(scanner.Text(), " ", 2)
|
||||
if toks[0] != ":" && toks[0] != "$" && toks[0] != "%" && toks[0] != "!" && toks[0] != "&" {
|
||||
continue
|
||||
}
|
||||
if len(toks) < 2 {
|
||||
continue
|
||||
}
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{toks[0], toks[1]})
|
||||
}
|
||||
|
||||
@@ -133,12 +155,20 @@ func (app *app) writeHistory() error {
|
||||
// for evaluation. Similarly directories and regular files are also read in
|
||||
// separate goroutines and sent here for update.
|
||||
func (app *app) loop() {
|
||||
clientChan := app.ui.readExpr()
|
||||
serverChan := readExpr()
|
||||
|
||||
app.ui.readExpr()
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
lstat, err := os.Lstat(gSelect)
|
||||
if err != nil {
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||
} else if lstat.IsDir() {
|
||||
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||
} else {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -156,19 +186,30 @@ 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:
|
||||
log.Print("bye!")
|
||||
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
log.Printf("writing marks file: %s", err)
|
||||
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
|
||||
}
|
||||
|
||||
if app.nav.deleteTotal > 0 {
|
||||
app.ui.echoerr("quit: delete operation in progress")
|
||||
continue
|
||||
}
|
||||
|
||||
log.Print("bye!")
|
||||
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
}
|
||||
@@ -180,16 +221,62 @@ func (app *app) loop() {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
dir := app.nav.currDir()
|
||||
|
||||
_, err = f.WriteString(dir.path)
|
||||
_, err = f.WriteString(app.nav.currDir().path)
|
||||
if err != nil {
|
||||
log.Printf("writing last dir file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
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 n := <-app.nav.deleteCountChan:
|
||||
app.nav.deleteCount += n
|
||||
if app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {
|
||||
app.nav.deleteUpdate = 0
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
case n := <-app.nav.deleteTotalChan:
|
||||
app.nav.deleteTotal += n
|
||||
if n < 0 {
|
||||
app.nav.deleteCount += n
|
||||
}
|
||||
if app.nav.deleteTotal == 0 {
|
||||
app.nav.deleteUpdate = 0
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case d := <-app.nav.dirChan:
|
||||
app.nav.checkDir(d)
|
||||
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.ind = prev.ind
|
||||
@@ -218,6 +305,8 @@ func (app *app) loop() {
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
case r := <-app.nav.regChan:
|
||||
app.nav.checkReg(r)
|
||||
|
||||
app.nav.regCache[r.path] = r
|
||||
|
||||
curr, err := app.nav.currFile()
|
||||
@@ -228,7 +317,27 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
case e := <-clientChan:
|
||||
case ev := <-app.ui.evChan:
|
||||
e := app.ui.readEvent(ev)
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
e.eval(app, nil)
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case ev := <-app.ui.evChan:
|
||||
e = app.ui.readEvent(ev)
|
||||
if e == nil {
|
||||
continue
|
||||
}
|
||||
e.eval(app, nil)
|
||||
default:
|
||||
break loop
|
||||
}
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case e := <-app.ui.exprChan:
|
||||
e.eval(app, nil)
|
||||
app.ui.draw(app.nav)
|
||||
case e := <-serverChan:
|
||||
@@ -242,40 +351,15 @@ func (app *app) loop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) exportVars() {
|
||||
var envFile string
|
||||
if f, err := app.nav.currFile(); err == nil {
|
||||
envFile = f.path
|
||||
func (app *app) exportFiles() {
|
||||
var currFile string
|
||||
if curr, err := app.nav.currFile(); err == nil {
|
||||
currFile = curr.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,11 +384,13 @@ 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()
|
||||
exportOpts()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
var out io.Reader
|
||||
var err error
|
||||
switch prefix {
|
||||
case "$", "!":
|
||||
cmd.Stdin = os.Stdin
|
||||
@@ -314,6 +400,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.ui.pause()
|
||||
defer app.ui.resume()
|
||||
defer app.nav.renew()
|
||||
|
||||
err = cmd.Run()
|
||||
case "%":
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
@@ -326,29 +414,23 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
out = stdout
|
||||
cmd.Stderr = cmd.Stdout
|
||||
}
|
||||
|
||||
var err error
|
||||
switch prefix {
|
||||
case "$", "!":
|
||||
err = cmd.Run()
|
||||
case "%", "&":
|
||||
fallthrough
|
||||
case "&":
|
||||
err = cmd.Start()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
|
||||
switch prefix {
|
||||
case "%":
|
||||
@@ -378,5 +460,11 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.ui.cmdPrefix = ""
|
||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||
}()
|
||||
case "&":
|
||||
go func() {
|
||||
if err := cmd.Wait(); err != nil {
|
||||
log.Printf("running shell: %s", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,18 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
func run() {
|
||||
var screen tcell.Screen
|
||||
var err error
|
||||
if screen, err = tcell.NewScreen(); err != nil {
|
||||
log.Fatalf("creating screen: %s", err)
|
||||
} else if err = screen.Init(); err != nil {
|
||||
log.Fatalf("initializing screen: %s", err)
|
||||
}
|
||||
|
||||
f, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -24,24 +32,18 @@ func run() {
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
if err := termbox.Init(); err != nil {
|
||||
log.Fatalf("initializing termbox: %s", err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
setColorMode()
|
||||
|
||||
app := newApp()
|
||||
app := newApp(screen)
|
||||
|
||||
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()
|
||||
app.ui.screen.Fini()
|
||||
}
|
||||
|
||||
func readExpr() <-chan expr {
|
||||
@@ -52,7 +54,7 @@ func readExpr() <-chan expr {
|
||||
|
||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||
for err != nil {
|
||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
||||
log.Printf("connecting server: %s", err)
|
||||
time.Sleep(duration)
|
||||
duration *= 2
|
||||
c, err = net.Dial(gSocketProt, gSocketPath)
|
||||
@@ -140,7 +142,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)
|
||||
|
||||
@@ -7,48 +7,18 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||
type styleMap map[string]tcell.Style
|
||||
|
||||
var gAnsiCodes = map[int]termbox.Attribute{
|
||||
0: termbox.ColorDefault,
|
||||
1: termbox.AttrBold,
|
||||
4: termbox.AttrUnderline,
|
||||
7: termbox.AttrReverse,
|
||||
30: termbox.ColorBlack,
|
||||
31: termbox.ColorRed,
|
||||
32: termbox.ColorGreen,
|
||||
33: termbox.ColorYellow,
|
||||
34: termbox.ColorBlue,
|
||||
35: termbox.ColorMagenta,
|
||||
36: termbox.ColorCyan,
|
||||
37: termbox.ColorWhite,
|
||||
40: termbox.ColorBlack,
|
||||
41: termbox.ColorRed,
|
||||
42: termbox.ColorGreen,
|
||||
43: termbox.ColorYellow,
|
||||
44: termbox.ColorBlue,
|
||||
45: termbox.ColorMagenta,
|
||||
46: termbox.ColorCyan,
|
||||
47: termbox.ColorWhite,
|
||||
}
|
||||
|
||||
type colorEntry struct {
|
||||
fg termbox.Attribute
|
||||
bg termbox.Attribute
|
||||
}
|
||||
|
||||
type colorMap map[string]colorEntry
|
||||
|
||||
func parseColors() colorMap {
|
||||
func parseStyles() styleMap {
|
||||
if env := os.Getenv("LS_COLORS"); env != "" {
|
||||
return parseColorsGNU(env)
|
||||
return parseStylesGNU(env)
|
||||
}
|
||||
|
||||
if env := os.Getenv("LSCOLORS"); env != "" {
|
||||
return parseColorsBSD(env)
|
||||
return parseStylesBSD(env)
|
||||
}
|
||||
|
||||
// default values from dircolors with removed background colors
|
||||
@@ -73,10 +43,10 @@ func parseColors() colorMap {
|
||||
"ex=01;32",
|
||||
}
|
||||
|
||||
return parseColorsGNU(strings.Join(defaultColors, ":"))
|
||||
return parseStylesGNU(strings.Join(defaultColors, ":"))
|
||||
}
|
||||
|
||||
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) {
|
||||
func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
var nums []int
|
||||
@@ -93,43 +63,63 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
|
||||
nums = append(nums, n)
|
||||
}
|
||||
|
||||
// ECMA-48 details the standard
|
||||
for i := 0; i < len(nums); i++ {
|
||||
n := nums[i]
|
||||
switch {
|
||||
case n == 38 && i+2 < len(nums) && nums[i+1] == 5:
|
||||
fg &= gAnsiColorResetMask
|
||||
fg |= termbox.Attribute(nums[i+2] + 1)
|
||||
i += 2
|
||||
continue
|
||||
case n == 48 && i+2 < len(nums) && nums[i+1] == 5:
|
||||
bg = termbox.Attribute(nums[i+2] + 1)
|
||||
i += 2
|
||||
continue
|
||||
}
|
||||
attr, ok := gAnsiCodes[n]
|
||||
if !ok {
|
||||
log.Printf("unknown ansi code: %d", n)
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case n == 0:
|
||||
fg, bg = attr, attr
|
||||
case n == 1 || n == 4 || n == 7:
|
||||
fg |= attr
|
||||
case 30 <= n && n <= 37:
|
||||
fg &= gAnsiColorResetMask
|
||||
fg |= attr
|
||||
case 40 <= n && n <= 47:
|
||||
bg = attr
|
||||
st = tcell.StyleDefault
|
||||
case n == 1:
|
||||
st = st.Bold(true)
|
||||
case n == 2:
|
||||
st = st.Dim(true)
|
||||
case n == 4:
|
||||
st = st.Underline(true)
|
||||
case n == 5 || n == 6:
|
||||
st = st.Blink(true)
|
||||
case n == 7:
|
||||
st = st.Reverse(true)
|
||||
case n >= 30 && n <= 37:
|
||||
st = st.Foreground(tcell.Color(n - 30))
|
||||
case n == 38:
|
||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
||||
st = st.Foreground(tcell.Color(nums[i+2]))
|
||||
i += 2
|
||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
||||
st = st.Foreground(tcell.NewRGBColor(
|
||||
int32(nums[i+2]),
|
||||
int32(nums[i+3]),
|
||||
int32(nums[i+4])))
|
||||
i += 4
|
||||
} else {
|
||||
log.Printf("unknown ansi code or incorrect form: %d", n)
|
||||
}
|
||||
case n >= 40 && n <= 47:
|
||||
st = st.Background(tcell.Color(n - 40))
|
||||
case n == 48:
|
||||
if i+3 <= len(nums) && nums[i+1] == 5 {
|
||||
st = st.Background(tcell.Color(nums[i+2]))
|
||||
i += 2
|
||||
} else if i+5 <= len(nums) && nums[i+1] == 2 {
|
||||
st = st.Background(tcell.NewRGBColor(
|
||||
int32(nums[i+2]),
|
||||
int32(nums[i+3]),
|
||||
int32(nums[i+4])))
|
||||
i += 4
|
||||
} else {
|
||||
log.Printf("unknown ansi code or incorrect form: %d", n)
|
||||
}
|
||||
default:
|
||||
log.Printf("unknown ansi code: %d", n)
|
||||
}
|
||||
}
|
||||
|
||||
return fg, bg
|
||||
return st
|
||||
}
|
||||
|
||||
// This function parses $LS_COLORS environment variable.
|
||||
func parseColorsGNU(env string) colorMap {
|
||||
colors := make(colorMap)
|
||||
func parseStylesGNU(env string) styleMap {
|
||||
styles := make(styleMap)
|
||||
|
||||
entries := strings.Split(env, ":")
|
||||
for _, entry := range entries {
|
||||
@@ -139,66 +129,69 @@ func parseColorsGNU(env string) colorMap {
|
||||
pair := strings.Split(entry, "=")
|
||||
if len(pair) != 2 {
|
||||
log.Printf("invalid $LS_COLORS entry: %s", entry)
|
||||
return colors
|
||||
return styles
|
||||
}
|
||||
key, val := pair[0], pair[1]
|
||||
fg, bg := applyAnsiCodes(val, termbox.ColorDefault, termbox.ColorDefault)
|
||||
colors[key] = colorEntry{fg: fg, bg: bg}
|
||||
styles[key] = applyAnsiCodes(val, tcell.StyleDefault)
|
||||
}
|
||||
|
||||
return colors
|
||||
return styles
|
||||
}
|
||||
|
||||
// This function parses $LSCOLORS environment variable.
|
||||
func parseColorsBSD(env string) colorMap {
|
||||
colors := make(colorMap)
|
||||
func parseStylesBSD(env string) styleMap {
|
||||
styles := make(styleMap)
|
||||
|
||||
if len(env) != 22 {
|
||||
log.Printf("invalid $LSCOLORS variable: %s", env)
|
||||
return colors
|
||||
return styles
|
||||
}
|
||||
|
||||
colorNames := []string{"di", "ln", "so", "pi", "ex", "bd", "cd", "su", "sg", "tw", "ow"}
|
||||
colorCodes := map[byte]termbox.Attribute{
|
||||
'a': termbox.ColorBlack,
|
||||
'b': termbox.ColorRed,
|
||||
'c': termbox.ColorGreen,
|
||||
'd': termbox.ColorYellow, // brown
|
||||
'e': termbox.ColorBlue,
|
||||
'f': termbox.ColorMagenta,
|
||||
'g': termbox.ColorCyan,
|
||||
'h': termbox.ColorWhite, // light grey
|
||||
'A': termbox.AttrBold | termbox.ColorBlack,
|
||||
'B': termbox.AttrBold | termbox.ColorRed,
|
||||
'C': termbox.AttrBold | termbox.ColorGreen,
|
||||
'D': termbox.AttrBold | termbox.ColorYellow, // brown
|
||||
'E': termbox.AttrBold | termbox.ColorBlue,
|
||||
'F': termbox.AttrBold | termbox.ColorMagenta,
|
||||
'G': termbox.AttrBold | termbox.ColorCyan,
|
||||
'H': termbox.AttrBold | termbox.ColorWhite, // light grey
|
||||
'x': termbox.ColorDefault,
|
||||
}
|
||||
|
||||
getColor := func(r byte) termbox.Attribute {
|
||||
if color, ok := colorCodes[r]; ok {
|
||||
return color
|
||||
getStyle := func(r1, r2 byte) tcell.Style {
|
||||
st := tcell.StyleDefault
|
||||
|
||||
switch {
|
||||
case r1 == 'x':
|
||||
st = st.Foreground(tcell.ColorDefault)
|
||||
case 'A' <= r1 && r1 <= 'H':
|
||||
st = st.Foreground(tcell.Color(r1 - 'A')).Bold(true)
|
||||
case 'a' <= r1 && r1 <= 'h':
|
||||
st = st.Foreground(tcell.Color(r1 - 'a'))
|
||||
default:
|
||||
log.Printf("invalid $LSCOLORS entry: %c", r1)
|
||||
return tcell.StyleDefault
|
||||
}
|
||||
|
||||
log.Printf("invalid $LSCOLORS entry: %c", r)
|
||||
return termbox.ColorDefault
|
||||
switch {
|
||||
case r2 == 'x':
|
||||
st = st.Background(tcell.ColorDefault)
|
||||
case 'a' <= r2 && r2 <= 'h':
|
||||
st = st.Background(tcell.Color(r2 - 'a'))
|
||||
default:
|
||||
log.Printf("invalid $LSCOLORS entry: %c", r2)
|
||||
return tcell.StyleDefault
|
||||
}
|
||||
|
||||
return st
|
||||
}
|
||||
|
||||
for i, key := range colorNames {
|
||||
colors[key] = colorEntry{fg: getColor(env[i*2]), bg: getColor(env[i*2+1])}
|
||||
styles[key] = getStyle(env[i*2], env[i*2+1])
|
||||
}
|
||||
|
||||
return colors
|
||||
return styles
|
||||
}
|
||||
|
||||
func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
func (cm styleMap) get(f *file) tcell.Style {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
@@ -207,10 +200,6 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
@@ -230,12 +219,12 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
}
|
||||
|
||||
if val, ok := cm[key]; ok {
|
||||
return val.fg, val.bg
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := cm["fi"]; ok {
|
||||
return val.fg, val.bg
|
||||
return val
|
||||
}
|
||||
|
||||
return termbox.ColorDefault, termbox.ColorDefault
|
||||
return tcell.StyleDefault
|
||||
}
|
||||
+51
-47
@@ -3,75 +3,79 @@ package main
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
"github.com/gdamore/tcell"
|
||||
)
|
||||
|
||||
func TestApplyAnsiCodes(t *testing.T) {
|
||||
none := termbox.ColorDefault
|
||||
none := tcell.StyleDefault
|
||||
|
||||
tests := []struct {
|
||||
s string
|
||||
fg termbox.Attribute
|
||||
bg termbox.Attribute
|
||||
fgExp termbox.Attribute
|
||||
bgExp termbox.Attribute
|
||||
st tcell.Style
|
||||
stExp tcell.Style
|
||||
}{
|
||||
{"", none, none, none, none},
|
||||
{"", termbox.ColorRed, termbox.ColorRed, none, none},
|
||||
{"", termbox.AttrBold, none, none, none},
|
||||
{"", termbox.ColorRed | termbox.AttrBold, none, none, none},
|
||||
{"", none, none},
|
||||
{"", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
|
||||
{"", none.Bold(true), none},
|
||||
{"", none.Foreground(tcell.ColorMaroon).Bold(true), none},
|
||||
|
||||
{"0", none, none, none, none},
|
||||
{"0", termbox.ColorRed, termbox.ColorRed, none, none},
|
||||
{"0", termbox.AttrBold, none, none, none},
|
||||
{"0", termbox.ColorRed | termbox.AttrBold, none, none, none},
|
||||
{"0", none, none},
|
||||
{"0", none.Foreground(tcell.ColorMaroon).Background(tcell.ColorMaroon), none},
|
||||
{"0", none.Bold(true), none},
|
||||
{"0", none.Foreground(tcell.ColorMaroon).Bold(true), none},
|
||||
|
||||
{"1", none, none, termbox.AttrBold, none},
|
||||
{"4", none, none, termbox.AttrUnderline, none},
|
||||
{"7", none, none, termbox.AttrReverse, none},
|
||||
{"1", none, none.Bold(true)},
|
||||
{"4", none, none.Underline(true)},
|
||||
{"7", none, none.Reverse(true)},
|
||||
|
||||
{"1", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"4", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrUnderline, none},
|
||||
{"7", termbox.ColorRed, none, termbox.ColorRed | termbox.AttrReverse, none},
|
||||
{"1", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
{"4", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Underline(true)},
|
||||
{"7", none.Foreground(tcell.ColorMaroon), none.Foreground(tcell.ColorMaroon).Reverse(true)},
|
||||
|
||||
{"4", termbox.AttrBold, none, termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
{"4", termbox.ColorRed | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
{"4", none.Bold(true), none.Bold(true).Underline(true)},
|
||||
{"4", none.Foreground(tcell.ColorMaroon).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true).Underline(true)},
|
||||
|
||||
{"31", none, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"31", none, none.Foreground(tcell.ColorMaroon)},
|
||||
{"31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
|
||||
{"31", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
|
||||
{"41", none, none, none, termbox.ColorRed},
|
||||
{"41", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
{"41", none, none.Background(tcell.ColorMaroon)},
|
||||
{"41", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
|
||||
|
||||
{"1;31", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;31", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;31", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
{"1;31", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
|
||||
{"38;5;0", none, none, termbox.ColorBlack, none},
|
||||
{"38;5;1", none, none, termbox.ColorRed, none},
|
||||
{"38;5;8", none, none, termbox.Attribute(9), none},
|
||||
{"38;5;16", none, none, termbox.Attribute(17), none},
|
||||
{"38;5;232", none, none, termbox.Attribute(233), none},
|
||||
{"38;5;0", none, none.Foreground(tcell.ColorBlack)},
|
||||
{"38;5;1", none, none.Foreground(tcell.ColorMaroon)},
|
||||
{"38;5;8", none, none.Foreground(tcell.Color(8))},
|
||||
{"38;5;16", none, none.Foreground(tcell.Color(16))},
|
||||
{"38;5;232", none, none.Foreground(tcell.Color(232))},
|
||||
|
||||
{"38;5;1", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"38;5;1", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon)},
|
||||
{"38;5;1", none.Foreground(tcell.ColorGreen).Bold(true), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
|
||||
{"48;5;0", none, none, none, termbox.ColorBlack},
|
||||
{"48;5;1", none, none, none, termbox.ColorRed},
|
||||
{"48;5;8", none, none, none, termbox.Attribute(9)},
|
||||
{"48;5;16", none, none, none, termbox.Attribute(17)},
|
||||
{"48;5;232", none, none, none, termbox.Attribute(233)},
|
||||
{"48;5;0", none, none.Background(tcell.ColorBlack)},
|
||||
{"48;5;1", none, none.Background(tcell.ColorMaroon)},
|
||||
{"48;5;8", none, none.Background(tcell.Color(8))},
|
||||
{"48;5;16", none, none.Background(tcell.Color(16))},
|
||||
{"48;5;232", none, none.Background(tcell.Color(232))},
|
||||
|
||||
{"48;5;1", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
{"48;5;1", none.Background(tcell.ColorGreen), none.Background(tcell.ColorMaroon)},
|
||||
|
||||
{"1;38;5;1", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;38;5;1", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;38;5;1", none, none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
{"1;38;5;1", none.Foreground(tcell.ColorGreen), none.Foreground(tcell.ColorMaroon).Bold(true)},
|
||||
|
||||
{"38;2;5;102;8", none, none.Foreground(tcell.NewRGBColor(5, 102, 8))},
|
||||
{"48;2;0;48;143", none, none.Background(tcell.NewRGBColor(0, 48, 143))},
|
||||
|
||||
// Fixes color construction issue: https://github.com/gokcehan/lf/pull/439#issuecomment-674409446
|
||||
{"38;5;34;1", none, none.Foreground(tcell.Color(34)).Bold(true)},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
if fgGot, bgGot := applyAnsiCodes(test.s, test.fg, test.bg); fgGot != test.fgExp || bgGot != test.bgExp {
|
||||
t.Errorf("at input '%s' with '%d' and '%d' expected '%d' and '%d' but got '%d' and '%d'",
|
||||
test.s, test.fg, test.bg, test.fgExp, test.bgExp, fgGot, bgGot)
|
||||
if stGot := applyAnsiCodes(test.s, test.st); stGot != test.stExp {
|
||||
t.Errorf("at input '%s' with '%d' expected '%d' but got '%d'",
|
||||
test.s, test.st, test.stExp, stGot)
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
-20
@@ -31,13 +31,11 @@ var (
|
||||
"copy",
|
||||
"cut",
|
||||
"paste",
|
||||
"delete",
|
||||
"clear",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"read",
|
||||
"rename",
|
||||
"shell",
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
@@ -51,22 +49,27 @@ var (
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"mark-save",
|
||||
"mark-remove",
|
||||
"mark-load",
|
||||
"draw",
|
||||
"load",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"source",
|
||||
"push",
|
||||
"delete",
|
||||
}
|
||||
|
||||
gOptWords = []string{
|
||||
"anchorfind",
|
||||
"noanchorfind",
|
||||
"anchorfind!",
|
||||
"color256",
|
||||
"nocolor256",
|
||||
"color256!",
|
||||
"dircounts",
|
||||
"nodircounts",
|
||||
"dircounts!",
|
||||
@@ -82,6 +85,9 @@ var (
|
||||
"hidden",
|
||||
"nohidden",
|
||||
"hidden!",
|
||||
"icons",
|
||||
"noicons",
|
||||
"icons!",
|
||||
"ignorecase",
|
||||
"noignorecase",
|
||||
"ignorecase!",
|
||||
@@ -91,9 +97,15 @@ var (
|
||||
"incsearch",
|
||||
"noincsearch",
|
||||
"incsearch!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
"preview",
|
||||
"nopreview",
|
||||
"preview!",
|
||||
"relativenumber",
|
||||
"norelativenumber",
|
||||
"relativenumber!",
|
||||
"reverse",
|
||||
"noreverse",
|
||||
"reverse!",
|
||||
@@ -106,26 +118,26 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
"relativenumber",
|
||||
"norelativenumber",
|
||||
"relativenumber!",
|
||||
"wrapscroll",
|
||||
"nowrapscroll",
|
||||
"wrapscroll!",
|
||||
"findlen",
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"errorfmt",
|
||||
"filesep",
|
||||
"hiddenfiles",
|
||||
"ifs",
|
||||
"info",
|
||||
"previewer",
|
||||
"promptfmt",
|
||||
"ratios",
|
||||
"shell",
|
||||
"shellopts",
|
||||
"sortby",
|
||||
"timefmt",
|
||||
"ratios",
|
||||
"info",
|
||||
"shellopts",
|
||||
"truncatechar",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -211,7 +223,7 @@ func matchExec(s string) (matches []string, longest string) {
|
||||
}
|
||||
|
||||
func matchFile(s string) (matches []string, longest string) {
|
||||
dir := strings.Replace(s, "~", gUser.HomeDir, -1)
|
||||
dir := replaceTilde(s)
|
||||
|
||||
if !filepath.IsAbs(dir) {
|
||||
wd, err := os.Getwd()
|
||||
@@ -243,13 +255,13 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
|
||||
name := f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += string(filepath.Separator)
|
||||
item += escape(string(filepath.Separator))
|
||||
}
|
||||
matches = append(matches, item)
|
||||
|
||||
@@ -259,7 +271,7 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + string(filepath.Separator)
|
||||
longest = name + escape(string(filepath.Separator))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,6 +331,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)
|
||||
@@ -331,7 +381,7 @@ func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
longestAcc = []rune(longest)
|
||||
default:
|
||||
matches, longest = matchFile(f[len(f)-1])
|
||||
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...)
|
||||
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], []rune(longest)...)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -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.Lstat(dst)
|
||||
if !os.IsNotExist(err) {
|
||||
var newPath string
|
||||
for i := 1; !os.IsNotExist(err); i++ {
|
||||
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||
_, err = os.Lstat(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
|
||||
}
|
||||
+10
-17
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var normMap map[rune]rune
|
||||
@@ -14,46 +14,39 @@ func init() {
|
||||
appendTransliterate(
|
||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||
true,
|
||||
)
|
||||
|
||||
// Vietnamese
|
||||
appendTransliterate(
|
||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||
true,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func appendTransliterate(base, norm string, uppercase bool) {
|
||||
func appendTransliterate(base, norm string) {
|
||||
normRunes := []rune(norm)
|
||||
baseRunes := []rune(base)
|
||||
|
||||
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 {
|
||||
normMap[baseRune] = normRunes[i]
|
||||
}
|
||||
for i := 0; i < lenBase; i++ {
|
||||
normMap[baseRunes[i]] = normRunes[i]
|
||||
|
||||
if uppercase {
|
||||
upperBase := strings.ToUpper(base)
|
||||
upperNorm := strings.ToUpper(norm)
|
||||
normRune := []rune(upperNorm)
|
||||
for i, baseRune := range []rune(upperBase) {
|
||||
normMap[baseRune] = normRune[i]
|
||||
}
|
||||
baseUpper := unicode.ToUpper(baseRunes[i])
|
||||
normUpper := unicode.ToUpper(normRunes[i])
|
||||
|
||||
normMap[baseUpper] = normUpper
|
||||
}
|
||||
}
|
||||
|
||||
// Remove diacritics and make lowercase.
|
||||
func removeDiacritics(baseString string) string {
|
||||
var normalizedRunes []rune
|
||||
for _, baseRune := range []rune(baseString) {
|
||||
for _, baseRune := range baseString {
|
||||
if normRune, ok := normMap[baseRune]; ok {
|
||||
normalizedRunes = append(normalizedRunes, normRune)
|
||||
} else {
|
||||
|
||||
@@ -12,147 +12,145 @@ at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command
|
||||
|
||||
You can run 'lf -help' to see descriptions of command line options.
|
||||
|
||||
Reference
|
||||
Quick Reference
|
||||
|
||||
The following commands are provided by lf with default keybindings:
|
||||
The following commands are provided by lf:
|
||||
|
||||
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 "'")
|
||||
quit (default 'q')
|
||||
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>')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
glob-select
|
||||
glob-unselect
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
sync
|
||||
draw
|
||||
redraw (default '<c-l>')
|
||||
load
|
||||
reload (default '<c-r>')
|
||||
echo
|
||||
echomsg
|
||||
echoerr
|
||||
cd
|
||||
select
|
||||
delete (modal)
|
||||
rename (modal) (default 'r')
|
||||
source
|
||||
push
|
||||
read (modal) (default ':')
|
||||
shell (modal) (default '$')
|
||||
shell-pipe (modal) (default '%')
|
||||
shell-wait (modal) (default '!')
|
||||
shell-async (modal) (default '&')
|
||||
find (modal) (default 'f')
|
||||
find-back (modal) (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (modal) (default '/')
|
||||
search-back (modal) (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (modal) (default 'm')
|
||||
mark-load (modal) (default "'")
|
||||
mark-remove (modal) (default `"`)
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
The following command line commands are provided by lf:
|
||||
|
||||
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)
|
||||
|
||||
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-interrupt (default '<c-c>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
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 (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<backspace>' and '<backspace2>')
|
||||
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-transpose-word (default '<a-t>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
|
||||
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 bool (default on)
|
||||
dircounts bool (default off)
|
||||
dirfirst bool (default on)
|
||||
drawbox bool (default off)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
findlen int (default 1)
|
||||
globsearch bool (default off)
|
||||
hidden bool (default off)
|
||||
hiddenfiles []string (default '.*')
|
||||
icons bool (default off)
|
||||
ifs string (default '')
|
||||
ignorecase bool (default on)
|
||||
ignoredia bool (default off)
|
||||
incsearch bool (default off)
|
||||
info []string (default '')
|
||||
number bool (default off)
|
||||
period int (default 0)
|
||||
preview bool (default on)
|
||||
previewer string (default '')
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||
ratios []int (default '1:2:3')
|
||||
relativenumber bool (default off)
|
||||
reverse bool (default off)
|
||||
scrolloff int (default 0)
|
||||
shell string (default 'sh' for unix and 'cmd' for windows)
|
||||
shellopts []string (default '')
|
||||
smartcase bool (default on)
|
||||
smartdia bool (default off)
|
||||
sortby string (default 'natural')
|
||||
tabstop int (default 8)
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
truncatechar string (default '~')
|
||||
wrapscan bool (default on)
|
||||
wrapscroll bool (default off)
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
The following environment variables are exported for shell commands:
|
||||
|
||||
$f current file
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
f
|
||||
fs
|
||||
fx
|
||||
id
|
||||
LF_LEVEL
|
||||
OPENER
|
||||
EDITOR
|
||||
PAGER
|
||||
SHELL
|
||||
|
||||
The following variables are set to the corresponding values:
|
||||
The following commands/keybindings are provided by default:
|
||||
|
||||
$LF_LEVEL current nesting level
|
||||
|
||||
The following default values are set to the environmental variables on unix
|
||||
when they are not set or empty:
|
||||
|
||||
$OPENER open # macos
|
||||
$OPENER xdg-open # others
|
||||
$EDITOR vi
|
||||
$PAGER less
|
||||
$SHELL sh
|
||||
|
||||
The following default values are set to the environmental variables on windows
|
||||
when they are not set or empty:
|
||||
|
||||
%OPENER% start
|
||||
%EDITOR% notepad
|
||||
%PAGER% more
|
||||
%SHELL% cmd
|
||||
unix windows
|
||||
cmd open &$OPENER "$f" cmd open &%OPENER% %f%
|
||||
map e $$EDITOR "$f" map e $%EDITOR% %f%
|
||||
map i $$PAGER "$f" map i !%PAGER% %f%
|
||||
map w $$SHELL map w $%SHELL%
|
||||
|
||||
The following additional keybindings are provided by default:
|
||||
|
||||
@@ -165,13 +163,11 @@ The following additional keybindings are provided by default:
|
||||
map sn :set sortby natural; set info
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
map sa :set sortby atime; set info atime
|
||||
map sc :set sortby ctime; set info ctime
|
||||
map se :set sortby ext; set info
|
||||
map gh cd ~
|
||||
|
||||
The following keybindings to applications are provided by default:
|
||||
|
||||
map e $$EDITOR $f
|
||||
map i $$PAGER $f
|
||||
map w $$SHELL
|
||||
map <space> :toggle; down
|
||||
|
||||
Configuration
|
||||
|
||||
@@ -202,6 +198,507 @@ locations:
|
||||
A sample configuration file can be found at
|
||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||
|
||||
Commands
|
||||
|
||||
This section shows information about builtin commands.
|
||||
Modal commands do not take any arguments, but instead change the operation mode to read their input conveniently, and so they are meant to be assigned to keybindings.
|
||||
|
||||
quit (default 'q')
|
||||
|
||||
Quit lf and return to the shell.
|
||||
|
||||
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>')
|
||||
|
||||
Move the current file selection upwards/downwards by one/half a page/full page.
|
||||
|
||||
updir (default 'h' and '<left>')
|
||||
|
||||
Change the current working directory to the parent directory.
|
||||
|
||||
open (default 'l' and '<right>')
|
||||
|
||||
If the current file is a directory, then change the current directory to it, otherwise, execute the 'open' command.
|
||||
A default 'open' command is provided to call the default system opener asynchronously with the current file as the argument.
|
||||
A custom 'open' command can be defined to override this default.
|
||||
|
||||
(See also 'OPENER' variable and 'Opening Files' section)
|
||||
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
|
||||
Move the current file selection to the top/bottom of the directory.
|
||||
|
||||
toggle
|
||||
|
||||
Toggle the selection of the current file or files given as arguments.
|
||||
|
||||
invert (default 'v')
|
||||
|
||||
Reverse the selection of all files in the current directory (i.e. 'toggle' all files).
|
||||
Selections in other directories are not effected by this command.
|
||||
You can define a new command to select all files in the directory by combining 'invert' with 'unselect' (i.e. `cmd select-all :unselect; invert`), though this will also remove selections in other directories.
|
||||
|
||||
unselect (default 'u')
|
||||
|
||||
Remove the selection of all files in all directories.
|
||||
|
||||
glob-select
|
||||
|
||||
Select files that match the given glob.
|
||||
|
||||
glob-unselect
|
||||
|
||||
Unselect files that match the given glob.
|
||||
|
||||
copy (default 'y')
|
||||
|
||||
If there are no selections, save the path of the current file to the copy buffer, otherwise, copy the paths of selected files.
|
||||
|
||||
cut (default 'd')
|
||||
|
||||
If there are no selections, save the path of the current file to the cut buffer, otherwise, copy the paths of selected files.
|
||||
|
||||
paste (default 'p')
|
||||
|
||||
Copy/Move files in copy/cut buffer to the current working directory.
|
||||
|
||||
clear (default 'c')
|
||||
|
||||
Clear file paths in copy/cut buffer.
|
||||
|
||||
sync
|
||||
|
||||
Synchronize copied/cut files with server.
|
||||
This command is automatically called when required.
|
||||
|
||||
draw
|
||||
|
||||
Draw the screen.
|
||||
This command is automatically called when required.
|
||||
|
||||
redraw (default '<c-l>')
|
||||
|
||||
Synchronize the terminal and redraw the screen.
|
||||
|
||||
load
|
||||
|
||||
Load modified files and directories.
|
||||
This command is automatically called when required.
|
||||
|
||||
reload (default '<c-r>')
|
||||
|
||||
Flush the cache and reload all files and directories.
|
||||
|
||||
echo
|
||||
|
||||
Print given arguments to the message line at the bottom.
|
||||
|
||||
echomsg
|
||||
|
||||
Print given arguments to the message line at the bottom and also to the log file.
|
||||
|
||||
echoerr
|
||||
|
||||
Print given arguments to the message line at the bottom in red color and also to the log file.
|
||||
|
||||
cd
|
||||
|
||||
Change the working directory to the given argument.
|
||||
|
||||
select
|
||||
|
||||
Change the current file selection to the given argument.
|
||||
|
||||
delete (modal)
|
||||
|
||||
Remove the current file or selected file(s).
|
||||
|
||||
rename (modal) (default 'r')
|
||||
|
||||
Rename the current file using the builtin method.
|
||||
A custom 'rename' command can be defined to override this default.
|
||||
|
||||
source
|
||||
|
||||
Read the configuration file given in the argument.
|
||||
|
||||
push
|
||||
|
||||
Simulate key pushes given in the argument.
|
||||
|
||||
read (modal) (default ':')
|
||||
|
||||
Read a command to evaluate.
|
||||
|
||||
shell (modal) (default '$')
|
||||
|
||||
Read a shell command to execute.
|
||||
|
||||
(See also 'Prefixes' and 'Shell Commands' sections)
|
||||
|
||||
shell-pipe (modal) (default '%')
|
||||
|
||||
Read a shell command to execute piping its standard I/O to the bottom statline.
|
||||
|
||||
(See also 'Prefixes' and 'Piping Shell Commands' sections)
|
||||
|
||||
shell-wait (modal) (default '!')
|
||||
|
||||
Read a shell command to execute and wait for a key press in the end.
|
||||
|
||||
(See also 'Prefixes' and 'Waiting Shell Commands' sections)
|
||||
|
||||
shell-async (modal) (default '&')
|
||||
|
||||
Read a shell command to execute synchronously without standard I/O.
|
||||
|
||||
find (modal) (default 'f')
|
||||
find-back (modal) (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
|
||||
Read key(s) to find the appropriate file name match in the forward/backward direction and jump to the next/previous match.
|
||||
|
||||
(See also 'anchorfind', 'findlen', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
|
||||
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
|
||||
Read a pattern to search for a file name match in the forward/backward direction and jump to the next/previous match.
|
||||
|
||||
(See also 'globsearch', 'incsearch', 'wrapscan', 'ignorecase', 'smartcase', 'ignoredia', and 'smartdia' options and 'Searching Files' section)
|
||||
|
||||
mark-save (modal) (default 'm')
|
||||
|
||||
Save the current directory as a bookmark assigned to the given key.
|
||||
|
||||
mark-load (modal) (default "'")
|
||||
|
||||
Change the current directory to the bookmark assigned to the given key.
|
||||
A special bookmark "'" holds the previous directory after a 'mark-load', 'cd', or 'select' command.
|
||||
|
||||
mark-remove (modal) (default `"`)
|
||||
|
||||
Remove a bookmark assigned to the given key.
|
||||
|
||||
Command Line Commands
|
||||
|
||||
This section shows information about command line commands.
|
||||
These should be mostly compatible with readline keybindings.
|
||||
A character refers to a unicode code point, a word consists of letters and digits, and a unix word consists of any non-blank characters.
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
|
||||
Quit command line mode and return to normal mode.
|
||||
|
||||
cmd-complete (default '<tab>')
|
||||
|
||||
Autocomplete the current word.
|
||||
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
|
||||
Execute the current line.
|
||||
|
||||
cmd-interrupt (default '<c-c>')
|
||||
|
||||
Interrupt the current shell-pipe command and return to the normal mode.
|
||||
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
|
||||
Go to next/previous item in the history.
|
||||
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
|
||||
Move the cursor to the left/right.
|
||||
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
|
||||
Move the cursor to the beginning/end of line.
|
||||
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<backspace>' and '<backspace2>')
|
||||
|
||||
Delete the next character in forward/backward direction.
|
||||
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
|
||||
Delete everything up to the beginning/end of line.
|
||||
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
|
||||
Delete the previous unix word.
|
||||
|
||||
cmd-yank (default '<c-y>')
|
||||
|
||||
Paste the buffer content containing the last deleted item.
|
||||
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
Transpose the positions of last two characters/words.
|
||||
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
|
||||
Move the cursor by one word in forward/backward direction.
|
||||
|
||||
cmd-delete-word (default '<a-d>')
|
||||
|
||||
Delete the next word in forward direction.
|
||||
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
|
||||
Capitalize/uppercase/lowercase the current word and jump to the next word.
|
||||
|
||||
Options
|
||||
|
||||
This section shows information about options to customize the behavior.
|
||||
Character ':' is used as the separator for list options '[]int' and '[]string'.
|
||||
|
||||
anchorfind bool (default on)
|
||||
|
||||
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
|
||||
|
||||
dircounts bool (default off)
|
||||
|
||||
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
|
||||
The former needs to be calculated by reading the directory and counting the items inside.
|
||||
The latter is directly provided by the operating system and it does not require any calculation, though it is non-intuitive and it can often be misleading.
|
||||
This option is disabled by default for performance reasons.
|
||||
This option only has an effect when 'info' has a 'size' field and the pane is wide enough to show the information.
|
||||
A thousand items are counted per directory at most, and bigger directories are shown as '999+'.
|
||||
|
||||
dirfirst bool (default on)
|
||||
|
||||
Show directories first above regular files.
|
||||
|
||||
drawbox bool (default off)
|
||||
|
||||
Draw boxes around panes with box drawing characters.
|
||||
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
|
||||
Format string of error messages shown in the bottom message line.
|
||||
|
||||
filesep string (default "\n")
|
||||
|
||||
File separator used in environment variables 'fs' and 'fx'.
|
||||
|
||||
findlen int (default 1)
|
||||
|
||||
Number of characters prompted for the find command.
|
||||
When this value is set to 0, find command prompts until there is only a single match left.
|
||||
|
||||
globsearch bool (default off)
|
||||
|
||||
When this option is enabled, search command patterns are considered as globs, otherwise they are literals.
|
||||
With globbing, '*' matches any sequence, '?' matches any character, and '[...]' or '[^...] matches character sets or ranges.
|
||||
Otherwise, these characters are interpreted as they are.
|
||||
|
||||
hidden bool (default off)
|
||||
|
||||
Show hidden files.
|
||||
On unix systems, hidden files are determined by the value of 'hiddenfiles'.
|
||||
On windows, only files with hidden attributes are considered hidden files.
|
||||
|
||||
hiddenfiles []string (default '.*')
|
||||
|
||||
List of hidden file glob patterns.
|
||||
Patterns can be given as relative or absolute paths.
|
||||
Globbing supports the usual special characters, '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges.
|
||||
In addition, if a pattern starts with '!', then its matches are excluded from hidden files.
|
||||
|
||||
icons bool (default off)
|
||||
|
||||
Show icons before each item in the list.
|
||||
By default, only two icons, 🗀 (U+1F5C0) and 🗎 (U+1F5CE), are used for directories and files respectively, as they are supported in the unicode standard.
|
||||
Icons can be configured with an environment variable named 'LF_ICONS'.
|
||||
The syntax of this variable is similar to 'LS_COLORS'.
|
||||
See the wiki page for an example icon configuration.
|
||||
|
||||
ifs string (default '')
|
||||
|
||||
Sets 'IFS' variable in shell commands.
|
||||
It works by adding the assignment to the beginning of the command string as 'IFS='...'; ...'.
|
||||
The reason is that 'IFS' variable is not inherited by the shell for security reasons.
|
||||
This method assumes a POSIX shell syntax and so it can fail for non-POSIX shells.
|
||||
This option has no effect when the value is left empty.
|
||||
This option does not have any effect on windows.
|
||||
|
||||
ignorecase bool (default on)
|
||||
|
||||
Ignore case in search patterns.
|
||||
|
||||
ignoredia bool (default off)
|
||||
|
||||
Ignore diacritics in search patterns.
|
||||
|
||||
incsearch bool (default off)
|
||||
|
||||
Jump to the first match after each keystroke during searching.
|
||||
|
||||
info []string (default '')
|
||||
|
||||
List of information shown for directory items at the right side of pane.
|
||||
Currently supported information types are 'size', 'time', 'atime', and 'ctime'.
|
||||
Information is only shown when the pane width is more than twice the width of information.
|
||||
|
||||
number bool (default off)
|
||||
|
||||
Show the position number for directory items at the left side of pane.
|
||||
When 'relativenumber' is enabled, only the current line shows the absolute position and relative positions are shown for the rest.
|
||||
|
||||
period int (default 0)
|
||||
|
||||
Set the interval in seconds for periodic checks of directory updates.
|
||||
This works by periodically calling the 'load' command.
|
||||
Note that directories are already updated automatically in many cases.
|
||||
This option can be useful when there is an external process changing the displayed directory and you are not doing anything in lf.
|
||||
Periodic checks are disabled when the value of this option is set to zero.
|
||||
|
||||
preview bool (default on)
|
||||
|
||||
Show previews of files and directories at the right most pane.
|
||||
If the file has more lines than the preview pane, rest of the lines are not read.
|
||||
Files containing the null character (U+0000) in the read portion are considered binary files and displayed as 'binary'.
|
||||
|
||||
previewer string (default '') (not filtered if empty)
|
||||
|
||||
Set the path of a previewer file to filter the content of regular files for previewing.
|
||||
The file should be executable.
|
||||
Two arguments are passed to the file, first is the current file name, and second is the height of preview pane.
|
||||
SIGPIPE signal is sent when enough lines are read.
|
||||
Preview filtering is disabled and files are displayed as they are when the value of this option is left empty.
|
||||
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||
|
||||
Format string of the prompt shown in the top line.
|
||||
Special expansions are provided, '%u' as the user name, '%h' as the host name, '%w' as the working directory, and '%f' as the file name.
|
||||
Home folder is shown as '~' in the working directory expansion.
|
||||
Directory names are automatically shortened to a single character starting from the left most parent when the prompt does not fit to the screen.
|
||||
|
||||
ratios []int (default '1:2:3')
|
||||
|
||||
List of ratios of pane widths.
|
||||
Number of items in the list determines the number of panes in the ui.
|
||||
When 'preview' option is enabled, the right most number is used for the width of preview pane.
|
||||
|
||||
relativenumber bool (default off)
|
||||
|
||||
Show the position number relative to the current line.
|
||||
When 'number' is enabled, current line shows the absolute position, otherwise nothing is shown.
|
||||
|
||||
reverse bool (default off)
|
||||
|
||||
Reverse the direction of sort.
|
||||
|
||||
scrolloff int (default 0)
|
||||
|
||||
Minimum number of offset lines shown at all times in the top and the bottom of the screen when scrolling.
|
||||
The current line is kept in the middle when this option is set to a large value that is bigger than the half of number of lines.
|
||||
A smaller offset can be used when the current file is close to the beginning or end of the list to show the maximum number of items.
|
||||
|
||||
shell string (default 'sh' for unix and 'cmd' for windows)
|
||||
|
||||
Shell executable to use for shell commands.
|
||||
Shell commands are executed as 'shell shellopts -c command -- arguments'.
|
||||
On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
|
||||
|
||||
shellopts []string (default '')
|
||||
|
||||
List of shell options to pass to the shell executable.
|
||||
|
||||
smartcase bool (default on)
|
||||
|
||||
Override 'ignorecase' option when the pattern contains an uppercase character.
|
||||
This option has no effect when 'ignorecase' is disabled.
|
||||
|
||||
smartdia bool (default off)
|
||||
|
||||
Override 'ignoredia' option when the pattern contains a character with diacritic.
|
||||
This option has no effect when 'ignoredia' is disabled.
|
||||
|
||||
sortby string (default 'natural')
|
||||
|
||||
Sort type for directories.
|
||||
Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||
|
||||
tabstop int (default 8)
|
||||
|
||||
Number of space characters to show for horizontal tabulation (U+0009) character.
|
||||
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
|
||||
Format string of the file modification time shown in the bottom line.
|
||||
|
||||
truncatechar string (default '~')
|
||||
|
||||
Truncate character shown at the end when the file name does not fit to the pane.
|
||||
|
||||
wrapscan bool (default on)
|
||||
|
||||
Searching can wrap around the file list.
|
||||
|
||||
wrapscroll bool (default off)
|
||||
|
||||
Scrolling can wrap around the file list.
|
||||
|
||||
Environment Variables
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
These are referred with a '$' prefix on POSIX shells (e.g. '$f'), between '%' characters on Windows cmd (e.g. '%f%'), and with a '$env:' prefix on Windows powershell (e.g. '$env:f').
|
||||
|
||||
f
|
||||
|
||||
Current file selection as a full path.
|
||||
|
||||
fs
|
||||
|
||||
Selected file(s) separated with the value of 'filesep' option as full path(s).
|
||||
|
||||
fx
|
||||
|
||||
Selected file(s) (i.e. 'fs') if there are any selected files, otherwise current file selection (i.e. 'f').
|
||||
|
||||
id
|
||||
|
||||
Id of the running client.
|
||||
|
||||
LF_LEVEL
|
||||
|
||||
The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.
|
||||
You can add the value of this variable to your shell prompt to make it clear that your shell runs inside lf.
|
||||
For example, with POSIX shells, you can use '[ -n "$LF_LEVEL" ] && PS1="$PS1""(lf level: $LF_LEVEL) "' in your shell configuration file (e.g. '~/.bashrc').
|
||||
|
||||
OPENER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
|
||||
EDITOR
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'vi' on unix, 'notepad' in Windows.
|
||||
|
||||
PAGER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'less' on unix, 'more' in Windows.
|
||||
|
||||
SHELL
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'sh' on unix, 'cmd' in Windows.
|
||||
|
||||
Prefixes
|
||||
|
||||
The following command prefixes are used by lf:
|
||||
@@ -211,14 +708,11 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file for
|
||||
read and shell commands. The difference is that prefixes are not necessary in
|
||||
the command line. Instead, different modes are provided to read corresponding
|
||||
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||
commands are only used from the command line.
|
||||
commands. These modes are mapped to the prefix keys above by default.
|
||||
|
||||
Syntax
|
||||
|
||||
@@ -517,33 +1011,47 @@ 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. For cross-device
|
||||
moving, lf falls back to copying and then deletes the original files if there
|
||||
are no errors. Operation errors are shown in the message line as well as the
|
||||
log file and they do not preemptively finish the corresponding file operation.
|
||||
|
||||
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
|
||||
@@ -565,7 +1073,16 @@ Globbing supports '*' to match any sequence, '?' to match any character, and
|
||||
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||
'incsearch' option to jump to the current match at each keystroke while typing.
|
||||
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||
'cmd-escape' to cancel the search.
|
||||
'cmd-escape' to cancel the search. Alternatively, you can also map some other
|
||||
commands with 'cmap' to accept the search and execute the command immediately
|
||||
afterwards. Possible candidates are 'up', 'down' and their variants, 'updir',
|
||||
and 'open' commands. For example, you can use arrow keys to finish the search
|
||||
with the following mappings:
|
||||
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
@@ -605,6 +1122,9 @@ You may want to use either file extensions or mime types from 'file' command:
|
||||
esac
|
||||
}}
|
||||
|
||||
You may want to use 'setsid' before your opener command to have persistent
|
||||
processes that continue to run after lf quits.
|
||||
|
||||
Following command is provided by default:
|
||||
|
||||
cmd open &$OPENER $f
|
||||
@@ -657,6 +1177,39 @@ pipe with a SIGPIPE when enough lines are read. When everything else fails, you
|
||||
can make use of the height argument to only feed the first portion of the file
|
||||
to a program for preview.
|
||||
|
||||
Changing Directory
|
||||
|
||||
lf changes the working directory of the process to the current directory so
|
||||
that shell commands always work in the displayed directory. After quitting, it
|
||||
returns to the original directory where it is first launched like all shell
|
||||
programs. If you want to stay in the current directory after quitting, you can
|
||||
use one of the example wrapper shell scripts provided in the repository.
|
||||
|
||||
There is a special command 'on-cd' that runs a shell command when it is defined
|
||||
and the directory is changed. You can define it just as you would define any
|
||||
other command:
|
||||
|
||||
cmd on-cd &{{
|
||||
# display git repository status in your prompt
|
||||
source /usr/share/git/completion/git-prompt.sh
|
||||
GIT_PS1_SHOWDIRTYSTATE=auto
|
||||
GIT_PS1_SHOWSTASHSTATE=auto
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=auto
|
||||
GIT_PS1_SHOWUPSTREAM=auto
|
||||
git=$(__git_ps1 " (%s)") || true
|
||||
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f$git\033[0m"
|
||||
lf -remote "send $id set promptfmt \"$fmt\""
|
||||
}}
|
||||
|
||||
This command runs whenever you change directory but not on startup. You can add
|
||||
an extra call to make it run on startup as well:
|
||||
|
||||
cmd on-cd &{{ # ... }}
|
||||
on-cd
|
||||
|
||||
Note that all shell commands are possible but `%` and `&` are usually more
|
||||
appropriate as `$` and `!` causes flickers and pauses respectively.
|
||||
|
||||
Colorschemes
|
||||
|
||||
lf tries to automatically adapt its colors to the environment. On startup,
|
||||
@@ -674,25 +1227,29 @@ If both of these environment variables are not set, then lf fallbacks to its
|
||||
default colorscheme. Default lf colors are taken from GNU dircolors defaults.
|
||||
These defaults use 8 basic colors and bold attribute.
|
||||
|
||||
You should also note that lf uses 8 color mode by default which uses sgr 3-bit
|
||||
color escapes (e.g. '\033[34m'). If you want to use 256 colors, you need to
|
||||
enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g.
|
||||
'\033[38;5;4m'). This option is intended to eliminate differences between
|
||||
default colors used by ls and lf since terminals may render 3-bit and 8-bit
|
||||
escapes differently even for the same color.
|
||||
It is worth noting that lf uses as many colors are advertised by your terminal's
|
||||
entry in your systems terminfo or infocmp database, if this is not present lf
|
||||
will default to an internal database. For terminals supporting 24-bit (or
|
||||
"true") color that do not have a database entry (or one that does not advertise
|
||||
all capabilities), support can be enabled by either setting the '$COLORTERM'
|
||||
variable to "truecolor" or ensuring '$TERM' is set to a value that ends with
|
||||
"-truecolor".
|
||||
|
||||
Keeping this mechanism in mind, you can configure lf colors in two different
|
||||
ways. First, you can configure 8 basic colors used by your terminal and lf
|
||||
should pick up those colors automatically. Depending on your terminal, you
|
||||
should be able to select your colors from a 24-bit palette. This is the
|
||||
recommended approach as colors used by other programs will also match each
|
||||
other.
|
||||
Keeping this in mind, you can configure lf colors in two different ways. First,
|
||||
you can configure 8 basic colors used by your terminal and lf should pick up
|
||||
those colors automatically. Depending on your terminal, you should be able to
|
||||
select your colors from a 24-bit palette. This is the recommended approach as
|
||||
colors used by other programs will also match each other.
|
||||
|
||||
Second, you can set the values of environmental variables mentioned above for
|
||||
fine grained customization. This is useful to change colors used for different
|
||||
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and
|
||||
it can be used even when GNU programs are not installed on the system. You can
|
||||
combine this second method with the first method for best results.
|
||||
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it
|
||||
can be used even when GNU programs are not installed on the system. You can
|
||||
combine this second method with the first method for best results. lf can also
|
||||
be configured to ignore your terminal theme and output colors "as they were
|
||||
intended" by translating all numbered colors into a 24-bit output that matches
|
||||
the description; this can be enabled by setting the environment variable
|
||||
'$TCELL_TRUECOLOR' to "on" (or any text except ""/nothing or "disable").
|
||||
|
||||
Lastly, you may also want to configure the colors of the prompt line to match
|
||||
the rest of the colors. Colors of the prompt line can be configured using the
|
||||
|
||||
+779
-168
File diff suppressed because it is too large.
Load diff
+12
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# For using these completions you must load it from .tcshrc
|
||||
#
|
||||
# source ~/.config/lf/lf.csh
|
||||
#
|
||||
set lf_args = "-command -cpuprofile -doc --help -last-dir-path -memprofile -remote -selection-path -server -version --version"
|
||||
|
||||
uncomplete lf
|
||||
uncomplete lfcd
|
||||
|
||||
complete lf "C/-*/(${lf_args})/"
|
||||
complete lfcd "C/-*/(${lf_args})/"
|
||||
+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'
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
#compdef lf
|
||||
|
||||
# For using these completions you must:
|
||||
# - rename this file to _lf
|
||||
# - add the containing folder to $fpath in .zshrc, like this:
|
||||
# '''
|
||||
# fpath=(/path/to/folder/containing_lf $fpath)
|
||||
# autoload -U compinit
|
||||
# compinit
|
||||
# '''
|
||||
#
|
||||
# zsh completions for 'lf'
|
||||
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||
local arguments
|
||||
|
||||
arguments=(
|
||||
'-command[command to execute on client initialization]'
|
||||
'-cpuprofile[path to the file to write the CPU profile]'
|
||||
'-doc[show documentation]'
|
||||
'-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'
|
||||
'-memprofile[path to the file to write the memory profile]'
|
||||
'-remote[send remote command to server]'
|
||||
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
|
||||
'-server[start server (automatic)]'
|
||||
'-version[show version]'
|
||||
'*:filename:_files'
|
||||
)
|
||||
|
||||
_arguments -s $arguments
|
||||
+6
-6
@@ -5,11 +5,11 @@ rem You need to put this file to a folder in %PATH% variable.
|
||||
|
||||
:tmploop
|
||||
set tmpfile="%tmp%\lf.%random%.tmp"
|
||||
if exist "%tmpfile%" goto:tmploop
|
||||
lf -last-dir-path="%tmpfile%" %*
|
||||
if not exist "%tmpfile%" exit
|
||||
set /p dir=<"%tmpfile%"
|
||||
del /f "%tmpfile%"
|
||||
if exist %tmpfile% goto:tmploop
|
||||
lf -last-dir-path=%tmpfile% %*
|
||||
if not exist %tmpfile% exit
|
||||
set /p dir=<%tmpfile%
|
||||
del /f %tmpfile%
|
||||
if not exist "%dir%" exit
|
||||
if "%dir%" == "%cd%" exit
|
||||
cd "%dir%"
|
||||
cd /d "%dir%"
|
||||
@@ -0,0 +1,13 @@
|
||||
# Change working dir in shell to last dir in lf on exit.
|
||||
#
|
||||
# You need to either copy the content of this file to your shell rc file
|
||||
# (e.g. ~/.tcshrc) or source this file directly:
|
||||
#
|
||||
# setenv LF_HOME "${HOME}/.config/lf"
|
||||
# [ -e "${LF_HOME}/lfcd.csh" ] && source "${LF_HOME}/lfcd.csh"
|
||||
#
|
||||
# You may also like to assign a key to this command:
|
||||
#
|
||||
# bindkey -c "^O" lfcd
|
||||
#
|
||||
alias lfcd 'set _=`mktemp` && lf -last-dir-path=$_ "\!*" && set _=`cat $_ && rm -f $_` && [ -d "$_" ] && cd "$_"'
|
||||
+17
-13
@@ -38,29 +38,33 @@ map O $mimeopen --ask $f
|
||||
cmd open ${{
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) $EDITOR $fx;;
|
||||
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
# rename current file without overwrite
|
||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
map r push :rename<space>
|
||||
# define a custom 'rename' command without prompt for overwrite
|
||||
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
# map r push :rename<space>
|
||||
|
||||
# make sure trash folder exists
|
||||
%mkdir -p ~/.trash
|
||||
# %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/)
|
||||
|
||||
+65
-27
@@ -67,8 +67,8 @@ var gEvalTests = []struct {
|
||||
|
||||
{
|
||||
`echo "hello\zworld"`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||
[]string{"echo", `hello\zworld`, "\n"},
|
||||
[]expr{&callExpr{"echo", []string{`hello\zworld`}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -90,7 +90,7 @@ var gEvalTests = []struct {
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
"echo hello\\\tworld",
|
||||
[]string{"echo", "hello\tworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||
},
|
||||
@@ -101,10 +101,16 @@ var gEvalTests = []struct {
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\\world`,
|
||||
[]string{"echo", `hello\world`, "\n"},
|
||||
[]expr{&callExpr{"echo", []string{`hello\world`}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\zworld`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||
[]string{"echo", "hellozworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hellozworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -125,6 +131,18 @@ var gEvalTests = []struct {
|
||||
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
`set ifs ""`,
|
||||
[]string{"set", "ifs", "", "\n"},
|
||||
[]expr{&setExpr{"ifs", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
`set ifs "\n"`,
|
||||
[]string{"set", "ifs", "\n", "\n"},
|
||||
[]expr{&setExpr{"ifs", "\n"}},
|
||||
},
|
||||
|
||||
{
|
||||
"set ratios 1:2:3",
|
||||
[]string{"set", "ratios", "1:2:3", "\n"},
|
||||
@@ -140,25 +158,37 @@ var gEvalTests = []struct {
|
||||
{
|
||||
":set ratios 1:2:3",
|
||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3\nset hidden",
|
||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3;",
|
||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
":set ratios 1:2:3;\nset hidden",
|
||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"set ratios 1:2:3\n set hidden",
|
||||
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
|
||||
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
"set ratios 1:2:3 \nset hidden",
|
||||
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
|
||||
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -176,13 +206,13 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map gh :cd ~",
|
||||
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh :cd ~;",
|
||||
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -218,13 +248,13 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map u :usage",
|
||||
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u :usage;",
|
||||
[]string{"map", "u", ":", "usage", ";", "\n"},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -248,13 +278,13 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map r :push :rename<space>",
|
||||
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r :push :rename<space> ; set hidden",
|
||||
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -278,13 +308,13 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map ss :set sortby size; set info size",
|
||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", "\n", "\n"},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map ss :set sortby size; set info size;",
|
||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", ";", "\n"},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}},
|
||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -292,13 +322,17 @@ var gEvalTests = []struct {
|
||||
cd ~
|
||||
set hidden
|
||||
}}`,
|
||||
[]string{"cmd", "gohome", ":", "{{",
|
||||
[]string{
|
||||
"cmd", "gohome", ":", "{{",
|
||||
"cd", "~", "\n",
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""}}},
|
||||
"}}", "\n",
|
||||
},
|
||||
[]expr{&cmdExpr{
|
||||
"gohome", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""},
|
||||
}, 1},
|
||||
}},
|
||||
},
|
||||
|
||||
@@ -307,13 +341,17 @@ var gEvalTests = []struct {
|
||||
cd ~
|
||||
set hidden
|
||||
}}`,
|
||||
[]string{"map", "gh", ":", "{{",
|
||||
[]string{
|
||||
"map", "gh", ":", "{{",
|
||||
"cd", "~", "\n",
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""}}},
|
||||
"}}", "\n",
|
||||
},
|
||||
[]expr{&mapExpr{
|
||||
"gh", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""},
|
||||
}, 1},
|
||||
}},
|
||||
},
|
||||
|
||||
|
||||
+41
-24
@@ -14,28 +14,45 @@ set -o verbose
|
||||
|
||||
mkdir -p dist
|
||||
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-darwin-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-darwin-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-dragonfly-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-freebsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-freebsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-freebsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-ppc64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-ppc64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-mips.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-mipsle.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-mips64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-linux-mips64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-netbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-netbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-netbsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-openbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-openbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && sync && tar czf dist/lf-openbsd-arm.tar.gz lf --remove-files
|
||||
# https://golang.org/doc/install/source#environment
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && sync && zip dist/lf-windows-386.zip lf.exe --move
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && sync && zip dist/lf-windows-amd64.zip lf.exe --move
|
||||
CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-dragonfly-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-freebsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=illumos GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-illumos-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-ppc64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=ppc64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-ppc64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mipsle go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mipsle.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=mips64le go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-mips64le.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=s390x go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-linux-s390x.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=netbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-netbsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-386.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-amd64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=openbsd GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-openbsd-arm64.tar.gz lf --remove-files
|
||||
CGO_ENABLED=0 GOOS=solaris GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-solaris-amd64.tar.gz lf --remove-files
|
||||
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-386.zip lf.exe --move
|
||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && zip dist/lf-windows-amd64.zip lf.exe --move
|
||||
|
||||
# not supported
|
||||
# CGO_ENABLED=0 GOOS=aix GOARCH=ppc64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-aix-ppc64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-386.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-amd64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=android GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-android-arm.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-darwin-arm64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=js GOARCH=wasm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-js-wasm.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=386 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-386.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=amd64 go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-amd64.tar.gz lf --remove-files
|
||||
# CGO_ENABLED=0 GOOS=plan9 GOARCH=arm go build -ldflags="-s -w -X main.gVersion=$version" && tar czf dist/lf-plan9-arm.tar.gz lf --remove-files
|
||||
@@ -0,0 +1,9 @@
|
||||
module github.com/gokcehan/lf
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/gdamore/tcell v1.3.0
|
||||
github.com/mattn/go-runewidth v0.0.9
|
||||
gopkg.in/djherbis/times.v1 v1.2.0
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFDnH08=
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/gdamore/tcell v1.3.0 h1:r35w0JBADPZCVQijYebl6YMWWtHRqVEGt7kL2eBADRM=
|
||||
github.com/gdamore/tcell v1.3.0/go.mod h1:Hjvr+Ofd+gLglo7RYKxxnzCBmev3BzsS67MebKS4zMM=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.2 h1:mCMFu6PgSozg9tDNMMK3g18oJBX7oYGrC09mS6CXfO4=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.2/go.mod h1:0MS4r+7BZKSJ5mw4/S5MPN+qHFF1fYclkSPilDOKW0s=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
|
||||
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
|
||||
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
|
||||
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type iconMap map[string]string
|
||||
|
||||
func parseIcons() iconMap {
|
||||
if env := os.Getenv("LF_ICONS"); env != "" {
|
||||
return parseIconsEnv(env)
|
||||
}
|
||||
|
||||
defaultIcons := []string{
|
||||
"tw=🗀",
|
||||
"st=🗀",
|
||||
"ow=🗀",
|
||||
"di=🗀",
|
||||
"fi=🗎",
|
||||
}
|
||||
|
||||
return parseIconsEnv(strings.Join(defaultIcons, ":"))
|
||||
}
|
||||
|
||||
func parseIconsEnv(env string) iconMap {
|
||||
icons := make(iconMap)
|
||||
|
||||
entries := strings.Split(env, ":")
|
||||
for _, entry := range entries {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
pair := strings.Split(entry, "=")
|
||||
if len(pair) != 2 {
|
||||
log.Printf("invalid $LF_ICONS entry: %s", entry)
|
||||
return icons
|
||||
}
|
||||
key, val := pair[0], pair[1]
|
||||
icons[key] = val
|
||||
}
|
||||
|
||||
return icons
|
||||
}
|
||||
|
||||
func (im iconMap) get(f *file) string {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
key = "st"
|
||||
case f.IsDir() && f.Mode()&0002 != 0:
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
key = "so"
|
||||
case f.Mode()&os.ModeCharDevice != 0:
|
||||
key = "cd"
|
||||
case f.Mode()&os.ModeDevice != 0:
|
||||
key = "bd"
|
||||
case f.Mode()&os.ModeSetuid != 0:
|
||||
key = "su"
|
||||
case f.Mode()&os.ModeSetgid != 0:
|
||||
key = "sg"
|
||||
case f.Mode().IsRegular() && f.Mode()&0111 != 0:
|
||||
key = "ex"
|
||||
default:
|
||||
key = "*" + filepath.Ext(f.Name())
|
||||
}
|
||||
|
||||
if val, ok := im[key]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im["fi"]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
return " "
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=lf
|
||||
Comment=Launches the lf file manager
|
||||
Icon=utilities-terminal
|
||||
Terminal=true
|
||||
Exec=lf
|
||||
Categories=ConsoleOnly;System;FileTools;FileManager
|
||||
MimeType=inode/directory;
|
||||
@@ -7,8 +7,10 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,6 +44,105 @@ 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)
|
||||
os.Setenv("TCELL_TRUECOLOR", envTcellTruecolor)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
// used by exportOpts below
|
||||
func fieldToString(field reflect.Value) string {
|
||||
kind := field.Kind()
|
||||
var value string
|
||||
|
||||
switch kind {
|
||||
case reflect.Int:
|
||||
value = strconv.Itoa(int(field.Int()))
|
||||
case reflect.Bool:
|
||||
value = strconv.FormatBool(field.Bool())
|
||||
case reflect.Slice:
|
||||
for i := 0; i < field.Len(); i++ {
|
||||
element := field.Index(i)
|
||||
|
||||
if i == 0 {
|
||||
value = fieldToString(element)
|
||||
} else {
|
||||
value += ":" + fieldToString(element)
|
||||
}
|
||||
}
|
||||
default:
|
||||
value = field.String()
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func exportOpts() {
|
||||
e := reflect.ValueOf(&gOpts).Elem()
|
||||
|
||||
for i := 0; i < e.NumField(); i++ {
|
||||
// Get name and prefix it with lf_
|
||||
name := e.Type().Field(i).Name
|
||||
name = fmt.Sprintf("lf_%s", name)
|
||||
|
||||
// Skip maps
|
||||
if name == "lf_keys" || name == "lf_cmdkeys" || name == "lf_cmds" {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get string representation of the value
|
||||
if name == "lf_sortType" {
|
||||
var sortby string
|
||||
|
||||
switch gOpts.sortType.method {
|
||||
case naturalSort:
|
||||
sortby = "natural"
|
||||
case nameSort:
|
||||
sortby = "name"
|
||||
case sizeSort:
|
||||
sortby = "size"
|
||||
case timeSort:
|
||||
sortby = "time"
|
||||
case ctimeSort:
|
||||
sortby = "ctime"
|
||||
case atimeSort:
|
||||
sortby = "atime"
|
||||
case extSort:
|
||||
sortby = "ext"
|
||||
}
|
||||
|
||||
os.Setenv("lf_sortby", sortby)
|
||||
|
||||
reverse := strconv.FormatBool(gOpts.sortType.option&reverseSort != 0)
|
||||
os.Setenv("lf_reverse", reverse)
|
||||
|
||||
hidden := strconv.FormatBool(gOpts.sortType.option&hiddenSort != 0)
|
||||
os.Setenv("lf_hidden", hidden)
|
||||
|
||||
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
|
||||
os.Setenv("lf_dirfirst", dirfirst)
|
||||
} else {
|
||||
field := e.Field(i)
|
||||
value := fieldToString(field)
|
||||
|
||||
os.Setenv(name, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
cmd := detachedCommand(os.Args[0], "-server")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -132,10 +233,11 @@ 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:
|
||||
os.Chdir(gUser.HomeDir)
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
default:
|
||||
@@ -162,6 +264,8 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
exportEnvVars()
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,13 @@ import (
|
||||
|
||||
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
||||
|
||||
func replaceTilde(s string) string {
|
||||
if strings.HasPrefix(s, "~") {
|
||||
s = strings.Replace(s, "~", gUser.HomeDir, 1)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func runeSliceWidth(rs []rune) int {
|
||||
w := 0
|
||||
for _, r := range rs {
|
||||
@@ -41,22 +48,12 @@ func runeSliceWidthRange(rs []rune, beg, end int) []rune {
|
||||
return nil
|
||||
}
|
||||
|
||||
// This function is used to escape whitespaces with backlashes in a given
|
||||
// string. If a whitespace is already escaped then it is not escaped again.
|
||||
// This function is used to escape whitespaces and special characters with
|
||||
// backlashes in a given string.
|
||||
func escape(s string) string {
|
||||
esc := false
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
if r == '\\' {
|
||||
esc = true
|
||||
continue
|
||||
}
|
||||
if esc {
|
||||
esc = false
|
||||
buf = append(buf, '\\', r)
|
||||
continue
|
||||
}
|
||||
if unicode.IsSpace(r) {
|
||||
if unicode.IsSpace(r) || r == '\\' || r == ';' || r == '#' {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
buf = append(buf, r)
|
||||
@@ -65,26 +62,29 @@ func escape(s string) string {
|
||||
}
|
||||
|
||||
// This function is used to remove backlashes that are used to escape
|
||||
// whitespaces in a given string.
|
||||
// whitespaces and special characters in a given string.
|
||||
func unescape(s string) string {
|
||||
esc := false
|
||||
buf := make([]rune, 0, len(s))
|
||||
for _, r := range s {
|
||||
if esc {
|
||||
if !unicode.IsSpace(r) && r != '\\' && r != ';' && r != '#' {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
buf = append(buf, r)
|
||||
esc = false
|
||||
continue
|
||||
}
|
||||
if r == '\\' {
|
||||
esc = true
|
||||
continue
|
||||
}
|
||||
if esc {
|
||||
esc = false
|
||||
if unicode.IsSpace(r) {
|
||||
buf = append(buf, r)
|
||||
} else {
|
||||
buf = append(buf, '\\', r)
|
||||
}
|
||||
continue
|
||||
}
|
||||
esc = false
|
||||
buf = append(buf, r)
|
||||
}
|
||||
if esc {
|
||||
buf = append(buf, '\\')
|
||||
}
|
||||
return string(buf)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
+14
-3
@@ -80,8 +80,13 @@ func TestEscape(t *testing.T) {
|
||||
{"foo", "foo"},
|
||||
{"foo bar", `foo\ bar`},
|
||||
{"foo bar", `foo\ \ bar`},
|
||||
{`foo\ bar`, `foo\ bar`},
|
||||
{`foo\bar`, `foo\bar`},
|
||||
{`foo\bar`, `foo\\bar`},
|
||||
{`foo\ bar`, `foo\\\ bar`},
|
||||
{`foo;bar`, `foo\;bar`},
|
||||
{`foo#bar`, `foo\#bar`},
|
||||
{`foo\tbar`, `foo\\tbar`},
|
||||
{"foo\tbar", "foo\\\tbar"},
|
||||
{`foo\`, `foo\\`},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -98,9 +103,15 @@ func TestUnescape(t *testing.T) {
|
||||
}{
|
||||
{"", ""},
|
||||
{"foo", "foo"},
|
||||
{`foo\bar`, `foo\bar`},
|
||||
{`foo\ bar`, "foo bar"},
|
||||
{`foo\ \ bar`, "foo bar"},
|
||||
{`foo\\bar`, `foo\bar`},
|
||||
{`foo\\\ bar`, `foo\ bar`},
|
||||
{`foo\;bar`, `foo;bar`},
|
||||
{`foo\#bar`, `foo#bar`},
|
||||
{`foo\\tbar`, `foo\tbar`},
|
||||
{"foo\\\tbar", "foo\tbar"},
|
||||
{`foo\`, `foo\`},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
@@ -9,10 +9,13 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
times "gopkg.in/djherbis/times.v1"
|
||||
)
|
||||
|
||||
type linkState byte
|
||||
@@ -25,9 +28,13 @@ const (
|
||||
|
||||
type file struct {
|
||||
os.FileInfo
|
||||
linkState linkState
|
||||
path string
|
||||
dirCount int
|
||||
linkState linkState
|
||||
linkTarget string
|
||||
path string
|
||||
dirCount int
|
||||
accessTime time.Time
|
||||
changeTime time.Time
|
||||
ext string
|
||||
}
|
||||
|
||||
func readdir(path string) ([]*file, error) {
|
||||
@@ -51,6 +58,7 @@ func readdir(path string) ([]*file, error) {
|
||||
}
|
||||
|
||||
var linkState linkState
|
||||
var linkTarget string
|
||||
|
||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||
stat, err := os.Stat(fpath)
|
||||
@@ -60,13 +68,36 @@ func readdir(path string) ([]*file, error) {
|
||||
} else {
|
||||
linkState = broken
|
||||
}
|
||||
linkTarget, err = os.Readlink(fpath)
|
||||
if err != nil {
|
||||
log.Printf("reading link target: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
ts := times.Get(lstat)
|
||||
at := ts.AccessTime()
|
||||
var ct time.Time
|
||||
// from times docs: ChangeTime() panics unless HasChangeTime() is true
|
||||
if ts.HasChangeTime() {
|
||||
ct = ts.ChangeTime()
|
||||
} else {
|
||||
// fall back to ModTime if ChangeTime cannot be determined
|
||||
ct = lstat.ModTime()
|
||||
}
|
||||
|
||||
// returns an empty string if extension could not be determined
|
||||
// i.e. directories, filenames without extensions
|
||||
ext := filepath.Ext(fpath)
|
||||
|
||||
files = append(files, &file{
|
||||
FileInfo: lstat,
|
||||
linkState: linkState,
|
||||
path: fpath,
|
||||
dirCount: -1,
|
||||
FileInfo: lstat,
|
||||
linkState: linkState,
|
||||
linkTarget: linkTarget,
|
||||
path: fpath,
|
||||
dirCount: -1,
|
||||
accessTime: at,
|
||||
changeTime: ct,
|
||||
ext: ext,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -74,14 +105,16 @@ func readdir(path string) ([]*file, error) {
|
||||
}
|
||||
|
||||
type dir struct {
|
||||
loading bool // directory is loading from disk
|
||||
loadTime time.Time // current loading or last load time
|
||||
ind int // index of current entry in files
|
||||
pos int // position of current entry in ui
|
||||
path string // full path of directory
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortType sortType // sort method and options from last sort
|
||||
loading bool // directory is loading from disk
|
||||
loadTime time.Time // current loading or last load time
|
||||
ind int // index of current entry in files
|
||||
pos int // position of current entry in ui
|
||||
path string // full path of directory
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortType sortType // sort method and options from last sort
|
||||
hiddenfiles []string // hiddenfiles value from last sort
|
||||
noPerm bool // whether lf has no permission to open the directory
|
||||
}
|
||||
|
||||
func newDir(path string) *dir {
|
||||
@@ -97,11 +130,13 @@ func newDir(path string) *dir {
|
||||
path: path,
|
||||
files: files,
|
||||
allFiles: files,
|
||||
noPerm: os.IsPermission(err),
|
||||
}
|
||||
}
|
||||
|
||||
func (dir *dir) sort() {
|
||||
dir.sortType = gOpts.sortType
|
||||
dir.hiddenfiles = gOpts.hiddenfiles
|
||||
|
||||
dir.files = dir.allFiles
|
||||
|
||||
@@ -122,6 +157,34 @@ func (dir *dir) sort() {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||
})
|
||||
case atimeSort:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return dir.files[i].accessTime.Before(dir.files[j].accessTime)
|
||||
})
|
||||
case ctimeSort:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
|
||||
})
|
||||
case extSort:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
leftExt := strings.ToLower(dir.files[i].ext)
|
||||
rightExt := strings.ToLower(dir.files[j].ext)
|
||||
|
||||
// if the extension could not be determined (directories, files without)
|
||||
// use a zero byte so that these files can be ranked higher
|
||||
if leftExt == "" {
|
||||
leftExt = "\x00"
|
||||
}
|
||||
if rightExt == "" {
|
||||
rightExt = "\x00"
|
||||
}
|
||||
|
||||
// in order to also have natural sorting with the filenames
|
||||
// combine the name with the ext but have the ext at the front
|
||||
left := leftExt + strings.ToLower(dir.files[i].Name())
|
||||
right := rightExt + strings.ToLower(dir.files[j].Name())
|
||||
return left < right
|
||||
})
|
||||
}
|
||||
|
||||
if gOpts.sortType.option&reverseSort != 0 {
|
||||
@@ -144,13 +207,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], dir.path) && isHidden(dir.files[j], dir.path) {
|
||||
return i < j
|
||||
}
|
||||
return dir.files[i].Name()[0] == '.'
|
||||
return isHidden(dir.files[i], dir.path)
|
||||
})
|
||||
for i, f := range dir.files {
|
||||
if f.Name()[0] != '.' {
|
||||
if !isHidden(f, dir.path) {
|
||||
dir.files = dir.files[i:]
|
||||
return
|
||||
}
|
||||
@@ -188,64 +251,84 @@ 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
|
||||
deleteCount int
|
||||
deleteTotal int
|
||||
deleteUpdate int
|
||||
copyBytesChan chan int64
|
||||
copyTotalChan chan int64
|
||||
moveCountChan chan int
|
||||
moveTotalChan chan int
|
||||
deleteCountChan chan int
|
||||
deleteTotalChan chan int
|
||||
dirChan chan *dir
|
||||
regChan chan *reg
|
||||
dirCache map[string]*dir
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
renameOldPath string
|
||||
renameNewPath 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 {
|
||||
d, ok := nav.dirCache[path]
|
||||
if !ok {
|
||||
d := &dir{loading: true, loadTime: time.Now(), path: path, sortType: gOpts.sortType, hiddenfiles: gOpts.hiddenfiles}
|
||||
nav.dirCache[path] = d
|
||||
go func() {
|
||||
d := newDir(path)
|
||||
d.sort()
|
||||
d.ind, d.pos = 0, 0
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
|
||||
nav.dirCache[path] = d
|
||||
return d
|
||||
}
|
||||
|
||||
s, err := os.Stat(d.path)
|
||||
nav.checkDir(d)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (nav *nav) checkDir(dir *dir) {
|
||||
s, err := os.Stat(dir.path)
|
||||
if err != nil {
|
||||
return d
|
||||
log.Printf("getting directory info: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case s.ModTime().After(d.loadTime):
|
||||
case s.ModTime().After(dir.loadTime):
|
||||
dir.loading = true
|
||||
dir.loadTime = time.Now()
|
||||
go func() {
|
||||
d.loadTime = time.Now()
|
||||
nd := newDir(path)
|
||||
nd := newDir(dir.path)
|
||||
nd.sort()
|
||||
nd.sel(d.name(), nav.height)
|
||||
nav.dirChan <- nd
|
||||
}()
|
||||
case d.sortType != gOpts.sortType:
|
||||
case dir.sortType != gOpts.sortType || !reflect.DeepEqual(dir.hiddenfiles, gOpts.hiddenfiles):
|
||||
dir.loading = true
|
||||
go func() {
|
||||
d.loading = true
|
||||
name := d.name()
|
||||
d.sort()
|
||||
d.sel(name, nav.height)
|
||||
d.loading = false
|
||||
nav.dirChan <- d
|
||||
dir.sort()
|
||||
dir.loading = false
|
||||
nav.dirChan <- dir
|
||||
}()
|
||||
}
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (nav *nav) getDirs(wd string) {
|
||||
@@ -271,15 +354,21 @@ 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),
|
||||
deleteCountChan: make(chan int, 1024),
|
||||
deleteTotalChan: 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)
|
||||
@@ -289,27 +378,15 @@ func newNav(height int) *nav {
|
||||
|
||||
func (nav *nav) renew() {
|
||||
for _, d := range nav.dirs {
|
||||
go func(d *dir) {
|
||||
s, err := os.Stat(d.path)
|
||||
if err != nil {
|
||||
log.Printf("getting directory info: %s", err)
|
||||
return
|
||||
}
|
||||
if d.loadTime.After(s.ModTime()) {
|
||||
return
|
||||
}
|
||||
d.loadTime = time.Now()
|
||||
nd := newDir(d.path)
|
||||
nd.sort()
|
||||
nav.dirChan <- nd
|
||||
}(d)
|
||||
nav.checkDir(d)
|
||||
}
|
||||
|
||||
for m := range nav.selections {
|
||||
if _, err := os.Stat(m); os.IsNotExist(err) {
|
||||
if _, err := os.Lstat(m); os.IsNotExist(err) {
|
||||
delete(nav.selections, m)
|
||||
}
|
||||
}
|
||||
|
||||
if len(nav.selections) == 0 {
|
||||
nav.selectionInd = 0
|
||||
}
|
||||
@@ -342,16 +419,14 @@ func (nav *nav) position() {
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) preview() {
|
||||
curr, err := nav.currFile()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
func (nav *nav) preview(path string) {
|
||||
reg := ®{loadTime: time.Now(), path: path}
|
||||
|
||||
var reader io.Reader
|
||||
|
||||
if len(gOpts.previewer) != 0 {
|
||||
cmd := exec.Command(gOpts.previewer, curr.path, strconv.Itoa(nav.height))
|
||||
exportOpts()
|
||||
cmd := exec.Command(gOpts.previewer, path, strconv.Itoa(nav.height))
|
||||
|
||||
out, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
@@ -366,7 +441,7 @@ func (nav *nav) preview() {
|
||||
defer out.Close()
|
||||
reader = out
|
||||
} else {
|
||||
f, err := os.Open(curr.path)
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Printf("opening file: %s", err)
|
||||
}
|
||||
@@ -375,14 +450,12 @@ func (nav *nav) preview() {
|
||||
reader = f
|
||||
}
|
||||
|
||||
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||
|
||||
buf := bufio.NewScanner(reader)
|
||||
|
||||
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
|
||||
}
|
||||
@@ -397,28 +470,32 @@ func (nav *nav) preview() {
|
||||
nav.regChan <- reg
|
||||
}
|
||||
|
||||
func (nav *nav) loadReg(ui *ui, path string) *reg {
|
||||
func (nav *nav) loadReg(path string) *reg {
|
||||
r, ok := nav.regCache[path]
|
||||
if !ok {
|
||||
go nav.preview()
|
||||
r := ®{loading: true, path: path}
|
||||
r := ®{loading: true, loadTime: time.Now(), path: path}
|
||||
nav.regCache[path] = r
|
||||
go nav.preview(path)
|
||||
return r
|
||||
}
|
||||
|
||||
s, err := os.Stat(r.path)
|
||||
if err != nil {
|
||||
return r
|
||||
}
|
||||
|
||||
if s.ModTime().After(r.loadTime) {
|
||||
r.loadTime = time.Now()
|
||||
go nav.preview()
|
||||
}
|
||||
nav.checkReg(r)
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func (nav *nav) checkReg(reg *reg) {
|
||||
s, err := os.Stat(reg.path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if s.ModTime().After(reg.loadTime) {
|
||||
reg.loadTime = time.Now()
|
||||
go nav.preview(reg.path)
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) sort() {
|
||||
for _, d := range nav.dirs {
|
||||
name := d.name()
|
||||
@@ -431,6 +508,9 @@ func (nav *nav) up(dist int) {
|
||||
dir := nav.currDir()
|
||||
|
||||
if dir.ind == 0 {
|
||||
if gOpts.wrapscroll {
|
||||
nav.bottom()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -448,6 +528,9 @@ func (nav *nav) down(dist int) {
|
||||
maxind := len(dir.files) - 1
|
||||
|
||||
if dir.ind >= maxind {
|
||||
if gOpts.wrapscroll {
|
||||
nav.top()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -533,14 +616,12 @@ func (nav *nav) toggle() {
|
||||
}
|
||||
|
||||
nav.toggleSelection(curr.path)
|
||||
|
||||
nav.down(1)
|
||||
}
|
||||
|
||||
func (nav *nav) invert() {
|
||||
last := nav.currDir()
|
||||
for _, f := range last.files {
|
||||
path := filepath.Join(last.path, f.Name())
|
||||
dir := nav.currDir()
|
||||
for _, f := range dir.files {
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
nav.toggleSelection(path)
|
||||
}
|
||||
}
|
||||
@@ -568,44 +649,240 @@ 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
|
||||
}
|
||||
|
||||
if errCount == 0 {
|
||||
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mCopied successfully\033[0m"}, 1}
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
||||
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.Lstat(newPath)
|
||||
}
|
||||
dst = newPath
|
||||
}
|
||||
|
||||
if err := os.Rename(src, dst); err != nil {
|
||||
if errCrossDevice(err) {
|
||||
total, err := copySize([]string{src})
|
||||
if err != nil {
|
||||
echo.args[0] = err.Error()
|
||||
ui.exprChan <- echo
|
||||
continue
|
||||
}
|
||||
|
||||
nav.copyTotalChan <- total
|
||||
|
||||
nums, errs := copyAll([]string{src}, dstDir)
|
||||
|
||||
oldCount := errCount
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case n := <-nums:
|
||||
nav.copyBytesChan <- n
|
||||
case err, ok := <-errs:
|
||||
if !ok {
|
||||
break loop
|
||||
}
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
}
|
||||
|
||||
nav.copyTotalChan <- -total
|
||||
|
||||
if errCount == oldCount {
|
||||
if err := os.RemoveAll(src); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nav.moveTotalChan <- -len(srcs)
|
||||
|
||||
if err := remote("send load"); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
|
||||
if errCount == 0 {
|
||||
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) paste(ui *ui) error {
|
||||
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
|
||||
}
|
||||
|
||||
func (nav *nav) del() error {
|
||||
func (nav *nav) del(ui *ui) error {
|
||||
list, err := nav.currFileOrSelections()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, path := range list {
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
return err
|
||||
go func() {
|
||||
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||
errCount := 0
|
||||
|
||||
nav.deleteTotalChan <- len(list)
|
||||
|
||||
for _, path := range list {
|
||||
nav.deleteCountChan <- 1
|
||||
|
||||
if err := os.RemoveAll(path); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
}
|
||||
|
||||
nav.deleteTotalChan <- -len(list)
|
||||
|
||||
if err := remote("send load"); err != nil {
|
||||
errCount++
|
||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||
ui.exprChan <- echo
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) rename() error {
|
||||
oldPath := nav.renameOldPath
|
||||
newPath := nav.renameNewPath
|
||||
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lstat, err := os.Lstat(newPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dir := nav.loadDir(filepath.Dir(newPath))
|
||||
|
||||
if dir.loading {
|
||||
dir.files = append(dir.files, &file{FileInfo: lstat})
|
||||
}
|
||||
|
||||
dir.sel(lstat.Name(), nav.height)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -620,11 +897,11 @@ func (nav *nav) sync() error {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
|
||||
return nil
|
||||
return nav.readMarks()
|
||||
}
|
||||
|
||||
func (nav *nav) cd(wd string) error {
|
||||
wd = strings.Replace(wd, "~", gUser.HomeDir, -1)
|
||||
wd = replaceTilde(wd)
|
||||
wd = filepath.Clean(wd)
|
||||
|
||||
if !filepath.IsAbs(wd) {
|
||||
@@ -641,7 +918,10 @@ func (nav *nav) cd(wd string) error {
|
||||
}
|
||||
|
||||
func (nav *nav) sel(path string) error {
|
||||
lstat, err := os.Stat(path)
|
||||
path = replaceTilde(path)
|
||||
path = filepath.Clean(path)
|
||||
|
||||
lstat, err := os.Lstat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select: %s", err)
|
||||
}
|
||||
@@ -655,10 +935,36 @@ func (nav *nav) sel(path string) error {
|
||||
base := filepath.Base(path)
|
||||
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
|
||||
if last.loading {
|
||||
last.files = append(last.files, &file{FileInfo: lstat})
|
||||
} else {
|
||||
last.sel(base, nav.height)
|
||||
}
|
||||
|
||||
last.sel(base, nav.height)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) globSel(pattern string, invert bool) error {
|
||||
dir := nav.currDir()
|
||||
anyMatched := false
|
||||
|
||||
for i := 0; i < len(dir.files); i++ {
|
||||
matched, err := filepath.Match(pattern, dir.files[i].Name())
|
||||
if err != nil {
|
||||
return fmt.Errorf("glob-select: %s", err)
|
||||
}
|
||||
if matched {
|
||||
anyMatched = true
|
||||
fpath := filepath.Join(dir.path, dir.files[i].Name())
|
||||
if _, ok := nav.selections[fpath]; ok == invert {
|
||||
nav.toggleSelection(fpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !anyMatched {
|
||||
return fmt.Errorf("glob-select: pattern not found: %s", pattern)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -688,9 +994,9 @@ func findMatch(name, pattern string) bool {
|
||||
func (nav *nav) findSingle() int {
|
||||
count := 0
|
||||
index := 0
|
||||
last := nav.currDir()
|
||||
for i := 0; i < len(last.files); i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
dir := nav.currDir()
|
||||
for i := 0; i < len(dir.files); i++ {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
count++
|
||||
if count > 1 {
|
||||
return count
|
||||
@@ -699,27 +1005,27 @@ func (nav *nav) findSingle() int {
|
||||
}
|
||||
}
|
||||
if count == 1 {
|
||||
if index > last.ind {
|
||||
nav.down(index - last.ind)
|
||||
if index > dir.ind {
|
||||
nav.down(index - dir.ind)
|
||||
} else {
|
||||
nav.up(last.ind - index)
|
||||
nav.up(dir.ind - index)
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (nav *nav) findNext() bool {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.files); i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.down(i - last.ind)
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
nav.down(i - dir.ind)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := 0; i < last.ind; i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.up(last.ind - i)
|
||||
for i := 0; i < dir.ind; i++ {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
nav.up(dir.ind - i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -728,17 +1034,17 @@ func (nav *nav) findNext() bool {
|
||||
}
|
||||
|
||||
func (nav *nav) findPrev() bool {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i >= 0; i-- {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.up(last.ind - i)
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind - 1; i >= 0; i-- {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
nav.up(dir.ind - i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.down(i - last.ind)
|
||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||
if findMatch(dir.files[i].Name(), nav.find) {
|
||||
nav.down(i - dir.ind)
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -768,25 +1074,25 @@ func searchMatch(name, pattern string) (matched bool, err error) {
|
||||
}
|
||||
|
||||
func (nav *nav) searchNext() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.files); i++ {
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if matched {
|
||||
nav.down(i - last.ind)
|
||||
nav.down(i - dir.ind)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := 0; i < last.ind; i++ {
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
for i := 0; i < dir.ind; i++ {
|
||||
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if matched {
|
||||
nav.up(last.ind - i)
|
||||
nav.up(dir.ind - i)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -795,25 +1101,25 @@ func (nav *nav) searchNext() error {
|
||||
}
|
||||
|
||||
func (nav *nav) searchPrev() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i >= 0; i-- {
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
dir := nav.currDir()
|
||||
for i := dir.ind - 1; i >= 0; i-- {
|
||||
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if matched {
|
||||
nav.up(last.ind - i)
|
||||
nav.up(dir.ind - i)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if matched {
|
||||
nav.down(i - last.ind)
|
||||
nav.down(i - dir.ind)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -821,7 +1127,16 @@ func (nav *nav) searchPrev() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) removeMark(mark string) error {
|
||||
if _, ok := nav.marks[mark]; ok {
|
||||
delete(nav.marks, mark)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("no such mark")
|
||||
}
|
||||
|
||||
func (nav *nav) readMarks() error {
|
||||
nav.marks = make(map[string]string)
|
||||
f, err := os.Open(gMarksPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -847,14 +1162,6 @@ func (nav *nav) readMarks() error {
|
||||
}
|
||||
|
||||
func (nav *nav) writeMarks() error {
|
||||
if len(nav.marks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := nav.readMarks(); err != nil {
|
||||
return fmt.Errorf("reading marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating data directory: %s", err)
|
||||
}
|
||||
@@ -886,12 +1193,12 @@ func (nav *nav) currDir() *dir {
|
||||
}
|
||||
|
||||
func (nav *nav) currFile() (*file, error) {
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
dir := nav.dirs[len(nav.dirs)-1]
|
||||
|
||||
if len(last.files) == 0 {
|
||||
if len(dir.files) == 0 {
|
||||
return nil, fmt.Errorf("empty directory")
|
||||
}
|
||||
return last.files[last.ind], nil
|
||||
return dir.files[dir.ind], nil
|
||||
}
|
||||
|
||||
type indexedSelections struct {
|
||||
|
||||
@@ -9,6 +9,9 @@ const (
|
||||
nameSort
|
||||
sizeSort
|
||||
timeSort
|
||||
atimeSort
|
||||
ctimeSort
|
||||
extSort
|
||||
)
|
||||
|
||||
type sortOption byte
|
||||
@@ -26,30 +29,34 @@ type sortType struct {
|
||||
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
color256 bool
|
||||
dircounts bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
incsearch bool
|
||||
preview bool
|
||||
smartcase bool
|
||||
ignoredia bool
|
||||
incsearch bool
|
||||
number bool
|
||||
preview bool
|
||||
relativenumber bool
|
||||
smartcase bool
|
||||
smartdia bool
|
||||
wrapscan bool
|
||||
number bool
|
||||
relativenumber bool
|
||||
wrapscroll bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
promptfmt string
|
||||
shell string
|
||||
timefmt string
|
||||
truncatechar string
|
||||
ratios []int
|
||||
hiddenfiles []string
|
||||
info []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
@@ -60,26 +67,34 @@ var gOpts struct {
|
||||
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.color256 = false
|
||||
gOpts.dircounts = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.icons = false
|
||||
gOpts.ignorecase = true
|
||||
gOpts.incsearch = false
|
||||
gOpts.preview = true
|
||||
gOpts.smartcase = true
|
||||
gOpts.ignoredia = false
|
||||
gOpts.incsearch = false
|
||||
gOpts.number = false
|
||||
gOpts.preview = true
|
||||
gOpts.relativenumber = false
|
||||
gOpts.smartcase = true
|
||||
gOpts.smartdia = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.wrapscroll = 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.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||
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
|
||||
gOpts.truncatechar = "~"
|
||||
gOpts.ratios = []int{1, 2, 3}
|
||||
gOpts.hiddenfiles = []string{".*"}
|
||||
gOpts.info = nil
|
||||
gOpts.shellopts = nil
|
||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||
@@ -105,7 +120,7 @@ func init() {
|
||||
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
||||
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
||||
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
||||
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
|
||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||
@@ -129,6 +144,8 @@ func init() {
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||
gOpts.keys[`"`] = &callExpr{"mark-remove", nil, 1}
|
||||
gOpts.keys[`r`] = &callExpr{"rename", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
@@ -138,9 +155,12 @@ func init() {
|
||||
gOpts.keys["zs"] = &setExpr{"info", "size"}
|
||||
gOpts.keys["zt"] = &setExpr{"info", "time"}
|
||||
gOpts.keys["za"] = &setExpr{"info", "size:time"}
|
||||
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
|
||||
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
|
||||
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
|
||||
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}, 1}
|
||||
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}
|
||||
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1}
|
||||
gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1}
|
||||
gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1}
|
||||
gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1}
|
||||
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
||||
|
||||
gOpts.cmdkeys = make(map[string]expr)
|
||||
@@ -154,8 +174,8 @@ func init() {
|
||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil, 1}
|
||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||
gOpts.cmdkeys["<backspace>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||
gOpts.cmdkeys["<backspace2>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil, 1}
|
||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||
|
||||
@@ -10,13 +10,16 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -53,6 +56,10 @@ func init() {
|
||||
envShell = "sh"
|
||||
}
|
||||
|
||||
if envTcellTruecolor == "" {
|
||||
envTcellTruecolor = "disable"
|
||||
}
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("user: %s", err)
|
||||
@@ -114,31 +121,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"`}
|
||||
@@ -149,10 +131,52 @@ func setDefaults() {
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
}
|
||||
|
||||
func moveCursor(y, x int) {
|
||||
fmt.Printf("\033[%d;%dH", y, x)
|
||||
}
|
||||
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
return f.Mode()&0111 != 0
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo, path string) bool {
|
||||
hidden := false
|
||||
for _, pattern := range gOpts.hiddenfiles {
|
||||
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
|
||||
if strings.HasPrefix(pattern, "!") && matched {
|
||||
hidden = false
|
||||
} else if matched {
|
||||
hidden = true
|
||||
}
|
||||
}
|
||||
return hidden
|
||||
}
|
||||
|
||||
func matchPattern(pattern, name, path string) bool {
|
||||
s := name
|
||||
|
||||
pattern = replaceTilde(pattern)
|
||||
|
||||
if filepath.IsAbs(pattern) {
|
||||
s = filepath.Join(path, name)
|
||||
}
|
||||
|
||||
// pattern errors are checked when 'hiddenfiles' option is set
|
||||
matched, _ := filepath.Match(pattern, s)
|
||||
|
||||
return matched
|
||||
}
|
||||
|
||||
func errCrossDevice(err error) bool {
|
||||
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
+48
-41
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -11,20 +12,19 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
envTcellTruecolor = os.Getenv("TCELL_TRUECOLOR")
|
||||
)
|
||||
|
||||
var (
|
||||
envPathExt = os.Getenv("PATHEXT")
|
||||
)
|
||||
var envPathExt = os.Getenv("PATHEXT")
|
||||
|
||||
var (
|
||||
gDefaultShell = "cmd"
|
||||
gDefaultSocketProt = "tcp"
|
||||
gDefaultSocketPath = ":12345"
|
||||
gDefaultSocketPath = "127.0.0.1:12345"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -36,7 +36,7 @@ var (
|
||||
|
||||
func init() {
|
||||
if envOpener == "" {
|
||||
envOpener = "start"
|
||||
envOpener = `start ""`
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
@@ -51,6 +51,10 @@ func init() {
|
||||
envShell = "cmd"
|
||||
}
|
||||
|
||||
if envTcellTruecolor == "" {
|
||||
envTcellTruecolor = "disable"
|
||||
}
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("user: %s", err)
|
||||
@@ -89,33 +93,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%"}
|
||||
@@ -126,11 +103,6 @@ func setDefaults() {
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
}
|
||||
|
||||
func moveCursor(y, x int) {
|
||||
// TODO: implement
|
||||
return
|
||||
}
|
||||
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
exts := strings.Split(envPathExt, string(filepath.ListSeparator))
|
||||
for _, e := range exts {
|
||||
@@ -141,3 +113,38 @@ func isExecutable(f os.FileInfo) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo, path string) bool {
|
||||
ptr, err := syscall.UTF16PtrFromString(filepath.Join(path, f.Name()))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
attrs, err := syscall.GetFileAttributes(ptr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
|
||||
}
|
||||
|
||||
func errCrossDevice(err error) bool {
|
||||
return err.(*os.LinkError).Err.(syscall.Errno) == 17
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,7 @@ func (e *execExpr) String() string {
|
||||
|
||||
type listExpr struct {
|
||||
exprs []expr
|
||||
count int
|
||||
}
|
||||
|
||||
func (e *listExpr) String() string {
|
||||
@@ -265,7 +266,7 @@ func (p *parser) parseExpr() expr {
|
||||
|
||||
s.scan()
|
||||
|
||||
result = &listExpr{exprs}
|
||||
result = &listExpr{exprs, 1}
|
||||
case tokenPrefix:
|
||||
var expr string
|
||||
|
||||
|
||||
@@ -177,9 +177,6 @@ scan:
|
||||
s.tok = string(s.buf[beg:s.off])
|
||||
s.cmd = false
|
||||
s.sem = true
|
||||
case s.chr == '\r':
|
||||
s.next()
|
||||
goto scan
|
||||
case s.chr == '\n':
|
||||
if s.sem {
|
||||
s.typ = tokenSemicolon
|
||||
@@ -196,7 +193,7 @@ scan:
|
||||
}
|
||||
goto scan
|
||||
case isSpace(s.chr):
|
||||
for !s.eof && isSpace(s.chr) {
|
||||
for !s.eof && isSpace(s.chr) && s.chr != '\n' {
|
||||
s.next()
|
||||
}
|
||||
goto scan
|
||||
@@ -216,25 +213,24 @@ scan:
|
||||
for !s.eof && s.chr != '"' {
|
||||
if s.chr == '\\' {
|
||||
s.next()
|
||||
switch s.chr {
|
||||
case '"', '\\':
|
||||
switch {
|
||||
case s.chr == '"' || s.chr == '\\':
|
||||
buf = append(buf, s.chr)
|
||||
case 'a':
|
||||
case s.chr == 'a':
|
||||
buf = append(buf, '\a')
|
||||
case 'b':
|
||||
case s.chr == 'b':
|
||||
buf = append(buf, '\b')
|
||||
case 'f':
|
||||
case s.chr == 'f':
|
||||
buf = append(buf, '\f')
|
||||
case 'n':
|
||||
case s.chr == 'n':
|
||||
buf = append(buf, '\n')
|
||||
case 'r':
|
||||
case s.chr == 'r':
|
||||
buf = append(buf, '\r')
|
||||
case 't':
|
||||
case s.chr == 't':
|
||||
buf = append(buf, '\t')
|
||||
case 'v':
|
||||
case s.chr == 'v':
|
||||
buf = append(buf, '\v')
|
||||
}
|
||||
if isDigit(s.chr) {
|
||||
case isDigit(s.chr):
|
||||
var oct []byte
|
||||
for isDigit(s.chr) {
|
||||
oct = append(oct, s.chr)
|
||||
@@ -245,13 +241,15 @@ scan:
|
||||
log.Printf("scanning: %s", err)
|
||||
}
|
||||
buf = append(buf, byte(n))
|
||||
} else {
|
||||
s.next()
|
||||
continue
|
||||
default:
|
||||
buf = append(buf, '\\', s.chr)
|
||||
}
|
||||
} else {
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
continue
|
||||
}
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
}
|
||||
s.typ = tokenIdent
|
||||
s.tok = string(buf)
|
||||
@@ -293,12 +291,9 @@ scan:
|
||||
for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {
|
||||
if s.chr == '\\' {
|
||||
s.next()
|
||||
if isSpace(s.chr) {
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
} else {
|
||||
s.next()
|
||||
}
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
continue
|
||||
}
|
||||
buf = append(buf, s.chr)
|
||||
s.next()
|
||||
|
||||
@@ -58,6 +58,7 @@ func listen(l net.Listener) {
|
||||
func handleConn(c net.Conn) {
|
||||
s := bufio.NewScanner(c)
|
||||
|
||||
Loop:
|
||||
for s.Scan() {
|
||||
log.Printf("listen: %s", s.Text())
|
||||
word, rest := splitWord(s.Text())
|
||||
@@ -71,7 +72,7 @@ func handleConn(c net.Conn) {
|
||||
gCopyFile = false
|
||||
default:
|
||||
log.Printf("unexpected option to copy file(s): %s", s.Text())
|
||||
break
|
||||
break Loop
|
||||
}
|
||||
gFileList = nil
|
||||
for s.Scan() && s.Text() != "" {
|
||||
@@ -120,7 +121,7 @@ func handleConn(c net.Conn) {
|
||||
c.Close()
|
||||
}
|
||||
gListener.Close()
|
||||
break
|
||||
break Loop
|
||||
default:
|
||||
log.Printf("listen: unexpected command: %s", word)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user