Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
No files matched your search
@@ -2,3 +2,4 @@ lf
|
|||||||
lf.exe
|
lf.exe
|
||||||
tags
|
tags
|
||||||
dist/
|
dist/
|
||||||
|
vendor/
|
||||||
Generated
+21
@@ -0,0 +1,21 @@
|
|||||||
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/mattn/go-runewidth"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/nsf/termbox-go"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3"
|
||||||
|
|
||||||
|
[solve-meta]
|
||||||
|
analyzer-name = "dep"
|
||||||
|
analyzer-version = 1
|
||||||
|
inputs-digest = "8508b73787d4948edb76ccc25789c311a4ab84d4c8c0b96b267857e2e88d974e"
|
||||||
|
solver-name = "gps-cdcl"
|
||||||
|
solver-version = 1
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
# Gopkg.toml example
|
||||||
|
#
|
||||||
|
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||||
|
# for detailed Gopkg.toml documentation.
|
||||||
|
#
|
||||||
|
# required = ["github.com/user/thing/cmd/thing"]
|
||||||
|
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project"
|
||||||
|
# version = "1.0.0"
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project2"
|
||||||
|
# branch = "dev"
|
||||||
|
# source = "github.com/myfork/project2"
|
||||||
|
#
|
||||||
|
# [[override]]
|
||||||
|
# name = "github.com/x/y"
|
||||||
|
# version = "2.4.0"
|
||||||
|
#
|
||||||
|
# [prune]
|
||||||
|
# non-go = false
|
||||||
|
# go-tests = true
|
||||||
|
# unused-packages = true
|
||||||
|
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/nsf/termbox-go"
|
||||||
|
|
||||||
|
[prune]
|
||||||
|
go-tests = true
|
||||||
|
unused-packages = true
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
`lf` (as in "list files") is a terminal file manager written in Go.
|
`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.
|
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.
|
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.
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
@@ -38,7 +38,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
|
|
||||||
## May-Futures
|
## May-Futures
|
||||||
|
|
||||||
- Bookmarks
|
- Mouse control
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdItem struct {
|
type cmdItem struct {
|
||||||
@@ -17,14 +19,16 @@ type cmdItem struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type app struct {
|
type app struct {
|
||||||
ui *ui
|
ui *ui
|
||||||
nav *nav
|
nav *nav
|
||||||
quitChan chan bool
|
ticker *time.Ticker
|
||||||
cmd *exec.Cmd
|
quitChan chan bool
|
||||||
cmdIn io.WriteCloser
|
cmd *exec.Cmd
|
||||||
cmdOutBuf []byte
|
cmdIn io.WriteCloser
|
||||||
cmdHist []cmdItem
|
cmdOutBuf []byte
|
||||||
cmdHistInd int
|
cmdHistory []cmdItem
|
||||||
|
cmdHistoryBeg int
|
||||||
|
cmdHistoryInd int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newApp() *app {
|
func newApp() *app {
|
||||||
@@ -34,6 +38,7 @@ func newApp() *app {
|
|||||||
return &app{
|
return &app{
|
||||||
ui: ui,
|
ui: ui,
|
||||||
nav: nav,
|
nav: nav,
|
||||||
|
ticker: new(time.Ticker),
|
||||||
quitChan: make(chan bool, 1),
|
quitChan: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +54,7 @@ func (app *app) readFile(path string) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
p := newParser(f)
|
p := newParser(f)
|
||||||
|
|
||||||
for p.parse() {
|
for p.parse() {
|
||||||
p.expr.eval(app, nil)
|
p.expr.eval(app, nil)
|
||||||
}
|
}
|
||||||
@@ -58,9 +64,74 @@ func (app *app) readFile(path string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the main event loop of the application. There are two channels to
|
func (app *app) readHistory() error {
|
||||||
// read expressions from client and server. Reading and evaluation are done on
|
f, err := os.Open(gHistoryPath)
|
||||||
// separate goroutines.
|
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() {
|
func (app *app) loop() {
|
||||||
clientChan := app.ui.readExpr()
|
clientChan := app.ui.readExpr()
|
||||||
serverChan := readExpr()
|
serverChan := readExpr()
|
||||||
@@ -70,6 +141,14 @@ func (app *app) loop() {
|
|||||||
case <-app.quitChan:
|
case <-app.quitChan:
|
||||||
log.Print("bye!")
|
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 != "" {
|
if gLastDirPath != "" {
|
||||||
f, err := os.Create(gLastDirPath)
|
f, err := os.Create(gLastDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -89,7 +168,8 @@ func (app *app) loop() {
|
|||||||
case d := <-app.nav.dirChan:
|
case d := <-app.nav.dirChan:
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
if ok {
|
||||||
d.find(prev.name(), app.nav.height)
|
d.ind = prev.ind
|
||||||
|
d.sel(prev.name(), app.nav.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.nav.dirCache[d.path] = d
|
app.nav.dirCache[d.path] = d
|
||||||
@@ -130,6 +210,10 @@ func (app *app) loop() {
|
|||||||
case e := <-serverChan:
|
case e := <-serverChan:
|
||||||
e.eval(app, nil)
|
e.eval(app, nil)
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case <-app.ticker.C:
|
||||||
|
app.nav.renew()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,20 +224,34 @@ func (app *app) exportVars() {
|
|||||||
envFile = f.path
|
envFile = f.path
|
||||||
}
|
}
|
||||||
|
|
||||||
marks := app.nav.currMarks()
|
selections := app.nav.currSelections()
|
||||||
|
|
||||||
envFiles := strings.Join(marks, gOpts.filesep)
|
envFiles := strings.Join(selections, gOpts.filesep)
|
||||||
|
|
||||||
os.Setenv("f", envFile)
|
os.Setenv("f", envFile)
|
||||||
os.Setenv("fs", envFiles)
|
os.Setenv("fs", envFiles)
|
||||||
|
|
||||||
if len(marks) == 0 {
|
if len(selections) == 0 {
|
||||||
os.Setenv("fx", envFile)
|
os.Setenv("fx", envFile)
|
||||||
} else {
|
} else {
|
||||||
os.Setenv("fx", envFiles)
|
os.Setenv("fx", envFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("id", strconv.Itoa(gClientID))
|
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 waitKey() error {
|
func waitKey() error {
|
||||||
@@ -170,13 +268,13 @@ func waitKey() error {
|
|||||||
return nil
|
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
|
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||||
// $ No No Yes Yes Yes Pause and then resume
|
// $ No No Yes Yes Yes Pause and then resume
|
||||||
// % No No Yes Yes Yes Use statline for input/output
|
// % No No Yes Yes Yes Statline for input/output
|
||||||
// ! Yes No Yes Yes Yes Pause and then resume
|
// ! Yes No Yes Yes Yes Pause and then resume
|
||||||
// & No Yes No No No Do nothing
|
// & No Yes No No No Do nothing
|
||||||
func (app *app) runShell(s string, args []string, prefix string) {
|
func (app *app) runShell(s string, args []string, prefix string) {
|
||||||
app.exportVars()
|
app.exportVars()
|
||||||
|
|
||||||
@@ -254,7 +352,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
}
|
}
|
||||||
app.cmd = nil
|
app.cmd = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
app.ui.exprChan <- &callExpr{"reload", nil, 1}
|
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,18 +8,19 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
logFile, err := os.Create(gLogPath)
|
f, err := os.Create(gLogPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer os.Remove(gLogPath)
|
defer os.Remove(gLogPath)
|
||||||
defer logFile.Close()
|
defer f.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(f)
|
||||||
|
|
||||||
log.Print("hi!")
|
log.Print("hi!")
|
||||||
|
|
||||||
@@ -32,8 +33,18 @@ func run() {
|
|||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
|
||||||
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
|
for _, path := range gConfigPaths {
|
||||||
app.readFile(gConfigPath)
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
app.readFile(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.nav.readMarks(); err != nil {
|
||||||
|
app.ui.printf("reading marks file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.readHistory(); err != nil {
|
||||||
|
app.ui.printf("reading history file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.loop()
|
app.loop()
|
||||||
@@ -43,10 +54,14 @@ func readExpr() <-chan expr {
|
|||||||
ch := make(chan expr)
|
ch := make(chan expr)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
duration := 1 * time.Second
|
||||||
|
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
if err != nil {
|
for err != nil {
|
||||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
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)
|
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||||
@@ -68,7 +83,7 @@ func readExpr() <-chan expr {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveFiles(list []string, copy bool) error {
|
func saveFiles(list []string, cp bool) error {
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dialing to save files: %s", err)
|
return fmt.Errorf("dialing to save files: %s", err)
|
||||||
@@ -79,7 +94,7 @@ func saveFiles(list []string, copy bool) error {
|
|||||||
|
|
||||||
fmt.Fprintln(c, "save")
|
fmt.Fprintln(c, "save")
|
||||||
|
|
||||||
if copy {
|
if cp {
|
||||||
fmt.Fprintln(c, "copy")
|
fmt.Fprintln(c, "copy")
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(c, "move")
|
fmt.Fprintln(c, "move")
|
||||||
@@ -93,7 +108,7 @@ func saveFiles(list []string, copy bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFiles() (list []string, copy bool, err error) {
|
func loadFiles() (list []string, cp bool, err error) {
|
||||||
c, e := net.Dial(gSocketProt, gSocketPath)
|
c, e := net.Dial(gSocketProt, gSocketPath)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = fmt.Errorf("dialing to load files: %s", e)
|
err = fmt.Errorf("dialing to load files: %s", e)
|
||||||
@@ -109,9 +124,9 @@ func loadFiles() (list []string, copy bool, err error) {
|
|||||||
|
|
||||||
switch s.Text() {
|
switch s.Text() {
|
||||||
case "copy":
|
case "copy":
|
||||||
copy = true
|
cp = true
|
||||||
case "move":
|
case "move":
|
||||||
copy = false
|
cp = false
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -12,6 +12,29 @@ import (
|
|||||||
|
|
||||||
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
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 {
|
type colorEntry struct {
|
||||||
fg termbox.Attribute
|
fg termbox.Attribute
|
||||||
bg termbox.Attribute
|
bg termbox.Attribute
|
||||||
@@ -57,13 +80,12 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
|
|||||||
toks := strings.Split(s, ";")
|
toks := strings.Split(s, ";")
|
||||||
|
|
||||||
var nums []int
|
var nums []int
|
||||||
for _, t := range toks {
|
for _, tok := range toks {
|
||||||
if t == "" {
|
if tok == "" {
|
||||||
fg = termbox.ColorDefault
|
nums = append(nums, 0)
|
||||||
bg = termbox.ColorDefault
|
continue
|
||||||
break
|
|
||||||
}
|
}
|
||||||
n, err := strconv.Atoi(t)
|
n, err := strconv.Atoi(tok)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("converting escape code: %s", err)
|
log.Printf("converting escape code: %s", err)
|
||||||
continue
|
continue
|
||||||
@@ -71,17 +93,19 @@ func applyAnsiCodes(s string, fg, bg termbox.Attribute) (termbox.Attribute, term
|
|||||||
nums = append(nums, n)
|
nums = append(nums, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse 256 color terminal ansi codes
|
for i := 0; i < len(nums); i++ {
|
||||||
if len(nums) == 3 {
|
n := nums[i]
|
||||||
if nums[0] == 48 && nums[1] == 5 {
|
switch {
|
||||||
bg = termbox.Attribute(nums[2] + 1)
|
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
|
||||||
}
|
}
|
||||||
if nums[0] == 38 && nums[1] == 5 {
|
|
||||||
fg = termbox.Attribute(nums[2] + 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, n := range nums {
|
|
||||||
attr, ok := gAnsiCodes[n]
|
attr, ok := gAnsiCodes[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("unknown ansi code: %d", n)
|
log.Printf("unknown ansi code: %d", n)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+75
-51
@@ -24,34 +24,45 @@ var (
|
|||||||
"open",
|
"open",
|
||||||
"quit",
|
"quit",
|
||||||
"top",
|
"top",
|
||||||
"bot",
|
"bottom",
|
||||||
"toggle",
|
"toggle",
|
||||||
"invert",
|
"invert",
|
||||||
"unmark",
|
"unselect",
|
||||||
"yank",
|
"copy",
|
||||||
"delete",
|
"cut",
|
||||||
"put",
|
"paste",
|
||||||
"clear",
|
"clear",
|
||||||
"draw",
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
|
"load",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
"shell",
|
"shell",
|
||||||
"shell-pipe",
|
"shell-pipe",
|
||||||
"shell-wait",
|
"shell-wait",
|
||||||
"shell-async",
|
"shell-async",
|
||||||
|
"find",
|
||||||
|
"find-back",
|
||||||
|
"find-next",
|
||||||
|
"find-prev",
|
||||||
"search",
|
"search",
|
||||||
"search-back",
|
"search-back",
|
||||||
"search-next",
|
"search-next",
|
||||||
"search-prev",
|
"search-prev",
|
||||||
|
"mark-save",
|
||||||
|
"mark-load",
|
||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
"cd",
|
"cd",
|
||||||
"select",
|
"select",
|
||||||
|
"source",
|
||||||
"push",
|
"push",
|
||||||
}
|
}
|
||||||
|
|
||||||
gOptWords = []string{
|
gOptWords = []string{
|
||||||
|
"anchorfind",
|
||||||
|
"noanchorfind",
|
||||||
|
"anchorfind!",
|
||||||
"dircounts",
|
"dircounts",
|
||||||
"nodircounts",
|
"nodircounts",
|
||||||
"dircounts!",
|
"dircounts!",
|
||||||
@@ -82,6 +93,8 @@ var (
|
|||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"findlen",
|
||||||
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
"filesep",
|
"filesep",
|
||||||
@@ -93,6 +106,7 @@ var (
|
|||||||
"timefmt",
|
"timefmt",
|
||||||
"ratios",
|
"ratios",
|
||||||
"info",
|
"info",
|
||||||
|
"shellopts",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -108,13 +122,15 @@ func matchLongest(s1, s2 string) string {
|
|||||||
|
|
||||||
func matchWord(s string, words []string) (matches []string, longest string) {
|
func matchWord(s string, words []string) (matches []string, longest string) {
|
||||||
for _, w := range words {
|
for _, w := range words {
|
||||||
if strings.HasPrefix(w, s) {
|
if !strings.HasPrefix(w, s) {
|
||||||
matches = append(matches, w)
|
continue
|
||||||
if longest != "" {
|
}
|
||||||
longest = matchLongest(longest, w)
|
|
||||||
} else if s != "" {
|
matches = append(matches, w)
|
||||||
longest = w + " "
|
if longest != "" {
|
||||||
}
|
longest = matchLongest(longest, w)
|
||||||
|
} else if s != "" {
|
||||||
|
longest = w + " "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,32 +144,35 @@ func matchWord(s string, words []string) (matches []string, longest string) {
|
|||||||
func matchExec(s string) (matches []string, longest string) {
|
func matchExec(s string) (matches []string, longest string) {
|
||||||
var words []string
|
var words []string
|
||||||
|
|
||||||
paths := strings.Split(envPath, ":")
|
paths := strings.Split(envPath, string(filepath.ListSeparator))
|
||||||
|
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := ioutil.ReadDir(p)
|
files, err := ioutil.ReadDir(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading path: %s", err)
|
log.Printf("reading path: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range files {
|
||||||
if strings.HasPrefix(f.Name(), s) {
|
if !strings.HasPrefix(f.Name(), s) {
|
||||||
f, err = os.Stat(filepath.Join(p, f.Name()))
|
continue
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,18 +198,19 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting current directory: %s", err)
|
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))
|
dir = unescape(filepath.Dir(dir))
|
||||||
|
|
||||||
fi, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading directory: %s", err)
|
log.Printf("reading directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fi {
|
for _, f := range files {
|
||||||
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
f, err := os.Stat(filepath.Join(dir, f.Name()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting file information: %s", err)
|
log.Printf("getting file information: %s", err)
|
||||||
@@ -198,25 +218,29 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, last := filepath.Split(s)
|
_, last := filepath.Split(s)
|
||||||
if strings.HasPrefix(escape(f.Name()), last) {
|
if !strings.HasPrefix(escape(f.Name()), last) {
|
||||||
name := f.Name()
|
continue
|
||||||
if isRoot(s) || filepath.Base(s) != s {
|
}
|
||||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
|
||||||
}
|
name := f.Name()
|
||||||
name = escape(name)
|
if isRoot(s) || filepath.Base(s) != s {
|
||||||
item := f.Name()
|
name = filepath.Join(filepath.Dir(s), f.Name())
|
||||||
if f.Mode().IsDir() {
|
}
|
||||||
item += string(filepath.Separator)
|
name = escape(name)
|
||||||
}
|
|
||||||
matches = append(matches, item)
|
item := f.Name()
|
||||||
if longest != "" {
|
if f.Mode().IsDir() {
|
||||||
longest = matchLongest(longest, name)
|
item += string(filepath.Separator)
|
||||||
} else if s != "" {
|
}
|
||||||
if f.Mode().IsRegular() {
|
matches = append(matches, item)
|
||||||
longest = name + " "
|
|
||||||
} else {
|
if longest != "" {
|
||||||
longest = name + string(filepath.Separator)
|
longest = matchLongest(longest, name)
|
||||||
}
|
} else if s != "" {
|
||||||
|
if f.Mode().IsRegular() {
|
||||||
|
longest = name + " "
|
||||||
|
} else {
|
||||||
|
longest = name + string(filepath.Separator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,7 +252,7 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
|
||||||
@@ -267,7 +291,7 @@ func compCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func compShell(acc []rune) (matches []string, longestAcc []rune) {
|
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
|
||||||
File renamed without changes.
@@ -1,4 +1,5 @@
|
|||||||
//go:generate gen/docstring.sh
|
//go:generate gen/docstring.sh
|
||||||
|
//go:generate gen/man.sh
|
||||||
|
|
||||||
/*
|
/*
|
||||||
lf is a terminal file manager.
|
lf is a terminal file manager.
|
||||||
@@ -6,103 +7,146 @@ lf is a terminal file manager.
|
|||||||
Source code can be found in the repository at https://github.com/gokcehan/lf.
|
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
|
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
|
Reference
|
||||||
|
|
||||||
The following commands are provided by lf with default keybindings:
|
The following commands are provided by lf with default keybindings:
|
||||||
|
|
||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg' and '<home>')
|
||||||
bot (default 'G')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unselect (default 'u')
|
||||||
yank (default 'y')
|
copy (default 'y')
|
||||||
delete (default 'd')
|
cut (default 'd')
|
||||||
put (default 'p')
|
paste (default 'p')
|
||||||
clear (default 'c')
|
clear (default 'c')
|
||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
shell (default '$')
|
shell (default '$')
|
||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
search (default '/')
|
find (default 'f')
|
||||||
search-back (default '?')
|
find-back (default 'F')
|
||||||
search-next (default 'n')
|
find-next (default ';')
|
||||||
search-prev (default 'N')
|
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:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
sync synchronizes yanked/deleted files with server
|
load load modified files and directories
|
||||||
|
sync synchronizes copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
select changes current file selection to its argument
|
select changes current file selection to its argument
|
||||||
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
|
|
||||||
cmd-escape (default '<esc>')
|
cmd-escape (default '<esc>')
|
||||||
cmd-comp (default '<tab>')
|
cmd-complete (default '<tab>')
|
||||||
cmd-enter (default '<c-j>' and '<enter>')
|
cmd-enter (default '<c-j>' and '<enter>')
|
||||||
cmd-hist-next (default '<c-n>')
|
cmd-history-next (default '<c-n>')
|
||||||
cmd-hist-prev (default '<c-p>')
|
cmd-history-prev (default '<c-p>')
|
||||||
cmd-delete (default '<c-d>' and '<delete>')
|
cmd-delete (default '<c-d>' and '<delete>')
|
||||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||||
cmd-left (default '<c-b>' and '<left>')
|
cmd-left (default '<c-b>' and '<left>')
|
||||||
cmd-right (default '<c-f>' and '<right>')
|
cmd-right (default '<c-f>' and '<right>')
|
||||||
cmd-beg (default '<c-a>' and '<home>')
|
cmd-home (default '<c-a>' and '<home>')
|
||||||
cmd-end (default '<c-e>' and '<end>')
|
cmd-end (default '<c-e>' and '<end>')
|
||||||
cmd-delete-beg (default '<c-u>')
|
cmd-delete-home (default '<c-u>')
|
||||||
cmd-delete-end (default '<c-k>')
|
cmd-delete-end (default '<c-k>')
|
||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-unix-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-yank (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
cmd-transpose (default '<c-t>')
|
||||||
cmd-interrupt (default '<c-c>')
|
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:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dircounts boolean (default off)
|
anchorfind boolean (default on)
|
||||||
dirfirst boolean (default on)
|
dircounts boolean (default off)
|
||||||
drawbox boolean (default off)
|
dirfirst boolean (default on)
|
||||||
globsearch boolean (default off)
|
drawbox boolean (default off)
|
||||||
hidden boolean (default off)
|
globsearch boolean (default off)
|
||||||
ignorecase boolean (default on)
|
hidden boolean (default off)
|
||||||
preview boolean (default on)
|
ignorecase boolean (default on)
|
||||||
reverse boolean (default off)
|
preview boolean (default on)
|
||||||
smartcase boolean (default on)
|
reverse boolean (default off)
|
||||||
wrapscan boolean (default on)
|
smartcase boolean (default on)
|
||||||
scrolloff integer (default 0)
|
wrapscan boolean (default on)
|
||||||
tabstop integer (default 8)
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
filesep string (default "\n")
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
ifs string (default '') (not exported if empty)
|
scrolloff integer (default 0)
|
||||||
previewer string (default '') (not filtered if empty)
|
tabstop integer (default 8)
|
||||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
filesep string (default "\n")
|
||||||
shell string (default 'sh')
|
ifs string (default '') (not exported if empty)
|
||||||
sortby string (default 'natural')
|
previewer string (default '') (not filtered if empty)
|
||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||||
ratios string (default '1:2:3')
|
shell string (default 'sh')
|
||||||
info string (default '')
|
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:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with 'filesep'
|
$fs selected file(s) separated with 'filesep'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$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:
|
The following additional keybindings are provided by default:
|
||||||
|
|
||||||
map zh set hidden!
|
map zh set hidden!
|
||||||
@@ -116,28 +160,37 @@ The following additional keybindings are provided by default:
|
|||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
map gh cd ~
|
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 e $$EDITOR $f
|
||||||
map i $$PAGER $f ('less' if empty)
|
map i $$PAGER $f
|
||||||
map w $$SHELL ('sh' if empty)
|
map w $$SHELL
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on windows:
|
|
||||||
|
|
||||||
map e $notepad "%f%"
|
|
||||||
map i $more "%f%"
|
|
||||||
map w $cmd
|
|
||||||
|
|
||||||
Configuration
|
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
|
Marks file should be located at:
|
||||||
location should be:
|
|
||||||
|
|
||||||
~/.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
|
A sample configuration file can be found at
|
||||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||||
@@ -154,10 +207,11 @@ The following command prefixes are used by lf:
|
|||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file. The
|
The same evaluator is used for the command line and the configuration file for
|
||||||
difference is that prefixes are not necessary in the command line. Instead
|
read and shell commands. The difference is that prefixes are not necessary in
|
||||||
different modes are provided to read corresponding commands. Note that by
|
the command line. Instead, different modes are provided to read corresponding
|
||||||
default these modes are mapped to the prefix keys above.
|
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||||
|
commands are only used from the command line.
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
|
|
||||||
@@ -168,7 +222,8 @@ Characters from '#' to newline are comments and ignored:
|
|||||||
There are three special commands ('set', 'map', and 'cmd') and their variants
|
There are three special commands ('set', 'map', and 'cmd') and their variants
|
||||||
for configuration.
|
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 hidden # boolean on
|
||||||
set nohidden # boolean off
|
set nohidden # boolean off
|
||||||
@@ -178,16 +233,16 @@ for configuration.
|
|||||||
set sortby 'time' # string value with single quotes (whitespaces)
|
set sortby 'time' # string value with single quotes (whitespaces)
|
||||||
set sortby "time" # string value with double quotes (backslash escapes)
|
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 'map' is used to bind a key to a command which can be builtin command,
|
||||||
command, or shell command:
|
custom command, or shell command:
|
||||||
|
|
||||||
map gh cd ~ # builtin command
|
map gh cd ~ # builtin command
|
||||||
map D trash # custom command
|
map D trash # custom command
|
||||||
map i $less $f # shell 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
|
Command 'cmap' is used to bind a key to a command line command which can only
|
||||||
the builtin commands:
|
be one of the builtin commands:
|
||||||
|
|
||||||
cmap <c-g> cmd-escape
|
cmap <c-g> cmd-escape
|
||||||
|
|
||||||
@@ -196,9 +251,9 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
map gh # deletes 'gh' mapping
|
map gh # deletes 'gh' mapping
|
||||||
cmap <c-g> # deletes '<c-g>' 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:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -221,6 +276,53 @@ prefix.
|
|||||||
set info time
|
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
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
@@ -261,7 +363,7 @@ trash. A first attempt to write such a command may look like this:
|
|||||||
fi
|
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'
|
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:
|
variable is provided. We can use this variable to get rid of the conditional:
|
||||||
|
|
||||||
@@ -370,7 +472,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
|
needs. For example, you can configure the number of columns in the ui with
|
||||||
respect to the terminal width as follows:
|
respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -390,34 +492,35 @@ Setting the file selection is done with 'save' command:
|
|||||||
|
|
||||||
Getting the file selection is similarly done with 'load' command:
|
Getting the file selection is similarly done with 'load' command:
|
||||||
|
|
||||||
resp=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$resp" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$resp" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
# do something with $list
|
# do something with $list
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
# do something else with $list
|
# do something else with $list
|
||||||
fi
|
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
|
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||||
should not be needed for users.
|
should not be needed for users.
|
||||||
|
|
||||||
File Operations
|
File Operations
|
||||||
|
|
||||||
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
lf uses 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
|
this purpose, when you 'copy' a file, it doesn't actually copy the file on the
|
||||||
file on the disk, but only records its name to memory. The actual file
|
disk, but only records its name to memory. The actual file operation takes
|
||||||
operation takes place when you do the 'put' in which case the 'cp' command is
|
place when you 'paste' in which case the 'cp' command is used. Similarly the
|
||||||
used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
'mv' command is used for 'cut' followed by 'paste'.
|
||||||
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.
|
|
||||||
|
|
||||||
You can customize these operations by defining a 'put' command. This is a
|
You can customize these operations by defining a 'paste' command. This is a
|
||||||
special command that is called when it is defined instead of the builtin
|
special command that is called when it is defined instead of the builtin
|
||||||
implementation. The default behavior is similar to the following command:
|
implementation. The default behavior is similar to the following command:
|
||||||
|
|
||||||
cmd put ${{
|
cmd paste %{{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
@@ -426,9 +529,8 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
lf -remote 'send load'
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
lf -remote 'send clear'
|
||||||
lf -remote "send sync"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
||||||
@@ -443,31 +545,29 @@ completely are provided in the example configuration file.
|
|||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can use 'open-file' command to open a file. This is a special command
|
You can define a an 'open' command (default 'l') to configure file opening.
|
||||||
called by 'open' when the current file is not a directory. Normally a user maps
|
This command is only called when the current file is not a directory, otherwise
|
||||||
the 'open' command to a key (default 'l') and customize 'open-file' command as
|
the directory is entered instead. You can define it just as you would define
|
||||||
desired. You can define it just as you would define any other command:
|
any other command:
|
||||||
|
|
||||||
cmd open-file $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
It is possible to use different command types:
|
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:
|
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
|
case $(file --mime-type $f -b) in
|
||||||
text/*) vi $fx;;
|
text/*) vi $fx;;
|
||||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Following commands are provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open-file &start "" "%f%" # windows
|
cmd open &$OPENER $f
|
||||||
cmd open-file &open "$f" # mac
|
|
||||||
cmd open-file &xdg-open "$f" # others
|
|
||||||
|
|
||||||
You may also use any other existing file openers as you like. Possible options
|
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
|
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
||||||
|
|||||||
+228
-129
@@ -1,4 +1,4 @@
|
|||||||
// DO NOT EDIT! (AUTO-GENERATED)
|
// Code generated by gen/docstring.sh DO NOT EDIT.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@@ -9,104 +9,147 @@ Source code can be found in the repository at
|
|||||||
https://github.com/gokcehan/lf.
|
https://github.com/gokcehan/lf.
|
||||||
|
|
||||||
This documentation can either be read from terminal using 'lf -doc' or
|
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
|
Reference
|
||||||
|
|
||||||
The following commands are provided by lf with default keybindings:
|
The following commands are provided by lf with default keybindings:
|
||||||
|
|
||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg' and '<home>')
|
||||||
bot (default 'G')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unselect (default 'u')
|
||||||
yank (default 'y')
|
copy (default 'y')
|
||||||
delete (default 'd')
|
cut (default 'd')
|
||||||
put (default 'p')
|
paste (default 'p')
|
||||||
clear (default 'c')
|
clear (default 'c')
|
||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
shell (default '$')
|
shell (default '$')
|
||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
search (default '/')
|
find (default 'f')
|
||||||
search-back (default '?')
|
find-back (default 'F')
|
||||||
search-next (default 'n')
|
find-next (default ';')
|
||||||
search-prev (default 'N')
|
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:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
sync synchronizes yanked/deleted files with server
|
load load modified files and directories
|
||||||
|
sync synchronizes copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
select changes current file selection to its argument
|
select changes current file selection to its argument
|
||||||
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
|
|
||||||
cmd-escape (default '<esc>')
|
cmd-escape (default '<esc>')
|
||||||
cmd-comp (default '<tab>')
|
cmd-complete (default '<tab>')
|
||||||
cmd-enter (default '<c-j>' and '<enter>')
|
cmd-enter (default '<c-j>' and '<enter>')
|
||||||
cmd-hist-next (default '<c-n>')
|
cmd-history-next (default '<c-n>')
|
||||||
cmd-hist-prev (default '<c-p>')
|
cmd-history-prev (default '<c-p>')
|
||||||
cmd-delete (default '<c-d>' and '<delete>')
|
cmd-delete (default '<c-d>' and '<delete>')
|
||||||
cmd-delete-back (default '<bs>' and '<bs2>')
|
cmd-delete-back (default '<bs>' and '<bs2>')
|
||||||
cmd-left (default '<c-b>' and '<left>')
|
cmd-left (default '<c-b>' and '<left>')
|
||||||
cmd-right (default '<c-f>' and '<right>')
|
cmd-right (default '<c-f>' and '<right>')
|
||||||
cmd-beg (default '<c-a>' and '<home>')
|
cmd-home (default '<c-a>' and '<home>')
|
||||||
cmd-end (default '<c-e>' and '<end>')
|
cmd-end (default '<c-e>' and '<end>')
|
||||||
cmd-delete-beg (default '<c-u>')
|
cmd-delete-home (default '<c-u>')
|
||||||
cmd-delete-end (default '<c-k>')
|
cmd-delete-end (default '<c-k>')
|
||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-unix-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-yank (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
cmd-transpose (default '<c-t>')
|
||||||
cmd-interrupt (default '<c-c>')
|
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:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dircounts boolean (default off)
|
anchorfind boolean (default on)
|
||||||
dirfirst boolean (default on)
|
dircounts boolean (default off)
|
||||||
drawbox boolean (default off)
|
dirfirst boolean (default on)
|
||||||
globsearch boolean (default off)
|
drawbox boolean (default off)
|
||||||
hidden boolean (default off)
|
globsearch boolean (default off)
|
||||||
ignorecase boolean (default on)
|
hidden boolean (default off)
|
||||||
preview boolean (default on)
|
ignorecase boolean (default on)
|
||||||
reverse boolean (default off)
|
preview boolean (default on)
|
||||||
smartcase boolean (default on)
|
reverse boolean (default off)
|
||||||
wrapscan boolean (default on)
|
smartcase boolean (default on)
|
||||||
scrolloff integer (default 0)
|
wrapscan boolean (default on)
|
||||||
tabstop integer (default 8)
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
filesep string (default "\n")
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
ifs string (default '') (not exported if empty)
|
scrolloff integer (default 0)
|
||||||
previewer string (default '') (not filtered if empty)
|
tabstop integer (default 8)
|
||||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
filesep string (default "\n")
|
||||||
shell string (default 'sh')
|
ifs string (default '') (not exported if empty)
|
||||||
sortby string (default 'natural')
|
previewer string (default '') (not filtered if empty)
|
||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||||
ratios string (default '1:2:3')
|
shell string (default 'sh')
|
||||||
info string (default '')
|
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:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with 'filesep'
|
$fs selected file(s) separated with 'filesep'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$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:
|
The following additional keybindings are provided by default:
|
||||||
|
|
||||||
map zh set hidden!
|
map zh set hidden!
|
||||||
@@ -120,30 +163,38 @@ The following additional keybindings are provided by default:
|
|||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
map gh cd ~
|
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 e $$EDITOR $f
|
||||||
map i $$PAGER $f ('less' if empty)
|
map i $$PAGER $f
|
||||||
map w $$SHELL ('sh' if empty)
|
map w $$SHELL
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on
|
|
||||||
windows:
|
|
||||||
|
|
||||||
map e $notepad "%f%"
|
|
||||||
map i $more "%f%"
|
|
||||||
map w $cmd
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
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
|
Marks file should be located at:
|
||||||
location should be:
|
|
||||||
|
|
||||||
~/.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
|
A sample configuration file can be found at
|
||||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||||
@@ -161,10 +212,11 @@ The following command prefixes are used by lf:
|
|||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file.
|
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.
|
for read and shell commands. The difference is that prefixes are not
|
||||||
Instead different modes are provided to read corresponding commands. Note
|
necessary in the command line. Instead, different modes are provided to read
|
||||||
that by default these modes are mapped to the prefix keys above.
|
corresponding commands. These modes are mapped to the prefix keys above by
|
||||||
|
default. Searching commands are only used from the command line.
|
||||||
|
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
@@ -176,7 +228,8 @@ Characters from '#' to newline are comments and ignored:
|
|||||||
There are three special commands ('set', 'map', and 'cmd') and their
|
There are three special commands ('set', 'map', and 'cmd') and their
|
||||||
variants for configuration.
|
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 hidden # boolean on
|
||||||
set nohidden # boolean off
|
set nohidden # boolean off
|
||||||
@@ -186,16 +239,16 @@ variants for configuration.
|
|||||||
set sortby 'time' # string value with single quotes (whitespaces)
|
set sortby 'time' # string value with single quotes (whitespaces)
|
||||||
set sortby "time" # string value with double quotes (backslash escapes)
|
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,
|
Command 'map' is used to bind a key to a command which can be builtin
|
||||||
custom command, or shell command:
|
command, custom command, or shell command:
|
||||||
|
|
||||||
map gh cd ~ # builtin command
|
map gh cd ~ # builtin command
|
||||||
map D trash # custom command
|
map D trash # custom command
|
||||||
map i $less $f # shell 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
|
Command 'cmap' is used to bind a key to a command line command which can
|
||||||
of the builtin commands:
|
only be one of the builtin commands:
|
||||||
|
|
||||||
cmap <c-g> cmd-escape
|
cmap <c-g> cmd-escape
|
||||||
|
|
||||||
@@ -204,9 +257,9 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
map gh # deletes 'gh' mapping
|
map gh # deletes 'gh' mapping
|
||||||
cmap <c-g> # deletes '<c-g>' 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:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -230,6 +283,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
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
@@ -273,7 +375,7 @@ this:
|
|||||||
fi
|
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
|
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
|
'$fx' variable is provided. We can use this variable to get rid of the
|
||||||
conditional:
|
conditional:
|
||||||
@@ -391,7 +493,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
|
such needs. For example, you can configure the number of columns in the ui
|
||||||
with respect to the terminal width as follows:
|
with respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -411,15 +513,19 @@ newline character. Setting the file selection is done with 'save' command:
|
|||||||
|
|
||||||
Getting the file selection is similarly done with 'load' command:
|
Getting the file selection is similarly done with 'load' command:
|
||||||
|
|
||||||
resp=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$resp" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$resp" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
# do something with $list
|
# do something with $list
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
# do something else with $list
|
# do something else with $list
|
||||||
fi
|
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
|
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||||
should not be needed for users.
|
should not be needed for users.
|
||||||
|
|
||||||
@@ -427,19 +533,16 @@ should not be needed for users.
|
|||||||
File Operations
|
File Operations
|
||||||
|
|
||||||
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
lf uses 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
|
this purpose, when you 'copy' a file, it doesn't actually copy the file on
|
||||||
the file on the disk, but only records its name to memory. The actual file
|
the disk, but only records its name to memory. The actual file operation
|
||||||
operation takes place when you do the 'put' in which case the 'cp' command
|
takes place when you 'paste' in which case the 'cp' command is used.
|
||||||
is used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
||||||
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.
|
|
||||||
|
|
||||||
You can customize these operations by defining a 'put' command. This is a
|
You can customize these operations by defining a 'paste' command. This is a
|
||||||
special command that is called when it is defined instead of the builtin
|
special command that is called when it is defined instead of the builtin
|
||||||
implementation. The default behavior is similar to the following command:
|
implementation. The default behavior is similar to the following command:
|
||||||
|
|
||||||
cmd put ${{
|
cmd paste %{{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
@@ -448,9 +551,8 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
lf -remote 'send load'
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
lf -remote 'send clear'
|
||||||
lf -remote "send sync"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and
|
Some useful things are to use the backup option ('--backup') with 'cp' and
|
||||||
@@ -467,33 +569,30 @@ files completely are provided in the example configuration file.
|
|||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can use 'open-file' command to open a file. This is a special command
|
You can define a an 'open' command (default 'l') to configure file opening.
|
||||||
called by 'open' when the current file is not a directory. Normally a user
|
This command is only called when the current file is not a directory,
|
||||||
maps the 'open' command to a key (default 'l') and customize 'open-file'
|
otherwise the directory is entered instead. You can define it just as you
|
||||||
command as desired. You can define it just as you would define any other
|
would define any other command:
|
||||||
command:
|
|
||||||
|
|
||||||
cmd open-file $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
It is possible to use different command types:
|
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'
|
You may want to use either file extensions or mime types from 'file'
|
||||||
command:
|
command:
|
||||||
|
|
||||||
cmd open-file ${{
|
cmd open ${{
|
||||||
case $(file --mime-type $f -b) in
|
case $(file --mime-type $f -b) in
|
||||||
text/*) vi $fx;;
|
text/*) vi $fx;;
|
||||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Following commands are provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open-file &start "" "%f%" # windows
|
cmd open &$OPENER $f
|
||||||
cmd open-file &open "$f" # mac
|
|
||||||
cmd open-file &xdg-open "$f" # others
|
|
||||||
|
|
||||||
You may also use any other existing file openers as you like. Possible
|
You may also use any other existing file openers as you like. Possible
|
||||||
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
||||||
|
|||||||
+34
-16
@@ -1,6 +1,15 @@
|
|||||||
# interpreter for shell commands (needs to be POSIX compatible)
|
# interpreter for shell commands (needs to be POSIX compatible)
|
||||||
set shell sh
|
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
|
# set internal field separator (IFS) to "\n" for shell commands
|
||||||
# This is useful to automatically split file names in $fs and $fx properly
|
# 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)
|
# 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 $f
|
||||||
map O $mimeopen --ask $f
|
map O $mimeopen --ask $f
|
||||||
|
|
||||||
# show documentation (overrides 'search-back' command)
|
# define a custom 'open' command
|
||||||
map ? $lf -doc | less
|
# 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
|
||||||
# define a custom 'open-file' command
|
# text files and a file opener for the rest.
|
||||||
# 'open-file' is called by 'open' when current file is not a directory. You may
|
cmd open ${{
|
||||||
# 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 ${{
|
|
||||||
case $(file --mime-type $f -b) in
|
case $(file --mime-type $f -b) in
|
||||||
text/*) vi $fx;;
|
text/*) $EDITOR $fx;;
|
||||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -45,19 +51,21 @@ map r push :rename<space>
|
|||||||
|
|
||||||
# move current file or selected files to trash folder
|
# move current file or selected files to trash folder
|
||||||
# (also see 'man mv' for backup/overwrite options)
|
# (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)
|
# delete current file or selected files (prompting)
|
||||||
cmd remove ${{
|
cmd delete ${{
|
||||||
|
set -f
|
||||||
printf "$fx\n"
|
printf "$fx\n"
|
||||||
printf "remove?[y/n]"
|
printf "delete?[y/n]"
|
||||||
read ans
|
read ans
|
||||||
[ $ans = "y" ] && rm -rf $fx
|
[ $ans = "y" ] && rm -rf $fx
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# extract the current file with the right command
|
# extract the current file with the right command
|
||||||
# (xkcd link: https://xkcd.com/1168/)
|
# (xkcd link: https://xkcd.com/1168/)
|
||||||
cmd extract %{{
|
cmd extract ${{
|
||||||
|
set -f
|
||||||
case $f in
|
case $f in
|
||||||
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
||||||
*.tar.gz|*.tgz) tar xzvf $f;;
|
*.tar.gz|*.tgz) tar xzvf $f;;
|
||||||
@@ -69,9 +77,19 @@ cmd extract %{{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
# compress current file or selected files with tar and gunzip
|
# compress current file or selected files with tar and gunzip
|
||||||
cmd compress %{{
|
cmd tar ${{
|
||||||
|
set -f
|
||||||
mkdir $1
|
mkdir $1
|
||||||
cp -r $fx $1
|
cp -r $fx $1
|
||||||
tar czf $1.tar.gz $1
|
tar czf $1.tar.gz $1
|
||||||
rm -rf $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
|
||||||
|
}}
|
||||||
@@ -4,13 +4,22 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (e *setExpr) eval(app *app, args []string) {
|
func (e *setExpr) eval(app *app, args []string) {
|
||||||
switch e.opt {
|
switch e.opt {
|
||||||
|
case "anchorfind":
|
||||||
|
gOpts.anchorfind = true
|
||||||
|
case "noanchorfind":
|
||||||
|
gOpts.anchorfind = false
|
||||||
|
case "anchorfind!":
|
||||||
|
gOpts.anchorfind = !gOpts.anchorfind
|
||||||
case "dircounts":
|
case "dircounts":
|
||||||
gOpts.dircounts = true
|
gOpts.dircounts = true
|
||||||
case "nodircounts":
|
case "nodircounts":
|
||||||
@@ -50,15 +59,21 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "hidden":
|
case "hidden":
|
||||||
gOpts.sortType.option |= hiddenSort
|
gOpts.sortType.option |= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "nohidden":
|
case "nohidden":
|
||||||
gOpts.sortType.option &= ^hiddenSort
|
gOpts.sortType.option &= ^hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "hidden!":
|
case "hidden!":
|
||||||
gOpts.sortType.option ^= hiddenSort
|
gOpts.sortType.option ^= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -95,6 +110,34 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.wrapscan
|
gOpts.wrapscan = !gOpts.wrapscan
|
||||||
|
case "findlen":
|
||||||
|
n, err := strconv.Atoi(e.val)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.printf("findlen: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n < 0 {
|
||||||
|
app.ui.print("findlen: value should be a non-negative number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gOpts.findlen = n
|
||||||
|
case "period":
|
||||||
|
n, err := strconv.Atoi(e.val)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.printf("period: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n < 0 {
|
||||||
|
app.ui.print("period: value should be a non-negative number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gOpts.period = n
|
||||||
|
if n == 0 {
|
||||||
|
app.ticker.Stop()
|
||||||
|
} else {
|
||||||
|
app.ticker.Stop()
|
||||||
|
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
|
||||||
|
}
|
||||||
case "scrolloff":
|
case "scrolloff":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -177,6 +220,8 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gOpts.info = toks
|
gOpts.info = toks
|
||||||
|
case "shellopts":
|
||||||
|
gOpts.shellopts = strings.Split(e.val, ":")
|
||||||
default:
|
default:
|
||||||
app.ui.printf("unknown option: %s", e.opt)
|
app.ui.printf("unknown option: %s", e.opt)
|
||||||
}
|
}
|
||||||
@@ -208,14 +253,14 @@ func (e *cmdExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
func splitKeys(s string) (keys []string) {
|
func splitKeys(s string) (keys []string) {
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
c, w := utf8.DecodeRuneInString(s[i:])
|
r, w := utf8.DecodeRuneInString(s[i:])
|
||||||
if c != '<' {
|
if r != '<' {
|
||||||
keys = append(keys, s[i:i+w])
|
keys = append(keys, s[i:i+w])
|
||||||
i += w
|
i += w
|
||||||
} else {
|
} else {
|
||||||
j := i + w
|
j := i + w
|
||||||
for c != '>' && j < len(s) {
|
for r != '>' && j < len(s) {
|
||||||
c, w = utf8.DecodeRuneInString(s[j:])
|
r, w = utf8.DecodeRuneInString(s[j:])
|
||||||
j += w
|
j += w
|
||||||
}
|
}
|
||||||
keys = append(keys, s[i:j])
|
keys = append(keys, s[i:j])
|
||||||
@@ -225,6 +270,115 @@ func splitKeys(s string) (keys []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func insert(app *app, arg string) {
|
||||||
|
switch app.ui.cmdPrefix {
|
||||||
|
case "find: ":
|
||||||
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
if gOpts.findlen == 0 {
|
||||||
|
switch app.nav.findSingle() {
|
||||||
|
case 0:
|
||||||
|
app.ui.printf("find: pattern not found: %s", app.nav.find)
|
||||||
|
case 1:
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(app.nav.find) < gOpts.findlen {
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.nav.findNext() {
|
||||||
|
app.ui.printf("find: pattern not found: %s", app.nav.find)
|
||||||
|
} else {
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
case "find-back: ":
|
||||||
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
if gOpts.findlen == 0 {
|
||||||
|
switch app.nav.findSingle() {
|
||||||
|
case 0:
|
||||||
|
app.ui.printf("find-back: pattern not found: %s", app.nav.find)
|
||||||
|
case 1:
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if len(app.nav.find) < gOpts.findlen {
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !app.nav.findPrev() {
|
||||||
|
app.ui.printf("find-back: pattern not found: %s", app.nav.find)
|
||||||
|
} else {
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
case "mark-save: ":
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.nav.marks[arg] = wd
|
||||||
|
case "mark-load: ":
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
path, ok := app.nav.marks[arg]
|
||||||
|
if !ok {
|
||||||
|
app.ui.print("mark-load: no such mark")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.cd(path); err != nil {
|
||||||
|
app.ui.printf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
|
if wd != path {
|
||||||
|
app.nav.marks["'"] = wd
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (e *callExpr) eval(app *app, args []string) {
|
func (e *callExpr) eval(app *app, args []string) {
|
||||||
switch e.name {
|
switch e.name {
|
||||||
case "up":
|
case "up":
|
||||||
@@ -287,9 +441,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
if len(app.nav.marks) != 0 {
|
if len(app.nav.selections) != 0 {
|
||||||
marks := app.nav.currMarks()
|
selections := app.nav.currSelections()
|
||||||
path = strings.Join(marks, "\n")
|
path = strings.Join(selections, "\n")
|
||||||
} else if curr, err := app.nav.currFile(); err == nil {
|
} else if curr, err := app.nav.currFile(); err == nil {
|
||||||
path = curr.path
|
path = curr.path
|
||||||
} else {
|
} else {
|
||||||
@@ -306,7 +460,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd, ok := gOpts.cmds["open-file"]; ok {
|
if cmd, ok := gOpts.cmds["open"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
}
|
}
|
||||||
case "quit":
|
case "quit":
|
||||||
@@ -315,8 +469,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.top()
|
app.nav.top()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "bot":
|
case "bottom":
|
||||||
app.nav.bot()
|
app.nav.bottom()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "toggle":
|
case "toggle":
|
||||||
@@ -327,36 +481,38 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "invert":
|
case "invert":
|
||||||
app.nav.invert()
|
app.nav.invert()
|
||||||
case "unmark":
|
case "unselect":
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
case "yank":
|
case "copy":
|
||||||
if err := app.nav.save(true); err != nil {
|
if err := app.nav.save(true); err != nil {
|
||||||
app.ui.printf("yank: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("yank: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
}
|
}
|
||||||
case "delete":
|
case "cut":
|
||||||
if err := app.nav.save(false); err != nil {
|
if err := app.nav.save(false); err != nil {
|
||||||
app.ui.printf("delete: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("delete: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
}
|
}
|
||||||
case "put":
|
case "paste":
|
||||||
if cmd, ok := gOpts.cmds["put"]; ok {
|
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
} else if err := app.nav.put(); err != nil {
|
} else if err := app.nav.paste(); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("paste: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.renew()
|
if err := sendRemote("send load"); err != nil {
|
||||||
|
app.ui.printf("paste: %s", err)
|
||||||
|
}
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("paste: %s", err)
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
@@ -371,10 +527,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.nav.height = app.ui.wins[0].h
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
case "load":
|
||||||
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
app.ui.sync()
|
if err := app.nav.reload(); err != nil {
|
||||||
app.ui.renew()
|
app.ui.printf("reload: %s", err)
|
||||||
app.nav.reload()
|
}
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
case "shell":
|
case "shell":
|
||||||
@@ -385,28 +543,75 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdPrefix = "!"
|
app.ui.cmdPrefix = "!"
|
||||||
case "shell-async":
|
case "shell-async":
|
||||||
app.ui.cmdPrefix = "&"
|
app.ui.cmdPrefix = "&"
|
||||||
|
case "find":
|
||||||
|
app.ui.cmdPrefix = "find: "
|
||||||
|
app.nav.findBack = false
|
||||||
|
case "find-back":
|
||||||
|
app.ui.cmdPrefix = "find-back: "
|
||||||
|
app.nav.findBack = true
|
||||||
|
case "find-next":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
|
if app.nav.findBack {
|
||||||
|
app.nav.findPrev()
|
||||||
|
} else {
|
||||||
|
app.nav.findNext()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case "find-prev":
|
||||||
|
for i := 0; i < e.count; i++ {
|
||||||
|
if app.nav.findBack {
|
||||||
|
app.nav.findNext()
|
||||||
|
} else {
|
||||||
|
app.nav.findPrev()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search":
|
case "search":
|
||||||
app.ui.cmdPrefix = "/"
|
app.ui.cmdPrefix = "/"
|
||||||
|
app.nav.searchBack = false
|
||||||
case "search-back":
|
case "search-back":
|
||||||
app.ui.cmdPrefix = "?"
|
app.ui.cmdPrefix = "?"
|
||||||
|
app.nav.searchBack = true
|
||||||
case "search-next":
|
case "search-next":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.searchNext(); err != nil {
|
if app.nav.searchBack {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
return
|
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchNext(); err != nil {
|
||||||
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search-prev":
|
case "search-prev":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
if app.nav.searchBack {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
if err := app.nav.searchNext(); err != nil {
|
||||||
return
|
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case "mark-save":
|
||||||
|
app.ui.cmdPrefix = "mark-save: "
|
||||||
|
case "mark-load":
|
||||||
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||||
|
app.ui.cmdPrefix = "mark-load: "
|
||||||
case "sync":
|
case "sync":
|
||||||
if err := app.nav.sync(); err != nil {
|
if err := app.nav.sync(); err != nil {
|
||||||
app.ui.printf("sync: %s", err)
|
app.ui.printf("sync: %s", err)
|
||||||
@@ -418,34 +623,78 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if len(e.args) > 0 {
|
if len(e.args) > 0 {
|
||||||
path = e.args[0]
|
path = e.args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := app.nav.cd(path); err != nil {
|
if err := app.nav.cd(path); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.printf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(wd, path)
|
||||||
|
} else {
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if wd != path {
|
||||||
|
app.nav.marks["'"] = wd
|
||||||
|
}
|
||||||
case "select":
|
case "select":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.print("select: requires an argument")
|
app.ui.print("select: requires an argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := app.nav.find(e.args[0]); err != nil {
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.nav.sel(e.args[0]); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.printf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
|
path := filepath.Dir(e.args[0])
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(wd, path)
|
||||||
|
} else {
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
if wd != path {
|
||||||
|
app.nav.marks["'"] = wd
|
||||||
|
}
|
||||||
|
case "source":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("source: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) != 1 {
|
||||||
log.Println("pushing keys", e.args[0])
|
app.ui.print("push: requires an argument")
|
||||||
for _, key := range splitKeys(e.args[0]) {
|
return
|
||||||
app.ui.keyChan <- key
|
}
|
||||||
}
|
log.Println("pushing keys", e.args[0])
|
||||||
|
for _, key := range splitKeys(e.args[0]) {
|
||||||
|
app.ui.keyChan <- key
|
||||||
}
|
}
|
||||||
case "cmd-insert":
|
case "cmd-insert":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) == 0 {
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
return
|
||||||
}
|
}
|
||||||
|
insert(app, e.args[0])
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
if app.ui.cmdPrefix == ">" {
|
if app.ui.cmdPrefix == ">" {
|
||||||
return
|
return
|
||||||
@@ -454,12 +703,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "cmd-comp":
|
case "cmd-complete":
|
||||||
var matches []string
|
var matches []string
|
||||||
if app.ui.cmdPrefix == ":" {
|
if app.ui.cmdPrefix == ":" {
|
||||||
matches, app.ui.cmdAccLeft = compCmd(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||||
} else {
|
} else {
|
||||||
matches, app.ui.cmdAccLeft = compShell(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
@@ -485,24 +734,30 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
app.ui.printf("%s", p.err)
|
app.ui.printf("%s", p.err)
|
||||||
}
|
}
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s", s)
|
log.Printf("shell: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "%":
|
case "%":
|
||||||
log.Printf("shell-pipe: %s", s)
|
log.Printf("shell-pipe: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
app.cmdHist = append(app.cmdHist, cmdItem{"%", s})
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
return
|
|
||||||
case ">":
|
case ">":
|
||||||
io.WriteString(app.cmdIn, s+"\n")
|
io.WriteString(app.cmdIn, s+"\n")
|
||||||
app.cmdOutBuf = nil
|
app.cmdOutBuf = nil
|
||||||
return
|
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s", s)
|
log.Printf("shell-wait: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s", s)
|
log.Printf("shell-async: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "/":
|
case "/":
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
@@ -512,96 +767,106 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
case "?":
|
case "?":
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||||
} else {
|
} else {
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
default:
|
default:
|
||||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||||
}
|
}
|
||||||
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdPrefix, s})
|
case "cmd-history-next":
|
||||||
app.ui.cmdPrefix = ""
|
if app.ui.cmdPrefix == "" || app.ui.cmdPrefix == ">" {
|
||||||
case "cmd-hist-next":
|
|
||||||
if app.ui.cmdPrefix == "" {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if app.cmdHistInd > 0 {
|
if app.cmdHistoryInd > 0 {
|
||||||
app.cmdHistInd--
|
app.cmdHistoryInd--
|
||||||
}
|
}
|
||||||
if app.cmdHistInd == 0 {
|
if app.cmdHistoryInd == 0 {
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||||
app.ui.cmdPrefix = cmd.prefix
|
app.ui.cmdPrefix = cmd.prefix
|
||||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
case "cmd-hist-prev":
|
case "cmd-history-prev":
|
||||||
if app.ui.cmdPrefix == "" {
|
if app.ui.cmdPrefix == ">" {
|
||||||
app.cmdHistInd = 0
|
|
||||||
}
|
|
||||||
if app.cmdHistInd == len(app.cmdHist) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.cmdHistInd++
|
if app.ui.cmdPrefix == "" {
|
||||||
cmd := app.cmdHist[len(app.cmdHist)-app.cmdHistInd]
|
app.cmdHistoryInd = 0
|
||||||
|
}
|
||||||
|
if app.cmdHistoryInd == len(app.cmdHistory) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.cmdHistoryInd++
|
||||||
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||||
app.ui.cmdPrefix = cmd.prefix
|
app.ui.cmdPrefix = cmd.prefix
|
||||||
app.ui.cmdAccLeft = []rune(cmd.value)
|
app.ui.cmdAccLeft = []rune(cmd.value)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
case "cmd-delete":
|
case "cmd-delete":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
case "cmd-delete-back":
|
case "cmd-delete-back":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
case "cmd-left":
|
case "cmd-left":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
app.ui.cmdAccRight = append([]rune{app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]}, app.ui.cmdAccRight...)
|
return
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccRight = append([]rune{app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]}, app.ui.cmdAccRight...)
|
||||||
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
case "cmd-right":
|
case "cmd-right":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
return
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
|
||||||
}
|
}
|
||||||
case "cmd-beg":
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[0])
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
|
case "cmd-home":
|
||||||
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
app.ui.cmdAccRight = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
case "cmd-end":
|
case "cmd-end":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight...)
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
case "cmd-delete-beg":
|
case "cmd-delete-home":
|
||||||
if len(app.ui.cmdAccLeft) > 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
app.ui.cmdBuf = app.ui.cmdAccLeft
|
return
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
}
|
}
|
||||||
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
case "cmd-delete-end":
|
case "cmd-delete-end":
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
app.ui.cmdBuf = app.ui.cmdAccRight
|
return
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
}
|
}
|
||||||
case "cmd-delete-word":
|
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
case "cmd-delete-unix-word":
|
||||||
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
||||||
app.ui.cmdBuf = app.ui.cmdAccLeft[ind:]
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
case "cmd-put":
|
case "cmd-yank":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdBuf...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
||||||
case "cmd-transpose":
|
case "cmd-transpose":
|
||||||
if len(app.ui.cmdAccLeft) > 1 {
|
if len(app.ui.cmdAccLeft) < 2 {
|
||||||
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
||||||
case "cmd-interrupt":
|
case "cmd-interrupt":
|
||||||
if app.cmd != nil {
|
if app.cmd != nil {
|
||||||
app.cmd.Process.Kill()
|
app.cmd.Process.Kill()
|
||||||
@@ -610,6 +875,113 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
case "cmd-word":
|
||||||
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := loc[0] + 1
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
case "cmd-word-back":
|
||||||
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||||
|
if locs == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := locs[len(locs)-1][1] - 1
|
||||||
|
old := app.ui.cmdAccRight
|
||||||
|
app.ui.cmdAccRight = append([]rune{}, app.ui.cmdAccLeft[ind:]...)
|
||||||
|
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
||||||
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
|
case "cmd-capitalize-word":
|
||||||
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := 0
|
||||||
|
for ; ind < len(app.ui.cmdAccRight) && unicode.IsSpace(app.ui.cmdAccRight[ind]); ind++ {
|
||||||
|
}
|
||||||
|
if ind >= len(app.ui.cmdAccRight) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind = loc[0] + 1
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
case "cmd-delete-word":
|
||||||
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := loc[0] + 1
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
case "cmd-uppercase-word":
|
||||||
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := loc[0] + 1
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
case "cmd-lowercase-word":
|
||||||
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ind := loc[0] + 1
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
case "cmd-transpose-word":
|
||||||
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
locs := reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||||
|
if len(locs) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(app.ui.cmdAccRight) > 0 {
|
||||||
|
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
||||||
|
if loc != nil {
|
||||||
|
ind := loc[0] + 1
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||||
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
locs = reWord.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
||||||
|
|
||||||
|
beg1, end1 := locs[len(locs)-2][0], locs[len(locs)-2][1]
|
||||||
|
beg2, end2 := locs[len(locs)-1][0], locs[len(locs)-1][1]
|
||||||
|
|
||||||
|
var acc []rune
|
||||||
|
|
||||||
|
acc = append(acc, app.ui.cmdAccLeft[:beg1]...)
|
||||||
|
acc = append(acc, app.ui.cmdAccLeft[beg2:end2]...)
|
||||||
|
acc = append(acc, app.ui.cmdAccLeft[end1:beg2]...)
|
||||||
|
acc = append(acc, app.ui.cmdAccLeft[beg1:end1]...)
|
||||||
|
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
||||||
|
|
||||||
|
app.ui.cmdAccLeft = acc
|
||||||
default:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
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
|
tmp=gen/docstring.go
|
||||||
|
|
||||||
echo "// DO NOT EDIT! (AUTO-GENERATED)" >> $tmp
|
echo "// Code generated by gen/docstring.sh DO NOT EDIT." >> $tmp
|
||||||
echo >> $tmp
|
echo >> $tmp
|
||||||
echo "package main" >> $tmp
|
echo "package main" >> $tmp
|
||||||
echo >> $tmp
|
echo >> $tmp
|
||||||
echo "var genDocString = \`" >> $tmp
|
echo "var genDocString = \`" >> $tmp
|
||||||
go doc | tr "\`" "'" >> $tmp
|
go doc | tr "\`" "'" >> $tmp
|
||||||
echo "\`" >> $tmp
|
echo "\`" >> $tmp
|
||||||
|
|
||||||
mv $tmp docstring.go
|
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
|
# This script is used to build binaries for all supported platforms. Cgo is
|
||||||
# disabled to make sure binaries are statically linked. Appropriate flags are
|
# 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
|
# given to the go compiler to strip binaries. Current git tag is passed to the
|
||||||
# archive form (`.zip` for windows and `.tar.gz` for the rest) within a folder
|
# compiler by default to be used as the version in binaries. These are then
|
||||||
# named `dist`.
|
# compressed in an archive form (`.zip` for windows and `.tar.gz` for the rest)
|
||||||
|
# within a folder named `dist`.
|
||||||
|
|
||||||
set -o verbose
|
set -o verbose
|
||||||
|
|
||||||
version=$(git describe --tags)
|
[ -z $version ] && version=$(git describe --tags)
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,614 @@
|
|||||||
|
.\" 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 synchronizes copied/cut files with server
|
||||||
|
echo prints its arguments to the message line
|
||||||
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
|
source reads the configuration file in its argument
|
||||||
|
push simulate key pushes given in its argument
|
||||||
|
.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)
|
||||||
|
dircounts boolean (default off)
|
||||||
|
dirfirst boolean (default on)
|
||||||
|
drawbox boolean (default off)
|
||||||
|
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)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
|
scrolloff integer (default 0)
|
||||||
|
tabstop integer (default 8)
|
||||||
|
filesep string (default "\en")
|
||||||
|
ifs string (default '') (not exported if empty)
|
||||||
|
previewer string (default '') (not filtered if empty)
|
||||||
|
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
|
||||||
|
shell string (default 'sh')
|
||||||
|
sortby string (default 'natural')
|
||||||
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||||
|
ratios string (default '1:2:3')
|
||||||
|
info string (default '')
|
||||||
|
shellopts string (default '')
|
||||||
|
.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 the underlying 'cp' and 'mv' shell commands for file operations. For this purpose, when you 'copy' a file, it doesn't actually copy the file on the disk, but only records its name to memory. The actual file operation takes place when you 'paste' in which case the 'cp' command is used. Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
||||||
|
.PP
|
||||||
|
You can customize these operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. The default behavior is similar to the following command:
|
||||||
|
.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 -n $list .
|
||||||
|
elif [ $mode = 'move' ]; then
|
||||||
|
mv -n $list .
|
||||||
|
fi
|
||||||
|
lf -remote 'send load'
|
||||||
|
lf -remote 'send clear'
|
||||||
|
}}
|
||||||
|
.EE
|
||||||
|
.PP
|
||||||
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
||||||
|
.PP
|
||||||
|
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.
|
||||||
|
.SH OPENING FILES
|
||||||
|
You can define a an 'open' command (default 'l') 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
|
||||||
|
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.
|
||||||
@@ -4,15 +4,16 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envPath = os.Getenv("PATH")
|
envPath = os.Getenv("PATH")
|
||||||
|
envLevel = os.Getenv("LF_LEVEL")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -33,15 +34,34 @@ func init() {
|
|||||||
log.Printf("hostname: %s", err)
|
log.Printf("hostname: %s", err)
|
||||||
}
|
}
|
||||||
gHostname = h
|
gHostname = h
|
||||||
|
|
||||||
|
if envLevel == "" {
|
||||||
|
envLevel = "0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
cmd := exec.Command(os.Args[0], "-server")
|
cmd := detachedCommand(os.Args[0], "-server")
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
log.Printf("starting server: %s", err)
|
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() {
|
func main() {
|
||||||
showDoc := flag.Bool(
|
showDoc := flag.Bool(
|
||||||
"doc",
|
"doc",
|
||||||
@@ -99,19 +119,6 @@ func main() {
|
|||||||
defer pprof.StopCPUProfile()
|
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 {
|
switch {
|
||||||
case *showDoc:
|
case *showDoc:
|
||||||
fmt.Print(genDocString)
|
fmt.Print(genDocString)
|
||||||
@@ -125,10 +132,7 @@ func main() {
|
|||||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||||
serve()
|
serve()
|
||||||
default:
|
default:
|
||||||
// TODO: check if the socket is working
|
checkServer()
|
||||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
|
||||||
startServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
gClientID = 1000
|
gClientID = 1000
|
||||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||||
@@ -137,6 +141,24 @@ func main() {
|
|||||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
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:
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,12 @@ func naturalLess(s1, s2 string) bool {
|
|||||||
return len(parts1) < len(parts2)
|
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 {
|
func min(a, b int) int {
|
||||||
if a < b {
|
if a < b {
|
||||||
return a
|
return a
|
||||||
@@ -210,7 +216,7 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We don't need no generic code
|
// 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
|
// No dark templates in compiler
|
||||||
// Haskell leave them kids alone
|
// Haskell leave them kids alone
|
||||||
// Hey Bjarne leave them kids alone
|
// Hey Bjarne leave them kids alone
|
||||||
|
|||||||
@@ -27,21 +27,7 @@ type file struct {
|
|||||||
os.FileInfo
|
os.FileInfo
|
||||||
linkState linkState
|
linkState linkState
|
||||||
path string
|
path string
|
||||||
count int
|
dirCount int
|
||||||
}
|
|
||||||
|
|
||||||
type filesSortable struct {
|
|
||||||
files []*file
|
|
||||||
less func(i, j int) bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f filesSortable) Len() int { return len(f.files) }
|
|
||||||
func (f filesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] }
|
|
||||||
func (f filesSortable) Less(i, j int) bool { return f.less(i, j) }
|
|
||||||
|
|
||||||
// TODO: Replace with `sort.SliceStable` once available
|
|
||||||
func sortFilesStable(files []*file, less func(i, j int) bool) {
|
|
||||||
sort.Stable(filesSortable{files: files, less: less})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func readdir(path string) ([]*file, error) {
|
func readdir(path string) ([]*file, error) {
|
||||||
@@ -49,61 +35,59 @@ func readdir(path string) ([]*file, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
names, err := f.Readdirnames(-1)
|
names, err := f.Readdirnames(-1)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
fi := make([]*file, 0, len(names))
|
files := make([]*file, 0, len(names))
|
||||||
for _, filename := range names {
|
for _, fname := range names {
|
||||||
fpath := filepath.Join(path, filename)
|
fpath := filepath.Join(path, fname)
|
||||||
|
|
||||||
lstat, lerr := os.Lstat(fpath)
|
lstat, err := os.Lstat(fpath)
|
||||||
if os.IsNotExist(lerr) {
|
if os.IsNotExist(err) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if lerr != nil {
|
if err != nil {
|
||||||
return fi, lerr
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkState linkState
|
var linkState linkState
|
||||||
|
|
||||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||||
stat, serr := os.Stat(fpath)
|
stat, err := os.Stat(fpath)
|
||||||
if serr == nil {
|
if err == nil {
|
||||||
linkState = working
|
linkState = working
|
||||||
lstat = stat
|
lstat = stat
|
||||||
} else {
|
} else {
|
||||||
linkState = broken
|
linkState = broken
|
||||||
log.Printf("getting link destination info: %s", serr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fi = append(fi, &file{
|
files = append(files, &file{
|
||||||
FileInfo: lstat,
|
FileInfo: lstat,
|
||||||
linkState: linkState,
|
linkState: linkState,
|
||||||
path: fpath,
|
path: fpath,
|
||||||
count: -1,
|
dirCount: -1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return fi, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type dir struct {
|
type dir struct {
|
||||||
loading bool // directory is loading from disk
|
loading bool // directory is loading from disk
|
||||||
loadTime time.Time // current loading or last load time
|
loadTime time.Time // current loading or last load time
|
||||||
ind int // index of current entry in fi
|
ind int // index of current entry in files
|
||||||
pos int // position of current entry in ui
|
pos int // position of current entry in ui
|
||||||
path string // full path of directory
|
path string // full path of directory
|
||||||
fi []*file // displayed files in directory including or excluding hidden ones
|
files []*file // displayed files in directory including or excluding hidden ones
|
||||||
all []*file // all files in directory including hidden ones (same array as fi)
|
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||||
sortType sortType // sort method and options from last sort
|
sortType sortType // sort method and options from last sort
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(path string) *dir {
|
func newDir(path string) *dir {
|
||||||
time := time.Now()
|
time := time.Now()
|
||||||
|
|
||||||
fi, err := readdir(path)
|
files, err := readdir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("reading directory: %s", err)
|
log.Printf("reading directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -111,57 +95,47 @@ func newDir(path string) *dir {
|
|||||||
return &dir{
|
return &dir{
|
||||||
loadTime: time,
|
loadTime: time,
|
||||||
path: path,
|
path: path,
|
||||||
fi: fi,
|
files: files,
|
||||||
all: fi,
|
allFiles: files,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) renew() {
|
|
||||||
fi, err := readdir(dir.path)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("reading directory: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
dir.fi = fi
|
|
||||||
dir.all = fi
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dir *dir) sort() {
|
func (dir *dir) sort() {
|
||||||
dir.sortType = gOpts.sortType
|
dir.sortType = gOpts.sortType
|
||||||
|
|
||||||
dir.fi = dir.all
|
dir.files = dir.allFiles
|
||||||
|
|
||||||
switch gOpts.sortType.method {
|
switch gOpts.sortType.method {
|
||||||
case naturalSort:
|
case naturalSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return naturalLess(strings.ToLower(dir.fi[i].Name()), strings.ToLower(dir.fi[j].Name()))
|
return naturalLess(strings.ToLower(dir.files[i].Name()), strings.ToLower(dir.files[j].Name()))
|
||||||
})
|
})
|
||||||
case nameSort:
|
case nameSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return strings.ToLower(dir.fi[i].Name()) < strings.ToLower(dir.fi[j].Name())
|
return strings.ToLower(dir.files[i].Name()) < strings.ToLower(dir.files[j].Name())
|
||||||
})
|
})
|
||||||
case sizeSort:
|
case sizeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return dir.fi[i].Size() < dir.fi[j].Size()
|
return dir.files[i].Size() < dir.files[j].Size()
|
||||||
})
|
})
|
||||||
case timeSort:
|
case timeSort:
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return dir.fi[i].ModTime().Before(dir.fi[j].ModTime())
|
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.sortType.option&reverseSort != 0 {
|
if gOpts.sortType.option&reverseSort != 0 {
|
||||||
for i, j := 0, len(dir.fi)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(dir.files)-1; i < j; i, j = i+1, j-1 {
|
||||||
dir.fi[i], dir.fi[j] = dir.fi[j], dir.fi[i]
|
dir.files[i], dir.files[j] = dir.files[j], dir.files[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.sortType.option&dirfirstSort != 0 {
|
if gOpts.sortType.option&dirfirstSort != 0 {
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.fi[i].IsDir() == dir.fi[j].IsDir() {
|
if dir.files[i].IsDir() == dir.files[j].IsDir() {
|
||||||
return i < j
|
return i < j
|
||||||
}
|
}
|
||||||
return dir.fi[i].IsDir()
|
return dir.files[i].IsDir()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,39 +143,39 @@ func (dir *dir) sort() {
|
|||||||
// beginning of our file list and then set the beginning of displayed
|
// beginning of our file list and then set the beginning of displayed
|
||||||
// files to the first non-hidden file in the list
|
// files to the first non-hidden file in the list
|
||||||
if gOpts.sortType.option&hiddenSort == 0 {
|
if gOpts.sortType.option&hiddenSort == 0 {
|
||||||
sortFilesStable(dir.fi, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.fi[i].Name()[0] == '.' && dir.fi[j].Name()[0] == '.' {
|
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
||||||
return i < j
|
return i < j
|
||||||
}
|
}
|
||||||
return dir.fi[i].Name()[0] == '.'
|
return dir.files[i].Name()[0] == '.'
|
||||||
})
|
})
|
||||||
for i, f := range dir.fi {
|
for i, f := range dir.files {
|
||||||
if f.Name()[0] != '.' {
|
if f.Name()[0] != '.' {
|
||||||
dir.fi = dir.fi[i:]
|
dir.files = dir.files[i:]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dir.fi = dir.fi[len(dir.fi):]
|
dir.files = dir.files[len(dir.files):]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) name() string {
|
func (dir *dir) name() string {
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return dir.fi[dir.ind].Name()
|
return dir.files[dir.ind].Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dir *dir) find(name string, height int) {
|
func (dir *dir) sel(name string, height int) {
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
dir.ind, dir.pos = 0, 0
|
dir.ind, dir.pos = 0, 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.ind = min(dir.ind, len(dir.fi)-1)
|
dir.ind = min(dir.ind, len(dir.files)-1)
|
||||||
|
|
||||||
if dir.fi[dir.ind].Name() != name {
|
if dir.files[dir.ind].Name() != name {
|
||||||
for i, f := range dir.fi {
|
for i, f := range dir.files {
|
||||||
if f.Name() == name {
|
if f.Name() == name {
|
||||||
dir.ind = i
|
dir.ind = i
|
||||||
break
|
break
|
||||||
@@ -209,116 +183,25 @@ func (dir *dir) find(name string, height int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := min(min(height/2, gOpts.scrolloff), len(dir.fi)-dir.ind-1)
|
edge := min(min(height/2, gOpts.scrolloff), len(dir.files)-dir.ind-1)
|
||||||
dir.pos = min(dir.ind, height-edge-1)
|
dir.pos = min(dir.ind, height-edge-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
type nav struct {
|
type nav struct {
|
||||||
dirs []*dir
|
dirs []*dir
|
||||||
dirChan chan *dir
|
dirChan chan *dir
|
||||||
regChan chan *reg
|
regChan chan *reg
|
||||||
dirCache map[string]*dir
|
dirCache map[string]*dir
|
||||||
regCache map[string]*reg
|
regCache map[string]*reg
|
||||||
saves map[string]bool
|
saves map[string]bool
|
||||||
marks map[string]int
|
marks map[string]string
|
||||||
markInd int
|
selections map[string]int
|
||||||
height int
|
selectionInd int
|
||||||
search string
|
height int
|
||||||
}
|
find string
|
||||||
|
findBack bool
|
||||||
func newNav(height int) *nav {
|
search string
|
||||||
wd, err := os.Getwd()
|
searchBack bool
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting current directory: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
nav := &nav{
|
|
||||||
dirChan: make(chan *dir),
|
|
||||||
regChan: make(chan *reg),
|
|
||||||
dirCache: make(map[string]*dir),
|
|
||||||
regCache: make(map[string]*reg),
|
|
||||||
marks: make(map[string]int),
|
|
||||||
saves: make(map[string]bool),
|
|
||||||
markInd: 0,
|
|
||||||
height: height,
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.getDirs(wd)
|
|
||||||
|
|
||||||
return nav
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) position() {
|
|
||||||
path := nav.currDir().path
|
|
||||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
|
||||||
nav.dirs[i].find(filepath.Base(path), nav.height)
|
|
||||||
path = filepath.Dir(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) getDirs(wd string) {
|
|
||||||
var dirs []*dir
|
|
||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
|
||||||
dir := nav.loadDir(curr)
|
|
||||||
dir.find(base, nav.height)
|
|
||||||
dirs = append(dirs, dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, j := 0, len(dirs)-1; i < j; i, j = i+1, j-1 {
|
|
||||||
dirs[i], dirs[j] = dirs[j], dirs[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.dirs = dirs
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) renew() {
|
|
||||||
nav.dirCache = make(map[string]*dir)
|
|
||||||
for _, d := range nav.dirs {
|
|
||||||
nav.dirCache[d.path] = d
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, d := range nav.dirs {
|
|
||||||
go func(d *dir) {
|
|
||||||
s, err := os.Stat(d.path)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting directory info: %s", err)
|
|
||||||
}
|
|
||||||
if d.loadTime.After(s.ModTime()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.loadTime = time.Now()
|
|
||||||
nd := newDir(d.path)
|
|
||||||
nd.sort()
|
|
||||||
nav.dirChan <- nd
|
|
||||||
}(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
for m := range nav.marks {
|
|
||||||
if _, err := os.Stat(m); os.IsNotExist(err) {
|
|
||||||
delete(nav.marks, m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(nav.marks) == 0 {
|
|
||||||
nav.markInd = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) reload() {
|
|
||||||
nav.dirCache = make(map[string]*dir)
|
|
||||||
nav.regCache = make(map[string]*reg)
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting current directory: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
curr, err := nav.currFile()
|
|
||||||
nav.getDirs(wd)
|
|
||||||
if err == nil {
|
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
|
||||||
last.fi = append(last.fi, curr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDir(path string) *dir {
|
func (nav *nav) loadDir(path string) *dir {
|
||||||
@@ -335,12 +218,26 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.sortType != gOpts.sortType {
|
s, err := os.Stat(d.path)
|
||||||
|
if err != nil {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case s.ModTime().After(d.loadTime):
|
||||||
|
go func() {
|
||||||
|
d.loadTime = time.Now()
|
||||||
|
nd := newDir(path)
|
||||||
|
nd.sort()
|
||||||
|
nd.sel(d.name(), nav.height)
|
||||||
|
nav.dirChan <- nd
|
||||||
|
}()
|
||||||
|
case d.sortType != gOpts.sortType:
|
||||||
go func() {
|
go func() {
|
||||||
d.loading = true
|
d.loading = true
|
||||||
name := d.name()
|
name := d.name()
|
||||||
d.sort()
|
d.sort()
|
||||||
d.find(name, nav.height)
|
d.sel(name, nav.height)
|
||||||
d.loading = false
|
d.loading = false
|
||||||
nav.dirChan <- d
|
nav.dirChan <- d
|
||||||
}()
|
}()
|
||||||
@@ -349,6 +246,100 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) getDirs(wd string) {
|
||||||
|
var dirs []*dir
|
||||||
|
|
||||||
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
|
dir := nav.loadDir(curr)
|
||||||
|
dir.sel(base, nav.height)
|
||||||
|
dirs = append(dirs, dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, j := 0, len(dirs)-1; i < j; i, j = i+1, j-1 {
|
||||||
|
dirs[i], dirs[j] = dirs[j], dirs[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.dirs = dirs
|
||||||
|
}
|
||||||
|
|
||||||
|
func newNav(height int) *nav {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
nav := &nav{
|
||||||
|
dirChan: make(chan *dir),
|
||||||
|
regChan: make(chan *reg),
|
||||||
|
dirCache: make(map[string]*dir),
|
||||||
|
regCache: make(map[string]*reg),
|
||||||
|
saves: make(map[string]bool),
|
||||||
|
marks: make(map[string]string),
|
||||||
|
selections: make(map[string]int),
|
||||||
|
selectionInd: 0,
|
||||||
|
height: height,
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.getDirs(wd)
|
||||||
|
|
||||||
|
return nav
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) renew() {
|
||||||
|
for _, d := range nav.dirs {
|
||||||
|
go func(d *dir) {
|
||||||
|
s, err := os.Stat(d.path)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting directory info: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if d.loadTime.After(s.ModTime()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.loadTime = time.Now()
|
||||||
|
nd := newDir(d.path)
|
||||||
|
nd.sort()
|
||||||
|
nav.dirChan <- nd
|
||||||
|
}(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
for m := range nav.selections {
|
||||||
|
if _, err := os.Stat(m); os.IsNotExist(err) {
|
||||||
|
delete(nav.selections, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(nav.selections) == 0 {
|
||||||
|
nav.selectionInd = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) reload() error {
|
||||||
|
nav.dirCache = make(map[string]*dir)
|
||||||
|
nav.regCache = make(map[string]*reg)
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
curr, err := nav.currFile()
|
||||||
|
nav.getDirs(wd)
|
||||||
|
if err == nil {
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
last.files = append(last.files, curr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) position() {
|
||||||
|
path := nav.currDir().path
|
||||||
|
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||||
|
nav.dirs[i].sel(filepath.Base(path), nav.height)
|
||||||
|
path = filepath.Dir(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) preview() {
|
func (nav *nav) preview() {
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -382,7 +373,7 @@ func (nav *nav) preview() {
|
|||||||
reader = f
|
reader = f
|
||||||
}
|
}
|
||||||
|
|
||||||
reg := ®{path: curr.path}
|
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||||
|
|
||||||
buf := bufio.NewScanner(reader)
|
buf := bufio.NewScanner(reader)
|
||||||
|
|
||||||
@@ -408,10 +399,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
|||||||
r, ok := nav.regCache[path]
|
r, ok := nav.regCache[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
go nav.preview()
|
go nav.preview()
|
||||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
r := ®{loading: true, path: path}
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s, err := os.Stat(r.path)
|
||||||
|
if err != nil {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.ModTime().After(r.loadTime) {
|
||||||
|
r.loadTime = time.Now()
|
||||||
|
go nav.preview()
|
||||||
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,7 +421,7 @@ func (nav *nav) sort() {
|
|||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
name := d.name()
|
name := d.name()
|
||||||
d.sort()
|
d.sort()
|
||||||
d.find(name, nav.height)
|
d.sel(name, nav.height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -441,7 +443,7 @@ func (nav *nav) up(dist int) {
|
|||||||
func (nav *nav) down(dist int) {
|
func (nav *nav) down(dist int) {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
maxind := len(dir.fi) - 1
|
maxind := len(dir.files) - 1
|
||||||
|
|
||||||
if dir.ind >= maxind {
|
if dir.ind >= maxind {
|
||||||
return
|
return
|
||||||
@@ -503,22 +505,22 @@ func (nav *nav) top() {
|
|||||||
dir.pos = 0
|
dir.pos = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) bot() {
|
func (nav *nav) bottom() {
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
dir.ind = len(dir.fi) - 1
|
dir.ind = len(dir.files) - 1
|
||||||
dir.pos = min(dir.ind, nav.height-1)
|
dir.pos = min(dir.ind, nav.height-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) toggleMark(path string) {
|
func (nav *nav) toggleSelection(path string) {
|
||||||
if _, ok := nav.marks[path]; ok {
|
if _, ok := nav.selections[path]; ok {
|
||||||
delete(nav.marks, path)
|
delete(nav.selections, path)
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
nav.markInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nav.marks[path] = nav.markInd
|
nav.selections[path] = nav.selectionInd
|
||||||
nav.markInd = nav.markInd + 1
|
nav.selectionInd++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -528,87 +530,87 @@ func (nav *nav) toggle() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.toggleMark(curr.path)
|
nav.toggleSelection(curr.path)
|
||||||
|
|
||||||
nav.down(1)
|
nav.down(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) invert() {
|
func (nav *nav) invert() {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for _, f := range last.fi {
|
for _, f := range last.files {
|
||||||
path := filepath.Join(last.path, f.Name())
|
path := filepath.Join(last.path, f.Name())
|
||||||
nav.toggleMark(path)
|
nav.toggleSelection(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) unmark() {
|
func (nav *nav) unselect() {
|
||||||
nav.marks = make(map[string]int)
|
nav.selections = make(map[string]int)
|
||||||
nav.markInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) save(copy bool) error {
|
func (nav *nav) save(cp bool) error {
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("no file selected")
|
return errors.New("no file selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles([]string{curr.path}, copy); err != nil {
|
if err := saveFiles([]string{curr.path}, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
nav.saves[curr.path] = copy
|
nav.saves[curr.path] = cp
|
||||||
} else {
|
} else {
|
||||||
marks := nav.currMarks()
|
selections := nav.currSelections()
|
||||||
|
|
||||||
if err := saveFiles(marks, copy); err != nil {
|
if err := saveFiles(selections, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
for f := range nav.marks {
|
for f := range nav.selections {
|
||||||
nav.saves[f] = copy
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) put() error {
|
func (nav *nav) paste() error {
|
||||||
list, copy, err := loadFiles()
|
list, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return errors.New("no file in yank/delete buffer")
|
return errors.New("no file in copy/cut buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
cmd := putCommand(list, dir, copy)
|
cmd := pasteCommand(list, dir, cp)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return fmt.Errorf("putting files: %s", err)
|
return fmt.Errorf("pasting files: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
return fmt.Errorf("clearing yank/delete buffer: %s", err)
|
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) sync() error {
|
func (nav *nav) sync() error {
|
||||||
list, copy, err := loadFiles()
|
list, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
nav.saves[f] = copy
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -631,7 +633,7 @@ func (nav *nav) cd(wd string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) find(path string) error {
|
func (nav *nav) sel(path string) error {
|
||||||
lstat, err := os.Stat(path)
|
lstat, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("select: %s", err)
|
return fmt.Errorf("select: %s", err)
|
||||||
@@ -647,15 +649,90 @@ func (nav *nav) find(path string) error {
|
|||||||
|
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
if last.loading {
|
if last.loading {
|
||||||
last.fi = append(last.fi, &file{FileInfo: lstat})
|
last.files = append(last.files, &file{FileInfo: lstat})
|
||||||
} else {
|
} else {
|
||||||
last.find(base, nav.height)
|
last.sel(base, nav.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func match(pattern, name string) (matched bool, err error) {
|
func findMatch(name, pattern string) bool {
|
||||||
|
if gOpts.ignorecase {
|
||||||
|
lpattern := strings.ToLower(pattern)
|
||||||
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = strings.ToLower(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gOpts.anchorfind {
|
||||||
|
return strings.HasPrefix(name, pattern)
|
||||||
|
}
|
||||||
|
return strings.Contains(name, pattern)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) findSingle() int {
|
||||||
|
count := 0
|
||||||
|
index := 0
|
||||||
|
last := nav.currDir()
|
||||||
|
for i := 0; i < len(last.files); i++ {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
count++
|
||||||
|
if count > 1 {
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
index = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if count == 1 {
|
||||||
|
if index > last.ind {
|
||||||
|
nav.down(index - last.ind)
|
||||||
|
} else {
|
||||||
|
nav.up(last.ind - index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) findNext() bool {
|
||||||
|
last := nav.currDir()
|
||||||
|
for i := last.ind + 1; i < len(last.files); i++ {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
nav.down(i - last.ind)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gOpts.wrapscan {
|
||||||
|
for i := 0; i < last.ind; i++ {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
nav.up(last.ind - i)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) findPrev() bool {
|
||||||
|
last := nav.currDir()
|
||||||
|
for i := last.ind - 1; i >= 0; i-- {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
nav.up(last.ind - i)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gOpts.wrapscan {
|
||||||
|
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||||
|
if findMatch(last.files[i].Name(), nav.find) {
|
||||||
|
nav.down(i - last.ind)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func searchMatch(name, pattern string) (matched bool, err error) {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
if !gOpts.smartcase || lpattern == pattern {
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
@@ -671,8 +748,8 @@ func match(pattern, name string) (matched bool, err error) {
|
|||||||
|
|
||||||
func (nav *nav) searchNext() error {
|
func (nav *nav) searchNext() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.fi); i++ {
|
for i := last.ind + 1; i < len(last.files); i++ {
|
||||||
matched, err := match(nav.search, last.fi[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -683,7 +760,7 @@ func (nav *nav) searchNext() error {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
for i := 0; i < last.ind; i++ {
|
||||||
matched, err := match(nav.search, last.fi[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -699,7 +776,7 @@ func (nav *nav) searchNext() error {
|
|||||||
func (nav *nav) searchPrev() error {
|
func (nav *nav) searchPrev() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
for i := last.ind - 1; i >= 0; i-- {
|
||||||
matched, err := match(nav.search, last.fi[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -709,8 +786,8 @@ func (nav *nav) searchPrev() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.fi) - 1; i > last.ind; i-- {
|
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||||
matched, err := match(nav.search, last.fi[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -730,33 +807,93 @@ func (nav *nav) currDir() *dir {
|
|||||||
func (nav *nav) currFile() (*file, error) {
|
func (nav *nav) currFile() (*file, error) {
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
if len(last.fi) == 0 {
|
if len(last.files) == 0 {
|
||||||
return nil, fmt.Errorf("empty directory")
|
return nil, fmt.Errorf("empty directory")
|
||||||
}
|
}
|
||||||
return last.fi[last.ind], nil
|
return last.files[last.ind], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type indexedMarks struct {
|
func (nav *nav) readMarks() error {
|
||||||
|
f, err := os.Open(gMarksPath)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("opening marks file: %s", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
toks := strings.SplitN(scanner.Text(), ":", 2)
|
||||||
|
if _, ok := nav.marks[toks[0]]; !ok {
|
||||||
|
nav.marks[toks[0]] = toks[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return fmt.Errorf("reading marks file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) writeMarks() error {
|
||||||
|
if len(nav.marks) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := nav.readMarks(); err != nil {
|
||||||
|
return fmt.Errorf("reading marks file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||||
|
return fmt.Errorf("creating data directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Create(gMarksPath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("creating marks file: %s", err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
var keys []string
|
||||||
|
for k := range nav.marks {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
for _, k := range keys {
|
||||||
|
_, err = f.WriteString(fmt.Sprintf("%s:%s\n", k, nav.marks[k]))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("writing marks file: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type indexedSelections struct {
|
||||||
paths []string
|
paths []string
|
||||||
indices []int
|
indices []int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m indexedMarks) Len() int { return len(m.paths) }
|
func (m indexedSelections) Len() int { return len(m.paths) }
|
||||||
|
|
||||||
func (m indexedMarks) Swap(i, j int) {
|
func (m indexedSelections) Swap(i, j int) {
|
||||||
m.paths[i], m.paths[j] = m.paths[j], m.paths[i]
|
m.paths[i], m.paths[j] = m.paths[j], m.paths[i]
|
||||||
m.indices[i], m.indices[j] = m.indices[j], m.indices[i]
|
m.indices[i], m.indices[j] = m.indices[j], m.indices[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m indexedMarks) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
func (m indexedSelections) Less(i, j int) bool { return m.indices[i] < m.indices[j] }
|
||||||
|
|
||||||
func (nav *nav) currMarks() []string {
|
func (nav *nav) currSelections() []string {
|
||||||
paths := make([]string, 0, len(nav.marks))
|
paths := make([]string, 0, len(nav.selections))
|
||||||
indices := make([]int, 0, len(nav.marks))
|
indices := make([]int, 0, len(nav.selections))
|
||||||
for path, index := range nav.marks {
|
for path, index := range nav.selections {
|
||||||
paths = append(paths, path)
|
paths = append(paths, path)
|
||||||
indices = append(indices, index)
|
indices = append(indices, index)
|
||||||
}
|
}
|
||||||
sort.Sort(indexedMarks{paths: paths, indices: indices})
|
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ type sortType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
|
anchorfind bool
|
||||||
dircounts bool
|
dircounts bool
|
||||||
drawbox bool
|
drawbox bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
@@ -32,6 +33,8 @@ var gOpts struct {
|
|||||||
preview bool
|
preview bool
|
||||||
smartcase bool
|
smartcase bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
findlen int
|
||||||
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
filesep string
|
filesep string
|
||||||
@@ -42,6 +45,7 @@ var gOpts struct {
|
|||||||
timefmt string
|
timefmt string
|
||||||
ratios []int
|
ratios []int
|
||||||
info []string
|
info []string
|
||||||
|
shellopts []string
|
||||||
keys map[string]expr
|
keys map[string]expr
|
||||||
cmdkeys map[string]expr
|
cmdkeys map[string]expr
|
||||||
cmds map[string]expr
|
cmds map[string]expr
|
||||||
@@ -49,6 +53,7 @@ var gOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
gOpts.anchorfind = true
|
||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
gOpts.drawbox = false
|
gOpts.drawbox = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
@@ -56,6 +61,8 @@ func init() {
|
|||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
|
gOpts.findlen = 1
|
||||||
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
gOpts.filesep = "\n"
|
gOpts.filesep = "\n"
|
||||||
@@ -64,6 +71,7 @@ func init() {
|
|||||||
gOpts.timefmt = time.ANSIC
|
gOpts.timefmt = time.ANSIC
|
||||||
gOpts.ratios = []int{1, 2, 3}
|
gOpts.ratios = []int{1, 2, 3}
|
||||||
gOpts.info = nil
|
gOpts.info = nil
|
||||||
|
gOpts.shellopts = nil
|
||||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||||
|
|
||||||
gOpts.keys = make(map[string]expr)
|
gOpts.keys = make(map[string]expr)
|
||||||
@@ -72,24 +80,28 @@ func init() {
|
|||||||
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
||||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||||
gOpts.keys["<c-b>"] = &callExpr{"page-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["j"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||||
gOpts.keys["<c-f>"] = &callExpr{"page-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["h"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
||||||
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
||||||
gOpts.keys["G"] = &callExpr{"bot", 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["<space>"] = &callExpr{"toggle", nil, 1}
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||||
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||||
gOpts.keys["y"] = &callExpr{"yank", nil, 1}
|
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||||
gOpts.keys["d"] = &callExpr{"delete", nil, 1}
|
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
||||||
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
||||||
gOpts.keys["p"] = &callExpr{"put", nil, 1}
|
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
|
||||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
||||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
||||||
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
||||||
@@ -97,12 +109,18 @@ func init() {
|
|||||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||||
gOpts.keys["&"] = &callExpr{"shell-async", 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", nil, 1}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-hist-prev", 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["zh"] = &setExpr{"hidden!", ""}
|
||||||
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
gOpts.keys["zr"] = &setExpr{"reverse!", ""}
|
||||||
@@ -117,14 +135,13 @@ func init() {
|
|||||||
|
|
||||||
gOpts.cmdkeys = make(map[string]expr)
|
gOpts.cmdkeys = make(map[string]expr)
|
||||||
|
|
||||||
// TODO: rest of the keys
|
|
||||||
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
gOpts.cmdkeys["<space>"] = &callExpr{"cmd-insert", []string{" "}, 1}
|
||||||
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
gOpts.cmdkeys["<esc>"] = &callExpr{"cmd-escape", nil, 1}
|
||||||
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-comp", nil, 1}
|
gOpts.cmdkeys["<tab>"] = &callExpr{"cmd-complete", nil, 1}
|
||||||
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
gOpts.cmdkeys["<enter>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
gOpts.cmdkeys["<c-j>"] = &callExpr{"cmd-enter", nil, 1}
|
||||||
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-hist-next", nil, 1}
|
gOpts.cmdkeys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||||
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-hist-prev", nil, 1}
|
gOpts.cmdkeys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||||
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
gOpts.cmdkeys["<delete>"] = &callExpr{"cmd-delete", nil, 1}
|
||||||
gOpts.cmdkeys["<c-d>"] = &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["<bs>"] = &callExpr{"cmd-delete-back", nil, 1}
|
||||||
@@ -133,16 +150,23 @@ func init() {
|
|||||||
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
gOpts.cmdkeys["<c-b>"] = &callExpr{"cmd-left", nil, 1}
|
||||||
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
gOpts.cmdkeys["<right>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
gOpts.cmdkeys["<c-f>"] = &callExpr{"cmd-right", nil, 1}
|
||||||
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-beg", nil, 1}
|
gOpts.cmdkeys["<home>"] = &callExpr{"cmd-home", nil, 1}
|
||||||
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-beg", nil, 1}
|
gOpts.cmdkeys["<c-a>"] = &callExpr{"cmd-home", nil, 1}
|
||||||
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
gOpts.cmdkeys["<end>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
gOpts.cmdkeys["<c-e>"] = &callExpr{"cmd-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-u>"] = &callExpr{"cmd-delete-beg", 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-k>"] = &callExpr{"cmd-delete-end", nil, 1}
|
||||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil, 1}
|
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-unix-word", nil, 1}
|
||||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil, 1}
|
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-yank", nil, 1}
|
||||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil, 1}
|
||||||
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", 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)
|
gOpts.cmds = make(map[string]expr)
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
envOpener = os.Getenv("OPENER")
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = os.Getenv("EDITOR")
|
||||||
envPager = os.Getenv("PAGER")
|
envPager = os.Getenv("PAGER")
|
||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
@@ -25,14 +26,42 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gUser *user.User
|
gUser *user.User
|
||||||
gConfigPath string
|
gConfigPaths []string
|
||||||
|
gMarksPath string
|
||||||
|
gHistoryPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
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
|
gUser = u
|
||||||
|
|
||||||
@@ -41,21 +70,36 @@ func init() {
|
|||||||
config = filepath.Join(gUser.HomeDir, ".config")
|
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))
|
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||||
}
|
}
|
||||||
|
|
||||||
func pauseCommand() *exec.Cmd {
|
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||||
c := `echo
|
return exec.Command(name, arg...)
|
||||||
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", 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 {
|
func shellCommand(s string, args []string) *exec.Cmd {
|
||||||
@@ -65,14 +109,16 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
|||||||
|
|
||||||
args = append([]string{"-c", s, "--"}, args...)
|
args = append([]string{"-c", s, "--"}, args...)
|
||||||
|
|
||||||
|
args = append(gOpts.shellopts, args...)
|
||||||
|
|
||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
||||||
var sh string
|
var sh string
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
if copy {
|
if cp {
|
||||||
sh = "cp"
|
sh = "cp"
|
||||||
args = append(args, "-R")
|
args = append(args, "-R")
|
||||||
} else {
|
} else {
|
||||||
@@ -80,10 +126,11 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// XXX: POSIX standard states that -i flag shall do nothing when the
|
// 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,
|
// response is not affirmative. Since this command is run with a nil
|
||||||
// it should not give an affirmative answer and in return this command
|
// stdin, it should not give an affirmative answer and in return this
|
||||||
// should not overwrite existing files. Our intention here is to use the
|
// command should not overwrite existing files. Our intention here is
|
||||||
// standard -i flag in place of non-standard -n flag to avoid overwrites.
|
// to use the standard -i flag in place of non-standard -n flag to
|
||||||
|
// avoid overwrites.
|
||||||
args = append(args, "-i")
|
args = append(args, "-i")
|
||||||
|
|
||||||
args = append(args, list...)
|
args = append(args, list...)
|
||||||
@@ -93,31 +140,19 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
if envEditor == "" {
|
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||||
gOpts.keys["e"] = &execExpr{"$", `vi "$f"`}
|
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||||
} else {
|
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
|
||||||
gOpts.keys["e"] = &execExpr{"$", envEditor + ` "$f"`}
|
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}
|
||||||
}
|
|
||||||
|
|
||||||
if envPager == "" {
|
gOpts.cmds["doc"] = &execExpr{"$", "lf -doc | $PAGER"}
|
||||||
gOpts.keys["i"] = &execExpr{"$", `less "$f"`}
|
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||||
} 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"`}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
func moveCursor(y, x int) {
|
||||||
fmt.Printf("\033[%d;%dH", y, x)
|
fmt.Printf("\033[%d;%dH", y, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExecutable(f os.FileInfo) bool {
|
||||||
|
return f.Mode()&0111 != 0
|
||||||
|
}
|
||||||
+70
-9
@@ -7,6 +7,18 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"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 (
|
var (
|
||||||
@@ -16,11 +28,29 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gUser *user.User
|
gUser *user.User
|
||||||
gConfigPath string
|
gConfigPaths []string
|
||||||
|
gMarksPath string
|
||||||
|
gHistoryPath string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if envOpener == "" {
|
||||||
|
envOpener = "start"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envEditor == "" {
|
||||||
|
envEditor = "notepad"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envPager == "" {
|
||||||
|
envPager = "more"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envShell == "" {
|
||||||
|
envShell = "cmd"
|
||||||
|
}
|
||||||
|
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
log.Printf("user: %s", err)
|
||||||
@@ -30,7 +60,21 @@ func init() {
|
|||||||
// remove domain prefix
|
// remove domain prefix
|
||||||
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
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 {
|
func pauseCommand() *exec.Cmd {
|
||||||
@@ -39,14 +83,17 @@ func pauseCommand() *exec.Cmd {
|
|||||||
|
|
||||||
func shellCommand(s string, args []string) *exec.Cmd {
|
func shellCommand(s string, args []string) *exec.Cmd {
|
||||||
args = append([]string{"/c", s}, args...)
|
args = append([]string{"/c", s}, args...)
|
||||||
|
|
||||||
|
args = append(gOpts.shellopts, args...)
|
||||||
|
|
||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
sh := "robocopy"
|
sh := "robocopy"
|
||||||
if !copy {
|
if !cp {
|
||||||
args = []string{"/move"}
|
args = []string{"/move"}
|
||||||
}
|
}
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
@@ -70,13 +117,27 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
gOpts.keys["e"] = &execExpr{"$", `notepad "%f%"`}
|
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||||
gOpts.keys["i"] = &execExpr{"$", `more "%f%"`}
|
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||||
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
|
||||||
gOpts.cmds["open-file"] = &execExpr{"&", `start "" "%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) {
|
func moveCursor(y, x int) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return
|
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
|
||||||
|
}
|
||||||
@@ -23,7 +23,7 @@ package main
|
|||||||
// ExecExpr = Prefix <value> '\n'
|
// ExecExpr = Prefix <value> '\n'
|
||||||
// | Prefix '{{' <value> '}}' ';'
|
// | Prefix '{{' <value> '}}' ';'
|
||||||
//
|
//
|
||||||
// Prefix = '$' | '!' | '&' | '/' | '?'
|
// Prefix = '$' | '%' | '!' | '&'
|
||||||
//
|
//
|
||||||
// ListExpr = ':' Expr ListRest '\n'
|
// ListExpr = ':' Expr ListRest '\n'
|
||||||
// | ':' '{{' Expr ListRest '}}' ';'
|
// | ':' '{{' Expr ListRest '}}' ';'
|
||||||
|
|||||||
@@ -13,15 +13,17 @@ var (
|
|||||||
gCopyFile bool
|
gCopyFile bool
|
||||||
gFileList []string
|
gFileList []string
|
||||||
gConnList = make(map[int]net.Conn)
|
gConnList = make(map[int]net.Conn)
|
||||||
|
gQuitChan = make(chan bool, 1)
|
||||||
|
gListener net.Listener
|
||||||
)
|
)
|
||||||
|
|
||||||
func serve() {
|
func serve() {
|
||||||
logFile, err := os.Create(gServerLogPath)
|
f, err := os.Create(gServerLogPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer f.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(f)
|
||||||
|
|
||||||
log.Print("hi!")
|
log.Print("hi!")
|
||||||
|
|
||||||
@@ -32,6 +34,8 @@ func serve() {
|
|||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
|
gListener = l
|
||||||
|
|
||||||
listen(l)
|
listen(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +43,13 @@ func listen(l net.Listener) {
|
|||||||
for {
|
for {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
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)
|
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:
|
default:
|
||||||
log.Printf("listen: unexpected command: %s", word)
|
log.Printf("listen: unexpected command: %s", word)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@@ -20,86 +21,63 @@ import (
|
|||||||
|
|
||||||
const gEscapeCode = 27
|
const gEscapeCode = 27
|
||||||
|
|
||||||
var gAnsiCodes = map[int]termbox.Attribute{
|
var gKeyVal = map[termbox.Key]string{
|
||||||
0: termbox.ColorDefault,
|
termbox.KeyF1: "<f-1>",
|
||||||
1: termbox.AttrBold,
|
termbox.KeyF2: "<f-2>",
|
||||||
4: termbox.AttrUnderline,
|
termbox.KeyF3: "<f-3>",
|
||||||
7: termbox.AttrReverse,
|
termbox.KeyF4: "<f-4>",
|
||||||
30: termbox.ColorBlack,
|
termbox.KeyF5: "<f-5>",
|
||||||
31: termbox.ColorRed,
|
termbox.KeyF6: "<f-6>",
|
||||||
32: termbox.ColorGreen,
|
termbox.KeyF7: "<f-7>",
|
||||||
33: termbox.ColorYellow,
|
termbox.KeyF8: "<f-8>",
|
||||||
34: termbox.ColorBlue,
|
termbox.KeyF9: "<f-9>",
|
||||||
35: termbox.ColorMagenta,
|
termbox.KeyF10: "<f-10>",
|
||||||
36: termbox.ColorCyan,
|
termbox.KeyF11: "<f-11>",
|
||||||
37: termbox.ColorWhite,
|
termbox.KeyF12: "<f-12>",
|
||||||
40: termbox.ColorBlack,
|
termbox.KeyInsert: "<insert>",
|
||||||
41: termbox.ColorRed,
|
termbox.KeyDelete: "<delete>",
|
||||||
42: termbox.ColorGreen,
|
termbox.KeyHome: "<home>",
|
||||||
43: termbox.ColorYellow,
|
termbox.KeyEnd: "<end>",
|
||||||
44: termbox.ColorBlue,
|
termbox.KeyPgup: "<pgup>",
|
||||||
45: termbox.ColorMagenta,
|
termbox.KeyPgdn: "<pgdn>",
|
||||||
46: termbox.ColorCyan,
|
termbox.KeyArrowUp: "<up>",
|
||||||
47: termbox.ColorWhite,
|
termbox.KeyArrowDown: "<down>",
|
||||||
}
|
termbox.KeyArrowLeft: "<left>",
|
||||||
|
termbox.KeyArrowRight: "<right>",
|
||||||
var gKeyVal = map[termbox.Key][]rune{
|
termbox.KeyCtrlSpace: "<c-space>",
|
||||||
termbox.KeyF1: {'<', 'f', '-', '1', '>'},
|
termbox.KeyCtrlA: "<c-a>",
|
||||||
termbox.KeyF2: {'<', 'f', '-', '2', '>'},
|
termbox.KeyCtrlB: "<c-b>",
|
||||||
termbox.KeyF3: {'<', 'f', '-', '3', '>'},
|
termbox.KeyCtrlC: "<c-c>",
|
||||||
termbox.KeyF4: {'<', 'f', '-', '4', '>'},
|
termbox.KeyCtrlD: "<c-d>",
|
||||||
termbox.KeyF5: {'<', 'f', '-', '5', '>'},
|
termbox.KeyCtrlE: "<c-e>",
|
||||||
termbox.KeyF6: {'<', 'f', '-', '6', '>'},
|
termbox.KeyCtrlF: "<c-f>",
|
||||||
termbox.KeyF7: {'<', 'f', '-', '7', '>'},
|
termbox.KeyCtrlG: "<c-g>",
|
||||||
termbox.KeyF8: {'<', 'f', '-', '8', '>'},
|
termbox.KeyBackspace: "<bs>",
|
||||||
termbox.KeyF9: {'<', 'f', '-', '9', '>'},
|
termbox.KeyTab: "<tab>",
|
||||||
termbox.KeyF10: {'<', 'f', '-', '1', '0', '>'},
|
termbox.KeyCtrlJ: "<c-j>",
|
||||||
termbox.KeyF11: {'<', 'f', '-', '1', '1', '>'},
|
termbox.KeyCtrlK: "<c-k>",
|
||||||
termbox.KeyF12: {'<', 'f', '-', '1', '2', '>'},
|
termbox.KeyCtrlL: "<c-l>",
|
||||||
termbox.KeyInsert: {'<', 'i', 'n', 's', 'e', 'r', 't', '>'},
|
termbox.KeyEnter: "<enter>",
|
||||||
termbox.KeyDelete: {'<', 'd', 'e', 'l', 'e', 't', 'e', '>'},
|
termbox.KeyCtrlN: "<c-n>",
|
||||||
termbox.KeyHome: {'<', 'h', 'o', 'm', 'e', '>'},
|
termbox.KeyCtrlO: "<c-o>",
|
||||||
termbox.KeyEnd: {'<', 'e', 'n', 'd', '>'},
|
termbox.KeyCtrlP: "<c-p>",
|
||||||
termbox.KeyPgup: {'<', 'p', 'g', 'u', 'p', '>'},
|
termbox.KeyCtrlQ: "<c-q>",
|
||||||
termbox.KeyPgdn: {'<', 'p', 'g', 'd', 'n', '>'},
|
termbox.KeyCtrlR: "<c-r>",
|
||||||
termbox.KeyArrowUp: {'<', 'u', 'p', '>'},
|
termbox.KeyCtrlS: "<c-s>",
|
||||||
termbox.KeyArrowDown: {'<', 'd', 'o', 'w', 'n', '>'},
|
termbox.KeyCtrlT: "<c-t>",
|
||||||
termbox.KeyArrowLeft: {'<', 'l', 'e', 'f', 't', '>'},
|
termbox.KeyCtrlU: "<c-u>",
|
||||||
termbox.KeyArrowRight: {'<', 'r', 'i', 'g', 'h', 't', '>'},
|
termbox.KeyCtrlV: "<c-v>",
|
||||||
termbox.KeyCtrlSpace: {'<', 'c', '-', 's', 'p', 'a', 'c', 'e', '>'},
|
termbox.KeyCtrlW: "<c-w>",
|
||||||
termbox.KeyCtrlA: {'<', 'c', '-', 'a', '>'},
|
termbox.KeyCtrlX: "<c-x>",
|
||||||
termbox.KeyCtrlB: {'<', 'c', '-', 'b', '>'},
|
termbox.KeyCtrlY: "<c-y>",
|
||||||
termbox.KeyCtrlC: {'<', 'c', '-', 'c', '>'},
|
termbox.KeyCtrlZ: "<c-z>",
|
||||||
termbox.KeyCtrlD: {'<', 'c', '-', 'd', '>'},
|
termbox.KeyEsc: "<esc>",
|
||||||
termbox.KeyCtrlE: {'<', 'c', '-', 'e', '>'},
|
termbox.KeyCtrlBackslash: "<c-\\>",
|
||||||
termbox.KeyCtrlF: {'<', 'c', '-', 'f', '>'},
|
termbox.KeyCtrlRsqBracket: "<c-]>",
|
||||||
termbox.KeyCtrlG: {'<', 'c', '-', 'g', '>'},
|
termbox.KeyCtrl6: "<c-6>",
|
||||||
termbox.KeyBackspace: {'<', 'b', 's', '>'},
|
termbox.KeyCtrlSlash: "<c-/>",
|
||||||
termbox.KeyTab: {'<', 't', 'a', 'b', '>'},
|
termbox.KeySpace: "<space>",
|
||||||
termbox.KeyCtrlJ: {'<', 'c', '-', 'j', '>'},
|
termbox.KeyBackspace2: "<bs2>",
|
||||||
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 gValKey map[string]termbox.Key
|
var gValKey map[string]termbox.Key
|
||||||
@@ -107,7 +85,7 @@ var gValKey map[string]termbox.Key
|
|||||||
func init() {
|
func init() {
|
||||||
gValKey = make(map[string]termbox.Key)
|
gValKey = make(map[string]termbox.Key)
|
||||||
for k, v := range gKeyVal {
|
for k, v := range gKeyVal {
|
||||||
gValKey[string(v)] = k
|
gValKey[v] = k
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
|||||||
|
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
|
if reg.loading {
|
||||||
|
fg = termbox.AttrBold
|
||||||
|
win.print(2, 0, fg, bg, "loading...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for i, l := range reg.lines {
|
for i, l := range reg.lines {
|
||||||
fg, bg = win.print(2, i, fg, bg, l)
|
fg, bg = win.print(2, i, fg, bg, l)
|
||||||
}
|
}
|
||||||
@@ -223,27 +207,27 @@ func fileInfo(f *file, d *dir) string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.count == -1 {
|
if f.dirCount == -1 {
|
||||||
d, err := os.Open(path)
|
d, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.count = -2
|
f.dirCount = -2
|
||||||
}
|
}
|
||||||
|
|
||||||
names, err := d.Readdirnames(1000)
|
names, err := d.Readdirnames(1000)
|
||||||
d.Close()
|
d.Close()
|
||||||
|
|
||||||
if names == nil && err != io.EOF {
|
if names == nil && err != io.EOF {
|
||||||
f.count = -2
|
f.dirCount = -2
|
||||||
} else {
|
} else {
|
||||||
f.count = len(names)
|
f.dirCount = len(names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case f.count < 0:
|
case f.dirCount < 0:
|
||||||
info = fmt.Sprintf("%s ?", info)
|
info = fmt.Sprintf("%s ?", info)
|
||||||
case f.count < 1000:
|
case f.dirCount < 1000:
|
||||||
info = fmt.Sprintf("%s %4d", info, f.count)
|
info = fmt.Sprintf("%s %4d", info, f.dirCount)
|
||||||
default:
|
default:
|
||||||
info = fmt.Sprintf("%s 999+", info)
|
info = fmt.Sprintf("%s 999+", info)
|
||||||
}
|
}
|
||||||
@@ -257,7 +241,7 @@ func fileInfo(f *file, d *dir) string {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool, colors colorMap) {
|
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
||||||
if win.w < 5 || dir == nil {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -270,28 +254,28 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dir.fi) == 0 {
|
if len(dir.files) == 0 {
|
||||||
fg = termbox.AttrBold
|
fg = termbox.AttrBold
|
||||||
win.print(2, 0, fg, bg, "empty")
|
win.print(2, 0, fg, bg, "empty")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
beg := max(dir.ind-dir.pos, 0)
|
beg := max(dir.ind-dir.pos, 0)
|
||||||
end := min(beg+win.h, len(dir.fi))
|
end := min(beg+win.h, len(dir.files))
|
||||||
|
|
||||||
if beg > end {
|
if beg > end {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, f := range dir.fi[beg:end] {
|
for i, f := range dir.files[beg:end] {
|
||||||
fg, bg = colors.get(f)
|
fg, bg = colors.get(f)
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := marks[path]; ok {
|
if _, ok := selections[path]; ok {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||||
} else if copy, ok := saves[path]; ok {
|
} else if cp, ok := saves[path]; ok {
|
||||||
if copy {
|
if cp {
|
||||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
win.print(0, i, fg, termbox.ColorYellow, " ")
|
||||||
} else {
|
} else {
|
||||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
win.print(0, i, fg, termbox.ColorRed, " ")
|
||||||
@@ -356,7 +340,7 @@ type ui struct {
|
|||||||
cmdPrefix string
|
cmdPrefix string
|
||||||
cmdAccLeft []rune
|
cmdAccLeft []rune
|
||||||
cmdAccRight []rune
|
cmdAccRight []rune
|
||||||
cmdBuf []rune
|
cmdYankBuf []rune
|
||||||
keyAcc []rune
|
keyAcc []rune
|
||||||
keyCount []rune
|
keyCount []rune
|
||||||
colors colorMap
|
colors colorMap
|
||||||
@@ -364,8 +348,8 @@ type ui struct {
|
|||||||
|
|
||||||
func getWidths(wtot int) []int {
|
func getWidths(wtot int) []int {
|
||||||
rsum := 0
|
rsum := 0
|
||||||
for _, rat := range gOpts.ratios {
|
for _, r := range gOpts.ratios {
|
||||||
rsum += rat
|
rsum += r
|
||||||
}
|
}
|
||||||
|
|
||||||
wlen := len(gOpts.ratios)
|
wlen := len(gOpts.ratios)
|
||||||
@@ -409,11 +393,27 @@ func getWins() []*win {
|
|||||||
func newUI() *ui {
|
func newUI() *ui {
|
||||||
wtot, htot := termbox.Size()
|
wtot, htot := termbox.Size()
|
||||||
|
|
||||||
evChan := make(chan termbox.Event)
|
evQueue := make(chan termbox.Event)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
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
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -455,7 +455,7 @@ func (ui *ui) sort() {
|
|||||||
}
|
}
|
||||||
name := ui.dirPrev.name()
|
name := ui.dirPrev.name()
|
||||||
ui.dirPrev.sort()
|
ui.dirPrev.sort()
|
||||||
ui.dirPrev.find(name, ui.wins[0].h)
|
ui.dirPrev.sel(name, ui.wins[0].h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) print(msg string) {
|
func (ui *ui) print(msg string) {
|
||||||
@@ -468,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type reg struct {
|
type reg struct {
|
||||||
path string
|
loading bool
|
||||||
lines []string
|
loadTime time.Time
|
||||||
|
path string
|
||||||
|
lines []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) loadFile(nav *nav) {
|
func (ui *ui) loadFile(nav *nav) {
|
||||||
@@ -543,7 +545,7 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
|
|
||||||
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
||||||
|
|
||||||
tot := len(currDir.fi)
|
tot := len(currDir.files)
|
||||||
ind := min(currDir.ind+1, tot)
|
ind := min(currDir.ind+1, tot)
|
||||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
@@ -600,7 +602,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
|
|
||||||
doff := len(nav.dirs) - length
|
doff := len(nav.dirs) - length
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves, ui.colors)
|
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ui.cmdPrefix {
|
switch ui.cmdPrefix {
|
||||||
@@ -626,7 +628,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
preview := ui.wins[len(ui.wins)-1]
|
preview := ui.wins[len(ui.wins)-1]
|
||||||
|
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
preview.printDir(ui.dirPrev, nav.marks, nav.saves, ui.colors)
|
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
||||||
} else if f.Mode().IsRegular() {
|
} else if f.Mode().IsRegular() {
|
||||||
preview.printReg(ui.regPrev)
|
preview.printReg(ui.regPrev)
|
||||||
}
|
}
|
||||||
@@ -667,11 +669,12 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
||||||
binds = make(map[string]expr)
|
binds = make(map[string]expr)
|
||||||
for key, expr := range keys {
|
for key, expr := range keys {
|
||||||
if strings.HasPrefix(key, prefix) {
|
if !strings.HasPrefix(key, prefix) {
|
||||||
binds[key] = expr
|
continue
|
||||||
if key == prefix {
|
}
|
||||||
ok = true
|
binds[key] = expr
|
||||||
}
|
if key == prefix {
|
||||||
|
ok = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -697,6 +700,26 @@ func listBinds(binds map[string]expr) *bytes.Buffer {
|
|||||||
return b
|
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 {
|
func (ui *ui) pollEvent() termbox.Event {
|
||||||
select {
|
select {
|
||||||
case key := <-ui.keyChan:
|
case key := <-ui.keyChan:
|
||||||
@@ -705,11 +728,15 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
if len(key) == 1 {
|
if len(key) == 1 {
|
||||||
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
||||||
} else {
|
} else {
|
||||||
switch key {
|
switch {
|
||||||
case "<lt>":
|
case key == "<lt>":
|
||||||
ev.Ch = '<'
|
ev.Ch = '<'
|
||||||
case "<gt>":
|
case key == "<gt>":
|
||||||
ev.Ch = '>'
|
ev.Ch = '>'
|
||||||
|
case reAltKey.MatchString(key):
|
||||||
|
match := reAltKey.FindStringSubmatch(key)[1]
|
||||||
|
ev.Ch, _ = utf8.DecodeRuneInString(match)
|
||||||
|
ev.Mod = termbox.ModAlt
|
||||||
default:
|
default:
|
||||||
if val, ok := gValKey[key]; ok {
|
if val, ok := gValKey[key]; ok {
|
||||||
ev.Key = val
|
ev.Key = val
|
||||||
@@ -726,17 +753,9 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
// This function is used to read a normal event on the client side. For keys,
|
||||||
if ev.Ch != 0 {
|
// digits are interpreted as command counts but this is only done for digits
|
||||||
ch <- &callExpr{"cmd-insert", []string{string(ev.Ch)}, 1}
|
// preceding any non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
||||||
} else {
|
|
||||||
val := gKeyVal[ev.Key]
|
|
||||||
if expr, ok := gOpts.cmdkeys[string(val)]; ok {
|
|
||||||
ch <- expr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||||
draw := &callExpr{"draw", nil, 1}
|
draw := &callExpr{"draw", nil, 1}
|
||||||
count := 1
|
count := 1
|
||||||
@@ -746,9 +765,11 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
if ev.Ch != 0 {
|
if ev.Ch != 0 {
|
||||||
switch {
|
switch {
|
||||||
case ev.Ch == '<':
|
case ev.Ch == '<':
|
||||||
ui.keyAcc = append(ui.keyAcc, '<', 'l', 't', '>')
|
ui.keyAcc = append(ui.keyAcc, []rune("<lt>")...)
|
||||||
case ev.Ch == '>':
|
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:
|
case unicode.IsDigit(ev.Ch) && len(ui.keyAcc) == 0:
|
||||||
ui.keyCount = append(ui.keyCount, ev.Ch)
|
ui.keyCount = append(ui.keyCount, ev.Ch)
|
||||||
default:
|
default:
|
||||||
@@ -756,12 +777,12 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := gKeyVal[ev.Key]
|
val := gKeyVal[ev.Key]
|
||||||
if string(val) == "<esc>" {
|
if val == "<esc>" {
|
||||||
ch <- draw
|
ch <- draw
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
}
|
}
|
||||||
ui.keyAcc = append(ui.keyAcc, val...)
|
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ui.keyAcc) == 0 {
|
if len(ui.keyAcc) == 0 {
|
||||||
@@ -803,7 +824,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: use a delay
|
|
||||||
if len(ui.keyCount) > 0 {
|
if len(ui.keyCount) > 0 {
|
||||||
c, err := strconv.Atoi(string(ui.keyCount))
|
c, err := strconv.Atoi(string(ui.keyCount))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -828,14 +848,27 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
case termbox.EventResize:
|
case termbox.EventResize:
|
||||||
ch <- &callExpr{"redraw", nil, 1}
|
ch <- &callExpr{"redraw", nil, 1}
|
||||||
default:
|
|
||||||
// TODO: handle other events
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to read expressions on the client side. Digits are
|
func readCmdEvent(ch chan<- expr, ev termbox.Event) {
|
||||||
// interpreted as command counts but this is only done for digits preceding any
|
if ev.Ch != 0 {
|
||||||
// non-digit characters (e.g. "42y2k" as 42 times "y2k").
|
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 {
|
func (ui *ui) readExpr() <-chan expr {
|
||||||
ch := make(chan expr)
|
ch := make(chan expr)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user