Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b445aa205 | ||
|
|
d2414f7580 | ||
|
|
8be63a9c83 | ||
|
|
c630293cc2 | ||
|
|
9c891307f3 | ||
|
|
9539daf8df | ||
|
|
7174b7e307 | ||
|
|
6d1a840587 | ||
|
|
490a4a9d07 | ||
|
|
a6544757db | ||
|
|
f8daa60b31 | ||
|
|
3b49e1a2b6 | ||
|
|
d0cd181eb6 | ||
|
|
9880104c12 | ||
|
|
ffdcb71897 | ||
|
|
707d927788 | ||
|
|
0a22e7c5c8 | ||
|
|
2f056ad359 | ||
|
|
e7fb56391f | ||
|
|
3e36500901 | ||
|
|
f2e3c7a0ce | ||
|
|
75e59cdd08 | ||
|
|
001ee5bfae | ||
|
|
e1b939bf7c | ||
|
|
ce4ea6ea53 | ||
|
|
45552cf809 | ||
|
|
c937dab9e9 | ||
|
|
1119ba0d25 | ||
|
|
83a6e506d2 | ||
|
|
bc2a80fd6e | ||
|
|
e2bf773f3b | ||
|
|
4d3e1cfd6e | ||
|
|
fd73a53f84 | ||
|
|
cbb559346d | ||
|
|
5d1136abfe | ||
|
|
0e3910652a | ||
|
|
99cee56d6e | ||
|
|
25e487cc51 | ||
|
|
72facea2a0 | ||
|
|
8933a3eafe | ||
|
|
41e0bb32cd | ||
|
|
c49140ab36 | ||
|
|
933b49d095 | ||
|
|
c5d05b7683 | ||
|
|
9c1836c18b | ||
|
|
6693709f36 | ||
|
|
17949fc25a | ||
|
|
3c5abbbc5d | ||
|
|
e0747fa2f9 | ||
|
|
b0064df32c | ||
|
|
74eab96637 | ||
|
|
d63e7a2076 | ||
|
|
d5f989f373 | ||
|
|
f76bf30f65 | ||
|
|
8327505398 | ||
|
|
74ef9fcd83 | ||
|
|
0482340d5e | ||
|
|
7a4d1cc275 | ||
|
|
cd396605da | ||
|
|
c43026d1e2 | ||
|
|
7b89126e04 | ||
|
|
ff4c36565c | ||
|
|
cfc9e355b3 | ||
|
|
bc33f3154a | ||
|
|
9991a40e87 | ||
|
|
41339a9e5a | ||
|
|
9515bd73d0 | ||
|
|
d13cc79bc4 | ||
|
|
bba32beb8a | ||
|
|
50ac367626 | ||
|
|
3b34b20cb8 | ||
|
|
6982ffe4cf | ||
|
|
488bf9f6b6 | ||
|
|
2ab866d474 | ||
|
|
9f661344ed | ||
|
|
bfd01e5ed8 | ||
|
|
27861f06e2 | ||
|
|
cb36e87b80 | ||
|
|
30d3078559 | ||
|
|
db224f04fe | ||
|
|
afca893153 | ||
|
|
16db95707e | ||
|
|
bf39c7c63b | ||
|
|
eb8e516cfb | ||
|
|
34f39f90b2 | ||
|
|
4c6241ca42 | ||
|
|
8388b4f385 | ||
|
|
80ab2e4fc4 | ||
|
|
f071a3ae70 | ||
|
|
f3407b2d61 | ||
|
|
a5199960ed | ||
|
|
e69a229578 | ||
|
|
e815adc6a6 |
No files matched your search
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
language: go
|
language: go
|
||||||
install:
|
install:
|
||||||
- go get github.com/nsf/termbox-go
|
- go get github.com/doronbehar/termbox-go
|
||||||
|
- go get gopkg.in/djherbis/times.v1
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- gen/xbuild.sh
|
- gen/xbuild.sh
|
||||||
deploy:
|
deploy:
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,11 +36,24 @@ func newApp() *app {
|
|||||||
ui := newUI()
|
ui := newUI()
|
||||||
nav := newNav(ui.wins[0].h)
|
nav := newNav(ui.wins[0].h)
|
||||||
|
|
||||||
|
quitChan := make(chan bool, 1)
|
||||||
|
|
||||||
|
osChan := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(osChan, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-osChan
|
||||||
|
nav.copyTotalChan <- -nav.copyTotal
|
||||||
|
nav.moveTotalChan <- -nav.moveTotal
|
||||||
|
nav.deleteTotalChan <- -nav.deleteTotal
|
||||||
|
quitChan <- true
|
||||||
|
return
|
||||||
|
}()
|
||||||
|
|
||||||
return &app{
|
return &app{
|
||||||
ui: ui,
|
ui: ui,
|
||||||
nav: nav,
|
nav: nav,
|
||||||
ticker: new(time.Ticker),
|
ticker: new(time.Ticker),
|
||||||
quitChan: make(chan bool, 1),
|
quitChan: quitChan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +152,14 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
if gSelect != "" {
|
if gSelect != "" {
|
||||||
go func() {
|
go func() {
|
||||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
lstat, err := os.Lstat(gSelect)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||||
|
} else if lstat.IsDir() {
|
||||||
|
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||||
|
} else {
|
||||||
|
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,12 +194,13 @@ func (app *app) loop() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("bye!")
|
if app.nav.deleteTotal > 0 {
|
||||||
|
app.ui.echoerr("quit: delete operation in progress")
|
||||||
if err := app.nav.writeMarks(); err != nil {
|
continue
|
||||||
log.Printf("writing marks file: %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Print("bye!")
|
||||||
|
|
||||||
if err := app.writeHistory(); err != nil {
|
if err := app.writeHistory(); err != nil {
|
||||||
log.Printf("writing history file: %s", err)
|
log.Printf("writing history file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -189,9 +212,7 @@ func (app *app) loop() {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
dir := app.nav.currDir()
|
_, err = f.WriteString(app.nav.currDir().path)
|
||||||
|
|
||||||
_, err = f.WriteString(dir.path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("writing last dir file: %s", err)
|
log.Printf("writing last dir file: %s", err)
|
||||||
}
|
}
|
||||||
@@ -229,7 +250,24 @@ func (app *app) loop() {
|
|||||||
app.nav.moveUpdate = 0
|
app.nav.moveUpdate = 0
|
||||||
}
|
}
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case n := <-app.nav.deleteCountChan:
|
||||||
|
app.nav.deleteCount += n
|
||||||
|
if app.nav.deleteUpdate++; app.nav.deleteUpdate >= 1000 {
|
||||||
|
app.nav.deleteUpdate = 0
|
||||||
|
app.ui.draw(app.nav)
|
||||||
|
}
|
||||||
|
case n := <-app.nav.deleteTotalChan:
|
||||||
|
app.nav.deleteTotal += n
|
||||||
|
if n < 0 {
|
||||||
|
app.nav.deleteCount += n
|
||||||
|
}
|
||||||
|
if app.nav.deleteTotal == 0 {
|
||||||
|
app.nav.deleteUpdate = 0
|
||||||
|
}
|
||||||
|
app.ui.draw(app.nav)
|
||||||
case d := <-app.nav.dirChan:
|
case d := <-app.nav.dirChan:
|
||||||
|
app.nav.checkDir(d)
|
||||||
|
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
if ok {
|
||||||
d.ind = prev.ind
|
d.ind = prev.ind
|
||||||
@@ -258,6 +296,8 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
case r := <-app.nav.regChan:
|
case r := <-app.nav.regChan:
|
||||||
|
app.nav.checkReg(r)
|
||||||
|
|
||||||
app.nav.regCache[r.path] = r
|
app.nav.regCache[r.path] = r
|
||||||
|
|
||||||
curr, err := app.nav.currFile()
|
curr, err := app.nav.currFile()
|
||||||
@@ -284,8 +324,8 @@ func (app *app) loop() {
|
|||||||
|
|
||||||
func (app *app) exportFiles() {
|
func (app *app) exportFiles() {
|
||||||
var currFile string
|
var currFile string
|
||||||
if f, err := app.nav.currFile(); err == nil {
|
if curr, err := app.nav.currFile(); err == nil {
|
||||||
currFile = f.path
|
currFile = curr.path
|
||||||
}
|
}
|
||||||
|
|
||||||
currSelections := app.nav.currSelections()
|
currSelections := app.nav.currSelections()
|
||||||
@@ -320,6 +360,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
cmd := shellCommand(s, args)
|
cmd := shellCommand(s, args)
|
||||||
|
|
||||||
var out io.Reader
|
var out io.Reader
|
||||||
|
var err error
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "$", "!":
|
case "$", "!":
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
@@ -329,6 +370,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
app.ui.pause()
|
app.ui.pause()
|
||||||
defer app.ui.resume()
|
defer app.ui.resume()
|
||||||
defer app.nav.renew()
|
defer app.nav.renew()
|
||||||
|
|
||||||
|
err = cmd.Run()
|
||||||
case "%":
|
case "%":
|
||||||
stdin, err := cmd.StdinPipe()
|
stdin, err := cmd.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -341,13 +384,8 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
}
|
}
|
||||||
out = stdout
|
out = stdout
|
||||||
cmd.Stderr = cmd.Stdout
|
cmd.Stderr = cmd.Stdout
|
||||||
}
|
fallthrough
|
||||||
|
case "&":
|
||||||
var err error
|
|
||||||
switch prefix {
|
|
||||||
case "$", "!":
|
|
||||||
err = cmd.Run()
|
|
||||||
case "%", "&":
|
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,5 +431,11 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||||
}()
|
}()
|
||||||
|
case "&":
|
||||||
|
go func() {
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
log.Printf("running shell: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/doronbehar/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run() {
|
func run() {
|
||||||
@@ -52,7 +52,7 @@ func readExpr() <-chan expr {
|
|||||||
|
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
for err != nil {
|
for err != nil {
|
||||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
log.Printf("connecting server: %s", err)
|
||||||
time.Sleep(duration)
|
time.Sleep(duration)
|
||||||
duration *= 2
|
duration *= 2
|
||||||
c, err = net.Dial(gSocketProt, gSocketPath)
|
c, err = net.Dial(gSocketProt, gSocketPath)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/doronbehar/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
const gAnsiColorResetMask = termbox.AttrBold | termbox.AttrUnderline | termbox.AttrReverse
|
||||||
@@ -199,6 +199,10 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
|||||||
var key string
|
var key string
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case f.linkState == working:
|
||||||
|
key = "ln"
|
||||||
|
case f.linkState == broken:
|
||||||
|
key = "or"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||||
key = "tw"
|
key = "tw"
|
||||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||||
@@ -207,10 +211,6 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
|||||||
key = "ow"
|
key = "ow"
|
||||||
case f.IsDir():
|
case f.IsDir():
|
||||||
key = "di"
|
key = "di"
|
||||||
case f.linkState == working:
|
|
||||||
key = "ln"
|
|
||||||
case f.linkState == broken:
|
|
||||||
key = "or"
|
|
||||||
case f.Mode()&os.ModeNamedPipe != 0:
|
case f.Mode()&os.ModeNamedPipe != 0:
|
||||||
key = "pi"
|
key = "pi"
|
||||||
case f.Mode()&os.ModeSocket != 0:
|
case f.Mode()&os.ModeSocket != 0:
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/doronbehar/termbox-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestApplyAnsiCodes(t *testing.T) {
|
func TestApplyAnsiCodes(t *testing.T) {
|
||||||
|
|||||||
+29
-17
@@ -31,13 +31,11 @@ var (
|
|||||||
"copy",
|
"copy",
|
||||||
"cut",
|
"cut",
|
||||||
"paste",
|
"paste",
|
||||||
"delete",
|
|
||||||
"clear",
|
"clear",
|
||||||
"draw",
|
|
||||||
"redraw",
|
"redraw",
|
||||||
"load",
|
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
|
"rename",
|
||||||
"shell",
|
"shell",
|
||||||
"shell-pipe",
|
"shell-pipe",
|
||||||
"shell-wait",
|
"shell-wait",
|
||||||
@@ -51,15 +49,21 @@ var (
|
|||||||
"search-next",
|
"search-next",
|
||||||
"search-prev",
|
"search-prev",
|
||||||
"mark-save",
|
"mark-save",
|
||||||
|
"mark-remove",
|
||||||
"mark-load",
|
"mark-load",
|
||||||
|
"draw",
|
||||||
|
"load",
|
||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
"echomsg",
|
"echomsg",
|
||||||
"echoerr",
|
"echoerr",
|
||||||
"cd",
|
"cd",
|
||||||
"select",
|
"select",
|
||||||
|
"glob-select",
|
||||||
|
"glob-unselect",
|
||||||
"source",
|
"source",
|
||||||
"push",
|
"push",
|
||||||
|
"delete",
|
||||||
}
|
}
|
||||||
|
|
||||||
gOptWords = []string{
|
gOptWords = []string{
|
||||||
@@ -84,6 +88,9 @@ var (
|
|||||||
"hidden",
|
"hidden",
|
||||||
"nohidden",
|
"nohidden",
|
||||||
"hidden!",
|
"hidden!",
|
||||||
|
"icons",
|
||||||
|
"noicons",
|
||||||
|
"icons!",
|
||||||
"ignorecase",
|
"ignorecase",
|
||||||
"noignorecase",
|
"noignorecase",
|
||||||
"ignorecase!",
|
"ignorecase!",
|
||||||
@@ -93,9 +100,15 @@ var (
|
|||||||
"incsearch",
|
"incsearch",
|
||||||
"noincsearch",
|
"noincsearch",
|
||||||
"incsearch!",
|
"incsearch!",
|
||||||
|
"number",
|
||||||
|
"nonumber",
|
||||||
|
"number!",
|
||||||
"preview",
|
"preview",
|
||||||
"nopreview",
|
"nopreview",
|
||||||
"preview!",
|
"preview!",
|
||||||
|
"relativenumber",
|
||||||
|
"norelativenumber",
|
||||||
|
"relativenumber!",
|
||||||
"reverse",
|
"reverse",
|
||||||
"noreverse",
|
"noreverse",
|
||||||
"reverse!",
|
"reverse!",
|
||||||
@@ -108,27 +121,26 @@ var (
|
|||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
"number",
|
"wrapscroll",
|
||||||
"nonumber",
|
"nowrapscroll",
|
||||||
"number!",
|
"wrapscroll!",
|
||||||
"relativenumber",
|
|
||||||
"norelativenumber",
|
|
||||||
"relativenumber!",
|
|
||||||
"findlen",
|
"findlen",
|
||||||
"period",
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
"errorfmt",
|
"errorfmt",
|
||||||
"filesep",
|
"filesep",
|
||||||
|
"hiddenfiles",
|
||||||
"ifs",
|
"ifs",
|
||||||
|
"info",
|
||||||
"previewer",
|
"previewer",
|
||||||
"promptfmt",
|
"promptfmt",
|
||||||
|
"ratios",
|
||||||
"shell",
|
"shell",
|
||||||
|
"shellopts",
|
||||||
"sortby",
|
"sortby",
|
||||||
"timefmt",
|
"timefmt",
|
||||||
"ratios",
|
"truncatechar",
|
||||||
"info",
|
|
||||||
"shellopts",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -214,7 +226,7 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func matchFile(s string) (matches []string, longest string) {
|
func matchFile(s string) (matches []string, longest string) {
|
||||||
dir := strings.Replace(s, "~", gUser.HomeDir, -1)
|
dir := replaceTilde(s)
|
||||||
|
|
||||||
if !filepath.IsAbs(dir) {
|
if !filepath.IsAbs(dir) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
@@ -246,13 +258,13 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
|
|
||||||
name := f.Name()
|
name := f.Name()
|
||||||
if isRoot(s) || filepath.Base(s) != s {
|
if isRoot(s) || filepath.Base(s) != s {
|
||||||
name = filepath.Join(filepath.Dir(s), f.Name())
|
name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
|
||||||
}
|
}
|
||||||
name = escape(name)
|
name = escape(name)
|
||||||
|
|
||||||
item := f.Name()
|
item := f.Name()
|
||||||
if f.Mode().IsDir() {
|
if f.Mode().IsDir() {
|
||||||
item += string(filepath.Separator)
|
item += escape(string(filepath.Separator))
|
||||||
}
|
}
|
||||||
matches = append(matches, item)
|
matches = append(matches, item)
|
||||||
|
|
||||||
@@ -262,7 +274,7 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
if f.Mode().IsRegular() {
|
if f.Mode().IsRegular() {
|
||||||
longest = name + " "
|
longest = name + " "
|
||||||
} else {
|
} else {
|
||||||
longest = name + string(filepath.Separator)
|
longest = name + escape(string(filepath.Separator))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,7 +384,7 @@ func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
longestAcc = []rune(longest)
|
longestAcc = []rune(longest)
|
||||||
default:
|
default:
|
||||||
matches, longest = matchFile(f[len(f)-1])
|
matches, longest = matchFile(f[len(f)-1])
|
||||||
longestAcc = append(acc[:len(acc)-len(f[len(f)-1])], []rune(longest)...)
|
longestAcc = append(acc[:len(acc)-len([]rune(f[len(f)-1]))], []rune(longest)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -86,12 +86,12 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
|
|||||||
for _, src := range srcs {
|
for _, src := range srcs {
|
||||||
dst := filepath.Join(dstDir, filepath.Base(src))
|
dst := filepath.Join(dstDir, filepath.Base(src))
|
||||||
|
|
||||||
_, err := os.Stat(dst)
|
_, err := os.Lstat(dst)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
var newPath string
|
var newPath string
|
||||||
for i := 1; !os.IsNotExist(err); i++ {
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||||
_, err = os.Stat(newPath)
|
_, err = os.Lstat(newPath)
|
||||||
}
|
}
|
||||||
dst = newPath
|
dst = newPath
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-16
@@ -2,7 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
var normMap map[rune]rune
|
var normMap map[rune]rune
|
||||||
@@ -14,19 +14,16 @@ func init() {
|
|||||||
appendTransliterate(
|
appendTransliterate(
|
||||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vietnamese
|
// Vietnamese
|
||||||
appendTransliterate(
|
appendTransliterate(
|
||||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||||
true,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendTransliterate(base, norm string, uppercase bool) {
|
func appendTransliterate(base, norm string) {
|
||||||
normRunes := []rune(norm)
|
normRunes := []rune(norm)
|
||||||
baseRunes := []rune(base)
|
baseRunes := []rune(base)
|
||||||
|
|
||||||
@@ -36,24 +33,20 @@ func appendTransliterate(base, norm string, uppercase bool) {
|
|||||||
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
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 {
|
for i := 0; i < lenBase; i++ {
|
||||||
normMap[baseRune] = normRunes[i]
|
normMap[baseRunes[i]] = normRunes[i]
|
||||||
}
|
|
||||||
|
|
||||||
if uppercase {
|
baseUpper := unicode.ToUpper(baseRunes[i])
|
||||||
upperBase := strings.ToUpper(base)
|
normUpper := unicode.ToUpper(normRunes[i])
|
||||||
upperNorm := strings.ToUpper(norm)
|
|
||||||
normRune := []rune(upperNorm)
|
normMap[baseUpper] = normUpper
|
||||||
for i, baseRune := range []rune(upperBase) {
|
|
||||||
normMap[baseRune] = normRune[i]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove diacritics and make lowercase.
|
// Remove diacritics and make lowercase.
|
||||||
func removeDiacritics(baseString string) string {
|
func removeDiacritics(baseString string) string {
|
||||||
var normalizedRunes []rune
|
var normalizedRunes []rune
|
||||||
for _, baseRune := range []rune(baseString) {
|
for _, baseRune := range baseString {
|
||||||
if normRune, ok := normMap[baseRune]; ok {
|
if normRune, ok := normMap[baseRune]; ok {
|
||||||
normalizedRunes = append(normalizedRunes, normRune)
|
normalizedRunes = append(normalizedRunes, normRune)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ The following commands are provided by lf with default keybindings:
|
|||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unselect (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
@@ -37,6 +36,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
|
rename (default 'r')
|
||||||
shell (default '$')
|
shell (default '$')
|
||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
@@ -51,20 +51,24 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (default `"`)
|
||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronize copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo print arguments to the message line
|
echo print arguments to the message line
|
||||||
echomsg same as echo but logging
|
echomsg same as echo but logging
|
||||||
echoerr same as echomsg but red color
|
echoerr same as echomsg but red color
|
||||||
cd change working directory to the argument
|
cd change working directory to the argument
|
||||||
select change current file selection to the argument
|
select change current file selection to the argument
|
||||||
source read the configuration file in the argument
|
toggle toggle the selection of the current file or its arguments
|
||||||
push simulate key pushes given in the argument
|
glob-select select files that match the given glob
|
||||||
delete remove the current file or selected file(s)
|
glob-unselect unselect files that match the given glob
|
||||||
|
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:
|
||||||
@@ -103,31 +107,35 @@ The following options can be used to customize the behavior of lf:
|
|||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
|
icons boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
ignoredia boolean (default off)
|
ignoredia boolean (default off)
|
||||||
incsearch boolean (default off)
|
incsearch boolean (default off)
|
||||||
|
number boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
|
relativenumber boolean (default off)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
smartdia boolean (default off)
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
number boolean (default off)
|
wrapscroll boolean (default off)
|
||||||
relativenumber boolean (default off)
|
|
||||||
findlen integer (default 1) (zero to prompt until single match)
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
period integer (default 0) (zero to disable periodic loading)
|
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")
|
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
|
hiddenfiles string (default '.*')
|
||||||
ifs string (default '') (not exported if empty)
|
ifs string (default '') (not exported if empty)
|
||||||
|
info string (default '')
|
||||||
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")
|
||||||
|
ratios string (default '1:2:3')
|
||||||
shell string (default 'sh')
|
shell string (default 'sh')
|
||||||
|
shellopts string (default '')
|
||||||
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')
|
truncatechar string (default '~')
|
||||||
info string (default '')
|
|
||||||
shellopts string (default '')
|
|
||||||
|
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
@@ -168,7 +176,11 @@ The following additional keybindings are provided by default:
|
|||||||
map sn :set sortby natural; set info
|
map sn :set sortby natural; set info
|
||||||
map ss :set sortby size; set info size
|
map ss :set sortby size; set info size
|
||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
|
map sa :set sortby atime; set info atime
|
||||||
|
map sc :set sortby ctime; set info ctime
|
||||||
|
map se :set sortby ext; set info
|
||||||
map gh cd ~
|
map gh cd ~
|
||||||
|
map <space> :toggle; down
|
||||||
|
|
||||||
The following keybindings to applications are provided by default:
|
The following keybindings to applications are provided by default:
|
||||||
|
|
||||||
@@ -214,14 +226,11 @@ The following command prefixes are used by lf:
|
|||||||
% shell-pipe shell command running with the ui
|
% shell-pipe shell command running with the ui
|
||||||
! shell-wait shell command waiting for key press
|
! shell-wait shell command waiting for key press
|
||||||
& shell-async shell command running asynchronously
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
|
||||||
? search-back search file in the reverse order
|
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file for
|
The same evaluator is used for the command line and the configuration file for
|
||||||
read and shell commands. The difference is that prefixes are not necessary in
|
read and shell commands. The difference is that prefixes are not necessary in
|
||||||
the command line. Instead, different modes are provided to read corresponding
|
the command line. Instead, different modes are provided to read corresponding
|
||||||
commands. These modes are mapped to the prefix keys above by default. Searching
|
commands. These modes are mapped to the prefix keys above by default.
|
||||||
commands are only used from the command line.
|
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
|
|
||||||
@@ -528,11 +537,10 @@ 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,
|
preserved and all other attributes are ignored including ownership, timestamps,
|
||||||
context, links, and xattr. Special files such as character and block devices,
|
context, links, and xattr. Special files such as character and block devices,
|
||||||
named pipes, and sockets are skipped and links are followed. Moving is
|
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
|
performed using the rename operation of the underlying OS. For cross-device
|
||||||
move files between different partitions when it needs to copy files. For these
|
moving, lf falls back to copying and then deletes the original files if there
|
||||||
cases, users are expected to explicitly copy files and then delete the old ones
|
are no errors. Operation errors are shown in the message line as well as the
|
||||||
manually. Operation errors are shown in the message line as well as the log
|
log file and they do not preemptively finish the corresponding file operation.
|
||||||
file and they do not preemptively finish the corresponding file operation.
|
|
||||||
|
|
||||||
File operations can be performed on the current selected file or alternatively
|
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
|
on multiple files by selecting them first. When you 'copy' a file, lf doesn't
|
||||||
@@ -583,7 +591,16 @@ Globbing supports '*' to match any sequence, '?' to match any character, and
|
|||||||
'[...]' or '[^...] to match character sets or ranges. You can enable
|
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||||
'incsearch' option to jump to the current match at each keystroke while typing.
|
'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
|
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||||
'cmd-escape' to cancel the search.
|
'cmd-escape' to cancel the search. Alternatively, you can also map some other
|
||||||
|
commands with 'cmap' to accept the search and execute the command immediately
|
||||||
|
afterwards. Possible candidates are 'up', 'down' and their variants, 'updir',
|
||||||
|
and 'open' commands. For example, you can use arrow keys to finish the search
|
||||||
|
with the following mappings:
|
||||||
|
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
cmap <left> updir
|
||||||
|
cmap <right> open
|
||||||
|
|
||||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
@@ -623,6 +640,9 @@ You may want to use either file extensions or mime types from 'file' command:
|
|||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
You may want to use 'setsid' before your opener command to have persistent
|
||||||
|
processes that continue to run after lf quits.
|
||||||
|
|
||||||
Following command is provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open &$OPENER $f
|
cmd open &$OPENER $f
|
||||||
@@ -675,6 +695,39 @@ pipe with a SIGPIPE when enough lines are read. When everything else fails, you
|
|||||||
can make use of the height argument to only feed the first portion of the file
|
can make use of the height argument to only feed the first portion of the file
|
||||||
to a program for preview.
|
to a program for preview.
|
||||||
|
|
||||||
|
Changing Directory
|
||||||
|
|
||||||
|
lf changes the working directory of the process to the current directory so
|
||||||
|
that shell commands always work in the displayed directory. After quitting, it
|
||||||
|
returns to the original directory where it is first launched like all shell
|
||||||
|
programs. If you want to stay in the current directory after quitting, you can
|
||||||
|
use one of the example wrapper shell scripts provided in the repository.
|
||||||
|
|
||||||
|
There is a special command 'on-cd' that runs a shell command when it is defined
|
||||||
|
and the directory is changed. You can define it just as you would define any
|
||||||
|
other command:
|
||||||
|
|
||||||
|
cmd on-cd &{{
|
||||||
|
# display git repository status in your prompt
|
||||||
|
source /usr/share/git/completion/git-prompt.sh
|
||||||
|
GIT_PS1_SHOWDIRTYSTATE=auto
|
||||||
|
GIT_PS1_SHOWSTASHSTATE=auto
|
||||||
|
GIT_PS1_SHOWUNTRACKEDFILES=auto
|
||||||
|
GIT_PS1_SHOWUPSTREAM=auto
|
||||||
|
git=$(__git_ps1 " (%s)") || true
|
||||||
|
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f$git\033[0m"
|
||||||
|
lf -remote "send $id set promptfmt \"$fmt\""
|
||||||
|
}}
|
||||||
|
|
||||||
|
This command runs whenever you change directory but not on startup. You can add
|
||||||
|
an extra call to make it run on startup as well:
|
||||||
|
|
||||||
|
cmd on-cd &{{ # ... }}
|
||||||
|
on-cd
|
||||||
|
|
||||||
|
Note that all shell commands are possible but `%` and `&` are usually more
|
||||||
|
appropriate as `$` and `!` causes flickers and pauses respectively.
|
||||||
|
|
||||||
Colorschemes
|
Colorschemes
|
||||||
|
|
||||||
lf tries to automatically adapt its colors to the environment. On startup,
|
lf tries to automatically adapt its colors to the environment. On startup,
|
||||||
|
|||||||
+83
-27
@@ -30,7 +30,6 @@ The following commands are provided by lf with default keybindings:
|
|||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unselect (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
@@ -40,6 +39,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
|
rename (default 'r')
|
||||||
shell (default '$')
|
shell (default '$')
|
||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
@@ -54,20 +54,24 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (default '"')
|
||||||
|
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronize copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo print arguments to the message line
|
echo print arguments to the message line
|
||||||
echomsg same as echo but logging
|
echomsg same as echo but logging
|
||||||
echoerr same as echomsg but red color
|
echoerr same as echomsg but red color
|
||||||
cd change working directory to the argument
|
cd change working directory to the argument
|
||||||
select change current file selection to the argument
|
select change current file selection to the argument
|
||||||
source read the configuration file in the argument
|
toggle toggle the selection of the current file or its arguments
|
||||||
push simulate key pushes given in the argument
|
glob-select select files that match the given glob
|
||||||
delete remove the current file or selected file(s)
|
glob-unselect unselect files that match the given glob
|
||||||
|
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:
|
||||||
@@ -106,31 +110,35 @@ The following options can be used to customize the behavior of lf:
|
|||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
|
icons boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
ignoredia boolean (default off)
|
ignoredia boolean (default off)
|
||||||
incsearch boolean (default off)
|
incsearch boolean (default off)
|
||||||
|
number boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
|
relativenumber boolean (default off)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
smartdia boolean (default off)
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
number boolean (default off)
|
wrapscroll boolean (default off)
|
||||||
relativenumber boolean (default off)
|
|
||||||
findlen integer (default 1) (zero to prompt until single match)
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
period integer (default 0) (zero to disable periodic loading)
|
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")
|
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)
|
hiddenfiles string (default '.*')
|
||||||
previewer string (default ”) (not filtered if empty)
|
ifs string (default '') (not exported if empty)
|
||||||
|
info string (default '')
|
||||||
|
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")
|
||||||
|
ratios string (default '1:2:3')
|
||||||
shell string (default 'sh')
|
shell string (default 'sh')
|
||||||
|
shellopts string (default '')
|
||||||
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')
|
truncatechar string (default '~')
|
||||||
info string (default ”)
|
|
||||||
shellopts string (default ”)
|
|
||||||
|
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
@@ -171,7 +179,11 @@ The following additional keybindings are provided by default:
|
|||||||
map sn :set sortby natural; set info
|
map sn :set sortby natural; set info
|
||||||
map ss :set sortby size; set info size
|
map ss :set sortby size; set info size
|
||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
|
map sa :set sortby atime; set info atime
|
||||||
|
map sc :set sortby ctime; set info ctime
|
||||||
|
map se :set sortby ext; set info
|
||||||
map gh cd ~
|
map gh cd ~
|
||||||
|
map <space> :toggle; down
|
||||||
|
|
||||||
The following keybindings to applications are provided by default:
|
The following keybindings to applications are provided by default:
|
||||||
|
|
||||||
@@ -219,14 +231,12 @@ The following command prefixes are used by lf:
|
|||||||
% shell-pipe shell command running with the ui
|
% shell-pipe shell command running with the ui
|
||||||
! shell-wait shell command waiting for key press
|
! shell-wait shell command waiting for key press
|
||||||
& shell-async shell command running asynchronously
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
|
||||||
? search-back search file in the reverse order
|
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file
|
The same evaluator is used for the command line and the configuration file
|
||||||
for read and shell commands. The difference is that prefixes are not
|
for read and shell commands. The difference is that prefixes are not
|
||||||
necessary in the command line. Instead, different modes are provided to read
|
necessary in the command line. Instead, different modes are provided to read
|
||||||
corresponding commands. These modes are mapped to the prefix keys above by
|
corresponding commands. These modes are mapped to the prefix keys above by
|
||||||
default. Searching commands are only used from the command line.
|
default.
|
||||||
|
|
||||||
|
|
||||||
Syntax
|
Syntax
|
||||||
@@ -550,10 +560,9 @@ 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,
|
are preserved and all other attributes are ignored including ownership,
|
||||||
timestamps, context, links, and xattr. Special files such as character and
|
timestamps, context, links, and xattr. Special files such as character and
|
||||||
block devices, named pipes, and sockets are skipped and links are followed.
|
block devices, named pipes, and sockets are skipped and links are followed.
|
||||||
Moving is performed using the rename operation of the underlying OS. This
|
Moving is performed using the rename operation of the underlying OS. For
|
||||||
can fail to move files between different partitions when it needs to copy
|
cross-device moving, lf falls back to copying and then deletes the original
|
||||||
files. For these cases, users are expected to explicitly copy files and then
|
files if there are no errors. Operation errors are shown in the message line
|
||||||
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
|
as well as the log file and they do not preemptively finish the
|
||||||
corresponding file operation.
|
corresponding file operation.
|
||||||
|
|
||||||
@@ -608,7 +617,16 @@ pattern. Globbing supports '*' to match any sequence, '?' to match any
|
|||||||
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||||
enable 'incsearch' option to jump to the current match at each keystroke
|
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
|
while typing. In this mode, you can either use 'cmd-enter' to accept the
|
||||||
search or use 'cmd-escape' to cancel the search.
|
search or use 'cmd-escape' to cancel the search. Alternatively, you can also
|
||||||
|
map some other commands with 'cmap' to accept the search and execute the
|
||||||
|
command immediately afterwards. Possible candidates are 'up', 'down' and
|
||||||
|
their variants, 'updir', and 'open' commands. For example, you can use arrow
|
||||||
|
keys to finish the search with the following mappings:
|
||||||
|
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
cmap <left> updir
|
||||||
|
cmap <right> open
|
||||||
|
|
||||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
@@ -650,6 +668,9 @@ command:
|
|||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
You may want to use 'setsid' before your opener command to have persistent
|
||||||
|
processes that continue to run after lf quits.
|
||||||
|
|
||||||
Following command is provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open &$OPENER $f
|
cmd open &$OPENER $f
|
||||||
@@ -705,6 +726,41 @@ everything else fails, you can make use of the height argument to only feed
|
|||||||
the first portion of the file to a program for preview.
|
the first portion of the file to a program for preview.
|
||||||
|
|
||||||
|
|
||||||
|
Changing Directory
|
||||||
|
|
||||||
|
lf changes the working directory of the process to the current directory so
|
||||||
|
that shell commands always work in the displayed directory. After quitting,
|
||||||
|
it returns to the original directory where it is first launched like all
|
||||||
|
shell programs. If you want to stay in the current directory after quitting,
|
||||||
|
you can use one of the example wrapper shell scripts provided in the
|
||||||
|
repository.
|
||||||
|
|
||||||
|
There is a special command 'on-cd' that runs a shell command when it is
|
||||||
|
defined and the directory is changed. You can define it just as you would
|
||||||
|
define any other command:
|
||||||
|
|
||||||
|
cmd on-cd &{{
|
||||||
|
# display git repository status in your prompt
|
||||||
|
source /usr/share/git/completion/git-prompt.sh
|
||||||
|
GIT_PS1_SHOWDIRTYSTATE=auto
|
||||||
|
GIT_PS1_SHOWSTASHSTATE=auto
|
||||||
|
GIT_PS1_SHOWUNTRACKEDFILES=auto
|
||||||
|
GIT_PS1_SHOWUPSTREAM=auto
|
||||||
|
git=$(__git_ps1 " (%s)") || true
|
||||||
|
fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w\033[0m\033[1m%f$git\033[0m"
|
||||||
|
lf -remote "send $id set promptfmt \"$fmt\""
|
||||||
|
}}
|
||||||
|
|
||||||
|
This command runs whenever you change directory but not on startup. You can
|
||||||
|
add an extra call to make it run on startup as well:
|
||||||
|
|
||||||
|
cmd on-cd &{{ # ... }}
|
||||||
|
on-cd
|
||||||
|
|
||||||
|
Note that all shell commands are possible but '%' and '&' are usually more
|
||||||
|
appropriate as '$' and '!' causes flickers and pauses respectively.
|
||||||
|
|
||||||
|
|
||||||
Colorschemes
|
Colorschemes
|
||||||
|
|
||||||
lf tries to automatically adapt its colors to the environment. On startup,
|
lf tries to automatically adapt its colors to the environment. On startup,
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#
|
||||||
|
# For using these completions you must load it from .tcshrc
|
||||||
|
#
|
||||||
|
# source ~/.config/lf/lf.csh
|
||||||
|
#
|
||||||
|
set lf_args = "-command -cpuprofile -doc --help -last-dir-path -memprofile -remote -selection-path -server -version --version"
|
||||||
|
|
||||||
|
uncomplete lf
|
||||||
|
uncomplete lfcd
|
||||||
|
|
||||||
|
complete lf "C/-*/(${lf_args})/"
|
||||||
|
complete lfcd "C/-*/(${lf_args})/"
|
||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
#compdef lf
|
||||||
|
|
||||||
|
# For using these completions you must:
|
||||||
|
# - rename this file to _lf
|
||||||
|
# - add the containing folder to $fpath in .zshrc, like this:
|
||||||
|
# '''
|
||||||
|
# fpath=(/path/to/folder/containing_lf $fpath)
|
||||||
|
# autoload -U compinit
|
||||||
|
# compinit
|
||||||
|
# '''
|
||||||
|
#
|
||||||
|
# zsh completions for 'lf'
|
||||||
|
# automatically generated with http://github.com/RobSis/zsh-completion-generator
|
||||||
|
local arguments
|
||||||
|
|
||||||
|
arguments=(
|
||||||
|
'-command[command to execute on client initialization]'
|
||||||
|
'-cpuprofile[path to the file to write the CPU profile]'
|
||||||
|
'-doc[show documentation]'
|
||||||
|
'-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'
|
||||||
|
'-memprofile[path to the file to write the memory profile]'
|
||||||
|
'-remote[send remote command to server]'
|
||||||
|
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
|
||||||
|
'-server[start server (automatic)]'
|
||||||
|
'-version[show version]'
|
||||||
|
'*:filename:_files'
|
||||||
|
)
|
||||||
|
|
||||||
|
_arguments -s $arguments
|
||||||
+6
-6
@@ -5,11 +5,11 @@ rem You need to put this file to a folder in %PATH% variable.
|
|||||||
|
|
||||||
:tmploop
|
:tmploop
|
||||||
set tmpfile="%tmp%\lf.%random%.tmp"
|
set tmpfile="%tmp%\lf.%random%.tmp"
|
||||||
if exist "%tmpfile%" goto:tmploop
|
if exist %tmpfile% goto:tmploop
|
||||||
lf -last-dir-path="%tmpfile%" %*
|
lf -last-dir-path=%tmpfile% %*
|
||||||
if not exist "%tmpfile%" exit
|
if not exist %tmpfile% exit
|
||||||
set /p dir=<"%tmpfile%"
|
set /p dir=<%tmpfile%
|
||||||
del /f "%tmpfile%"
|
del /f %tmpfile%
|
||||||
if not exist "%dir%" exit
|
if not exist "%dir%" exit
|
||||||
if "%dir%" == "%cd%" exit
|
if "%dir%" == "%cd%" exit
|
||||||
cd "%dir%"
|
cd /d "%dir%"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Change working dir in shell to last dir in lf on exit.
|
||||||
|
#
|
||||||
|
# You need to either copy the content of this file to your shell rc file
|
||||||
|
# (e.g. ~/.tcshrc) or source this file directly:
|
||||||
|
#
|
||||||
|
# setenv LF_HOME "${HOME}/.config/lf"
|
||||||
|
# [ -e "${LF_HOME}/lfcd.csh" ] && source "${LF_HOME}/lfcd.csh"
|
||||||
|
#
|
||||||
|
# You may also like to assign a key to this command:
|
||||||
|
#
|
||||||
|
# bindkey -c "^O" lfcd
|
||||||
|
#
|
||||||
|
alias lfcd 'set _=`mktemp` && lf -last-dir-path=$_ "\!*" && set _=`cat $_ && rm -f $_` && [ -d "$_" ] && cd "$_"'
|
||||||
+4
-4
@@ -38,13 +38,13 @@ map O $mimeopen --ask $f
|
|||||||
cmd open ${{
|
cmd open ${{
|
||||||
case $(file --mime-type $f -b) in
|
case $(file --mime-type $f -b) in
|
||||||
text/*) $EDITOR $fx;;
|
text/*) $EDITOR $fx;;
|
||||||
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# rename current file without overwrite
|
# define a custom 'rename' command without prompt for overwrite
|
||||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
# 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
|
||||||
|
|||||||
@@ -89,6 +89,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
app.nav.position()
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
|
case "icons":
|
||||||
|
gOpts.icons = true
|
||||||
|
case "noicons":
|
||||||
|
gOpts.icons = false
|
||||||
|
case "icons!":
|
||||||
|
gOpts.icons = !gOpts.icons
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -107,12 +113,32 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.incsearch = false
|
gOpts.incsearch = false
|
||||||
case "incsearch!":
|
case "incsearch!":
|
||||||
gOpts.incsearch = !gOpts.incsearch
|
gOpts.incsearch = !gOpts.incsearch
|
||||||
|
case "number":
|
||||||
|
gOpts.number = true
|
||||||
|
case "nonumber":
|
||||||
|
gOpts.number = false
|
||||||
|
case "number!":
|
||||||
|
gOpts.number = !gOpts.number
|
||||||
case "preview":
|
case "preview":
|
||||||
|
if len(gOpts.ratios) < 2 {
|
||||||
|
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||||
|
return
|
||||||
|
}
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
case "nopreview":
|
case "nopreview":
|
||||||
gOpts.preview = false
|
gOpts.preview = false
|
||||||
case "preview!":
|
case "preview!":
|
||||||
|
if len(gOpts.ratios) < 2 {
|
||||||
|
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||||
|
return
|
||||||
|
}
|
||||||
gOpts.preview = !gOpts.preview
|
gOpts.preview = !gOpts.preview
|
||||||
|
case "relativenumber":
|
||||||
|
gOpts.relativenumber = true
|
||||||
|
case "norelativenumber":
|
||||||
|
gOpts.relativenumber = false
|
||||||
|
case "relativenumber!":
|
||||||
|
gOpts.relativenumber = !gOpts.relativenumber
|
||||||
case "reverse":
|
case "reverse":
|
||||||
gOpts.sortType.option |= reverseSort
|
gOpts.sortType.option |= reverseSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
@@ -143,18 +169,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.wrapscan
|
gOpts.wrapscan = !gOpts.wrapscan
|
||||||
case "number":
|
case "wrapscroll":
|
||||||
gOpts.number = true
|
gOpts.wrapscroll = true
|
||||||
case "nonumber":
|
case "nowrapscroll":
|
||||||
gOpts.number = false
|
gOpts.wrapscroll = false
|
||||||
case "number!":
|
case "wrapscroll!":
|
||||||
gOpts.number = !gOpts.number
|
gOpts.wrapscroll = !gOpts.wrapscroll
|
||||||
case "relativenumber":
|
|
||||||
gOpts.relativenumber = true
|
|
||||||
case "norelativenumber":
|
|
||||||
gOpts.relativenumber = false
|
|
||||||
case "relativenumber!":
|
|
||||||
gOpts.relativenumber = !gOpts.relativenumber
|
|
||||||
case "findlen":
|
case "findlen":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -209,33 +229,41 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.errorfmt = e.val
|
gOpts.errorfmt = e.val
|
||||||
case "filesep":
|
case "filesep":
|
||||||
gOpts.filesep = e.val
|
gOpts.filesep = e.val
|
||||||
|
case "hiddenfiles":
|
||||||
|
toks := strings.Split(e.val, ":")
|
||||||
|
for _, s := range toks {
|
||||||
|
if s == "" {
|
||||||
|
app.ui.echoerr("hiddenfiles: glob should be non-empty")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err := filepath.Match(s, "a")
|
||||||
|
if err != nil {
|
||||||
|
app.ui.echoerrf("hiddenfiles: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gOpts.hiddenfiles = toks
|
||||||
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "ifs":
|
case "ifs":
|
||||||
gOpts.ifs = e.val
|
gOpts.ifs = e.val
|
||||||
|
case "info":
|
||||||
|
toks := strings.Split(e.val, ":")
|
||||||
|
for _, s := range toks {
|
||||||
|
switch s {
|
||||||
|
case "", "size", "time", "atime", "ctime":
|
||||||
|
default:
|
||||||
|
app.ui.echoerr("info: should consist of 'size', 'time', 'atime' or 'ctime' separated with colon")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gOpts.info = toks
|
||||||
case "previewer":
|
case "previewer":
|
||||||
gOpts.previewer = strings.Replace(e.val, "~", gUser.HomeDir, -1)
|
gOpts.previewer = replaceTilde(e.val)
|
||||||
case "promptfmt":
|
case "promptfmt":
|
||||||
gOpts.promptfmt = e.val
|
gOpts.promptfmt = e.val
|
||||||
case "shell":
|
|
||||||
gOpts.shell = e.val
|
|
||||||
case "sortby":
|
|
||||||
if e.val != "natural" && e.val != "name" && e.val != "size" && e.val != "time" {
|
|
||||||
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size' or 'time'")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch e.val {
|
|
||||||
case "natural":
|
|
||||||
gOpts.sortType.method = naturalSort
|
|
||||||
case "name":
|
|
||||||
gOpts.sortType.method = nameSort
|
|
||||||
case "size":
|
|
||||||
gOpts.sortType.method = sizeSort
|
|
||||||
case "time":
|
|
||||||
gOpts.sortType.method = timeSort
|
|
||||||
}
|
|
||||||
app.nav.sort()
|
|
||||||
app.ui.sort()
|
|
||||||
case "timefmt":
|
|
||||||
gOpts.timefmt = e.val
|
|
||||||
case "ratios":
|
case "ratios":
|
||||||
toks := strings.Split(e.val, ":")
|
toks := strings.Split(e.val, ":")
|
||||||
var rats []int
|
var rats []int
|
||||||
@@ -258,44 +286,79 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.ratios = rats
|
gOpts.ratios = rats
|
||||||
app.ui.wins = getWins()
|
app.ui.wins = getWins()
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
case "info":
|
case "shell":
|
||||||
toks := strings.Split(e.val, ":")
|
gOpts.shell = e.val
|
||||||
for _, s := range toks {
|
|
||||||
if s != "" && s != "size" && s != "time" {
|
|
||||||
app.ui.echoerr("info: should consist of 'size' or 'time' separated with colon")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gOpts.info = toks
|
|
||||||
case "shellopts":
|
case "shellopts":
|
||||||
gOpts.shellopts = strings.Split(e.val, ":")
|
gOpts.shellopts = strings.Split(e.val, ":")
|
||||||
|
case "sortby":
|
||||||
|
switch e.val {
|
||||||
|
case "natural":
|
||||||
|
gOpts.sortType.method = naturalSort
|
||||||
|
case "name":
|
||||||
|
gOpts.sortType.method = nameSort
|
||||||
|
case "size":
|
||||||
|
gOpts.sortType.method = sizeSort
|
||||||
|
case "time":
|
||||||
|
gOpts.sortType.method = timeSort
|
||||||
|
case "ctime":
|
||||||
|
gOpts.sortType.method = ctimeSort
|
||||||
|
case "atime":
|
||||||
|
gOpts.sortType.method = atimeSort
|
||||||
|
case "ext":
|
||||||
|
gOpts.sortType.method = extSort
|
||||||
|
default:
|
||||||
|
app.ui.echoerr("sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime' or 'ext'")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.nav.sort()
|
||||||
|
app.ui.sort()
|
||||||
|
case "timefmt":
|
||||||
|
gOpts.timefmt = e.val
|
||||||
|
case "truncatechar":
|
||||||
|
if runeSliceWidth([]rune(e.val)) != 1 {
|
||||||
|
app.ui.echoerr("truncatechar: value should be a single character")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gOpts.truncatechar = e.val
|
||||||
default:
|
default:
|
||||||
app.ui.echoerrf("unknown option: %s", e.opt)
|
app.ui.echoerrf("unknown option: %s", e.opt)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *mapExpr) eval(app *app, args []string) {
|
func (e *mapExpr) eval(app *app, args []string) {
|
||||||
if e.expr == nil {
|
if e.expr == nil {
|
||||||
delete(gOpts.keys, e.keys)
|
delete(gOpts.keys, e.keys)
|
||||||
return
|
} else {
|
||||||
|
gOpts.keys[e.keys] = e.expr
|
||||||
}
|
}
|
||||||
gOpts.keys[e.keys] = e.expr
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *cmapExpr) eval(app *app, args []string) {
|
func (e *cmapExpr) eval(app *app, args []string) {
|
||||||
if e.cmd == "" {
|
if e.cmd == "" {
|
||||||
delete(gOpts.cmdkeys, e.key)
|
delete(gOpts.cmdkeys, e.key)
|
||||||
return
|
} else {
|
||||||
|
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||||
}
|
}
|
||||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *cmdExpr) eval(app *app, args []string) {
|
func (e *cmdExpr) eval(app *app, args []string) {
|
||||||
if e.expr == nil {
|
if e.expr == nil {
|
||||||
delete(gOpts.cmds, e.name)
|
delete(gOpts.cmds, e.name)
|
||||||
return
|
} else {
|
||||||
|
gOpts.cmds[e.name] = e.expr
|
||||||
|
}
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
|
||||||
|
func onChdir(app *app) {
|
||||||
|
if cmd, ok := gOpts.cmds["on-cd"]; ok {
|
||||||
|
cmd.eval(app, nil)
|
||||||
}
|
}
|
||||||
gOpts.cmds[e.name] = e.expr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitKeys(s string) (keys []string) {
|
func splitKeys(s string) (keys []string) {
|
||||||
@@ -322,20 +385,13 @@ func update(app *app) {
|
|||||||
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
||||||
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
last.ind = app.nav.searchInd
|
dir.ind = app.nav.searchInd
|
||||||
last.pos = app.nav.searchPos
|
dir.pos = app.nav.searchPos
|
||||||
|
|
||||||
if app.nav.searchBack {
|
if err := app.nav.searchNext(); err != nil {
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
||||||
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)
|
||||||
@@ -343,20 +399,13 @@ func update(app *app) {
|
|||||||
case gOpts.incsearch && app.ui.cmdPrefix == "?":
|
case gOpts.incsearch && app.ui.cmdPrefix == "?":
|
||||||
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
last.ind = app.nav.searchInd
|
dir.ind = app.nav.searchInd
|
||||||
last.pos = app.nav.searchPos
|
dir.pos = app.nav.searchPos
|
||||||
|
|
||||||
if app.nav.searchBack {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
if err := app.nav.searchNext(); err != nil {
|
app.ui.echoerrf("search: %s: %s", err, app.nav.search)
|
||||||
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)
|
||||||
@@ -364,6 +413,13 @@ func update(app *app) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normal(app *app) {
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
}
|
||||||
|
|
||||||
func insert(app *app, arg string) {
|
func insert(app *app, arg string) {
|
||||||
switch {
|
switch {
|
||||||
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
||||||
@@ -397,10 +453,7 @@ func insert(app *app, arg string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case app.ui.cmdPrefix == "find-back: ":
|
case app.ui.cmdPrefix == "find-back: ":
|
||||||
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
@@ -429,31 +482,59 @@ func insert(app *app, arg string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
case strings.HasPrefix(app.ui.cmdPrefix, "delete"):
|
||||||
app.ui.cmdAccRight = nil
|
normal(app)
|
||||||
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 arg == "y" {
|
||||||
if err := app.nav.del(); err != nil {
|
if err := app.nav.del(app.ui); err != nil {
|
||||||
app.ui.echoerrf("delete: %s", err)
|
app.ui.echoerrf("delete: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := remote("send load"); err != nil {
|
if err := remote("send load"); err != nil {
|
||||||
app.ui.echoerrf("delete: %s", err)
|
app.ui.echoerrf("delete: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
case strings.HasPrefix(app.ui.cmdPrefix, "replace"):
|
||||||
|
normal(app)
|
||||||
|
|
||||||
|
if arg == "y" {
|
||||||
|
if err := app.nav.rename(); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
case strings.HasPrefix(app.ui.cmdPrefix, "create"):
|
||||||
|
normal(app)
|
||||||
|
|
||||||
|
if arg == "y" {
|
||||||
|
if err := os.MkdirAll(filepath.Dir(app.nav.renameNewPath), os.ModePerm); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.rename(); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
case app.ui.cmdPrefix == "mark-save: ":
|
case app.ui.cmdPrefix == "mark-save: ":
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -461,11 +542,14 @@ func insert(app *app, arg string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.marks[arg] = wd
|
app.nav.marks[arg] = wd
|
||||||
|
if err := app.nav.writeMarks(); err != nil {
|
||||||
|
app.ui.echoerrf("mark-save: %s", err)
|
||||||
|
}
|
||||||
|
if err := remote("send sync"); err != nil {
|
||||||
|
app.ui.echoerrf("mark-save: %s", err)
|
||||||
|
}
|
||||||
case app.ui.cmdPrefix == "mark-load: ":
|
case app.ui.cmdPrefix == "mark-load: ":
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -486,6 +570,20 @@ func insert(app *app, arg string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
|
}
|
||||||
|
case app.ui.cmdPrefix == "mark-remove: ":
|
||||||
|
normal(app)
|
||||||
|
if err := app.nav.removeMark(arg); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.writeMarks(); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := remote("send sync"); err != nil {
|
||||||
|
app.ui.echoerrf("mark-remove: %s", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
@@ -495,30 +593,51 @@ func insert(app *app, arg string) {
|
|||||||
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":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.up(e.count)
|
app.nav.up(e.count)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "half-up":
|
case "half-up":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.up(e.count * app.nav.height / 2)
|
app.nav.up(e.count * app.nav.height / 2)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "page-up":
|
case "page-up":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.up(e.count * app.nav.height)
|
app.nav.up(e.count * app.nav.height)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "down":
|
case "down":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.down(e.count)
|
app.nav.down(e.count)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "half-down":
|
case "half-down":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.down(e.count * app.nav.height / 2)
|
app.nav.down(e.count * app.nav.height / 2)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "page-down":
|
case "page-down":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
app.nav.down(e.count * app.nav.height)
|
app.nav.down(e.count * app.nav.height)
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "updir":
|
case "updir":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
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.echoerrf("%s", err)
|
app.ui.echoerrf("%s", err)
|
||||||
@@ -527,7 +646,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
onChdir(app)
|
||||||
case "open":
|
case "open":
|
||||||
|
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||||
|
normal(app)
|
||||||
|
}
|
||||||
curr, err := app.nav.currFile()
|
curr, err := app.nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.echoerrf("opening: %s", err)
|
app.ui.echoerrf("opening: %s", err)
|
||||||
@@ -542,6 +665,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
onChdir(app)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,11 +708,21 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "toggle":
|
case "toggle":
|
||||||
for i := 0; i < e.count; i++ {
|
if len(e.args) == 0 {
|
||||||
app.nav.toggle()
|
app.nav.toggle()
|
||||||
|
} else {
|
||||||
|
dir := app.nav.currDir()
|
||||||
|
for _, path := range e.args {
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(dir.path, path)
|
||||||
|
}
|
||||||
|
if _, err := os.Lstat(path); !os.IsNotExist(err) {
|
||||||
|
app.nav.toggleSelection(path)
|
||||||
|
} else {
|
||||||
|
app.ui.echoerrf("toggle: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
|
||||||
app.ui.loadFileInfo(app.nav)
|
|
||||||
case "invert":
|
case "invert":
|
||||||
app.nav.invert()
|
app.nav.invert()
|
||||||
case "unselect":
|
case "unselect":
|
||||||
@@ -601,7 +735,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := remote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.echoerrf("copy: %s", err)
|
app.ui.echoerrf("copy: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "cut":
|
case "cut":
|
||||||
if err := app.nav.save(false); err != nil {
|
if err := app.nav.save(false); err != nil {
|
||||||
app.ui.echoerrf("cut: %s", err)
|
app.ui.echoerrf("cut: %s", err)
|
||||||
@@ -610,7 +746,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := remote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.echoerrf("cut: %s", err)
|
app.ui.echoerrf("cut: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
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)
|
||||||
@@ -618,20 +756,31 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.echoerrf("paste: %s", err)
|
app.ui.echoerrf("paste: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "delete":
|
case "delete":
|
||||||
if cmd, ok := gOpts.cmds["delete"]; ok {
|
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
app.nav.unselect()
|
app.nav.unselect()
|
||||||
if err := remote("send load"); err != nil {
|
if err := remote("send load"); err != nil {
|
||||||
app.ui.echoerrf("delete: %s", err)
|
app.ui.echoerrf("delete: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, err := app.nav.currFileOrSelections(); err != nil {
|
list, err := app.nav.currFileOrSelections()
|
||||||
|
if err != nil {
|
||||||
app.ui.echoerrf("delete: %s", err)
|
app.ui.echoerrf("delete: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdPrefix = "delete?[y/N]: "
|
|
||||||
|
if len(list) == 1 {
|
||||||
|
app.ui.cmdPrefix = "delete '" + list[0] + "' ? [y/N] "
|
||||||
|
} else {
|
||||||
|
app.ui.cmdPrefix = "delete " + strconv.Itoa(len(list)) + " items? [y/N] "
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
app.ui.echoerrf("clear: %s", err)
|
app.ui.echoerrf("clear: %s", err)
|
||||||
@@ -639,34 +788,47 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
if err := remote("send sync"); err != nil {
|
if err := remote("send sync"); err != nil {
|
||||||
app.ui.echoerrf("clear: %s", err)
|
app.ui.echoerrf("clear: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "draw":
|
case "draw":
|
||||||
case "redraw":
|
case "redraw":
|
||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.nav.height = app.ui.wins[0].h
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "load":
|
case "load":
|
||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
if err := app.nav.reload(); err != nil {
|
if err := app.nav.reload(); err != nil {
|
||||||
app.ui.echoerrf("reload: %s", err)
|
app.ui.echoerrf("reload: %s", err)
|
||||||
}
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "shell":
|
case "shell":
|
||||||
app.ui.cmdPrefix = "$"
|
app.ui.cmdPrefix = "$"
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "shell-pipe":
|
case "shell-pipe":
|
||||||
app.ui.cmdPrefix = "%"
|
app.ui.cmdPrefix = "%"
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "shell-wait":
|
case "shell-wait":
|
||||||
app.ui.cmdPrefix = "!"
|
app.ui.cmdPrefix = "!"
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "shell-async":
|
case "shell-async":
|
||||||
app.ui.cmdPrefix = "&"
|
app.ui.cmdPrefix = "&"
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "find":
|
case "find":
|
||||||
app.ui.cmdPrefix = "find: "
|
app.ui.cmdPrefix = "find: "
|
||||||
app.nav.findBack = false
|
app.nav.findBack = false
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "find-back":
|
case "find-back":
|
||||||
app.ui.cmdPrefix = "find-back: "
|
app.ui.cmdPrefix = "find-back: "
|
||||||
app.nav.findBack = true
|
app.nav.findBack = true
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "find-next":
|
case "find-next":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if app.nav.findBack {
|
if app.nav.findBack {
|
||||||
@@ -689,16 +851,18 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search":
|
case "search":
|
||||||
app.ui.cmdPrefix = "/"
|
app.ui.cmdPrefix = "/"
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
app.nav.searchInd = last.ind
|
app.nav.searchInd = dir.ind
|
||||||
app.nav.searchPos = last.pos
|
app.nav.searchPos = dir.pos
|
||||||
app.nav.searchBack = false
|
app.nav.searchBack = false
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search-back":
|
case "search-back":
|
||||||
app.ui.cmdPrefix = "?"
|
app.ui.cmdPrefix = "?"
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
app.nav.searchInd = last.ind
|
app.nav.searchInd = dir.ind
|
||||||
app.nav.searchPos = last.pos
|
app.nav.searchPos = dir.pos
|
||||||
app.nav.searchBack = true
|
app.nav.searchBack = true
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search-next":
|
case "search-next":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
if app.nav.searchBack {
|
if app.nav.searchBack {
|
||||||
@@ -736,6 +900,27 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "mark-load":
|
case "mark-load":
|
||||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||||
app.ui.cmdPrefix = "mark-load: "
|
app.ui.cmdPrefix = "mark-load: "
|
||||||
|
case "mark-remove":
|
||||||
|
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||||
|
app.ui.cmdPrefix = "mark-remove: "
|
||||||
|
case "rename":
|
||||||
|
if cmd, ok := gOpts.cmds["rename"]; ok {
|
||||||
|
cmd.eval(app, e.args)
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
curr, err := app.nav.currFile()
|
||||||
|
if err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdPrefix = "rename: "
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "sync":
|
case "sync":
|
||||||
if err := app.nav.sync(); err != nil {
|
if err := app.nav.sync(); err != nil {
|
||||||
app.ui.echoerrf("sync: %s", err)
|
app.ui.echoerrf("sync: %s", err)
|
||||||
@@ -773,6 +958,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
}
|
}
|
||||||
case "select":
|
case "select":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
@@ -802,13 +988,33 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
if wd != path {
|
if wd != path {
|
||||||
app.nav.marks["'"] = wd
|
app.nav.marks["'"] = wd
|
||||||
|
onChdir(app)
|
||||||
|
}
|
||||||
|
case "glob-select":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.echoerr("glob-select: requires a pattern to match")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.globSel(e.args[0], false); err != nil {
|
||||||
|
app.ui.echoerrf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case "glob-unselect":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.echoerr("glob-unselect: requires a pattern to match")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.globSel(e.args[0], true); err != nil {
|
||||||
|
app.ui.echoerrf("%s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case "source":
|
case "source":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.echoerr("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(replaceTilde(e.args[0]))
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.echoerr("push: requires an argument")
|
app.ui.echoerr("push: requires an argument")
|
||||||
@@ -828,17 +1034,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
last.ind = app.nav.searchInd
|
dir.ind = app.nav.searchInd
|
||||||
last.pos = app.nav.searchPos
|
dir.pos = app.nav.searchPos
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "cmd-complete":
|
case "cmd-complete":
|
||||||
var matches []string
|
var matches []string
|
||||||
switch app.ui.cmdPrefix {
|
switch app.ui.cmdPrefix {
|
||||||
@@ -901,9 +1104,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.runShell(s, nil, "&")
|
app.runShell(s, nil, "&")
|
||||||
case "/":
|
case "/":
|
||||||
if gOpts.incsearch {
|
if gOpts.incsearch {
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
last.ind = app.nav.searchInd
|
dir.ind = app.nav.searchInd
|
||||||
last.pos = app.nav.searchPos
|
dir.pos = app.nav.searchPos
|
||||||
}
|
}
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
@@ -916,9 +1119,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
case "?":
|
case "?":
|
||||||
if gOpts.incsearch {
|
if gOpts.incsearch {
|
||||||
last := app.nav.currDir()
|
dir := app.nav.currDir()
|
||||||
last.ind = app.nav.searchInd
|
dir.ind = app.nav.searchInd
|
||||||
last.pos = app.nav.searchPos
|
dir.pos = app.nav.searchPos
|
||||||
}
|
}
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
@@ -926,6 +1129,61 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if err := app.nav.searchPrev(); err != nil {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
app.ui.echoerrf("search-back: %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.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
case "rename: ":
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
if curr, err := app.nav.currFile(); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
} else {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("getting current directory: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldPath := filepath.Join(wd, curr.Name())
|
||||||
|
|
||||||
|
newPath := filepath.Clean(s)
|
||||||
|
if !filepath.IsAbs(newPath) {
|
||||||
|
newPath = filepath.Join(wd, newPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if oldPath == newPath {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
app.nav.renameOldPath = oldPath
|
||||||
|
app.nav.renameNewPath = newPath
|
||||||
|
|
||||||
|
newDir := filepath.Dir(newPath)
|
||||||
|
if _, err := os.Stat(newDir); os.IsNotExist(err) {
|
||||||
|
app.ui.cmdPrefix = "create '" + newDir + "' ? [y/N] "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldStat, err := os.Stat(oldPath)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if newStat, err := os.Stat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {
|
||||||
|
app.ui.cmdPrefix = "replace '" + newPath + "' ? [y/N] "
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.nav.rename(); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
app.ui.echoerrf("rename: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
@@ -943,7 +1201,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ":"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||||
@@ -1013,8 +1271,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
update(app)
|
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 = []rune(string(app.ui.cmdAccLeft)[ind:])
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
|
||||||
update(app)
|
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...)
|
||||||
@@ -1029,34 +1287,31 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if app.cmd != nil {
|
if app.cmd != nil {
|
||||||
app.cmd.Process.Kill()
|
app.cmd.Process.Kill()
|
||||||
}
|
}
|
||||||
app.ui.menuBuf = nil
|
normal(app)
|
||||||
app.ui.cmdAccLeft = nil
|
|
||||||
app.ui.cmdAccRight = nil
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "cmd-word":
|
case "cmd-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[3]
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
case "cmd-word-back":
|
case "cmd-word-back":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
locs := reWordBeg.FindAllStringIndex(string(app.ui.cmdAccLeft), -1)
|
locs := reWordBeg.FindAllStringSubmatchIndex(string(app.ui.cmdAccLeft), -1)
|
||||||
if locs == nil {
|
if locs == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := locs[len(locs)-1][1] - 1
|
ind := locs[len(locs)-1][3]
|
||||||
old := app.ui.cmdAccRight
|
old := app.ui.cmdAccRight
|
||||||
app.ui.cmdAccRight = append([]rune{}, app.ui.cmdAccLeft[ind:]...)
|
app.ui.cmdAccRight = append([]rune{}, []rune(string(app.ui.cmdAccLeft)[ind:])...)
|
||||||
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
app.ui.cmdAccLeft = []rune(string(app.ui.cmdAccLeft)[:ind])
|
||||||
case "cmd-capitalize-word":
|
case "cmd-capitalize-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -1068,48 +1323,48 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
|
app.ui.cmdAccRight[ind] = unicode.ToUpper(app.ui.cmdAccRight[ind])
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind = loc[0] + 1
|
ind = loc[3]
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
update(app)
|
update(app)
|
||||||
case "cmd-delete-word":
|
case "cmd-delete-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[3]
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
update(app)
|
update(app)
|
||||||
case "cmd-uppercase-word":
|
case "cmd-uppercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[3]
|
||||||
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 = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
update(app)
|
update(app)
|
||||||
case "cmd-lowercase-word":
|
case "cmd-lowercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc == nil {
|
if loc == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[3]
|
||||||
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 = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
update(app)
|
update(app)
|
||||||
case "cmd-transpose-word":
|
case "cmd-transpose-word":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
@@ -1122,11 +1377,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(app.ui.cmdAccRight) > 0 {
|
if len(app.ui.cmdAccRight) > 0 {
|
||||||
loc := reWordEnd.FindStringIndex(string(app.ui.cmdAccRight))
|
loc := reWordEnd.FindStringSubmatchIndex(string(app.ui.cmdAccRight))
|
||||||
if loc != nil {
|
if loc != nil {
|
||||||
ind := loc[0] + 1
|
ind := loc[3]
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(string(app.ui.cmdAccRight)[:ind])...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = []rune(string(app.ui.cmdAccRight)[ind:])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1137,11 +1392,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
|
|
||||||
var acc []rune
|
var acc []rune
|
||||||
|
|
||||||
acc = append(acc, app.ui.cmdAccLeft[:beg1]...)
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[:beg1])...)
|
||||||
acc = append(acc, app.ui.cmdAccLeft[beg2:end2]...)
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg2:end2])...)
|
||||||
acc = append(acc, app.ui.cmdAccLeft[end1:beg2]...)
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end1:beg2])...)
|
||||||
acc = append(acc, app.ui.cmdAccLeft[beg1:end1]...)
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[beg1:end1])...)
|
||||||
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
acc = append(acc, []rune(string(app.ui.cmdAccLeft)[end2:])...)
|
||||||
|
|
||||||
app.ui.cmdAccLeft = acc
|
app.ui.cmdAccLeft = acc
|
||||||
update(app)
|
update(app)
|
||||||
@@ -1175,7 +1430,9 @@ func (e *execExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *listExpr) eval(app *app, args []string) {
|
func (e *listExpr) eval(app *app, args []string) {
|
||||||
for _, expr := range e.exprs {
|
for i := 0; i < e.count; i++ {
|
||||||
expr.eval(app, nil)
|
for _, expr := range e.exprs {
|
||||||
|
expr.eval(app, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+65
-27
@@ -67,8 +67,8 @@ var gEvalTests = []struct {
|
|||||||
|
|
||||||
{
|
{
|
||||||
`echo "hello\zworld"`,
|
`echo "hello\zworld"`,
|
||||||
[]string{"echo", "helloworld", "\n"},
|
[]string{"echo", `hello\zworld`, "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
[]expr{&callExpr{"echo", []string{`hello\zworld`}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -90,7 +90,7 @@ var gEvalTests = []struct {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo hello\ world`,
|
"echo hello\\\tworld",
|
||||||
[]string{"echo", "hello\tworld", "\n"},
|
[]string{"echo", "hello\tworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
[]expr{&callExpr{"echo", []string{"hello\tworld"}, 1}},
|
||||||
},
|
},
|
||||||
@@ -101,10 +101,16 @@ var gEvalTests = []struct {
|
|||||||
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
[]expr{&callExpr{"echo", []string{"hello\nworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`echo hello\\world`,
|
||||||
|
[]string{"echo", `hello\world`, "\n"},
|
||||||
|
[]expr{&callExpr{"echo", []string{`hello\world`}, 1}},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`echo hello\zworld`,
|
`echo hello\zworld`,
|
||||||
[]string{"echo", "helloworld", "\n"},
|
[]string{"echo", "hellozworld", "\n"},
|
||||||
[]expr{&callExpr{"echo", []string{"helloworld"}, 1}},
|
[]expr{&callExpr{"echo", []string{"hellozworld"}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -125,6 +131,18 @@ var gEvalTests = []struct {
|
|||||||
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
[]expr{&setExpr{"hidden", ""}, &setExpr{"preview", ""}},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`set ifs ""`,
|
||||||
|
[]string{"set", "ifs", "", "\n"},
|
||||||
|
[]expr{&setExpr{"ifs", ""}},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
`set ifs "\n"`,
|
||||||
|
[]string{"set", "ifs", "\n", "\n"},
|
||||||
|
[]expr{&setExpr{"ifs", "\n"}},
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"set ratios 1:2:3",
|
"set ratios 1:2:3",
|
||||||
[]string{"set", "ratios", "1:2:3", "\n"},
|
[]string{"set", "ratios", "1:2:3", "\n"},
|
||||||
@@ -140,25 +158,37 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
":set ratios 1:2:3",
|
":set ratios 1:2:3",
|
||||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n"},
|
[]string{":", "set", "ratios", "1:2:3", "\n", "\n"},
|
||||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
":set ratios 1:2:3\nset hidden",
|
":set ratios 1:2:3\nset hidden",
|
||||||
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
|
[]string{":", "set", "ratios", "1:2:3", "\n", "\n", "set", "hidden", "\n"},
|
||||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
":set ratios 1:2:3;",
|
":set ratios 1:2:3;",
|
||||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n"},
|
[]string{":", "set", "ratios", "1:2:3", ";", "\n"},
|
||||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}},
|
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
":set ratios 1:2:3;\nset hidden",
|
":set ratios 1:2:3;\nset hidden",
|
||||||
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
|
[]string{":", "set", "ratios", "1:2:3", ";", "\n", "set", "hidden", "\n"},
|
||||||
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}}, &setExpr{"hidden", ""}},
|
[]expr{&listExpr{[]expr{&setExpr{"ratios", "1:2:3"}}, 1}, &setExpr{"hidden", ""}},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"set ratios 1:2:3\n set hidden",
|
||||||
|
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
|
||||||
|
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"set ratios 1:2:3 \nset hidden",
|
||||||
|
[]string{"set", "ratios", "1:2:3", "\n", "set", "hidden", "\n"},
|
||||||
|
[]expr{&setExpr{"ratios", "1:2:3"}, &setExpr{"hidden", ""}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -176,13 +206,13 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map gh :cd ~",
|
"map gh :cd ~",
|
||||||
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
[]string{"map", "gh", ":", "cd", "~", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map gh :cd ~;",
|
"map gh :cd ~;",
|
||||||
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
[]string{"map", "gh", ":", "cd", "~", ";", "\n"},
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}}}},
|
[]expr{&mapExpr{"gh", &listExpr{[]expr{&callExpr{"cd", []string{"~"}, 1}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -218,13 +248,13 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map u :usage",
|
"map u :usage",
|
||||||
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
[]string{"map", "u", ":", "usage", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map u :usage;",
|
"map u :usage;",
|
||||||
[]string{"map", "u", ":", "usage", ";", "\n"},
|
[]string{"map", "u", ":", "usage", ";", "\n"},
|
||||||
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}}}},
|
[]expr{&mapExpr{"u", &listExpr{[]expr{&callExpr{"usage", nil, 1}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -248,13 +278,13 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map r :push :rename<space>",
|
"map r :push :rename<space>",
|
||||||
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
[]string{"map", "r", ":", "push", ":rename<space>", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}}}},
|
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map r :push :rename<space> ; set hidden",
|
"map r :push :rename<space> ; set hidden",
|
||||||
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
[]string{"map", "r", ":", "push", ":rename<space>", ";", "set", "hidden", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}}}},
|
[]expr{&mapExpr{"r", &listExpr{[]expr{&callExpr{"push", []string{":rename<space>"}, 1}, &setExpr{"hidden", ""}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -278,13 +308,13 @@ var gEvalTests = []struct {
|
|||||||
{
|
{
|
||||||
"map ss :set sortby size; set info size",
|
"map ss :set sortby size; set info size",
|
||||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", "\n", "\n"},
|
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", "\n", "\n"},
|
||||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}},
|
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"map ss :set sortby size; set info size;",
|
"map ss :set sortby size; set info size;",
|
||||||
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", ";", "\n"},
|
[]string{"map", "ss", ":", "set", "sortby", "size", ";", "set", "info", "size", ";", "\n"},
|
||||||
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}}},
|
[]expr{&mapExpr{"ss", &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}}},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -292,13 +322,17 @@ var gEvalTests = []struct {
|
|||||||
cd ~
|
cd ~
|
||||||
set hidden
|
set hidden
|
||||||
}}`,
|
}}`,
|
||||||
[]string{"cmd", "gohome", ":", "{{",
|
[]string{
|
||||||
|
"cmd", "gohome", ":", "{{",
|
||||||
"cd", "~", "\n",
|
"cd", "~", "\n",
|
||||||
"set", "hidden", "\n",
|
"set", "hidden", "\n",
|
||||||
"}}", "\n"},
|
"}}", "\n",
|
||||||
[]expr{&cmdExpr{"gohome", &listExpr{[]expr{
|
},
|
||||||
&callExpr{"cd", []string{"~"}, 1},
|
[]expr{&cmdExpr{
|
||||||
&setExpr{"hidden", ""}}},
|
"gohome", &listExpr{[]expr{
|
||||||
|
&callExpr{"cd", []string{"~"}, 1},
|
||||||
|
&setExpr{"hidden", ""},
|
||||||
|
}, 1},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -307,13 +341,17 @@ var gEvalTests = []struct {
|
|||||||
cd ~
|
cd ~
|
||||||
set hidden
|
set hidden
|
||||||
}}`,
|
}}`,
|
||||||
[]string{"map", "gh", ":", "{{",
|
[]string{
|
||||||
|
"map", "gh", ":", "{{",
|
||||||
"cd", "~", "\n",
|
"cd", "~", "\n",
|
||||||
"set", "hidden", "\n",
|
"set", "hidden", "\n",
|
||||||
"}}", "\n"},
|
"}}", "\n",
|
||||||
[]expr{&mapExpr{"gh", &listExpr{[]expr{
|
},
|
||||||
&callExpr{"cd", []string{"~"}, 1},
|
[]expr{&mapExpr{
|
||||||
&setExpr{"hidden", ""}}},
|
"gh", &listExpr{[]expr{
|
||||||
|
&callExpr{"cd", []string{"~"}, 1},
|
||||||
|
&setExpr{"hidden", ""},
|
||||||
|
}, 1},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ module github.com/gokcehan/lf
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/mattn/go-runewidth v0.0.4
|
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14
|
||||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e
|
github.com/mattn/go-runewidth v0.0.9
|
||||||
|
gopkg.in/djherbis/times.v1 v1.2.0
|
||||||
)
|
)
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
github.com/doronbehar/termbox-go v0.0.0-20190817171036-93860e161317 h1:mdOm+1RdYwVwC4Wjb53M5L96fRwWJ8gI7YXwwiCsHTk=
|
||||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/doronbehar/termbox-go v0.0.0-20190817171036-93860e161317/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c h1:qvLYQAhDCaMq+XiQ+t4YLaTJtUyHC1r20odd6ryKYIk=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20191006140624-aa2cdd26fb8c/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05 h1:pmXx7j8+mmkFJB2+qoB1C/Mz8SWvMlHTxSWOptJrr7E=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20191006141301-8c9470559e05/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14 h1:KKPl27Vj3HRF384G7jW7K8uCRv0Ks+GuAOkGsz4qWAs=
|
||||||
|
github.com/doronbehar/termbox-go v0.0.0-20200711071547-71407e3bfa14/go.mod h1:cHYbFQiZNC8LPG6clYoLMKAl0xx7KR75RPsHtG/f1Hk=
|
||||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
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/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/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
|
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
|
||||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
gopkg.in/djherbis/times.v1 v1.2.0/go.mod h1:AQlg6unIsrsCEdQYhTzERy542dz6SFdQFZFv6mUY0P8=
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type iconMap map[string]string
|
||||||
|
|
||||||
|
func parseIcons() iconMap {
|
||||||
|
if env := os.Getenv("LF_ICONS"); env != "" {
|
||||||
|
return parseIconsEnv(env)
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultIcons := []string{
|
||||||
|
"tw=🗀",
|
||||||
|
"st=🗀",
|
||||||
|
"ow=🗀",
|
||||||
|
"di=🗀",
|
||||||
|
"fi=🗎",
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseIconsEnv(strings.Join(defaultIcons, ":"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseIconsEnv(env string) iconMap {
|
||||||
|
icons := make(iconMap)
|
||||||
|
|
||||||
|
entries := strings.Split(env, ":")
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pair := strings.Split(entry, "=")
|
||||||
|
if len(pair) != 2 {
|
||||||
|
log.Printf("invalid $LF_ICONS entry: %s", entry)
|
||||||
|
return icons
|
||||||
|
}
|
||||||
|
key, val := pair[0], pair[1]
|
||||||
|
icons[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
return icons
|
||||||
|
}
|
||||||
|
|
||||||
|
func (im iconMap) get(f *file) string {
|
||||||
|
var key string
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||||
|
key = "tw"
|
||||||
|
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||||
|
key = "st"
|
||||||
|
case f.IsDir() && f.Mode()&0002 != 0:
|
||||||
|
key = "ow"
|
||||||
|
case f.IsDir():
|
||||||
|
key = "di"
|
||||||
|
case f.linkState == working:
|
||||||
|
key = "ln"
|
||||||
|
case f.linkState == broken:
|
||||||
|
key = "or"
|
||||||
|
case f.Mode()&os.ModeNamedPipe != 0:
|
||||||
|
key = "pi"
|
||||||
|
case f.Mode()&os.ModeSocket != 0:
|
||||||
|
key = "so"
|
||||||
|
case f.Mode()&os.ModeCharDevice != 0:
|
||||||
|
key = "cd"
|
||||||
|
case f.Mode()&os.ModeDevice != 0:
|
||||||
|
key = "bd"
|
||||||
|
case f.Mode()&os.ModeSetuid != 0:
|
||||||
|
key = "su"
|
||||||
|
case f.Mode()&os.ModeSetgid != 0:
|
||||||
|
key = "sg"
|
||||||
|
case f.Mode().IsRegular() && f.Mode()&0111 != 0:
|
||||||
|
key = "ex"
|
||||||
|
default:
|
||||||
|
key = "*" + filepath.Ext(f.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := im[key]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := im["fi"]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
return " "
|
||||||
|
}
|
||||||
@@ -37,7 +37,6 @@ The following commands are provided by lf with default keybindings:
|
|||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg' and '<home>')
|
top (default 'gg' and '<home>')
|
||||||
bottom (default 'G' and '<end>')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unselect (default 'u')
|
unselect (default 'u')
|
||||||
copy (default 'y')
|
copy (default 'y')
|
||||||
@@ -47,6 +46,7 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
|
rename (default 'r')
|
||||||
shell (default '$')
|
shell (default '$')
|
||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
@@ -61,22 +61,26 @@ The following commands are provided by lf with default keybindings:
|
|||||||
search-prev (default 'N')
|
search-prev (default 'N')
|
||||||
mark-save (default 'm')
|
mark-save (default 'm')
|
||||||
mark-load (default "'")
|
mark-load (default "'")
|
||||||
|
mark-remove (default `"`)
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
load load modified files and directories
|
load load modified files and directories
|
||||||
sync synchronize copied/cut files with server
|
sync synchronize copied/cut files with server
|
||||||
echo print arguments to the message line
|
echo print arguments to the message line
|
||||||
echomsg same as echo but logging
|
echomsg same as echo but logging
|
||||||
echoerr same as echomsg but red color
|
echoerr same as echomsg but red color
|
||||||
cd change working directory to the argument
|
cd change working directory to the argument
|
||||||
select change current file selection to the argument
|
select change current file selection to the argument
|
||||||
source read the configuration file in the argument
|
toggle toggle the selection of the current file or its arguments
|
||||||
push simulate key pushes given in the argument
|
glob-select select files that match the given glob
|
||||||
delete remove the current file or selected file(s)
|
glob-unselect unselect files that match the given glob
|
||||||
|
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:
|
||||||
@@ -118,31 +122,35 @@ The following options can be used to customize the behavior of lf:
|
|||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
|
icons boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
ignoredia boolean (default off)
|
ignoredia boolean (default off)
|
||||||
incsearch boolean (default off)
|
incsearch boolean (default off)
|
||||||
|
number boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
|
relativenumber boolean (default off)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
smartdia boolean (default off)
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
number boolean (default off)
|
wrapscroll boolean (default off)
|
||||||
relativenumber boolean (default off)
|
|
||||||
findlen integer (default 1) (zero to prompt until single match)
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
period integer (default 0) (zero to disable periodic loading)
|
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")
|
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)
|
hiddenfiles string (default '.*')
|
||||||
previewer string (default ”) (not filtered if empty)
|
ifs string (default '') (not exported if empty)
|
||||||
|
info string (default '')
|
||||||
|
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")
|
||||||
|
ratios string (default '1:2:3')
|
||||||
shell string (default 'sh')
|
shell string (default 'sh')
|
||||||
|
shellopts string (default '')
|
||||||
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')
|
truncatechar string (default '~')
|
||||||
info 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:
|
||||||
@@ -191,7 +199,11 @@ The following additional keybindings are provided by default:
|
|||||||
map sn :set sortby natural; set info
|
map sn :set sortby natural; set info
|
||||||
map ss :set sortby size; set info size
|
map ss :set sortby size; set info size
|
||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
|
map sa :set sortby atime; set info atime
|
||||||
|
map sc :set sortby ctime; set info ctime
|
||||||
|
map se :set sortby ext; set info
|
||||||
map gh cd ~
|
map gh cd ~
|
||||||
|
map <space> :toggle; down
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The following keybindings to applications are provided by default:
|
The following keybindings to applications are provided by default:
|
||||||
@@ -243,11 +255,9 @@ The following command prefixes are used by lf:
|
|||||||
% shell-pipe shell command running with the ui
|
% shell-pipe shell command running with the ui
|
||||||
! shell-wait shell command waiting for key press
|
! shell-wait shell command waiting for key press
|
||||||
& shell-async shell command running asynchronously
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
|
||||||
? search-back search file in the reverse order
|
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default. Searching commands are only used from the command line.
|
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default.
|
||||||
.SH SYNTAX
|
.SH SYNTAX
|
||||||
Characters from '#' to newline are comments and ignored:
|
Characters from '#' to newline are comments and ignored:
|
||||||
.PP
|
.PP
|
||||||
@@ -531,7 +541,7 @@ There is a 'quit' command to close client connections and quit the server:
|
|||||||
.PP
|
.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 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.
|
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. For cross-device moving, lf falls back to copying and then deletes the original files if there are no errors. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
|
||||||
.PP
|
.PP
|
||||||
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
|
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
|
.PP
|
||||||
@@ -558,7 +568,14 @@ By default, lf does not assign 'delete' command to a key to protect new users. Y
|
|||||||
.SH SEARCHING FILES
|
.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.
|
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
|
.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.
|
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. Alternatively, you can also map some other commands with 'cmap' to accept the search and execute the command immediately afterwards. Possible candidates are 'up', 'down' and their variants, 'updir', and 'open' commands. For example, you can use arrow keys to finish the search with the following mappings:
|
||||||
|
.PP
|
||||||
|
.EX
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
cmap <left> updir
|
||||||
|
cmap <right> open
|
||||||
|
.EE
|
||||||
.PP
|
.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.
|
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
|
.PP
|
||||||
@@ -587,6 +604,8 @@ You may want to use either file extensions or mime types from 'file' command:
|
|||||||
}}
|
}}
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
|
You may want to use 'setsid' before your opener command to have persistent processes that continue to run after lf quits.
|
||||||
|
.PP
|
||||||
Following command is provided by default:
|
Following command is provided by default:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
@@ -622,6 +641,33 @@ Since this script is called for each file selection change it needs to be as eff
|
|||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
Another important consideration for efficiency is the use of programs with short startup times for preview. For this reason, 'highlight' is recommended over 'pygmentize' for syntax highlighting. Besides, it is also important that the application is processing the file on the fly rather than first reading it to the memory and then do the processing afterwards. This is especially relevant for big files. lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read. When everything else fails, you can make use of the height argument to only feed the first portion of the file to a program for preview.
|
Another important consideration for efficiency is the use of programs with short startup times for preview. For this reason, 'highlight' is recommended over 'pygmentize' for syntax highlighting. Besides, it is also important that the application is processing the file on the fly rather than first reading it to the memory and then do the processing afterwards. This is especially relevant for big files. lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read. When everything else fails, you can make use of the height argument to only feed the first portion of the file to a program for preview.
|
||||||
|
.SH CHANGING DIRECTORY
|
||||||
|
lf changes the working directory of the process to the current directory so that shell commands always work in the displayed directory. After quitting, it returns to the original directory where it is first launched like all shell programs. If you want to stay in the current directory after quitting, you can use one of the example wrapper shell scripts provided in the repository.
|
||||||
|
.PP
|
||||||
|
There is a special command 'on-cd' that runs a shell command when it is defined and the directory is changed. You can define it just as you would define any other command:
|
||||||
|
.PP
|
||||||
|
.EX
|
||||||
|
cmd on-cd &{{
|
||||||
|
# display git repository status in your prompt
|
||||||
|
source /usr/share/git/completion/git-prompt.sh
|
||||||
|
GIT_PS1_SHOWDIRTYSTATE=auto
|
||||||
|
GIT_PS1_SHOWSTASHSTATE=auto
|
||||||
|
GIT_PS1_SHOWUNTRACKEDFILES=auto
|
||||||
|
GIT_PS1_SHOWUPSTREAM=auto
|
||||||
|
git=$(__git_ps1 " (%s)") || true
|
||||||
|
fmt="\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w\e033[0m\e033[1m%f$git\e033[0m"
|
||||||
|
lf -remote "send $id set promptfmt \e"$fmt\e""
|
||||||
|
}}
|
||||||
|
.EE
|
||||||
|
.PP
|
||||||
|
This command runs whenever you change directory but not on startup. You can add an extra call to make it run on startup as well:
|
||||||
|
.PP
|
||||||
|
.EX
|
||||||
|
cmd on-cd &{{ # ... }}
|
||||||
|
on-cd
|
||||||
|
.EE
|
||||||
|
.PP
|
||||||
|
Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively.
|
||||||
.SH COLORSCHEMES
|
.SH COLORSCHEMES
|
||||||
lf tries to automatically adapt its colors to the environment. On startup, first '$LS_COLORS' environment variable is checked. This variable is used by GNU ls to configure its colors based on file types and extensions. The value of this variable is often set by GNU dircolors in a shell configuration file. dircolors program itself can be configured with a configuration file. dircolors supports 256 colors along with common attributes such as bold and underline.
|
lf tries to automatically adapt its colors to the environment. On startup, first '$LS_COLORS' environment variable is checked. This variable is used by GNU ls to configure its colors based on file types and extensions. The value of this variable is often set by GNU dircolors in a shell configuration file. dircolors program itself can be configured with a configuration file. dircolors supports 256 colors along with common attributes such as bold and underline.
|
||||||
.PP
|
.PP
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=lf
|
||||||
|
Comment=Launches the lf file manager
|
||||||
|
Icon=utilities-terminal
|
||||||
|
Terminal=true
|
||||||
|
Exec=lf
|
||||||
|
Categories=ConsoleOnly;System;FileTools;FileManager
|
||||||
|
MimeType=inode/directory;
|
||||||
@@ -63,6 +63,7 @@ func exportEnvVars() {
|
|||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
cmd := detachedCommand(os.Args[0], "-server")
|
cmd := detachedCommand(os.Args[0], "-server")
|
||||||
|
cmd.Dir = gUser.HomeDir
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
log.Printf("starting server: %s", err)
|
log.Printf("starting server: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ import (
|
|||||||
|
|
||||||
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
func isRoot(name string) bool { return filepath.Dir(name) == name }
|
||||||
|
|
||||||
|
func replaceTilde(s string) string {
|
||||||
|
if strings.HasPrefix(s, "~") {
|
||||||
|
s = strings.Replace(s, "~", gUser.HomeDir, 1)
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
func runeSliceWidth(rs []rune) int {
|
func runeSliceWidth(rs []rune) int {
|
||||||
w := 0
|
w := 0
|
||||||
for _, r := range rs {
|
for _, r := range rs {
|
||||||
@@ -41,22 +48,12 @@ func runeSliceWidthRange(rs []rune, beg, end int) []rune {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to escape whitespaces with backlashes in a given
|
// This function is used to escape whitespaces and special characters with
|
||||||
// string. If a whitespace is already escaped then it is not escaped again.
|
// backlashes in a given string.
|
||||||
func escape(s string) string {
|
func escape(s string) string {
|
||||||
esc := false
|
|
||||||
buf := make([]rune, 0, len(s))
|
buf := make([]rune, 0, len(s))
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
if r == '\\' {
|
if unicode.IsSpace(r) || r == '\\' || r == ';' || r == '#' {
|
||||||
esc = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if esc {
|
|
||||||
esc = false
|
|
||||||
buf = append(buf, '\\', r)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if unicode.IsSpace(r) {
|
|
||||||
buf = append(buf, '\\')
|
buf = append(buf, '\\')
|
||||||
}
|
}
|
||||||
buf = append(buf, r)
|
buf = append(buf, r)
|
||||||
@@ -65,26 +62,29 @@ func escape(s string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This function is used to remove backlashes that are used to escape
|
// This function is used to remove backlashes that are used to escape
|
||||||
// whitespaces in a given string.
|
// whitespaces and special characters in a given string.
|
||||||
func unescape(s string) string {
|
func unescape(s string) string {
|
||||||
esc := false
|
esc := false
|
||||||
buf := make([]rune, 0, len(s))
|
buf := make([]rune, 0, len(s))
|
||||||
for _, r := range s {
|
for _, r := range s {
|
||||||
|
if esc {
|
||||||
|
if !unicode.IsSpace(r) && r != '\\' && r != ';' && r != '#' {
|
||||||
|
buf = append(buf, '\\')
|
||||||
|
}
|
||||||
|
buf = append(buf, r)
|
||||||
|
esc = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
if r == '\\' {
|
if r == '\\' {
|
||||||
esc = true
|
esc = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if esc {
|
esc = false
|
||||||
esc = false
|
|
||||||
if unicode.IsSpace(r) {
|
|
||||||
buf = append(buf, r)
|
|
||||||
} else {
|
|
||||||
buf = append(buf, '\\', r)
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf = append(buf, r)
|
buf = append(buf, r)
|
||||||
}
|
}
|
||||||
|
if esc {
|
||||||
|
buf = append(buf, '\\')
|
||||||
|
}
|
||||||
return string(buf)
|
return string(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-3
@@ -80,8 +80,13 @@ func TestEscape(t *testing.T) {
|
|||||||
{"foo", "foo"},
|
{"foo", "foo"},
|
||||||
{"foo bar", `foo\ bar`},
|
{"foo bar", `foo\ bar`},
|
||||||
{"foo bar", `foo\ \ bar`},
|
{"foo bar", `foo\ \ bar`},
|
||||||
{`foo\ bar`, `foo\ bar`},
|
{`foo\bar`, `foo\\bar`},
|
||||||
{`foo\bar`, `foo\bar`},
|
{`foo\ bar`, `foo\\\ bar`},
|
||||||
|
{`foo;bar`, `foo\;bar`},
|
||||||
|
{`foo#bar`, `foo\#bar`},
|
||||||
|
{`foo\tbar`, `foo\\tbar`},
|
||||||
|
{"foo\tbar", "foo\\\tbar"},
|
||||||
|
{`foo\`, `foo\\`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -98,9 +103,15 @@ func TestUnescape(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"", ""},
|
{"", ""},
|
||||||
{"foo", "foo"},
|
{"foo", "foo"},
|
||||||
{`foo\bar`, `foo\bar`},
|
|
||||||
{`foo\ bar`, "foo bar"},
|
{`foo\ bar`, "foo bar"},
|
||||||
{`foo\ \ bar`, "foo bar"},
|
{`foo\ \ bar`, "foo bar"},
|
||||||
|
{`foo\\bar`, `foo\bar`},
|
||||||
|
{`foo\\\ bar`, `foo\ bar`},
|
||||||
|
{`foo\;bar`, `foo;bar`},
|
||||||
|
{`foo\#bar`, `foo#bar`},
|
||||||
|
{`foo\\tbar`, `foo\tbar`},
|
||||||
|
{"foo\\\tbar", "foo\tbar"},
|
||||||
|
{`foo\`, `foo\`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
times "gopkg.in/djherbis/times.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type linkState byte
|
type linkState byte
|
||||||
@@ -25,9 +27,13 @@ const (
|
|||||||
|
|
||||||
type file struct {
|
type file struct {
|
||||||
os.FileInfo
|
os.FileInfo
|
||||||
linkState linkState
|
linkState linkState
|
||||||
path string
|
linkTarget string
|
||||||
dirCount int
|
path string
|
||||||
|
dirCount int
|
||||||
|
accessTime time.Time
|
||||||
|
changeTime time.Time
|
||||||
|
ext string
|
||||||
}
|
}
|
||||||
|
|
||||||
func readdir(path string) ([]*file, error) {
|
func readdir(path string) ([]*file, error) {
|
||||||
@@ -51,6 +57,7 @@ func readdir(path string) ([]*file, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var linkState linkState
|
var linkState linkState
|
||||||
|
var linkTarget string
|
||||||
|
|
||||||
if lstat.Mode()&os.ModeSymlink != 0 {
|
if lstat.Mode()&os.ModeSymlink != 0 {
|
||||||
stat, err := os.Stat(fpath)
|
stat, err := os.Stat(fpath)
|
||||||
@@ -60,13 +67,36 @@ func readdir(path string) ([]*file, error) {
|
|||||||
} else {
|
} else {
|
||||||
linkState = broken
|
linkState = broken
|
||||||
}
|
}
|
||||||
|
linkTarget, err = os.Readlink(fpath)
|
||||||
|
if err != nil {
|
||||||
|
return files, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ts := times.Get(lstat)
|
||||||
|
at := ts.AccessTime()
|
||||||
|
var ct time.Time
|
||||||
|
// from times docs: ChangeTime() panics unless HasChangeTime() is true
|
||||||
|
if ts.HasChangeTime() {
|
||||||
|
ct = ts.ChangeTime()
|
||||||
|
} else {
|
||||||
|
// fall back to ModTime if ChangeTime cannot be determined
|
||||||
|
ct = lstat.ModTime()
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns an empty string if extension could not be determined
|
||||||
|
// i.e. directories, filenames without extensions
|
||||||
|
ext := filepath.Ext(fpath)
|
||||||
|
|
||||||
files = append(files, &file{
|
files = append(files, &file{
|
||||||
FileInfo: lstat,
|
FileInfo: lstat,
|
||||||
linkState: linkState,
|
linkState: linkState,
|
||||||
path: fpath,
|
linkTarget: linkTarget,
|
||||||
dirCount: -1,
|
path: fpath,
|
||||||
|
dirCount: -1,
|
||||||
|
accessTime: at,
|
||||||
|
changeTime: ct,
|
||||||
|
ext: ext,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +112,7 @@ type dir struct {
|
|||||||
files []*file // displayed files in directory including or excluding hidden ones
|
files []*file // displayed files in directory including or excluding hidden ones
|
||||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||||
sortType sortType // sort method and options from last sort
|
sortType sortType // sort method and options from last sort
|
||||||
|
noPerm bool // whether lf has no permission to open the directory
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDir(path string) *dir {
|
func newDir(path string) *dir {
|
||||||
@@ -97,6 +128,7 @@ func newDir(path string) *dir {
|
|||||||
path: path,
|
path: path,
|
||||||
files: files,
|
files: files,
|
||||||
allFiles: files,
|
allFiles: files,
|
||||||
|
noPerm: os.IsPermission(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +154,34 @@ func (dir *dir) sort() {
|
|||||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
return dir.files[i].ModTime().Before(dir.files[j].ModTime())
|
||||||
})
|
})
|
||||||
|
case atimeSort:
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
return dir.files[i].accessTime.Before(dir.files[j].accessTime)
|
||||||
|
})
|
||||||
|
case ctimeSort:
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
return dir.files[i].changeTime.Before(dir.files[j].changeTime)
|
||||||
|
})
|
||||||
|
case extSort:
|
||||||
|
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||||
|
leftExt := strings.ToLower(dir.files[i].ext)
|
||||||
|
rightExt := strings.ToLower(dir.files[j].ext)
|
||||||
|
|
||||||
|
// if the extension could not be determined (directories, files without)
|
||||||
|
// use a zero byte so that these files can be ranked higher
|
||||||
|
if leftExt == "" {
|
||||||
|
leftExt = "\x00"
|
||||||
|
}
|
||||||
|
if rightExt == "" {
|
||||||
|
rightExt = "\x00"
|
||||||
|
}
|
||||||
|
|
||||||
|
// in order to also have natural sorting with the filenames
|
||||||
|
// combine the name with the ext but have the ext at the front
|
||||||
|
left := leftExt + strings.ToLower(dir.files[i].Name())
|
||||||
|
right := rightExt + strings.ToLower(dir.files[j].Name())
|
||||||
|
return left < right
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.sortType.option&reverseSort != 0 {
|
if gOpts.sortType.option&reverseSort != 0 {
|
||||||
@@ -144,13 +204,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 isHidden(dir.files[i]) && isHidden(dir.files[j]) {
|
if isHidden(dir.files[i], dir.path) && isHidden(dir.files[j], dir.path) {
|
||||||
return i < j
|
return i < j
|
||||||
}
|
}
|
||||||
return isHidden(dir.files[i])
|
return isHidden(dir.files[i], dir.path)
|
||||||
})
|
})
|
||||||
for i, f := range dir.files {
|
for i, f := range dir.files {
|
||||||
if !isHidden(f) {
|
if !isHidden(f, dir.path) {
|
||||||
dir.files = dir.files[i:]
|
dir.files = dir.files[i:]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -188,74 +248,84 @@ func (dir *dir) sel(name string, height int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type nav struct {
|
type nav struct {
|
||||||
dirs []*dir
|
dirs []*dir
|
||||||
copyBytes int64
|
copyBytes int64
|
||||||
copyTotal int64
|
copyTotal int64
|
||||||
copyUpdate int
|
copyUpdate int
|
||||||
moveCount int
|
moveCount int
|
||||||
moveTotal int
|
moveTotal int
|
||||||
moveUpdate int
|
moveUpdate int
|
||||||
copyBytesChan chan int64
|
deleteCount int
|
||||||
copyTotalChan chan int64
|
deleteTotal int
|
||||||
moveCountChan chan int
|
deleteUpdate int
|
||||||
moveTotalChan chan int
|
copyBytesChan chan int64
|
||||||
dirChan chan *dir
|
copyTotalChan chan int64
|
||||||
regChan chan *reg
|
moveCountChan chan int
|
||||||
dirCache map[string]*dir
|
moveTotalChan chan int
|
||||||
regCache map[string]*reg
|
deleteCountChan chan int
|
||||||
saves map[string]bool
|
deleteTotalChan chan int
|
||||||
marks map[string]string
|
dirChan chan *dir
|
||||||
selections map[string]int
|
regChan chan *reg
|
||||||
selectionInd int
|
dirCache map[string]*dir
|
||||||
height int
|
regCache map[string]*reg
|
||||||
find string
|
saves map[string]bool
|
||||||
findBack bool
|
marks map[string]string
|
||||||
search string
|
renameOldPath string
|
||||||
searchBack bool
|
renameNewPath string
|
||||||
searchInd int
|
selections map[string]int
|
||||||
searchPos int
|
selectionInd int
|
||||||
|
height int
|
||||||
|
find string
|
||||||
|
findBack bool
|
||||||
|
search string
|
||||||
|
searchBack bool
|
||||||
|
searchInd int
|
||||||
|
searchPos int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDir(path string) *dir {
|
func (nav *nav) loadDir(path string) *dir {
|
||||||
d, ok := nav.dirCache[path]
|
d, ok := nav.dirCache[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
d := &dir{loading: true, loadTime: time.Now(), path: path, sortType: gOpts.sortType}
|
||||||
|
nav.dirCache[path] = d
|
||||||
go func() {
|
go func() {
|
||||||
d := newDir(path)
|
d := newDir(path)
|
||||||
d.sort()
|
d.sort()
|
||||||
d.ind, d.pos = 0, 0
|
d.ind, d.pos = 0, 0
|
||||||
nav.dirChan <- d
|
nav.dirChan <- d
|
||||||
}()
|
}()
|
||||||
d := &dir{loading: true, path: path, sortType: gOpts.sortType}
|
|
||||||
nav.dirCache[path] = d
|
|
||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := os.Stat(d.path)
|
nav.checkDir(d)
|
||||||
|
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) checkDir(dir *dir) {
|
||||||
|
s, err := os.Stat(dir.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d
|
log.Printf("getting directory info: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case s.ModTime().After(d.loadTime):
|
case s.ModTime().After(dir.loadTime):
|
||||||
|
dir.loading = true
|
||||||
|
dir.loadTime = time.Now()
|
||||||
go func() {
|
go func() {
|
||||||
d.loadTime = time.Now()
|
nd := newDir(dir.path)
|
||||||
nd := newDir(path)
|
|
||||||
nd.sort()
|
nd.sort()
|
||||||
nd.sel(d.name(), nav.height)
|
|
||||||
nav.dirChan <- nd
|
nav.dirChan <- nd
|
||||||
}()
|
}()
|
||||||
case d.sortType != gOpts.sortType:
|
case dir.sortType != gOpts.sortType:
|
||||||
|
dir.loading = true
|
||||||
go func() {
|
go func() {
|
||||||
d.loading = true
|
dir.sort()
|
||||||
name := d.name()
|
dir.loading = false
|
||||||
d.sort()
|
nav.dirChan <- dir
|
||||||
d.sel(name, nav.height)
|
|
||||||
d.loading = false
|
|
||||||
nav.dirChan <- d
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
return d
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) getDirs(wd string) {
|
func (nav *nav) getDirs(wd string) {
|
||||||
@@ -281,19 +351,21 @@ func newNav(height int) *nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nav := &nav{
|
nav := &nav{
|
||||||
copyBytesChan: make(chan int64, 1024),
|
copyBytesChan: make(chan int64, 1024),
|
||||||
copyTotalChan: make(chan int64, 1024),
|
copyTotalChan: make(chan int64, 1024),
|
||||||
moveCountChan: make(chan int, 1024),
|
moveCountChan: make(chan int, 1024),
|
||||||
moveTotalChan: make(chan int, 1024),
|
moveTotalChan: make(chan int, 1024),
|
||||||
dirChan: make(chan *dir),
|
deleteCountChan: make(chan int, 1024),
|
||||||
regChan: make(chan *reg),
|
deleteTotalChan: make(chan int, 1024),
|
||||||
dirCache: make(map[string]*dir),
|
dirChan: make(chan *dir),
|
||||||
regCache: make(map[string]*reg),
|
regChan: make(chan *reg),
|
||||||
saves: make(map[string]bool),
|
dirCache: make(map[string]*dir),
|
||||||
marks: make(map[string]string),
|
regCache: make(map[string]*reg),
|
||||||
selections: make(map[string]int),
|
saves: make(map[string]bool),
|
||||||
selectionInd: 0,
|
marks: make(map[string]string),
|
||||||
height: height,
|
selections: make(map[string]int),
|
||||||
|
selectionInd: 0,
|
||||||
|
height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.getDirs(wd)
|
nav.getDirs(wd)
|
||||||
@@ -303,27 +375,15 @@ func newNav(height int) *nav {
|
|||||||
|
|
||||||
func (nav *nav) renew() {
|
func (nav *nav) renew() {
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
go func(d *dir) {
|
nav.checkDir(d)
|
||||||
s, err := os.Stat(d.path)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("getting directory info: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if d.loadTime.After(s.ModTime()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
d.loadTime = time.Now()
|
|
||||||
nd := newDir(d.path)
|
|
||||||
nd.sort()
|
|
||||||
nav.dirChan <- nd
|
|
||||||
}(d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for m := range nav.selections {
|
for m := range nav.selections {
|
||||||
if _, err := os.Stat(m); os.IsNotExist(err) {
|
if _, err := os.Lstat(m); os.IsNotExist(err) {
|
||||||
delete(nav.selections, m)
|
delete(nav.selections, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(nav.selections) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
nav.selectionInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
@@ -362,6 +422,8 @@ func (nav *nav) preview() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||||
|
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
|
|
||||||
if len(gOpts.previewer) != 0 {
|
if len(gOpts.previewer) != 0 {
|
||||||
@@ -389,8 +451,6 @@ func (nav *nav) preview() {
|
|||||||
reader = f
|
reader = f
|
||||||
}
|
}
|
||||||
|
|
||||||
reg := ®{loadTime: time.Now(), path: curr.path}
|
|
||||||
|
|
||||||
buf := bufio.NewScanner(reader)
|
buf := bufio.NewScanner(reader)
|
||||||
|
|
||||||
for i := 0; i < nav.height && buf.Scan(); i++ {
|
for i := 0; i < nav.height && buf.Scan(); i++ {
|
||||||
@@ -411,28 +471,32 @@ func (nav *nav) preview() {
|
|||||||
nav.regChan <- reg
|
nav.regChan <- reg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadReg(ui *ui, path string) *reg {
|
func (nav *nav) loadReg(path string) *reg {
|
||||||
r, ok := nav.regCache[path]
|
r, ok := nav.regCache[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
go nav.preview()
|
r := ®{loading: true, loadTime: time.Now(), path: path}
|
||||||
r := ®{loading: true, path: path}
|
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
s, err := os.Stat(r.path)
|
|
||||||
if err != nil {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.ModTime().After(r.loadTime) {
|
|
||||||
r.loadTime = time.Now()
|
|
||||||
go nav.preview()
|
go nav.preview()
|
||||||
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav.checkReg(r)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) checkReg(reg *reg) {
|
||||||
|
s, err := os.Stat(reg.path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.ModTime().After(reg.loadTime) {
|
||||||
|
reg.loadTime = time.Now()
|
||||||
|
go nav.preview()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) sort() {
|
func (nav *nav) sort() {
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
name := d.name()
|
name := d.name()
|
||||||
@@ -445,6 +509,9 @@ func (nav *nav) up(dist int) {
|
|||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
if dir.ind == 0 {
|
if dir.ind == 0 {
|
||||||
|
if gOpts.wrapscroll {
|
||||||
|
nav.bottom()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,6 +529,9 @@ func (nav *nav) down(dist int) {
|
|||||||
maxind := len(dir.files) - 1
|
maxind := len(dir.files) - 1
|
||||||
|
|
||||||
if dir.ind >= maxind {
|
if dir.ind >= maxind {
|
||||||
|
if gOpts.wrapscroll {
|
||||||
|
nav.top()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -547,14 +617,12 @@ func (nav *nav) toggle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nav.toggleSelection(curr.path)
|
nav.toggleSelection(curr.path)
|
||||||
|
|
||||||
nav.down(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) invert() {
|
func (nav *nav) invert() {
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for _, f := range last.files {
|
for _, f := range dir.files {
|
||||||
path := filepath.Join(last.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
nav.toggleSelection(path)
|
nav.toggleSelection(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -626,6 +694,10 @@ loop:
|
|||||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
ui.exprChan <- echo
|
ui.exprChan <- echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errCount == 0 {
|
||||||
|
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mCopied successfully\033[0m"}, 1}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
||||||
@@ -664,15 +736,54 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
|||||||
var newPath string
|
var newPath string
|
||||||
for i := 1; !os.IsNotExist(err); i++ {
|
for i := 1; !os.IsNotExist(err); i++ {
|
||||||
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
newPath = fmt.Sprintf("%s.~%d~", dst, i)
|
||||||
_, err = os.Stat(newPath)
|
_, err = os.Lstat(newPath)
|
||||||
}
|
}
|
||||||
dst = newPath
|
dst = newPath
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Rename(src, dst); err != nil {
|
if err := os.Rename(src, dst); err != nil {
|
||||||
errCount++
|
if errCrossDevice(err) {
|
||||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
total, err := copySize([]string{src})
|
||||||
ui.exprChan <- echo
|
if err != nil {
|
||||||
|
echo.args[0] = err.Error()
|
||||||
|
ui.exprChan <- echo
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.copyTotalChan <- total
|
||||||
|
|
||||||
|
nums, errs := copyAll([]string{src}, dstDir)
|
||||||
|
|
||||||
|
oldCount := errCount
|
||||||
|
loop:
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case n := <-nums:
|
||||||
|
nav.copyBytesChan <- n
|
||||||
|
case err, ok := <-errs:
|
||||||
|
if !ok {
|
||||||
|
break loop
|
||||||
|
}
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nav.copyTotalChan <- -total
|
||||||
|
|
||||||
|
if errCount == oldCount {
|
||||||
|
if err := os.RemoveAll(src); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,6 +794,10 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
|
|||||||
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
ui.exprChan <- echo
|
ui.exprChan <- echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if errCount == 0 {
|
||||||
|
ui.exprChan <- &callExpr{"echo", []string{"\033[0;32mMoved successfully\033[0m"}, 1}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) paste(ui *ui) error {
|
func (nav *nav) paste(ui *ui) error {
|
||||||
@@ -714,19 +829,61 @@ func (nav *nav) paste(ui *ui) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) del() error {
|
func (nav *nav) del(ui *ui) error {
|
||||||
list, err := nav.currFileOrSelections()
|
list, err := nav.currFileOrSelections()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range list {
|
go func() {
|
||||||
if err := os.RemoveAll(path); err != nil {
|
echo := &callExpr{"echoerr", []string{""}, 1}
|
||||||
return err
|
errCount := 0
|
||||||
|
|
||||||
|
nav.deleteTotalChan <- len(list)
|
||||||
|
|
||||||
|
for _, path := range list {
|
||||||
|
nav.deleteCountChan <- 1
|
||||||
|
|
||||||
|
if err := os.RemoveAll(path); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav.deleteTotalChan <- -len(list)
|
||||||
|
|
||||||
|
if err := remote("send load"); err != nil {
|
||||||
|
errCount++
|
||||||
|
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
|
||||||
|
ui.exprChan <- echo
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) rename() error {
|
||||||
|
oldPath := nav.renameOldPath
|
||||||
|
newPath := nav.renameNewPath
|
||||||
|
|
||||||
|
if err := os.Rename(oldPath, newPath); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lstat, err := os.Lstat(newPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := nav.loadDir(filepath.Dir(newPath))
|
||||||
|
|
||||||
|
if dir.loading {
|
||||||
|
dir.files = append(dir.files, &file{FileInfo: lstat})
|
||||||
|
}
|
||||||
|
|
||||||
|
dir.sel(lstat.Name(), nav.height)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,11 +898,11 @@ func (nav *nav) sync() error {
|
|||||||
nav.saves[f] = cp
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nav.readMarks()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) cd(wd string) error {
|
func (nav *nav) cd(wd string) error {
|
||||||
wd = strings.Replace(wd, "~", gUser.HomeDir, -1)
|
wd = replaceTilde(wd)
|
||||||
wd = filepath.Clean(wd)
|
wd = filepath.Clean(wd)
|
||||||
|
|
||||||
if !filepath.IsAbs(wd) {
|
if !filepath.IsAbs(wd) {
|
||||||
@@ -762,7 +919,10 @@ func (nav *nav) cd(wd string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) sel(path string) error {
|
func (nav *nav) sel(path string) error {
|
||||||
lstat, err := os.Stat(path)
|
path = replaceTilde(path)
|
||||||
|
path = filepath.Clean(path)
|
||||||
|
|
||||||
|
lstat, err := os.Lstat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("select: %s", err)
|
return fmt.Errorf("select: %s", err)
|
||||||
}
|
}
|
||||||
@@ -776,10 +936,36 @@ func (nav *nav) sel(path string) error {
|
|||||||
base := filepath.Base(path)
|
base := filepath.Base(path)
|
||||||
|
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
if last.loading {
|
if last.loading {
|
||||||
last.files = append(last.files, &file{FileInfo: lstat})
|
last.files = append(last.files, &file{FileInfo: lstat})
|
||||||
} else {
|
}
|
||||||
last.sel(base, nav.height)
|
|
||||||
|
last.sel(base, nav.height)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) globSel(pattern string, invert bool) error {
|
||||||
|
dir := nav.currDir()
|
||||||
|
anyMatched := false
|
||||||
|
|
||||||
|
for i := 0; i < len(dir.files); i++ {
|
||||||
|
matched, err := filepath.Match(pattern, dir.files[i].Name())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("glob-select: %s", err)
|
||||||
|
}
|
||||||
|
if matched {
|
||||||
|
anyMatched = true
|
||||||
|
fpath := filepath.Join(dir.path, dir.files[i].Name())
|
||||||
|
if _, ok := nav.selections[fpath]; ok == invert {
|
||||||
|
nav.toggleSelection(fpath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !anyMatched {
|
||||||
|
return fmt.Errorf("glob-select: pattern not found: %s", pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -809,9 +995,9 @@ func findMatch(name, pattern string) bool {
|
|||||||
func (nav *nav) findSingle() int {
|
func (nav *nav) findSingle() int {
|
||||||
count := 0
|
count := 0
|
||||||
index := 0
|
index := 0
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := 0; i < len(last.files); i++ {
|
for i := 0; i < len(dir.files); i++ {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
count++
|
count++
|
||||||
if count > 1 {
|
if count > 1 {
|
||||||
return count
|
return count
|
||||||
@@ -820,27 +1006,27 @@ func (nav *nav) findSingle() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if count == 1 {
|
if count == 1 {
|
||||||
if index > last.ind {
|
if index > dir.ind {
|
||||||
nav.down(index - last.ind)
|
nav.down(index - dir.ind)
|
||||||
} else {
|
} else {
|
||||||
nav.up(last.ind - index)
|
nav.up(dir.ind - index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) findNext() bool {
|
func (nav *nav) findNext() bool {
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.files); i++ {
|
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
nav.down(i - last.ind)
|
nav.down(i - dir.ind)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
for i := 0; i < dir.ind; i++ {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
nav.up(last.ind - i)
|
nav.up(dir.ind - i)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -849,17 +1035,17 @@ func (nav *nav) findNext() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) findPrev() bool {
|
func (nav *nav) findPrev() bool {
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
for i := dir.ind - 1; i >= 0; i-- {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
nav.up(last.ind - i)
|
nav.up(dir.ind - i)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||||
if findMatch(last.files[i].Name(), nav.find) {
|
if findMatch(dir.files[i].Name(), nav.find) {
|
||||||
nav.down(i - last.ind)
|
nav.down(i - dir.ind)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -889,25 +1075,25 @@ func searchMatch(name, pattern string) (matched bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) searchNext() error {
|
func (nav *nav) searchNext() error {
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.files); i++ {
|
for i := dir.ind + 1; i < len(dir.files); i++ {
|
||||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if matched {
|
if matched {
|
||||||
nav.down(i - last.ind)
|
nav.down(i - dir.ind)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
for i := 0; i < dir.ind; i++ {
|
||||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if matched {
|
if matched {
|
||||||
nav.up(last.ind - i)
|
nav.up(dir.ind - i)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -916,25 +1102,25 @@ func (nav *nav) searchNext() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) searchPrev() error {
|
func (nav *nav) searchPrev() error {
|
||||||
last := nav.currDir()
|
dir := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
for i := dir.ind - 1; i >= 0; i-- {
|
||||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if matched {
|
if matched {
|
||||||
nav.up(last.ind - i)
|
nav.up(dir.ind - i)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
for i := len(dir.files) - 1; i > dir.ind; i-- {
|
||||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
matched, err := searchMatch(dir.files[i].Name(), nav.search)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if matched {
|
if matched {
|
||||||
nav.down(i - last.ind)
|
nav.down(i - dir.ind)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -942,7 +1128,16 @@ func (nav *nav) searchPrev() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) removeMark(mark string) error {
|
||||||
|
if _, ok := nav.marks[mark]; ok {
|
||||||
|
delete(nav.marks, mark)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("no such mark")
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) readMarks() error {
|
func (nav *nav) readMarks() error {
|
||||||
|
nav.marks = make(map[string]string)
|
||||||
f, err := os.Open(gMarksPath)
|
f, err := os.Open(gMarksPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return nil
|
return nil
|
||||||
@@ -968,14 +1163,6 @@ func (nav *nav) readMarks() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) writeMarks() error {
|
func (nav *nav) writeMarks() error {
|
||||||
if len(nav.marks) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := nav.readMarks(); err != nil {
|
|
||||||
return fmt.Errorf("reading marks file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||||
return fmt.Errorf("creating data directory: %s", err)
|
return fmt.Errorf("creating data directory: %s", err)
|
||||||
}
|
}
|
||||||
@@ -1007,12 +1194,12 @@ func (nav *nav) currDir() *dir {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) currFile() (*file, error) {
|
func (nav *nav) currFile() (*file, error) {
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
dir := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
if len(last.files) == 0 {
|
if len(dir.files) == 0 {
|
||||||
return nil, fmt.Errorf("empty directory")
|
return nil, fmt.Errorf("empty directory")
|
||||||
}
|
}
|
||||||
return last.files[last.ind], nil
|
return dir.files[dir.ind], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type indexedSelections struct {
|
type indexedSelections struct {
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ const (
|
|||||||
nameSort
|
nameSort
|
||||||
sizeSort
|
sizeSort
|
||||||
timeSort
|
timeSort
|
||||||
|
atimeSort
|
||||||
|
ctimeSort
|
||||||
|
extSort
|
||||||
)
|
)
|
||||||
|
|
||||||
type sortOption byte
|
type sortOption byte
|
||||||
@@ -30,15 +33,17 @@ var gOpts struct {
|
|||||||
dircounts bool
|
dircounts bool
|
||||||
drawbox bool
|
drawbox bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
|
icons bool
|
||||||
ignorecase bool
|
ignorecase bool
|
||||||
incsearch bool
|
|
||||||
preview bool
|
|
||||||
smartcase bool
|
|
||||||
ignoredia bool
|
ignoredia bool
|
||||||
|
incsearch bool
|
||||||
|
number bool
|
||||||
|
preview bool
|
||||||
|
relativenumber bool
|
||||||
|
smartcase bool
|
||||||
smartdia bool
|
smartdia bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
number bool
|
wrapscroll bool
|
||||||
relativenumber bool
|
|
||||||
findlen int
|
findlen int
|
||||||
period int
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
@@ -50,7 +55,9 @@ var gOpts struct {
|
|||||||
promptfmt string
|
promptfmt string
|
||||||
shell string
|
shell string
|
||||||
timefmt string
|
timefmt string
|
||||||
|
truncatechar string
|
||||||
ratios []int
|
ratios []int
|
||||||
|
hiddenfiles []string
|
||||||
info []string
|
info []string
|
||||||
shellopts []string
|
shellopts []string
|
||||||
keys map[string]expr
|
keys map[string]expr
|
||||||
@@ -65,15 +72,17 @@ func init() {
|
|||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
gOpts.drawbox = false
|
gOpts.drawbox = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
|
gOpts.icons = false
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
gOpts.incsearch = false
|
|
||||||
gOpts.preview = true
|
|
||||||
gOpts.smartcase = true
|
|
||||||
gOpts.ignoredia = false
|
gOpts.ignoredia = false
|
||||||
|
gOpts.incsearch = false
|
||||||
|
gOpts.number = false
|
||||||
|
gOpts.preview = true
|
||||||
|
gOpts.relativenumber = false
|
||||||
|
gOpts.smartcase = true
|
||||||
gOpts.smartdia = false
|
gOpts.smartdia = false
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
gOpts.number = false
|
gOpts.wrapscroll = false
|
||||||
gOpts.relativenumber = false
|
|
||||||
gOpts.findlen = 1
|
gOpts.findlen = 1
|
||||||
gOpts.period = 0
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
@@ -82,10 +91,12 @@ func init() {
|
|||||||
gOpts.filesep = "\n"
|
gOpts.filesep = "\n"
|
||||||
gOpts.ifs = ""
|
gOpts.ifs = ""
|
||||||
gOpts.previewer = ""
|
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
|
||||||
|
gOpts.truncatechar = "~"
|
||||||
gOpts.ratios = []int{1, 2, 3}
|
gOpts.ratios = []int{1, 2, 3}
|
||||||
|
gOpts.hiddenfiles = []string{".*"}
|
||||||
gOpts.info = nil
|
gOpts.info = nil
|
||||||
gOpts.shellopts = nil
|
gOpts.shellopts = nil
|
||||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||||
@@ -111,7 +122,7 @@ func init() {
|
|||||||
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
||||||
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
||||||
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
||||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
gOpts.keys["<space>"] = &listExpr{[]expr{&callExpr{"toggle", nil, 1}, &callExpr{"down", nil, 1}}, 1}
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||||
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
gOpts.keys["u"] = &callExpr{"unselect", nil, 1}
|
||||||
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||||
@@ -135,6 +146,8 @@ func init() {
|
|||||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||||
|
gOpts.keys[`"`] = &callExpr{"mark-remove", nil, 1}
|
||||||
|
gOpts.keys[`r`] = &callExpr{"rename", nil, 1}
|
||||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||||
|
|
||||||
@@ -144,9 +157,12 @@ func init() {
|
|||||||
gOpts.keys["zs"] = &setExpr{"info", "size"}
|
gOpts.keys["zs"] = &setExpr{"info", "size"}
|
||||||
gOpts.keys["zt"] = &setExpr{"info", "time"}
|
gOpts.keys["zt"] = &setExpr{"info", "time"}
|
||||||
gOpts.keys["za"] = &setExpr{"info", "size:time"}
|
gOpts.keys["za"] = &setExpr{"info", "size:time"}
|
||||||
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}}
|
gOpts.keys["sn"] = &listExpr{[]expr{&setExpr{"sortby", "natural"}, &setExpr{"info", ""}}, 1}
|
||||||
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}}
|
gOpts.keys["ss"] = &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}
|
||||||
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}}
|
gOpts.keys["st"] = &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1}
|
||||||
|
gOpts.keys["sa"] = &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1}
|
||||||
|
gOpts.keys["sc"] = &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1}
|
||||||
|
gOpts.keys["se"] = &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1}
|
||||||
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
gOpts.keys["gh"] = &callExpr{"cd", []string{"~"}, 1}
|
||||||
|
|
||||||
gOpts.cmdkeys = make(map[string]expr)
|
gOpts.cmdkeys = make(map[string]expr)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -125,16 +126,40 @@ func setDefaults() {
|
|||||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
|
||||||
fmt.Printf("\033[%d;%dH", y, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isExecutable(f os.FileInfo) bool {
|
func isExecutable(f os.FileInfo) bool {
|
||||||
return f.Mode()&0111 != 0
|
return f.Mode()&0111 != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func isHidden(f os.FileInfo) bool {
|
func isHidden(f os.FileInfo, path string) bool {
|
||||||
return f.Name()[0] == '.'
|
hidden := false
|
||||||
|
for _, pattern := range gOpts.hiddenfiles {
|
||||||
|
matched := matchPattern(strings.TrimPrefix(pattern, "!"), f.Name(), path)
|
||||||
|
if strings.HasPrefix(pattern, "!") && matched {
|
||||||
|
hidden = false
|
||||||
|
} else if matched {
|
||||||
|
hidden = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hidden
|
||||||
|
}
|
||||||
|
|
||||||
|
func matchPattern(pattern, name, path string) bool {
|
||||||
|
s := name
|
||||||
|
|
||||||
|
pattern = replaceTilde(pattern)
|
||||||
|
|
||||||
|
if filepath.IsAbs(pattern) {
|
||||||
|
s = filepath.Join(path, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// pattern errors are checked when 'hiddenfiles' option is set
|
||||||
|
matched, _ := filepath.Match(pattern, s)
|
||||||
|
|
||||||
|
return matched
|
||||||
|
}
|
||||||
|
|
||||||
|
func errCrossDevice(err error) bool {
|
||||||
|
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportFiles(f string, fs []string) {
|
func exportFiles(f string, fs []string) {
|
||||||
|
|||||||
+15
-11
@@ -18,9 +18,7 @@ var (
|
|||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var envPathExt = os.Getenv("PATHEXT")
|
||||||
envPathExt = os.Getenv("PATHEXT")
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gDefaultShell = "cmd"
|
gDefaultShell = "cmd"
|
||||||
@@ -100,11 +98,6 @@ func setDefaults() {
|
|||||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
|
||||||
// TODO: implement
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func isExecutable(f os.FileInfo) bool {
|
func isExecutable(f os.FileInfo) bool {
|
||||||
exts := strings.Split(envPathExt, string(filepath.ListSeparator))
|
exts := strings.Split(envPathExt, string(filepath.ListSeparator))
|
||||||
for _, e := range exts {
|
for _, e := range exts {
|
||||||
@@ -116,9 +109,20 @@ func isExecutable(f os.FileInfo) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isHidden(f os.FileInfo) bool {
|
func isHidden(f os.FileInfo, path string) bool {
|
||||||
// TODO: implement
|
ptr, err := syscall.UTF16PtrFromString(filepath.Join(path, f.Name()))
|
||||||
return false
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
attrs, err := syscall.GetFileAttributes(ptr)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func errCrossDevice(err error) bool {
|
||||||
|
return err.(*os.LinkError).Err.(syscall.Errno) == 17
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportFiles(f string, fs []string) {
|
func exportFiles(f string, fs []string) {
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ func (e *execExpr) String() string {
|
|||||||
|
|
||||||
type listExpr struct {
|
type listExpr struct {
|
||||||
exprs []expr
|
exprs []expr
|
||||||
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *listExpr) String() string {
|
func (e *listExpr) String() string {
|
||||||
@@ -265,7 +266,7 @@ func (p *parser) parseExpr() expr {
|
|||||||
|
|
||||||
s.scan()
|
s.scan()
|
||||||
|
|
||||||
result = &listExpr{exprs}
|
result = &listExpr{exprs, 1}
|
||||||
case tokenPrefix:
|
case tokenPrefix:
|
||||||
var expr string
|
var expr string
|
||||||
|
|
||||||
|
|||||||
@@ -177,9 +177,6 @@ scan:
|
|||||||
s.tok = string(s.buf[beg:s.off])
|
s.tok = string(s.buf[beg:s.off])
|
||||||
s.cmd = false
|
s.cmd = false
|
||||||
s.sem = true
|
s.sem = true
|
||||||
case s.chr == '\r':
|
|
||||||
s.next()
|
|
||||||
goto scan
|
|
||||||
case s.chr == '\n':
|
case s.chr == '\n':
|
||||||
if s.sem {
|
if s.sem {
|
||||||
s.typ = tokenSemicolon
|
s.typ = tokenSemicolon
|
||||||
@@ -196,7 +193,7 @@ scan:
|
|||||||
}
|
}
|
||||||
goto scan
|
goto scan
|
||||||
case isSpace(s.chr):
|
case isSpace(s.chr):
|
||||||
for !s.eof && isSpace(s.chr) {
|
for !s.eof && isSpace(s.chr) && s.chr != '\n' {
|
||||||
s.next()
|
s.next()
|
||||||
}
|
}
|
||||||
goto scan
|
goto scan
|
||||||
@@ -216,25 +213,24 @@ scan:
|
|||||||
for !s.eof && s.chr != '"' {
|
for !s.eof && s.chr != '"' {
|
||||||
if s.chr == '\\' {
|
if s.chr == '\\' {
|
||||||
s.next()
|
s.next()
|
||||||
switch s.chr {
|
switch {
|
||||||
case '"', '\\':
|
case s.chr == '"' || s.chr == '\\':
|
||||||
buf = append(buf, s.chr)
|
buf = append(buf, s.chr)
|
||||||
case 'a':
|
case s.chr == 'a':
|
||||||
buf = append(buf, '\a')
|
buf = append(buf, '\a')
|
||||||
case 'b':
|
case s.chr == 'b':
|
||||||
buf = append(buf, '\b')
|
buf = append(buf, '\b')
|
||||||
case 'f':
|
case s.chr == 'f':
|
||||||
buf = append(buf, '\f')
|
buf = append(buf, '\f')
|
||||||
case 'n':
|
case s.chr == 'n':
|
||||||
buf = append(buf, '\n')
|
buf = append(buf, '\n')
|
||||||
case 'r':
|
case s.chr == 'r':
|
||||||
buf = append(buf, '\r')
|
buf = append(buf, '\r')
|
||||||
case 't':
|
case s.chr == 't':
|
||||||
buf = append(buf, '\t')
|
buf = append(buf, '\t')
|
||||||
case 'v':
|
case s.chr == 'v':
|
||||||
buf = append(buf, '\v')
|
buf = append(buf, '\v')
|
||||||
}
|
case isDigit(s.chr):
|
||||||
if isDigit(s.chr) {
|
|
||||||
var oct []byte
|
var oct []byte
|
||||||
for isDigit(s.chr) {
|
for isDigit(s.chr) {
|
||||||
oct = append(oct, s.chr)
|
oct = append(oct, s.chr)
|
||||||
@@ -245,13 +241,15 @@ scan:
|
|||||||
log.Printf("scanning: %s", err)
|
log.Printf("scanning: %s", err)
|
||||||
}
|
}
|
||||||
buf = append(buf, byte(n))
|
buf = append(buf, byte(n))
|
||||||
} else {
|
continue
|
||||||
s.next()
|
default:
|
||||||
|
buf = append(buf, '\\', s.chr)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
buf = append(buf, s.chr)
|
|
||||||
s.next()
|
s.next()
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
buf = append(buf, s.chr)
|
||||||
|
s.next()
|
||||||
}
|
}
|
||||||
s.typ = tokenIdent
|
s.typ = tokenIdent
|
||||||
s.tok = string(buf)
|
s.tok = string(buf)
|
||||||
@@ -293,12 +291,9 @@ scan:
|
|||||||
for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {
|
for !s.eof && !isSpace(s.chr) && s.chr != ';' && s.chr != '#' {
|
||||||
if s.chr == '\\' {
|
if s.chr == '\\' {
|
||||||
s.next()
|
s.next()
|
||||||
if isSpace(s.chr) {
|
buf = append(buf, s.chr)
|
||||||
buf = append(buf, s.chr)
|
s.next()
|
||||||
s.next()
|
continue
|
||||||
} else {
|
|
||||||
s.next()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buf = append(buf, s.chr)
|
buf = append(buf, s.chr)
|
||||||
s.next()
|
s.next()
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ func listen(l net.Listener) {
|
|||||||
func handleConn(c net.Conn) {
|
func handleConn(c net.Conn) {
|
||||||
s := bufio.NewScanner(c)
|
s := bufio.NewScanner(c)
|
||||||
|
|
||||||
|
Loop:
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
log.Printf("listen: %s", s.Text())
|
log.Printf("listen: %s", s.Text())
|
||||||
word, rest := splitWord(s.Text())
|
word, rest := splitWord(s.Text())
|
||||||
@@ -71,7 +72,7 @@ func handleConn(c net.Conn) {
|
|||||||
gCopyFile = false
|
gCopyFile = false
|
||||||
default:
|
default:
|
||||||
log.Printf("unexpected option to copy file(s): %s", s.Text())
|
log.Printf("unexpected option to copy file(s): %s", s.Text())
|
||||||
break
|
break Loop
|
||||||
}
|
}
|
||||||
gFileList = nil
|
gFileList = nil
|
||||||
for s.Scan() && s.Text() != "" {
|
for s.Scan() && s.Text() != "" {
|
||||||
@@ -120,7 +121,7 @@ func handleConn(c net.Conn) {
|
|||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
gListener.Close()
|
gListener.Close()
|
||||||
break
|
break Loop
|
||||||
default:
|
default:
|
||||||
log.Printf("listen: unexpected command: %s", word)
|
log.Printf("listen: unexpected command: %s", word)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ import (
|
|||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/doronbehar/termbox-go"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
"github.com/nsf/termbox-go"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const gEscapeCode = 27
|
const gEscapeCode = 27
|
||||||
@@ -153,7 +153,11 @@ func (win *win) print(x, y int, fg, bg termbox.Attribute, s string) (termbox.Att
|
|||||||
i += w - 1
|
i += w - 1
|
||||||
|
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
x += gOpts.tabstop - (x-off)%gOpts.tabstop
|
s := gOpts.tabstop - (x-off)%gOpts.tabstop
|
||||||
|
for i := 0; i < s && x+i < win.w; i++ {
|
||||||
|
termbox.SetCell(win.x+x+i, win.y+y, ' ', fg, bg)
|
||||||
|
}
|
||||||
|
x += s
|
||||||
} else {
|
} else {
|
||||||
x += runewidth.RuneWidth(r)
|
x += runewidth.RuneWidth(r)
|
||||||
}
|
}
|
||||||
@@ -190,8 +194,6 @@ func (win *win) printReg(reg *reg) {
|
|||||||
for i, l := range reg.lines {
|
for i, l := range reg.lines {
|
||||||
fg, bg = win.print(2, i, fg, bg, l)
|
fg, bg = win.print(2, i, fg, bg, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileInfo(f *file, d *dir) string {
|
func fileInfo(f *file, d *dir) string {
|
||||||
@@ -233,6 +235,10 @@ func fileInfo(f *file, d *dir) string {
|
|||||||
}
|
}
|
||||||
case "time":
|
case "time":
|
||||||
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
info = fmt.Sprintf("%s %12s", info, f.ModTime().Format("Jan _2 15:04"))
|
||||||
|
case "atime":
|
||||||
|
info = fmt.Sprintf("%s %12s", info, f.accessTime.Format("Jan _2 15:04"))
|
||||||
|
case "ctime":
|
||||||
|
info = fmt.Sprintf("%s %12s", info, f.changeTime.Format("Jan _2 15:04"))
|
||||||
default:
|
default:
|
||||||
log.Printf("unknown info type: %s", s)
|
log.Printf("unknown info type: %s", s)
|
||||||
}
|
}
|
||||||
@@ -241,7 +247,7 @@ func fileInfo(f *file, d *dir) string {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap, icons iconMap) {
|
||||||
if win.w < 5 || dir == nil {
|
if win.w < 5 || dir == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -251,6 +257,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dir.noPerm {
|
||||||
|
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "permission denied")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(dir.files) == 0 {
|
if len(dir.files) == 0 {
|
||||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||||
return
|
return
|
||||||
@@ -268,6 +279,9 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
if gOpts.number || gOpts.relativenumber {
|
if gOpts.number || gOpts.relativenumber {
|
||||||
lnwidth = 1
|
lnwidth = 1
|
||||||
|
if gOpts.number && gOpts.relativenumber {
|
||||||
|
lnwidth++
|
||||||
|
}
|
||||||
for j := 10; j < len(dir.files); j *= 10 {
|
for j := 10; j < len(dir.files); j *= 10 {
|
||||||
lnwidth++
|
lnwidth++
|
||||||
}
|
}
|
||||||
@@ -280,13 +294,18 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
if lnwidth > 0 {
|
if lnwidth > 0 {
|
||||||
var ln string
|
var ln string
|
||||||
|
|
||||||
if gOpts.number && (!gOpts.relativenumber || i == dir.pos) {
|
if gOpts.number && (!gOpts.relativenumber) {
|
||||||
ln = fmt.Sprintf(lnformat, i+1+beg)
|
ln = fmt.Sprintf(lnformat, i+1+beg)
|
||||||
} else if gOpts.relativenumber {
|
} else if gOpts.relativenumber {
|
||||||
if i < dir.pos {
|
switch {
|
||||||
|
case i < dir.pos:
|
||||||
ln = fmt.Sprintf(lnformat, dir.pos-i)
|
ln = fmt.Sprintf(lnformat, dir.pos-i)
|
||||||
} else {
|
case i > dir.pos:
|
||||||
ln = fmt.Sprintf(lnformat, i-dir.pos)
|
ln = fmt.Sprintf(lnformat, i-dir.pos)
|
||||||
|
case gOpts.number:
|
||||||
|
ln = fmt.Sprintf(fmt.Sprintf("%%%d.d ", lnwidth-1), i+1+beg)
|
||||||
|
default:
|
||||||
|
ln = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -313,6 +332,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
s = append(s, ' ')
|
s = append(s, ' ')
|
||||||
|
|
||||||
|
if gOpts.icons {
|
||||||
|
s = append(s, []rune(icons.get(f))...)
|
||||||
|
s = append(s, ' ')
|
||||||
|
}
|
||||||
|
|
||||||
for _, r := range f.Name() {
|
for _, r := range f.Name() {
|
||||||
s = append(s, r)
|
s = append(s, r)
|
||||||
}
|
}
|
||||||
@@ -321,7 +345,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
if w > win.w-3 {
|
if w > win.w-3 {
|
||||||
s = runeSliceWidthRange(s, 0, win.w-4)
|
s = runeSliceWidthRange(s, 0, win.w-4)
|
||||||
s = append(s, '~')
|
s = append(s, []rune(gOpts.truncatechar)...)
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < win.w-3-w; i++ {
|
for i := 0; i < win.w-3-w; i++ {
|
||||||
s = append(s, ' ')
|
s = append(s, ' ')
|
||||||
@@ -332,10 +356,10 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
if len(info) > 0 && win.w-2 > 2*len(info) {
|
if len(info) > 0 && win.w-2 > 2*len(info) {
|
||||||
if win.w-2 > w+len(info) {
|
if win.w-2 > w+len(info) {
|
||||||
s = runeSliceWidthRange(s, 0, win.w-3-len(info))
|
s = runeSliceWidthRange(s, 0, win.w-3-len(info)-lnwidth)
|
||||||
} else {
|
} else {
|
||||||
s = runeSliceWidthRange(s, 0, win.w-4-len(info))
|
s = runeSliceWidthRange(s, 0, win.w-4-len(info)-lnwidth)
|
||||||
s = append(s, '~')
|
s = append(s, []rune(gOpts.truncatechar)...)
|
||||||
}
|
}
|
||||||
for _, r := range info {
|
for _, r := range info {
|
||||||
s = append(s, r)
|
s = append(s, r)
|
||||||
@@ -367,6 +391,7 @@ type ui struct {
|
|||||||
keyAcc []rune
|
keyAcc []rune
|
||||||
keyCount []rune
|
keyCount []rune
|
||||||
colors colorMap
|
colors colorMap
|
||||||
|
icons iconMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func getWidths(wtot int) []int {
|
func getWidths(wtot int) []int {
|
||||||
@@ -448,6 +473,7 @@ func newUI() *ui {
|
|||||||
keyChan: make(chan string, 1000),
|
keyChan: make(chan string, 1000),
|
||||||
evChan: evChan,
|
evChan: evChan,
|
||||||
colors: parseColors(),
|
colors: parseColors(),
|
||||||
|
icons: parseIcons(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -527,7 +553,7 @@ func (ui *ui) loadFile(nav *nav) {
|
|||||||
if curr.IsDir() {
|
if curr.IsDir() {
|
||||||
ui.dirPrev = nav.loadDir(curr.path)
|
ui.dirPrev = nav.loadDir(curr.path)
|
||||||
} else if curr.Mode().IsRegular() {
|
} else if curr.Mode().IsRegular() {
|
||||||
ui.regPrev = nav.loadReg(ui, curr.path)
|
ui.regPrev = nav.loadReg(curr.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -537,16 +563,27 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.echof("%v %4s %v", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt))
|
var linkTarget string
|
||||||
|
if curr.linkTarget != "" {
|
||||||
|
linkTarget = " -> " + curr.linkTarget
|
||||||
|
}
|
||||||
|
ui.echof("%v %4s %v%s", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt), linkTarget)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawPromptLine(nav *nav) {
|
func (ui *ui) drawPromptLine(nav *nav) {
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
dir := nav.currDir()
|
pwd := nav.currDir().path
|
||||||
|
|
||||||
pwd := strings.Replace(dir.path, gUser.HomeDir, "~", -1)
|
if strings.HasPrefix(pwd, gUser.HomeDir) {
|
||||||
pwd = filepath.Clean(pwd)
|
pwd = filepath.Join("~", strings.TrimPrefix(pwd, gUser.HomeDir))
|
||||||
|
}
|
||||||
|
|
||||||
|
sep := string(filepath.Separator)
|
||||||
|
|
||||||
|
if !strings.HasSuffix(pwd, sep) {
|
||||||
|
pwd += sep
|
||||||
|
}
|
||||||
|
|
||||||
var fname string
|
var fname string
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
@@ -561,9 +598,11 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
|||||||
prompt = strings.Replace(prompt, "%f", fname, -1)
|
prompt = strings.Replace(prompt, "%f", fname, -1)
|
||||||
|
|
||||||
if printLength(strings.Replace(prompt, "%w", pwd, -1)) > ui.promptWin.w {
|
if printLength(strings.Replace(prompt, "%w", pwd, -1)) > ui.promptWin.w {
|
||||||
sep := string(filepath.Separator)
|
|
||||||
names := strings.Split(pwd, sep)
|
names := strings.Split(pwd, sep)
|
||||||
for i := range names {
|
for i := range names {
|
||||||
|
if names[i] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
r, _ := utf8.DecodeRuneInString(names[i])
|
r, _ := utf8.DecodeRuneInString(names[i])
|
||||||
names[i] = string(r)
|
names[i] = string(r)
|
||||||
if printLength(strings.Replace(prompt, "%w", strings.Join(names, sep), -1)) <= ui.promptWin.w {
|
if printLength(strings.Replace(prompt, "%w", strings.Join(names, sep), -1)) <= ui.promptWin.w {
|
||||||
@@ -581,12 +620,12 @@ func (ui *ui) drawPromptLine(nav *nav) {
|
|||||||
func (ui *ui) drawStatLine(nav *nav) {
|
func (ui *ui) drawStatLine(nav *nav) {
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
currDir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
ui.msgWin.print(0, 0, fg, bg, ui.msg)
|
||||||
|
|
||||||
tot := len(currDir.files)
|
tot := len(dir.files)
|
||||||
ind := min(currDir.ind+1, tot)
|
ind := min(dir.ind+1, tot)
|
||||||
acc := string(ui.keyCount) + string(ui.keyAcc)
|
acc := string(ui.keyCount) + string(ui.keyAcc)
|
||||||
|
|
||||||
var progress string
|
var progress string
|
||||||
@@ -600,12 +639,16 @@ func (ui *ui) drawStatLine(nav *nav) {
|
|||||||
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
|
progress += fmt.Sprintf(" [%d/%d]", nav.moveCount, nav.moveTotal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nav.deleteTotal > 0 {
|
||||||
|
progress += fmt.Sprintf(" [%d/%d]", nav.deleteCount, nav.deleteTotal)
|
||||||
|
}
|
||||||
|
|
||||||
ruler := fmt.Sprintf("%s%s %d/%d", acc, progress, ind, tot)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawBox(nav *nav) {
|
func (ui *ui) drawBox() {
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
w, h := termbox.Size()
|
w, h := termbox.Size()
|
||||||
@@ -653,7 +696,7 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
|
|
||||||
doff := len(nav.dirs) - length
|
doff := len(nav.dirs) - length
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors, ui.icons)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ui.cmdPrefix {
|
switch ui.cmdPrefix {
|
||||||
@@ -674,20 +717,20 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.preview {
|
if gOpts.preview {
|
||||||
f, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
preview := ui.wins[len(ui.wins)-1]
|
preview := ui.wins[len(ui.wins)-1]
|
||||||
|
|
||||||
if f.IsDir() {
|
if curr.IsDir() {
|
||||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons)
|
||||||
} else if f.Mode().IsRegular() {
|
} else if curr.Mode().IsRegular() {
|
||||||
preview.printReg(ui.regPrev)
|
preview.printReg(ui.regPrev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.drawbox {
|
if gOpts.drawbox {
|
||||||
ui.drawBox(nav)
|
ui.drawBox()
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.menuBuf != nil {
|
if ui.menuBuf != nil {
|
||||||
@@ -710,11 +753,6 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
termbox.Flush()
|
termbox.Flush()
|
||||||
|
|
||||||
if ui.cmdPrefix == "" {
|
|
||||||
// leave the cursor at the beginning of the current file for screen readers
|
|
||||||
moveCursor(ui.wins[woff+length-1].y+nav.dirs[doff+length-1].pos+1, ui.wins[woff+length-1].x+1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
func findBinds(keys map[string]expr, prefix string) (binds map[string]expr, ok bool) {
|
||||||
@@ -776,7 +814,7 @@ func (ui *ui) pollEvent() termbox.Event {
|
|||||||
case key := <-ui.keyChan:
|
case key := <-ui.keyChan:
|
||||||
ev := termbox.Event{Type: termbox.EventKey}
|
ev := termbox.Event{Type: termbox.EventKey}
|
||||||
|
|
||||||
if len(key) == 1 {
|
if utf8.RuneCountInString(key) == 1 {
|
||||||
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
ev.Ch, _ = utf8.DecodeRuneInString(key)
|
||||||
} else {
|
} else {
|
||||||
switch {
|
switch {
|
||||||
@@ -832,6 +870,8 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
ch <- draw
|
ch <- draw
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
|
ui.menuBuf = nil
|
||||||
|
return
|
||||||
}
|
}
|
||||||
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
ui.keyAcc = append(ui.keyAcc, []rune(val)...)
|
||||||
}
|
}
|
||||||
@@ -850,27 +890,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
ui.keyCount = nil
|
ui.keyCount = nil
|
||||||
ui.menuBuf = nil
|
ui.menuBuf = nil
|
||||||
case 1:
|
|
||||||
if ok {
|
|
||||||
if len(ui.keyCount) > 0 {
|
|
||||||
c, err := strconv.Atoi(string(ui.keyCount))
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("converting command count: %s", err)
|
|
||||||
}
|
|
||||||
count = c
|
|
||||||
}
|
|
||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
|
||||||
if e, ok := expr.(*callExpr); ok {
|
|
||||||
e.count = count
|
|
||||||
}
|
|
||||||
ch <- expr
|
|
||||||
ui.keyAcc = nil
|
|
||||||
ui.keyCount = nil
|
|
||||||
ui.menuBuf = nil
|
|
||||||
} else {
|
|
||||||
ui.menuBuf = listBinds(binds)
|
|
||||||
ch <- draw
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
if ok {
|
if ok {
|
||||||
if len(ui.keyCount) > 0 {
|
if len(ui.keyCount) > 0 {
|
||||||
@@ -883,6 +902,8 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
expr := gOpts.keys[string(ui.keyAcc)]
|
expr := gOpts.keys[string(ui.keyAcc)]
|
||||||
if e, ok := expr.(*callExpr); ok {
|
if e, ok := expr.(*callExpr); ok {
|
||||||
e.count = count
|
e.count = count
|
||||||
|
} else if e, ok := expr.(*listExpr); ok {
|
||||||
|
e.count = count
|
||||||
}
|
}
|
||||||
ch <- expr
|
ch <- expr
|
||||||
ui.keyAcc = nil
|
ui.keyAcc = nil
|
||||||
|
|||||||
Reference in new issue
Block a user