Compare commits

34 Commits
Author SHA1 Message Date
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
Gokcehan 4601e74d66 export OLDPWD variable as the initial directory
cc #601
2021-04-13 23:48:49 +03:00
Gokcehan c8f60623f3 cleanup 2021-04-13 23:29:26 +03:00
Gokcehan fec767d11b dont change findlen to force find with cmd-enter
cc #605
2021-04-13 20:32:01 +03:00
gotroyb127 0dcfb3d4fe force find at cmd-enter (#605)
cc #559
2021-04-06 19:02:16 +03:00
gotroyb127 0cfd34f30d add 'waitmsg' option to configure the message after shell-wait commands (#604) 2021-04-06 18:57:23 +03:00
Gokcehan 229b7b1ade export PWD on windows to fix broken build
cc #591
2021-04-04 18:30:00 +03:00
Gokcehan ca0068514a add 'shellflag' option to customize shell flag
cc #597
2021-04-04 18:23:14 +03:00
Gokcehan aebff483a7 update tcell version to fix delete key on st
cc #486
2021-03-30 01:34:58 +03:00
Gokcehan 5166eef0b3 change to local tcell fork
cc #586
2021-03-30 01:12:58 +03:00
Gokcehan 73be81595e handle ui suspend/resume errors
cc #592
2021-03-28 18:54:40 +03:00
Gokcehan 06bf58851b update doc
cc #591
2021-03-19 14:00:00 +03:00
SeerLite b7aaa23bd0 Export $PWD to shell (#591)
Most shells use $PWD to show the right working directory when it's a
symlink. Without it, they'd fall back to the absolute path instead.
2021-03-19 13:58:10 +03:00
SPFab a9cb7156a3 added ability to use custom config file (#587) 2021-03-09 14:35:50 +03:00
Gokcehan 91f40b1f02 update example config 2021-03-03 18:06:44 +03:00
25 changed files with 591 additions and 298 deletions

No files matched your search

+108 -13
View File
@@ -49,8 +49,7 @@ func newApp(ui *ui, nav *nav) *app {
case os.Interrupt:
return
case syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM:
app.writeHistory()
os.Remove(gLogPath)
app.quit()
os.Exit(3)
return
}
@@ -59,6 +58,23 @@ func newApp(ui *ui, nav *nav) *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) {
log.Printf("reading file: %s", path)
@@ -80,6 +96,68 @@ 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 {
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 {
f, err := os.Open(gHistoryPath)
if os.IsNotExist(err) {
@@ -157,7 +235,10 @@ func (app *app) writeHistory() error {
func (app *app) loop() {
go app.nav.previewLoop(app.ui)
serverChan := readExpr()
var serverChan <-chan expr
if !gSingleMode {
serverChan = readExpr()
}
app.ui.readExpr()
@@ -174,9 +255,17 @@ func (app *app) loop() {
}()
}
for _, path := range gConfigPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
app.readFile(path)
if gConfigPath != "" {
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
app.readFile(gConfigPath)
} else {
log.Printf("config file does not exist: %s", err)
}
} else {
for _, path := range gConfigPaths {
if _, err := os.Stat(path); !os.IsNotExist(err) {
app.readFile(path)
}
}
}
@@ -210,14 +299,12 @@ func (app *app) loop() {
continue
}
app.quit()
app.nav.previewChan <- ""
log.Print("bye!")
if err := app.writeHistory(); err != nil {
log.Printf("writing history file: %s", err)
}
if gLastDirPath != "" {
f, err := os.Create(gLastDirPath)
if err != nil {
@@ -363,7 +450,7 @@ func (app *app) exportFiles() {
currSelections := app.nav.currSelections()
exportFiles(currFile, currSelections)
exportFiles(currFile, currSelections, app.nav.currDir().path)
}
// This function is used to run a shell command. Modes are as follows:
@@ -388,8 +475,16 @@ func (app *app) runShell(s string, args []string, prefix string) {
cmd.Stderr = os.Stderr
app.nav.previewChan <- ""
app.ui.suspend()
defer app.ui.resume()
if err := app.ui.suspend(); err != nil {
log.Printf("suspend: %s", err)
}
defer func() {
if err := app.ui.resume(); err != nil {
app.quit()
os.Exit(3)
return
}
}()
defer app.nav.renew()
err = cmd.Run()
+4 -64
View File
@@ -29,7 +29,6 @@ func run() {
if err != nil {
panic(err)
}
defer os.Remove(gLogPath)
defer f.Close()
log.SetOutput(f)
@@ -39,6 +38,10 @@ func run() {
nav := newNav(ui.wins[0].h)
app := newApp(ui, nav)
if err := nav.sync(); err != nil {
app.ui.echoerrf("sync: %s", err)
}
if err := app.nav.readMarks(); err != nil {
app.ui.echoerrf("reading marks file: %s", err)
}
@@ -85,69 +88,6 @@ func readExpr() <-chan expr {
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 {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
+4
View File
@@ -118,6 +118,8 @@ func applyAnsiCodes(s string, st tcell.Style) tcell.Style {
st = st.StrikeThrough(true)
case n >= 30 && n <= 37:
st = st.Foreground(tcell.PaletteColor(n - 30))
case n >= 90 && n <= 97:
st = st.Foreground(tcell.PaletteColor(n - 82))
case n == 38:
if i+3 <= len(nums) && nums[i+1] == 5 {
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:
st = st.Background(tcell.PaletteColor(n - 40))
case n >= 100 && n <= 107:
st = st.Background(tcell.PaletteColor(n - 92))
case n == 48:
if i+3 <= len(nums) && nums[i+1] == 5 {
st = st.Background(tcell.PaletteColor(nums[i+2]))
+5
View File
@@ -70,6 +70,9 @@ var (
"anchorfind",
"noanchorfind",
"anchorfind!",
"autoquit",
"noautoquit",
"autoquit!",
"dircounts",
"nodircounts",
"dircounts!",
@@ -118,6 +121,7 @@ var (
"smartdia",
"nosmartdia",
"smartdia!",
"waitmsg",
"wrapscan",
"nowrapscan",
"wrapscan!",
@@ -138,6 +142,7 @@ var (
"promptfmt",
"ratios",
"shell",
"shellflag",
"shellopts",
"sortby",
"timefmt",
+42 -29
View File
@@ -6,9 +6,8 @@ lf is a terminal file manager.
Source code can be found in the repository at https://github.com/gokcehan/lf.
This documentation can either be read from terminal using 'lf -doc' or online
at https://godoc.org/github.com/gokcehan/lf. You can also use 'doc' command
(default '<f-1>') inside lf to view the documentation in a pager.
This documentation can either be read from terminal using 'lf -doc' or online at https://godoc.org/github.com/gokcehan/lf.
You can also use 'doc' command (default '<f-1>') inside lf to view the documentation in a pager.
You can run 'lf -help' to see descriptions of command line options.
@@ -99,6 +98,7 @@ The following command line commands are provided by lf:
The following options can be used to customize the behavior of lf:
anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
drawbox bool (default off)
@@ -126,6 +126,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off)
scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '')
smartcase bool (default on)
smartdia bool (default off)
@@ -133,6 +134,7 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8)
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
@@ -142,6 +144,8 @@ The following environment variables are exported for shell commands:
fs
fx
id
PWD
OLDPWD
LF_LEVEL
OPENER
EDITOR
@@ -181,6 +185,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/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:
unix ~/.local/share/lf/marks
@@ -486,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.
autoquit bool (default off)
Automatically quit server when there are no clients left connected.
dircounts bool (default off)
When this option is enabled, directory sizes show the number of items inside instead of the size of directory file.
@@ -640,8 +653,11 @@ 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 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'.
Shell commands are executed as 'shell shellopts shellflag command -- arguments'.
shellflag string (default '-c' for unix and '/c' for windows)
Command line flag used to pass shell commands.
shellopts []string (default '')
@@ -674,6 +690,10 @@ Format string of the file modification time shown in the bottom line.
Truncate character shown at the end when the file name does not fit to the pane.
waitmsg string (default 'Press any key to continue')
String shown after commands of shell-wait type.
wrapscan bool (default on)
Searching can wrap around the file list.
@@ -703,6 +723,14 @@ Selected file(s) (i.e. 'fs') if there are any selected files, otherwise current
Id of the running client.
PWD
Present working directory.
OLDPWD
Initial working directory.
LF_LEVEL
The value of this variable is set to the current nesting level when you run lf from a shell spawned inside lf.
@@ -763,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 D trash # custom 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:
@@ -978,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.
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.
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:
@@ -1001,27 +1030,10 @@ For example, you can configure the number of columns in the ui with respect to t
fi
}}
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:
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:
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:
lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client.
This should not be needed for users.
@@ -1039,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.
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'.
Similarly 'paste' after a 'cut' operation moves the file.
@@ -1048,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:
cmd paste %{{
load=$(lf -remote 'load')
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
@@ -1056,7 +1068,7 @@ You can use the following example as a starting point:
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
@@ -1115,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:
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+53 -37
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:
anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
drawbox bool (default off)
@@ -129,6 +130,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off)
scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '')
smartcase bool (default on)
smartdia bool (default off)
@@ -136,6 +138,7 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8)
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
@@ -145,6 +148,8 @@ The following environment variables are exported for shell commands:
fs
fx
id
PWD
OLDPWD
LF_LEVEL
OPENER
EDITOR
@@ -185,6 +190,11 @@ Configuration files should be located at:
unix /etc/lf/lfrc ~/.config/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:
unix ~/.local/share/lf/marks
@@ -511,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
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)
When this option is enabled, directory sizes show the number of items inside
@@ -684,8 +698,11 @@ beginning or end of the list to show the maximum number of items.
shell string (default 'sh' for unix and 'cmd' for windows)
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'.
'shell shellopts shellflag command -- arguments'.
shellflag string (default '-c' for unix and '/c' for windows)
Command line flag used to pass shell commands.
shellopts []string (default '')
@@ -720,6 +737,10 @@ Format string of the file modification time shown in the bottom line.
Truncate character shown at the end when the file name does not fit to the
pane.
waitmsg string (default 'Press any key to continue')
String shown after commands of shell-wait type.
wrapscan bool (default on)
Searching can wrap around the file list.
@@ -754,6 +775,14 @@ current file selection (i.e. 'f').
Id of the running client.
PWD
Present working directory.
OLDPWD
Initial working directory.
LF_LEVEL
The value of this variable is set to the current nesting level when you run
@@ -827,7 +856,7 @@ command, custom command, or shell command:
map gh cd ~ # builtin command
map D trash # custom 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:
@@ -1076,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
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. 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
back to itself. So now you can display a message in the current client by
calling the following in a shell command:
@@ -1102,27 +1132,12 @@ with respect to the terminal width as follows:
fi
}}
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:
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:
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:
lf -remote 'quit'
lf -remote 'quit!'
Lastly, there is a 'conn' command to connect the server as a client. This
should not be needed for users.
@@ -1147,7 +1162,7 @@ corresponding file operation.
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'.
name to a file. The actual file copying takes place when you 'paste'.
Similarly 'paste' after a 'cut' operation moves the file.
You can customize copy and move operations by defining a 'paste' command.
@@ -1155,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
point:
cmd paste %{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd paste %{{
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
Some useful things to be considered are to use the backup ('--backup')
and/or preserve attributes ('-a') options with 'cp' and 'mv' commands if
@@ -1240,6 +1255,7 @@ You may want to use either file extensions or mime types from 'file'
command:
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+2
View File
@@ -9,6 +9,7 @@
_lf () {
local -a opts=(
-command
-config
-cpuprofile
-doc
-last-dir-path
@@ -16,6 +17,7 @@ _lf () {
-remote
-selection-path
-server
-single
-version
-help
)
+1 -1
View File
@@ -9,7 +9,7 @@
# endif
#
set LF_ARGS = "-command -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 lfcd "C/-*/(${LF_ARGS})/"
+2
View File
@@ -7,6 +7,7 @@
#
complete -c lf -o command -r -d 'command to execute on client initialization'
complete -c lf -o config -r -d 'path to the config file (instead of the usual paths)'
complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'
complete -c lf -o doc -d 'show documentation'
complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'
@@ -14,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 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 single -d 'start a client without server'
complete -c lf -o version -d 'show version'
complete -c lf -o help -d 'show help'
+3
View File
@@ -10,6 +10,7 @@ Register-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {
param($wordToComplete)
$completions = @(
[CompletionResult]::new('-command ', '-command', [CompletionResultType]::ParameterName, 'command to execute on client initialization')
[CompletionResult]::new('-config ', '-config', [CompletionResultType]::ParameterName, 'path to the config file (instead of the usual paths)')
[CompletionResult]::new('-cpuprofile ', '-cpuprofile', [CompletionResultType]::ParameterName, 'path to the file to write the CPU profile')
[CompletionResult]::new('-doc', '-doc', [CompletionResultType]::ParameterName, 'show documentation')
[CompletionResult]::new('-last-dir-path ', '-last-dir-path', [CompletionResultType]::ParameterName, 'path to the file to write the last dir on exit (to use for cd)')
@@ -17,7 +18,9 @@ Register-ArgumentCompleter -Native -CommandName 'lf' -ScriptBlock {
[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('-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('-help', '-help', [CompletionResultType]::ParameterName, 'show help')
)
if ($wordToComplete.StartsWith('-')) {
+3
View File
@@ -14,6 +14,7 @@ local arguments
arguments=(
'-command[command to execute on client initialization]'
'-config[path to the config file (instead of the usual paths)]'
'-cpuprofile[path to the file to write the CPU profile]'
'-doc[show documentation]'
'-last-dir-path[path to the file to write the last dir on exit (to use for cd)]'
@@ -21,7 +22,9 @@ arguments=(
'-remote[send remote command to server]'
'-selection-path[path to the file to write selected files on open (to use as open file dialog)]'
'-server[start server (automatic)]'
'-single[start a client without server]'
'-version[show version]'
'-help[show help]'
'*:filename:_files'
)
+5 -5
View File
@@ -4,11 +4,11 @@
#
# You may also like to assign a key to this command:
#
# Set-PSReadLineKeyHandler -Chord Ctrl+o -ScriptBlock {
# [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
# [Microsoft.PowerShell.PSConsoleReadLine]::Insert('lfcd.ps1')
# [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# }
# Set-PSReadLineKeyHandler -Chord Ctrl+o -ScriptBlock {
# [Microsoft.PowerShell.PSConsoleReadLine]::RevertLine()
# [Microsoft.PowerShell.PSConsoleReadLine]::Insert('lfcd.ps1')
# [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
# }
#
# You may put this in one of the profiles found in $PROFILE.
#
+2 -1
View File
@@ -1,4 +1,4 @@
# interpreter for shell commands (needs to be POSIX compatible)
# interpreter for shell commands
set shell sh
# set '-eu' options for shell commands
@@ -36,6 +36,7 @@ map O $mimeopen --ask $f
# use either file extensions and/or mime types here. Below uses an editor for
# text files and a file opener for the rest.
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) $EDITOR $fx;;
*) for f in $fx; do setsid $OPENER $f > /dev/null 2> /dev/null & done;;
+139 -35
View File
@@ -20,6 +20,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.anchorfind = false
case "anchorfind!":
gOpts.anchorfind = !gOpts.anchorfind
case "autoquit":
gOpts.autoquit = true
case "noautoquit":
gOpts.autoquit = false
case "autoquit!":
gOpts.autoquit = !gOpts.autoquit
case "dircounts":
gOpts.dircounts = true
case "nodircounts":
@@ -41,15 +47,27 @@ func (e *setExpr) eval(app *app, args []string) {
case "drawbox":
gOpts.drawbox = true
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":
gOpts.drawbox = false
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!":
gOpts.drawbox = !gOpts.drawbox
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":
gOpts.globsearch = true
case "noglobsearch":
@@ -178,6 +196,8 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.smartdia = false
case "smartdia!":
gOpts.smartdia = !gOpts.smartdia
case "waitmsg":
gOpts.waitmsg = e.val
case "wrapscan":
gOpts.wrapscan = true
case "nowrapscan":
@@ -309,6 +329,8 @@ func (e *setExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
case "shell":
gOpts.shell = e.val
case "shellflag":
gOpts.shellflag = e.val
case "shellopts":
if e.val == "" {
gOpts.shellopts = nil
@@ -524,9 +546,14 @@ func insert(app *app, arg string) {
return
}
app.nav.unselect()
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
if gSingleMode {
app.nav.renew()
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.loadFileInfo(app.nav)
@@ -539,9 +566,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err)
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
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.loadFileInfo(app.nav)
@@ -558,9 +590,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("rename: %s", err)
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
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.loadFileInfo(app.nav)
@@ -577,8 +614,14 @@ func insert(app *app, arg string) {
if err := app.nav.writeMarks(); err != nil {
app.ui.echoerrf("mark-save: %s", err)
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-save: %s", err)
if gSingleMode {
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: ":
normal(app)
@@ -614,8 +657,14 @@ func insert(app *app, arg string) {
app.ui.echoerrf("mark-remove: %s", err)
return
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("mark-remove: %s", err)
if gSingleMode {
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:
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
@@ -779,9 +828,16 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.unselect()
if err := remote("send sync"); err != nil {
app.ui.echoerrf("copy: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
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)
case "cut":
@@ -790,9 +846,16 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
app.nav.unselect()
if err := remote("send sync"); err != nil {
app.ui.echoerrf("cut: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
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)
case "paste":
@@ -808,9 +871,14 @@ func (e *callExpr) eval(app *app, args []string) {
if cmd, ok := gOpts.cmds["delete"]; ok {
cmd.eval(app, e.args)
app.nav.unselect()
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("delete: %s", err)
return
}
}
} else {
list, err := app.nav.currFileOrSelections()
@@ -832,16 +900,26 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.echoerrf("clear: %s", err)
return
}
if err := remote("send sync"); err != nil {
app.ui.echoerrf("clear: %s", err)
return
if gSingleMode {
if err := app.nav.sync(); err != nil {
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)
case "draw":
case "redraw":
app.ui.renew()
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)
case "load":
app.nav.renew()
@@ -964,9 +1042,14 @@ func (e *callExpr) eval(app *app, args []string) {
case "rename":
if cmd, ok := gOpts.cmds["rename"]; ok {
cmd.eval(app, e.args)
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
app.ui.loadFile(app.nav, true)
} else {
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
}
}
} else {
curr, err := app.nav.currFile()
@@ -1301,6 +1384,22 @@ func (e *callExpr) eval(app *app, args []string) {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "find: ":
app.ui.cmdPrefix = ""
if moved, found := app.nav.findNext(); !found {
app.ui.echoerrf("find: pattern not found: %s", app.nav.find)
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "find-back: ":
app.ui.cmdPrefix = ""
if moved, found := app.nav.findPrev(); !found {
app.ui.echoerrf("find-back: pattern not found: %s", app.nav.find)
} else if moved {
app.ui.loadFile(app.nav, true)
app.ui.loadFileInfo(app.nav)
}
case "rename: ":
app.ui.cmdPrefix = ""
if curr, err := app.nav.currFile(); err != nil {
@@ -1348,9 +1447,14 @@ func (e *callExpr) eval(app *app, args []string) {
return
}
if err := remote("send load"); err != nil {
app.ui.echoerrf("rename: %s", err)
return
if gSingleMode {
app.nav.renew()
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)
+3
View File
@@ -24,6 +24,7 @@ lf \- terminal file manager
.SH SYNOPSIS
.SY lf
.OP \-command command
.OP \-config path
.OP \-cpuprofile path
.OP \-doc
.OP \-last-dir-path path
@@ -31,7 +32,9 @@ lf \- terminal file manager
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ directory ]
.YS
.SH DESCRIPTION
+1 -1
View File
@@ -3,7 +3,7 @@ module github.com/gokcehan/lf
go 1.12
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
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
gopkg.in/djherbis/times.v1 v1.2.0
+2 -3
View File
@@ -1,7 +1,7 @@
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/tcell/v2 v2.2.0 h1:vSyEgKwraXPSOkvCk7IwOSyX+Pv3V2cV9CikJMXg4U4=
github.com/gdamore/tcell/v2 v2.2.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
github.com/gdamore/tcell/v2 v2.3.1 h1:htEXmKMzurgcnNH3VqQA7GYlCpdl9LCSNpzFpZOKhJE=
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/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
@@ -10,7 +10,6 @@ github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
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=
+65 -37
View File
@@ -5,6 +5,7 @@ lf \- terminal file manager
.SH SYNOPSIS
.SY lf
.OP \-command command
.OP \-config path
.OP \-cpuprofile path
.OP \-doc
.OP \-last-dir-path path
@@ -12,7 +13,9 @@ lf \- terminal file manager
.OP \-remote command
.OP \-selection-path path
.OP \-server
.OP \-single
.OP \-version
.OP \-help
.RI [ directory ]
.YS
.SH DESCRIPTION
@@ -114,6 +117,7 @@ The following options can be used to customize the behavior of lf:
.PP
.EX
anchorfind bool (default on)
autoquit bool (default off)
dircounts bool (default off)
dirfirst bool (default on)
drawbox bool (default off)
@@ -141,6 +145,7 @@ The following options can be used to customize the behavior of lf:
reverse bool (default off)
scrolloff int (default 0)
shell string (default 'sh' for unix and 'cmd' for windows)
shellflag string (default '-c' for unix and '/c' for windows)
shellopts []string (default '')
smartcase bool (default on)
smartdia bool (default off)
@@ -148,6 +153,7 @@ The following options can be used to customize the behavior of lf:
tabstop int (default 8)
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
.EE
@@ -159,6 +165,8 @@ The following environment variables are exported for shell commands:
fs
fx
id
PWD
OLDPWD
LF_LEVEL
OPENER
EDITOR
@@ -203,6 +211,13 @@ Configuration files should be located at:
windows C:\eProgramData\elf\elfrc C:\eUsers\e<user>\eAppData\eLocal\elf\elfrc
.EE
.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:
.PP
.EX
@@ -603,6 +618,12 @@ This section shows information about options to customize the behavior. Characte
.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.
.PP
.EX
autoquit bool (default off)
.EE
.PP
Automatically quit server when there are no clients left connected.
.PP
.EX
dircounts bool (default off)
.EE
@@ -763,7 +784,13 @@ 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)
.EE
.PP
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'.
Shell executable to use for shell commands. Shell commands are executed as 'shell shellopts shellflag command -- arguments'.
.PP
.EX
shellflag string (default '-c' for unix and '/c' for windows)
.EE
.PP
Command line flag used to pass shell commands.
.PP
.EX
shellopts []string (default '')
@@ -807,6 +834,12 @@ Format string of the file modification time shown in the bottom line.
.PP
Truncate character shown at the end when the file name does not fit to the pane.
.PP
.EX
waitmsg string (default 'Press any key to continue')
.EE
.PP
String shown after commands of shell-wait type.
.PP
.EX
wrapscan bool (default on)
.EE
@@ -845,6 +878,18 @@ Selected file(s) (i.e. 'fs') if there are any selected files, otherwise current
.PP
Id of the running client.
.PP
.EX
PWD
.EE
.PP
Present working directory.
.PP
.EX
OLDPWD
.EE
.PP
Initial working directory.
.PP
.EX
LF_LEVEL
.EE
@@ -913,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 D trash # custom command
map i $less $f # shell command
map U !du -sh # waiting shell command
map U !du -csh * # waiting shell command
.EE
.PP
Command 'cmap' is used to bind a key to a command line command which can only be one of the builtin commands:
@@ -1140,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:
.PP
.EX
lf -remote 'send 1000 echo hello world'
lf -remote 'send 1234 echo hello world'
.EE
.PP
All clients have a unique id number but you may not be aware of the id number when you are writing a command. For this purpose, an '$id' variable is exported to the environment for shell commands. You can use it to send a remote command from a client to the server which in return sends a command back to itself. So now you can display a message in the current client by calling the following in a shell command:
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
.EX
lf -remote "send $id echo hello world"
@@ -1164,52 +1209,34 @@ Since lf does not have control flow syntax, remote commands are used for such ne
}}
.EE
.PP
Besides 'send' command, there are also two commands to get or set the current file selection. Two possible modes 'copy' and 'move' specify whether selected files are to be copied or moved. File names are separated by newline character. Setting the file selection is done with 'save' command:
.PP
.EX
lf -remote "$(printf 'save\encopy\enfoo.txt\enbar.txt\enbaz.txt\en')"
.EE
.PP
Getting the file selection is similarly done with 'load' command:
.PP
.EX
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with $list
fi
.EE
.PP
There is a 'quit' command to close client connections and quit the server:
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 'quit'
lf -remote 'quit!'
.EE
.PP
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
.SH FILE OPERATIONS
lf uses 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
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
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
.EX
cmd paste %{{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
lf -remote 'send load'
lf -remote 'send clear'
}}
cmd paste %{{
load=$(cat ~/.local/share/lf/files)
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
if [ $mode = 'copy' ]; then
cp -R $list .
elif [ $mode = 'move' ]; then
mv $list .
fi
rm ~/.local/share/lf/files
lf -remote 'send clear'
}}
.EE
.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.
@@ -1247,6 +1274,7 @@ You may want to use either file extensions or mime types from 'file' command:
.PP
.EX
cmd open ${{
test -L $f && f=$(readlink -f $f)
case $(file --mime-type $f -b) in
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
+28 -6
View File
@@ -22,6 +22,7 @@ var (
type arrayFlag []string
var (
gSingleMode bool
gClientID int
gHostname string
gLastDirPath string
@@ -31,6 +32,7 @@ var (
gLogPath string
gServerLogPath string
gSelect string
gConfigPath string
gCommands arrayFlag
gVersion string
)
@@ -64,6 +66,12 @@ func exportEnvVars() {
os.Setenv("PAGER", envPager)
os.Setenv("SHELL", envShell)
dir, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
}
os.Setenv("OLDPWD", dir)
level, err := strconv.Atoi(envLevel)
if err != nil {
log.Printf("reading lf level: %s", err)
@@ -187,16 +195,21 @@ func main() {
false,
"show version")
remoteCmd := flag.String(
"remote",
"",
"send remote command to server")
serverMode := flag.Bool(
"server",
false,
"start server (automatic)")
singleMode := flag.Bool(
"single",
false,
"start a client without server")
remoteCmd := flag.String(
"remote",
"",
"send remote command to server")
cpuprofile := flag.String(
"cpuprofile",
"",
@@ -217,6 +230,11 @@ func main() {
"",
"path to the file to write selected files on open (to use as open file dialog)")
flag.StringVar(&gConfigPath,
"config",
"",
"path to the config file (instead of the usual paths)")
flag.Var(&gCommands,
"command",
"command to execute on client initialization")
@@ -251,7 +269,11 @@ func main() {
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
serve()
default:
checkServer()
gSingleMode = *singleMode
if !gSingleMode {
checkServer()
}
gClientID = os.Getpid()
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 {
return ""
}
dir.ind = max(dir.ind, 0)
dir.ind = min(dir.ind, len(dir.files)-1)
return dir.files[dir.ind].Name()
}
@@ -797,10 +801,15 @@ loop:
nav.copyTotalChan <- -total
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
if errCount == 0 {
@@ -897,10 +906,15 @@ func (nav *nav) moveAsync(ui *ui, srcs []string, dstDir string) {
nav.moveTotalChan <- -len(srcs)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} else {
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
}
}
if errCount == 0 {
@@ -930,8 +944,14 @@ func (nav *nav) paste(ui *ui) error {
return fmt.Errorf("clearing copy/cut buffer: %s", err)
}
if err := remote("send sync"); err != nil {
return fmt.Errorf("paste: %s", err)
if gSingleMode {
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
@@ -961,10 +981,15 @@ func (nav *nav) del(ui *ui) error {
nav.deleteTotalChan <- -len(list)
if err := remote("send load"); err != nil {
errCount++
echo.args[0] = fmt.Sprintf("[%d] %s", errCount, err)
ui.exprChan <- echo
if gSingleMode {
nav.renew()
ui.loadFile(nav, true)
} 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
}
return nav.readMarks()
path, ok := nav.marks["'"]
err = nav.readMarks()
if ok {
nav.marks["'"] = path
}
return err
}
func (nav *nav) cd(wd string) error {
+6
View File
@@ -29,6 +29,7 @@ type sortType struct {
var gOpts struct {
anchorfind bool
autoquit bool
dircounts bool
drawbox bool
globsearch bool
@@ -42,6 +43,7 @@ var gOpts struct {
relativenumber bool
smartcase bool
smartdia bool
waitmsg string
wrapscan bool
wrapscroll bool
findlen int
@@ -55,6 +57,7 @@ var gOpts struct {
cleaner string
promptfmt string
shell string
shellflag string
timefmt string
truncatechar string
ratios []int
@@ -69,6 +72,7 @@ var gOpts struct {
func init() {
gOpts.anchorfind = true
gOpts.autoquit = false
gOpts.dircounts = false
gOpts.drawbox = false
gOpts.globsearch = false
@@ -82,6 +86,7 @@ func init() {
gOpts.relativenumber = false
gOpts.smartcase = true
gOpts.smartdia = false
gOpts.waitmsg = "Press any key to continue"
gOpts.wrapscan = true
gOpts.wrapscroll = false
gOpts.findlen = 1
@@ -95,6 +100,7 @@ func init() {
gOpts.cleaner = ""
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
gOpts.shell = gDefaultShell
gOpts.shellflag = gDefaultShellFlag
gOpts.timefmt = time.ANSIC
gOpts.truncatechar = "~"
gOpts.ratios = []int{1, 2, 3}
+6 -2
View File
@@ -23,6 +23,7 @@ var (
var (
gDefaultShell = "sh"
gDefaultShellFlag = "-c"
gDefaultSocketProt = "unix"
gDefaultSocketPath string
)
@@ -30,6 +31,7 @@ var (
var (
gUser *user.User
gConfigPaths []string
gFilesPath string
gMarksPath string
gHistoryPath string
)
@@ -82,6 +84,7 @@ func init() {
data = filepath.Join(gUser.HomeDir, ".local", "share")
}
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history")
@@ -99,7 +102,7 @@ func shellCommand(s string, args []string) *exec.Cmd {
s = fmt.Sprintf("IFS='%s'; %s", gOpts.ifs, s)
}
args = append([]string{"-c", s, "--"}, args...)
args = append([]string{gOpts.shellflag, s, "--"}, args...)
args = append(gOpts.shellopts, args...)
@@ -177,12 +180,13 @@ func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == syscall.EXDEV
}
func exportFiles(f string, fs []string) {
func exportFiles(f string, fs []string, pwd string) {
envFile := f
envFiles := strings.Join(fs, gOpts.filesep)
os.Setenv("f", envFile)
os.Setenv("fs", envFiles)
os.Setenv("PWD", pwd)
if len(fs) == 0 {
os.Setenv("fx", envFile)
+6 -2
View File
@@ -22,6 +22,7 @@ var envPathExt = os.Getenv("PATHEXT")
var (
gDefaultShell = "cmd"
gDefaultShellFlag = "/c"
gDefaultSocketProt = "tcp"
gDefaultSocketPath = "127.0.0.1:12345"
)
@@ -29,6 +30,7 @@ var (
var (
gUser *user.User
gConfigPaths []string
gFilesPath string
gMarksPath string
gHistoryPath string
)
@@ -66,6 +68,7 @@ func init() {
filepath.Join(data, "lf", "lfrc"),
}
gFilesPath = filepath.Join(data, "lf", "files")
gMarksPath = filepath.Join(data, "lf", "marks")
gHistoryPath = filepath.Join(data, "lf", "history")
}
@@ -77,7 +80,7 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
}
func shellCommand(s string, args []string) *exec.Cmd {
args = append([]string{"/c", s}, args...)
args = append([]string{gOpts.shellflag, s}, args...)
args = append(gOpts.shellopts, args...)
@@ -133,7 +136,7 @@ func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(syscall.Errno) == 17
}
func exportFiles(f string, fs []string) {
func exportFiles(f string, fs []string, pwd string) {
envFile := fmt.Sprintf(`"%s"`, f)
var quotedFiles []string
@@ -144,6 +147,7 @@ func exportFiles(f string, fs []string) {
os.Setenv("f", envFile)
os.Setenv("fs", envFiles)
os.Setenv("PWD", pwd)
if len(fs) == 0 {
os.Setenv("fx", envFile)
+31 -31
View File
@@ -10,8 +10,6 @@ import (
)
var (
gCopyFile bool
gFileList []string
gConnList = make(map[int]net.Conn)
gQuitChan = make(chan struct{}, 1)
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) {
s := bufio.NewScanner(c)
@@ -63,42 +70,29 @@ Loop:
log.Printf("listen: %s", s.Text())
word, rest := splitWord(s.Text())
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":
if rest != "" {
word2, _ := splitWord(rest)
id, err := strconv.Atoi(word2)
if err != nil {
log.Print("listen: conn: client id should be a number")
echoerr(c, "listen: conn: client id should be a number")
} else {
gConnList[id] = c
}
} 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":
if rest != "" {
@@ -115,6 +109,12 @@ Loop:
}
}
case "quit":
if len(gConnList) == 0 {
gQuitChan <- struct{}{}
gListener.Close()
break Loop
}
case "quit!":
gQuitChan <- struct{}{}
for _, c := range gConnList {
fmt.Fprintln(c, "echo server is quitting...")
@@ -123,12 +123,12 @@ Loop:
gListener.Close()
break Loop
default:
log.Printf("listen: unexpected command: %s", word)
echoerrf(c, "listen: unexpected command: %s", word)
}
}
if s.Err() != nil {
log.Printf("listening: %s", s.Err())
echoerrf(c, "listening: %s", s.Err())
}
c.Close()
+24 -16
View File
@@ -171,7 +171,7 @@ func printLength(s string) int {
r, w := utf8.DecodeRuneInString(s[i:])
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 {
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:])
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 {
continue
}
st = applyAnsiCodes(s[i+2:i+j], st)
if s[i+j] == 'm' {
st = applyAnsiCodes(s[i+2:i+j], st)
}
i += j
continue
@@ -499,7 +500,7 @@ func getWidths(wtot int) []int {
wsum := 0
for i := 0; i < wlen-1; i++ {
widths[i] = gOpts.ratios[i] * (wtot / rsum)
widths[i] = gOpts.ratios[i] * wtot / rsum
wsum += widths[i]
}
widths[wlen-1] = wtot - wsum
@@ -835,16 +836,22 @@ func (ui *ui) draw(nav *nav) {
ui.drawStatLine(nav)
ui.screen.HideCursor()
case ">":
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, ui.msg)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+printLength(ui.msg)+runeSliceWidth(left), ui.msgWin.y)
default:
pos := min(runeSliceWidth(ui.cmdAccLeft), ui.msgWin.w-len(ui.cmdPrefix)-1)
left := ui.cmdAccLeft[runeSliceWidth(ui.cmdAccLeft)-pos:]
right := ui.cmdAccRight
ui.msgWin.printLine(ui.screen, 0, 0, st, ui.cmdPrefix)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(ui.cmdAccLeft))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, st, string(ui.cmdAccRight))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
ui.msgWin.print(ui.screen, len(ui.cmdPrefix), 0, st, string(left))
ui.msgWin.print(ui.screen, len(ui.cmdPrefix)+runeSliceWidth(left), 0, st, string(right))
ui.screen.ShowCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(left), ui.msgWin.y)
}
if gOpts.preview {
@@ -1144,22 +1151,23 @@ func (ui *ui) readExpr() {
}()
}
func (ui *ui) suspend() {
ui.screen.Suspend()
func (ui *ui) suspend() error {
return ui.screen.Suspend()
}
func (ui *ui) resume() {
ui.screen.Resume()
func (ui *ui) resume() error {
return ui.screen.Resume()
}
func anyKey() {
fmt.Print(gOpts.waitmsg)
defer fmt.Print("\n")
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer term.Restore(int(os.Stdin.Fd()), oldState)
fmt.Print("Press any key to continue")
b := make([]byte, 1)
os.Stdin.Read(b)
}