Compare commits

31 Commits
Author SHA1 Message Date
Gokcehan 55b9189713 build release only on tags 2021-06-20 01:43:45 +03:00
Gokcehan b763c30cc5 deprecate travis in favor of github actions 2021-06-20 01:38:53 +03:00
gokcehan 61489ad00b Create release.yml 2021-06-20 01:37:44 +03:00
gokcehan 1ff3910c70 Create go.yml 2021-06-20 01:12:57 +03:00
Gokcehan 1966a30deb bump go version 2021-06-20 01:01:06 +03:00
ratijas 50e3a6856e PowerShell: use native Camel-Case style for commands (#650)
In PowerShell land it is preferred to use Camel Case for command names,
options and parameters, so lets respect that.
2021-06-19 23:41:14 +03:00
Gokcehan 9885c4be7a trim command prefix when it is longer than width
cc #648
2021-06-13 01:09:19 +03:00
Gokcehan 29aa77aa27 update doc 2021-06-13 00:36:48 +03:00
István Donkó 6e9f53f4bb Fix minor typo (#647)
* Fix minor typo

lf.1 will need to be regenerated as well.

* Fix minor typo
2021-06-13 00:36:16 +03:00
Gokcehan 099cccdcb5 show remote error when client id does not exists
cc #495
2021-06-13 00:27:43 +03:00
Gokcehan 4220868cc7 create data directory first before selection file
cc #645
2021-06-12 23:29:54 +03:00
Gokcehan eaaf08e425 ignore erase line escape code
cc #440
2021-05-30 20:43:17 +03:00
Gokcehan f885af55f2 add support for bright fg/bg ansi escape codes
cc #307
2021-05-30 19:26:08 +03:00
Gokcehan 599e42c12b calculate rune widths properly in shell outputs 2021-05-30 17:35:44 +03:00
Gokcehan 5d439419ea scroll when the prompt is longer than the width
cc #269
2021-05-30 17:24:19 +03:00
Gokcehan 5d02b557d3 follow links in 'open' examples
cc #634
2021-05-22 01:46:13 +03:00
Gokcehan 7acb69c40a echo logged server errors back to client as well 2021-05-21 16:54:01 +03:00
Gokcehan 7cdb7495ea add a command line parameter for single use
cc #177
2021-05-19 23:38:05 +03:00
Gokcehan d6acf4a6ec update doc 2021-05-19 22:25:26 +03:00
Gokcehan 06a30eda19 add 'autoquit' option to auto quit server on quit
cc #177
2021-05-19 21:55:19 +03:00
Gokcehan 7bf895e301 add server quit command to quit without clients
cc #177
2021-05-19 21:47:53 +03:00
Gokcehan 1841bba3e6 rename server quit command to quit!
cc #177
2021-05-19 21:47:08 +03:00
Gokcehan 6ca07b1bfc drop client connections on quit
cc #177
2021-05-19 21:45:27 +03:00
Gokcehan ec330c1bc5 use a local file instead of server load and save
cc #177
2021-05-19 19:54:50 +03:00
Gokcehan d31cd98b58 bump tcell to v2.3.1
cc #616 #621
2021-05-16 22:52:15 +03:00
Marius 0cd634e9a8 Preserve ' bookmark on sync (#624) 2021-05-13 21:31:25 +03:00
Marius 843afdfe4f Make ratios behave like ratios (#622)
Integer division causes miscalculation of pane widths. With `set ratios 100:200:300` the first two panes have width 0, the third pane will take up all space (unless you happen to have a huge terminal). I noticed this when fine tuning ratios, e.g. going from `1:2:3` to something like `10:21:30`.
2021-05-13 21:25:04 +03:00
Gokcehan 1bd78220e2 avoid crash with dir preview when hidden changes
cc #615
2021-04-28 18:50:24 +03:00
Gokcehan 202a998731 invalidate reg cache when drawbox option changes
cc #602
2021-04-25 16:51:40 +03:00
Gokcehan 8739087fe1 increase lookahead length for color escapes
cc #609
2021-04-15 17:23:25 +03:00
Gokcehan 628bf408b4 invalidate reg cache when height changes in resize
cc #610
2021-04-14 14:49:41 +03:00
29 changed files with 497 additions and 299 deletions

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
name: Go
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: go build -v ./...
- name: Test
run: go test -v ./...
+28
View File
@@ -0,0 +1,28 @@
name: Release
on:
push:
tags:
- '*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Build
run: gen/xbuild.sh
- name: Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-19
View File
@@ -1,19 +0,0 @@
language: go
go:
- 1.15.x
before_deploy:
- gen/xbuild.sh
deploy:
provider: releases
api_key:
secure: RdZAOPWooYq73iFQIjqe9+Awr7oA8m0j0tn1tUUfLjP+PGYpuz2lf1SHW/UjPcxySFkkBxnNPC1xgqmxekmvZadBaQbApqko4e47zCF0Pe91QG9OcDFaiJUWb7wcg+UDLoS0lJq8mcKYoi6bV76syOk0gBunLUmuYYpz/hR4lbalfq5//fD6sOOJ9cJPjeuG7LwYqbyw/8VwQWpiWgK9Sb5gu7+ZBgXkLG+/5OSHW8yNHGmtkw5sjMr4jQnNt2ixXVe5OdQ14mvRx0n4vlnzjNjmY6cPjEeqAc9eniOJ5o99k1OnR3H5kmNgI749q+VAkdu/uJfHiLXL1zerReb4SSTU+tTw9c7JYTcjBHlCT11CHlksVu55hHAbFvPkIpLfoRvdqrcjUyEHiCI/HbWiHhsQ+Gve+tpIcgu/aAC2TEsQ+vmmaXbOFcUsG77XP8gn1y+Spkyzou7tUvypIXduDSKFIvI51HYK2F5t5ttG6zJw9lpmmuoUWvCvbGvdAW893O6ef+iZvBoZYRjdeWvIqh/no2gWi1CRa4ZPSZWkn9NoE/2koaCQkrx9RHmEeLIukZVAT6ZViwvhMAOrvXQdKTDwbQ3ovMdtDvGcvjGz9k5xwnWrIcF7MV7nf7sj/JlcX2tulevcSLsYeBvcuTUFzy90erMy70MS01wp0I/IgpY=
skip_cleanup: true
file_glob: true
file: dist/*
name: $TRAVIS_TAG
on:
tags: true
repo: gokcehan/lf
-1
View File
@@ -5,7 +5,6 @@
| [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode) | [#lf](https://webchat.freenode.net/?channels=lf) (on Freenode)
| [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge) | [#lf:matrix.org](https://matrix.to/#/#lf:matrix.org) (with IRC bridge)
[![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)
[![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf) [![Go Reference](https://pkg.go.dev/badge/github.com/gokcehan/lf.svg)](https://pkg.go.dev/github.com/gokcehan/lf)
+91 -9
View File
@@ -49,8 +49,7 @@ func newApp(ui *ui, nav *nav) *app {
case os.Interrupt: case os.Interrupt:
return return
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM: case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
app.writeHistory() app.quit()
os.Remove(gLogPath)
os.Exit(3) os.Exit(3)
return return
} }
@@ -59,6 +58,23 @@ func newApp(ui *ui, nav *nav) *app {
return app return app
} }
func (app *app) quit() {
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
if !gSingleMode {
if err := remote(fmt.Sprintf("drop %d", gClientID)); err != nil {
log.Printf("dropping connection: %s", err)
}
if gOpts.autoquit {
if err := remote("quit"); err != nil {
log.Printf("auto quitting server: %s", err)
}
}
}
os.Remove(gLogPath)
}
func (app *app) readFile(path string) { func (app *app) readFile(path string) {
log.Printf("reading file: %s", path) log.Printf("reading file: %s", path)
@@ -80,6 +96,72 @@ func (app *app) readFile(path string) {
} }
} }
func loadFiles() (list []string, cp bool, err error) {
files, err := os.Open(gFilesPath)
if os.IsNotExist(err) {
err = nil
return
}
if err != nil {
err = fmt.Errorf("opening file selections file: %s", err)
return
}
defer files.Close()
s := bufio.NewScanner(files)
s.Scan()
switch s.Text() {
case "copy":
cp = true
case "move":
cp = false
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
list = append(list, s.Text())
}
if s.Err() != nil {
err = fmt.Errorf("scanning file list: %s", s.Err())
return
}
log.Printf("loading files: %v", list)
return
}
func saveFiles(list []string, cp bool) error {
if err := os.MkdirAll(filepath.Dir(gFilesPath), os.ModePerm); err != nil {
return fmt.Errorf("creating data directory: %s", err)
}
files, err := os.Create(gFilesPath)
if err != nil {
return fmt.Errorf("opening file selections file: %s", err)
}
defer files.Close()
log.Printf("saving files: %v", list)
if cp {
fmt.Fprintln(files, "copy")
} else {
fmt.Fprintln(files, "move")
}
for _, f := range list {
fmt.Fprintln(files, f)
}
return nil
}
func (app *app) readHistory() error { func (app *app) readHistory() error {
f, err := os.Open(gHistoryPath) f, err := os.Open(gHistoryPath)
if os.IsNotExist(err) { if os.IsNotExist(err) {
@@ -157,7 +239,10 @@ func (app *app) writeHistory() error {
func (app *app) loop() { func (app *app) loop() {
go app.nav.previewLoop(app.ui) go app.nav.previewLoop(app.ui)
serverChan := readExpr() var serverChan <-chan expr
if !gSingleMode {
serverChan = readExpr()
}
app.ui.readExpr() app.ui.readExpr()
@@ -218,14 +303,12 @@ func (app *app) loop() {
continue continue
} }
app.quit()
app.nav.previewChan <- "" app.nav.previewChan <- ""
log.Print("bye!") log.Print("bye!")
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
if gLastDirPath != "" { if gLastDirPath != "" {
f, err := os.Create(gLastDirPath) f, err := os.Create(gLastDirPath)
if err != nil { if err != nil {
@@ -401,8 +484,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
} }
defer func() { defer func() {
if err := app.ui.resume(); err != nil { if err := app.ui.resume(); err != nil {
app.writeHistory() app.quit()
os.Remove(gLogPath)
os.Exit(3) os.Exit(3)
return return
} }
+4 -64
View File
@@ -29,7 +29,6 @@ func run() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
defer os.Remove(gLogPath)
defer f.Close() defer f.Close()
log.SetOutput(f) log.SetOutput(f)
@@ -39,6 +38,10 @@ func run() {
nav := newNav(ui.wins[0].h) nav := newNav(ui.wins[0].h)
app := newApp(ui, nav) app := newApp(ui, nav)
if err := nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)
}
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)
} }
@@ -85,69 +88,6 @@ func readExpr() <-chan expr {
return ch return ch
} }
func saveFiles(list []string, cp bool) error {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
return fmt.Errorf("dialing to save files: %s", err)
}
defer c.Close()
log.Printf("saving files: %v", list)
fmt.Fprintln(c, "save")
if cp {
fmt.Fprintln(c, "copy")
} else {
fmt.Fprintln(c, "move")
}
for _, f := range list {
fmt.Fprintln(c, f)
}
fmt.Fprintln(c)
return nil
}
func loadFiles() (list []string, cp bool, err error) {
c, e := net.Dial(gSocketProt, gSocketPath)
if e != nil {
err = fmt.Errorf("dialing to load files: %s", e)
return
}
defer c.Close()
fmt.Fprintln(c, "load")
s := bufio.NewScanner(c)
s.Scan()
switch s.Text() {
case "copy":
cp = true
case "move":
cp = false
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
}
for s.Scan() && s.Text() != "" {
list = append(list, s.Text())
}
if s.Err() != nil {
err = fmt.Errorf("scanning file list: %s", s.Err())
return
}
log.Printf("loading files: %v", list)
return
}
func remote(cmd string) error { func remote(cmd string) error {
c, err := net.Dial(gSocketProt, gSocketPath) c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil { if err != nil {
+4
View File
@@ -118,6 +118,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
st = st.StrikeThrough(true) st = st.StrikeThrough(true)
case n >= 30 && n <= 37: case n >= 30 && n <= 37:
st = st.Foreground(tcell.PaletteColor(n - 30)) st = st.Foreground(tcell.PaletteColor(n - 30))
case n >= 90 && n <= 97:
st = st.Foreground(tcell.PaletteColor(n - 82))
case n == 38: case n == 38:
if i+3 <= len(nums) && nums[i+1] == 5 { if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Foreground(tcell.PaletteColor(nums[i+2])) st = st.Foreground(tcell.PaletteColor(nums[i+2]))
@@ -133,6 +135,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
} }
case n >= 40 && n <= 47: case n >= 40 && n <= 47:
st = st.Background(tcell.PaletteColor(n - 40)) st = st.Background(tcell.PaletteColor(n - 40))
case n >= 100 && n <= 107:
st = st.Background(tcell.PaletteColor(n - 92))
case n == 48: case n == 48:
if i+3 <= len(nums) && nums[i+1] == 5 { if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Background(tcell.PaletteColor(nums[i+2])) st = st.Background(tcell.PaletteColor(nums[i+2]))
+3
View File
@@ -70,6 +70,9 @@ var (
"anchorfind", "anchorfind",
"noanchorfind", "noanchorfind",
"anchorfind!", "anchorfind!",
"autoquit",
"noautoquit",
"autoquit!",
"dircounts", "dircounts",
"nodircounts", "nodircounts",
"dircounts!", "dircounts!",
+20 -25
View File
@@ -98,6 +98,7 @@ The following command line commands are provided by lf:
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
drawbox bool (default off) drawbox bool (default off)
@@ -184,6 +185,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/lf/lfrc unix /etc/lf/lfrc ~/.config/lf/lfrc
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
Selection file should be located at:
unix ~/.local/share/lf/files
windows C:\Users\<user>\AppData\Local\lf\files
Marks file should be located at: Marks file should be located at:
unix ~/.local/share/lf/marks unix ~/.local/share/lf/marks
@@ -362,7 +368,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f') find (modal) (default 'f')
find-back (modal) (default 'F') find-back (modal) (default 'F')
@@ -489,6 +495,10 @@ Character ':' is used as the separator for list options '[]int' and '[]string'.
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position. When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
autoquit bool (default off)
Automatically quit server when there are no clients left connected.
dircounts bool (default off) dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file. When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
@@ -781,7 +791,7 @@ Command 'map' is used to bind a key to a command which can be builtin command, c
map gh cd ~ # builtin command map gh cd ~ # builtin command
map D trash # custom command map D trash # custom command
map i $less $f # shell command map i $less $f # shell command
map U !du -sh # waiting shell command map U !du -csh * # waiting shell command
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands: Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
@@ -996,10 +1006,11 @@ This is the recommended way of using remote commands since it is shorter and imm
In this command 'send' is used to send the rest of the string as a command to all connected clients. In this command 'send' is used to send the rest of the string as a command to all connected clients.
You can optionally give it an id number to send a command to a single client: You can optionally give it an id number to send a command to a single client:
lf -remote 'send 1000 echo hello world' lf -remote 'send 1234 echo hello world'
All clients have a unique id number but you may not be aware of the id number when you are writing a command. All clients have a unique id number but you may not be aware of the id number when you are writing a command.
For this purpose, an '$id' variable is exported to the environment for shell commands. For this purpose, an '$id' variable is exported to the environment for shell commands.
The value of this variable is set to the process id of the client.
You can use it to send a remote command from a client to the server which in return sends a command back to itself. You can use it to send a remote command from a client to the server which in return sends a command back to itself.
So now you can display a message in the current client by calling the following in a shell command: So now you can display a message in the current client by calling the following in a shell command:
@@ -1019,27 +1030,10 @@ For example, you can configure the number of columns in the ui with respect to t
fi fi
}} }}
Besides 'send' command, there are also two commands to get or set the current file selection. Besides 'send' command, there is a 'quit' command to quit the server when there are no connected clients left, and a 'quit!' command to force quit the server by closing client connections first:
Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved.
File names are separated by newline character.
Setting the file selection is done with 'save' command:
lf -remote "$(printf 'save\ncopy\nfoo.txt\nbar.txt\nbaz.txt\n')"
Getting the file selection is similarly done with 'load' command:
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
There is a 'quit' command to close client connections and quit the server:
lf -remote 'quit' lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client. Lastly, there is a 'conn' command to connect the server as a client.
This should not be needed for users. This should not be needed for users.
@@ -1057,7 +1051,7 @@ For cross-device moving, lf falls back to copying and then deletes the original
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.
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. 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. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to a file.
The actual file copying takes place when you 'paste'. The actual file copying takes place when you 'paste'.
Similarly 'paste' after a 'cut' operation moves the file. Similarly 'paste' after a 'cut' operation moves the file.
@@ -1066,7 +1060,7 @@ This is a special command that is called when it is defined instead of the built
You can use the following example as a starting point: You can use the following example as a starting point:
cmd paste %{{ cmd paste %{{
load=$(lf -remote 'load') load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
@@ -1074,7 +1068,7 @@ You can use the following example as a starting point:
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv $list . mv $list .
fi fi
lf -remote 'send load' rm ~/.local/share/lf/files
lf -remote 'send clear' lf -remote 'send clear'
}} }}
@@ -1133,6 +1127,7 @@ It is possible to use different command types:
You may want to use either file extensions or mime types from 'file' command: You may want to use either file extensions or mime types from 'file' command:
cmd open ${{ cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in case $(file --mime-type $f -b) in
text/*) vi $fx;; text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;; *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+33 -36
View File
@@ -102,6 +102,7 @@ The following command line commands are provided by lf:
The following options can be used to customize the behavior of lf: The following options can be used to customize the behavior of lf:
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
drawbox bool (default off) drawbox bool (default off)
@@ -189,6 +190,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/lf/lfrc unix /etc/lf/lfrc ~/.config/lf/lfrc
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
Selection file should be located at:
unix ~/.local/share/lf/files
windows C:\Users\<user>\AppData\Local\lf\files
Marks file should be located at: Marks file should be located at:
unix ~/.local/share/lf/marks unix ~/.local/share/lf/marks
@@ -378,7 +384,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
find (modal) (default 'f') find (modal) (default 'f')
find-back (modal) (default 'F') find-back (modal) (default 'F')
@@ -515,6 +521,10 @@ Character ':' is used as the separator for list options '[]int' and
When this option is enabled, find command starts matching patterns from the When this option is enabled, find command starts matching patterns from the
beginning of file names, otherwise, it can match at an arbitrary position. beginning of file names, otherwise, it can match at an arbitrary position.
autoquit bool (default off)
Automatically quit server when there are no clients left connected.
dircounts bool (default off) dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside When this option is enabled, directory sizes show the number of items inside
@@ -846,7 +856,7 @@ command, custom command, or shell command:
map gh cd ~ # builtin command map gh cd ~ # builtin command
map D trash # custom command map D trash # custom command
map i $less $f # shell command map i $less $f # shell command
map U !du -sh # waiting shell command map U !du -csh * # waiting shell command
Command 'cmap' is used to bind a key to a command line command which can Command 'cmap' is used to bind a key to a command line command which can
only be one of the builtin commands: only be one of the builtin commands:
@@ -1095,11 +1105,12 @@ In this command 'send' is used to send the rest of the string as a command
to all connected clients. You can optionally give it an id number to send a to all connected clients. You can optionally give it an id number to send a
command to a single client: command to a single client:
lf -remote 'send 1000 echo hello world' lf -remote 'send 1234 echo hello world'
All clients have a unique id number but you may not be aware of the id All clients have a unique id number but you may not be aware of the id
number when you are writing a command. For this purpose, an '$id' variable number when you are writing a command. For this purpose, an '$id' variable
is exported to the environment for shell commands. You can use it to send a is exported to the environment for shell commands. The value of this
variable is set to the process id of the client. You can use it to send a
remote command from a client to the server which in return sends a command remote command from a client to the server which in return sends a command
back to itself. So now you can display a message in the current client by back to itself. So now you can display a message in the current client by
calling the following in a shell command: calling the following in a shell command:
@@ -1121,27 +1132,12 @@ with respect to the terminal width as follows:
fi fi
}} }}
Besides 'send' command, there are also two commands to get or set the Besides 'send' command, there is a 'quit' command to quit the server when
current file selection. Two possible modes 'copy' and 'move' specify whether there are no connected clients left, and a 'quit!' command to force quit the
selected files are to be copied or moved. File names are separated by server by closing client connections first:
newline character. Setting the file selection is done with 'save' command:
lf -remote "$(printf 'save\ncopy\nfoo.txt\nbar.txt\nbaz.txt\n')"
Getting the file selection is similarly done with 'load' command:
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
There is a 'quit' command to close client connections and quit the server:
lf -remote 'quit' lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client. This Lastly, there is a 'conn' command to connect the server as a client. This
should not be needed for users. should not be needed for users.
@@ -1166,7 +1162,7 @@ corresponding file operation.
File operations can be performed on the current selected file or File operations can be performed on the current selected file or
alternatively on multiple files by selecting them first. When you 'copy' a 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 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'. name to a file. The actual file copying takes place when you 'paste'.
Similarly 'paste' after a 'cut' operation moves the file. Similarly 'paste' after a 'cut' operation moves the file.
You can customize copy and move operations by defining a 'paste' command. You can customize copy and move operations by defining a 'paste' command.
@@ -1174,18 +1170,18 @@ This is a special command that is called when it is defined instead of the
builtin implementation. You can use the following example as a starting builtin implementation. You can use the following example as a starting
point: point:
cmd paste %{{ cmd paste %{{
load=$(lf -remote 'load') load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
cp -R $list . cp -R $list .
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv $list . mv $list .
fi fi
lf -remote 'send load' rm ~/.local/share/lf/files
lf -remote 'send clear' lf -remote 'send clear'
}} }}
Some useful things to be considered are to use the backup ('--backup') Some useful things to be considered are to use the backup ('--backup')
and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if
@@ -1259,6 +1255,7 @@ You may want to use either file extensions or mime types from 'file'
command: command:
cmd open ${{ cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in case $(file --mime-type $f -b) in
text/*) vi $fx;; text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;; *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+1
View File
@@ -17,6 +17,7 @@ _lf () {
-remote -remote
-selection-path -selection-path
-server -server
-single
-version -version
-help -help
) )
+1 -1
View File
@@ -9,7 +9,7 @@
# endif # endif
# #
set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -memprofile -remote -selection-path -server -version -help " set LF_ARGS = "-command -config -cpuprofile -doc -last-dir-path -memprofile -remote -selection-path -server -single -version -help "
complete lf "C/-*/(${LF_ARGS})/" complete lf "C/-*/(${LF_ARGS})/"
complete lfcd "C/-*/(${LF_ARGS})/" complete lfcd "C/-*/(${LF_ARGS})/"
+1
View File
@@ -15,5 +15,6 @@ complete -c lf -o memprofile -r -d 'path to the file to write the memory profile
complete -c lf -o remote -x -d 'send remote command to server' complete -c lf -o remote -x -d 'send remote command to server'
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)' complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
complete -c lf -o server -d 'start server (automatic)' complete -c lf -o server -d 'start server (automatic)'
complete -c lf -o single -d 'start a client without server'
complete -c lf -o version -d 'show version' complete -c lf -o version -d 'show version'
complete -c lf -o help -d 'show help' complete -c lf -o help -d 'show help'
+1
View File
@@ -18,6 +18,7 @@ Register-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {
[CompletionResult]::new('-remote ', '-remote', [CompletionResultType]::ParameterName, 'send remote command to server') [CompletionResult]::new('-remote ', '-remote', [CompletionResultType]::ParameterName, 'send remote command to server')
[CompletionResult]::new('-selection-path ', '-selection-path', [CompletionResultType]::ParameterName, 'path to the file to write selected files on open (to use as open file dialog)') [CompletionResult]::new('-selection-path ', '-selection-path', [CompletionResultType]::ParameterName, 'path to the file to write selected files on open (to use as open file dialog)')
[CompletionResult]::new('-server', '-server', [CompletionResultType]::ParameterName, 'start server (automatic)') [CompletionResult]::new('-server', '-server', [CompletionResultType]::ParameterName, 'start server (automatic)')
[CompletionResult]::new('-single', '-single', [CompletionResultType]::ParameterName, 'start a client without server')
[CompletionResult]::new('-version', '-version', [CompletionResultType]::ParameterName, 'show version') [CompletionResult]::new('-version', '-version', [CompletionResultType]::ParameterName, 'show version')
[CompletionResult]::new('-help', '-help', [CompletionResultType]::ParameterName, 'show help') [CompletionResult]::new('-help', '-help', [CompletionResultType]::ParameterName, 'show help')
) )
+1
View File
@@ -22,6 +22,7 @@ arguments=(
'-remote[send remote command to server]' '-remote[send remote command to server]'
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]' '-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
'-server[start server (automatic)]' '-server[start server (automatic)]'
'-single[start a client without server]'
'-version[show version]' '-version[show version]'
'-help[show help]' '-help[show help]'
'*:filename:_files' '*:filename:_files'
+4 -4
View File
@@ -15,10 +15,10 @@
$tmp = [System.IO.Path]::GetTempFileName() $tmp = [System.IO.Path]::GetTempFileName()
lf -last-dir-path="$tmp" $args lf -last-dir-path="$tmp" $args
if (test-path -pathtype leaf "$tmp") { if (Test-Path -PathType Leaf "$tmp") {
$dir = type "$tmp" $dir = Get-Content "$tmp"
remove-item -force "$tmp" Remove-Item -Force "$tmp"
if (test-path -pathtype container "$dir") { if (Test-Path -PathType Container "$dir") {
if ("$dir" -ne "$pwd") { if ("$dir" -ne "$pwd") {
cd "$dir" cd "$dir"
} }
+1
View File
@@ -36,6 +36,7 @@ map O $mimeopen --ask $f
# use either file extensions and/or mime types here. Below uses an editor for # use either file extensions and/or mime types here. Below uses an editor for
# text files and a file opener for the rest. # text files and a file opener for the rest.
cmd open ${{ cmd open ${{
test -L $f && f=$(readlink -f $f)
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 setsid $OPENER $f > /dev/null 2> /dev/null & done;; *) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
+119 -35
View File
@@ -20,6 +20,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.anchorfind = false gOpts.anchorfind = false
case "anchorfind!": case "anchorfind!":
gOpts.anchorfind = !gOpts.anchorfind gOpts.anchorfind = !gOpts.anchorfind
case "autoquit":
gOpts.autoquit = true
case "noautoquit":
gOpts.autoquit = false
case "autoquit!":
gOpts.autoquit = !gOpts.autoquit
case "dircounts": case "dircounts":
gOpts.dircounts = true gOpts.dircounts = true
case "nodircounts": case "nodircounts":
@@ -41,15 +47,27 @@ func (e *setExpr) eval(app *app, args []string) {
case "drawbox": case "drawbox":
gOpts.drawbox = true gOpts.drawbox = true
app.ui.renew() app.ui.renew()
app.nav.height = app.ui.wins[0].h if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "nodrawbox": case "nodrawbox":
gOpts.drawbox = false gOpts.drawbox = false
app.ui.renew() app.ui.renew()
app.nav.height = app.ui.wins[0].h if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "drawbox!": case "drawbox!":
gOpts.drawbox = !gOpts.drawbox gOpts.drawbox = !gOpts.drawbox
app.ui.renew() app.ui.renew()
app.nav.height = app.ui.wins[0].h if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true)
case "globsearch": case "globsearch":
gOpts.globsearch = true gOpts.globsearch = true
case "noglobsearch": case "noglobsearch":
@@ -528,9 +546,14 @@ func insert(app *app, arg string) {
return return
} }
app.nav.unselect() app.nav.unselect()
if err := remote("send load"); err != nil { if gSingleMode {
app.ui.echoerrf("delete: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -543,9 +566,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
if err := remote("send load"); err != nil { if gSingleMode {
app.ui.echoerrf("rename: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -562,9 +590,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err) app.ui.echoerrf("rename: %s", err)
return return
} }
if err := remote("send load"); err != nil { if gSingleMode {
app.ui.echoerrf("rename: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
@@ -581,8 +614,14 @@ func insert(app *app, arg string) {
if err := app.nav.writeMarks(); err != nil { if err := app.nav.writeMarks(); err != nil {
app.ui.echoerrf("mark-save: %s", err) app.ui.echoerrf("mark-save: %s", err)
} }
if err := remote("send sync"); err != nil { if gSingleMode {
app.ui.echoerrf("mark-save: %s", err) if err := app.nav.sync(); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
} else {
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: ":
normal(app) normal(app)
@@ -618,8 +657,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("mark-remove: %s", err) app.ui.echoerrf("mark-remove: %s", err)
return return
} }
if err := remote("send sync"); err != nil { if gSingleMode {
app.ui.echoerrf("mark-remove: %s", err) if err := app.nav.sync(); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
}
} else {
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)...)
@@ -783,9 +828,16 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.nav.unselect() app.nav.unselect()
if err := remote("send sync"); err != nil { if gSingleMode {
app.ui.echoerrf("copy: %s", err) if err := app.nav.sync(); err != nil {
return app.ui.echoerrf("copy: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("copy: %s", err)
return
}
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "cut": case "cut":
@@ -794,9 +846,16 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
app.nav.unselect() app.nav.unselect()
if err := remote("send sync"); err != nil { if gSingleMode {
app.ui.echoerrf("cut: %s", err) if err := app.nav.sync(); err != nil {
return app.ui.echoerrf("cut: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("cut: %s", err)
return
}
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "paste": case "paste":
@@ -812,9 +871,14 @@ func (e *callExpr) eval(app *app, args []string) {
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 gSingleMode {
app.ui.echoerrf("delete: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
} }
} else { } else {
list, err := app.nav.currFileOrSelections() list, err := app.nav.currFileOrSelections()
@@ -836,16 +900,26 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("clear: %s", err) app.ui.echoerrf("clear: %s", err)
return return
} }
if err := remote("send sync"); err != nil { if gSingleMode {
app.ui.echoerrf("clear: %s", err) if err := app.nav.sync(); err != nil {
return app.ui.echoerrf("clear: %s", err)
return
}
} else {
if err := remote("send sync"); err != nil {
app.ui.echoerrf("clear: %s", err)
return
}
} }
app.ui.loadFileInfo(app.nav) app.ui.loadFileInfo(app.nav)
case "draw": case "draw":
case "redraw": case "redraw":
app.ui.renew() app.ui.renew()
app.ui.screen.Sync() app.ui.screen.Sync()
app.nav.height = app.ui.wins[0].h if app.nav.height != app.ui.wins[0].h {
app.nav.height = app.ui.wins[0].h
app.nav.regCache = make(map[string]*reg)
}
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
case "load": case "load":
app.nav.renew() app.nav.renew()
@@ -968,9 +1042,14 @@ func (e *callExpr) eval(app *app, args []string) {
case "rename": case "rename":
if cmd, ok := gOpts.cmds["rename"]; ok { if cmd, ok := gOpts.cmds["rename"]; ok {
cmd.eval(app, e.args) cmd.eval(app, e.args)
if err := remote("send load"); err != nil { if gSingleMode {
app.ui.echoerrf("rename: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
} }
} else { } else {
curr, err := app.nav.currFile() curr, err := app.nav.currFile()
@@ -1368,9 +1447,14 @@ func (e *callExpr) eval(app *app, args []string) {
return return
} }
if err := remote("send load"); err != nil { if gSingleMode {
app.ui.echoerrf("rename: %s", err) app.nav.renew()
return app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
} }
app.ui.loadFile(app.nav, true) app.ui.loadFile(app.nav, true)
+1
View File
@@ -32,6 +32,7 @@ lf \- terminal file manager
.OP \-remote command .OP \-remote command
.OP \-selection-path path .OP \-selection-path path
.OP \-server .OP \-server
.OP \-single
.OP \-version .OP \-version
.OP \-help .OP \-help
.RI [ directory ] .RI [ directory ]
+1 -3
View File
@@ -3,10 +3,8 @@ module github.com/gokcehan/lf
go 1.12 go 1.12
require ( require (
github.com/gdamore/tcell/v2 v2.2.0 github.com/gdamore/tcell/v2 v2.3.1
github.com/mattn/go-runewidth v0.0.10 github.com/mattn/go-runewidth v0.0.10
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d 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
) )
replace github.com/gdamore/tcell/v2 => github.com/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef
+2 -2
View File
@@ -1,7 +1,7 @@
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/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef h1:I2KyR549rTlwGBHe2uwZHGNNeAIHUpwIs6V522yK+SE= github.com/gdamore/tcell/v2 v2.3.1 h1:htEXmKMzurgcnNH3VqQA7GYlCpdl9LCSNpzFpZOKhJE=
github.com/gokcehan/tcell/v2 v2.2.1-0.20210329222449-4dd2d52e83ef/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= github.com/gdamore/tcell/v2 v2.3.1/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.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg= github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
+35 -37
View File
@@ -13,6 +13,7 @@ lf \- terminal file manager
.OP \-remote command .OP \-remote command
.OP \-selection-path path .OP \-selection-path path
.OP \-server .OP \-server
.OP \-single
.OP \-version .OP \-version
.OP \-help .OP \-help
.RI [ directory ] .RI [ directory ]
@@ -116,6 +117,7 @@ The following options can be used to customize the behavior of lf:
.PP .PP
.EX .EX
anchorfind bool (default on) anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off) dircounts bool (default off)
dirfirst bool (default on) dirfirst bool (default on)
drawbox bool (default off) drawbox bool (default off)
@@ -209,6 +211,13 @@ Configuration files should be located at:
windows C:\eProgramData\elf\elfrc C:\eUsers\e<user>\eAppData\eLocal\elf\elfrc windows C:\eProgramData\elf\elfrc C:\eUsers\e<user>\eAppData\eLocal\elf\elfrc
.EE .EE
.PP .PP
Selection file should be located at:
.PP
.EX
unix ~/.local/share/lf/files
windows C:\eUsers\e<user>\eAppData\eLocal\elf\efiles
.EE
.PP
Marks file should be located at: Marks file should be located at:
.PP .PP
.EX .EX
@@ -446,7 +455,7 @@ Read a shell command to execute and wait for a key press in the end.
shell-async (modal) (default '&') shell-async (modal) (default '&')
.EE .EE
.PP .PP
Read a shell command to execute synchronously without standard I/O. Read a shell command to execute asynchronously without standard I/O.
.PP .PP
.EX .EX
find (modal) (default 'f') find (modal) (default 'f')
@@ -609,6 +618,12 @@ This section shows information about options to customize the behavior. Characte
.PP .PP
When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position. When this option is enabled, find command starts matching patterns from the beginning of file names, otherwise, it can match at an arbitrary position.
.PP .PP
.EX
autoquit bool (default off)
.EE
.PP
Automatically quit server when there are no clients left connected.
.PP
.EX .EX
dircounts bool (default off) dircounts bool (default off)
.EE .EE
@@ -943,7 +958,7 @@ Command 'map' is used to bind a key to a command which can be builtin command, c
map gh cd ~ # builtin command map gh cd ~ # builtin command
map D trash # custom command map D trash # custom command
map i $less $f # shell command map i $less $f # shell command
map U !du -sh # waiting shell command map U !du -csh * # waiting shell command
.EE .EE
.PP .PP
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands: Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
@@ -1170,10 +1185,10 @@ Since such a client may not be available everywhere, lf comes bundled with a com
In this command 'send' is used to send the rest of the string as a command to all connected clients. You can optionally give it an id number to send a command to a single client: In this command 'send' is used to send the rest of the string as a command to all connected clients. You can optionally give it an id number to send a command to a single client:
.PP .PP
.EX .EX
lf -remote 'send 1000 echo hello world' lf -remote 'send 1234 echo hello world'
.EE .EE
.PP .PP
All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command: All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. The value of this variable is set to the process id of the client. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command:
.PP .PP
.EX .EX
lf -remote "send $id echo hello world" lf -remote "send $id echo hello world"
@@ -1194,52 +1209,34 @@ Since lf does not have control flow syntax, remote commands are used for such ne
}} }}
.EE .EE
.PP .PP
Besides 'send' command, there are also two commands to get or set the current file selection. Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved. File names are separated by newline character. Setting the file selection is done with 'save' command: Besides 'send' command, there is a 'quit' command to quit the server when there are no connected clients left, and a 'quit!' command to force quit the server by closing client connections first:
.PP
.EX
lf -remote "$(printf 'save\encopy\enfoo.txt\enbar.txt\enbaz.txt\en')"
.EE
.PP
Getting the file selection is similarly done with 'load' command:
.PP
.EX
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
.EE
.PP
There is a 'quit' command to close client connections and quit the server:
.PP .PP
.EX .EX
lf -remote 'quit' lf -remote 'quit'
lf -remote 'quit!'
.EE .EE
.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, 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. 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 a file. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
.PP .PP
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point: You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
.PP .PP
.EX .EX
cmd paste %{{ cmd paste %{{
load=$(lf -remote 'load') load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p') mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d') list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
cp -R $list . cp -R $list .
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
mv $list . mv $list .
fi fi
lf -remote 'send load' rm ~/.local/share/lf/files
lf -remote 'send clear' lf -remote 'send clear'
}} }}
.EE .EE
.PP .PP
Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls. Some useful things to be considered are to use the backup ('--backup') and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
@@ -1277,6 +1274,7 @@ You may want to use either file extensions or mime types from 'file' command:
.PP .PP
.EX .EX
cmd open ${{ cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in case $(file --mime-type $f -b) in
text/*) vi $fx;; text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;; *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+11 -1
View File
@@ -22,6 +22,7 @@ var (
type arrayFlag []string type arrayFlag []string
var ( var (
gSingleMode bool
gClientID int gClientID int
gHostname string gHostname string
gLastDirPath string gLastDirPath string
@@ -199,6 +200,11 @@ func main() {
false, false,
"start server (automatic)") "start server (automatic)")
singleMode := flag.Bool(
"single",
false,
"start a client without server")
remoteCmd := flag.String( remoteCmd := flag.String(
"remote", "remote",
"", "",
@@ -263,7 +269,11 @@ func main() {
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username)) gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve() serve()
default: default:
checkServer() gSingleMode = *singleMode
if !gSingleMode {
checkServer()
}
gClientID = os.Getpid() gClientID = os.Getpid()
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID)) gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
+46 -15
View File
@@ -243,6 +243,10 @@ func (dir *dir) name() string {
if len(dir.files) == 0 { if len(dir.files) == 0 {
return "" return ""
} }
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
return dir.files[dir.ind].Name() return dir.files[dir.ind].Name()
} }
@@ -797,10 +801,15 @@ loop:
nav.copyTotalChan <- -total nav.copyTotalChan <- -total
if err := remote("send load"); err != nil { if gSingleMode {
errCount++ nav.renew()
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) ui.loadFile(nav, true)
ui.exprChan <- echo } else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
} }
if errCount == 0 { if errCount == 0 {
@@ -897,10 +906,15 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
nav.moveTotalChan <- -len(srcs) nav.moveTotalChan <- -len(srcs)
if err := remote("send load"); err != nil { if gSingleMode {
errCount++ nav.renew()
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) ui.loadFile(nav, true)
ui.exprChan <- echo } else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
} }
if errCount == 0 { if errCount == 0 {
@@ -930,8 +944,14 @@ func (nav *nav) paste(ui *ui) error {
return fmt.Errorf("clearing copy/cut buffer: %s", err) return fmt.Errorf("clearing copy/cut buffer: %s", err)
} }
if err := remote("send sync"); err != nil { if gSingleMode {
return fmt.Errorf("paste: %s", err) if err := nav.sync(); err != nil {
return fmt.Errorf("paste: %s", err)
}
} else {
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
}
} }
return nil return nil
@@ -961,10 +981,15 @@ func (nav *nav) del(ui *ui) error {
nav.deleteTotalChan <- -len(list) nav.deleteTotalChan <- -len(list)
if err := remote("send load"); err != nil { if gSingleMode {
errCount++ nav.renew()
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err) ui.loadFile(nav, true)
ui.exprChan <- echo } else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
} }
}() }()
@@ -1006,7 +1031,13 @@ func (nav *nav) sync() error {
nav.saves[f] = cp nav.saves[f] = cp
} }
return nav.readMarks() path, ok := nav.marks["'"]
err = nav.readMarks()
if ok {
nav.marks["'"] = path
}
return err
} }
func (nav *nav) cd(wd string) error { func (nav *nav) cd(wd string) error {
+2
View File
@@ -29,6 +29,7 @@ type sortType struct {
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
autoquit bool
dircounts bool dircounts bool
drawbox bool drawbox bool
globsearch bool globsearch bool
@@ -71,6 +72,7 @@ var gOpts struct {
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.autoquit = false
gOpts.dircounts = false gOpts.dircounts = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.globsearch = false gOpts.globsearch = false
+2
View File
@@ -31,6 +31,7 @@ var (
var ( var (
gUser *user.User gUser *user.User
gConfigPaths []string gConfigPaths []string
gFilesPath string
gMarksPath string gMarksPath string
gHistoryPath string gHistoryPath string
) )
@@ -83,6 +84,7 @@ func init() {
data = filepath.Join(gUser.HomeDir, ".local", "share") data = filepath.Join(gUser.HomeDir, ".local", "share")
} }
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks") gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history") gHistoryPath = filepath.Join(data, "lf", "history")
+2
View File
@@ -30,6 +30,7 @@ var (
var ( var (
gUser *user.User gUser *user.User
gConfigPaths []string gConfigPaths []string
gFilesPath string
gMarksPath string gMarksPath string
gHistoryPath string gHistoryPath string
) )
@@ -67,6 +68,7 @@ func init() {
filepath.Join(data, "lf", "lfrc"), filepath.Join(data, "lf", "lfrc"),
} }
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks") gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history") gHistoryPath = filepath.Join(data, "lf", "history")
} }
+35 -33
View File
@@ -10,8 +10,6 @@ import (
) )
var ( var (
gCopyFile bool
gFileList []string
gConnList = make(map[int]net.Conn) gConnList = make(map[int]net.Conn)
gQuitChan = make(chan struct{}, 1) gQuitChan = make(chan struct{}, 1)
gListener net.Listener gListener net.Listener
@@ -55,6 +53,15 @@ func listen(l net.Listener) {
} }
} }
func echoerr(c net.Conn, msg string) {
fmt.Fprintln(c, msg)
log.Printf(msg)
}
func echoerrf(c net.Conn, format string, a ...interface{}) {
echoerr(c, fmt.Sprintf(format, a...))
}
func handleConn(c net.Conn) { func handleConn(c net.Conn) {
s := bufio.NewScanner(c) s := bufio.NewScanner(c)
@@ -63,42 +70,29 @@ Loop:
log.Printf("listen: %s", s.Text()) log.Printf("listen: %s", s.Text())
word, rest := splitWord(s.Text()) word, rest := splitWord(s.Text())
switch word { switch word {
case "save":
s.Scan()
switch s.Text() {
case "copy":
gCopyFile = true
case "move":
gCopyFile = false
default:
log.Printf("unexpected option to copy file(s): %s", s.Text())
break Loop
}
gFileList = nil
for s.Scan() && s.Text() != "" {
gFileList = append(gFileList, s.Text())
}
case "load":
if gCopyFile {
fmt.Fprintln(c, "copy")
} else {
fmt.Fprintln(c, "move")
}
for _, f := range gFileList {
fmt.Fprintln(c, f)
}
fmt.Fprintln(c)
case "conn": case "conn":
if rest != "" { if rest != "" {
word2, _ := splitWord(rest) word2, _ := splitWord(rest)
id, err := strconv.Atoi(word2) id, err := strconv.Atoi(word2)
if err != nil { if err != nil {
log.Print("listen: conn: client id should be a number") echoerr(c, "listen: conn: client id should be a number")
} else { } else {
gConnList[id] = c gConnList[id] = c
} }
} else { } else {
log.Print("listen: conn: requires a client id") echoerr(c, "listen: conn: requires a client id")
}
case "drop":
if rest != "" {
word2, _ := splitWord(rest)
id, err := strconv.Atoi(word2)
if err != nil {
echoerr(c, "listen: drop: client id should be a number")
} else {
delete(gConnList, id)
}
} else {
echoerr(c, "listen: drop: requires a client id")
} }
case "send": case "send":
if rest != "" { if rest != "" {
@@ -109,12 +103,20 @@ Loop:
fmt.Fprintln(c, rest) fmt.Fprintln(c, rest)
} }
} else { } else {
if c, ok := gConnList[id]; ok { if c2, ok := gConnList[id]; ok {
fmt.Fprintln(c, rest2) fmt.Fprintln(c2, rest2)
} else {
echoerr(c, "listen: send: no such client id is connected")
} }
} }
} }
case "quit": case "quit":
if len(gConnList) == 0 {
gQuitChan <- struct{}{}
gListener.Close()
break Loop
}
case "quit!":
gQuitChan <- struct{}{} gQuitChan <- struct{}{}
for _, c := range gConnList { for _, c := range gConnList {
fmt.Fprintln(c, "echo server is quitting...") fmt.Fprintln(c, "echo server is quitting...")
@@ -123,12 +125,12 @@ Loop:
gListener.Close() gListener.Close()
break Loop break Loop
default: default:
log.Printf("listen: unexpected command: %s", word) echoerrf(c, "listen: unexpected command: %s", word)
} }
} }
if s.Err() != nil { if s.Err() != nil {
log.Printf("listening: %s", s.Err()) echoerrf(c, "listening: %s", s.Err())
} }
c.Close() c.Close()
+23 -14
View File
@@ -171,7 +171,7 @@ func printLength(s string) int {
r, w := utf8.DecodeRuneInString(s[i:]) r, w := utf8.DecodeRuneInString(s[i:])
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' { if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
j := strings.IndexByte(s[i:min(len(s), i+32)], 'm') j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
if j == -1 { if j == -1 {
continue continue
} }
@@ -199,12 +199,13 @@ func (win *win) print(screen tcell.Screen, x, y int, st tcell.Style, s string) t
r, w := utf8.DecodeRuneInString(s[i:]) r, w := utf8.DecodeRuneInString(s[i:])
if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' { if r == gEscapeCode && i+1 < len(s) && s[i+1] == '[' {
j := strings.IndexByte(s[i:min(len(s), i+32)], 'm') j := strings.IndexAny(s[i:min(len(s), i+64)], "mK")
if j == -1 { if j == -1 {
continue continue
} }
if s[i+j] == 'm' {
st = applyAnsiCodes(s[i+2:i+j], st) st = applyAnsiCodes(s[i+2:i+j], st)
}
i += j i += j
continue continue
@@ -499,7 +500,7 @@ func getWidths(wtot int) []int {
wsum := 0 wsum := 0
for i := 0; i < wlen-1; i++ { for i := 0; i < wlen-1; i++ {
widths[i] = gOpts.ratios[i] * (wtot / rsum) widths[i] = gOpts.ratios[i] * wtot / rsum
wsum += widths[i] wsum += widths[i]
} }
widths[wlen-1] = wtot - wsum widths[wlen-1] = wtot - wsum
@@ -835,16 +836,24 @@ func (ui *ui) draw(nav *nav) {
ui.drawStatLine(nav) ui.drawStatLine(nav)
ui.screen.HideCursor() ui.screen.HideCursor()
case ">": case ">":
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg) pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg), 0, st, string(ui.cmdAccLeft)) left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight)) right := ui.cmdAccRight
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y) ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(prefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg), 0, st, string(left))
ui.msgWin.print(ui.screen, len(prefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y)
default: default:
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix) prefix := ui.cmdPrefix[:min(ui.msgWin.w-1, len(ui.cmdPrefix))]
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(ui.cmdAccLeft)) pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(prefix)-1)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight)) left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y) right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, prefix)
ui.msgWin.print(ui.screen, len(prefix), 0, st, string(left))
ui.msgWin.print(ui.screen, len(prefix)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(prefix)+runeSliceWidth(left), ui.msgWin.y)
} }
if gOpts.preview { if gOpts.preview {