Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13fe1931cd | ||
|
|
2c87b0dcfe | ||
|
|
b2b22fb674 | ||
|
|
45270e389e | ||
|
|
fee016f406 | ||
|
|
29de45e466 | ||
|
|
791b704257 | ||
|
|
e3bc11408f | ||
|
|
6f35abb4ca | ||
|
|
0eedb71d6c | ||
|
|
1eedd29546 | ||
|
|
866a7e6a2b | ||
|
|
1956a759c4 | ||
|
|
9656553974 | ||
|
|
31945fbcb5 | ||
|
|
4a8943b6b7 | ||
|
|
885e896b4a | ||
|
|
808404978e | ||
|
|
99734c7dcf | ||
|
|
f44ec4f5bd | ||
|
|
4d2a628550 | ||
|
|
193285a65d | ||
|
|
6ec2924b6b | ||
|
|
599ac11f26 | ||
|
|
728c5fbb2c | ||
|
|
0f47c5428b | ||
|
|
4865ce9b00 | ||
|
|
d6e9aece51 | ||
|
|
fd1af47233 | ||
|
|
184762d83a | ||
|
|
27f104b3e6 | ||
|
|
35930924a7 | ||
|
|
4a1388a5c7 | ||
|
|
92e994ebf6 | ||
|
|
245db502cc | ||
|
|
ca95bcf1d8 | ||
|
|
dd6a85f480 | ||
|
|
db8f535b61 | ||
|
|
52be0b3aab | ||
|
|
bd889a9e06 | ||
|
|
951529ebc0 | ||
|
|
0fc14e3b2d | ||
|
|
79b05dc365 | ||
|
|
c7fe60c541 | ||
|
|
ec5fac3274 | ||
|
|
90f0339fa9 | ||
|
|
e0e5977008 | ||
|
|
85a6fe95c5 | ||
|
|
55955fa5c1 | ||
|
|
993b227682 | ||
|
|
d8b9bab3ea | ||
|
|
c5297d6b6b | ||
|
|
8dd3f692b8 | ||
|
|
7e3f92f049 | ||
|
|
3efdfd3bca | ||
|
|
b101603a4a | ||
|
|
c693b7eae4 | ||
|
|
4ee6488a09 | ||
|
|
8229d972b9 | ||
|
|
6193885a55 | ||
|
|
6b1748240c | ||
|
|
629a7f3297 | ||
|
|
5e67147204 | ||
|
|
266a583adb | ||
|
|
b22384d634 | ||
|
|
4ba3c3cda9 | ||
|
|
4420e41c76 | ||
|
|
a59a5aa712 | ||
|
|
170e39b95e | ||
|
|
011cca76d1 | ||
|
|
0b8de7c77e | ||
|
|
d3f9a3588f | ||
|
|
a0935fabcb | ||
|
|
e82cbb820f | ||
|
|
9234bcd5b8 | ||
|
|
7dbb61f295 | ||
|
|
40002a7752 | ||
|
|
ffa913d943 | ||
|
|
abf2187271 | ||
|
|
ee7293e2f7 | ||
|
|
95a9305f70 | ||
|
|
cdf4fcb810 | ||
|
|
211bcd0444 | ||
|
|
0d0f7451ac | ||
|
|
a80900f41e | ||
|
|
552182958a | ||
|
|
d86e9c991c | ||
|
|
e74a43bf0e | ||
|
|
9d4accbcde | ||
|
|
db9d795cb0 | ||
|
|
2f3c52f9f2 | ||
|
|
63892ee83c | ||
|
|
2c14b3cd4a | ||
|
|
e1b6d38386 | ||
|
|
fef99c1d70 | ||
|
|
b8523c3258 | ||
|
|
4cbb211757 | ||
|
|
5787ecd1bd | ||
|
|
96f35e986d | ||
|
|
07c16fede0 | ||
|
|
2d821216a8 | ||
|
|
638d67c0e4 | ||
|
|
6c319316e2 | ||
|
|
5d5d00e30b | ||
|
|
d987c9e439 | ||
|
|
b67b042d43 | ||
|
|
e99478e8a1 | ||
|
|
4c54acebeb | ||
|
|
fe786aae4c | ||
|
|
a607e53e51 | ||
|
|
da126a3959 | ||
|
|
6d20887b16 | ||
|
|
078dc47e34 | ||
|
|
8070cd82b7 | ||
|
|
52974615f2 | ||
|
|
76a725eaf2 | ||
|
|
2e014b3c0a | ||
|
|
51101f7020 | ||
|
|
ba01f85340 | ||
|
|
723357fe3d | ||
|
|
e025c68130 | ||
|
|
7acc85f81c | ||
|
|
4846a74320 | ||
|
|
9177ddd406 | ||
|
|
9d21a4f359 | ||
|
|
20720c832d | ||
|
|
448f2a3cb2 | ||
|
|
397d5e0fac | ||
|
|
9400f07e45 | ||
|
|
a85e0da9b0 | ||
|
|
03b9fe0c5e | ||
|
|
42d57121f7 | ||
|
|
ed8137a79c | ||
|
|
d9761d2dc8 | ||
|
|
04f1d68d1e | ||
|
|
3deea69c4d | ||
|
|
980a89c908 | ||
|
|
de39594a46 | ||
|
|
6e6cca33b8 | ||
|
|
18f6d954a7 | ||
|
|
1a95df7b64 | ||
|
|
afefc30a67 | ||
|
|
0c672fef6f | ||
|
|
bc67283f2a | ||
|
|
f672a71f3d | ||
|
|
ef709b5611 | ||
|
|
7543b2256c | ||
|
|
0855507298 | ||
|
|
6b235beb39 | ||
|
|
d267bc70d4 | ||
|
|
3b043752a4 | ||
|
|
a0e1d4d59a | ||
|
|
09b1daaade | ||
|
|
8eb9055622 | ||
|
|
d608eb4a56 | ||
|
|
ad4fc51805 | ||
|
|
ebd599deca | ||
|
|
5a9a829252 | ||
|
|
f92e0f53a5 | ||
|
|
54dbf5cbe4 | ||
|
|
c1fc79b6ae | ||
|
|
4d3437a198 | ||
|
|
9d14888ba2 | ||
|
|
68a23a10e1 | ||
|
|
03619c3cbb |
No files matched your search
@@ -2,3 +2,4 @@ lf
|
||||
lf.exe
|
||||
tags
|
||||
dist/
|
||||
vendor/
|
||||
@@ -15,7 +15,7 @@
|
||||
`lf` (as in "list files") is a terminal file manager written in Go.
|
||||
It is heavily inspired by ranger with some missing and extra features.
|
||||
Some of the missing features are deliberately omitted since they are better handled by external tools.
|
||||
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
||||
See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information and [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
|
||||
|
||||

|
||||

|
||||
@@ -26,7 +26,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
||||
- Single binary without any runtime dependencies (except for terminfo database)
|
||||
- Fast startup and low memory footprint (due to native code and static binaries)
|
||||
- Server/client architecture to share file selection between multiple instances
|
||||
- Configurable with shell commands (sync or async)
|
||||
- Configuration with shell commands
|
||||
- Customizable keybindings (vi and readline defaults)
|
||||
- Preview filtering (for source highlight, archives, pdfs/images as text etc.)
|
||||
|
||||
@@ -38,8 +38,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
||||
|
||||
## May-Futures
|
||||
|
||||
- Bookmarks
|
||||
- Colorschemes
|
||||
- Mouse control
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type cmdItem struct {
|
||||
@@ -17,14 +18,16 @@ type cmdItem struct {
|
||||
}
|
||||
|
||||
type app struct {
|
||||
ui *ui
|
||||
nav *nav
|
||||
quitChan chan bool
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHist []cmdItem
|
||||
cmdHistInd int
|
||||
ui *ui
|
||||
nav *nav
|
||||
ticker *time.Ticker
|
||||
quitChan chan bool
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
cmdOutBuf []byte
|
||||
cmdHistory []cmdItem
|
||||
cmdHistoryBeg int
|
||||
cmdHistoryInd int
|
||||
}
|
||||
|
||||
func newApp() *app {
|
||||
@@ -34,6 +37,7 @@ func newApp() *app {
|
||||
return &app{
|
||||
ui: ui,
|
||||
nav: nav,
|
||||
ticker: new(time.Ticker),
|
||||
quitChan: make(chan bool, 1),
|
||||
}
|
||||
}
|
||||
@@ -43,33 +47,141 @@ 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()
|
||||
|
||||
p := newParser(f)
|
||||
|
||||
for p.parse() {
|
||||
p.expr.eval(app, nil)
|
||||
}
|
||||
|
||||
if p.err != nil {
|
||||
app.ui.printf("%s", p.err)
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
}
|
||||
|
||||
// This is the main event loop of the application. There are two channels to
|
||||
// read expressions from client and server. Reading and evaluation are done on
|
||||
// separate goroutines.
|
||||
func (app *app) readHistory() error {
|
||||
f, err := os.Open(gHistoryPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("opening history file: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
for scanner.Scan() {
|
||||
toks := strings.SplitN(scanner.Text(), " ", 2)
|
||||
app.cmdHistory = append(app.cmdHistory, cmdItem{toks[0], toks[1]})
|
||||
}
|
||||
|
||||
app.cmdHistoryBeg = len(app.cmdHistory)
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return fmt.Errorf("reading history file: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *app) writeHistory() error {
|
||||
if len(app.cmdHistory) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
local := make([]cmdItem, len(app.cmdHistory)-app.cmdHistoryBeg)
|
||||
copy(local, app.cmdHistory[app.cmdHistoryBeg:])
|
||||
app.cmdHistory = nil
|
||||
|
||||
if err := app.readHistory(); err != nil {
|
||||
return fmt.Errorf("reading history file: %s", err)
|
||||
}
|
||||
|
||||
app.cmdHistory = append(app.cmdHistory, local...)
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(gHistoryPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating data directory: %s", err)
|
||||
}
|
||||
|
||||
f, err := os.Create(gHistoryPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating history file: %s", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if len(app.cmdHistory) > 1000 {
|
||||
app.cmdHistory = app.cmdHistory[len(app.cmdHistory)-1000:]
|
||||
}
|
||||
|
||||
for _, cmd := range app.cmdHistory {
|
||||
_, err = f.WriteString(fmt.Sprintf("%s %s\n", cmd.prefix, cmd.value))
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing history file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// This is the main event loop of the application. Expressions are read from
|
||||
// the client and the server on separate goroutines and sent here over channels
|
||||
// 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()
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}()
|
||||
}
|
||||
|
||||
for _, path := range gConfigPaths {
|
||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||
app.readFile(path)
|
||||
}
|
||||
}
|
||||
|
||||
if gCommand != "" {
|
||||
p := newParser(strings.NewReader(gCommand))
|
||||
|
||||
for p.parse() {
|
||||
p.expr.eval(app, nil)
|
||||
}
|
||||
|
||||
if p.err != nil {
|
||||
app.ui.echoerrf("%s", p.err)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-app.quitChan:
|
||||
if app.nav.copyTotal > 0 {
|
||||
app.ui.echoerr("quit: copy operation in progress")
|
||||
continue
|
||||
}
|
||||
|
||||
if app.nav.moveTotal > 0 {
|
||||
app.ui.echoerr("quit: move operation in progress")
|
||||
continue
|
||||
}
|
||||
|
||||
log.Print("bye!")
|
||||
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
log.Printf("writing marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
}
|
||||
|
||||
if gLastDirPath != "" {
|
||||
f, err := os.Create(gLastDirPath)
|
||||
if err != nil {
|
||||
@@ -86,10 +198,42 @@ func (app *app) loop() {
|
||||
}
|
||||
|
||||
return
|
||||
case n := <-app.nav.copyBytesChan:
|
||||
app.nav.copyBytes += n
|
||||
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
|
||||
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
|
||||
app.nav.copyUpdate = 0
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
case n := <-app.nav.copyTotalChan:
|
||||
app.nav.copyTotal += n
|
||||
if n < 0 {
|
||||
app.nav.copyBytes += n
|
||||
}
|
||||
if app.nav.copyTotal == 0 {
|
||||
app.nav.copyUpdate = 0
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case n := <-app.nav.moveCountChan:
|
||||
app.nav.moveCount += n
|
||||
if app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {
|
||||
app.nav.moveUpdate = 0
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
case n := <-app.nav.moveTotalChan:
|
||||
app.nav.moveTotal += n
|
||||
if n < 0 {
|
||||
app.nav.moveCount += n
|
||||
}
|
||||
if app.nav.moveTotal == 0 {
|
||||
app.nav.moveUpdate = 0
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
case d := <-app.nav.dirChan:
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.find(prev.name(), app.nav.height)
|
||||
d.ind = prev.ind
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
|
||||
app.nav.dirCache[d.path] = d
|
||||
@@ -125,37 +269,28 @@ func (app *app) loop() {
|
||||
|
||||
app.ui.draw(app.nav)
|
||||
case e := <-clientChan:
|
||||
for i := 0; i < e.count; i++ {
|
||||
e.expr.eval(app, nil)
|
||||
}
|
||||
e.eval(app, nil)
|
||||
app.ui.draw(app.nav)
|
||||
case e := <-serverChan:
|
||||
e.eval(app, nil)
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.ticker.C:
|
||||
app.nav.renew()
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) exportVars() {
|
||||
var envFile string
|
||||
func (app *app) exportFiles() {
|
||||
var currFile string
|
||||
if f, err := app.nav.currFile(); err == nil {
|
||||
envFile = f.path
|
||||
currFile = f.path
|
||||
}
|
||||
|
||||
marks := app.nav.currMarks()
|
||||
currSelections := app.nav.currSelections()
|
||||
|
||||
envFiles := strings.Join(marks, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(marks) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
exportFiles(currFile, currSelections)
|
||||
}
|
||||
|
||||
func waitKey() error {
|
||||
@@ -172,15 +307,15 @@ func waitKey() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// This function is used to run a command in shell. Following modes are used:
|
||||
// This function is used to run a shell command. Modes are as follows:
|
||||
//
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Use statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||
// $ No No Yes Yes Yes Pause and then resume
|
||||
// % No No Yes Yes Yes Statline for input/output
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.exportVars()
|
||||
app.exportFiles()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
@@ -193,7 +328,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
|
||||
app.ui.pause()
|
||||
defer app.ui.resume()
|
||||
defer app.nav.renew(app.ui.wins[0].h)
|
||||
defer app.nav.renew()
|
||||
case "%":
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
@@ -217,13 +352,13 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
app.ui.printf("running shell: %s", err)
|
||||
app.ui.echoerrf("running shell: %s", err)
|
||||
}
|
||||
|
||||
switch prefix {
|
||||
case "!":
|
||||
if err := waitKey(); err != nil {
|
||||
app.ui.printf("waiting key: %s", err)
|
||||
app.ui.echoerrf("waiting key: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,12 +367,12 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
|
||||
switch prefix {
|
||||
case "%":
|
||||
go func() {
|
||||
app.cmd = cmd
|
||||
app.cmdOutBuf = nil
|
||||
app.ui.msg = ""
|
||||
app.ui.cmdPrefix = ">"
|
||||
app.cmd = cmd
|
||||
app.cmdOutBuf = nil
|
||||
app.ui.msg = ""
|
||||
app.ui.cmdPrefix = ">"
|
||||
|
||||
go func() {
|
||||
reader := bufio.NewReader(out)
|
||||
for {
|
||||
b, err := reader.ReadByte()
|
||||
@@ -245,7 +380,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
break
|
||||
}
|
||||
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||
app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(app.cmdOutBuf)}}, 1}
|
||||
app.ui.exprChan <- &callExpr{"echo", []string{string(app.cmdOutBuf)}, 1}
|
||||
if b == '\n' || b == '\r' {
|
||||
app.cmdOutBuf = nil
|
||||
}
|
||||
@@ -256,7 +391,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
app.cmd = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
app.ui.exprChan <- multiExpr{&callExpr{"reload", nil}, 1}
|
||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -8,32 +8,37 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
func run() {
|
||||
logFile, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(gLogPath)
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
if err := termbox.Init(); err != nil {
|
||||
log.Fatalf("initializing termbox: %s", err)
|
||||
}
|
||||
defer termbox.Close()
|
||||
|
||||
termbox.SetOutputMode(termbox.Output256)
|
||||
setColorMode()
|
||||
|
||||
f, err := os.Create(gLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.Remove(gLogPath)
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
app := newApp()
|
||||
|
||||
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
|
||||
app.readFile(gConfigPath)
|
||||
if err := app.nav.readMarks(); err != nil {
|
||||
app.ui.echoerrf("reading marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := app.readHistory(); err != nil {
|
||||
app.ui.echoerrf("reading history file: %s", err)
|
||||
}
|
||||
|
||||
app.loop()
|
||||
@@ -43,15 +48,19 @@ func readExpr() <-chan expr {
|
||||
ch := make(chan expr)
|
||||
|
||||
go func() {
|
||||
duration := 1 * time.Second
|
||||
|
||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||
if err != nil {
|
||||
for err != nil {
|
||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
||||
return
|
||||
time.Sleep(duration)
|
||||
duration *= 2
|
||||
c, err = net.Dial(gSocketProt, gSocketPath)
|
||||
}
|
||||
|
||||
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||
|
||||
ch <- &callExpr{"sync", nil}
|
||||
ch <- &callExpr{"sync", nil, 1}
|
||||
|
||||
s := bufio.NewScanner(c)
|
||||
for s.Scan() {
|
||||
@@ -68,7 +77,7 @@ func readExpr() <-chan expr {
|
||||
return ch
|
||||
}
|
||||
|
||||
func saveFiles(list []string, copy bool) error {
|
||||
func saveFiles(list []string, cp bool) error {
|
||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("dialing to save files: %s", err)
|
||||
@@ -79,7 +88,7 @@ func saveFiles(list []string, copy bool) error {
|
||||
|
||||
fmt.Fprintln(c, "save")
|
||||
|
||||
if copy {
|
||||
if cp {
|
||||
fmt.Fprintln(c, "copy")
|
||||
} else {
|
||||
fmt.Fprintln(c, "move")
|
||||
@@ -93,7 +102,7 @@ func saveFiles(list []string, copy bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadFiles() (list []string, copy bool, err error) {
|
||||
func loadFiles() (list []string, cp bool, err error) {
|
||||
c, e := net.Dial(gSocketProt, gSocketPath)
|
||||
if e != nil {
|
||||
err = fmt.Errorf("dialing to load files: %s", e)
|
||||
@@ -109,9 +118,9 @@ func loadFiles() (list []string, copy bool, err error) {
|
||||
|
||||
switch s.Text() {
|
||||
case "copy":
|
||||
copy = true
|
||||
cp = true
|
||||
case "move":
|
||||
copy = false
|
||||
cp = false
|
||||
default:
|
||||
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
||||
return
|
||||
@@ -131,7 +140,7 @@ func loadFiles() (list []string, copy 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)
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||
|
||||
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 {
|
||||
if env := os.Getenv("LS_COLORS"); env != "" {
|
||||
return parseColorsGNU(env)
|
||||
}
|
||||
|
||||
if env := os.Getenv("LSCOLORS"); env != "" {
|
||||
return parseColorsBSD(env)
|
||||
}
|
||||
|
||||
// default values from dircolors with removed background colors
|
||||
defaultColors := []string{
|
||||
// "rs=0",
|
||||
"di=01;34",
|
||||
"ln=01;36",
|
||||
// "mh=00",
|
||||
"pi=33", // "pi=40;33",
|
||||
"so=01;35",
|
||||
"do=01;35",
|
||||
"bd=33;01", // "bd=40;33;01",
|
||||
"cd=33;01", // "cd=40;33;01",
|
||||
"or=31;01", // "or=40;31;01",
|
||||
// "mi=00",
|
||||
"su=01;32", // "su=37;41",
|
||||
"sg=01;32", // "sg=30;43",
|
||||
// "ca=30;41",
|
||||
"tw=01;34", // "tw=30;42",
|
||||
"ow=01;34", // "ow=34;42",
|
||||
"st=01;34", // "st=37;44",
|
||||
"ex=01;32",
|
||||
}
|
||||
|
||||
return parseColorsGNU(strings.Join(defaultColors, ":"))
|
||||
}
|
||||
|
||||
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) {
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
var nums []int
|
||||
for _, tok := range toks {
|
||||
if tok == "" {
|
||||
nums = append(nums, 0)
|
||||
continue
|
||||
}
|
||||
n, err := strconv.Atoi(tok)
|
||||
if err != nil {
|
||||
log.Printf("converting escape code: %s", err)
|
||||
continue
|
||||
}
|
||||
nums = append(nums, n)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return fg, bg
|
||||
}
|
||||
|
||||
// This function parses $LS_COLORS environment variable.
|
||||
func parseColorsGNU(env string) colorMap {
|
||||
colors := make(colorMap)
|
||||
|
||||
entries := strings.Split(env, ":")
|
||||
for _, entry := range entries {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
pair := strings.Split(entry, "=")
|
||||
if len(pair) != 2 {
|
||||
log.Printf("invalid $LS_COLORS entry: %s", entry)
|
||||
return colors
|
||||
}
|
||||
key, val := pair[0], pair[1]
|
||||
fg, bg := applyAnsiCodes(val, termbox.ColorDefault, termbox.ColorDefault)
|
||||
colors[key] = colorEntry{fg: fg, bg: bg}
|
||||
}
|
||||
|
||||
return colors
|
||||
}
|
||||
|
||||
// This function parses $LSCOLORS environment variable.
|
||||
func parseColorsBSD(env string) colorMap {
|
||||
colors := make(colorMap)
|
||||
|
||||
if len(env) != 22 {
|
||||
log.Printf("invalid $LSCOLORS variable: %s", env)
|
||||
return colors
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
log.Printf("invalid $LSCOLORS entry: %c", r)
|
||||
return termbox.ColorDefault
|
||||
}
|
||||
|
||||
for i, key := range colorNames {
|
||||
colors[key] = colorEntry{fg: getColor(env[i*2]), bg: getColor(env[i*2+1])}
|
||||
}
|
||||
|
||||
return colors
|
||||
}
|
||||
|
||||
func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
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 := cm[key]; ok {
|
||||
return val.fg, val.bg
|
||||
}
|
||||
|
||||
if val, ok := cm["fi"]; ok {
|
||||
return val.fg, val.bg
|
||||
}
|
||||
|
||||
return termbox.ColorDefault, termbox.ColorDefault
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
func TestApplyAnsiCodes(t *testing.T) {
|
||||
none := termbox.ColorDefault
|
||||
|
||||
tests := []struct {
|
||||
s string
|
||||
fg termbox.Attribute
|
||||
bg termbox.Attribute
|
||||
fgExp termbox.Attribute
|
||||
bgExp termbox.Attribute
|
||||
}{
|
||||
{"", none, none, none, none},
|
||||
{"", termbox.ColorRed, termbox.ColorRed, none, none},
|
||||
{"", termbox.AttrBold, none, none, none},
|
||||
{"", termbox.ColorRed | termbox.AttrBold, none, none, 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},
|
||||
|
||||
{"1", none, none, termbox.AttrBold, none},
|
||||
{"4", none, none, termbox.AttrUnderline, none},
|
||||
{"7", none, none, termbox.AttrReverse, none},
|
||||
|
||||
{"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},
|
||||
|
||||
{"4", termbox.AttrBold, none, termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
{"4", termbox.ColorRed | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold | termbox.AttrUnderline, none},
|
||||
|
||||
{"31", none, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"31", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"41", none, none, none, termbox.ColorRed},
|
||||
{"41", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
|
||||
{"1;31", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;31", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"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;1", termbox.ColorGreen, none, termbox.ColorRed, none},
|
||||
{"38;5;1", termbox.ColorGreen | termbox.AttrBold, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
|
||||
{"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;1", none, termbox.ColorGreen, none, termbox.ColorRed},
|
||||
|
||||
{"1;38;5;1", none, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
{"1;38;5;1", termbox.ColorGreen, none, termbox.ColorRed | termbox.AttrBold, none},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
-50
@@ -24,39 +24,60 @@ var (
|
||||
"open",
|
||||
"quit",
|
||||
"top",
|
||||
"bot",
|
||||
"bottom",
|
||||
"toggle",
|
||||
"invert",
|
||||
"unmark",
|
||||
"yank",
|
||||
"unselect",
|
||||
"copy",
|
||||
"cut",
|
||||
"paste",
|
||||
"delete",
|
||||
"put",
|
||||
"clear",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"read",
|
||||
"shell",
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
"shell-async",
|
||||
"find",
|
||||
"find-back",
|
||||
"find-next",
|
||||
"find-prev",
|
||||
"search",
|
||||
"search-back",
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"mark-save",
|
||||
"mark-load",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"source",
|
||||
"push",
|
||||
}
|
||||
|
||||
gOptWords = []string{
|
||||
"anchorfind",
|
||||
"noanchorfind",
|
||||
"anchorfind!",
|
||||
"color256",
|
||||
"nocolor256",
|
||||
"color256!",
|
||||
"dircounts",
|
||||
"nodircounts",
|
||||
"dircounts!",
|
||||
"dirfirst",
|
||||
"nodirfirst",
|
||||
"dirfirst!",
|
||||
"drawbox",
|
||||
"nodrawbox",
|
||||
"drawbox!",
|
||||
"globsearch",
|
||||
"noglobsearch",
|
||||
"globsearch!",
|
||||
@@ -66,6 +87,12 @@ var (
|
||||
"ignorecase",
|
||||
"noignorecase",
|
||||
"ignorecase!",
|
||||
"ignoredia",
|
||||
"noignoredia",
|
||||
"ignoredia!",
|
||||
"incsearch",
|
||||
"noincsearch",
|
||||
"incsearch!",
|
||||
"preview",
|
||||
"nopreview",
|
||||
"preview!",
|
||||
@@ -75,11 +102,23 @@ var (
|
||||
"smartcase",
|
||||
"nosmartcase",
|
||||
"smartcase!",
|
||||
"smartdia",
|
||||
"nosmartdia",
|
||||
"smartdia!",
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
"relativenumber",
|
||||
"norelativenumber",
|
||||
"relativenumber!",
|
||||
"findlen",
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"errorfmt",
|
||||
"filesep",
|
||||
"ifs",
|
||||
"previewer",
|
||||
@@ -89,6 +128,7 @@ var (
|
||||
"timefmt",
|
||||
"ratios",
|
||||
"info",
|
||||
"shellopts",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -104,13 +144,15 @@ func matchLongest(s1, s2 string) string {
|
||||
|
||||
func matchWord(s string, words []string) (matches []string, longest string) {
|
||||
for _, w := range words {
|
||||
if strings.HasPrefix(w, s) {
|
||||
matches = append(matches, w)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, w)
|
||||
} else if s != "" {
|
||||
longest = w + " "
|
||||
}
|
||||
if !strings.HasPrefix(w, s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, w)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, w)
|
||||
} else if s != "" {
|
||||
longest = w + " "
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,32 +166,35 @@ func matchWord(s string, words []string) (matches []string, longest string) {
|
||||
func matchExec(s string) (matches []string, longest string) {
|
||||
var words []string
|
||||
|
||||
paths := strings.Split(envPath, ":")
|
||||
paths := strings.Split(envPath, string(filepath.ListSeparator))
|
||||
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
fi, err := ioutil.ReadDir(p)
|
||||
files, err := ioutil.ReadDir(p)
|
||||
if err != nil {
|
||||
log.Printf("reading path: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range fi {
|
||||
if strings.HasPrefix(f.Name(), s) {
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !f.Mode().IsRegular() || f.Mode()&0111 == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
words = append(words, f.Name())
|
||||
for _, f := range files {
|
||||
if !strings.HasPrefix(f.Name(), s) {
|
||||
continue
|
||||
}
|
||||
|
||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !f.Mode().IsRegular() || !isExecutable(f) {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Print(f.Name())
|
||||
words = append(words, f.Name())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +220,19 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
} else {
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
|
||||
dir = unescape(filepath.Dir(dir))
|
||||
|
||||
fi, err := ioutil.ReadDir(dir)
|
||||
files, err := ioutil.ReadDir(dir)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
for _, f := range fi {
|
||||
for _, f := range files {
|
||||
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
||||
if err != nil {
|
||||
log.Printf("getting file information: %s", err)
|
||||
@@ -194,25 +240,29 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
}
|
||||
|
||||
_, last := filepath.Split(s)
|
||||
if strings.HasPrefix(escape(f.Name()), last) {
|
||||
name := f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += string(filepath.Separator)
|
||||
}
|
||||
matches = append(matches, item)
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, name)
|
||||
} else if s != "" {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + string(filepath.Separator)
|
||||
}
|
||||
if !strings.HasPrefix(escape(f.Name()), last) {
|
||||
continue
|
||||
}
|
||||
|
||||
name := f.Name()
|
||||
if isRoot(s) || filepath.Base(s) != s {
|
||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||
}
|
||||
name = escape(name)
|
||||
|
||||
item := f.Name()
|
||||
if f.Mode().IsDir() {
|
||||
item += string(filepath.Separator)
|
||||
}
|
||||
matches = append(matches, item)
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, name)
|
||||
} else if s != "" {
|
||||
if f.Mode().IsRegular() {
|
||||
longest = name + " "
|
||||
} else {
|
||||
longest = name + string(filepath.Separator)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -224,7 +274,7 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
return
|
||||
}
|
||||
|
||||
func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
@@ -237,6 +287,15 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
words = append(words, c)
|
||||
}
|
||||
sort.Strings(words)
|
||||
j := 0
|
||||
for i := 1; i < len(words); i++ {
|
||||
if words[j] == words[i] {
|
||||
continue
|
||||
}
|
||||
j++
|
||||
words[i], words[j] = words[j], words[i]
|
||||
}
|
||||
words = words[:j+1]
|
||||
matches, longest = matchWord(s, words)
|
||||
longestAcc = []rune(longest)
|
||||
case 2:
|
||||
@@ -263,7 +322,45 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
return
|
||||
}
|
||||
|
||||
func compShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
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)
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,128 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func copySize(srcs []string) (int64, error) {
|
||||
var total int64
|
||||
|
||||
for _, src := range srcs {
|
||||
_, err := os.Stat(src)
|
||||
if os.IsNotExist(err) {
|
||||
return total, fmt.Errorf("src does not exist: %q", src)
|
||||
}
|
||||
|
||||
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("walk: %s", err)
|
||||
}
|
||||
total += info.Size()
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
}
|
||||
|
||||
return total, nil
|
||||
}
|
||||
|
||||
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
||||
buf := make([]byte, 4096)
|
||||
|
||||
r, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
w, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
n, err := r.Read(buf)
|
||||
if err != nil && err != io.EOF {
|
||||
w.Close()
|
||||
os.Remove(dst)
|
||||
return err
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
if _, err := w.Write(buf[:n]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nums <- int64(n)
|
||||
}
|
||||
|
||||
if err := w.Close(); err != nil {
|
||||
os.Remove(dst)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Chmod(dst, info.Mode()); err != nil {
|
||||
os.Remove(dst)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
||||
nums = make(chan int64, 1024)
|
||||
errs = make(chan error, 1024)
|
||||
|
||||
go func() {
|
||||
for _, src := range srcs {
|
||||
dst := filepath.Join(dstDir, filepath.Base(src))
|
||||
|
||||
_, err := os.Stat(dst)
|
||||
if !os.IsNotExist(err) {
|
||||
var newPath string
|
||||
for i := 1; !os.IsNotExist(err); i++ {
|
||||
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||
_, err = os.Stat(newPath)
|
||||
}
|
||||
dst = newPath
|
||||
}
|
||||
|
||||
filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("walk: %s", err)
|
||||
return nil
|
||||
}
|
||||
rel, err := filepath.Rel(src, path)
|
||||
if err != nil {
|
||||
errs <- fmt.Errorf("relative: %s", err)
|
||||
return nil
|
||||
}
|
||||
newPath := filepath.Join(dst, rel)
|
||||
if info.IsDir() {
|
||||
if err := os.MkdirAll(newPath, info.Mode()); err != nil {
|
||||
errs <- fmt.Errorf("mkdir: %s", err)
|
||||
}
|
||||
nums <- info.Size()
|
||||
} else {
|
||||
if err := copyFile(path, newPath, info, nums); err != nil {
|
||||
errs <- fmt.Errorf("copy: %s", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
close(errs)
|
||||
}()
|
||||
|
||||
return nums, errs
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var normMap map[rune]rune
|
||||
|
||||
func init() {
|
||||
normMap = make(map[rune]rune)
|
||||
|
||||
// (not only) european
|
||||
appendTransliterate(
|
||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||
true,
|
||||
)
|
||||
|
||||
// Vietnamese
|
||||
appendTransliterate(
|
||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||
true,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func appendTransliterate(base, norm string, uppercase bool) {
|
||||
normRunes := []rune(norm)
|
||||
baseRunes := []rune(base)
|
||||
|
||||
lenNorm := len(normRunes)
|
||||
lenBase := len(baseRunes)
|
||||
if lenNorm != lenBase {
|
||||
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]
|
||||
}
|
||||
|
||||
if uppercase {
|
||||
upperBase := strings.ToUpper(base)
|
||||
upperNorm := strings.ToUpper(norm)
|
||||
normRune := []rune(upperNorm)
|
||||
for i, baseRune := range []rune(upperBase) {
|
||||
normMap[baseRune] = normRune[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove diacritics and make lowercase.
|
||||
func removeDiacritics(baseString string) string {
|
||||
var normalizedRunes []rune
|
||||
for _, baseRune := range []rune(baseString) {
|
||||
if normRune, ok := normMap[baseRune]; ok {
|
||||
normalizedRunes = append(normalizedRunes, normRune)
|
||||
} else {
|
||||
normalizedRunes = append(normalizedRunes, baseRune)
|
||||
}
|
||||
}
|
||||
return string(normalizedRunes)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// typical czech test sentence ;-)
|
||||
const baseTestString = "Příliš žluťoučký kůň příšerně úpěl ďábelské ódy"
|
||||
|
||||
func TestRemoveDiacritics(t *testing.T) {
|
||||
testStr := baseTestString
|
||||
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
|
||||
checkRemoveDiacritics(testStr, expStr, t)
|
||||
|
||||
// other accents (non comlete, but all I founded)
|
||||
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
|
||||
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
|
||||
checkRemoveDiacritics(testStr, expStr, t)
|
||||
|
||||
testStr = "ÁÉÍÓÚÝČĎĚŇŘŠŤŽŮÅØĈĜĤĴŜŬŠŽÕÄÖÜÀÂÇÉÈÊËÎÏÔÙÛÜŸŽŠČĆĐÁÉÍÓÚĄĘĖĮŲŪČŠŽĀĒĪŪČŠŽĻĶŅĢÁÉÍÓÚÖÜŐŰÄÖÜËÏĄĆĘŁŃÓŚŹŻÁÀÃÂÇÉÊÍÓÕÔĂÂÎȘȚÁÄČĎÉÍĹĽŇÓÔŔŠŤÚÝŽÁÉÍÑÓÚÜÅÄÖÂÇÎŞÛĞĂÂĐÊÔƠƯÁÀÃẢẠ"
|
||||
expStr = "AEIOUYCDENRSTZUAOCGHJSUSZOAOUAACEEEEIIOUUUYZSCCDAEIOUAEEIUUCSZAEIUCSZLKNGAEIOUOUOUAOUEIACELNOSZZAAAACEEIOOOAAISTAACDEILLNOORSTUYZAEINOUUAAOACISUGAADEOOUAAAAA"
|
||||
checkRemoveDiacritics(testStr, expStr, t)
|
||||
|
||||
testStr = "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ"
|
||||
expStr = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd"
|
||||
checkRemoveDiacritics(testStr, expStr, t)
|
||||
|
||||
testStr = "ÁẠÀẢÃĂẮẶẰẲẴÂẤẬẦẨẪÉẸÈẺẼÊẾỆỀỂỄÍỊÌỈĨÓỌÒỎÕÔỐỘỒỔỖƠỚỢỜỞỠÚỤÙỦŨƯỨỰỪỬỮÝỴỲỶỸĐ"
|
||||
expStr = "AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD"
|
||||
checkRemoveDiacritics(testStr, expStr, t)
|
||||
}
|
||||
|
||||
func checkRemoveDiacritics(testStr string, expStr string, t *testing.T) {
|
||||
resultStr := removeDiacritics(testStr)
|
||||
if resultStr != expStr {
|
||||
t.Errorf("at input '%v' expected '%v' but got '%v'", testStr, expStr, resultStr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchSettings(t *testing.T) {
|
||||
runSearch(t, true, false, true, true, "Veřejný", "vere", true)
|
||||
|
||||
runSearch(t, true, false, true, false, baseTestString, "Zlutoucky", true)
|
||||
runSearch(t, true, false, true, false, baseTestString, "zlutoucky", true)
|
||||
runSearch(t, true, true, true, false, baseTestString, "Zlutoucky", false)
|
||||
runSearch(t, true, true, true, true, baseTestString, "zlutoucky", true)
|
||||
|
||||
runSearch(t, false, false, true, false, baseTestString, "žlutoucky", true)
|
||||
runSearch(t, false, false, true, false, baseTestString, "Žlutoucky", false)
|
||||
|
||||
runSearch(t, false, false, true, true, baseTestString, "žluťoučký", true)
|
||||
runSearch(t, false, false, true, false, baseTestString, "žluťoučký", true)
|
||||
runSearch(t, false, false, false, false, baseTestString, "žluťoučký", true)
|
||||
runSearch(t, false, false, false, false, baseTestString, "zlutoucky", false)
|
||||
runSearch(t, false, false, true, true, baseTestString, "zlutoucky", true)
|
||||
}
|
||||
|
||||
func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacritics bool, base, pattern string, expected bool) {
|
||||
gOpts.ignorecase = ignorecase
|
||||
gOpts.smartcase = smartcase
|
||||
gOpts.ignoredia = ignorediacritics
|
||||
gOpts.smartdia = smartdiacritics
|
||||
matched, _ := searchMatch(base, pattern)
|
||||
if matched != expected {
|
||||
t.Errorf("False search for" +
|
||||
" ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " +
|
||||
" smartcase = " + strconv.FormatBool(gOpts.smartcase) + ", " +
|
||||
" ignoredia = " + strconv.FormatBool(gOpts.ignoredia) + ", " +
|
||||
" smartdia = " + strconv.FormatBool(gOpts.smartdia) + ", ")
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
//go:generate gen/docstring.sh
|
||||
//go:generate gen/man.sh
|
||||
|
||||
/*
|
||||
lf is a terminal file manager.
|
||||
@@ -6,101 +7,156 @@ lf is a terminal file manager.
|
||||
Source code can be found in the repository at https://github.com/gokcehan/lf.
|
||||
|
||||
This documentation can either be read from terminal using 'lf -doc' or online
|
||||
at https://godoc.org/github.com/gokcehan/lf.
|
||||
at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command
|
||||
(default '<f-1>') inside lf to view the documentation in a pager.
|
||||
|
||||
You can run 'lf -help' to see descriptions of command line options.
|
||||
|
||||
Reference
|
||||
|
||||
The following commands are provided by lf with default keybindings:
|
||||
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg')
|
||||
bot (default 'G')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
yank (default 'y')
|
||||
delete (default 'd')
|
||||
put (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 '&')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
sync synchronizes yanked/deleted 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
|
||||
push simulate key pushes given in its argument
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
|
||||
The following command line commands are provided by lf with default
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-comp (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-hist-next (default '<c-n>')
|
||||
cmd-hist-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-beg (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-beg (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-word (default '<c-w>')
|
||||
cmd-put (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
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 '')
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default '') (not exported if empty)
|
||||
previewer string (default '') (not filtered if empty)
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default '')
|
||||
shellopts string (default '')
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
|
||||
$f current file
|
||||
$fs marked file(s) separated with 'filesep'
|
||||
$fx current file or marked file(s) if any
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
The following variables are set to the corresponding values:
|
||||
|
||||
$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
|
||||
|
||||
The following additional keybindings are provided by default:
|
||||
|
||||
map zh set hidden!
|
||||
@@ -114,28 +170,37 @@ The following additional keybindings are provided by default:
|
||||
map st :set sortby time; set info time
|
||||
map gh cd ~
|
||||
|
||||
The following keybindings to applications are provided by default on unix:
|
||||
The following keybindings to applications are provided by default:
|
||||
|
||||
map e $$EDITOR $f ('vi' if empty)
|
||||
map i $$PAGER $f ('less' if empty)
|
||||
map w $$SHELL ('sh' if empty)
|
||||
|
||||
The following keybindings to applications are provided by default on windows:
|
||||
|
||||
map e $notepad "%f%"
|
||||
map i $more "%f%"
|
||||
map w $cmd
|
||||
map e $$EDITOR $f
|
||||
map i $$PAGER $f
|
||||
map w $$SHELL
|
||||
|
||||
Configuration
|
||||
|
||||
The configuration file should be located at:
|
||||
Configuration files should be located at:
|
||||
|
||||
$XDG_CONFIG_HOME/lf/lfrc
|
||||
os system-wide user-specific
|
||||
unix /etc/lf/lfrc ~/.config/lf/lfrc
|
||||
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||
|
||||
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
|
||||
location should be:
|
||||
Marks file should be located at:
|
||||
|
||||
~/.config/lf/lfrc
|
||||
unix ~/.local/share/lf/marks
|
||||
windows C:\Users\<user>\AppData\Local\lf\marks
|
||||
|
||||
History file should be located at:
|
||||
|
||||
unix ~/.local/share/lf/history
|
||||
windows C:\Users\<user>\AppData\Local\lf\history
|
||||
|
||||
You can configure the default values of following variables to change these
|
||||
locations:
|
||||
|
||||
$XDG_CONFIG_HOME ~/.config
|
||||
$XDG_DATA_HOME ~/.local/share
|
||||
%ProgramData% C:\ProgramData
|
||||
%LOCALAPPDATA% C:\Users\<user>\AppData\Local
|
||||
|
||||
A sample configuration file can be found at
|
||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||
@@ -152,10 +217,11 @@ The following command prefixes are used by lf:
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file. The
|
||||
difference is that prefixes are not necessary in the command line. Instead
|
||||
different modes are provided to read corresponding commands. Note that by
|
||||
default these modes are mapped to the prefix keys above.
|
||||
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.
|
||||
|
||||
Syntax
|
||||
|
||||
@@ -166,7 +232,8 @@ Characters from '#' to newline are comments and ignored:
|
||||
There are three special commands ('set', 'map', and 'cmd') and their variants
|
||||
for configuration.
|
||||
|
||||
'set' is used to set an option which can be boolean, integer, or string:
|
||||
Command 'set' is used to set an option which can be boolean, integer, or
|
||||
string:
|
||||
|
||||
set hidden # boolean on
|
||||
set nohidden # boolean off
|
||||
@@ -176,16 +243,16 @@ for configuration.
|
||||
set sortby 'time' # string value with single quotes (whitespaces)
|
||||
set sortby "time" # string value with double quotes (backslash escapes)
|
||||
|
||||
'map' is used to bind a key to a command which can be builtin command, custom
|
||||
command, or shell command:
|
||||
Command 'map' is used to bind a key to a command which can be builtin command,
|
||||
custom command, or shell command:
|
||||
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom command
|
||||
map i $less $f # shell command
|
||||
map u !du -h . # waiting shell command
|
||||
map U !du -sh # waiting shell command
|
||||
|
||||
'cmap' is used to bind a key to a command line command which can only be one of
|
||||
the builtin commands:
|
||||
Command 'cmap' is used to bind a key to a command line command which can only
|
||||
be one of the builtin commands:
|
||||
|
||||
cmap <c-g> cmd-escape
|
||||
|
||||
@@ -194,9 +261,9 @@ You can delete an existing binding by leaving the expression empty:
|
||||
map gh # deletes 'gh' mapping
|
||||
cmap <c-g> # deletes '<c-g>' mapping
|
||||
|
||||
'cmd' is used to define a custom command
|
||||
Command 'cmd' is used to define a custom command:
|
||||
|
||||
cmd usage $du -h . | less
|
||||
cmd usage $du -h -d1 | less
|
||||
|
||||
You can delete an existing command by leaving the expression empty:
|
||||
|
||||
@@ -219,6 +286,53 @@ prefix.
|
||||
set info time
|
||||
}}
|
||||
|
||||
Key Mappings
|
||||
|
||||
Regular keys are assigned to a command with the usual syntax:
|
||||
|
||||
map a down
|
||||
|
||||
Keys combined with the shift key simply use the uppercase letter:
|
||||
|
||||
map A down
|
||||
|
||||
Special keys are written in between '<' and '>' characters and always use
|
||||
lowercase letters:
|
||||
|
||||
map <enter> down
|
||||
|
||||
Angle brackets can be assigned with their special names:
|
||||
|
||||
map <lt> down
|
||||
map <gt> down
|
||||
|
||||
Function keys are prefixed with 'f' character:
|
||||
|
||||
map <f-1> down
|
||||
|
||||
Keys combined with the control key are prefixed with 'c' character:
|
||||
|
||||
map <c-a> down
|
||||
|
||||
Keys combined with the alt key are assigned in two different ways depending on
|
||||
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
|
||||
of a character when the alt key is pressed. On these terminals, you can use the
|
||||
corresponding byte for the mapping:
|
||||
|
||||
map á down
|
||||
|
||||
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
|
||||
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
|
||||
with the alt key are prefixed with 'a' character:
|
||||
|
||||
map <a-a> down
|
||||
|
||||
Please note that, some key combinations are not possible due to the way
|
||||
terminals work (e.g. control and h combination sends a backspace key instead).
|
||||
The easiest way to find the name of a key combination is to press the key while
|
||||
lf is running and read the name of the key from the unknown mapping error.
|
||||
|
||||
Push Mappings
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -259,7 +373,7 @@ trash. A first attempt to write such a command may look like this:
|
||||
fi
|
||||
}}
|
||||
|
||||
We check '$fs' to see if there are any marked files. Otherwise we just delete
|
||||
We check '$fs' to see if there are any selected files. Otherwise we just delete
|
||||
the current file. Since this is such a common pattern, a separate '$fx'
|
||||
variable is provided. We can use this variable to get rid of the conditional:
|
||||
|
||||
@@ -368,7 +482,7 @@ Since lf does not have control flow syntax, remote commands are used for such
|
||||
needs. For example, you can configure the number of columns in the ui with
|
||||
respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -388,84 +502,130 @@ Setting the file selection is done with 'save' command:
|
||||
|
||||
Getting the file selection is similarly done with 'load' command:
|
||||
|
||||
resp=$(lf -remote 'load')
|
||||
mode=$(echo "$resp" | sed -n '1p')
|
||||
list=$(echo "$resp" | sed '1d')
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
# do something with $list
|
||||
elif [ $mode = 'move' ]; then
|
||||
# do something else with $list
|
||||
fi
|
||||
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
|
||||
lf -remote 'quit'
|
||||
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||
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 'yank' (i.e. 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 do the 'put' in which case the 'cp' command is
|
||||
used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
||||
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and 'put')
|
||||
are picked instead of the other common convention (e.g. copy and cut) to
|
||||
resemble the default keybinds for these operations.
|
||||
lf uses its own builtin copy and move operations by default. These are
|
||||
implemented as asynchronous operations and progress is shown in the bottom
|
||||
ruler. These commands do not overwrite existing files or directories with the
|
||||
same name. Instead, a suffix that is compatible with '--backup=numbered' option
|
||||
in GNU cp is added to the new files or directories. Only file modes are
|
||||
preserved and all other attributes are ignored including ownership, timestamps,
|
||||
context, links, and xattr. Special files such as character and block devices,
|
||||
named pipes, and sockets are skipped and links are followed. Moving is
|
||||
performed using the rename operation of the underlying OS. This can fail to
|
||||
move files between different partitions when it needs to copy files. For these
|
||||
cases, users are expected to explicitly copy files and then delete the old ones
|
||||
manually. Operation errors are shown in the message line as well as the log
|
||||
file and they do not preemptively finish the corresponding file operation.
|
||||
|
||||
You can customize these operations by defining a 'put' 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.
|
||||
|
||||
cmd put ${{
|
||||
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 $id reload"
|
||||
lf -remote "$(printf 'save\nmove\n\n')"
|
||||
lf -remote "send sync"
|
||||
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 provide an actual file deletion command to protect new
|
||||
users. You can define such a command and optionally assign a key if you like.
|
||||
An example command to move selected files to a trash folder and remove files
|
||||
completely are provided in the example configuration file.
|
||||
By default, lf does not assign 'delete' command to a key to protect new users.
|
||||
You can customize file deletion by defining a 'delete' command. You can also
|
||||
assign a key to this command if you like. An example command to move selected
|
||||
files to a trash folder and remove files completely after a prompt are provided
|
||||
in the example configuration file.
|
||||
|
||||
Searching Files
|
||||
|
||||
There are two mechanisms implemented in lf to search a file in the current
|
||||
directory. Searching is the traditional method to move the selection to a file
|
||||
matching a given pattern. Finding is an alternative way to search for a pattern
|
||||
possibly using fewer keystrokes.
|
||||
|
||||
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||
(default 'N'). You can enable 'globsearch' option to match with a glob pattern.
|
||||
Globbing supports '*' to match any sequence, '?' to match any character, and
|
||||
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||
'incsearch' option to jump to the current match at each keystroke while typing.
|
||||
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||
'cmd-escape' to cancel the search.
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||
position in the filename instead of the beginning. You can set the number of
|
||||
keys to match using 'findlen' option. If you set this value to zero, then the
|
||||
the keys are read until there is only a single match. Default values of these
|
||||
two options are set to jump to the first file with the given initial.
|
||||
|
||||
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||
option to prevent searches to wrap around at the end of the file list. You can
|
||||
disable 'ignorecase' option to match cases in the pattern and the filename.
|
||||
This option is already automatically overridden if the pattern contains upper
|
||||
case characters. You can disable 'smartcase' option to disable this behavior.
|
||||
Two similar options 'ignoredia' and 'smartdia' are provided to control matching
|
||||
diacritics in latin letters.
|
||||
|
||||
Opening Files
|
||||
|
||||
You can use 'open-file' command to open a file. This is a special command
|
||||
called by 'open' when the current file is not a directory. Normally a user maps
|
||||
the 'open' command to a key (default 'l') and customize 'open-file' command as
|
||||
desired. You can define it just as you would define any other command:
|
||||
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||
file opening. This command is only called when the current file is not a
|
||||
directory, otherwise the directory is entered instead. You can define it just
|
||||
as you would define any other command:
|
||||
|
||||
cmd open-file $vi $fx
|
||||
cmd open $vi $fx
|
||||
|
||||
It is possible to use different command types:
|
||||
|
||||
cmd open-file &xdg-open $f
|
||||
cmd open &xdg-open $f
|
||||
|
||||
You may want to use either file extensions or mime types from 'file' command:
|
||||
|
||||
cmd open-file ${{
|
||||
cmd open ${{
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) vi $fx;;
|
||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
Following commands are provided by default:
|
||||
Following command is provided by default:
|
||||
|
||||
cmd open-file &start "" "%f%" # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
cmd open &$OPENER $f
|
||||
|
||||
You may also use any other existing file openers as you like. Possible options
|
||||
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
||||
@@ -514,5 +674,47 @@ relevant for big files. lf automatically closes the previewer script output
|
||||
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.
|
||||
|
||||
Colorschemes
|
||||
|
||||
lf tries to automatically adapt its colors to the environment. On startup,
|
||||
first '$LS_COLORS' environment variable is checked. This variable is used by
|
||||
GNU ls to configure its colors based on file types and extensions. The value of
|
||||
this variable is often set by GNU dircolors in a shell configuration file.
|
||||
dircolors program itself can be configured with a configuration file. dircolors
|
||||
supports 256 colors along with common attributes such as bold and underline.
|
||||
|
||||
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead.
|
||||
This variable is used by ls programs on unix systems such as Mac and BSDs. This
|
||||
variable has a simple syntax and supports 8 colors and bold attribute.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
'promptfmt' option which can include hardcoded colors as ansi escapes. See the
|
||||
default value of this option to have an idea about how to color this line.
|
||||
*/
|
||||
package main
|
||||
+354
-146
@@ -1,4 +1,4 @@
|
||||
// DO NOT EDIT! (AUTO-GENERATED)
|
||||
// Code generated by gen/docstring.sh DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
@@ -9,102 +9,157 @@ Source code can be found in the repository at
|
||||
https://github.com/gokcehan/lf.
|
||||
|
||||
This documentation can either be read from terminal using 'lf -doc' or
|
||||
online at https://godoc.org/github.com/gokcehan/lf.
|
||||
online at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc'
|
||||
command (default '<f-1>') inside lf to view the documentation in a pager.
|
||||
|
||||
You can run 'lf -help' to see descriptions of command line options.
|
||||
|
||||
|
||||
Reference
|
||||
|
||||
The following commands are provided by lf with default keybindings:
|
||||
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg')
|
||||
bot (default 'G')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unmark (default 'u')
|
||||
yank (default 'y')
|
||||
delete (default 'd')
|
||||
put (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 '&')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
sync synchronizes yanked/deleted 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
|
||||
push simulate key pushes given in its argument
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
|
||||
The following command line commands are provided by lf with default
|
||||
keybindings:
|
||||
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-comp (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-hist-next (default '<c-n>')
|
||||
cmd-hist-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-beg (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-beg (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-word (default '<c-w>')
|
||||
cmd-put (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
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 '')
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default ”) (not exported if empty)
|
||||
previewer string (default ”) (not filtered if empty)
|
||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default ”)
|
||||
shellopts string (default ”)
|
||||
|
||||
The following variables are exported for shell commands:
|
||||
|
||||
$f current file
|
||||
$fs marked file(s) separated with 'filesep'
|
||||
$fx current file or marked file(s) if any
|
||||
$fs selected file(s) separated with 'filesep'
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
The following variables are set to the corresponding values:
|
||||
|
||||
$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
|
||||
|
||||
The following additional keybindings are provided by default:
|
||||
|
||||
map zh set hidden!
|
||||
@@ -118,30 +173,38 @@ The following additional keybindings are provided by default:
|
||||
map st :set sortby time; set info time
|
||||
map gh cd ~
|
||||
|
||||
The following keybindings to applications are provided by default on unix:
|
||||
The following keybindings to applications are provided by default:
|
||||
|
||||
map e $$EDITOR $f ('vi' if empty)
|
||||
map i $$PAGER $f ('less' if empty)
|
||||
map w $$SHELL ('sh' if empty)
|
||||
|
||||
The following keybindings to applications are provided by default on
|
||||
windows:
|
||||
|
||||
map e $notepad "%f%"
|
||||
map i $more "%f%"
|
||||
map w $cmd
|
||||
map e $$EDITOR $f
|
||||
map i $$PAGER $f
|
||||
map w $$SHELL
|
||||
|
||||
|
||||
Configuration
|
||||
|
||||
The configuration file should be located at:
|
||||
Configuration files should be located at:
|
||||
|
||||
$XDG_CONFIG_HOME/lf/lfrc
|
||||
os system-wide user-specific
|
||||
unix /etc/lf/lfrc ~/.config/lf/lfrc
|
||||
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||
|
||||
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
|
||||
location should be:
|
||||
Marks file should be located at:
|
||||
|
||||
~/.config/lf/lfrc
|
||||
unix ~/.local/share/lf/marks
|
||||
windows C:\Users\<user>\AppData\Local\lf\marks
|
||||
|
||||
History file should be located at:
|
||||
|
||||
unix ~/.local/share/lf/history
|
||||
windows C:\Users\<user>\AppData\Local\lf\history
|
||||
|
||||
You can configure the default values of following variables to change these
|
||||
locations:
|
||||
|
||||
$XDG_CONFIG_HOME ~/.config
|
||||
$XDG_DATA_HOME ~/.local/share
|
||||
%ProgramData% C:\ProgramData
|
||||
%LOCALAPPDATA% C:\Users\<user>\AppData\Local
|
||||
|
||||
A sample configuration file can be found at
|
||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||
@@ -159,10 +222,11 @@ The following command prefixes are used by lf:
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file.
|
||||
The difference is that prefixes are not necessary in the command line.
|
||||
Instead different modes are provided to read corresponding commands. Note
|
||||
that by default these modes are mapped to the prefix keys above.
|
||||
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.
|
||||
|
||||
|
||||
Syntax
|
||||
@@ -174,7 +238,8 @@ Characters from '#' to newline are comments and ignored:
|
||||
There are three special commands ('set', 'map', and 'cmd') and their
|
||||
variants for configuration.
|
||||
|
||||
'set' is used to set an option which can be boolean, integer, or string:
|
||||
Command 'set' is used to set an option which can be boolean, integer, or
|
||||
string:
|
||||
|
||||
set hidden # boolean on
|
||||
set nohidden # boolean off
|
||||
@@ -184,16 +249,16 @@ variants for configuration.
|
||||
set sortby 'time' # string value with single quotes (whitespaces)
|
||||
set sortby "time" # string value with double quotes (backslash escapes)
|
||||
|
||||
'map' is used to bind a key to a command which can be builtin command,
|
||||
custom command, or shell command:
|
||||
Command 'map' is used to bind a key to a command which can be builtin
|
||||
command, custom command, or shell command:
|
||||
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom command
|
||||
map i $less $f # shell command
|
||||
map u !du -h . # waiting shell command
|
||||
map U !du -sh # waiting shell command
|
||||
|
||||
'cmap' is used to bind a key to a command line command which can only be one
|
||||
of the builtin commands:
|
||||
Command 'cmap' is used to bind a key to a command line command which can
|
||||
only be one of the builtin commands:
|
||||
|
||||
cmap <c-g> cmd-escape
|
||||
|
||||
@@ -202,9 +267,9 @@ You can delete an existing binding by leaving the expression empty:
|
||||
map gh # deletes 'gh' mapping
|
||||
cmap <c-g> # deletes '<c-g>' mapping
|
||||
|
||||
'cmd' is used to define a custom command
|
||||
Command 'cmd' is used to define a custom command:
|
||||
|
||||
cmd usage $du -h . | less
|
||||
cmd usage $du -h -d1 | less
|
||||
|
||||
You can delete an existing command by leaving the expression empty:
|
||||
|
||||
@@ -228,6 +293,55 @@ proper prefix.
|
||||
}}
|
||||
|
||||
|
||||
Key Mappings
|
||||
|
||||
Regular keys are assigned to a command with the usual syntax:
|
||||
|
||||
map a down
|
||||
|
||||
Keys combined with the shift key simply use the uppercase letter:
|
||||
|
||||
map A down
|
||||
|
||||
Special keys are written in between '<' and '>' characters and always use
|
||||
lowercase letters:
|
||||
|
||||
map <enter> down
|
||||
|
||||
Angle brackets can be assigned with their special names:
|
||||
|
||||
map <lt> down
|
||||
map <gt> down
|
||||
|
||||
Function keys are prefixed with 'f' character:
|
||||
|
||||
map <f-1> down
|
||||
|
||||
Keys combined with the control key are prefixed with 'c' character:
|
||||
|
||||
map <c-a> down
|
||||
|
||||
Keys combined with the alt key are assigned in two different ways depending
|
||||
on the behavior of your terminal. Older terminals (e.g. xterm) may set the
|
||||
8th bit of a character when the alt key is pressed. On these terminals, you
|
||||
can use the corresponding byte for the mapping:
|
||||
|
||||
map á down
|
||||
|
||||
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||
when the alt key is pressed. lf uses the escape delaying mechanism to
|
||||
recognize alt keys in these terminals (delay is 100ms). On these terminals,
|
||||
keys combined with the alt key are prefixed with 'a' character:
|
||||
|
||||
map <a-a> down
|
||||
|
||||
Please note that, some key combinations are not possible due to the way
|
||||
terminals work (e.g. control and h combination sends a backspace key
|
||||
instead). The easiest way to find the name of a key combination is to press
|
||||
the key while lf is running and read the name of the key from the unknown
|
||||
mapping error.
|
||||
|
||||
|
||||
Push Mappings
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -271,7 +385,7 @@ this:
|
||||
fi
|
||||
}}
|
||||
|
||||
We check '$fs' to see if there are any marked files. Otherwise we just
|
||||
We check '$fs' to see if there are any selected files. Otherwise we just
|
||||
delete the current file. Since this is such a common pattern, a separate
|
||||
'$fx' variable is provided. We can use this variable to get rid of the
|
||||
conditional:
|
||||
@@ -389,7 +503,7 @@ Since lf does not have control flow syntax, remote commands are used for
|
||||
such needs. For example, you can configure the number of columns in the ui
|
||||
with respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -409,89 +523,136 @@ newline character. Setting the file selection is done with 'save' command:
|
||||
|
||||
Getting the file selection is similarly done with 'load' command:
|
||||
|
||||
resp=$(lf -remote 'load')
|
||||
mode=$(echo "$resp" | sed -n '1p')
|
||||
list=$(echo "$resp" | sed '1d')
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
# do something with $list
|
||||
elif [ $mode = 'move' ]; then
|
||||
# do something else with $list
|
||||
fi
|
||||
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
|
||||
lf -remote 'quit'
|
||||
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||
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 'yank' (i.e. 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 do the 'put' in which case the 'cp' command
|
||||
is used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
||||
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and
|
||||
'put') are picked instead of the other common convention (e.g. copy and cut)
|
||||
to resemble the default keybinds for these operations.
|
||||
lf uses its own builtin copy and move operations by default. These are
|
||||
implemented as asynchronous operations and progress is shown in the bottom
|
||||
ruler. These commands do not overwrite existing files or directories with
|
||||
the same name. Instead, a suffix that is compatible with '--backup=numbered'
|
||||
option in GNU cp is added to the new files or directories. Only file modes
|
||||
are preserved and all other attributes are ignored including ownership,
|
||||
timestamps, context, links, and xattr. Special files such as character and
|
||||
block devices, named pipes, and sockets are skipped and links are followed.
|
||||
Moving is performed using the rename operation of the underlying OS. This
|
||||
can fail to move files between different partitions when it needs to copy
|
||||
files. For these cases, users are expected to explicitly copy files and then
|
||||
delete the old ones manually. Operation errors are shown in the message line
|
||||
as well as the log file and they do not preemptively finish the
|
||||
corresponding file operation.
|
||||
|
||||
You can customize these operations by defining a 'put' 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.
|
||||
|
||||
cmd put ${{
|
||||
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 $id reload"
|
||||
lf -remote "$(printf 'save\nmove\n\n')"
|
||||
lf -remote "send sync"
|
||||
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 provide an actual file deletion command to protect
|
||||
new users. You can define such a command and optionally assign a key if you
|
||||
like. An example command to move selected files to a trash folder and remove
|
||||
files completely are provided in the example configuration file.
|
||||
By default, lf does not assign 'delete' command to a key to protect new
|
||||
users. You can customize file deletion by defining a 'delete' command. You
|
||||
can also assign a key to this command if you like. An example command to
|
||||
move selected files to a trash folder and remove files completely after a
|
||||
prompt are provided in the example configuration file.
|
||||
|
||||
|
||||
Searching Files
|
||||
|
||||
There are two mechanisms implemented in lf to search a file in the current
|
||||
directory. Searching is the traditional method to move the selection to a
|
||||
file matching a given pattern. Finding is an alternative way to search for a
|
||||
pattern possibly using fewer keystrokes.
|
||||
|
||||
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||
(default 'N'). You can enable 'globsearch' option to match with a glob
|
||||
pattern. Globbing supports '*' to match any sequence, '?' to match any
|
||||
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||
enable 'incsearch' option to jump to the current match at each keystroke
|
||||
while typing. In this mode, you can either use 'cmd-enter' to accept the
|
||||
search or use 'cmd-escape' to cancel the search.
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||
position in the filename instead of the beginning. You can set the number of
|
||||
keys to match using 'findlen' option. If you set this value to zero, then
|
||||
the the keys are read until there is only a single match. Default values of
|
||||
these two options are set to jump to the first file with the given initial.
|
||||
|
||||
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||
option to prevent searches to wrap around at the end of the file list. You
|
||||
can disable 'ignorecase' option to match cases in the pattern and the
|
||||
filename. This option is already automatically overridden if the pattern
|
||||
contains upper case characters. You can disable 'smartcase' option to
|
||||
disable this behavior. Two similar options 'ignoredia' and 'smartdia' are
|
||||
provided to control matching diacritics in latin letters.
|
||||
|
||||
|
||||
Opening Files
|
||||
|
||||
You can use 'open-file' command to open a file. This is a special command
|
||||
called by 'open' when the current file is not a directory. Normally a user
|
||||
maps the 'open' command to a key (default 'l') and customize 'open-file'
|
||||
command as desired. You can define it just as you would define any other
|
||||
command:
|
||||
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||
file opening. This command is only called when the current file is not a
|
||||
directory, otherwise the directory is entered instead. You can define it
|
||||
just as you would define any other command:
|
||||
|
||||
cmd open-file $vi $fx
|
||||
cmd open $vi $fx
|
||||
|
||||
It is possible to use different command types:
|
||||
|
||||
cmd open-file &xdg-open $f
|
||||
cmd open &xdg-open $f
|
||||
|
||||
You may want to use either file extensions or mime types from 'file'
|
||||
command:
|
||||
|
||||
cmd open-file ${{
|
||||
cmd open ${{
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) vi $fx;;
|
||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
Following commands are provided by default:
|
||||
Following command is provided by default:
|
||||
|
||||
cmd open-file &start "" "%f%" # windows
|
||||
cmd open-file &open "$f" # mac
|
||||
cmd open-file &xdg-open "$f" # others
|
||||
cmd open &$OPENER $f
|
||||
|
||||
You may also use any other existing file openers as you like. Possible
|
||||
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
||||
@@ -542,4 +703,51 @@ especially relevant for big files. lf automatically closes the previewer
|
||||
script output 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.
|
||||
|
||||
|
||||
Colorschemes
|
||||
|
||||
lf tries to automatically adapt its colors to the environment. On startup,
|
||||
first '$LS_COLORS' environment variable is checked. This variable is used by
|
||||
GNU ls to configure its colors based on file types and extensions. The value
|
||||
of this variable is often set by GNU dircolors in a shell configuration
|
||||
file. dircolors program itself can be configured with a configuration file.
|
||||
dircolors supports 256 colors along with common attributes such as bold and
|
||||
underline.
|
||||
|
||||
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked
|
||||
instead. This variable is used by ls programs on unix systems such as Mac
|
||||
and BSDs. This variable has a simple syntax and supports 8 colors and bold
|
||||
attribute.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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 'promptfmt' option which can include hardcoded colors as ansi
|
||||
escapes. See the default value of this option to have an idea about how to
|
||||
color this line.
|
||||
`
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# 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 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'
|
||||
+43
-21
@@ -1,6 +1,15 @@
|
||||
# interpreter for shell commands (needs to be POSIX compatible)
|
||||
set shell sh
|
||||
|
||||
# set '-eu' options for shell commands
|
||||
# These options are used to have safer shell commands. Option '-e' is used to
|
||||
# exit on error and option '-u' is used to give error for unset variables.
|
||||
# Option '-f' disables pathname expansion which can be useful when $f, $fs, and
|
||||
# $fx variables contain names with '*' or '?' characters. However, this option
|
||||
# is used selectively within individual commands as it can be limiting at
|
||||
# times.
|
||||
set shellopts '-eu'
|
||||
|
||||
# set internal field separator (IFS) to "\n" for shell commands
|
||||
# This is useful to automatically split file names in $fs and $fx properly
|
||||
# since default file separator used in these variables (i.e. 'filesep' option)
|
||||
@@ -22,17 +31,14 @@ map X !$f
|
||||
map o &mimeopen $f
|
||||
map O $mimeopen --ask $f
|
||||
|
||||
# show documentation (overrides 'search-back' command)
|
||||
map ? $lf -doc | less
|
||||
|
||||
# define a custom 'open-file' command
|
||||
# 'open-file' is called by 'open' when current file is not a directory. You may
|
||||
# want to use either file extensions and/or mime types here. Below uses an
|
||||
# editor for text files and a file opener for the rest.
|
||||
cmd open-file ${{
|
||||
# define a custom 'open' command
|
||||
# This command is called when current file is not a directory. You may want to
|
||||
# use either file extensions and/or mime types here. Below uses an editor for
|
||||
# text files and a file opener for the rest.
|
||||
cmd open ${{
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) vi $fx;;
|
||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||
text/*) $EDITOR $fx;;
|
||||
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
|
||||
@@ -41,23 +47,29 @@ 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 %mv $fx ~/.trash
|
||||
cmd trash %set -f; mv $fx ~/.trash
|
||||
|
||||
# remove current file or selected files (prompting)
|
||||
cmd remove ${{
|
||||
printf "$fx\n"
|
||||
printf "remove?[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/)
|
||||
cmd extract %{{
|
||||
cmd extract ${{
|
||||
set -f
|
||||
case $f in
|
||||
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
||||
*.tar.gz|*.tgz) tar xzvf $f;;
|
||||
@@ -69,9 +81,19 @@ cmd extract %{{
|
||||
}}
|
||||
|
||||
# compress current file or selected files with tar and gunzip
|
||||
cmd compress %{{
|
||||
cmd tar ${{
|
||||
set -f
|
||||
mkdir $1
|
||||
cp -r $fx $1
|
||||
tar czf $1.tar.gz $1
|
||||
rm -rf $1
|
||||
}}
|
||||
|
||||
# compress current file or selected files with zip
|
||||
cmd zip ${{
|
||||
set -f
|
||||
mkdir $1
|
||||
cp -r $fx $1
|
||||
zip -r $1.zip $1
|
||||
rm -rf $1
|
||||
}}
|
||||
+30
-30
@@ -26,85 +26,85 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"echo hello",
|
||||
[]string{"echo", "hello", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo hello world",
|
||||
[]string{"echo", "hello", "world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello", "world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello", "world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo 'hello world'",
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello world"`,
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\"world"`,
|
||||
[]string{"echo", `hello"world`, "\n"},
|
||||
[]expr{&callExpr{"echo", []string{`hello"world`}}},
|
||||
[]expr{&callExpr{"echo", []string{`hello"world`}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\tworld"`,
|
||||
[]string{"echo", "hello\tworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\nworld"`,
|
||||
[]string{"echo", "hello\nworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\zworld"`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\0world"`,
|
||||
[]string{"echo", "hello\000world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\000world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\000world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo "hello\101world"`,
|
||||
[]string{"echo", "hello\101world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\101world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\101world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
[]string{"echo", "hello world", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello world"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\ world`,
|
||||
[]string{"echo", "hello\tworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
"echo hello\\\nworld",
|
||||
[]string{"echo", "hello\nworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
`echo hello\zworld`,
|
||||
[]string{"echo", "helloworld", "\n"},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}}},
|
||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -164,25 +164,25 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map gh cd ~",
|
||||
[]string{"map", "gh", "cd", "~", "\n"},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh cd ~;",
|
||||
[]string{"map", "gh", "cd", "~", ";"},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}}}},
|
||||
[]expr{&mapExpr{"gh", &callExpr{"cd", []string{"~"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh :cd ~",
|
||||
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map gh :cd ~;",
|
||||
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}}}}}},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -206,55 +206,55 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map u usage",
|
||||
[]string{"map", "u", "usage", "\n"},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u usage;",
|
||||
[]string{"map", "u", "usage", ";"},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", nil, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u :usage",
|
||||
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map u :usage;",
|
||||
[]string{"map", "u", ":", "usage", ";", "\n"},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil}}}}},
|
||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space>",
|
||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space>;",
|
||||
[]string{"map", "r", "push", ":rename<space>;", "\n"},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>;"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r push :rename<space> # trailing comments are allowed after a space",
|
||||
[]string{"map", "r", "push", ":rename<space>", "\n"},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}}}},
|
||||
[]expr{&mapExpr{"r", &callExpr{"push", []string{":rename<space>"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
"map r :push :rename<space>",
|
||||
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 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>"}}, &setExpr{"hidden", ""}}}}},
|
||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -272,7 +272,7 @@ var gEvalTests = []struct {
|
||||
{
|
||||
"map u usage /",
|
||||
[]string{"map", "u", "usage", "/", "\n"},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}}}},
|
||||
[]expr{&mapExpr{"u", &callExpr{"usage", []string{"/"}, 1}}},
|
||||
},
|
||||
|
||||
{
|
||||
@@ -297,7 +297,7 @@ var gEvalTests = []struct {
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}},
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""}}},
|
||||
}},
|
||||
},
|
||||
@@ -312,7 +312,7 @@ var gEvalTests = []struct {
|
||||
"set", "hidden", "\n",
|
||||
"}}", "\n"},
|
||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
||||
&callExpr{"cd", []string{"~"}},
|
||||
&callExpr{"cd", []string{"~"}, 1},
|
||||
&setExpr{"hidden", ""}}},
|
||||
}},
|
||||
},
|
||||
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
# Builds a static stripped binary with version information.
|
||||
#
|
||||
# This script is used to build a binary for the current platform. Cgo is
|
||||
# disabled to make sure the binary is statically linked. Appropriate flags are
|
||||
# given to the go compiler to strip the binary. Current git tag is passed to
|
||||
# the compiler by default to be used as the version in the binary.
|
||||
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
|
||||
CGO_ENABLED=0 go build -ldflags="-s -w -X main.gVersion=$version" "$@"
|
||||
+7
-7
@@ -8,12 +8,12 @@
|
||||
|
||||
tmp=gen/docstring.go
|
||||
|
||||
echo "// DO NOT EDIT! (AUTO-GENERATED)" >> $tmp
|
||||
echo >> $tmp
|
||||
echo "package main" >> $tmp
|
||||
echo >> $tmp
|
||||
echo "var genDocString = \`" >> $tmp
|
||||
go doc | tr "\`" "'" >> $tmp
|
||||
echo "\`" >> $tmp
|
||||
echo "// Code generated by gen/docstring.sh DO NOT EDIT." >> $tmp
|
||||
echo >> $tmp
|
||||
echo "package main" >> $tmp
|
||||
echo >> $tmp
|
||||
echo "var genDocString = \`" >> $tmp
|
||||
go doc | tr "\`" "'" >> $tmp
|
||||
echo "\`" >> $tmp
|
||||
|
||||
mv $tmp docstring.go
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
#!/bin/sh
|
||||
# Generates `lf.1` man page using man macros with `go doc` output.
|
||||
#
|
||||
# This script is called in `doc.go` using `go generate` to generate a man page
|
||||
# formatted with man macros from the documentation. A few additional sections
|
||||
# such as `NAME` and `SYNOPSIS` are added to comply with man page conventions.
|
||||
#
|
||||
# Conversion logic implemented here from godoc output to man macros should not
|
||||
# be considered compliant, as such it has inexact assumptions such as the use
|
||||
# of spaces over tabs along with various corner cases that are not handled
|
||||
# properly like character escaping. The intention here is to come up with
|
||||
# something that can convert the current content in the documentation. For this
|
||||
# reason, it is recommended to check the output after generation especially
|
||||
# when the documentation is changed in a significant way.
|
||||
|
||||
out=lf.1
|
||||
|
||||
echo '.\" Code generated by gen/man.sh DO NOT EDIT.' > $out
|
||||
|
||||
cat << END >> $out
|
||||
.TH LF 1
|
||||
.SH NAME
|
||||
lf \- terminal file manager
|
||||
.SH SYNOPSIS
|
||||
.SY lf
|
||||
.OP \-cpuprofile path
|
||||
.OP \-doc
|
||||
.OP \-last-dir-path path
|
||||
.OP \-memprofile path
|
||||
.OP \-remote command
|
||||
.OP \-selection-path path
|
||||
.OP \-server
|
||||
.OP \-version
|
||||
.RI [ directory ]
|
||||
.YS
|
||||
.SH DESCRIPTION
|
||||
END
|
||||
|
||||
go doc | awk '
|
||||
BEGIN {
|
||||
RS = ""
|
||||
start = 1
|
||||
}
|
||||
|
||||
# preformatted
|
||||
/^ / {
|
||||
gsub("\\\\", "\\e", $0)
|
||||
print ".PP"
|
||||
print ".EX"
|
||||
print $0
|
||||
print ".EE"
|
||||
next
|
||||
}
|
||||
|
||||
# heading
|
||||
/^[^[:punct:]]*$/ {
|
||||
print ".SH", toupper($0)
|
||||
start = 1
|
||||
next
|
||||
}
|
||||
|
||||
# paragraph
|
||||
{
|
||||
gsub("\n", " ", $0)
|
||||
gsub("\\\\", "\\e", $0)
|
||||
if (start) { start = 0 } else { print ".PP" }
|
||||
print $0
|
||||
}
|
||||
' >> $out
|
||||
+5
-4
@@ -3,13 +3,14 @@
|
||||
#
|
||||
# This script is used to build binaries for all supported platforms. Cgo is
|
||||
# disabled to make sure binaries are statically linked. Appropriate flags are
|
||||
# given to the go compiler to strip binaries. These are then compressed in an
|
||||
# archive form (`.zip` for windows and `.tar.gz` for the rest) within a folder
|
||||
# named `dist`.
|
||||
# given to the go compiler to strip binaries. Current git tag is passed to the
|
||||
# compiler by default to be used as the version in binaries. These are then
|
||||
# compressed in an archive form (`.zip` for windows and `.tar.gz` for the rest)
|
||||
# within a folder named `dist`.
|
||||
|
||||
set -o verbose
|
||||
|
||||
version=$(git describe --tags)
|
||||
[ -z $version ] && version=$(git describe --tags)
|
||||
|
||||
mkdir -p dist
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module github.com/gokcehan/lf
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs=
|
||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
@@ -0,0 +1,638 @@
|
||||
.\" Code generated by gen/man.sh DO NOT EDIT.
|
||||
.TH LF 1
|
||||
.SH NAME
|
||||
lf \- terminal file manager
|
||||
.SH SYNOPSIS
|
||||
.SY lf
|
||||
.OP \-cpuprofile path
|
||||
.OP \-doc
|
||||
.OP \-last-dir-path path
|
||||
.OP \-memprofile path
|
||||
.OP \-remote command
|
||||
.OP \-selection-path path
|
||||
.OP \-server
|
||||
.OP \-version
|
||||
.RI [ directory ]
|
||||
.YS
|
||||
.SH DESCRIPTION
|
||||
lf is a terminal file manager.
|
||||
.PP
|
||||
Source code can be found in the repository at https://github.com/gokcehan/lf.
|
||||
.PP
|
||||
This documentation can either be read from terminal using 'lf -doc' or online at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command (default '<f-1>') inside lf to view the documentation in a pager.
|
||||
.PP
|
||||
You can run 'lf -help' to see descriptions of command line options.
|
||||
.SH REFERENCE
|
||||
The following commands are provided by lf with default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
up (default 'k' and '<up>')
|
||||
half-up (default '<c-u>')
|
||||
page-up (default '<c-b>' and '<pgup>')
|
||||
down (default 'j' and '<down>')
|
||||
half-down (default '<c-d>')
|
||||
page-down (default '<c-f>' and '<pgdn>')
|
||||
updir (default 'h' and '<left>')
|
||||
open (default 'l' and '<right>')
|
||||
quit (default 'q')
|
||||
top (default 'gg' and '<home>')
|
||||
bottom (default 'G' and '<end>')
|
||||
toggle (default '<space>')
|
||||
invert (default 'v')
|
||||
unselect (default 'u')
|
||||
copy (default 'y')
|
||||
cut (default 'd')
|
||||
paste (default 'p')
|
||||
clear (default 'c')
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
.EE
|
||||
.PP
|
||||
The following commands are provided by lf without default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronize copied/cut files with server
|
||||
echo print arguments to the message line
|
||||
echomsg same as echo but logging
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
.EE
|
||||
.PP
|
||||
The following command line commands are provided by lf with default keybindings:
|
||||
.PP
|
||||
.EX
|
||||
cmd-escape (default '<esc>')
|
||||
cmd-complete (default '<tab>')
|
||||
cmd-enter (default '<c-j>' and '<enter>')
|
||||
cmd-history-next (default '<c-n>')
|
||||
cmd-history-prev (default '<c-p>')
|
||||
cmd-delete (default '<c-d>' and '<delete>')
|
||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||
cmd-left (default '<c-b>' and '<left>')
|
||||
cmd-right (default '<c-f>' and '<right>')
|
||||
cmd-home (default '<c-a>' and '<home>')
|
||||
cmd-end (default '<c-e>' and '<end>')
|
||||
cmd-delete-home (default '<c-u>')
|
||||
cmd-delete-end (default '<c-k>')
|
||||
cmd-delete-unix-word (default '<c-w>')
|
||||
cmd-yank (default '<c-y>')
|
||||
cmd-transpose (default '<c-t>')
|
||||
cmd-interrupt (default '<c-c>')
|
||||
cmd-word (default '<a-f>')
|
||||
cmd-word-back (default '<a-b>')
|
||||
cmd-capitalize-word (default '<a-c>')
|
||||
cmd-delete-word (default '<a-d>')
|
||||
cmd-uppercase-word (default '<a-u>')
|
||||
cmd-lowercase-word (default '<a-l>')
|
||||
cmd-transpose-word (default '<a-t>')
|
||||
.EE
|
||||
.PP
|
||||
The following options can be used to customize the behavior of lf:
|
||||
.PP
|
||||
.EX
|
||||
anchorfind boolean (default on)
|
||||
color256 boolean (default off)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
incsearch boolean (default off)
|
||||
preview boolean (default on)
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
number boolean (default off)
|
||||
relativenumber boolean (default off)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
|
||||
filesep string (default "\en")
|
||||
ifs string (default ”) (not exported if empty)
|
||||
previewer string (default ”) (not filtered if empty)
|
||||
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
|
||||
shell string (default 'sh')
|
||||
sortby string (default 'natural')
|
||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||
ratios string (default '1:2:3')
|
||||
info string (default ”)
|
||||
shellopts string (default ”)
|
||||
.EE
|
||||
.PP
|
||||
The following variables are exported for shell commands:
|
||||
.PP
|
||||
.EX
|
||||
$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
|
||||
.EE
|
||||
.PP
|
||||
The following variables are set to the corresponding values:
|
||||
.PP
|
||||
.EX
|
||||
$LF_LEVEL current nesting level
|
||||
.EE
|
||||
.PP
|
||||
The following default values are set to the environmental variables on unix when they are not set or empty:
|
||||
.PP
|
||||
.EX
|
||||
$OPENER open # macos
|
||||
$OPENER xdg-open # others
|
||||
$EDITOR vi
|
||||
$PAGER less
|
||||
$SHELL sh
|
||||
.EE
|
||||
.PP
|
||||
The following default values are set to the environmental variables on windows when they are not set or empty:
|
||||
.PP
|
||||
.EX
|
||||
%OPENER% start
|
||||
%EDITOR% notepad
|
||||
%PAGER% more
|
||||
%SHELL% cmd
|
||||
.EE
|
||||
.PP
|
||||
The following additional keybindings are provided by default:
|
||||
.PP
|
||||
.EX
|
||||
map zh set hidden!
|
||||
map zr set reverse!
|
||||
map zn set info
|
||||
map zs set info size
|
||||
map zt set info time
|
||||
map za set info size:time
|
||||
map sn :set sortby natural; set info
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
map gh cd ~
|
||||
.EE
|
||||
.PP
|
||||
The following keybindings to applications are provided by default:
|
||||
.PP
|
||||
.EX
|
||||
map e $$EDITOR $f
|
||||
map i $$PAGER $f
|
||||
map w $$SHELL
|
||||
.EE
|
||||
.SH CONFIGURATION
|
||||
Configuration files should be located at:
|
||||
.PP
|
||||
.EX
|
||||
os system-wide user-specific
|
||||
unix /etc/lf/lfrc ~/.config/lf/lfrc
|
||||
windows C:\eProgramData\elf\elfrc C:\eUsers\e<user>\eAppData\eLocal\elf\elfrc
|
||||
.EE
|
||||
.PP
|
||||
Marks file should be located at:
|
||||
.PP
|
||||
.EX
|
||||
unix ~/.local/share/lf/marks
|
||||
windows C:\eUsers\e<user>\eAppData\eLocal\elf\emarks
|
||||
.EE
|
||||
.PP
|
||||
History file should be located at:
|
||||
.PP
|
||||
.EX
|
||||
unix ~/.local/share/lf/history
|
||||
windows C:\eUsers\e<user>\eAppData\eLocal\elf\ehistory
|
||||
.EE
|
||||
.PP
|
||||
You can configure the default values of following variables to change these locations:
|
||||
.PP
|
||||
.EX
|
||||
$XDG_CONFIG_HOME ~/.config
|
||||
$XDG_DATA_HOME ~/.local/share
|
||||
%ProgramData% C:\eProgramData
|
||||
%LOCALAPPDATA% C:\eUsers\e<user>\eAppData\eLocal
|
||||
.EE
|
||||
.PP
|
||||
A sample configuration file can be found at https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||
.SH PREFIXES
|
||||
The following command prefixes are used by lf:
|
||||
.PP
|
||||
.EX
|
||||
: read (default) builtin/custom command
|
||||
$ shell shell command
|
||||
% 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
|
||||
.EE
|
||||
.PP
|
||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default. Searching commands are only used from the command line.
|
||||
.SH SYNTAX
|
||||
Characters from '#' to newline are comments and ignored:
|
||||
.PP
|
||||
.EX
|
||||
# comments start with '#'
|
||||
.EE
|
||||
.PP
|
||||
There are three special commands ('set', 'map', and 'cmd') and their variants for configuration.
|
||||
.PP
|
||||
Command 'set' is used to set an option which can be boolean, integer, or string:
|
||||
.PP
|
||||
.EX
|
||||
set hidden # boolean on
|
||||
set nohidden # boolean off
|
||||
set hidden! # boolean toggle
|
||||
set scrolloff 10 # integer value
|
||||
set sortby time # string value w/o quotes
|
||||
set sortby 'time' # string value with single quotes (whitespaces)
|
||||
set sortby "time" # string value with double quotes (backslash escapes)
|
||||
.EE
|
||||
.PP
|
||||
Command 'map' is used to bind a key to a command which can be builtin command, custom command, or shell command:
|
||||
.PP
|
||||
.EX
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom command
|
||||
map i $less $f # shell command
|
||||
map U !du -sh # waiting shell command
|
||||
.EE
|
||||
.PP
|
||||
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
|
||||
.PP
|
||||
.EX
|
||||
cmap <c-g> cmd-escape
|
||||
.EE
|
||||
.PP
|
||||
You can delete an existing binding by leaving the expression empty:
|
||||
.PP
|
||||
.EX
|
||||
map gh # deletes 'gh' mapping
|
||||
cmap <c-g> # deletes '<c-g>' mapping
|
||||
.EE
|
||||
.PP
|
||||
Command 'cmd' is used to define a custom command:
|
||||
.PP
|
||||
.EX
|
||||
cmd usage $du -h -d1 | less
|
||||
.EE
|
||||
.PP
|
||||
You can delete an existing command by leaving the expression empty:
|
||||
.PP
|
||||
.EX
|
||||
cmd trash # deletes 'trash' command
|
||||
.EE
|
||||
.PP
|
||||
If there is no prefix then ':' is assumed:
|
||||
.PP
|
||||
.EX
|
||||
map zt set info time
|
||||
.EE
|
||||
.PP
|
||||
An explicit ':' can be provided to group statements until a newline which is especially useful for 'map' and 'cmd' commands:
|
||||
.PP
|
||||
.EX
|
||||
map st :set sortby time; set info time
|
||||
.EE
|
||||
.PP
|
||||
If you need multiline you can wrap statements in '{{' and '}}' after the proper prefix.
|
||||
.PP
|
||||
.EX
|
||||
map st :{{
|
||||
set sortby time
|
||||
set info time
|
||||
}}
|
||||
.EE
|
||||
.SH KEY MAPPINGS
|
||||
Regular keys are assigned to a command with the usual syntax:
|
||||
.PP
|
||||
.EX
|
||||
map a down
|
||||
.EE
|
||||
.PP
|
||||
Keys combined with the shift key simply use the uppercase letter:
|
||||
.PP
|
||||
.EX
|
||||
map A down
|
||||
.EE
|
||||
.PP
|
||||
Special keys are written in between '<' and '>' characters and always use lowercase letters:
|
||||
.PP
|
||||
.EX
|
||||
map <enter> down
|
||||
.EE
|
||||
.PP
|
||||
Angle brackets can be assigned with their special names:
|
||||
.PP
|
||||
.EX
|
||||
map <lt> down
|
||||
map <gt> down
|
||||
.EE
|
||||
.PP
|
||||
Function keys are prefixed with 'f' character:
|
||||
.PP
|
||||
.EX
|
||||
map <f-1> down
|
||||
.EE
|
||||
.PP
|
||||
Keys combined with the control key are prefixed with 'c' character:
|
||||
.PP
|
||||
.EX
|
||||
map <c-a> down
|
||||
.EE
|
||||
.PP
|
||||
Keys combined with the alt key are assigned in two different ways depending on the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit of a character when the alt key is pressed. On these terminals, you can use the corresponding byte for the mapping:
|
||||
.PP
|
||||
.EX
|
||||
map á down
|
||||
.EE
|
||||
.PP
|
||||
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key when the alt key is pressed. lf uses the escape delaying mechanism to recognize alt keys in these terminals (delay is 100ms). On these terminals, keys combined with the alt key are prefixed with 'a' character:
|
||||
.PP
|
||||
.EX
|
||||
map <a-a> down
|
||||
.EE
|
||||
.PP
|
||||
Please note that, some key combinations are not possible due to the way terminals work (e.g. control and h combination sends a backspace key instead). The easiest way to find the name of a key combination is to press the key while lf is running and read the name of the key from the unknown mapping error.
|
||||
.SH PUSH MAPPINGS
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed command. While this provides a clean way to remap builtin keys as well as other commands, it can be limiting at times. For this reason 'push' command is provided by lf. This command is used to simulate key pushes given as its arguments. You can 'map' a key to a 'push' command with an argument to create various keybindings.
|
||||
.PP
|
||||
This is mainly useful for two purposes. First, it can be used to map a command with a command count:
|
||||
.PP
|
||||
.EX
|
||||
map <c-j> push 10j
|
||||
.EE
|
||||
.PP
|
||||
Second, it can be used to avoid typing the name when a command takes arguments:
|
||||
.PP
|
||||
.EX
|
||||
map r push :rename<space>
|
||||
.EE
|
||||
.PP
|
||||
One thing to be careful is that since 'push' command works with keys instead of commands it is possible to accidentally create recursive bindings:
|
||||
.PP
|
||||
.EX
|
||||
map j push 2j
|
||||
.EE
|
||||
.PP
|
||||
These types of bindings create a deadlock when executed.
|
||||
.SH SHELL COMMANDS
|
||||
Regular shell commands are the most basic command type that is useful for many purposes. For example, we can write a shell command to move selected file(s) to trash. A first attempt to write such a command may look like this:
|
||||
.PP
|
||||
.EX
|
||||
cmd trash ${{
|
||||
mkdir -p ~/.trash
|
||||
if [ -z "$fs" ]; then
|
||||
mv "$f" ~/.trash
|
||||
else
|
||||
IFS="`printf '\en\et'`"; mv $fs ~/.trash
|
||||
fi
|
||||
}}
|
||||
.EE
|
||||
.PP
|
||||
We check '$fs' to see if there are any selected files. Otherwise we just delete the current file. Since this is such a common pattern, a separate '$fx' variable is provided. We can use this variable to get rid of the conditional:
|
||||
.PP
|
||||
.EX
|
||||
cmd trash ${{
|
||||
mkdir -p ~/.trash
|
||||
IFS="`printf '\en\et'`"; mv $fx ~/.trash
|
||||
}}
|
||||
.EE
|
||||
.PP
|
||||
The trash directory is checked each time the command is executed. We can move it outside of the command so it would only run once at startup:
|
||||
.PP
|
||||
.EX
|
||||
${{ mkdir -p ~/.trash }}
|
||||
.EE
|
||||
.PP
|
||||
.EX
|
||||
cmd trash ${{ IFS="`printf '\en\et'`"; mv $fx ~/.trash }}
|
||||
.EE
|
||||
.PP
|
||||
Since these are one liners, we can drop '{{' and '}}':
|
||||
.PP
|
||||
.EX
|
||||
$mkdir -p ~/.trash
|
||||
.EE
|
||||
.PP
|
||||
.EX
|
||||
cmd trash $IFS="`printf '\en\et'`"; mv $fx ~/.trash
|
||||
.EE
|
||||
.PP
|
||||
Finally note that we set 'IFS' variable manually in these commands. Instead we could use the 'ifs' option to set it for all shell commands (i.e. 'set ifs "\en"'). This can be especially useful for interactive use (e.g. '$rm $f' or '$rm $fs' would simply work). This option is not set by default as it can behave unexpectedly for new users. However, use of this option is highly recommended and it is assumed in the rest of the documentation.
|
||||
.SH PIPING SHELL COMMANDS
|
||||
Regular shell commands have some limitations in some cases. When an output or error message is given and the command exits afterwards, the ui is immediately resumed and there is no way to see the message without dropping to shell again. Also, even when there is no output or error, the ui still needs to be paused while the command is running. This can cause flickering on the screen for short commands and similar distractions for longer commands.
|
||||
.PP
|
||||
Instead of pausing the ui, piping shell commands connects stdin, stdout, and stderr of the command to the statline in the bottom of the ui. This can be useful for programs following the unix philosophy to give no output in the success case, and brief error messages or prompts in other cases.
|
||||
.PP
|
||||
For example, following rename command prompts for overwrite in the statline if there is an existing file with the given name:
|
||||
.PP
|
||||
.EX
|
||||
cmd rename %mv -i $f $1
|
||||
.EE
|
||||
.PP
|
||||
You can also output error messages in the command and it will show up in the statline. For example, an alternative rename command may look like this:
|
||||
.PP
|
||||
.EX
|
||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
.EE
|
||||
.PP
|
||||
One thing to be careful is that although input is still line buffered, output and error are byte buffered and verbose commands will be very slow to display.
|
||||
.SH WAITING SHELL COMMANDS
|
||||
Waiting shell commands are similar to regular shell commands except that they wait for a key press when the command is finished. These can be useful to see the output of a program before the ui is resumed. Waiting shell commands are more appropriate than piping shell commands when the command is verbose and the output is best displayed as multiline.
|
||||
.SH ASYNCHRONOUS SHELL COMMANDS
|
||||
Asynchronous shell commands are used to start a command in the background and then resume operation without waiting for the command to finish. Stdin, stdout, and stderr of the command is neither connected to the terminal nor to the ui.
|
||||
.SH REMOTE COMMANDS
|
||||
One of the more advanced features in lf is remote commands. All clients connect to a server on startup. It is possible to send commands to all or any of the connected clients over the common server. This is used internally to notify file selection changes to other clients.
|
||||
.PP
|
||||
To use this feature, you need to use a client which supports communicating with a UNIX-domain socket. OpenBSD implementation of netcat (nc) is one such example. You can use it to send a command to the socket file:
|
||||
.PP
|
||||
.EX
|
||||
echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock
|
||||
.EE
|
||||
.PP
|
||||
Since such a client may not be available everywhere, lf comes bundled with a command line flag to be used as such. When using lf, you do not need to specify the address of the socket file. This is the recommended way of using remote commands since it is shorter and immune to socket file address changes:
|
||||
.PP
|
||||
.EX
|
||||
lf -remote 'send echo hello world'
|
||||
.EE
|
||||
.PP
|
||||
In this command 'send' is used to send the rest of the string as a command to all connected clients. You can optionally give it an id number to send a command to a single client:
|
||||
.PP
|
||||
.EX
|
||||
lf -remote 'send 1000 echo hello world'
|
||||
.EE
|
||||
.PP
|
||||
All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command:
|
||||
.PP
|
||||
.EX
|
||||
lf -remote "send $id echo hello world"
|
||||
.EE
|
||||
.PP
|
||||
Since lf does not have control flow syntax, remote commands are used for such needs. For example, you can configure the number of columns in the ui with respect to the terminal width as follows:
|
||||
.PP
|
||||
.EX
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
elif [ $w -le 160 ]; then
|
||||
lf -remote "send $id set ratios 1:2:3"
|
||||
else
|
||||
lf -remote "send $id set ratios 1:2:3:5"
|
||||
fi
|
||||
}}
|
||||
.EE
|
||||
.PP
|
||||
Besides 'send' command, there are also two commands to get or set the current file selection. Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved. File names are separated by newline character. Setting the file selection is done with 'save' command:
|
||||
.PP
|
||||
.EX
|
||||
lf -remote "$(printf 'save\encopy\enfoo.txt\enbar.txt\enbaz.txt\en')"
|
||||
.EE
|
||||
.PP
|
||||
Getting the file selection is similarly done with 'load' command:
|
||||
.PP
|
||||
.EX
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
# do something with $list
|
||||
elif [ $mode = 'move' ]; then
|
||||
# do something else with $list
|
||||
fi
|
||||
.EE
|
||||
.PP
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
.PP
|
||||
.EX
|
||||
lf -remote 'quit'
|
||||
.EE
|
||||
.PP
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
|
||||
.SH FILE OPERATIONS
|
||||
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. This can fail to move files between different partitions when it needs to copy files. For these cases, users are expected to explicitly copy files and then delete the old ones manually. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
|
||||
.PP
|
||||
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
|
||||
.PP
|
||||
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
|
||||
.PP
|
||||
.EX
|
||||
cmd paste %{{
|
||||
load=$(lf -remote 'load')
|
||||
mode=$(echo "$load" | sed -n '1p')
|
||||
list=$(echo "$load" | sed '1d')
|
||||
if [ $mode = 'copy' ]; then
|
||||
cp -R $list .
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv $list .
|
||||
fi
|
||||
lf -remote 'send load'
|
||||
lf -remote 'send clear'
|
||||
}}
|
||||
.EE
|
||||
.PP
|
||||
Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
||||
.PP
|
||||
By default, lf does not assign 'delete' command to a key to protect new users. You can customize file deletion by defining a 'delete' command. You can also assign a key to this command if you like. An example command to move selected files to a trash folder and remove files completely after a prompt are provided in the example configuration file.
|
||||
.SH SEARCHING FILES
|
||||
There are two mechanisms implemented in lf to search a file in the current directory. Searching is the traditional method to move the selection to a file matching a given pattern. Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
|
||||
.PP
|
||||
Searching mechanism is implemented with commands 'search' (default '/'), 'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev' (default 'N'). You can enable 'globsearch' option to match with a glob pattern. Globbing supports '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. You can enable 'incsearch' option to jump to the current match at each keystroke while typing. In this mode, you can either use 'cmd-enter' to accept the search or use 'cmd-escape' to cancel the search.
|
||||
.PP
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'), 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default ','). You can disable 'anchorfind' option to match a pattern at an arbitrary position in the filename instead of the beginning. You can set the number of keys to match using 'findlen' option. If you set this value to zero, then the the keys are read until there is only a single match. Default values of these two options are set to jump to the first file with the given initial.
|
||||
.PP
|
||||
Some options effect both searching and finding. You can disable 'wrapscan' option to prevent searches to wrap around at the end of the file list. You can disable 'ignorecase' option to match cases in the pattern and the filename. This option is already automatically overridden if the pattern contains upper case characters. You can disable 'smartcase' option to disable this behavior. Two similar options 'ignoredia' and 'smartdia' are provided to control matching diacritics in latin letters.
|
||||
.SH OPENING FILES
|
||||
You can define a an 'open' command (default 'l' and '<right>') to configure file opening. This command is only called when the current file is not a directory, otherwise the directory is entered instead. You can define it just as you would define any other command:
|
||||
.PP
|
||||
.EX
|
||||
cmd open $vi $fx
|
||||
.EE
|
||||
.PP
|
||||
It is possible to use different command types:
|
||||
.PP
|
||||
.EX
|
||||
cmd open &xdg-open $f
|
||||
.EE
|
||||
.PP
|
||||
You may want to use either file extensions or mime types from 'file' command:
|
||||
.PP
|
||||
.EX
|
||||
cmd open ${{
|
||||
case $(file --mime-type $f -b) in
|
||||
text/*) vi $fx;;
|
||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||
esac
|
||||
}}
|
||||
.EE
|
||||
.PP
|
||||
Following command is provided by default:
|
||||
.PP
|
||||
.EX
|
||||
cmd open &$OPENER $f
|
||||
.EE
|
||||
.PP
|
||||
You may also use any other existing file openers as you like. Possible options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's default file opener), or 'mimeo' to name a few.
|
||||
.SH PREVIEWING FILES
|
||||
lf previews files on the preview pane by printing the file until the end or the preview pane is filled. This output can be enhanced by providing a custom preview script for filtering. This can be used to highlight source codes, list contents of archive files or view pdf or image files as text to name few. For coloring lf recognizes ansi escape codes.
|
||||
.PP
|
||||
In order to use this feature you need to set the value of 'previewer' option to the path of an executable file. lf passes the current file name as the first argument and the height of the preview pane as the second argument when running this file. Output of the execution is printed in the preview pane. You may want to use the same script in your pager mapping as well if any:
|
||||
.PP
|
||||
.EX
|
||||
set previewer ~/.config/lf/pv.sh
|
||||
map i $~/.config/lf/pv.sh $f | less -R
|
||||
.EE
|
||||
.PP
|
||||
Since this script is called for each file selection change it needs to be as efficient as possible and this responsibility is left to the user. You may use file extensions to determine the type of file more efficiently compared to obtaining mime types from 'file' command. Extensions can then be used to match cleanly within a conditional:
|
||||
.PP
|
||||
.EX
|
||||
#!/bin/sh
|
||||
.EE
|
||||
.PP
|
||||
.EX
|
||||
case "$1" in
|
||||
*.tar*) tar tf "$1";;
|
||||
*.zip) unzip -l "$1";;
|
||||
*.rar) unrar l "$1";;
|
||||
*.7z) 7z l "$1";;
|
||||
*.pdf) pdftotext "$1" -;;
|
||||
*) highlight -O ansi "$1" || cat "$1";;
|
||||
esac
|
||||
.EE
|
||||
.PP
|
||||
Another important consideration for efficiency is the use of programs with short startup times for preview. For this reason, 'highlight' is recommended over 'pygmentize' for syntax highlighting. Besides, it is also important that the application is processing the file on the fly rather than first reading it to the memory and then do the processing afterwards. This is especially relevant for big files. lf automatically closes the previewer script output 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.
|
||||
.SH COLORSCHEMES
|
||||
lf tries to automatically adapt its colors to the environment. On startup, first '$LS_COLORS' environment variable is checked. This variable is used by GNU ls to configure its colors based on file types and extensions. The value of this variable is often set by GNU dircolors in a shell configuration file. dircolors program itself can be configured with a configuration file. dircolors supports 256 colors along with common attributes such as bold and underline.
|
||||
.PP
|
||||
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead. This variable is used by ls programs on unix systems such as Mac and BSDs. This variable has a simple syntax and supports 8 colors and bold attribute.
|
||||
.PP
|
||||
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.
|
||||
.PP
|
||||
You should also note that lf uses 8 color mode by default which uses sgr 3-bit color escapes (e.g. '\e033[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. '\e033[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.
|
||||
.PP
|
||||
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.
|
||||
.PP
|
||||
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.
|
||||
.PP
|
||||
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 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line.
|
||||
@@ -4,15 +4,17 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
envPath = os.Getenv("PATH")
|
||||
envPath = os.Getenv("PATH")
|
||||
envLevel = os.Getenv("LF_LEVEL")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,6 +26,8 @@ var (
|
||||
gSocketPath string
|
||||
gLogPath string
|
||||
gServerLogPath string
|
||||
gSelect string
|
||||
gCommand string
|
||||
gVersion string
|
||||
)
|
||||
|
||||
@@ -33,15 +37,52 @@ func init() {
|
||||
log.Printf("hostname: %s", err)
|
||||
}
|
||||
gHostname = h
|
||||
|
||||
if envLevel == "" {
|
||||
envLevel = "0"
|
||||
}
|
||||
}
|
||||
|
||||
func exportEnvVars() {
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
|
||||
os.Setenv("OPENER", envOpener)
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
cmd := exec.Command(os.Args[0], "-server")
|
||||
cmd := detachedCommand(os.Args[0], "-server")
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Printf("starting server: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func checkServer() {
|
||||
if gSocketProt == "unix" {
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||
os.Remove(gSocketPath)
|
||||
startServer()
|
||||
}
|
||||
} else {
|
||||
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||
startServer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
showDoc := flag.Bool(
|
||||
"doc",
|
||||
@@ -83,6 +124,11 @@ func main() {
|
||||
"",
|
||||
"path to the file to write selected files on open (to use as open file dialog)")
|
||||
|
||||
flag.StringVar(&gCommand,
|
||||
"command",
|
||||
"",
|
||||
"command to execute on client initialization")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
gSocketProt = gDefaultSocketProt
|
||||
@@ -99,36 +145,20 @@ func main() {
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
case 1:
|
||||
dir := flag.Arg(0)
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "only single directory is allowed\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
switch {
|
||||
case *showDoc:
|
||||
fmt.Print(genDocString)
|
||||
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:
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
default:
|
||||
// TODO: check if the socket is working
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
}
|
||||
checkServer()
|
||||
|
||||
gClientID = 1000
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
@@ -137,6 +167,22 @@ func main() {
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
}
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
_, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
case 1:
|
||||
gSelect = flag.Arg(0)
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "only single file or directory is allowed\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
exportEnvVars()
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
@@ -133,11 +133,10 @@ func splitWord(s string) (word, rest string) {
|
||||
return
|
||||
}
|
||||
|
||||
// This function converts a size in bytes to a human readable form. For this
|
||||
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
||||
// the first significant digit is shown, otherwise it is hidden. Numbers are
|
||||
// always rounded down. For these reasons this function always show somewhat
|
||||
// smaller values but it should be fine for most human beings.
|
||||
// This function converts a size in bytes to a human readable form using metric
|
||||
// suffixes (e.g. 1K = 1000). For values less than 10 the first significant
|
||||
// digit is shown, otherwise it is hidden. Numbers are always rounded down.
|
||||
// This should be fine for most human beings.
|
||||
func humanize(size int64) string {
|
||||
if size < 1000 {
|
||||
return fmt.Sprintf("%dB", size)
|
||||
@@ -195,6 +194,12 @@ func naturalLess(s1, s2 string) bool {
|
||||
return len(parts1) < len(parts2)
|
||||
}
|
||||
|
||||
var reAltKey = regexp.MustCompile(`<a-(.)>`)
|
||||
|
||||
var reWord = regexp.MustCompile(`(\pL|\pN)+`)
|
||||
var reWordBeg = regexp.MustCompile(`([^\pL\pN]|^)(\pL|\pN)`)
|
||||
var reWordEnd = regexp.MustCompile(`(\pL|\pN)([^\pL\pN]|$)`)
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
@@ -210,7 +215,7 @@ func max(a, b int) int {
|
||||
}
|
||||
|
||||
// We don't need no generic code
|
||||
// We don't need no thought control
|
||||
// We don't need no type control
|
||||
// No dark templates in compiler
|
||||
// Haskell leave them kids alone
|
||||
// Hey Bjarne leave them kids alone
|
||||
|
||||
@@ -2,89 +2,141 @@ package main
|
||||
|
||||
import "time"
|
||||
|
||||
type sortMethod byte
|
||||
|
||||
const (
|
||||
naturalSort sortMethod = iota
|
||||
nameSort
|
||||
sizeSort
|
||||
timeSort
|
||||
)
|
||||
|
||||
type sortOption byte
|
||||
|
||||
const (
|
||||
dirfirstSort sortOption = 1 << iota
|
||||
hiddenSort
|
||||
reverseSort
|
||||
)
|
||||
|
||||
type sortType struct {
|
||||
method sortMethod
|
||||
option sortOption
|
||||
}
|
||||
|
||||
var gOpts struct {
|
||||
dircounts bool
|
||||
dirfirst bool
|
||||
globsearch bool
|
||||
hidden bool
|
||||
ignorecase bool
|
||||
preview bool
|
||||
reverse bool
|
||||
smartcase bool
|
||||
wrapscan bool
|
||||
scrolloff int
|
||||
tabstop int
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
promptfmt string
|
||||
shell string
|
||||
sortby string
|
||||
timefmt string
|
||||
ratios []int
|
||||
info []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
anchorfind bool
|
||||
color256 bool
|
||||
dircounts bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
ignorecase bool
|
||||
incsearch bool
|
||||
preview bool
|
||||
smartcase bool
|
||||
ignoredia bool
|
||||
smartdia bool
|
||||
wrapscan bool
|
||||
number bool
|
||||
relativenumber bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
promptfmt string
|
||||
shell string
|
||||
timefmt string
|
||||
ratios []int
|
||||
info []string
|
||||
shellopts []string
|
||||
keys map[string]expr
|
||||
cmdkeys map[string]expr
|
||||
cmds map[string]expr
|
||||
sortType sortType
|
||||
}
|
||||
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.color256 = false
|
||||
gOpts.dircounts = false
|
||||
gOpts.dirfirst = true
|
||||
gOpts.drawbox = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.hidden = false
|
||||
gOpts.ignorecase = true
|
||||
gOpts.incsearch = false
|
||||
gOpts.preview = true
|
||||
gOpts.reverse = false
|
||||
gOpts.smartcase = true
|
||||
gOpts.ignoredia = false
|
||||
gOpts.smartdia = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.number = false
|
||||
gOpts.relativenumber = false
|
||||
gOpts.findlen = 1
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.ifs = ""
|
||||
gOpts.previewer = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.sortby = "natural"
|
||||
gOpts.timefmt = time.ANSIC
|
||||
gOpts.ratios = []int{1, 2, 3}
|
||||
gOpts.info = nil
|
||||
gOpts.shellopts = nil
|
||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||
|
||||
gOpts.keys = make(map[string]expr)
|
||||
|
||||
gOpts.keys["k"] = &callExpr{"up", nil}
|
||||
gOpts.keys["<up>"] = &callExpr{"up", nil}
|
||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil}
|
||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil}
|
||||
gOpts.keys["j"] = &callExpr{"down", nil}
|
||||
gOpts.keys["<down>"] = &callExpr{"down", nil}
|
||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil}
|
||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil}
|
||||
gOpts.keys["h"] = &callExpr{"updir", nil}
|
||||
gOpts.keys["<left>"] = &callExpr{"updir", nil}
|
||||
gOpts.keys["l"] = &callExpr{"open", nil}
|
||||
gOpts.keys["<right>"] = &callExpr{"open", nil}
|
||||
gOpts.keys["q"] = &callExpr{"quit", nil}
|
||||
gOpts.keys["gg"] = &callExpr{"top", nil}
|
||||
gOpts.keys["G"] = &callExpr{"bot", nil}
|
||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil}
|
||||
gOpts.keys["v"] = &callExpr{"invert", nil}
|
||||
gOpts.keys["u"] = &callExpr{"unmark", nil}
|
||||
gOpts.keys["y"] = &callExpr{"yank", nil}
|
||||
gOpts.keys["d"] = &callExpr{"delete", nil}
|
||||
gOpts.keys["c"] = &callExpr{"clear", nil}
|
||||
gOpts.keys["p"] = &callExpr{"put", nil}
|
||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil}
|
||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil}
|
||||
gOpts.keys[":"] = &callExpr{"read", nil}
|
||||
gOpts.keys["$"] = &callExpr{"shell", nil}
|
||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil}
|
||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil}
|
||||
gOpts.keys["&"] = &callExpr{"shell-async", nil}
|
||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
||||
gOpts.keys["k"] = &callExpr{"up", nil, 1}
|
||||
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
||||
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
||||
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
||||
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
||||
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
||||
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
||||
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
||||
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
||||
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
||||
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
||||
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["v"] = &callExpr{"invert", nil, 1}
|
||||
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
||||
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
||||
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
|
||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
||||
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
||||
gOpts.keys["$"] = &callExpr{"shell", nil, 1}
|
||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
||||
gOpts.keys["f"] = &callExpr{"find", nil, 1}
|
||||
gOpts.keys["F"] = &callExpr{"find-back", nil, 1}
|
||||
gOpts.keys[";"] = &callExpr{"find-next", nil, 1}
|
||||
gOpts.keys[","] = &callExpr{"find-prev", nil, 1}
|
||||
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||
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["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
gOpts.keys["zh"] = &setExpr{"hidden!", ""}
|
||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
||||
@@ -95,36 +147,42 @@ func init() {
|
||||
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["gh"] = &callExpr{"cd", []string{"~"}}
|
||||
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
||||
|
||||
gOpts.cmdkeys = make(map[string]expr)
|
||||
|
||||
// TODO: rest of the keys
|
||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}}
|
||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil}
|
||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil}
|
||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil}
|
||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil}
|
||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil}
|
||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil}
|
||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil}
|
||||
gOpts.cmdkeys["<c-d>"] = &callExpr{"cmd-delete", nil}
|
||||
gOpts.cmdkeys["<bs>"] = &callExpr{"cmd-delete-back", nil}
|
||||
gOpts.cmdkeys["<bs2>"] = &callExpr{"cmd-delete-back", nil}
|
||||
gOpts.cmdkeys["<left>"] = &callExpr{"cmd-left", nil}
|
||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil}
|
||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil}
|
||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil}
|
||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil}
|
||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil}
|
||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil}
|
||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil}
|
||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", nil}
|
||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil}
|
||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
|
||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
|
||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
|
||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil}
|
||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
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["<left>"] = &callExpr{"cmd-left", nil, 1}
|
||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-home", nil, 1}
|
||||
gOpts.cmdkeys["<c-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil, 1}
|
||||
gOpts.cmdkeys["<a-f>"] = &callExpr{"cmd-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-b>"] = &callExpr{"cmd-word-back", nil, 1}
|
||||
gOpts.cmdkeys["<a-c>"] = &callExpr{"cmd-capitalize-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-d>"] = &callExpr{"cmd-delete-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-u>"] = &callExpr{"cmd-uppercase-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-l>"] = &callExpr{"cmd-lowercase-word", nil, 1}
|
||||
gOpts.cmdkeys["<a-t>"] = &callExpr{"cmd-transpose-word", nil, 1}
|
||||
|
||||
gOpts.cmds = make(map[string]expr)
|
||||
|
||||
|
||||
@@ -10,9 +10,11 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
@@ -25,14 +27,42 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
gUser *user.User
|
||||
gConfigPath string
|
||||
gUser *user.User
|
||||
gConfigPaths []string
|
||||
gMarksPath string
|
||||
gHistoryPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
if envOpener == "" {
|
||||
if runtime.GOOS == "darwin" {
|
||||
envOpener = "open"
|
||||
} else {
|
||||
envOpener = "xdg-open"
|
||||
}
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = "vi"
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
envPager = "less"
|
||||
}
|
||||
|
||||
if envShell == "" {
|
||||
envShell = "sh"
|
||||
}
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("user: %s", err)
|
||||
if os.Getenv("HOME") == "" {
|
||||
log.Print("$HOME variable is empty or not set")
|
||||
}
|
||||
if os.Getenv("USER") == "" {
|
||||
log.Print("$USER variable is empty or not set")
|
||||
}
|
||||
}
|
||||
gUser = u
|
||||
|
||||
@@ -41,21 +71,36 @@ func init() {
|
||||
config = filepath.Join(gUser.HomeDir, ".config")
|
||||
}
|
||||
|
||||
gConfigPath = filepath.Join(config, "lf", "lfrc")
|
||||
gConfigPaths = []string{
|
||||
filepath.Join("/etc", "lf", "lfrc"),
|
||||
filepath.Join(config, "lf", "lfrc"),
|
||||
}
|
||||
|
||||
data := os.Getenv("XDG_DATA_HOME")
|
||||
if data == "" {
|
||||
data = filepath.Join(gUser.HomeDir, ".local", "share")
|
||||
}
|
||||
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
|
||||
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
c := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
old=$(stty -g)
|
||||
stty raw -echo
|
||||
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
|
||||
stty $old
|
||||
echo`
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
return exec.Command(name, arg...)
|
||||
}
|
||||
|
||||
return exec.Command(gOpts.shell, "-c", c)
|
||||
func pauseCommand() *exec.Cmd {
|
||||
cmd := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
old=$(stty -g)
|
||||
stty raw -echo
|
||||
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
|
||||
stty $old
|
||||
echo`
|
||||
|
||||
return exec.Command(gOpts.shell, "-c", cmd)
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
@@ -65,59 +110,43 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
||||
|
||||
args = append([]string{"-c", s, "--"}, args...)
|
||||
|
||||
args = append(gOpts.shellopts, args...)
|
||||
|
||||
return exec.Command(gOpts.shell, args...)
|
||||
}
|
||||
|
||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
||||
var sh string
|
||||
var args []string
|
||||
|
||||
if copy {
|
||||
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() {
|
||||
if envEditor == "" {
|
||||
gOpts.keys["e"] = &execExpr{"$", `vi "$f"`}
|
||||
} else {
|
||||
gOpts.keys["e"] = &execExpr{"$", envEditor + ` "$f"`}
|
||||
}
|
||||
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
|
||||
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}
|
||||
|
||||
if envPager == "" {
|
||||
gOpts.keys["i"] = &execExpr{"$", `less "$f"`}
|
||||
} else {
|
||||
gOpts.keys["i"] = &execExpr{"$", envPager + ` "$f"`}
|
||||
}
|
||||
|
||||
if envShell == "" {
|
||||
gOpts.keys["w"] = &execExpr{"$", "sh"}
|
||||
} else {
|
||||
gOpts.keys["w"] = &execExpr{"$", envShell}
|
||||
}
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
gOpts.cmds["open-file"] = &execExpr{"&", `open "$f"`}
|
||||
} else {
|
||||
gOpts.cmds["open-file"] = &execExpr{"&", `xdg-open "$f"`}
|
||||
}
|
||||
gOpts.cmds["doc"] = &execExpr{"$", "lf -doc | $PAGER"}
|
||||
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) bool {
|
||||
return f.Name()[0] == '.'
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := f
|
||||
envFiles := strings.Join(fs, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
+93
-34
@@ -1,12 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
envOpener = os.Getenv("OPENER")
|
||||
envEditor = os.Getenv("EDITOR")
|
||||
envPager = os.Getenv("PAGER")
|
||||
envShell = os.Getenv("SHELL")
|
||||
)
|
||||
|
||||
var (
|
||||
envPathExt = os.Getenv("PATHEXT")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -16,11 +29,29 @@ var (
|
||||
)
|
||||
|
||||
var (
|
||||
gUser *user.User
|
||||
gConfigPath string
|
||||
gUser *user.User
|
||||
gConfigPaths []string
|
||||
gMarksPath string
|
||||
gHistoryPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
if envOpener == "" {
|
||||
envOpener = `start ""`
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
envEditor = "notepad"
|
||||
}
|
||||
|
||||
if envPager == "" {
|
||||
envPager = "more"
|
||||
}
|
||||
|
||||
if envShell == "" {
|
||||
envShell = "cmd"
|
||||
}
|
||||
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("user: %s", err)
|
||||
@@ -30,7 +61,21 @@ func init() {
|
||||
// remove domain prefix
|
||||
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
||||
|
||||
gConfigPath = filepath.Join(gUser.HomeDir, "AppData", "Local", "lf", "lfrc")
|
||||
data := os.Getenv("LOCALAPPDATA")
|
||||
|
||||
gConfigPaths = []string{
|
||||
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||
filepath.Join(data, "lf", "lfrc"),
|
||||
}
|
||||
|
||||
gMarksPath = filepath.Join(data, "lf", "marks")
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
}
|
||||
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 8}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
@@ -39,44 +84,58 @@ func pauseCommand() *exec.Cmd {
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
args = append([]string{"/c", s}, args...)
|
||||
|
||||
args = append(gOpts.shellopts, args...)
|
||||
|
||||
return exec.Command(gOpts.shell, args...)
|
||||
}
|
||||
|
||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
||||
var args []string
|
||||
|
||||
sh := "robocopy"
|
||||
if !copy {
|
||||
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.keys["e"] = &execExpr{"$", `notepad "%f%"`}
|
||||
gOpts.keys["i"] = &execExpr{"$", `more "%f%"`}
|
||||
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
||||
gOpts.cmds["open-file"] = &execExpr{"&", `start "" "%f%"`}
|
||||
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
|
||||
gOpts.keys["w"] = &execExpr{"$", "%SHELL%"}
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "lf -doc | %PAGER%"}
|
||||
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 {
|
||||
if strings.HasSuffix(strings.ToLower(f.Name()), strings.ToLower(e)) {
|
||||
log.Print(f.Name(), e)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo) bool {
|
||||
// TODO: implement
|
||||
return false
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := fmt.Sprintf(`"%s"`, f)
|
||||
|
||||
var quotedFiles []string
|
||||
for _, f := range fs {
|
||||
quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f))
|
||||
}
|
||||
envFiles := strings.Join(quotedFiles, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ package main
|
||||
// ExecExpr = Prefix <value> '\n'
|
||||
// | Prefix '{{' <value> '}}' ';'
|
||||
//
|
||||
// Prefix = '$' | '!' | '&' | '/' | '?'
|
||||
// Prefix = '$' | '%' | '!' | '&'
|
||||
//
|
||||
// ListExpr = ':' Expr ListRest '\n'
|
||||
// | ':' '{{' Expr ListRest '}}' ';'
|
||||
@@ -72,8 +72,9 @@ type cmdExpr struct {
|
||||
func (e *cmdExpr) String() string { return fmt.Sprintf("cmd %s %s", e.name, e.expr) }
|
||||
|
||||
type callExpr struct {
|
||||
name string
|
||||
args []string
|
||||
name string
|
||||
args []string
|
||||
count int
|
||||
}
|
||||
|
||||
func (e *callExpr) String() string { return fmt.Sprintf("%s -- %s", e.name, e.args) }
|
||||
@@ -230,7 +231,7 @@ func (p *parser) parseExpr() expr {
|
||||
|
||||
s.scan()
|
||||
|
||||
result = &callExpr{name, args}
|
||||
result = &callExpr{name, args, 1}
|
||||
}
|
||||
case tokenColon:
|
||||
s.scan()
|
||||
|
||||
@@ -13,15 +13,17 @@ var (
|
||||
gCopyFile bool
|
||||
gFileList []string
|
||||
gConnList = make(map[int]net.Conn)
|
||||
gQuitChan = make(chan bool, 1)
|
||||
gListener net.Listener
|
||||
)
|
||||
|
||||
func serve() {
|
||||
logFile, err := os.Create(gServerLogPath)
|
||||
f, err := os.Create(gServerLogPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
defer f.Close()
|
||||
log.SetOutput(f)
|
||||
|
||||
log.Print("hi!")
|
||||
|
||||
@@ -32,6 +34,8 @@ func serve() {
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
gListener = l
|
||||
|
||||
listen(l)
|
||||
}
|
||||
|
||||
@@ -39,7 +43,13 @@ func listen(l net.Listener) {
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accepting connection: %s", err)
|
||||
select {
|
||||
case <-gQuitChan:
|
||||
log.Printf("bye!")
|
||||
return
|
||||
default:
|
||||
log.Printf("accepting connection: %s", err)
|
||||
}
|
||||
}
|
||||
go handleConn(c)
|
||||
}
|
||||
@@ -103,6 +113,14 @@ func handleConn(c net.Conn) {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "quit":
|
||||
gQuitChan <- true
|
||||
for _, c := range gConnList {
|
||||
fmt.Fprintln(c, "echo server is quitting...")
|
||||
c.Close()
|
||||
}
|
||||
gListener.Close()
|
||||
break
|
||||
default:
|
||||
log.Printf("listen: unexpected command: %s", word)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
@@ -18,91 +19,65 @@ import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
const (
|
||||
gEscapeCode = 27
|
||||
gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||
)
|
||||
const gEscapeCode = 27
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
var gKeyVal = map[termbox.Key][]rune{
|
||||
termbox.KeyF1: {'<', 'f', '-', '1', '>'},
|
||||
termbox.KeyF2: {'<', 'f', '-', '2', '>'},
|
||||
termbox.KeyF3: {'<', 'f', '-', '3', '>'},
|
||||
termbox.KeyF4: {'<', 'f', '-', '4', '>'},
|
||||
termbox.KeyF5: {'<', 'f', '-', '5', '>'},
|
||||
termbox.KeyF6: {'<', 'f', '-', '6', '>'},
|
||||
termbox.KeyF7: {'<', 'f', '-', '7', '>'},
|
||||
termbox.KeyF8: {'<', 'f', '-', '8', '>'},
|
||||
termbox.KeyF9: {'<', 'f', '-', '9', '>'},
|
||||
termbox.KeyF10: {'<', 'f', '-', '1', '0', '>'},
|
||||
termbox.KeyF11: {'<', 'f', '-', '1', '1', '>'},
|
||||
termbox.KeyF12: {'<', 'f', '-', '1', '2', '>'},
|
||||
termbox.KeyInsert: {'<', 'i', 'n', 's', 'e', 'r', 't', '>'},
|
||||
termbox.KeyDelete: {'<', 'd', 'e', 'l', 'e', 't', 'e', '>'},
|
||||
termbox.KeyHome: {'<', 'h', 'o', 'm', 'e', '>'},
|
||||
termbox.KeyEnd: {'<', 'e', 'n', 'd', '>'},
|
||||
termbox.KeyPgup: {'<', 'p', 'g', 'u', 'p', '>'},
|
||||
termbox.KeyPgdn: {'<', 'p', 'g', 'd', 'n', '>'},
|
||||
termbox.KeyArrowUp: {'<', 'u', 'p', '>'},
|
||||
termbox.KeyArrowDown: {'<', 'd', 'o', 'w', 'n', '>'},
|
||||
termbox.KeyArrowLeft: {'<', 'l', 'e', 'f', 't', '>'},
|
||||
termbox.KeyArrowRight: {'<', 'r', 'i', 'g', 'h', 't', '>'},
|
||||
termbox.KeyCtrlSpace: {'<', 'c', '-', 's', 'p', 'a', 'c', 'e', '>'},
|
||||
termbox.KeyCtrlA: {'<', 'c', '-', 'a', '>'},
|
||||
termbox.KeyCtrlB: {'<', 'c', '-', 'b', '>'},
|
||||
termbox.KeyCtrlC: {'<', 'c', '-', 'c', '>'},
|
||||
termbox.KeyCtrlD: {'<', 'c', '-', 'd', '>'},
|
||||
termbox.KeyCtrlE: {'<', 'c', '-', 'e', '>'},
|
||||
termbox.KeyCtrlF: {'<', 'c', '-', 'f', '>'},
|
||||
termbox.KeyCtrlG: {'<', 'c', '-', 'g', '>'},
|
||||
termbox.KeyBackspace: {'<', 'b', 's', '>'},
|
||||
termbox.KeyTab: {'<', 't', 'a', 'b', '>'},
|
||||
termbox.KeyCtrlJ: {'<', 'c', '-', 'j', '>'},
|
||||
termbox.KeyCtrlK: {'<', 'c', '-', 'k', '>'},
|
||||
termbox.KeyCtrlL: {'<', 'c', '-', 'l', '>'},
|
||||
termbox.KeyEnter: {'<', 'e', 'n', 't', 'e', 'r', '>'},
|
||||
termbox.KeyCtrlN: {'<', 'c', '-', 'n', '>'},
|
||||
termbox.KeyCtrlO: {'<', 'c', '-', 'o', '>'},
|
||||
termbox.KeyCtrlP: {'<', 'c', '-', 'p', '>'},
|
||||
termbox.KeyCtrlQ: {'<', 'c', '-', 'q', '>'},
|
||||
termbox.KeyCtrlR: {'<', 'c', '-', 'r', '>'},
|
||||
termbox.KeyCtrlS: {'<', 'c', '-', 's', '>'},
|
||||
termbox.KeyCtrlT: {'<', 'c', '-', 't', '>'},
|
||||
termbox.KeyCtrlU: {'<', 'c', '-', 'u', '>'},
|
||||
termbox.KeyCtrlV: {'<', 'c', '-', 'v', '>'},
|
||||
termbox.KeyCtrlW: {'<', 'c', '-', 'w', '>'},
|
||||
termbox.KeyCtrlX: {'<', 'c', '-', 'x', '>'},
|
||||
termbox.KeyCtrlY: {'<', 'c', '-', 'y', '>'},
|
||||
termbox.KeyCtrlZ: {'<', 'c', '-', 'z', '>'},
|
||||
termbox.KeyEsc: {'<', 'e', 's', 'c', '>'},
|
||||
termbox.KeyCtrlBackslash: {'<', 'c', '-', '\\', '>'},
|
||||
termbox.KeyCtrlRsqBracket: {'<', 'c', '-', ']', '>'},
|
||||
termbox.KeyCtrl6: {'<', 'c', '-', '6', '>'},
|
||||
termbox.KeyCtrlSlash: {'<', 'c', '-', '/', '>'},
|
||||
termbox.KeySpace: {'<', 's', 'p', 'a', 'c', 'e', '>'},
|
||||
termbox.KeyBackspace2: {'<', 'b', 's', '2', '>'},
|
||||
var gKeyVal = map[termbox.Key]string{
|
||||
termbox.KeyF1: "<f-1>",
|
||||
termbox.KeyF2: "<f-2>",
|
||||
termbox.KeyF3: "<f-3>",
|
||||
termbox.KeyF4: "<f-4>",
|
||||
termbox.KeyF5: "<f-5>",
|
||||
termbox.KeyF6: "<f-6>",
|
||||
termbox.KeyF7: "<f-7>",
|
||||
termbox.KeyF8: "<f-8>",
|
||||
termbox.KeyF9: "<f-9>",
|
||||
termbox.KeyF10: "<f-10>",
|
||||
termbox.KeyF11: "<f-11>",
|
||||
termbox.KeyF12: "<f-12>",
|
||||
termbox.KeyInsert: "<insert>",
|
||||
termbox.KeyDelete: "<delete>",
|
||||
termbox.KeyHome: "<home>",
|
||||
termbox.KeyEnd: "<end>",
|
||||
termbox.KeyPgup: "<pgup>",
|
||||
termbox.KeyPgdn: "<pgdn>",
|
||||
termbox.KeyArrowUp: "<up>",
|
||||
termbox.KeyArrowDown: "<down>",
|
||||
termbox.KeyArrowLeft: "<left>",
|
||||
termbox.KeyArrowRight: "<right>",
|
||||
termbox.KeyCtrlSpace: "<c-space>",
|
||||
termbox.KeyCtrlA: "<c-a>",
|
||||
termbox.KeyCtrlB: "<c-b>",
|
||||
termbox.KeyCtrlC: "<c-c>",
|
||||
termbox.KeyCtrlD: "<c-d>",
|
||||
termbox.KeyCtrlE: "<c-e>",
|
||||
termbox.KeyCtrlF: "<c-f>",
|
||||
termbox.KeyCtrlG: "<c-g>",
|
||||
termbox.KeyBackspace: "<bs>",
|
||||
termbox.KeyTab: "<tab>",
|
||||
termbox.KeyCtrlJ: "<c-j>",
|
||||
termbox.KeyCtrlK: "<c-k>",
|
||||
termbox.KeyCtrlL: "<c-l>",
|
||||
termbox.KeyEnter: "<enter>",
|
||||
termbox.KeyCtrlN: "<c-n>",
|
||||
termbox.KeyCtrlO: "<c-o>",
|
||||
termbox.KeyCtrlP: "<c-p>",
|
||||
termbox.KeyCtrlQ: "<c-q>",
|
||||
termbox.KeyCtrlR: "<c-r>",
|
||||
termbox.KeyCtrlS: "<c-s>",
|
||||
termbox.KeyCtrlT: "<c-t>",
|
||||
termbox.KeyCtrlU: "<c-u>",
|
||||
termbox.KeyCtrlV: "<c-v>",
|
||||
termbox.KeyCtrlW: "<c-w>",
|
||||
termbox.KeyCtrlX: "<c-x>",
|
||||
termbox.KeyCtrlY: "<c-y>",
|
||||
termbox.KeyCtrlZ: "<c-z>",
|
||||
termbox.KeyEsc: "<esc>",
|
||||
termbox.KeyCtrlBackslash: "<c-\\>",
|
||||
termbox.KeyCtrlRsqBracket: "<c-]>",
|
||||
termbox.KeyCtrl6: "<c-6>",
|
||||
termbox.KeyCtrlSlash: "<c-/>",
|
||||
termbox.KeySpace: "<space>",
|
||||
termbox.KeyBackspace2: "<bs2>",
|
||||
}
|
||||
|
||||
var gValKey map[string]termbox.Key
|
||||
@@ -110,7 +85,7 @@ var gValKey map[string]termbox.Key
|
||||
func init() {
|
||||
gValKey = make(map[string]termbox.Key)
|
||||
for k, v := range gKeyVal {
|
||||
gValKey[string(v)] = k
|
||||
gValKey[v] = k
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,60 +101,6 @@ func (win *win) renew(w, h, x, y int) {
|
||||
win.w, win.h, win.x, win.y = w, h, x, y
|
||||
}
|
||||
|
||||
func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, termbox.Attribute) {
|
||||
toks := strings.Split(s, ";")
|
||||
|
||||
var nums []int
|
||||
for _, t := range toks {
|
||||
if t == "" {
|
||||
fg = termbox.ColorDefault
|
||||
bg = termbox.ColorDefault
|
||||
break
|
||||
}
|
||||
n, err := strconv.Atoi(t)
|
||||
if err != nil {
|
||||
log.Printf("converting escape code: %s", err)
|
||||
continue
|
||||
}
|
||||
nums = append(nums, n)
|
||||
}
|
||||
|
||||
// Parse 256 color terminal ansi codes
|
||||
// termbox-go has a color offset of one, because of attributes
|
||||
if len(nums) == 3 {
|
||||
if nums[0] == 48 && nums[1] == 5 {
|
||||
bg = termbox.Attribute(nums[2])
|
||||
bg++
|
||||
}
|
||||
if nums[0] == 38 && nums[1] == 5 {
|
||||
fg = termbox.Attribute(nums[2])
|
||||
fg++
|
||||
}
|
||||
return fg, bg
|
||||
}
|
||||
|
||||
for _, n := range nums {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return fg, bg
|
||||
}
|
||||
|
||||
func printLength(s string) int {
|
||||
ind := 0
|
||||
off := 0
|
||||
@@ -260,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
||||
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if reg.loading {
|
||||
fg = termbox.AttrReverse
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
return
|
||||
}
|
||||
|
||||
for i, l := range reg.lines {
|
||||
fg, bg = win.print(2, i, fg, bg, l)
|
||||
}
|
||||
@@ -267,68 +194,114 @@ func (win *win) printReg(reg *reg) {
|
||||
return
|
||||
}
|
||||
|
||||
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool) {
|
||||
if win.w < 3 {
|
||||
return
|
||||
func fileInfo(f *file, d *dir) string {
|
||||
var info string
|
||||
|
||||
path := filepath.Join(d.path, f.Name())
|
||||
|
||||
for _, s := range gOpts.info {
|
||||
switch s {
|
||||
case "size":
|
||||
if !(gOpts.dircounts && f.IsDir()) {
|
||||
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
|
||||
continue
|
||||
}
|
||||
|
||||
if f.dirCount == -1 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
f.dirCount = -2
|
||||
}
|
||||
|
||||
names, err := d.Readdirnames(1000)
|
||||
d.Close()
|
||||
|
||||
if names == nil && err != io.EOF {
|
||||
f.dirCount = -2
|
||||
} else {
|
||||
f.dirCount = len(names)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case f.dirCount < 0:
|
||||
info = fmt.Sprintf("%s ?", info)
|
||||
case f.dirCount < 1000:
|
||||
info = fmt.Sprintf("%s %4d", info, f.dirCount)
|
||||
default:
|
||||
info = fmt.Sprintf("%s 999+", info)
|
||||
}
|
||||
case "time":
|
||||
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
||||
default:
|
||||
log.Printf("unknown info type: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
if dir == nil {
|
||||
return info
|
||||
}
|
||||
|
||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
||||
if win.w < 5 || dir == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
if dir.loading {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "loading...")
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "loading...")
|
||||
return
|
||||
}
|
||||
|
||||
if len(dir.fi) == 0 {
|
||||
fg = termbox.AttrBold
|
||||
win.print(2, 0, fg, bg, "empty")
|
||||
if len(dir.files) == 0 {
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||
return
|
||||
}
|
||||
|
||||
maxind := len(dir.fi) - 1
|
||||
|
||||
beg := max(dir.ind-dir.pos, 0)
|
||||
end := min(beg+win.h, maxind+1)
|
||||
end := min(beg+win.h, len(dir.files))
|
||||
|
||||
for i, f := range dir.fi[beg:end] {
|
||||
switch {
|
||||
case f.linkState == working:
|
||||
fg = termbox.ColorCyan
|
||||
if f.Mode().IsDir() {
|
||||
fg |= termbox.AttrBold
|
||||
if beg > end {
|
||||
return
|
||||
}
|
||||
|
||||
var lnwidth int
|
||||
var lnformat string
|
||||
|
||||
if gOpts.number || gOpts.relativenumber {
|
||||
lnwidth = 1
|
||||
for j := 10; j < len(dir.files); j *= 10 {
|
||||
lnwidth++
|
||||
}
|
||||
lnformat = fmt.Sprintf("%%%d.d ", lnwidth)
|
||||
}
|
||||
|
||||
for i, f := range dir.files[beg:end] {
|
||||
fg, bg := colors.get(f)
|
||||
|
||||
if lnwidth > 0 {
|
||||
var ln string
|
||||
|
||||
if gOpts.number && (!gOpts.relativenumber || i == dir.pos) {
|
||||
ln = fmt.Sprintf(lnformat, i+1+beg)
|
||||
} else if gOpts.relativenumber {
|
||||
if i < dir.pos {
|
||||
ln = fmt.Sprintf(lnformat, dir.pos-i)
|
||||
} else {
|
||||
ln = fmt.Sprintf(lnformat, i-dir.pos)
|
||||
}
|
||||
}
|
||||
case f.linkState == broken:
|
||||
fg = termbox.ColorMagenta
|
||||
case f.Mode().IsRegular():
|
||||
if f.Mode()&0111 != 0 {
|
||||
fg = termbox.AttrBold | termbox.ColorGreen
|
||||
} else {
|
||||
fg = termbox.ColorDefault
|
||||
}
|
||||
case f.Mode().IsDir():
|
||||
fg = termbox.AttrBold | termbox.ColorBlue
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
fg = termbox.ColorRed
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
fg = termbox.ColorYellow
|
||||
case f.Mode()&os.ModeDevice != 0:
|
||||
fg = termbox.ColorWhite
|
||||
|
||||
win.print(0, i, termbox.ColorYellow, bg, ln)
|
||||
}
|
||||
|
||||
path := filepath.Join(dir.path, f.Name())
|
||||
|
||||
if _, ok := marks[path]; ok {
|
||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||
} else if copy, ok := saves[path]; ok {
|
||||
if copy {
|
||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
||||
if _, ok := selections[path]; ok {
|
||||
win.print(lnwidth, i, fg, termbox.ColorMagenta, " ")
|
||||
} else if cp, ok := saves[path]; ok {
|
||||
if cp {
|
||||
win.print(lnwidth, i, fg, termbox.ColorYellow, " ")
|
||||
} else {
|
||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
||||
win.print(lnwidth, i, fg, termbox.ColorRed, " ")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,65 +318,33 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool)
|
||||
}
|
||||
|
||||
w := runeSliceWidth(s)
|
||||
if w > win.w-2 {
|
||||
s = runeSliceWidthRange(s, 0, win.w-2)
|
||||
|
||||
if w > win.w-3 {
|
||||
s = runeSliceWidthRange(s, 0, win.w-4)
|
||||
s = append(s, '~')
|
||||
} else {
|
||||
for i := 0; i < win.w-2-w; i++ {
|
||||
for i := 0; i < win.w-3-w; i++ {
|
||||
s = append(s, ' ')
|
||||
}
|
||||
}
|
||||
|
||||
var info string
|
||||
info := fileInfo(f, dir)
|
||||
|
||||
for _, s := range gOpts.info {
|
||||
switch s {
|
||||
case "size":
|
||||
if !(gOpts.dircounts && f.IsDir()) {
|
||||
info = fmt.Sprintf("%s %4s", info, humanize(f.Size()))
|
||||
continue
|
||||
}
|
||||
|
||||
if f.count == -1 {
|
||||
d, err := os.Open(path)
|
||||
if err != nil {
|
||||
f.count = -2
|
||||
}
|
||||
|
||||
names, err := d.Readdirnames(1000)
|
||||
d.Close()
|
||||
|
||||
if names == nil && err != io.EOF {
|
||||
f.count = -2
|
||||
} else {
|
||||
f.count = len(names)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case f.count < 0:
|
||||
info = fmt.Sprintf("%s ?", info)
|
||||
case f.count < 1000:
|
||||
info = fmt.Sprintf("%s %4d", info, f.count)
|
||||
default:
|
||||
info = fmt.Sprintf("%s 999+", info)
|
||||
}
|
||||
case "time":
|
||||
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
||||
default:
|
||||
log.Printf("unknown info type: %s", s)
|
||||
if len(info) > 0 && win.w-2 > 2*len(info) {
|
||||
if win.w-2 > w+len(info) {
|
||||
s = runeSliceWidthRange(s, 0, win.w-3-len(info))
|
||||
} else {
|
||||
s = runeSliceWidthRange(s, 0, win.w-4-len(info))
|
||||
s = append(s, '~')
|
||||
}
|
||||
}
|
||||
|
||||
if len(info) > 0 && win.w > 2*len(info) {
|
||||
s = runeSliceWidthRange(s, 0, win.w-2-len(info))
|
||||
for _, r := range info {
|
||||
s = append(s, r)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add a trailing '~' to the name if cut
|
||||
s = append(s, ' ')
|
||||
|
||||
win.print(1, i, fg, bg, string(s))
|
||||
win.print(lnwidth+1, i, fg, bg, string(s))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,22 +356,23 @@ type ui struct {
|
||||
msg string
|
||||
regPrev *reg
|
||||
dirPrev *dir
|
||||
exprChan chan multiExpr
|
||||
exprChan chan expr
|
||||
keyChan chan string
|
||||
evChan chan termbox.Event
|
||||
menuBuf *bytes.Buffer
|
||||
cmdPrefix string
|
||||
cmdAccLeft []rune
|
||||
cmdAccRight []rune
|
||||
cmdBuf []rune
|
||||
cmdYankBuf []rune
|
||||
keyAcc []rune
|
||||
keyCount []rune
|
||||
colors colorMap
|
||||
}
|
||||
|
||||
func getWidths(wtot int) []int {
|
||||
rsum := 0
|
||||
for _, rat := range gOpts.ratios {
|
||||
rsum += rat
|
||||
for _, r := range gOpts.ratios {
|
||||
rsum += r
|
||||
}
|
||||
|
||||
wlen := len(gOpts.ratios)
|
||||
@@ -443,6 +385,10 @@ func getWidths(wtot int) []int {
|
||||
}
|
||||
widths[wlen-1] = wtot - wsum
|
||||
|
||||
if gOpts.drawbox {
|
||||
widths[wlen-1]--
|
||||
}
|
||||
|
||||
return widths
|
||||
}
|
||||
|
||||
@@ -456,7 +402,11 @@ func getWins() []*win {
|
||||
wacc := 0
|
||||
wlen := len(widths)
|
||||
for i := 0; i < wlen; i++ {
|
||||
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
|
||||
if gOpts.drawbox {
|
||||
wins = append(wins, newWin(widths[i], htot-4, wacc+1, 2))
|
||||
} else {
|
||||
wins = append(wins, newWin(widths[i], htot-2, wacc, 1))
|
||||
}
|
||||
wacc += widths[i]
|
||||
}
|
||||
|
||||
@@ -466,11 +416,27 @@ func getWins() []*win {
|
||||
func newUI() *ui {
|
||||
wtot, htot := termbox.Size()
|
||||
|
||||
evChan := make(chan termbox.Event)
|
||||
|
||||
evQueue := make(chan termbox.Event)
|
||||
go func() {
|
||||
for {
|
||||
evChan <- termbox.PollEvent()
|
||||
evQueue <- termbox.PollEvent()
|
||||
}
|
||||
}()
|
||||
|
||||
evChan := make(chan termbox.Event)
|
||||
go func() {
|
||||
for {
|
||||
ev := <-evQueue
|
||||
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
|
||||
select {
|
||||
case ev2 := <-evQueue:
|
||||
ev2.Mod = termbox.ModAlt
|
||||
evChan <- ev2
|
||||
continue
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
evChan <- ev
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -481,6 +447,7 @@ func newUI() *ui {
|
||||
menuWin: newWin(wtot, 1, 0, htot-2),
|
||||
keyChan: make(chan string, 1000),
|
||||
evChan: evChan,
|
||||
colors: parseColors(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -492,25 +459,59 @@ func (ui *ui) renew() {
|
||||
wacc := 0
|
||||
wlen := len(widths)
|
||||
for i := 0; i < wlen; i++ {
|
||||
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
|
||||
if gOpts.drawbox {
|
||||
ui.wins[i].renew(widths[i], htot-4, wacc+1, 2)
|
||||
} else {
|
||||
ui.wins[i].renew(widths[i], htot-2, wacc, 1)
|
||||
}
|
||||
wacc += widths[i]
|
||||
}
|
||||
|
||||
ui.promptWin.renew(wtot, 1, 0, 0)
|
||||
ui.msgWin.renew(wtot, 1, 0, htot-1)
|
||||
ui.menuWin.renew(wtot, 1, 0, htot-2)
|
||||
}
|
||||
|
||||
func (ui *ui) print(msg string) {
|
||||
func (ui *ui) sort() {
|
||||
if ui.dirPrev == nil {
|
||||
return
|
||||
}
|
||||
name := ui.dirPrev.name()
|
||||
ui.dirPrev.sort()
|
||||
ui.dirPrev.sel(name, ui.wins[0].h)
|
||||
}
|
||||
|
||||
func (ui *ui) echo(msg string) {
|
||||
ui.msg = msg
|
||||
}
|
||||
|
||||
func (ui *ui) echof(format string, a ...interface{}) {
|
||||
ui.echo(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
func (ui *ui) echomsg(msg string) {
|
||||
ui.msg = msg
|
||||
log.Print(msg)
|
||||
}
|
||||
|
||||
func (ui *ui) printf(format string, a ...interface{}) {
|
||||
ui.print(fmt.Sprintf(format, a...))
|
||||
func (ui *ui) echomsgf(format string, a ...interface{}) {
|
||||
ui.echomsg(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
func (ui *ui) echoerr(msg string) {
|
||||
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
|
||||
log.Printf("error: %s", msg)
|
||||
}
|
||||
|
||||
func (ui *ui) echoerrf(format string, a ...interface{}) {
|
||||
ui.echoerr(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
type reg struct {
|
||||
path string
|
||||
lines []string
|
||||
loading bool
|
||||
loadTime time.Time
|
||||
path string
|
||||
lines []string
|
||||
}
|
||||
|
||||
func (ui *ui) loadFile(nav *nav) {
|
||||
@@ -536,7 +537,7 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
||||
return
|
||||
}
|
||||
|
||||
ui.msg = fmt.Sprintf("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
|
||||
ui.echof("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
|
||||
}
|
||||
|
||||
func (ui *ui) drawPromptLine(nav *nav) {
|
||||
@@ -584,14 +585,57 @@ func (ui *ui) drawStatLine(nav *nav) {
|
||||
|
||||
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
||||
|
||||
tot := len(currDir.fi)
|
||||
tot := len(currDir.files)
|
||||
ind := min(currDir.ind+1, tot)
|
||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||
|
||||
ruler := fmt.Sprintf("%d/%d", ind, tot)
|
||||
var progress string
|
||||
|
||||
if nav.copyTotal > 0 {
|
||||
percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal))
|
||||
progress += fmt.Sprintf(" [%d%%]", percentage)
|
||||
}
|
||||
|
||||
if nav.moveTotal > 0 {
|
||||
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
|
||||
}
|
||||
|
||||
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
|
||||
|
||||
ui.msgWin.printRight(0, fg, bg, ruler)
|
||||
}
|
||||
|
||||
func (ui *ui) drawBox(nav *nav) {
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
w, h := termbox.Size()
|
||||
|
||||
for i := 1; i < w-1; i++ {
|
||||
termbox.SetCell(i, 1, '─', fg, bg)
|
||||
termbox.SetCell(i, h-2, '─', fg, bg)
|
||||
}
|
||||
|
||||
for i := 2; i < h-2; i++ {
|
||||
termbox.SetCell(0, i, '│', fg, bg)
|
||||
termbox.SetCell(w-1, i, '│', fg, bg)
|
||||
}
|
||||
|
||||
termbox.SetCell(0, 1, '┌', fg, bg)
|
||||
termbox.SetCell(w-1, 1, '┐', fg, bg)
|
||||
termbox.SetCell(0, h-2, '└', fg, bg)
|
||||
termbox.SetCell(w-1, h-2, '┘', fg, bg)
|
||||
|
||||
wacc := 0
|
||||
for wind := 0; wind < len(ui.wins)-1; wind++ {
|
||||
wacc += ui.wins[wind].w
|
||||
termbox.SetCell(wacc, 1, '┬', fg, bg)
|
||||
for i := 2; i < h-2; i++ {
|
||||
termbox.SetCell(wacc, i, '│', fg, bg)
|
||||
}
|
||||
termbox.SetCell(wacc, h-2, '┴', fg, bg)
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) draw(nav *nav) {
|
||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||
|
||||
@@ -609,7 +653,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
doff := len(nav.dirs) - length
|
||||
for i := 0; i < length; i++ {
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves)
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
||||
}
|
||||
|
||||
switch ui.cmdPrefix {
|
||||
@@ -635,13 +679,17 @@ func (ui *ui) draw(nav *nav) {
|
||||
preview := ui.wins[len(ui.wins)-1]
|
||||
|
||||
if f.IsDir() {
|
||||
preview.printDir(ui.dirPrev, nav.marks, nav.saves)
|
||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
||||
} else if f.Mode().IsRegular() {
|
||||
preview.printReg(ui.regPrev)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if gOpts.drawbox {
|
||||
ui.drawBox(nav)
|
||||
}
|
||||
|
||||
if ui.menuBuf != nil {
|
||||
lines := strings.Split(ui.menuBuf.String(), "\n")
|
||||
|
||||
@@ -650,6 +698,10 @@ func (ui *ui) draw(nav *nav) {
|
||||
ui.menuWin.h = len(lines) - 1
|
||||
ui.menuWin.y = ui.wins[0].h - ui.menuWin.h
|
||||
|
||||
if gOpts.drawbox {
|
||||
ui.menuWin.y += 2
|
||||
}
|
||||
|
||||
ui.menuWin.printLine(0, 0, termbox.AttrBold, termbox.AttrBold, lines[0])
|
||||
for i, line := range lines[1:] {
|
||||
ui.menuWin.printLine(0, i+1, fg, bg, "")
|
||||
@@ -668,11 +720,12 @@ func (ui *ui) draw(nav *nav) {
|
||||
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
||||
binds = make(map[string]expr)
|
||||
for key, expr := range keys {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
binds[key] = expr
|
||||
if key == prefix {
|
||||
ok = true
|
||||
}
|
||||
if !strings.HasPrefix(key, prefix) {
|
||||
continue
|
||||
}
|
||||
binds[key] = expr
|
||||
if key == prefix {
|
||||
ok = true
|
||||
}
|
||||
}
|
||||
return
|
||||
@@ -698,6 +751,26 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
|
||||
return b
|
||||
}
|
||||
|
||||
func listMarks(marks map[string]string) *bytes.Buffer {
|
||||
t := new(tabwriter.Writer)
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
var keys []string
|
||||
for k := range marks {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
|
||||
fmt.Fprintln(t, "mark\tpath")
|
||||
for _, k := range keys {
|
||||
fmt.Fprintf(t, "%s\t%s\n", k, marks[k])
|
||||
}
|
||||
t.Flush()
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
func (ui *ui) pollEvent() termbox.Event {
|
||||
select {
|
||||
case key := <-ui.keyChan:
|
||||
@@ -706,17 +779,21 @@ func (ui *ui) pollEvent() termbox.Event {
|
||||
if len(key) == 1 {
|
||||
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
||||
} else {
|
||||
switch key {
|
||||
case "<lt>":
|
||||
switch {
|
||||
case key == "<lt>":
|
||||
ev.Ch = '<'
|
||||
case "<gt>":
|
||||
case key == "<gt>":
|
||||
ev.Ch = '>'
|
||||
case reAltKey.MatchString(key):
|
||||
match := reAltKey.FindStringSubmatch(key)[1]
|
||||
ev.Ch, _ = utf8.DecodeRuneInString(match)
|
||||
ev.Mod = termbox.ModAlt
|
||||
default:
|
||||
if val, ok := gValKey[key]; ok {
|
||||
ev.Key = val
|
||||
} else {
|
||||
ev.Key = termbox.KeyEsc
|
||||
ui.printf("unknown key: %s", key)
|
||||
ui.echoerrf("unknown key: %s", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -727,24 +804,11 @@ func (ui *ui) pollEvent() termbox.Event {
|
||||
}
|
||||
}
|
||||
|
||||
type multiExpr struct {
|
||||
expr expr
|
||||
count int
|
||||
}
|
||||
|
||||
func readCmdEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
ch <- multiExpr{&callExpr{"cmd-insert", []string{string(ev.Ch)}}, 1}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
||||
ch <- multiExpr{expr, 1}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
redraw := &callExpr{"redraw", nil}
|
||||
// This function is used to read a normal event on the client side. For keys,
|
||||
// digits are interpreted as command counts but this is only done for digits
|
||||
// preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
draw := &callExpr{"draw", nil, 1}
|
||||
count := 1
|
||||
|
||||
switch ev.Type {
|
||||
@@ -752,9 +816,11 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
switch {
|
||||
case ev.Ch == '<':
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'l', 't', '>')
|
||||
ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...)
|
||||
case ev.Ch == '>':
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'g', 't', '>')
|
||||
ui.keyAcc = append(ui.keyAcc, []rune("<gt>")...)
|
||||
case ev.Mod == termbox.ModAlt:
|
||||
ui.keyAcc = append(ui.keyAcc, '<', 'a', '-', ev.Ch, '>')
|
||||
case unicode.IsDigit(ev.Ch) && len(ui.keyAcc) == 0:
|
||||
ui.keyCount = append(ui.keyCount, ev.Ch)
|
||||
default:
|
||||
@@ -762,20 +828,25 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if string(val) == "<esc>" {
|
||||
ch <- multiExpr{redraw, 1}
|
||||
if val == "<esc>" {
|
||||
ch <- draw
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
}
|
||||
ui.keyAcc = append(ui.keyAcc, val...)
|
||||
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||
}
|
||||
|
||||
if len(ui.keyAcc) == 0 {
|
||||
ch <- draw
|
||||
break
|
||||
}
|
||||
|
||||
binds, ok := findBinds(gOpts.keys, string(ui.keyAcc))
|
||||
|
||||
switch len(binds) {
|
||||
case 0:
|
||||
ui.printf("unknown mapping: %s", string(ui.keyAcc))
|
||||
ch <- multiExpr{redraw, 1}
|
||||
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
||||
ch <- draw
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
ui.menuBuf = nil
|
||||
@@ -787,61 +858,71 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyAcc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
if e, ok := expr.(*callExpr); ok {
|
||||
e.count = count
|
||||
}
|
||||
ch <- expr
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
}
|
||||
if len(ui.keyAcc) > 0 {
|
||||
ui.menuBuf = listBinds(binds)
|
||||
ch <- multiExpr{redraw, 1}
|
||||
} else if ui.menuBuf != nil {
|
||||
ui.menuBuf = nil
|
||||
} else {
|
||||
ui.menuBuf = listBinds(binds)
|
||||
ch <- draw
|
||||
}
|
||||
default:
|
||||
if ok {
|
||||
// TODO: use a delay
|
||||
if len(ui.keyCount) > 0 {
|
||||
c, err := strconv.Atoi(string(ui.keyCount))
|
||||
if err != nil {
|
||||
log.Printf("converting command count: %s", err)
|
||||
}
|
||||
count = c
|
||||
} else {
|
||||
count = 1
|
||||
}
|
||||
expr := gOpts.keys[string(ui.keyAcc)]
|
||||
ch <- multiExpr{expr, count}
|
||||
if e, ok := expr.(*callExpr); ok {
|
||||
e.count = count
|
||||
}
|
||||
ch <- expr
|
||||
ui.keyAcc = nil
|
||||
ui.keyCount = nil
|
||||
}
|
||||
if len(ui.keyAcc) > 0 {
|
||||
ui.menuBuf = listBinds(binds)
|
||||
ch <- multiExpr{redraw, 1}
|
||||
} else {
|
||||
ui.menuBuf = nil
|
||||
} else {
|
||||
ui.menuBuf = listBinds(binds)
|
||||
ch <- draw
|
||||
}
|
||||
}
|
||||
case termbox.EventResize:
|
||||
ch <- multiExpr{redraw, 1}
|
||||
default:
|
||||
// TODO: handle other events
|
||||
ch <- &callExpr{"redraw", nil, 1}
|
||||
}
|
||||
}
|
||||
|
||||
// This function is used to read expressions on the client side. Digits are
|
||||
// interpreted as command counts but this is only done for digits preceding any
|
||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||
func (ui *ui) readExpr() <-chan multiExpr {
|
||||
ch := make(chan multiExpr)
|
||||
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||
if ev.Ch != 0 {
|
||||
if ev.Mod == termbox.ModAlt {
|
||||
val := string([]rune{'<', 'a', '-', ev.Ch, '>'})
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
ch <- expr
|
||||
}
|
||||
} else {
|
||||
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1}
|
||||
}
|
||||
} else {
|
||||
val := gKeyVal[ev.Key]
|
||||
if expr, ok := gOpts.cmdkeys[val]; ok {
|
||||
ch <- expr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) readExpr() <-chan expr {
|
||||
ch := make(chan expr)
|
||||
|
||||
ui.exprChan = ch
|
||||
|
||||
go func() {
|
||||
ch <- multiExpr{&callExpr{"redraw", nil}, 1}
|
||||
ch <- &callExpr{"draw", nil, 1}
|
||||
|
||||
for {
|
||||
ev := ui.pollEvent()
|
||||
@@ -858,6 +939,14 @@ func (ui *ui) readExpr() <-chan multiExpr {
|
||||
return ch
|
||||
}
|
||||
|
||||
func setColorMode() {
|
||||
if gOpts.color256 {
|
||||
termbox.SetOutputMode(termbox.Output256)
|
||||
} else {
|
||||
termbox.SetOutputMode(termbox.OutputNormal)
|
||||
}
|
||||
}
|
||||
|
||||
func (ui *ui) pause() {
|
||||
termbox.Close()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user