Compare commits

12 Commits
Author SHA1 Message Date
Gokcehan 1544d62206 update readme 2021-02-27 23:16:27 +03:00
Gokcehan 8742f25706 update doc 2021-02-27 22:56:18 +03:00
Gokcehan ced1ccd0c3 update doc 2021-02-22 01:45:48 +03:00
Gokcehan 7dfdcb51c0 unset shellopts when empty 2021-02-21 19:21:06 +03:00
Gokcehan 2c3cd35a5d use x/term instead of stty/pause to prompt any key
cc #480
2021-02-21 18:01:20 +03:00
Gokcehan c071e37316 cleanup 2021-02-21 17:48:23 +03:00
Gokcehan 4c0efdcb41 use suspend/resume api in tcell v2.2.0
cc #480
2021-02-21 17:34:38 +03:00
Gokcehan 1b93f2232e show number of selected/saved files in status line
cc #143
2021-02-13 17:45:18 +03:00
Gokcehan 9ec336fcdb update doc
cc #581
2021-02-12 20:54:18 +03:00
Nikita 6422bd7492 Fix symlink handling (#581)
* Fix replace dialog for symlinks

If the oldPath is a symlink to the newPath or vice versa, than os.Stat()
would resolve this symlink, and both the oldStat and newStat would be
the same. Hence, the replace dialog would not appear and the newPath
file would be overwritten by the oldPath file whilst the oldPath would
be deleted.

It is the same story when the oldPath and newPath are both symlinks to
the same file.

* Fix completion in the case of broken symlinks

If the current directory contains broken symlinks then matchFile() would
return at first broken symlink.

Let's consider the following example:

$ ls -F ~/
broken@ dir/ file

The broken@ is a symlink to ~/foo - non existent file.

If one would enter the following command in lf:

:cd ~/<tab>

it would not suggest possible completion options because matchFile()
would return as soon as it meet the broken symlink.

* Don't resolve symlinks when move files/dirs (#571)

This will allow to move broken symlinks.

* Fix symlinks copying/moving (#571)

Copy symlinks, do not try to resolve it and copy the file pointed by
this symlink. Also this allows to copy symlink to directory.
2021-02-12 20:50:48 +03:00
Gokcehan 60d6119858 add link/user/group to statline when available
cc #365
2021-02-12 16:01:54 +03:00
Gokcehan 3e403bb888 update sigpipe error fix in the doc 2021-02-06 00:19:09 +03:00
16 changed files with 158 additions and 115 deletions

No files matched your search

+2 -2
View File
@@ -7,7 +7,7 @@
[![Build Status](https://travis-ci.org/gokcehan/lf.svg?branch=master)](https://travis-ci.org/gokcehan/lf) [![Build Status](https://travis-ci.org/gokcehan/lf.svg?branch=master)](https://travis-ci.org/gokcehan/lf)
[![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf) [![Go Report Card](https://goreportcard.com/badge/github.com/gokcehan/lf)](https://goreportcard.com/report/github.com/gokcehan/lf)
[![GoDoc](https://godoc.org/github.com/gokcehan/lf?status.svg)](https://godoc.org/github.com/gokcehan/lf) [![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf)
> This is a work in progress. Use at your own risk. > This is a work in progress. Use at your own risk.
@@ -62,7 +62,7 @@ After the installation `lf` command should start the application in the current
Run `lf -help` to see command line options. Run `lf -help` to see command line options.
Run `lf -doc` to see the [documentation](https://godoc.org/github.com/gokcehan/lf). Run `lf -doc` to see the [documentation](https://pkg.go.dev/github.com/gokcehan/lf).
See [etc](etc) directory to integrate `lf` to your shell or editor. See [etc](etc) directory to integrate `lf` to your shell or editor.
An example configuration file can also be found in this directory. An example configuration file can also be found in this directory.
+5 -24
View File
@@ -12,8 +12,6 @@ import (
"strings" "strings"
"syscall" "syscall"
"time" "time"
"github.com/gdamore/tcell/v2"
) )
type cmdItem struct { type cmdItem struct {
@@ -34,10 +32,7 @@ type app struct {
cmdHistoryInd int cmdHistoryInd int
} }
func newApp(screen tcell.Screen) *app { func newApp(ui *ui, nav *nav) *app {
ui := newUI(screen)
nav := newNav(ui.wins[0].h)
quitChan := make(chan struct{}, 1) quitChan := make(chan struct{}, 1)
app := &app{ app := &app{
@@ -160,6 +155,8 @@ func (app *app) writeHistory() error {
// for evaluation. Similarly directories and regular files are also read in // for evaluation. Similarly directories and regular files are also read in
// separate goroutines and sent here for update. // separate goroutines and sent here for update.
func (app *app) loop() { func (app *app) loop() {
go app.nav.previewLoop(app.ui)
serverChan := readExpr() serverChan := readExpr()
app.ui.readExpr() app.ui.readExpr()
@@ -369,20 +366,6 @@ func (app *app) exportFiles() {
exportFiles(currFile, currSelections) exportFiles(currFile, currSelections)
} }
func waitKey() error {
cmd := pauseCommand()
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("waiting key: %s", err)
}
return nil
}
// This function is used to run a shell command. Modes are as follows: // This function is used to run a shell command. Modes are as follows:
// //
// Prefix Wait Async Stdin Stdout Stderr UI action // Prefix Wait Async Stdin Stdout Stderr UI action
@@ -405,7 +388,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
app.nav.previewChan <- "" app.nav.previewChan <- ""
app.ui.pause() app.ui.suspend()
defer app.ui.resume() defer app.ui.resume()
defer app.nav.renew() defer app.nav.renew()
@@ -433,9 +416,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
switch prefix { switch prefix {
case "!": case "!":
if err := waitKey(); err != nil { anyKey()
app.ui.echoerrf("waiting key: %s", err)
}
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
+4 -2
View File
@@ -35,7 +35,9 @@ func run() {
log.Print("hi!") log.Print("hi!")
app := newApp(screen) ui := newUI(screen)
nav := newNav(ui.wins[0].h)
app := newApp(ui, nav)
if err := app.nav.readMarks(); err != nil { if err := app.nav.readMarks(); err != nil {
app.ui.echoerrf("reading marks file: %s", err) app.ui.echoerrf("reading marks file: %s", err)
@@ -45,8 +47,8 @@ func run() {
app.ui.echoerrf("reading history file: %s", err) app.ui.echoerrf("reading history file: %s", err)
} }
go app.nav.previewLoop(app.ui)
app.loop() app.loop()
app.ui.screen.Fini() app.ui.screen.Fini()
} }
+8 -2
View File
@@ -246,18 +246,24 @@ func matchFile(s string) (matches []string, longest string) {
} }
for _, f := range files { for _, f := range files {
f, err := os.Stat(filepath.Join(dir, f.Name())) name := filepath.Join(dir, f.Name())
f, err := os.Stat(name)
if err != nil { if err != nil {
fl, err := os.Lstat(name)
if err == nil && fl.Mode()&os.ModeSymlink != 0 {
continue
} else {
log.Printf("getting file information: %s", err) log.Printf("getting file information: %s", err)
return return
} }
}
_, last := filepath.Split(s) _, last := filepath.Split(s)
if !strings.HasPrefix(escape(f.Name()), last) { if !strings.HasPrefix(escape(f.Name()), last) {
continue continue
} }
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(unescape(s)), f.Name()) name = filepath.Join(filepath.Dir(unescape(s)), f.Name())
} }
+10 -1
View File
@@ -11,7 +11,7 @@ func copySize(srcs []string) (int64, error) {
var total int64 var total int64
for _, src := range srcs { for _, src := range srcs {
_, err := os.Stat(src) _, err := os.Lstat(src)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return total, fmt.Errorf("src does not exist: %q", src) return total, fmt.Errorf("src does not exist: %q", src)
} }
@@ -112,6 +112,15 @@ func copyAll(srcs []string, dstDir string) (nums chan int64, errs chan error) {
errs <- fmt.Errorf("mkdir: %s", err) errs <- fmt.Errorf("mkdir: %s", err)
} }
nums <- info.Size() nums <- info.Size()
} else if info.Mode()&os.ModeSymlink != 0 { /* Symlink */
if rlink, err := os.Readlink(path); err != nil {
errs <- fmt.Errorf("symlink: %s", err)
} else {
if err := os.Symlink(rlink, newPath); err != nil {
errs <- fmt.Errorf("symlink: %s", err)
}
}
nums <- info.Size()
} else { } else {
if err := copyFile(path, newPath, info, nums); err != nil { if err := copyFile(path, newPath, info, nums); err != nil {
errs <- fmt.Errorf("copy: %s", err) errs <- fmt.Errorf("copy: %s", err)
+5 -10
View File
@@ -640,7 +640,6 @@ A smaller offset can be used when the current file is close to the beginning or
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands. Shell executable to use for shell commands.
On unix, a POSIX compatible shell is required.
Shell commands are executed as 'shell shellopts -c command -- arguments'. Shell commands are executed as 'shell shellopts -c command -- arguments'.
On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'. On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
@@ -1033,8 +1032,8 @@ 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 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. 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. 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. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, and xattr.
Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Special files such as character and block devices, named pipes, and sockets are skipped and links are not followed.
Moving is performed using the rename operation of the underlying OS. 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. 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. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
@@ -1163,7 +1162,7 @@ Extensions can then be used to match cleanly within a conditional:
*.rar) unrar l "$1";; *.rar) unrar l "$1";;
*.7z) 7z l "$1";; *.7z) 7z l "$1";;
*.pdf) pdftotext "$1" -;; *.pdf) pdftotext "$1" -;;
*) highlight -O ansi "$1" || cat "$1";; *) highlight -O ansi "$1";;
esac esac
Another important consideration for efficiency is the use of programs with short startup times for preview. Another important consideration for efficiency is the use of programs with short startup times for preview.
@@ -1173,13 +1172,9 @@ This is especially relevant for big files.
lf automatically closes the previewer script output pipe with a SIGPIPE when enough lines are read. 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. 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.
Note that some programs may not respond well to SIGPIPE to exit with a non-zero return code and avoid caching. Note that some programs may not respond well to SIGPIPE to exit with a non-zero return code and avoid caching.
You may trap SIGPIPE in your preview script to avoid error propogation: You may add a trailing '|| true' command to avoid such errors:
#!/bin/sh highlight -O ansi "$1" || true
trap "" PIPE
...
You may also use an existing preview filter as you like. You may also use an existing preview filter as you like.
Your system may already come with a preview filter named 'lesspipe'. Your system may already come with a preview filter named 'lesspipe'.
+9 -14
View File
@@ -683,10 +683,9 @@ beginning or end of the list to show the maximum number of items.
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
Shell executable to use for shell commands. On unix, a POSIX compatible Shell executable to use for shell commands. Shell commands are executed as
shell is required. Shell commands are executed as 'shell shellopts -c 'shell shellopts -c command -- arguments'. On windows, '/c' is used instead
command -- arguments'. On windows, '/c' is used instead of '-c' which should of '-c' which should work in 'cmd' and 'powershell'.
work in 'cmd' and 'powershell'.
shellopts []string (default '') shellopts []string (default '')
@@ -1137,8 +1136,8 @@ ruler. These commands do not overwrite existing files or directories with
the same name. Instead, a suffix that is compatible with '--backup=numbered' 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 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, and xattr. Special files such as character and block
block devices, named pipes, and sockets are skipped and links are followed. devices, named pipes, and sockets are skipped and links are not followed.
Moving is performed using the rename operation of the underlying OS. For 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 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 files if there are no errors. Operation errors are shown in the message line
@@ -1298,7 +1297,7 @@ match cleanly within a conditional:
*.rar) unrar l "$1";; *.rar) unrar l "$1";;
*.7z) 7z l "$1";; *.7z) 7z l "$1";;
*.pdf) pdftotext "$1" -;; *.pdf) pdftotext "$1" -;;
*) highlight -O ansi "$1" || cat "$1";; *) highlight -O ansi "$1";;
esac esac
Another important consideration for efficiency is the use of programs with Another important consideration for efficiency is the use of programs with
@@ -1311,14 +1310,10 @@ 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 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. Note that some the first portion of the file to a program for preview. Note that some
programs may not respond well to SIGPIPE to exit with a non-zero return code programs may not respond well to SIGPIPE to exit with a non-zero return code
and avoid caching. You may trap SIGPIPE in your preview script to avoid and avoid caching. You may add a trailing '|| true' command to avoid such
error propogation: errors:
#!/bin/sh highlight -O ansi "$1" || true
trap "" PIPE
...
You may also use an existing preview filter as you like. Your system may You may also use an existing preview filter as you like. Your system may
already come with a preview filter named 'lesspipe'. These filters may have already come with a preview filter named 'lesspipe'. These filters may have
+6 -2
View File
@@ -310,6 +310,10 @@ func (e *setExpr) eval(app *app, args []string) {
case "shell": case "shell":
gOpts.shell = e.val gOpts.shell = e.val
case "shellopts": case "shellopts":
if e.val == "" {
gOpts.shellopts = nil
return
}
gOpts.shellopts = strings.Split(e.val, ":") gOpts.shellopts = strings.Split(e.val, ":")
case "sortby": case "sortby":
switch e.val { switch e.val {
@@ -1328,13 +1332,13 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
oldStat, err := os.Stat(oldPath) oldStat, err := os.Lstat(oldPath)
if err != nil { if err != nil {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
if newStat, err := os.Stat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) { if newStat, err := os.Lstat(newPath); !os.IsNotExist(err) && !os.SameFile(oldStat, newStat) {
app.ui.cmdPrefix = "replace '" + newPath + "' ? [y/N] " app.ui.cmdPrefix = "replace '" + newPath + "' ? [y/N] "
return return
} }
+1
View File
@@ -23,6 +23,7 @@ cat << END >> $out
lf \- terminal file manager lf \- terminal file manager
.SH SYNOPSIS .SH SYNOPSIS
.SY lf .SY lf
.OP \-command command
.OP \-cpuprofile path .OP \-cpuprofile path
.OP \-doc .OP \-doc
.OP \-last-dir-path path .OP \-last-dir-path path
+3 -2
View File
@@ -3,7 +3,8 @@ module github.com/gokcehan/lf
go 1.12 go 1.12
require ( require (
github.com/gdamore/tcell/v2 v2.0.0 github.com/gdamore/tcell/v2 v2.2.0
github.com/mattn/go-runewidth v0.0.9 github.com/mattn/go-runewidth v0.0.10
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
gopkg.in/djherbis/times.v1 v1.2.0 gopkg.in/djherbis/times.v1 v1.2.0
) )
+12 -7
View File
@@ -1,14 +1,19 @@
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.0.0 h1:GRWG8aLfWAlekj9Q6W29bVvkHENc6hp79XOqG4AWDOs= github.com/gdamore/tcell/v2 v2.2.0 h1:vSyEgKwraXPSOkvCk7IwOSyX+Pv3V2cV9CikJMXg4U4=
github.com/gdamore/tcell/v2 v2.0.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA= github.com/gdamore/tcell/v2 v2.2.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM= gopkg.in/djherbis/times.v1 v1.2.0 h1:UCvDKl1L/fmBygl2Y7hubXCnY7t4Yj46ZrBFNUipFbM=
+6 -13
View File
@@ -4,6 +4,7 @@
lf \- terminal file manager lf \- terminal file manager
.SH SYNOPSIS .SH SYNOPSIS
.SY lf .SY lf
.OP \-command command
.OP \-cpuprofile path .OP \-cpuprofile path
.OP \-doc .OP \-doc
.OP \-last-dir-path path .OP \-last-dir-path path
@@ -762,7 +763,7 @@ Minimum number of offset lines shown at all times in the top and the bottom of t
shell string (default 'sh' for unix and 'cmd' for windows) shell string (default 'sh' for unix and 'cmd' for windows)
.EE .EE
.PP .PP
Shell executable to use for shell commands. On unix, a POSIX compatible shell is required. Shell commands are executed as 'shell shellopts -c command -- arguments'. On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'. Shell executable to use for shell commands. Shell commands are executed as 'shell shellopts -c command -- arguments'. On windows, '/c' is used instead of '-c' which should work in 'cmd' and 'powershell'.
.PP .PP
.EX .EX
shellopts []string (default '') shellopts []string (default '')
@@ -1190,7 +1191,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. 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. 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, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are not 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
@@ -1292,22 +1293,14 @@ Since this script is called for each file selection change it needs to be as eff
*.rar) unrar l "$1";; *.rar) unrar l "$1";;
*.7z) 7z l "$1";; *.7z) 7z l "$1";;
*.pdf) pdftotext "$1" -;; *.pdf) pdftotext "$1" -;;
*) highlight -O ansi "$1" || cat "$1";; *) highlight -O ansi "$1";;
esac esac
.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. Note that some programs may not respond well to SIGPIPE to exit with a non-zero return code and avoid caching. You may trap SIGPIPE in your preview script to avoid error propogation: 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. Note that some programs may not respond well to SIGPIPE to exit with a non-zero return code and avoid caching. You may add a trailing '|| true' command to avoid such errors:
.PP .PP
.EX .EX
#!/bin/sh highlight -O ansi "$1" || true
.EE
.PP
.EX
trap "" PIPE
.EE
.PP
.EX
...
.EE .EE
.PP .PP
You may also use an existing preview filter as you like. Your system may already come with a preview filter named 'lesspipe'. These filters may have a mechanism to add user customizations as well. See the related documentations for more information. You may also use an existing preview filter as you like. Your system may already come with a preview filter named 'lesspipe'. These filters may have a mechanism to add user customizations as well. See the related documentations for more information.
+1 -1
View File
@@ -824,7 +824,7 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
for _, src := range srcs { for _, src := range srcs {
nav.moveCountChan <- 1 nav.moveCountChan <- 1
srcStat, err := os.Stat(src) srcStat, err := os.Lstat(src)
if err != nil { if err != nil {
errCount++ errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
+25 -12
View File
@@ -94,18 +94,6 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
return cmd return cmd
} }
func pauseCommand() *exec.Cmd {
cmd := `echo
echo -n 'Press any key to continue'
old=$(stty -g)
stty raw -echo
eval "ignore=\$(dd bs=1 count=1 2> /dev/null)"
stty $old
echo`
return exec.Command(gOpts.shell, "-c", cmd)
}
func shellCommand(s string, args []string) *exec.Cmd { func shellCommand(s string, args []string) *exec.Cmd {
if len(gOpts.ifs) != 0 { if len(gOpts.ifs) != 0 {
s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s) s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s)
@@ -145,6 +133,31 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
return hidden return hidden
} }
func userName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
return fmt.Sprintf("%v ", u.Username)
}
}
return ""
}
func groupName(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
return fmt.Sprintf("%v ", g.Name)
}
}
return ""
}
func linkCount(f os.FileInfo) string {
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
return fmt.Sprintf("%v ", stat.Nlink)
}
return ""
}
func matchPattern(pattern, name, path string) bool { func matchPattern(pattern, name, path string) bool {
s := name s := name
+12 -4
View File
@@ -76,10 +76,6 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
return cmd return cmd
} }
func pauseCommand() *exec.Cmd {
return exec.Command("cmd", "/c", "pause")
}
func shellCommand(s string, args []string) *exec.Cmd { func shellCommand(s string, args []string) *exec.Cmd {
args = append([]string{"/c", s}, args...) args = append([]string{"/c", s}, args...)
@@ -121,6 +117,18 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0 return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
} }
func userName(f os.FileInfo) string {
return ""
}
func groupName(f os.FileInfo) string {
return ""
}
func linkCount(f os.FileInfo) string {
return ""
}
func errCrossDevice(err error) bool { func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == 17 return err.(*os.LinkError).Err.(syscall.Errno) == 17
} }
+49 -19
View File
@@ -17,6 +17,7 @@ import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"golang.org/x/term"
) )
const gEscapeCode = 27 const gEscapeCode = 27
@@ -244,11 +245,11 @@ func (win *win) printf(screen tcell.Screen, x, y int, st tcell.Style, format str
} }
func (win *win) printLine(screen tcell.Screen, x, y int, st tcell.Style, s string) { func (win *win) printLine(screen tcell.Screen, x, y int, st tcell.Style, s string) {
win.printf(screen, x, y, st, "%s%*s", s, win.w-len(s), "") win.printf(screen, x, y, st, "%s%*s", s, win.w-printLength(s), "")
} }
func (win *win) printRight(screen tcell.Screen, y int, st tcell.Style, s string) { func (win *win) printRight(screen tcell.Screen, y int, st tcell.Style, s string) {
win.print(screen, win.w-len(s), y, st, s) win.print(screen, win.w-printLength(s), y, st, s)
} }
func (win *win) printReg(screen tcell.Screen, reg *reg) { func (win *win) printReg(screen tcell.Screen, reg *reg) {
@@ -660,7 +661,15 @@ func (ui *ui) loadFileInfo(nav *nav) {
if curr.linkTarget != "" { if curr.linkTarget != "" {
linkTarget = " -> " + curr.linkTarget linkTarget = " -> " + curr.linkTarget
} }
ui.echof("%v %4s %v%s", curr.Mode(), humanize(curr.Size()), curr.ModTime().Format(gOpts.timefmt), linkTarget)
ui.echof("%v %v%v%v%4s %v%s",
curr.Mode(),
linkCount(curr), // optional
userName(curr), // optional
groupName(curr), // optional
humanize(curr.Size()),
curr.ModTime().Format(gOpts.timefmt),
linkTarget)
} }
func (ui *ui) drawPromptLine(nav *nav) { func (ui *ui) drawPromptLine(nav *nav) {
@@ -721,6 +730,30 @@ func (ui *ui) drawStatLine(nav *nav) {
ind := min(dir.ind+1, tot) ind := min(dir.ind+1, tot)
acc := string(ui.keyCount) + string(ui.keyAcc) acc := string(ui.keyCount) + string(ui.keyAcc)
var selection string
if len(nav.saves) > 0 {
copy := 0
move := 0
for _, cp := range nav.saves {
if cp {
copy++
} else {
move++
}
}
if copy > 0 {
selection += fmt.Sprintf(" \033[33;7m %d \033[0m", copy)
}
if move > 0 {
selection += fmt.Sprintf(" \033[31;7m %d \033[0m", move)
}
}
if len(nav.selections) > 0 {
selection += fmt.Sprintf(" \033[35;7m %d \033[0m", len(nav.selections))
}
var progress string var progress string
if nav.copyTotal > 0 { if nav.copyTotal > 0 {
@@ -736,7 +769,7 @@ func (ui *ui) drawStatLine(nav *nav) {
progress += fmt.Sprintf(" [%d/%d]", nav.deleteCount, nav.deleteTotal) 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%s %d/%d", acc, progress, selection, ind, tot)
ui.msgWin.printRight(ui.screen, 0, st, ruler) ui.msgWin.printRight(ui.screen, 0, st, ruler)
} }
@@ -1111,27 +1144,24 @@ func (ui *ui) readExpr() {
}() }()
} }
func (ui *ui) pause() { func (ui *ui) suspend() {
ui.screen.Fini() ui.screen.Suspend()
} }
func (ui *ui) resume() { func (ui *ui) resume() {
var screen tcell.Screen ui.screen.Resume()
var err error
if screen, err = tcell.NewScreen(); err != nil {
log.Fatalf("creating screen: %s", err)
} else if err = screen.Init(); err != nil {
log.Fatalf("initializing screen: %s", err)
}
if gOpts.mouse {
screen.EnableMouse()
} }
ui.screen = screen func anyKey() {
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer term.Restore(int(os.Stdin.Fd()), oldState)
go ui.pollEvents() fmt.Print("Press any key to continue")
b := make([]byte, 1)
ui.renew() os.Stdin.Read(b)
} }
func listMatches(screen tcell.Screen, matches []string) (*bytes.Buffer, error) { func listMatches(screen tcell.Screen, matches []string) (*bytes.Buffer, error) {