Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13fe1931cd | ||
|
|
2c87b0dcfe | ||
|
|
b2b22fb674 | ||
|
|
45270e389e | ||
|
|
fee016f406 | ||
|
|
29de45e466 | ||
|
|
791b704257 | ||
|
|
e3bc11408f | ||
|
|
6f35abb4ca | ||
|
|
0eedb71d6c | ||
|
|
1eedd29546 | ||
|
|
866a7e6a2b | ||
|
|
1956a759c4 | ||
|
|
9656553974 | ||
|
|
31945fbcb5 | ||
|
|
4a8943b6b7 | ||
|
|
885e896b4a | ||
|
|
808404978e | ||
|
|
99734c7dcf | ||
|
|
f44ec4f5bd | ||
|
|
4d2a628550 | ||
|
|
193285a65d | ||
|
|
6ec2924b6b | ||
|
|
599ac11f26 | ||
|
|
728c5fbb2c | ||
|
|
0f47c5428b | ||
|
|
4865ce9b00 | ||
|
|
d6e9aece51 | ||
|
|
fd1af47233 | ||
|
|
184762d83a | ||
|
|
27f104b3e6 | ||
|
|
35930924a7 | ||
|
|
4a1388a5c7 | ||
|
|
92e994ebf6 | ||
|
|
245db502cc | ||
|
|
ca95bcf1d8 | ||
|
|
dd6a85f480 | ||
|
|
db8f535b61 | ||
|
|
52be0b3aab | ||
|
|
bd889a9e06 | ||
|
|
951529ebc0 | ||
|
|
0fc14e3b2d | ||
|
|
79b05dc365 | ||
|
|
c7fe60c541 | ||
|
|
ec5fac3274 | ||
|
|
90f0339fa9 | ||
|
|
e0e5977008 | ||
|
|
85a6fe95c5 | ||
|
|
55955fa5c1 | ||
|
|
993b227682 | ||
|
|
d8b9bab3ea | ||
|
|
c5297d6b6b | ||
|
|
8dd3f692b8 | ||
|
|
7e3f92f049 | ||
|
|
3efdfd3bca | ||
|
|
b101603a4a | ||
|
|
c693b7eae4 | ||
|
|
4ee6488a09 | ||
|
|
8229d972b9 | ||
|
|
6193885a55 | ||
|
|
6b1748240c | ||
|
|
629a7f3297 | ||
|
|
5e67147204 | ||
|
|
266a583adb | ||
|
|
b22384d634 | ||
|
|
4ba3c3cda9 | ||
|
|
4420e41c76 | ||
|
|
a59a5aa712 | ||
|
|
170e39b95e | ||
|
|
011cca76d1 | ||
|
|
0b8de7c77e | ||
|
|
d3f9a3588f | ||
|
|
a0935fabcb | ||
|
|
e82cbb820f | ||
|
|
9234bcd5b8 | ||
|
|
7dbb61f295 | ||
|
|
40002a7752 |
No files matched your search
Generated
-21
@@ -1,21 +0,0 @@
|
|||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mattn/go-runewidth"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/nsf/termbox-go"
|
|
||||||
packages = ["."]
|
|
||||||
revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "8508b73787d4948edb76ccc25789c311a4ab84d4c8c0b96b267857e2e88d974e"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
||||||
-38
@@ -1,38 +0,0 @@
|
|||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
#
|
|
||||||
# [prune]
|
|
||||||
# non-go = false
|
|
||||||
# go-tests = true
|
|
||||||
# unused-packages = true
|
|
||||||
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/mattn/go-runewidth"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/nsf/termbox-go"
|
|
||||||
|
|
||||||
[prune]
|
|
||||||
go-tests = true
|
|
||||||
unused-packages = true
|
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -48,7 +47,7 @@ func (app *app) readFile(path string) {
|
|||||||
|
|
||||||
f, err := os.Open(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("opening file: %s", err)
|
app.ui.echoerrf("opening file: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@@ -60,7 +59,7 @@ func (app *app) readFile(path string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
app.ui.printf("%s", p.err)
|
app.ui.echoerrf("%s", p.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,9 +135,43 @@ func (app *app) loop() {
|
|||||||
clientChan := app.ui.readExpr()
|
clientChan := app.ui.readExpr()
|
||||||
serverChan := readExpr()
|
serverChan := readExpr()
|
||||||
|
|
||||||
|
if gSelect != "" {
|
||||||
|
go func() {
|
||||||
|
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range gConfigPaths {
|
||||||
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
app.readFile(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if gCommand != "" {
|
||||||
|
p := newParser(strings.NewReader(gCommand))
|
||||||
|
|
||||||
|
for p.parse() {
|
||||||
|
p.expr.eval(app, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.err != nil {
|
||||||
|
app.ui.echoerrf("%s", p.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.quitChan:
|
case <-app.quitChan:
|
||||||
|
if app.nav.copyTotal > 0 {
|
||||||
|
app.ui.echoerr("quit: copy operation in progress")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if app.nav.moveTotal > 0 {
|
||||||
|
app.ui.echoerr("quit: move operation in progress")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Print("bye!")
|
log.Print("bye!")
|
||||||
|
|
||||||
if err := app.nav.writeMarks(); err != nil {
|
if err := app.nav.writeMarks(); err != nil {
|
||||||
@@ -165,10 +198,42 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
case n := <-app.nav.copyBytesChan:
|
||||||
|
app.nav.copyBytes += n
|
||||||
|
// n is usually 4096B so update roughly per 4096B x 1024 = 4MB copied
|
||||||
|
if app.nav.copyUpdate++; app.nav.copyUpdate >= 1024 {
|
||||||
|
app.nav.copyUpdate = 0
|
||||||
|
app.ui.draw(app.nav)
|
||||||
|
}
|
||||||
|
case n := <-app.nav.copyTotalChan:
|
||||||
|
app.nav.copyTotal += n
|
||||||
|
if n < 0 {
|
||||||
|
app.nav.copyBytes += n
|
||||||
|
}
|
||||||
|
if app.nav.copyTotal == 0 {
|
||||||
|
app.nav.copyUpdate = 0
|
||||||
|
}
|
||||||
|
app.ui.draw(app.nav)
|
||||||
|
case n := <-app.nav.moveCountChan:
|
||||||
|
app.nav.moveCount += n
|
||||||
|
if app.nav.moveUpdate++; app.nav.moveUpdate >= 1000 {
|
||||||
|
app.nav.moveUpdate = 0
|
||||||
|
app.ui.draw(app.nav)
|
||||||
|
}
|
||||||
|
case n := <-app.nav.moveTotalChan:
|
||||||
|
app.nav.moveTotal += n
|
||||||
|
if n < 0 {
|
||||||
|
app.nav.moveCount += n
|
||||||
|
}
|
||||||
|
if app.nav.moveTotal == 0 {
|
||||||
|
app.nav.moveUpdate = 0
|
||||||
|
}
|
||||||
|
app.ui.draw(app.nav)
|
||||||
case d := <-app.nav.dirChan:
|
case d := <-app.nav.dirChan:
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
if ok {
|
||||||
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
|
||||||
@@ -217,31 +282,15 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *app) exportVars() {
|
func (app *app) exportFiles() {
|
||||||
var envFile string
|
var currFile string
|
||||||
if f, err := app.nav.currFile(); err == nil {
|
if f, err := app.nav.currFile(); err == nil {
|
||||||
envFile = f.path
|
currFile = f.path
|
||||||
}
|
}
|
||||||
|
|
||||||
selections := app.nav.currSelections()
|
currSelections := app.nav.currSelections()
|
||||||
|
|
||||||
envFiles := strings.Join(selections, gOpts.filesep)
|
exportFiles(currFile, currSelections)
|
||||||
|
|
||||||
os.Setenv("f", envFile)
|
|
||||||
os.Setenv("fs", envFiles)
|
|
||||||
|
|
||||||
if len(selections) == 0 {
|
|
||||||
os.Setenv("fx", envFile)
|
|
||||||
} else {
|
|
||||||
os.Setenv("fx", envFiles)
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Setenv("id", strconv.Itoa(gClientID))
|
|
||||||
|
|
||||||
os.Setenv("OPENER", envOpener)
|
|
||||||
os.Setenv("EDITOR", envEditor)
|
|
||||||
os.Setenv("PAGER", envPager)
|
|
||||||
os.Setenv("SHELL", envShell)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitKey() error {
|
func waitKey() error {
|
||||||
@@ -266,7 +315,7 @@ func waitKey() error {
|
|||||||
// ! 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.exportFiles()
|
||||||
|
|
||||||
cmd := shellCommand(s, args)
|
cmd := shellCommand(s, args)
|
||||||
|
|
||||||
@@ -303,13 +352,13 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("running shell: %s", err)
|
app.ui.echoerrf("running shell: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "!":
|
case "!":
|
||||||
if err := waitKey(); err != nil {
|
if err := waitKey(); err != nil {
|
||||||
app.ui.printf("waiting key: %s", err)
|
app.ui.echoerrf("waiting key: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,12 +367,12 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "%":
|
case "%":
|
||||||
go func() {
|
|
||||||
app.cmd = cmd
|
app.cmd = cmd
|
||||||
app.cmdOutBuf = nil
|
app.cmdOutBuf = nil
|
||||||
app.ui.msg = ""
|
app.ui.msg = ""
|
||||||
app.ui.cmdPrefix = ">"
|
app.ui.cmdPrefix = ">"
|
||||||
|
|
||||||
|
go func() {
|
||||||
reader := bufio.NewReader(out)
|
reader := bufio.NewReader(out)
|
||||||
for {
|
for {
|
||||||
b, err := reader.ReadByte()
|
b, err := reader.ReadByte()
|
||||||
@@ -342,7 +391,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,11 +8,19 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
|
if err := termbox.Init(); err != nil {
|
||||||
|
log.Fatalf("initializing termbox: %s", err)
|
||||||
|
}
|
||||||
|
defer termbox.Close()
|
||||||
|
|
||||||
|
setColorMode()
|
||||||
|
|
||||||
f, err := os.Create(gLogPath)
|
f, err := os.Create(gLogPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -23,27 +31,14 @@ func run() {
|
|||||||
|
|
||||||
log.Print("hi!")
|
log.Print("hi!")
|
||||||
|
|
||||||
if err := termbox.Init(); err != nil {
|
|
||||||
log.Fatalf("initializing termbox: %s", err)
|
|
||||||
}
|
|
||||||
defer termbox.Close()
|
|
||||||
|
|
||||||
termbox.SetOutputMode(termbox.Output256)
|
|
||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
|
||||||
for _, path := range gConfigPaths {
|
|
||||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
||||||
app.readFile(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.nav.readMarks(); err != nil {
|
if err := app.nav.readMarks(); err != nil {
|
||||||
app.ui.printf("reading marks file: %s", err)
|
app.ui.echoerrf("reading marks file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.readHistory(); err != nil {
|
if err := app.readHistory(); err != nil {
|
||||||
app.ui.printf("reading history file: %s", err)
|
app.ui.echoerrf("reading history file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.loop()
|
app.loop()
|
||||||
@@ -53,10 +48,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)
|
||||||
@@ -141,7 +140,7 @@ func loadFiles() (list []string, cp bool, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendRemote(cmd string) error {
|
func remote(cmd string) error {
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dialing to send server: %s", err)
|
return fmt.Errorf("dialing to send server: %s", err)
|
||||||
|
|||||||
@@ -51,25 +51,25 @@ func parseColors() colorMap {
|
|||||||
return parseColorsBSD(env)
|
return parseColorsBSD(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
// default values from dircolors
|
// default values from dircolors with removed background colors
|
||||||
defaultColors := []string{
|
defaultColors := []string{
|
||||||
// "rs=0",
|
// "rs=0",
|
||||||
"di=01;34",
|
"di=01;34",
|
||||||
"ln=01;36",
|
"ln=01;36",
|
||||||
// "mh=00",
|
// "mh=00",
|
||||||
"pi=40;33",
|
"pi=33", // "pi=40;33",
|
||||||
"so=01;35",
|
"so=01;35",
|
||||||
"do=01;35",
|
"do=01;35",
|
||||||
"bd=40;33;01",
|
"bd=33;01", // "bd=40;33;01",
|
||||||
"cd=40;33;01",
|
"cd=33;01", // "cd=40;33;01",
|
||||||
"or=40;31;01",
|
"or=31;01", // "or=40;31;01",
|
||||||
// "mi=00",
|
// "mi=00",
|
||||||
"su=37;41",
|
"su=01;32", // "su=37;41",
|
||||||
"sg=30;43",
|
"sg=01;32", // "sg=30;43",
|
||||||
"ca=30;41",
|
// "ca=30;41",
|
||||||
"tw=30;42",
|
"tw=01;34", // "tw=30;42",
|
||||||
"ow=34;42",
|
"ow=01;34", // "ow=34;42",
|
||||||
"st=37;44",
|
"st=01;34", // "st=37;44",
|
||||||
"ex=01;32",
|
"ex=01;32",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+79
-1
@@ -31,6 +31,7 @@ var (
|
|||||||
"copy",
|
"copy",
|
||||||
"cut",
|
"cut",
|
||||||
"paste",
|
"paste",
|
||||||
|
"delete",
|
||||||
"clear",
|
"clear",
|
||||||
"draw",
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
@@ -41,6 +42,10 @@ var (
|
|||||||
"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",
|
||||||
@@ -49,6 +54,8 @@ var (
|
|||||||
"mark-load",
|
"mark-load",
|
||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
|
"echomsg",
|
||||||
|
"echoerr",
|
||||||
"cd",
|
"cd",
|
||||||
"select",
|
"select",
|
||||||
"source",
|
"source",
|
||||||
@@ -56,6 +63,12 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
gOptWords = []string{
|
gOptWords = []string{
|
||||||
|
"anchorfind",
|
||||||
|
"noanchorfind",
|
||||||
|
"anchorfind!",
|
||||||
|
"color256",
|
||||||
|
"nocolor256",
|
||||||
|
"color256!",
|
||||||
"dircounts",
|
"dircounts",
|
||||||
"nodircounts",
|
"nodircounts",
|
||||||
"dircounts!",
|
"dircounts!",
|
||||||
@@ -74,6 +87,12 @@ var (
|
|||||||
"ignorecase",
|
"ignorecase",
|
||||||
"noignorecase",
|
"noignorecase",
|
||||||
"ignorecase!",
|
"ignorecase!",
|
||||||
|
"ignoredia",
|
||||||
|
"noignoredia",
|
||||||
|
"ignoredia!",
|
||||||
|
"incsearch",
|
||||||
|
"noincsearch",
|
||||||
|
"incsearch!",
|
||||||
"preview",
|
"preview",
|
||||||
"nopreview",
|
"nopreview",
|
||||||
"preview!",
|
"preview!",
|
||||||
@@ -83,12 +102,23 @@ var (
|
|||||||
"smartcase",
|
"smartcase",
|
||||||
"nosmartcase",
|
"nosmartcase",
|
||||||
"smartcase!",
|
"smartcase!",
|
||||||
|
"smartdia",
|
||||||
|
"nosmartdia",
|
||||||
|
"smartdia!",
|
||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"number",
|
||||||
|
"nonumber",
|
||||||
|
"number!",
|
||||||
|
"relativenumber",
|
||||||
|
"norelativenumber",
|
||||||
|
"relativenumber!",
|
||||||
|
"findlen",
|
||||||
"period",
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
|
"errorfmt",
|
||||||
"filesep",
|
"filesep",
|
||||||
"ifs",
|
"ifs",
|
||||||
"previewer",
|
"previewer",
|
||||||
@@ -190,9 +220,10 @@ 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))
|
||||||
|
|
||||||
@@ -256,6 +287,15 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
words = append(words, c)
|
words = append(words, c)
|
||||||
}
|
}
|
||||||
sort.Strings(words)
|
sort.Strings(words)
|
||||||
|
j := 0
|
||||||
|
for i := 1; i < len(words); i++ {
|
||||||
|
if words[j] == words[i] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
words[i], words[j] = words[j], words[i]
|
||||||
|
}
|
||||||
|
words = words[:j+1]
|
||||||
matches, longest = matchWord(s, words)
|
matches, longest = matchWord(s, words)
|
||||||
longestAcc = []rune(longest)
|
longestAcc = []rune(longest)
|
||||||
case 2:
|
case 2:
|
||||||
@@ -282,6 +322,44 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
|
s := string(acc)
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(wd)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("reading directory: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var longest string
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
if !strings.HasPrefix(f.Name(), s) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
matches = append(matches, f.Name())
|
||||||
|
|
||||||
|
if longest != "" {
|
||||||
|
longest = matchLongest(longest, f.Name())
|
||||||
|
} else if s != "" {
|
||||||
|
longest = f.Name()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if longest == "" {
|
||||||
|
longest = s
|
||||||
|
}
|
||||||
|
|
||||||
|
longestAcc = []rune(longest)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||||
s := string(acc)
|
s := string(acc)
|
||||||
f := tokenize(s)
|
f := tokenize(s)
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func copySize(srcs []string) (int64, error) {
|
||||||
|
var total int64
|
||||||
|
|
||||||
|
for _, src := range srcs {
|
||||||
|
_, err := os.Stat(src)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return total, fmt.Errorf("src does not exist: %q", src)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("walk: %s", err)
|
||||||
|
}
|
||||||
|
total += info.Size()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return total, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyFile(src, dst string, info os.FileInfo, nums chan int64) error {
|
||||||
|
buf := make([]byte, 4096)
|
||||||
|
|
||||||
|
r, err := os.Open(src)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
|
||||||
|
w, err := os.Create(dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
n, err := r.Read(buf)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
w.Close()
|
||||||
|
os.Remove(dst)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if n == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := w.Write(buf[:n]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
nums <- int64(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.Close(); err != nil {
|
||||||
|
os.Remove(dst)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Chmod(dst, info.Mode()); err != nil {
|
||||||
|
os.Remove(dst)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
||||||
|
nums = make(chan int64, 1024)
|
||||||
|
errs = make(chan error, 1024)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for _, src := range srcs {
|
||||||
|
dst := filepath.Join(dstDir, filepath.Base(src))
|
||||||
|
|
||||||
|
_, err := os.Stat(dst)
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
var newPath string
|
||||||
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
|
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||||
|
_, err = os.Stat(newPath)
|
||||||
|
}
|
||||||
|
dst = newPath
|
||||||
|
}
|
||||||
|
|
||||||
|
filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
errs <- fmt.Errorf("walk: %s", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
rel, err := filepath.Rel(src, path)
|
||||||
|
if err != nil {
|
||||||
|
errs <- fmt.Errorf("relative: %s", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
newPath := filepath.Join(dst, rel)
|
||||||
|
if info.IsDir() {
|
||||||
|
if err := os.MkdirAll(newPath, info.Mode()); err != nil {
|
||||||
|
errs <- fmt.Errorf("mkdir: %s", err)
|
||||||
|
}
|
||||||
|
nums <- info.Size()
|
||||||
|
} else {
|
||||||
|
if err := copyFile(path, newPath, info, nums); err != nil {
|
||||||
|
errs <- fmt.Errorf("copy: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
close(errs)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nums, errs
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var normMap map[rune]rune
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
normMap = make(map[rune]rune)
|
||||||
|
|
||||||
|
// (not only) european
|
||||||
|
appendTransliterate(
|
||||||
|
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||||
|
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Vietnamese
|
||||||
|
appendTransliterate(
|
||||||
|
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||||
|
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendTransliterate(base, norm string, uppercase bool) {
|
||||||
|
normRunes := []rune(norm)
|
||||||
|
baseRunes := []rune(base)
|
||||||
|
|
||||||
|
lenNorm := len(normRunes)
|
||||||
|
lenBase := len(baseRunes)
|
||||||
|
if lenNorm != lenBase {
|
||||||
|
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, baseRune := range baseRunes {
|
||||||
|
normMap[baseRune] = normRunes[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
if uppercase {
|
||||||
|
upperBase := strings.ToUpper(base)
|
||||||
|
upperNorm := strings.ToUpper(norm)
|
||||||
|
normRune := []rune(upperNorm)
|
||||||
|
for i, baseRune := range []rune(upperBase) {
|
||||||
|
normMap[baseRune] = normRune[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove diacritics and make lowercase.
|
||||||
|
func removeDiacritics(baseString string) string {
|
||||||
|
var normalizedRunes []rune
|
||||||
|
for _, baseRune := range []rune(baseString) {
|
||||||
|
if normRune, ok := normMap[baseRune]; ok {
|
||||||
|
normalizedRunes = append(normalizedRunes, normRune)
|
||||||
|
} else {
|
||||||
|
normalizedRunes = append(normalizedRunes, baseRune)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(normalizedRunes)
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// typical czech test sentence ;-)
|
||||||
|
const baseTestString = "Příliš žluťoučký kůň příšerně úpěl ďábelské ódy"
|
||||||
|
|
||||||
|
func TestRemoveDiacritics(t *testing.T) {
|
||||||
|
testStr := baseTestString
|
||||||
|
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
// other accents (non comlete, but all I founded)
|
||||||
|
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
|
||||||
|
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "ÁÉÍÓÚÝČĎĚŇŘŠŤŽŮÅØĈĜĤĴŜŬŠŽÕÄÖÜÀÂÇÉÈÊËÎÏÔÙÛÜŸŽŠČĆĐÁÉÍÓÚĄĘĖĮŲŪČŠŽĀĒĪŪČŠŽĻĶŅĢÁÉÍÓÚÖÜŐŰÄÖÜËÏĄĆĘŁŃÓŚŹŻÁÀÃÂÇÉÊÍÓÕÔĂÂÎȘȚÁÄČĎÉÍĹĽŇÓÔŔŠŤÚÝŽÁÉÍÑÓÚÜÅÄÖÂÇÎŞÛĞĂÂĐÊÔƠƯÁÀÃẢẠ"
|
||||||
|
expStr = "AEIOUYCDENRSTZUAOCGHJSUSZOAOUAACEEEEIIOUUUYZSCCDAEIOUAEEIUUCSZAEIUCSZLKNGAEIOUOUOUAOUEIACELNOSZZAAAACEEIOOOAAISTAACDEILLNOORSTUYZAEINOUUAAOACISUGAADEOOUAAAAA"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ"
|
||||||
|
expStr = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "ÁẠÀẢÃĂẮẶẰẲẴÂẤẬẦẨẪÉẸÈẺẼÊẾỆỀỂỄÍỊÌỈĨÓỌÒỎÕÔỐỘỒỔỖƠỚỢỜỞỠÚỤÙỦŨƯỨỰỪỬỮÝỴỲỶỸĐ"
|
||||||
|
expStr = "AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkRemoveDiacritics(testStr string, expStr string, t *testing.T) {
|
||||||
|
resultStr := removeDiacritics(testStr)
|
||||||
|
if resultStr != expStr {
|
||||||
|
t.Errorf("at input '%v' expected '%v' but got '%v'", testStr, expStr, resultStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSearchSettings(t *testing.T) {
|
||||||
|
runSearch(t, true, false, true, true, "Veřejný", "vere", true)
|
||||||
|
|
||||||
|
runSearch(t, true, false, true, false, baseTestString, "Zlutoucky", true)
|
||||||
|
runSearch(t, true, false, true, false, baseTestString, "zlutoucky", true)
|
||||||
|
runSearch(t, true, true, true, false, baseTestString, "Zlutoucky", false)
|
||||||
|
runSearch(t, true, true, true, true, baseTestString, "zlutoucky", true)
|
||||||
|
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "žlutoucky", true)
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "Žlutoucky", false)
|
||||||
|
|
||||||
|
runSearch(t, false, false, true, true, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, false, false, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, false, false, baseTestString, "zlutoucky", false)
|
||||||
|
runSearch(t, false, false, true, true, baseTestString, "zlutoucky", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacritics bool, base, pattern string, expected bool) {
|
||||||
|
gOpts.ignorecase = ignorecase
|
||||||
|
gOpts.smartcase = smartcase
|
||||||
|
gOpts.ignoredia = ignorediacritics
|
||||||
|
gOpts.smartdia = smartdiacritics
|
||||||
|
matched, _ := searchMatch(base, pattern)
|
||||||
|
if matched != expected {
|
||||||
|
t.Errorf("False search for" +
|
||||||
|
" ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " +
|
||||||
|
" smartcase = " + strconv.FormatBool(gOpts.smartcase) + ", " +
|
||||||
|
" ignoredia = " + strconv.FormatBool(gOpts.ignoredia) + ", " +
|
||||||
|
" smartdia = " + strconv.FormatBool(gOpts.smartdia) + ", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,6 +41,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -52,12 +56,15 @@ The following commands are provided by lf without default keybindings:
|
|||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronizes copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo print arguments to the message line
|
||||||
cd changes working directory to its argument
|
echomsg same as echo but logging
|
||||||
select changes current file selection to its argument
|
echoerr same as echomsg but red color
|
||||||
source reads the configuration file in its argument
|
cd change working directory to the argument
|
||||||
push simulate key pushes given in its argument
|
select change current file selection to the argument
|
||||||
|
source read the configuration file in the argument
|
||||||
|
push simulate key pushes given in the argument
|
||||||
|
delete remove the current file or selected file(s)
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
@@ -89,19 +96,28 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
|
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
ifs string (default '') (not exported if empty)
|
ifs string (default '') (not exported if empty)
|
||||||
previewer string (default '') (not filtered if empty)
|
previewer string (default '') (not filtered if empty)
|
||||||
@@ -120,6 +136,10 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or selected 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
|
The following default values are set to the environmental variables on unix
|
||||||
when they are not set or empty:
|
when they are not set or empty:
|
||||||
|
|
||||||
@@ -491,50 +511,102 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
# 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 its own builtin copy and move operations by default. These are
|
||||||
this purpose, when you 'copy' a file, it doesn't actually copy the file on the
|
implemented as asynchronous operations and progress is shown in the bottom
|
||||||
disk, but only records its name to memory. The actual file operation takes
|
ruler. These commands do not overwrite existing files or directories with the
|
||||||
place when you 'paste' in which case the 'cp' command is used. Similarly the
|
same name. Instead, a suffix that is compatible with '--backup=numbered' option
|
||||||
'mv' command is used for 'cut' followed by 'paste'.
|
in GNU cp is added to the new files or directories. Only file modes are
|
||||||
|
preserved and all other attributes are ignored including ownership, timestamps,
|
||||||
|
context, links, and xattr. Special files such as character and block devices,
|
||||||
|
named pipes, and sockets are skipped and links are followed. Moving is
|
||||||
|
performed using the rename operation of the underlying OS. This can fail to
|
||||||
|
move files between different partitions when it needs to copy files. For these
|
||||||
|
cases, users are expected to explicitly copy files and then delete the old ones
|
||||||
|
manually. Operation errors are shown in the message line as well as the log
|
||||||
|
file and they do not preemptively finish the corresponding file operation.
|
||||||
|
|
||||||
You can customize these operations by defining a 'paste' command. This is a
|
File operations can be performed on the current selected file or alternatively
|
||||||
special command that is called when it is defined instead of the builtin
|
on multiple files by selecting them first. When you 'copy' a file, lf doesn't
|
||||||
implementation. The default behavior is similar to the following command:
|
actually copy the file on the disk, but only records its name to memory. The
|
||||||
|
actual file copying takes place when you 'paste'. Similarly 'paste' after a
|
||||||
|
'cut' operation moves the file.
|
||||||
|
|
||||||
|
You can customize copy and move operations by defining a 'paste' command. This
|
||||||
|
is a special command that is called when it is defined instead of the builtin
|
||||||
|
implementation. You can use the following example as a starting point:
|
||||||
|
|
||||||
cmd paste %{{
|
cmd paste %{{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
cp -R -n $list .
|
cp -R $list .
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv $list .
|
||||||
fi
|
fi
|
||||||
lf -remote 'send load'
|
lf -remote 'send load'
|
||||||
lf -remote 'send clear'
|
lf -remote 'send clear'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
Some useful things to be considered are to use the backup ('--backup') and/or
|
||||||
commands if they support it (i.e. GNU implementation), change the command type
|
preserve attributes ('-a') options with 'cp' and 'mv' commands if they support
|
||||||
to asynchronous, or use 'rsync' command with progress bar option for copying
|
it (i.e. GNU implementation), change the command type to asynchronous, or use
|
||||||
and feed the progress to the client periodically with remote 'echo' calls.
|
'rsync' command with progress bar option for copying and feed the progress to
|
||||||
|
the client periodically with remote 'echo' calls.
|
||||||
|
|
||||||
By default, lf does not provide an actual file deletion command to protect new
|
By default, lf does not assign 'delete' command to a key to protect new users.
|
||||||
users. You can define such a command and optionally assign a key if you like.
|
You can customize file deletion by defining a 'delete' command. You can also
|
||||||
An example command to move selected files to a trash folder and remove files
|
assign a key to this command if you like. An example command to move selected
|
||||||
completely are provided in the example configuration file.
|
files to a trash folder and remove files completely after a prompt are provided
|
||||||
|
in the example configuration file.
|
||||||
|
|
||||||
|
Searching Files
|
||||||
|
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current
|
||||||
|
directory. Searching is the traditional method to move the selection to a file
|
||||||
|
matching a given pattern. Finding is an alternative way to search for a pattern
|
||||||
|
possibly using fewer keystrokes.
|
||||||
|
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||||
|
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||||
|
(default 'N'). You can enable 'globsearch' option to match with a glob pattern.
|
||||||
|
Globbing supports '*' to match any sequence, '?' to match any character, and
|
||||||
|
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||||
|
'incsearch' option to jump to the current match at each keystroke while typing.
|
||||||
|
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||||
|
'cmd-escape' to cancel the search.
|
||||||
|
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||||
|
position in the filename instead of the beginning. You can set the number of
|
||||||
|
keys to match using 'findlen' option. If you set this value to zero, then the
|
||||||
|
the keys are read until there is only a single match. Default values of these
|
||||||
|
two options are set to jump to the first file with the given initial.
|
||||||
|
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||||
|
option to prevent searches to wrap around at the end of the file list. You can
|
||||||
|
disable 'ignorecase' option to match cases in the pattern and the filename.
|
||||||
|
This option is already automatically overridden if the pattern contains upper
|
||||||
|
case characters. You can disable 'smartcase' option to disable this behavior.
|
||||||
|
Two similar options 'ignoredia' and 'smartdia' are provided to control matching
|
||||||
|
diacritics in latin letters.
|
||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can define a an 'open' command (default 'l') to configure file opening.
|
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||||
This command is only called when the current file is not a directory, otherwise
|
file opening. This command is only called when the current file is not a
|
||||||
the directory is entered instead. You can define it just as you would define
|
directory, otherwise the directory is entered instead. You can define it just
|
||||||
any other command:
|
as you would define any other command:
|
||||||
|
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
@@ -620,6 +692,13 @@ 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.
|
default colorscheme. Default lf colors are taken from GNU dircolors defaults.
|
||||||
These defaults use 8 basic colors and bold attribute.
|
These defaults use 8 basic colors and bold attribute.
|
||||||
|
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr 3-bit
|
||||||
|
color escapes (e.g. '\033[34m'). If you want to use 256 colors, you need to
|
||||||
|
enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g.
|
||||||
|
'\033[38;5;4m'). This option is intended to eliminate differences between
|
||||||
|
default colors used by ls and lf since terminals may render 3-bit and 8-bit
|
||||||
|
escapes differently even for the same color.
|
||||||
|
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different
|
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
|
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 pick up those colors automatically. Depending on your terminal, you
|
||||||
@@ -632,5 +711,10 @@ fine grained customization. This is useful to change colors used for different
|
|||||||
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and
|
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
|
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.
|
combine this second method with the first method for best results.
|
||||||
|
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to match
|
||||||
|
the rest of the colors. Colors of the prompt line can be configured using the
|
||||||
|
'promptfmt' option which can include hardcoded colors as ansi escapes. See the
|
||||||
|
default value of this option to have an idea about how to color this line.
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
+121
-34
@@ -44,6 +44,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -55,12 +59,15 @@ The following commands are provided by lf without default keybindings:
|
|||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronizes copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo print arguments to the message line
|
||||||
cd changes working directory to its argument
|
echomsg same as echo but logging
|
||||||
select changes current file selection to its argument
|
echoerr same as echomsg but red color
|
||||||
source reads the configuration file in its argument
|
cd change working directory to the argument
|
||||||
push simulate key pushes given in its argument
|
select change current file selection to the argument
|
||||||
|
source read the configuration file in the argument
|
||||||
|
push simulate key pushes given in the argument
|
||||||
|
delete remove the current file or selected file(s)
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
@@ -92,29 +99,38 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
|
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
ifs string (default '') (not exported if empty)
|
ifs string (default ”) (not exported if empty)
|
||||||
previewer string (default '') (not filtered if empty)
|
previewer string (default ”) (not filtered if empty)
|
||||||
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
||||||
shell string (default 'sh')
|
shell string (default 'sh')
|
||||||
sortby string (default 'natural')
|
sortby string (default 'natural')
|
||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||||
ratios string (default '1:2:3')
|
ratios string (default '1:2:3')
|
||||||
info string (default '')
|
info string (default ”)
|
||||||
shellopts string (default '')
|
shellopts string (default ”)
|
||||||
|
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
@@ -123,6 +139,10 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or selected 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
|
The following default values are set to the environmental variables on unix
|
||||||
when they are not set or empty:
|
when they are not set or empty:
|
||||||
|
|
||||||
@@ -512,53 +532,107 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
# 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 its own builtin copy and move operations by default. These are
|
||||||
this purpose, when you 'copy' a file, it doesn't actually copy the file on
|
implemented as asynchronous operations and progress is shown in the bottom
|
||||||
the disk, but only records its name to memory. The actual file operation
|
ruler. These commands do not overwrite existing files or directories with
|
||||||
takes place when you 'paste' in which case the 'cp' command is used.
|
the same name. Instead, a suffix that is compatible with '--backup=numbered'
|
||||||
Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
option in GNU cp is added to the new files or directories. Only file modes
|
||||||
|
are preserved and all other attributes are ignored including ownership,
|
||||||
|
timestamps, context, links, and xattr. Special files such as character and
|
||||||
|
block devices, named pipes, and sockets are skipped and links are followed.
|
||||||
|
Moving is performed using the rename operation of the underlying OS. This
|
||||||
|
can fail to move files between different partitions when it needs to copy
|
||||||
|
files. For these cases, users are expected to explicitly copy files and then
|
||||||
|
delete the old ones manually. Operation errors are shown in the message line
|
||||||
|
as well as the log file and they do not preemptively finish the
|
||||||
|
corresponding file operation.
|
||||||
|
|
||||||
You can customize these operations by defining a 'paste' command. This is a
|
File operations can be performed on the current selected file or
|
||||||
special command that is called when it is defined instead of the builtin
|
alternatively on multiple files by selecting them first. When you 'copy' a
|
||||||
implementation. The default behavior is similar to the following command:
|
file, lf doesn't actually copy the file on the disk, but only records its
|
||||||
|
name to memory. The actual file copying takes place when you 'paste'.
|
||||||
|
Similarly 'paste' after a 'cut' operation moves the file.
|
||||||
|
|
||||||
|
You can customize copy and move operations by defining a 'paste' command.
|
||||||
|
This is a special command that is called when it is defined instead of the
|
||||||
|
builtin implementation. You can use the following example as a starting
|
||||||
|
point:
|
||||||
|
|
||||||
cmd paste %{{
|
cmd paste %{{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
cp -R -n $list .
|
cp -R $list .
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv $list .
|
||||||
fi
|
fi
|
||||||
lf -remote 'send load'
|
lf -remote 'send load'
|
||||||
lf -remote 'send clear'
|
lf -remote 'send clear'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and
|
Some useful things to be considered are to use the backup ('--backup')
|
||||||
'mv' commands if they support it (i.e. GNU implementation), change the
|
and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if
|
||||||
command type to asynchronous, or use 'rsync' command with progress bar
|
they support it (i.e. GNU implementation), change the command type to
|
||||||
option for copying and feed the progress to the client periodically with
|
asynchronous, or use 'rsync' command with progress bar option for copying
|
||||||
remote 'echo' calls.
|
and feed the progress to the client periodically with remote 'echo' calls.
|
||||||
|
|
||||||
By default, lf does not provide an actual file deletion command to protect
|
By default, lf does not assign 'delete' command to a key to protect new
|
||||||
new users. You can define such a command and optionally assign a key if you
|
users. You can customize file deletion by defining a 'delete' command. You
|
||||||
like. An example command to move selected files to a trash folder and remove
|
can also assign a key to this command if you like. An example command to
|
||||||
files completely are provided in the example configuration file.
|
move selected files to a trash folder and remove files completely after a
|
||||||
|
prompt are provided in the example configuration file.
|
||||||
|
|
||||||
|
|
||||||
|
Searching Files
|
||||||
|
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current
|
||||||
|
directory. Searching is the traditional method to move the selection to a
|
||||||
|
file matching a given pattern. Finding is an alternative way to search for a
|
||||||
|
pattern possibly using fewer keystrokes.
|
||||||
|
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||||
|
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||||
|
(default 'N'). You can enable 'globsearch' option to match with a glob
|
||||||
|
pattern. Globbing supports '*' to match any sequence, '?' to match any
|
||||||
|
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||||
|
enable 'incsearch' option to jump to the current match at each keystroke
|
||||||
|
while typing. In this mode, you can either use 'cmd-enter' to accept the
|
||||||
|
search or use 'cmd-escape' to cancel the search.
|
||||||
|
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||||
|
position in the filename instead of the beginning. You can set the number of
|
||||||
|
keys to match using 'findlen' option. If you set this value to zero, then
|
||||||
|
the the keys are read until there is only a single match. Default values of
|
||||||
|
these two options are set to jump to the first file with the given initial.
|
||||||
|
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||||
|
option to prevent searches to wrap around at the end of the file list. You
|
||||||
|
can disable 'ignorecase' option to match cases in the pattern and the
|
||||||
|
filename. This option is already automatically overridden if the pattern
|
||||||
|
contains upper case characters. You can disable 'smartcase' option to
|
||||||
|
disable this behavior. Two similar options 'ignoredia' and 'smartdia' are
|
||||||
|
provided to control matching diacritics in latin letters.
|
||||||
|
|
||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can define a an 'open' command (default 'l') to configure file opening.
|
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||||
This command is only called when the current file is not a directory,
|
file opening. This command is only called when the current file is not a
|
||||||
otherwise the directory is entered instead. You can define it just as you
|
directory, otherwise the directory is entered instead. You can define it
|
||||||
would define any other command:
|
just as you would define any other command:
|
||||||
|
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
@@ -650,6 +724,13 @@ If both of these environment variables are not set, then lf fallbacks to its
|
|||||||
default colorscheme. Default lf colors are taken from GNU dircolors
|
default colorscheme. Default lf colors are taken from GNU dircolors
|
||||||
defaults. These defaults use 8 basic colors and bold attribute.
|
defaults. These defaults use 8 basic colors and bold attribute.
|
||||||
|
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr
|
||||||
|
3-bit color escapes (e.g. '\033[34m'). If you want to use 256 colors, you
|
||||||
|
need to enable 'color256' option which then makes lf use sgr 8-bit color
|
||||||
|
escapes (e.g. '\033[38;5;4m'). This option is intended to eliminate
|
||||||
|
differences between default colors used by ls and lf since terminals may
|
||||||
|
render 3-bit and 8-bit escapes differently even for the same color.
|
||||||
|
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different
|
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
|
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 pick up those colors automatically. Depending on your terminal, you
|
||||||
@@ -663,4 +744,10 @@ 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
|
'$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
|
the system. You can combine this second method with the first method for
|
||||||
best results.
|
best results.
|
||||||
|
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to
|
||||||
|
match the rest of the colors. Colors of the prompt line can be configured
|
||||||
|
using the 'promptfmt' option which can include hardcoded colors as ansi
|
||||||
|
escapes. See the default value of this option to have an idea about how to
|
||||||
|
color this line.
|
||||||
`
|
`
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Autocompletion for fish shell.
|
||||||
|
#
|
||||||
|
# You may put this file to a directory in $fish_complete_path variable:
|
||||||
|
#
|
||||||
|
# mkdir -p ~/.config/fish/completions
|
||||||
|
# ln -s "/path/to/lf.fish" ~/.config/fish/completions
|
||||||
|
#
|
||||||
|
|
||||||
|
complete -c lf -o command -r -d 'command to execute on client initialization'
|
||||||
|
complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'
|
||||||
|
complete -c lf -o doc -d 'show documentation'
|
||||||
|
complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'
|
||||||
|
complete -c lf -o memprofile -r -d 'path to the file to write the memory profile'
|
||||||
|
complete -c lf -o remote -x -d 'send remote command to server'
|
||||||
|
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
|
||||||
|
complete -c lf -o server -d 'start server (automatic)'
|
||||||
|
complete -c lf -o version -d 'show version'
|
||||||
|
complete -c lf -o help -d 'show help'
|
||||||
+13
-9
@@ -47,20 +47,24 @@ cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
|||||||
map r push :rename<space>
|
map r push :rename<space>
|
||||||
|
|
||||||
# make sure trash folder exists
|
# make sure trash folder exists
|
||||||
%mkdir -p ~/.trash
|
# %mkdir -p ~/.trash
|
||||||
|
|
||||||
# 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 %set -f; mv $fx ~/.trash
|
cmd trash %set -f; mv $fx ~/.trash
|
||||||
|
|
||||||
# delete current file or selected files (prompting)
|
# define a custom 'delete' command
|
||||||
cmd delete ${{
|
# cmd delete ${{
|
||||||
set -f
|
# set -f
|
||||||
printf "$fx\n"
|
# printf "$fx\n"
|
||||||
printf "delete?[y/n]"
|
# printf "delete?[y/n]"
|
||||||
read ans
|
# read ans
|
||||||
[ $ans = "y" ] && rm -rf $fx
|
# [ $ans = "y" ] && rm -rf $fx
|
||||||
}}
|
# }}
|
||||||
|
|
||||||
|
# use '<delete>' key for either 'trash' or 'delete' command
|
||||||
|
# map <delete> trash
|
||||||
|
# map <delete> delete
|
||||||
|
|
||||||
# extract the current file with the right command
|
# extract the current file with the right command
|
||||||
# (xkcd link: https://xkcd.com/1168/)
|
# (xkcd link: https://xkcd.com/1168/)
|
||||||
|
|||||||
@@ -14,6 +14,27 @@ import (
|
|||||||
|
|
||||||
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 "color256":
|
||||||
|
gOpts.color256 = true
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
|
case "nocolor256":
|
||||||
|
gOpts.color256 = false
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
|
case "color256!":
|
||||||
|
gOpts.color256 = !gOpts.color256
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
case "dircounts":
|
case "dircounts":
|
||||||
gOpts.dircounts = true
|
gOpts.dircounts = true
|
||||||
case "nodircounts":
|
case "nodircounts":
|
||||||
@@ -74,6 +95,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.ignorecase = false
|
gOpts.ignorecase = false
|
||||||
case "ignorecase!":
|
case "ignorecase!":
|
||||||
gOpts.ignorecase = !gOpts.ignorecase
|
gOpts.ignorecase = !gOpts.ignorecase
|
||||||
|
case "ignoredia":
|
||||||
|
gOpts.ignoredia = true
|
||||||
|
case "noignoredia":
|
||||||
|
gOpts.ignoredia = false
|
||||||
|
case "ignoredia!":
|
||||||
|
gOpts.ignoredia = !gOpts.ignoredia
|
||||||
|
case "incsearch":
|
||||||
|
gOpts.incsearch = true
|
||||||
|
case "noincsearch":
|
||||||
|
gOpts.incsearch = false
|
||||||
|
case "incsearch!":
|
||||||
|
gOpts.incsearch = !gOpts.incsearch
|
||||||
case "preview":
|
case "preview":
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
case "nopreview":
|
case "nopreview":
|
||||||
@@ -98,20 +131,49 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.smartcase = false
|
gOpts.smartcase = false
|
||||||
case "smartcase!":
|
case "smartcase!":
|
||||||
gOpts.smartcase = !gOpts.smartcase
|
gOpts.smartcase = !gOpts.smartcase
|
||||||
|
case "smartdia":
|
||||||
|
gOpts.smartdia = true
|
||||||
|
case "nosmartdia":
|
||||||
|
gOpts.smartdia = false
|
||||||
|
case "smartdia!":
|
||||||
|
gOpts.smartdia = !gOpts.smartdia
|
||||||
case "wrapscan":
|
case "wrapscan":
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
case "nowrapscan":
|
case "nowrapscan":
|
||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.wrapscan
|
gOpts.wrapscan = !gOpts.wrapscan
|
||||||
case "period":
|
case "number":
|
||||||
|
gOpts.number = true
|
||||||
|
case "nonumber":
|
||||||
|
gOpts.number = false
|
||||||
|
case "number!":
|
||||||
|
gOpts.number = !gOpts.number
|
||||||
|
case "relativenumber":
|
||||||
|
gOpts.relativenumber = true
|
||||||
|
case "norelativenumber":
|
||||||
|
gOpts.relativenumber = false
|
||||||
|
case "relativenumber!":
|
||||||
|
gOpts.relativenumber = !gOpts.relativenumber
|
||||||
|
case "findlen":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("period: %s", err)
|
app.ui.echoerrf("findlen: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
app.ui.print("period: value should be a non-negative number")
|
app.ui.echoerr("findlen: value should be a non-negative number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gOpts.findlen = n
|
||||||
|
case "period":
|
||||||
|
n, err := strconv.Atoi(e.val)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.echoerrf("period: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n < 0 {
|
||||||
|
app.ui.echoerr("period: value should be a non-negative number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.period = n
|
gOpts.period = n
|
||||||
@@ -124,25 +186,27 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "scrolloff":
|
case "scrolloff":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("scrolloff: %s", err)
|
app.ui.echoerrf("scrolloff: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
app.ui.print("scrolloff: value should be a non-negative number")
|
app.ui.echoerr("scrolloff: value should be a non-negative number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.scrolloff = n
|
gOpts.scrolloff = n
|
||||||
case "tabstop":
|
case "tabstop":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("tabstop: %s", err)
|
app.ui.echoerrf("tabstop: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
app.ui.print("tabstop: value should be a positive number")
|
app.ui.echoerr("tabstop: value should be a positive number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.tabstop = n
|
gOpts.tabstop = n
|
||||||
|
case "errorfmt":
|
||||||
|
gOpts.errorfmt = e.val
|
||||||
case "filesep":
|
case "filesep":
|
||||||
gOpts.filesep = e.val
|
gOpts.filesep = e.val
|
||||||
case "ifs":
|
case "ifs":
|
||||||
@@ -155,7 +219,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.shell = e.val
|
gOpts.shell = e.val
|
||||||
case "sortby":
|
case "sortby":
|
||||||
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
|
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
|
||||||
app.ui.print("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch e.val {
|
switch e.val {
|
||||||
@@ -178,17 +242,17 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
for _, s := range toks {
|
for _, s := range toks {
|
||||||
n, err := strconv.Atoi(s)
|
n, err := strconv.Atoi(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("ratios: %s", err)
|
app.ui.echoerrf("ratios: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
app.ui.print("ratios: value should be a positive number")
|
app.ui.echoerr("ratios: value should be a positive number")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rats = append(rats, n)
|
rats = append(rats, n)
|
||||||
}
|
}
|
||||||
if gOpts.preview && len(rats) < 2 {
|
if gOpts.preview && len(rats) < 2 {
|
||||||
app.ui.print("ratios: should consist of at least two numbers when 'preview' is enabled")
|
app.ui.echoerr("ratios: should consist of at least two numbers when 'preview' is enabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gOpts.ratios = rats
|
gOpts.ratios = rats
|
||||||
@@ -198,7 +262,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
toks := strings.Split(e.val, ":")
|
toks := strings.Split(e.val, ":")
|
||||||
for _, s := range toks {
|
for _, s := range toks {
|
||||||
if s != "" && s != "size" && s != "time" {
|
if s != "" && s != "size" && s != "time" {
|
||||||
app.ui.print("info: should consist of 'size' or 'time' separated with colon")
|
app.ui.echoerr("info: should consist of 'size' or 'time' separated with colon")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +270,7 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "shellopts":
|
case "shellopts":
|
||||||
gOpts.shellopts = strings.Split(e.val, ":")
|
gOpts.shellopts = strings.Split(e.val, ":")
|
||||||
default:
|
default:
|
||||||
app.ui.printf("unknown option: %s", e.opt)
|
app.ui.echoerrf("unknown option: %s", e.opt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,6 +317,181 @@ func splitKeys(s string) (keys []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func update(app *app) {
|
||||||
|
switch {
|
||||||
|
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
||||||
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
if app.nav.searchBack {
|
||||||
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchNext(); err != nil {
|
||||||
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case gOpts.incsearch && app.ui.cmdPrefix == "?":
|
||||||
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
if app.nav.searchBack {
|
||||||
|
if err := app.nav.searchNext(); err != nil {
|
||||||
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func insert(app *app, arg string) {
|
||||||
|
switch {
|
||||||
|
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
update(app)
|
||||||
|
case app.ui.cmdPrefix == "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.echoerrf("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.echoerrf("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 app.ui.cmdPrefix == "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.echoerrf("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.echoerrf("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 app.ui.cmdPrefix == "delete?[y/N]: ":
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
|
||||||
|
if arg == "y" {
|
||||||
|
if err := app.nav.del(); err != nil {
|
||||||
|
app.ui.echoerrf("delete: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.nav.unselect()
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("delete: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case app.ui.cmdPrefix == "mark-save: ":
|
||||||
|
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 app.ui.cmdPrefix == "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.echoerr("mark-load: no such mark")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.cd(path); err != nil {
|
||||||
|
app.ui.echoerrf("%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":
|
||||||
@@ -282,7 +521,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "updir":
|
case "updir":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if err := app.nav.updir(); err != nil {
|
if err := app.nav.updir(); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,14 +530,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "open":
|
case "open":
|
||||||
curr, err := app.nav.currFile()
|
curr, err := app.nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("opening: %s", err)
|
app.ui.echoerrf("opening: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if curr.IsDir() {
|
if curr.IsDir() {
|
||||||
err := app.nav.open()
|
err := app.nav.open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("opening directory: %s", err)
|
app.ui.echoerrf("opening directory: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
@@ -315,11 +554,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
if len(app.nav.selections) != 0 {
|
if list, err := app.nav.currFileOrSelections(); err == nil {
|
||||||
selections := app.nav.currSelections()
|
path = strings.Join(list, "\n")
|
||||||
path = strings.Join(selections, "\n")
|
|
||||||
} else if curr, err := app.nav.currFile(); err == nil {
|
|
||||||
path = curr.path
|
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -359,42 +595,50 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
case "copy":
|
case "copy":
|
||||||
if err := app.nav.save(true); err != nil {
|
if err := app.nav.save(true); err != nil {
|
||||||
app.ui.printf("copy: %s", err)
|
app.ui.echoerrf("copy: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.printf("copy: %s", err)
|
app.ui.echoerrf("copy: %s", err)
|
||||||
}
|
}
|
||||||
case "cut":
|
case "cut":
|
||||||
if err := app.nav.save(false); err != nil {
|
if err := app.nav.save(false); err != nil {
|
||||||
app.ui.printf("cut: %s", err)
|
app.ui.echoerrf("cut: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.printf("cut: %s", err)
|
app.ui.echoerrf("cut: %s", err)
|
||||||
}
|
}
|
||||||
case "paste":
|
case "paste":
|
||||||
if cmd, ok := gOpts.cmds["paste"]; ok {
|
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
} else if err := app.nav.paste(); err != nil {
|
} else if err := app.nav.paste(app.ui); err != nil {
|
||||||
app.ui.printf("paste: %s", err)
|
app.ui.echoerrf("paste: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := sendRemote("send load"); err != nil {
|
case "delete":
|
||||||
app.ui.printf("paste: %s", err)
|
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||||
|
cmd.eval(app, e.args)
|
||||||
|
app.nav.unselect()
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("delete: %s", err)
|
||||||
}
|
}
|
||||||
if err := sendRemote("send sync"); err != nil {
|
} else {
|
||||||
app.ui.printf("paste: %s", err)
|
if _, err := app.nav.currFileOrSelections(); err != nil {
|
||||||
|
app.ui.echoerrf("delete: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdPrefix = "delete?[y/N]: "
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
app.ui.printf("clear: %s", err)
|
app.ui.echoerrf("clear: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.printf("clear: %s", err)
|
app.ui.echoerrf("clear: %s", err)
|
||||||
}
|
}
|
||||||
case "draw":
|
case "draw":
|
||||||
case "redraw":
|
case "redraw":
|
||||||
@@ -404,7 +648,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "load":
|
case "load":
|
||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
app.nav.reload()
|
if err := app.nav.reload(); err != nil {
|
||||||
|
app.ui.echoerrf("reload: %s", err)
|
||||||
|
}
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
case "shell":
|
case "shell":
|
||||||
@@ -415,25 +661,73 @@ 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 = "/"
|
||||||
|
last := app.nav.currDir()
|
||||||
|
app.nav.searchInd = last.ind
|
||||||
|
app.nav.searchPos = last.pos
|
||||||
|
app.nav.searchBack = false
|
||||||
case "search-back":
|
case "search-back":
|
||||||
app.ui.cmdPrefix = "?"
|
app.ui.cmdPrefix = "?"
|
||||||
|
last := app.nav.currDir()
|
||||||
|
app.nav.searchInd = last.ind
|
||||||
|
app.nav.searchPos = last.pos
|
||||||
|
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 {
|
||||||
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchNext(); err != nil {
|
||||||
|
app.ui.echoerrf("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 {
|
||||||
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
|
app.ui.echoerrf("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)
|
||||||
@@ -444,10 +738,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdPrefix = "mark-load: "
|
app.ui.cmdPrefix = "mark-load: "
|
||||||
case "sync":
|
case "sync":
|
||||||
if err := app.nav.sync(); err != nil {
|
if err := app.nav.sync(); err != nil {
|
||||||
app.ui.printf("sync: %s", err)
|
app.ui.echoerrf("sync: %s", err)
|
||||||
}
|
}
|
||||||
case "echo":
|
case "echo":
|
||||||
app.ui.msg = strings.Join(e.args, " ")
|
app.ui.echo(strings.Join(e.args, " "))
|
||||||
|
case "echomsg":
|
||||||
|
app.ui.echomsg(strings.Join(e.args, " "))
|
||||||
|
case "echoerr":
|
||||||
|
app.ui.echoerr(strings.Join(e.args, " "))
|
||||||
case "cd":
|
case "cd":
|
||||||
path := "~"
|
path := "~"
|
||||||
if len(e.args) > 0 {
|
if len(e.args) > 0 {
|
||||||
@@ -460,7 +758,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := app.nav.cd(path); err != nil {
|
if err := app.nav.cd(path); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +776,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
case "select":
|
case "select":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.print("select: requires an argument")
|
app.ui.echoerr("select: requires an argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,8 +785,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
log.Printf("getting current directory: %s", err)
|
log.Printf("getting current directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.nav.find(e.args[0]); err != nil {
|
if err := app.nav.sel(e.args[0]); err != nil {
|
||||||
app.ui.printf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,13 +805,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
case "source":
|
case "source":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.print("source: requires an argument")
|
app.ui.echoerr("source: requires an argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.print("push: requires an argument")
|
app.ui.echoerr("push: requires an argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("pushing keys", e.args[0])
|
log.Println("pushing keys", e.args[0])
|
||||||
@@ -524,65 +822,34 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if len(e.args) == 0 {
|
if len(e.args) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch app.ui.cmdPrefix {
|
insert(app, e.args[0])
|
||||||
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[e.args[0]] = wd
|
|
||||||
|
|
||||||
return
|
|
||||||
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[e.args[0]]
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
if app.ui.cmdPrefix == ">" {
|
if app.ui.cmdPrefix == ">" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
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 = ""
|
||||||
case "cmd-complete":
|
case "cmd-complete":
|
||||||
var matches []string
|
var matches []string
|
||||||
if app.ui.cmdPrefix == ":" {
|
switch app.ui.cmdPrefix {
|
||||||
|
case ":":
|
||||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||||
} else {
|
case "/", "?":
|
||||||
|
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
||||||
|
case "$", "%", "!", "&":
|
||||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||||
|
default:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
if len(matches) > 1 {
|
if len(matches) > 1 {
|
||||||
@@ -601,57 +868,67 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
switch app.ui.cmdPrefix {
|
switch app.ui.cmdPrefix {
|
||||||
case ":":
|
case ":":
|
||||||
log.Printf("command: %s", s)
|
log.Printf("command: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{":", s})
|
||||||
p := newParser(strings.NewReader(s))
|
p := newParser(strings.NewReader(s))
|
||||||
for p.parse() {
|
for p.parse() {
|
||||||
p.expr.eval(app, nil)
|
p.expr.eval(app, nil)
|
||||||
}
|
}
|
||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
app.ui.printf("%s", p.err)
|
app.ui.echoerrf("%s", p.err)
|
||||||
}
|
}
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s", s)
|
log.Printf("shell: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"$", s})
|
||||||
|
app.runShell(s, nil, "$")
|
||||||
case "%":
|
case "%":
|
||||||
log.Printf("shell-pipe: %s", s)
|
log.Printf("shell-pipe: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"%", s})
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
app.runShell(s, nil, "%")
|
||||||
case ">":
|
case ">":
|
||||||
io.WriteString(app.cmdIn, s+"\n")
|
io.WriteString(app.cmdIn, s+"\n")
|
||||||
app.cmdOutBuf = nil
|
app.cmdOutBuf = nil
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s", s)
|
log.Printf("shell-wait: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"!", s})
|
||||||
|
app.runShell(s, nil, "!")
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s", s)
|
log.Printf("shell-async: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s})
|
||||||
|
app.runShell(s, nil, "&")
|
||||||
case "/":
|
case "/":
|
||||||
|
if gOpts.incsearch {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
}
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
if err := app.nav.searchNext(); err != nil {
|
if err := app.nav.searchNext(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
||||||
} else {
|
} else {
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "?":
|
case "?":
|
||||||
|
if gOpts.incsearch {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
}
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||||
} else {
|
} else {
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
default:
|
default:
|
||||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||||
}
|
}
|
||||||
@@ -695,11 +972,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
|
update(app)
|
||||||
case "cmd-delete-back":
|
case "cmd-delete-back":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
|
update(app)
|
||||||
case "cmd-left":
|
case "cmd-left":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
@@ -724,23 +1003,28 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
|
update(app)
|
||||||
case "cmd-delete-end":
|
case "cmd-delete-end":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
|
update(app)
|
||||||
case "cmd-delete-unix-word":
|
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.cmdYankBuf = 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]
|
||||||
|
update(app)
|
||||||
case "cmd-yank":
|
case "cmd-yank":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
||||||
|
update(app)
|
||||||
case "cmd-transpose":
|
case "cmd-transpose":
|
||||||
if len(app.ui.cmdAccLeft) < 2 {
|
if len(app.ui.cmdAccLeft) < 2 {
|
||||||
return
|
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]
|
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]
|
||||||
|
update(app)
|
||||||
case "cmd-interrupt":
|
case "cmd-interrupt":
|
||||||
if app.cmd != nil {
|
if app.cmd != nil {
|
||||||
app.cmd.Process.Kill()
|
app.cmd.Process.Kill()
|
||||||
@@ -791,6 +1075,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind = loc[0] + 1
|
ind = loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-delete-word":
|
case "cmd-delete-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -801,6 +1086,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-uppercase-word":
|
case "cmd-uppercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -812,6 +1098,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-lowercase-word":
|
case "cmd-lowercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -823,6 +1110,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-transpose-word":
|
case "cmd-transpose-word":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
@@ -856,10 +1144,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
||||||
|
|
||||||
app.ui.cmdAccLeft = acc
|
app.ui.cmdAccLeft = acc
|
||||||
|
update(app)
|
||||||
default:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
app.ui.printf("command not found: %s", e.name)
|
app.ui.echoerrf("command not found: %s", e.name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
module github.com/gokcehan/lf
|
||||||
|
|
||||||
|
go 1.12
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mattn/go-runewidth v0.0.4
|
||||||
|
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e
|
||||||
|
)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||||
|
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
|
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||||
|
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
|
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs=
|
||||||
|
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||||
|
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
|
||||||
|
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||||
@@ -51,6 +51,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -64,12 +68,15 @@ The following commands are provided by lf without default keybindings:
|
|||||||
.EX
|
.EX
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronizes copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo print arguments to the message line
|
||||||
cd changes working directory to its argument
|
echomsg same as echo but logging
|
||||||
select changes current file selection to its argument
|
echoerr same as echomsg but red color
|
||||||
source reads the configuration file in its argument
|
cd change working directory to the argument
|
||||||
push simulate key pushes given in its argument
|
select change current file selection to the argument
|
||||||
|
source read the configuration file in the argument
|
||||||
|
push simulate key pushes given in the argument
|
||||||
|
delete remove the current file or selected file(s)
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The following command line commands are provided by lf with default keybindings:
|
The following command line commands are provided by lf with default keybindings:
|
||||||
@@ -104,29 +111,38 @@ The following command line commands are provided by lf with default keybindings:
|
|||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
|
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
|
||||||
filesep string (default "\en")
|
filesep string (default "\en")
|
||||||
ifs string (default '') (not exported if empty)
|
ifs string (default ”) (not exported if empty)
|
||||||
previewer string (default '') (not filtered if empty)
|
previewer string (default ”) (not filtered if empty)
|
||||||
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
|
promptfmt string (default "\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f\e033[0m")
|
||||||
shell string (default 'sh')
|
shell string (default 'sh')
|
||||||
sortby string (default 'natural')
|
sortby string (default 'natural')
|
||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||||
ratios string (default '1:2:3')
|
ratios string (default '1:2:3')
|
||||||
info string (default '')
|
info string (default ”)
|
||||||
shellopts string (default '')
|
shellopts string (default ”)
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
@@ -138,6 +154,12 @@ The following variables are exported for shell commands:
|
|||||||
$id id number of the client
|
$id id number of the client
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.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:
|
The following default values are set to the environmental variables on unix when they are not set or empty:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
@@ -501,11 +523,19 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
fi
|
fi
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.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.
|
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
|
||||||
.SH FILE OPERATIONS
|
.SH FILE OPERATIONS
|
||||||
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For this purpose, when you 'copy' a file, it doesn't actually copy the file on the disk, but only records its name to memory. The actual file operation takes place when you 'paste' in which case the 'cp' command is used. Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. This can fail to move files between different partitions when it needs to copy files. For these cases, users are expected to explicitly copy files and then delete the old ones manually. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
|
||||||
.PP
|
.PP
|
||||||
You can customize these operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. The default behavior is similar to the following command:
|
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
|
||||||
|
.PP
|
||||||
|
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
cmd paste %{{
|
cmd paste %{{
|
||||||
@@ -513,20 +543,28 @@ You can customize these operations by defining a 'paste' command. This is a spec
|
|||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
cp -R -n $list .
|
cp -R $list .
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv $list .
|
||||||
fi
|
fi
|
||||||
lf -remote 'send load'
|
lf -remote 'send load'
|
||||||
lf -remote 'send clear'
|
lf -remote 'send clear'
|
||||||
}}
|
}}
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
||||||
.PP
|
.PP
|
||||||
By default, lf does not provide an actual file deletion command to protect new users. You can define such a command and optionally assign a key if you like. An example command to move selected files to a trash folder and remove files completely are provided in the example configuration file.
|
By default, lf does not assign 'delete' command to a key to protect new users. You can customize file deletion by defining a 'delete' command. You can also assign a key to this command if you like. An example command to move selected files to a trash folder and remove files completely after a prompt are provided in the example configuration file.
|
||||||
|
.SH SEARCHING FILES
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current directory. Searching is the traditional method to move the selection to a file matching a given pattern. Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
|
||||||
|
.PP
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'), 'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev' (default 'N'). You can enable 'globsearch' option to match with a glob pattern. Globbing supports '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. You can enable 'incsearch' option to jump to the current match at each keystroke while typing. In this mode, you can either use 'cmd-enter' to accept the search or use 'cmd-escape' to cancel the search.
|
||||||
|
.PP
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'), 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default ','). You can disable 'anchorfind' option to match a pattern at an arbitrary position in the filename instead of the beginning. You can set the number of keys to match using 'findlen' option. If you set this value to zero, then the the keys are read until there is only a single match. Default values of these two options are set to jump to the first file with the given initial.
|
||||||
|
.PP
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan' option to prevent searches to wrap around at the end of the file list. You can disable 'ignorecase' option to match cases in the pattern and the filename. This option is already automatically overridden if the pattern contains upper case characters. You can disable 'smartcase' option to disable this behavior. Two similar options 'ignoredia' and 'smartdia' are provided to control matching diacritics in latin letters.
|
||||||
.SH OPENING FILES
|
.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:
|
You can define a an 'open' command (default 'l' and '<right>') to configure file opening. This command is only called when the current file is not a directory, otherwise the directory is entered instead. You can define it just as you would define any other command:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
@@ -591,6 +629,10 @@ If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead. Th
|
|||||||
.PP
|
.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.
|
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
|
.PP
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr 3-bit color escapes (e.g. '\e033[34m'). If you want to use 256 colors, you need to enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. '\e033[38;5;4m'). This option is intended to eliminate differences between default colors used by ls and lf since terminals may render 3-bit and 8-bit escapes differently even for the same color.
|
||||||
|
.PP
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other.
|
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
|
.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.
|
Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results.
|
||||||
|
.PP
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors. Colors of the prompt line can be configured using the 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line.
|
||||||
@@ -6,14 +6,15 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
envPath = os.Getenv("PATH")
|
envPath = os.Getenv("PATH")
|
||||||
|
envLevel = os.Getenv("LF_LEVEL")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -25,6 +26,8 @@ var (
|
|||||||
gSocketPath string
|
gSocketPath string
|
||||||
gLogPath string
|
gLogPath string
|
||||||
gServerLogPath string
|
gServerLogPath string
|
||||||
|
gSelect string
|
||||||
|
gCommand string
|
||||||
gVersion string
|
gVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,10 +37,32 @@ func init() {
|
|||||||
log.Printf("hostname: %s", err)
|
log.Printf("hostname: %s", err)
|
||||||
}
|
}
|
||||||
gHostname = h
|
gHostname = h
|
||||||
|
|
||||||
|
if envLevel == "" {
|
||||||
|
envLevel = "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportEnvVars() {
|
||||||
|
os.Setenv("id", strconv.Itoa(gClientID))
|
||||||
|
|
||||||
|
os.Setenv("OPENER", envOpener)
|
||||||
|
os.Setenv("EDITOR", envEditor)
|
||||||
|
os.Setenv("PAGER", envPager)
|
||||||
|
os.Setenv("SHELL", envShell)
|
||||||
|
|
||||||
|
level, err := strconv.Atoi(envLevel)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("reading lf level: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
level++
|
||||||
|
|
||||||
|
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
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)
|
||||||
}
|
}
|
||||||
@@ -99,6 +124,11 @@ func main() {
|
|||||||
"",
|
"",
|
||||||
"path to the file to write selected files on open (to use as open file dialog)")
|
"path to the file to write selected files on open (to use as open file dialog)")
|
||||||
|
|
||||||
|
flag.StringVar(&gCommand,
|
||||||
|
"command",
|
||||||
|
"",
|
||||||
|
"command to execute on client initialization")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
gSocketProt = gDefaultSocketProt
|
gSocketProt = gDefaultSocketProt
|
||||||
@@ -115,26 +145,13 @@ 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)
|
||||||
case *showVersion:
|
case *showVersion:
|
||||||
fmt.Println(gVersion)
|
fmt.Println(gVersion)
|
||||||
case *remoteCmd != "":
|
case *remoteCmd != "":
|
||||||
if err := sendRemote(*remoteCmd); err != nil {
|
if err := remote(*remoteCmd); err != nil {
|
||||||
log.Fatalf("remote command: %s", err)
|
log.Fatalf("remote command: %s", err)
|
||||||
}
|
}
|
||||||
case *serverMode:
|
case *serverMode:
|
||||||
@@ -150,6 +167,22 @@ 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:
|
||||||
|
gSelect = flag.Arg(0)
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(os.Stderr, "only single file or directory is allowed\n")
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
exportEnvVars()
|
||||||
|
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,11 +133,10 @@ func splitWord(s string) (word, rest string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function converts a size in bytes to a human readable form. For this
|
// This function converts a size in bytes to a human readable form using metric
|
||||||
// purpose metric suffixes are used (e.g. 1K = 1000). For values less than 10
|
// suffixes (e.g. 1K = 1000). For values less than 10 the first significant
|
||||||
// the first significant digit is shown, otherwise it is hidden. Numbers are
|
// digit is shown, otherwise it is hidden. Numbers are always rounded down.
|
||||||
// always rounded down. For these reasons this function always show somewhat
|
// This should be fine for most human beings.
|
||||||
// smaller values but it should be fine for most human beings.
|
|
||||||
func humanize(size int64) string {
|
func humanize(size int64) string {
|
||||||
if size < 1000 {
|
if size < 1000 {
|
||||||
return fmt.Sprintf("%dB", size)
|
return fmt.Sprintf("%dB", size)
|
||||||
|
|||||||
@@ -144,13 +144,13 @@ func (dir *dir) sort() {
|
|||||||
// 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 {
|
||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
if isHidden(dir.files[i]) && isHidden(dir.files[j]) {
|
||||||
return i < j
|
return i < j
|
||||||
}
|
}
|
||||||
return dir.files[i].Name()[0] == '.'
|
return isHidden(dir.files[i])
|
||||||
})
|
})
|
||||||
for i, f := range dir.files {
|
for i, f := range dir.files {
|
||||||
if f.Name()[0] != '.' {
|
if !isHidden(f) {
|
||||||
dir.files = dir.files[i:]
|
dir.files = dir.files[i:]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func (dir *dir) name() string {
|
|||||||
return dir.files[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.files) == 0 {
|
if len(dir.files) == 0 {
|
||||||
dir.ind, dir.pos = 0, 0
|
dir.ind, dir.pos = 0, 0
|
||||||
return
|
return
|
||||||
@@ -189,6 +189,16 @@ func (dir *dir) find(name string, height int) {
|
|||||||
|
|
||||||
type nav struct {
|
type nav struct {
|
||||||
dirs []*dir
|
dirs []*dir
|
||||||
|
copyBytes int64
|
||||||
|
copyTotal int64
|
||||||
|
copyUpdate int
|
||||||
|
moveCount int
|
||||||
|
moveTotal int
|
||||||
|
moveUpdate int
|
||||||
|
copyBytesChan chan int64
|
||||||
|
copyTotalChan chan int64
|
||||||
|
moveCountChan chan int
|
||||||
|
moveTotalChan chan int
|
||||||
dirChan chan *dir
|
dirChan chan *dir
|
||||||
regChan chan *reg
|
regChan chan *reg
|
||||||
dirCache map[string]*dir
|
dirCache map[string]*dir
|
||||||
@@ -198,7 +208,12 @@ type nav struct {
|
|||||||
selections map[string]int
|
selections map[string]int
|
||||||
selectionInd int
|
selectionInd int
|
||||||
height int
|
height int
|
||||||
|
find string
|
||||||
|
findBack bool
|
||||||
search string
|
search string
|
||||||
|
searchBack bool
|
||||||
|
searchInd int
|
||||||
|
searchPos int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDir(path string) *dir {
|
func (nav *nav) loadDir(path string) *dir {
|
||||||
@@ -226,7 +241,7 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
d.loadTime = time.Now()
|
d.loadTime = time.Now()
|
||||||
nd := newDir(path)
|
nd := newDir(path)
|
||||||
nd.sort()
|
nd.sort()
|
||||||
nd.find(d.name(), nav.height)
|
nd.sel(d.name(), nav.height)
|
||||||
nav.dirChan <- nd
|
nav.dirChan <- nd
|
||||||
}()
|
}()
|
||||||
case d.sortType != gOpts.sortType:
|
case d.sortType != gOpts.sortType:
|
||||||
@@ -234,7 +249,7 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
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
|
||||||
}()
|
}()
|
||||||
@@ -248,7 +263,7 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
dir := nav.loadDir(curr)
|
dir := nav.loadDir(curr)
|
||||||
dir.find(base, nav.height)
|
dir.sel(base, nav.height)
|
||||||
dirs = append(dirs, dir)
|
dirs = append(dirs, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,6 +281,10 @@ func newNav(height int) *nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nav := &nav{
|
nav := &nav{
|
||||||
|
copyBytesChan: make(chan int64, 1024),
|
||||||
|
copyTotalChan: make(chan int64, 1024),
|
||||||
|
moveCountChan: make(chan int, 1024),
|
||||||
|
moveTotalChan: make(chan int, 1024),
|
||||||
dirChan: make(chan *dir),
|
dirChan: make(chan *dir),
|
||||||
regChan: make(chan *reg),
|
regChan: make(chan *reg),
|
||||||
dirCache: make(map[string]*dir),
|
dirCache: make(map[string]*dir),
|
||||||
@@ -288,6 +307,7 @@ func (nav *nav) renew() {
|
|||||||
s, err := os.Stat(d.path)
|
s, err := os.Stat(d.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting directory info: %s", err)
|
log.Printf("getting directory info: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if d.loadTime.After(s.ModTime()) {
|
if d.loadTime.After(s.ModTime()) {
|
||||||
return
|
return
|
||||||
@@ -309,13 +329,13 @@ func (nav *nav) renew() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) reload() {
|
func (nav *nav) reload() error {
|
||||||
nav.dirCache = make(map[string]*dir)
|
nav.dirCache = make(map[string]*dir)
|
||||||
nav.regCache = make(map[string]*reg)
|
nav.regCache = make(map[string]*reg)
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting current directory: %s", err)
|
return fmt.Errorf("getting current directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
@@ -324,12 +344,14 @@ func (nav *nav) reload() {
|
|||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
last.files = append(last.files, curr)
|
last.files = append(last.files, curr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) position() {
|
func (nav *nav) position() {
|
||||||
path := nav.currDir().path
|
path := nav.currDir().path
|
||||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||||
nav.dirs[i].find(filepath.Base(path), nav.height)
|
nav.dirs[i].sel(filepath.Base(path), nav.height)
|
||||||
path = filepath.Dir(path)
|
path = filepath.Dir(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -374,7 +396,7 @@ func (nav *nav) preview() {
|
|||||||
for i := 0; i < nav.height && buf.Scan(); i++ {
|
for i := 0; i < nav.height && buf.Scan(); i++ {
|
||||||
for _, r := range buf.Text() {
|
for _, r := range buf.Text() {
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
reg.lines = []string{"\033[1mbinary\033[0m"}
|
reg.lines = []string{"\033[7mbinary\033[0m"}
|
||||||
nav.regChan <- reg
|
nav.regChan <- reg
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -415,7 +437,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,56 +565,168 @@ func (nav *nav) unselect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) save(cp bool) error {
|
func (nav *nav) save(cp bool) error {
|
||||||
if len(nav.selections) == 0 {
|
list, err := nav.currFileOrSelections()
|
||||||
curr, err := nav.currFile()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("no file selected")
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles([]string{curr.path}, cp); err != nil {
|
if err := saveFiles(list, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
nav.saves[curr.path] = cp
|
for _, f := range list {
|
||||||
} else {
|
|
||||||
selections := nav.currSelections()
|
|
||||||
|
|
||||||
if err := saveFiles(selections, cp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
|
||||||
for f := range nav.selections {
|
|
||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) paste() error {
|
func (nav *nav) copyAsync(ui *ui, srcs []string, dstDir string) {
|
||||||
list, cp, err := loadFiles()
|
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||||
|
|
||||||
|
_, err := os.Stat(dstDir)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
echo.args[0] = err.Error()
|
||||||
|
ui.exprChan <- echo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
total, err := copySize(srcs)
|
||||||
|
if err != nil {
|
||||||
|
echo.args[0] = err.Error()
|
||||||
|
ui.exprChan <- echo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.copyTotalChan <- total
|
||||||
|
|
||||||
|
nums, errs := copyAll(srcs, dstDir)
|
||||||
|
|
||||||
|
errCount := 0
|
||||||
|
loop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case n := <-nums:
|
||||||
|
nav.copyBytesChan <- n
|
||||||
|
case err, ok := <-errs:
|
||||||
|
if !ok {
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.copyTotalChan <- -total
|
||||||
|
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
||||||
|
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||||
|
|
||||||
|
_, err := os.Stat(dstDir)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
echo.args[0] = err.Error()
|
||||||
|
ui.exprChan <- echo
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.moveTotalChan <- len(srcs)
|
||||||
|
|
||||||
|
errCount := 0
|
||||||
|
for _, src := range srcs {
|
||||||
|
nav.moveCountChan <- 1
|
||||||
|
|
||||||
|
srcStat, err := os.Stat(src)
|
||||||
|
if err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
dst := filepath.Join(dstDir, filepath.Base(src))
|
||||||
|
|
||||||
|
dstStat, err := os.Stat(dst)
|
||||||
|
if os.SameFile(srcStat, dstStat) {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] rename %s %s: source and destination are the same file", errCount, src, dst)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
continue
|
||||||
|
} else if !os.IsNotExist(err) {
|
||||||
|
var newPath string
|
||||||
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
|
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||||
|
_, err = os.Stat(newPath)
|
||||||
|
}
|
||||||
|
dst = newPath
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Rename(src, dst); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.moveTotalChan <- -len(srcs)
|
||||||
|
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) paste(ui *ui) error {
|
||||||
|
srcs, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(list) == 0 {
|
if len(srcs) == 0 {
|
||||||
return errors.New("no file in copy/cut buffer")
|
return errors.New("no file in copy/cut buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := nav.currDir()
|
dstDir := nav.currDir().path
|
||||||
|
|
||||||
cmd := pasteCommand(list, dir, cp)
|
if cp {
|
||||||
|
go nav.copyAsync(ui, srcs, dstDir)
|
||||||
if err := cmd.Run(); err != nil {
|
} else {
|
||||||
return fmt.Errorf("pasting files: %s", err)
|
go nav.moveAsync(ui, srcs, dstDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := remote("send sync"); err != nil {
|
||||||
|
return fmt.Errorf("paste: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) del() error {
|
||||||
|
list, err := nav.currFileOrSelections()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range list {
|
||||||
|
if err := os.RemoveAll(path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,7 +761,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)
|
||||||
@@ -645,13 +779,13 @@ func (nav *nav) find(path string) error {
|
|||||||
if last.loading {
|
if last.loading {
|
||||||
last.files = append(last.files, &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 {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
if !gOpts.smartcase || lpattern == pattern {
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
@@ -659,6 +793,95 @@ func match(pattern, name string) (matched bool, err error) {
|
|||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if gOpts.ignoredia {
|
||||||
|
lpattern := removeDiacritics(pattern)
|
||||||
|
if !gOpts.smartdia || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = removeDiacritics(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 {
|
||||||
|
lpattern := strings.ToLower(pattern)
|
||||||
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = strings.ToLower(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gOpts.ignoredia {
|
||||||
|
lpattern := removeDiacritics(pattern)
|
||||||
|
if !gOpts.smartdia || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = removeDiacritics(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
if gOpts.globsearch {
|
if gOpts.globsearch {
|
||||||
return filepath.Match(pattern, name)
|
return filepath.Match(pattern, name)
|
||||||
}
|
}
|
||||||
@@ -668,7 +891,7 @@ 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.files); i++ {
|
for i := last.ind + 1; i < len(last.files); i++ {
|
||||||
matched, err := match(nav.search, last.files[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -679,7 +902,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.files[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -695,7 +918,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.files[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -706,7 +929,7 @@ func (nav *nav) searchPrev() error {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||||
matched, err := match(nav.search, last.files[i].Name())
|
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -719,19 +942,6 @@ func (nav *nav) searchPrev() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) currDir() *dir {
|
|
||||||
return nav.dirs[len(nav.dirs)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) currFile() (*file, error) {
|
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
|
||||||
|
|
||||||
if len(last.files) == 0 {
|
|
||||||
return nil, fmt.Errorf("empty directory")
|
|
||||||
}
|
|
||||||
return last.files[last.ind], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) readMarks() error {
|
func (nav *nav) readMarks() error {
|
||||||
f, err := os.Open(gMarksPath)
|
f, err := os.Open(gMarksPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@@ -792,6 +1002,19 @@ func (nav *nav) writeMarks() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currDir() *dir {
|
||||||
|
return nav.dirs[len(nav.dirs)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currFile() (*file, error) {
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
|
if len(last.files) == 0 {
|
||||||
|
return nil, fmt.Errorf("empty directory")
|
||||||
|
}
|
||||||
|
return last.files[last.ind], nil
|
||||||
|
}
|
||||||
|
|
||||||
type indexedSelections struct {
|
type indexedSelections struct {
|
||||||
paths []string
|
paths []string
|
||||||
indices []int
|
indices []int
|
||||||
@@ -816,3 +1039,16 @@ func (nav *nav) currSelections() []string {
|
|||||||
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currFileOrSelections() (list []string, err error) {
|
||||||
|
if len(nav.selections) == 0 {
|
||||||
|
curr, err := nav.currFile()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("no file selected")
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{curr.path}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nav.currSelections(), nil
|
||||||
|
}
|
||||||
@@ -25,16 +25,25 @@ type sortType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
|
anchorfind bool
|
||||||
|
color256 bool
|
||||||
dircounts bool
|
dircounts bool
|
||||||
drawbox bool
|
drawbox bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
ignorecase bool
|
ignorecase bool
|
||||||
|
incsearch bool
|
||||||
preview bool
|
preview bool
|
||||||
smartcase bool
|
smartcase bool
|
||||||
|
ignoredia bool
|
||||||
|
smartdia bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
number bool
|
||||||
|
relativenumber bool
|
||||||
|
findlen int
|
||||||
period int
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
|
errorfmt string
|
||||||
filesep string
|
filesep string
|
||||||
ifs string
|
ifs string
|
||||||
previewer string
|
previewer string
|
||||||
@@ -51,17 +60,28 @@ var gOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
gOpts.anchorfind = true
|
||||||
|
gOpts.color256 = false
|
||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
gOpts.drawbox = false
|
gOpts.drawbox = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
|
gOpts.incsearch = false
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
|
gOpts.ignoredia = false
|
||||||
|
gOpts.smartdia = false
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
|
gOpts.number = false
|
||||||
|
gOpts.relativenumber = false
|
||||||
|
gOpts.findlen = 1
|
||||||
gOpts.period = 0
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
|
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
||||||
gOpts.filesep = "\n"
|
gOpts.filesep = "\n"
|
||||||
|
gOpts.ifs = ""
|
||||||
|
gOpts.previewer = ""
|
||||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||||
gOpts.shell = gDefaultShell
|
gOpts.shell = gDefaultShell
|
||||||
gOpts.timefmt = time.ANSIC
|
gOpts.timefmt = time.ANSIC
|
||||||
@@ -105,6 +125,10 @@ 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}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -56,6 +57,12 @@ func init() {
|
|||||||
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
|
||||||
|
|
||||||
@@ -80,6 +87,10 @@ func init() {
|
|||||||
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 detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||||
|
return exec.Command(name, arg...)
|
||||||
|
}
|
||||||
|
|
||||||
func pauseCommand() *exec.Cmd {
|
func pauseCommand() *exec.Cmd {
|
||||||
cmd := `echo
|
cmd := `echo
|
||||||
echo -n 'Press any key to continue'
|
echo -n 'Press any key to continue'
|
||||||
@@ -104,31 +115,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
|||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
|
||||||
var sh string
|
|
||||||
var args []string
|
|
||||||
|
|
||||||
if cp {
|
|
||||||
sh = "cp"
|
|
||||||
args = append(args, "-R")
|
|
||||||
} else {
|
|
||||||
sh = "mv"
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: POSIX standard states that -i flag shall do nothing when the
|
|
||||||
// response is not affirmative. Since this command is run with a nil
|
|
||||||
// stdin, it should not give an affirmative answer and in return this
|
|
||||||
// command should not overwrite existing files. Our intention here is
|
|
||||||
// to use the standard -i flag in place of non-standard -n flag to
|
|
||||||
// avoid overwrites.
|
|
||||||
args = append(args, "-i")
|
|
||||||
|
|
||||||
args = append(args, list...)
|
|
||||||
args = append(args, dir.path)
|
|
||||||
|
|
||||||
return exec.Command(sh, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||||
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||||
@@ -146,3 +132,21 @@ func moveCursor(y, x int) {
|
|||||||
func isExecutable(f os.FileInfo) bool {
|
func isExecutable(f os.FileInfo) bool {
|
||||||
return f.Mode()&0111 != 0
|
return f.Mode()&0111 != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHidden(f os.FileInfo) bool {
|
||||||
|
return f.Name()[0] == '.'
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportFiles(f string, fs []string) {
|
||||||
|
envFile := f
|
||||||
|
envFiles := strings.Join(fs, gOpts.filesep)
|
||||||
|
|
||||||
|
os.Setenv("f", envFile)
|
||||||
|
os.Setenv("fs", envFiles)
|
||||||
|
|
||||||
|
if len(fs) == 0 {
|
||||||
|
os.Setenv("fx", envFile)
|
||||||
|
} else {
|
||||||
|
os.Setenv("fx", envFiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
+33
-28
@@ -1,12 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -35,7 +37,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
if envOpener == "" {
|
if envOpener == "" {
|
||||||
envOpener = "start"
|
envOpener = `start ""`
|
||||||
}
|
}
|
||||||
|
|
||||||
if envEditor == "" {
|
if envEditor == "" {
|
||||||
@@ -70,6 +72,12 @@ func init() {
|
|||||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
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 {
|
||||||
return exec.Command("cmd", "/c", "pause")
|
return exec.Command("cmd", "/c", "pause")
|
||||||
}
|
}
|
||||||
@@ -82,33 +90,6 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
|||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
|
||||||
var args []string
|
|
||||||
|
|
||||||
sh := "robocopy"
|
|
||||||
if !cp {
|
|
||||||
args = []string{"/move"}
|
|
||||||
}
|
|
||||||
for _, f := range list {
|
|
||||||
stat, err := os.Stat(f)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting file information: %s", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
base := filepath.Base(f)
|
|
||||||
dest := filepath.Dir(f)
|
|
||||||
if stat.IsDir() {
|
|
||||||
exec.Command(sh, append(args, f, filepath.Join(dir.path, base))...).Run()
|
|
||||||
} else {
|
|
||||||
exec.Command(sh, append(args, dest, dir.path, base)...).Run()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: return 0 on success
|
|
||||||
|
|
||||||
return exec.Command(sh, args...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||||
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||||
@@ -134,3 +115,27 @@ func isExecutable(f os.FileInfo) bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHidden(f os.FileInfo) bool {
|
||||||
|
// TODO: implement
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func exportFiles(f string, fs []string) {
|
||||||
|
envFile := fmt.Sprintf(`"%s"`, f)
|
||||||
|
|
||||||
|
var quotedFiles []string
|
||||||
|
for _, f := range fs {
|
||||||
|
quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f))
|
||||||
|
}
|
||||||
|
envFiles := strings.Join(quotedFiles, gOpts.filesep)
|
||||||
|
|
||||||
|
os.Setenv("f", envFile)
|
||||||
|
os.Setenv("fs", envFiles)
|
||||||
|
|
||||||
|
if len(fs) == 0 {
|
||||||
|
os.Setenv("fx", envFile)
|
||||||
|
} else {
|
||||||
|
os.Setenv("fx", envFiles)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ 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() {
|
||||||
@@ -32,6 +34,8 @@ func serve() {
|
|||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
|
gListener = l
|
||||||
|
|
||||||
listen(l)
|
listen(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +43,14 @@ func listen(l net.Listener) {
|
|||||||
for {
|
for {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
select {
|
||||||
|
case <-gQuitChan:
|
||||||
|
log.Printf("bye!")
|
||||||
|
return
|
||||||
|
default:
|
||||||
log.Printf("accepting connection: %s", err)
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ func (win *win) printReg(reg *reg) {
|
|||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
if reg.loading {
|
if reg.loading {
|
||||||
fg = termbox.AttrBold
|
fg = termbox.AttrReverse
|
||||||
win.print(2, 0, fg, bg, "loading...")
|
win.print(2, 0, fg, bg, "loading...")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -246,17 +246,13 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
|
||||||
|
|
||||||
if dir.loading {
|
if dir.loading {
|
||||||
fg = termbox.AttrBold
|
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "loading...")
|
||||||
win.print(2, 0, fg, bg, "loading...")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dir.files) == 0 {
|
if len(dir.files) == 0 {
|
||||||
fg = termbox.AttrBold
|
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||||
win.print(2, 0, fg, bg, "empty")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,18 +263,45 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lnwidth int
|
||||||
|
var lnformat string
|
||||||
|
|
||||||
|
if gOpts.number || gOpts.relativenumber {
|
||||||
|
lnwidth = 1
|
||||||
|
for j := 10; j < len(dir.files); j *= 10 {
|
||||||
|
lnwidth++
|
||||||
|
}
|
||||||
|
lnformat = fmt.Sprintf("%%%d.d ", lnwidth)
|
||||||
|
}
|
||||||
|
|
||||||
for i, f := range dir.files[beg:end] {
|
for i, f := range dir.files[beg:end] {
|
||||||
fg, bg = colors.get(f)
|
fg, bg := colors.get(f)
|
||||||
|
|
||||||
|
if lnwidth > 0 {
|
||||||
|
var ln string
|
||||||
|
|
||||||
|
if gOpts.number && (!gOpts.relativenumber || i == dir.pos) {
|
||||||
|
ln = fmt.Sprintf(lnformat, i+1+beg)
|
||||||
|
} else if gOpts.relativenumber {
|
||||||
|
if i < dir.pos {
|
||||||
|
ln = fmt.Sprintf(lnformat, dir.pos-i)
|
||||||
|
} else {
|
||||||
|
ln = fmt.Sprintf(lnformat, i-dir.pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
win.print(0, i, termbox.ColorYellow, bg, ln)
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := selections[path]; ok {
|
if _, ok := selections[path]; ok {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(lnwidth, i, fg, termbox.ColorMagenta, " ")
|
||||||
} else if cp, ok := saves[path]; ok {
|
} else if cp, ok := saves[path]; ok {
|
||||||
if cp {
|
if cp {
|
||||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
win.print(lnwidth, i, fg, termbox.ColorYellow, " ")
|
||||||
} else {
|
} else {
|
||||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
win.print(lnwidth, i, fg, termbox.ColorRed, " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +344,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
s = append(s, ' ')
|
s = append(s, ' ')
|
||||||
|
|
||||||
win.print(1, i, fg, bg, string(s))
|
win.print(lnwidth+1, i, fg, bg, string(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,16 +478,33 @@ 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) echo(msg string) {
|
||||||
|
ui.msg = msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ui) echof(format string, a ...interface{}) {
|
||||||
|
ui.echo(fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ui) echomsg(msg string) {
|
||||||
ui.msg = msg
|
ui.msg = msg
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) printf(format string, a ...interface{}) {
|
func (ui *ui) echomsgf(format string, a ...interface{}) {
|
||||||
ui.print(fmt.Sprintf(format, a...))
|
ui.echomsg(fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ui) echoerr(msg string) {
|
||||||
|
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
|
||||||
|
log.Printf("error: %s", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *ui) echoerrf(format string, a ...interface{}) {
|
||||||
|
ui.echoerr(fmt.Sprintf(format, a...))
|
||||||
}
|
}
|
||||||
|
|
||||||
type reg struct {
|
type reg struct {
|
||||||
@@ -497,7 +537,7 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.msg = fmt.Sprintf("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
|
ui.echof("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawPromptLine(nav *nav) {
|
func (ui *ui) drawPromptLine(nav *nav) {
|
||||||
@@ -549,7 +589,18 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
ind := min(currDir.ind+1, tot)
|
ind := min(currDir.ind+1, tot)
|
||||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
ruler := fmt.Sprintf("%s %d/%d", acc, ind, tot)
|
var progress string
|
||||||
|
|
||||||
|
if nav.copyTotal > 0 {
|
||||||
|
percentage := int((100 * float64(nav.copyBytes)) / float64(nav.copyTotal))
|
||||||
|
progress += fmt.Sprintf(" [%d%%]", percentage)
|
||||||
|
}
|
||||||
|
|
||||||
|
if nav.moveTotal > 0 {
|
||||||
|
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
|
||||||
|
}
|
||||||
|
|
||||||
|
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
|
||||||
|
|
||||||
ui.msgWin.printRight(0, fg, bg, ruler)
|
ui.msgWin.printRight(0, fg, bg, ruler)
|
||||||
}
|
}
|
||||||
@@ -742,7 +793,7 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
ev.Key = val
|
ev.Key = val
|
||||||
} else {
|
} else {
|
||||||
ev.Key = termbox.KeyEsc
|
ev.Key = termbox.KeyEsc
|
||||||
ui.printf("unknown key: %s", key)
|
ui.echoerrf("unknown key: %s", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -794,7 +845,7 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
|
|
||||||
switch len(binds) {
|
switch len(binds) {
|
||||||
case 0:
|
case 0:
|
||||||
ui.printf("unknown mapping: %s", string(ui.keyAcc))
|
ui.echoerrf("unknown mapping: %s", string(ui.keyAcc))
|
||||||
ch <- draw
|
ch <- draw
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
@@ -807,8 +858,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
log.Printf("converting command count: %s", err)
|
log.Printf("converting command count: %s", err)
|
||||||
}
|
}
|
||||||
count = c
|
count = c
|
||||||
} else {
|
|
||||||
count = 1
|
|
||||||
}
|
}
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
if e, ok := expr.(*callExpr); ok {
|
if e, ok := expr.(*callExpr); ok {
|
||||||
@@ -830,8 +879,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
log.Printf("converting command count: %s", err)
|
log.Printf("converting command count: %s", err)
|
||||||
}
|
}
|
||||||
count = c
|
count = c
|
||||||
} else {
|
|
||||||
count = 1
|
|
||||||
}
|
}
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
if e, ok := expr.(*callExpr); ok {
|
if e, ok := expr.(*callExpr); ok {
|
||||||
@@ -892,6 +939,14 @@ func (ui *ui) readExpr() <-chan expr {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setColorMode() {
|
||||||
|
if gOpts.color256 {
|
||||||
|
termbox.SetOutputMode(termbox.Output256)
|
||||||
|
} else {
|
||||||
|
termbox.SetOutputMode(termbox.OutputNormal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ui *ui) pause() {
|
func (ui *ui) pause() {
|
||||||
termbox.Close()
|
termbox.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user