Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c14b3cd4a | ||
|
|
e1b6d38386 | ||
|
|
fef99c1d70 | ||
|
|
b8523c3258 | ||
|
|
4cbb211757 | ||
|
|
5787ecd1bd | ||
|
|
96f35e986d | ||
|
|
07c16fede0 | ||
|
|
2d821216a8 | ||
|
|
638d67c0e4 | ||
|
|
6c319316e2 | ||
|
|
5d5d00e30b | ||
|
|
d987c9e439 | ||
|
|
b67b042d43 | ||
|
|
e99478e8a1 | ||
|
|
4c54acebeb | ||
|
|
fe786aae4c | ||
|
|
a607e53e51 | ||
|
|
da126a3959 | ||
|
|
6d20887b16 | ||
|
|
078dc47e34 | ||
|
|
8070cd82b7 | ||
|
|
52974615f2 | ||
|
|
76a725eaf2 | ||
|
|
2e014b3c0a | ||
|
|
51101f7020 | ||
|
|
ba01f85340 | ||
|
|
723357fe3d | ||
|
|
e025c68130 | ||
|
|
7acc85f81c | ||
|
|
4846a74320 | ||
|
|
9177ddd406 | ||
|
|
9d21a4f359 | ||
|
|
20720c832d | ||
|
|
448f2a3cb2 |
No files matched your search
@@ -2,3 +2,4 @@ lf
|
|||||||
lf.exe
|
lf.exe
|
||||||
tags
|
tags
|
||||||
dist/
|
dist/
|
||||||
|
vendor/
|
||||||
Generated
+21
@@ -0,0 +1,21 @@
|
|||||||
|
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||||
|
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/mattn/go-runewidth"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/nsf/termbox-go"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3"
|
||||||
|
|
||||||
|
[solve-meta]
|
||||||
|
analyzer-name = "dep"
|
||||||
|
analyzer-version = 1
|
||||||
|
inputs-digest = "8508b73787d4948edb76ccc25789c311a4ab84d4c8c0b96b267857e2e88d974e"
|
||||||
|
solver-name = "gps-cdcl"
|
||||||
|
solver-version = 1
|
||||||
+38
@@ -0,0 +1,38 @@
|
|||||||
|
# Gopkg.toml example
|
||||||
|
#
|
||||||
|
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||||
|
# for detailed Gopkg.toml documentation.
|
||||||
|
#
|
||||||
|
# required = ["github.com/user/thing/cmd/thing"]
|
||||||
|
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project"
|
||||||
|
# version = "1.0.0"
|
||||||
|
#
|
||||||
|
# [[constraint]]
|
||||||
|
# name = "github.com/user/project2"
|
||||||
|
# branch = "dev"
|
||||||
|
# source = "github.com/myfork/project2"
|
||||||
|
#
|
||||||
|
# [[override]]
|
||||||
|
# name = "github.com/x/y"
|
||||||
|
# version = "2.4.0"
|
||||||
|
#
|
||||||
|
# [prune]
|
||||||
|
# non-go = false
|
||||||
|
# go-tests = true
|
||||||
|
# unused-packages = true
|
||||||
|
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
|
[[constraint]]
|
||||||
|
branch = "master"
|
||||||
|
name = "github.com/nsf/termbox-go"
|
||||||
|
|
||||||
|
[prune]
|
||||||
|
go-tests = true
|
||||||
|
unused-packages = true
|
||||||
@@ -39,6 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
|||||||
## May-Futures
|
## May-Futures
|
||||||
|
|
||||||
- Bookmarks
|
- Bookmarks
|
||||||
|
- Mouse control
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
See [tutorial](https://github.com/gokcehan/lf/wiki/Tutorial) for a gentle introduction with screencasts.
|
||||||
|
|
||||||
After the installation `lf` command should start the application in the current directory.
|
After the installation `lf` command should start the application in the current directory.
|
||||||
|
|
||||||
Run `lf -help` to see command line options.
|
Run `lf -help` to see command line options.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdItem struct {
|
type cmdItem struct {
|
||||||
@@ -19,6 +20,7 @@ type cmdItem struct {
|
|||||||
type app struct {
|
type app struct {
|
||||||
ui *ui
|
ui *ui
|
||||||
nav *nav
|
nav *nav
|
||||||
|
ticker *time.Ticker
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
cmdIn io.WriteCloser
|
cmdIn io.WriteCloser
|
||||||
@@ -34,6 +36,7 @@ func newApp() *app {
|
|||||||
return &app{
|
return &app{
|
||||||
ui: ui,
|
ui: ui,
|
||||||
nav: nav,
|
nav: nav,
|
||||||
|
ticker: new(time.Ticker),
|
||||||
quitChan: make(chan bool, 1),
|
quitChan: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,6 +135,10 @@ func (app *app) loop() {
|
|||||||
case e := <-serverChan:
|
case e := <-serverChan:
|
||||||
e.eval(app, nil)
|
e.eval(app, nil)
|
||||||
app.ui.draw(app.nav)
|
app.ui.draw(app.nav)
|
||||||
|
case <-app.ticker.C:
|
||||||
|
app.nav.renew()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.draw(app.nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,6 +163,11 @@ func (app *app) exportVars() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
os.Setenv("id", strconv.Itoa(gClientID))
|
os.Setenv("id", strconv.Itoa(gClientID))
|
||||||
|
|
||||||
|
os.Setenv("OPENER", envOpener)
|
||||||
|
os.Setenv("EDITOR", envEditor)
|
||||||
|
os.Setenv("PAGER", envPager)
|
||||||
|
os.Setenv("SHELL", envShell)
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitKey() error {
|
func waitKey() error {
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ func run() {
|
|||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
|
||||||
if _, err := os.Stat(gConfigPath); !os.IsNotExist(err) {
|
for _, path := range gConfigPaths {
|
||||||
app.readFile(gConfigPath)
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
app.readFile(path)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.loop()
|
app.loop()
|
||||||
@@ -68,7 +70,7 @@ func readExpr() <-chan expr {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveFiles(list []string, copy bool) error {
|
func saveFiles(list []string, cp bool) error {
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dialing to save files: %s", err)
|
return fmt.Errorf("dialing to save files: %s", err)
|
||||||
@@ -79,7 +81,7 @@ func saveFiles(list []string, copy bool) error {
|
|||||||
|
|
||||||
fmt.Fprintln(c, "save")
|
fmt.Fprintln(c, "save")
|
||||||
|
|
||||||
if copy {
|
if cp {
|
||||||
fmt.Fprintln(c, "copy")
|
fmt.Fprintln(c, "copy")
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(c, "move")
|
fmt.Fprintln(c, "move")
|
||||||
@@ -93,7 +95,7 @@ func saveFiles(list []string, copy bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFiles() (list []string, copy bool, err error) {
|
func loadFiles() (list []string, cp bool, err error) {
|
||||||
c, e := net.Dial(gSocketProt, gSocketPath)
|
c, e := net.Dial(gSocketProt, gSocketPath)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
err = fmt.Errorf("dialing to load files: %s", e)
|
err = fmt.Errorf("dialing to load files: %s", e)
|
||||||
@@ -109,9 +111,9 @@ func loadFiles() (list []string, copy bool, err error) {
|
|||||||
|
|
||||||
switch s.Text() {
|
switch s.Text() {
|
||||||
case "copy":
|
case "copy":
|
||||||
copy = true
|
cp = true
|
||||||
case "move":
|
case "move":
|
||||||
copy = false
|
cp = false
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
|
||||||
return
|
return
|
||||||
|
|||||||
+10
-5
@@ -28,12 +28,13 @@ var (
|
|||||||
"toggle",
|
"toggle",
|
||||||
"invert",
|
"invert",
|
||||||
"unmark",
|
"unmark",
|
||||||
"yank",
|
"copy",
|
||||||
"delete",
|
"cut",
|
||||||
"put",
|
"paste",
|
||||||
"clear",
|
"clear",
|
||||||
"draw",
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
|
"load",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
"shell",
|
"shell",
|
||||||
@@ -48,6 +49,7 @@ var (
|
|||||||
"echo",
|
"echo",
|
||||||
"cd",
|
"cd",
|
||||||
"select",
|
"select",
|
||||||
|
"source",
|
||||||
"push",
|
"push",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +84,7 @@ var (
|
|||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
"filesep",
|
"filesep",
|
||||||
@@ -93,6 +96,7 @@ var (
|
|||||||
"timefmt",
|
"timefmt",
|
||||||
"ratios",
|
"ratios",
|
||||||
"info",
|
"info",
|
||||||
|
"shellopts",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -130,7 +134,7 @@ func matchWord(s string, words []string) (matches []string, longest string) {
|
|||||||
func matchExec(s string) (matches []string, longest string) {
|
func matchExec(s string) (matches []string, longest string) {
|
||||||
var words []string
|
var words []string
|
||||||
|
|
||||||
paths := strings.Split(envPath, ":")
|
paths := strings.Split(envPath, string(filepath.ListSeparator))
|
||||||
|
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
if _, err := os.Stat(p); os.IsNotExist(err) {
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
||||||
@@ -153,10 +157,11 @@ func matchExec(s string) (matches []string, longest string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !f.Mode().IsRegular() || f.Mode()&0111 == 0 {
|
if !f.Mode().IsRegular() || !isExecutable(f) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Print(f.Name())
|
||||||
words = append(words, f.Name())
|
words = append(words, f.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,21 @@ The following commands are provided by lf with default keybindings:
|
|||||||
|
|
||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg' and '<home>')
|
||||||
bottom (default 'G')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unmark (default 'u')
|
||||||
yank (default 'y')
|
copy (default 'y')
|
||||||
delete (default 'd')
|
cut (default 'd')
|
||||||
put (default 'p')
|
paste (default 'p')
|
||||||
clear (default 'c')
|
clear (default 'c')
|
||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
@@ -45,10 +45,12 @@ The following commands are provided by lf with default keybindings:
|
|||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
sync synchronizes yanked/deleted files with server
|
load load modified files and directories
|
||||||
|
sync synchronizes copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
select changes current file selection to its argument
|
select changes current file selection to its argument
|
||||||
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
@@ -91,6 +93,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
|
period integer (default 0)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -102,6 +105,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||||
ratios string (default '1:2:3')
|
ratios string (default '1:2:3')
|
||||||
info string (default '')
|
info string (default '')
|
||||||
|
shellopts string (default '')
|
||||||
|
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
@@ -110,6 +114,23 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or marked file(s) if any
|
$fx current file or marked file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
|
|
||||||
|
The following default values are set to the environmental variables on unix
|
||||||
|
when they are not set or empty:
|
||||||
|
|
||||||
|
$OPENER open # macos
|
||||||
|
$OPENER xdg-open # others
|
||||||
|
$EDITOR vi
|
||||||
|
$PAGER less
|
||||||
|
$SHELL sh
|
||||||
|
|
||||||
|
The following default values are set to the environmental variables on windows
|
||||||
|
when they are not set or empty:
|
||||||
|
|
||||||
|
%OPENER% start
|
||||||
|
%EDITOR% notepad
|
||||||
|
%PAGER% more
|
||||||
|
%SHELL% cmd
|
||||||
|
|
||||||
The following additional keybindings are provided by default:
|
The following additional keybindings are provided by default:
|
||||||
|
|
||||||
map zh set hidden!
|
map zh set hidden!
|
||||||
@@ -123,28 +144,26 @@ The following additional keybindings are provided by default:
|
|||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
map gh cd ~
|
map gh cd ~
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on unix:
|
The following keybindings to applications are provided by default:
|
||||||
|
|
||||||
map e $$EDITOR $f ('vi' if empty)
|
map e $$EDITOR $f
|
||||||
map i $$PAGER $f ('less' if empty)
|
map i $$PAGER $f
|
||||||
map w $$SHELL ('sh' if empty)
|
map w $$SHELL
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on windows:
|
|
||||||
|
|
||||||
map e $notepad %f%
|
|
||||||
map i $more %f%
|
|
||||||
map w $cmd
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
|
|
||||||
The configuration file should be located at:
|
Configuration files should be located at:
|
||||||
|
|
||||||
$XDG_CONFIG_HOME/lf/lfrc
|
system-wide user-specific
|
||||||
|
unix /etc/lfrc ~/.config/lf/lfrc
|
||||||
|
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||||
|
|
||||||
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
|
You can configure the default values of following variables to change these
|
||||||
location should be:
|
locations:
|
||||||
|
|
||||||
~/.config/lf/lfrc
|
$XDG_CONFIG_HOME ~/.config
|
||||||
|
%ProgramData% C:\ProgramData
|
||||||
|
%LOCALAPPDATA% C:\Users\<user>\AppData\Local
|
||||||
|
|
||||||
A sample configuration file can be found at
|
A sample configuration file can be found at
|
||||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||||
@@ -192,7 +211,7 @@ 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 -h . # waiting shell command
|
map U !du -sh # waiting shell command
|
||||||
|
|
||||||
'cmap' is used to bind a key to a command line command which can only be one of
|
'cmap' is used to bind a key to a command line command which can only be one of
|
||||||
the builtin commands:
|
the builtin commands:
|
||||||
@@ -206,7 +225,7 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
|
|
||||||
'cmd' is used to define a custom command
|
'cmd' is used to define a custom command
|
||||||
|
|
||||||
cmd usage $du -h . | less
|
cmd usage $du -h -d1 | less
|
||||||
|
|
||||||
You can delete an existing command by leaving the expression empty:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -229,6 +248,53 @@ prefix.
|
|||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
Key Mappings
|
||||||
|
|
||||||
|
Regular keys are assigned to a command with the usual syntax:
|
||||||
|
|
||||||
|
map a down
|
||||||
|
|
||||||
|
Keys combined with the shift key simply use the uppercase letter:
|
||||||
|
|
||||||
|
map A down
|
||||||
|
|
||||||
|
Special keys are written in between '<' and '>' characters and always use
|
||||||
|
lowercase letters:
|
||||||
|
|
||||||
|
map <enter> down
|
||||||
|
|
||||||
|
Angle brackets can be assigned with their special names:
|
||||||
|
|
||||||
|
map <lt> down
|
||||||
|
map <gt> down
|
||||||
|
|
||||||
|
Function keys are prefixed with 'f' character:
|
||||||
|
|
||||||
|
map <f-1> down
|
||||||
|
|
||||||
|
Keys combined with the control key are prefixed with 'c' character:
|
||||||
|
|
||||||
|
map <c-a> down
|
||||||
|
|
||||||
|
Keys combined with the alt key are assigned in two different ways depending on
|
||||||
|
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
|
||||||
|
of a character when the alt key is pressed. On these terminals, you can use the
|
||||||
|
corresponding byte for the mapping:
|
||||||
|
|
||||||
|
map á down
|
||||||
|
|
||||||
|
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||||
|
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
|
||||||
|
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
|
||||||
|
with the alt key are prefixed with 'a' character:
|
||||||
|
|
||||||
|
map <a-a> down
|
||||||
|
|
||||||
|
Please note that, some key combinations are not possible due to the way
|
||||||
|
terminals work (e.g. control and h combination sends a backspace key instead).
|
||||||
|
The easiest way to find the name of a key combination is to press the key while
|
||||||
|
lf is running and read the name of the key from the unknown mapping error.
|
||||||
|
|
||||||
Push Mappings
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
@@ -378,7 +444,7 @@ Since lf does not have control flow syntax, remote commands are used for such
|
|||||||
needs. For example, you can configure the number of columns in the ui with
|
needs. For example, you can configure the number of columns in the ui with
|
||||||
respect to the terminal width as follows:
|
respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -413,19 +479,16 @@ should not be needed for users.
|
|||||||
File Operations
|
File Operations
|
||||||
|
|
||||||
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
||||||
this purpose, when you 'yank' (i.e. copy) a file, it doesn't actually copy the
|
this purpose, when you 'copy' a file, it doesn't actually copy the file on the
|
||||||
file on the disk, but only records its name to memory. The actual file
|
disk, but only records its name to memory. The actual file operation takes
|
||||||
operation takes place when you do the 'put' in which case the 'cp' command is
|
place when you 'paste' in which case the 'cp' command is used. Similarly the
|
||||||
used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
'mv' command is used for 'cut' followed by 'paste'.
|
||||||
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and 'put')
|
|
||||||
are picked instead of the other common convention (e.g. copy and cut) to
|
|
||||||
resemble the default keybinds for these operations.
|
|
||||||
|
|
||||||
You can customize these operations by defining a 'put' command. This is a
|
You can customize these operations by defining a 'paste' command. This is a
|
||||||
special command that is called when it is defined instead of the builtin
|
special command that is called when it is defined instead of the builtin
|
||||||
implementation. The default behavior is similar to the following command:
|
implementation. The default behavior is similar to the following command:
|
||||||
|
|
||||||
cmd put ${{
|
cmd paste ${{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
@@ -434,9 +497,9 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
lf -remote "$(printf 'save\nmove\n\n')"
|
||||||
lf -remote "send sync"
|
lf -remote 'send load'
|
||||||
|
lf -remote 'send sync'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
||||||
@@ -451,31 +514,29 @@ completely are provided in the example configuration file.
|
|||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can use 'open-file' command to open a file. This is a special command
|
You can define a an 'open' command (default 'l') to configure file opening.
|
||||||
called by 'open' when the current file is not a directory. Normally a user maps
|
This command is only called when the current file is not a directory, otherwise
|
||||||
the 'open' command to a key (default 'l') and customize 'open-file' command as
|
the directory is entered instead. You can define it just as you would define
|
||||||
desired. You can define it just as you would define any other command:
|
any other command:
|
||||||
|
|
||||||
cmd open-file $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
It is possible to use different command types:
|
It is possible to use different command types:
|
||||||
|
|
||||||
cmd open-file &xdg-open $f
|
cmd open &xdg-open $f
|
||||||
|
|
||||||
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-file ${{
|
cmd open ${{
|
||||||
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;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Following commands are provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open-file &start %f% # windows
|
cmd open &$OPENER $f
|
||||||
cmd open-file &open "$f" # mac
|
|
||||||
cmd open-file &xdg-open "$f" # others
|
|
||||||
|
|
||||||
You may also use any other existing file openers as you like. Possible options
|
You may also use any other existing file openers as you like. Possible options
|
||||||
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
||||||
|
|||||||
+111
-50
@@ -18,21 +18,21 @@ The following commands are provided by lf with default keybindings:
|
|||||||
|
|
||||||
up (default 'k' and '<up>')
|
up (default 'k' and '<up>')
|
||||||
half-up (default '<c-u>')
|
half-up (default '<c-u>')
|
||||||
page-up (default '<c-b>')
|
page-up (default '<c-b>' and '<pgup>')
|
||||||
down (default 'j' and '<down>')
|
down (default 'j' and '<down>')
|
||||||
half-down (default '<c-d>')
|
half-down (default '<c-d>')
|
||||||
page-down (default '<c-f>')
|
page-down (default '<c-f>' and '<pgdn>')
|
||||||
updir (default 'h' and '<left>')
|
updir (default 'h' and '<left>')
|
||||||
open (default 'l' and '<right>')
|
open (default 'l' and '<right>')
|
||||||
quit (default 'q')
|
quit (default 'q')
|
||||||
top (default 'gg')
|
top (default 'gg' and '<home>')
|
||||||
bottom (default 'G')
|
bottom (default 'G' and '<end>')
|
||||||
toggle (default '<space>')
|
toggle (default '<space>')
|
||||||
invert (default 'v')
|
invert (default 'v')
|
||||||
unmark (default 'u')
|
unmark (default 'u')
|
||||||
yank (default 'y')
|
copy (default 'y')
|
||||||
delete (default 'd')
|
cut (default 'd')
|
||||||
put (default 'p')
|
paste (default 'p')
|
||||||
clear (default 'c')
|
clear (default 'c')
|
||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
@@ -49,10 +49,12 @@ The following commands are provided by lf with default keybindings:
|
|||||||
The following commands are provided by lf without default keybindings:
|
The following commands are provided by lf without default keybindings:
|
||||||
|
|
||||||
draw draw the ui
|
draw draw the ui
|
||||||
sync synchronizes yanked/deleted files with server
|
load load modified files and directories
|
||||||
|
sync synchronizes copied/cut files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
select changes current file selection to its argument
|
select changes current file selection to its argument
|
||||||
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
@@ -95,6 +97,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
|
period integer (default 0)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -106,6 +109,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
||||||
ratios string (default '1:2:3')
|
ratios string (default '1:2:3')
|
||||||
info string (default '')
|
info string (default '')
|
||||||
|
shellopts string (default '')
|
||||||
|
|
||||||
The following variables are exported for shell commands:
|
The following variables are exported for shell commands:
|
||||||
|
|
||||||
@@ -114,6 +118,23 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or marked file(s) if any
|
$fx current file or marked file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
|
|
||||||
|
The following default values are set to the environmental variables on unix
|
||||||
|
when they are not set or empty:
|
||||||
|
|
||||||
|
$OPENER open # macos
|
||||||
|
$OPENER xdg-open # others
|
||||||
|
$EDITOR vi
|
||||||
|
$PAGER less
|
||||||
|
$SHELL sh
|
||||||
|
|
||||||
|
The following default values are set to the environmental variables on
|
||||||
|
windows when they are not set or empty:
|
||||||
|
|
||||||
|
%OPENER% start
|
||||||
|
%EDITOR% notepad
|
||||||
|
%PAGER% more
|
||||||
|
%SHELL% cmd
|
||||||
|
|
||||||
The following additional keybindings are provided by default:
|
The following additional keybindings are provided by default:
|
||||||
|
|
||||||
map zh set hidden!
|
map zh set hidden!
|
||||||
@@ -127,30 +148,27 @@ The following additional keybindings are provided by default:
|
|||||||
map st :set sortby time; set info time
|
map st :set sortby time; set info time
|
||||||
map gh cd ~
|
map gh cd ~
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on unix:
|
The following keybindings to applications are provided by default:
|
||||||
|
|
||||||
map e $$EDITOR $f ('vi' if empty)
|
map e $$EDITOR $f
|
||||||
map i $$PAGER $f ('less' if empty)
|
map i $$PAGER $f
|
||||||
map w $$SHELL ('sh' if empty)
|
map w $$SHELL
|
||||||
|
|
||||||
The following keybindings to applications are provided by default on
|
|
||||||
windows:
|
|
||||||
|
|
||||||
map e $notepad %f%
|
|
||||||
map i $more %f%
|
|
||||||
map w $cmd
|
|
||||||
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
|
|
||||||
The configuration file should be located at:
|
Configuration files should be located at:
|
||||||
|
|
||||||
$XDG_CONFIG_HOME/lf/lfrc
|
system-wide user-specific
|
||||||
|
unix /etc/lfrc ~/.config/lf/lfrc
|
||||||
|
windows C:\ProgramData\lf\lfrc C:\Users\<user>\AppData\Local\lf\lfrc
|
||||||
|
|
||||||
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
|
You can configure the default values of following variables to change these
|
||||||
location should be:
|
locations:
|
||||||
|
|
||||||
~/.config/lf/lfrc
|
$XDG_CONFIG_HOME ~/.config
|
||||||
|
%ProgramData% C:\ProgramData
|
||||||
|
%LOCALAPPDATA% C:\Users\<user>\AppData\Local
|
||||||
|
|
||||||
A sample configuration file can be found at
|
A sample configuration file can be found at
|
||||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||||
@@ -200,7 +218,7 @@ 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 -h . # waiting shell command
|
map U !du -sh # waiting shell command
|
||||||
|
|
||||||
'cmap' is used to bind a key to a command line command which can only be one
|
'cmap' is used to bind a key to a command line command which can only be one
|
||||||
of the builtin commands:
|
of the builtin commands:
|
||||||
@@ -214,7 +232,7 @@ You can delete an existing binding by leaving the expression empty:
|
|||||||
|
|
||||||
'cmd' is used to define a custom command
|
'cmd' is used to define a custom command
|
||||||
|
|
||||||
cmd usage $du -h . | less
|
cmd usage $du -h -d1 | less
|
||||||
|
|
||||||
You can delete an existing command by leaving the expression empty:
|
You can delete an existing command by leaving the expression empty:
|
||||||
|
|
||||||
@@ -238,6 +256,55 @@ proper prefix.
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
|
Key Mappings
|
||||||
|
|
||||||
|
Regular keys are assigned to a command with the usual syntax:
|
||||||
|
|
||||||
|
map a down
|
||||||
|
|
||||||
|
Keys combined with the shift key simply use the uppercase letter:
|
||||||
|
|
||||||
|
map A down
|
||||||
|
|
||||||
|
Special keys are written in between '<' and '>' characters and always use
|
||||||
|
lowercase letters:
|
||||||
|
|
||||||
|
map <enter> down
|
||||||
|
|
||||||
|
Angle brackets can be assigned with their special names:
|
||||||
|
|
||||||
|
map <lt> down
|
||||||
|
map <gt> down
|
||||||
|
|
||||||
|
Function keys are prefixed with 'f' character:
|
||||||
|
|
||||||
|
map <f-1> down
|
||||||
|
|
||||||
|
Keys combined with the control key are prefixed with 'c' character:
|
||||||
|
|
||||||
|
map <c-a> down
|
||||||
|
|
||||||
|
Keys combined with the alt key are assigned in two different ways depending
|
||||||
|
on the behavior of your terminal. Older terminals (e.g. xterm) may set the
|
||||||
|
8th bit of a character when the alt key is pressed. On these terminals, you
|
||||||
|
can use the corresponding byte for the mapping:
|
||||||
|
|
||||||
|
map á down
|
||||||
|
|
||||||
|
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
||||||
|
when the alt key is pressed. lf uses the escape delaying mechanism to
|
||||||
|
recognize alt keys in these terminals (delay is 100ms). On these terminals,
|
||||||
|
keys combined with the alt key are prefixed with 'a' character:
|
||||||
|
|
||||||
|
map <a-a> down
|
||||||
|
|
||||||
|
Please note that, some key combinations are not possible due to the way
|
||||||
|
terminals work (e.g. control and h combination sends a backspace key
|
||||||
|
instead). The easiest way to find the name of a key combination is to press
|
||||||
|
the key while lf is running and read the name of the key from the unknown
|
||||||
|
mapping error.
|
||||||
|
|
||||||
|
|
||||||
Push Mappings
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
@@ -399,7 +466,7 @@ Since lf does not have control flow syntax, remote commands are used for
|
|||||||
such needs. For example, you can configure the number of columns in the ui
|
such needs. For example, you can configure the number of columns in the ui
|
||||||
with respect to the terminal width as follows:
|
with respect to the terminal width as follows:
|
||||||
|
|
||||||
cmd recol ${{
|
cmd recol %{{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
@@ -435,19 +502,16 @@ should not be needed for users.
|
|||||||
File Operations
|
File Operations
|
||||||
|
|
||||||
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
|
||||||
this purpose, when you 'yank' (i.e. copy) a file, it doesn't actually copy
|
this purpose, when you 'copy' a file, it doesn't actually copy the file on
|
||||||
the file on the disk, but only records its name to memory. The actual file
|
the disk, but only records its name to memory. The actual file operation
|
||||||
operation takes place when you do the 'put' in which case the 'cp' command
|
takes place when you 'paste' in which case the 'cp' command is used.
|
||||||
is used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
|
Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
||||||
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and
|
|
||||||
'put') are picked instead of the other common convention (e.g. copy and cut)
|
|
||||||
to resemble the default keybinds for these operations.
|
|
||||||
|
|
||||||
You can customize these operations by defining a 'put' command. This is a
|
You can customize these operations by defining a 'paste' command. This is a
|
||||||
special command that is called when it is defined instead of the builtin
|
special command that is called when it is defined instead of the builtin
|
||||||
implementation. The default behavior is similar to the following command:
|
implementation. The default behavior is similar to the following command:
|
||||||
|
|
||||||
cmd put ${{
|
cmd paste ${{
|
||||||
load=$(lf -remote 'load')
|
load=$(lf -remote 'load')
|
||||||
mode=$(echo "$load" | sed -n '1p')
|
mode=$(echo "$load" | sed -n '1p')
|
||||||
list=$(echo "$load" | sed '1d')
|
list=$(echo "$load" | sed '1d')
|
||||||
@@ -456,9 +520,9 @@ implementation. The default behavior is similar to the following command:
|
|||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
mv -n $list .
|
mv -n $list .
|
||||||
fi
|
fi
|
||||||
lf -remote "send $id reload"
|
|
||||||
lf -remote "$(printf 'save\nmove\n\n')"
|
lf -remote "$(printf 'save\nmove\n\n')"
|
||||||
lf -remote "send sync"
|
lf -remote 'send load'
|
||||||
|
lf -remote 'send sync'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and
|
Some useful things are to use the backup option ('--backup') with 'cp' and
|
||||||
@@ -475,33 +539,30 @@ files completely are provided in the example configuration file.
|
|||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can use 'open-file' command to open a file. This is a special command
|
You can define a an 'open' command (default 'l') to configure file opening.
|
||||||
called by 'open' when the current file is not a directory. Normally a user
|
This command is only called when the current file is not a directory,
|
||||||
maps the 'open' command to a key (default 'l') and customize 'open-file'
|
otherwise the directory is entered instead. You can define it just as you
|
||||||
command as desired. You can define it just as you would define any other
|
would define any other command:
|
||||||
command:
|
|
||||||
|
|
||||||
cmd open-file $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
It is possible to use different command types:
|
It is possible to use different command types:
|
||||||
|
|
||||||
cmd open-file &xdg-open $f
|
cmd open &xdg-open $f
|
||||||
|
|
||||||
You may want to use either file extensions or mime types from 'file'
|
You may want to use either file extensions or mime types from 'file'
|
||||||
command:
|
command:
|
||||||
|
|
||||||
cmd open-file ${{
|
cmd open ${{
|
||||||
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;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Following commands are provided by default:
|
Following command is provided by default:
|
||||||
|
|
||||||
cmd open-file &start %f% # windows
|
cmd open &$OPENER $f
|
||||||
cmd open-file &open "$f" # mac
|
|
||||||
cmd open-file &xdg-open "$f" # others
|
|
||||||
|
|
||||||
You may also use any other existing file openers as you like. Possible
|
You may also use any other existing file openers as you like. Possible
|
||||||
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
options are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle'
|
||||||
|
|||||||
+35
-14
@@ -1,6 +1,15 @@
|
|||||||
# interpreter for shell commands (needs to be POSIX compatible)
|
# interpreter for shell commands (needs to be POSIX compatible)
|
||||||
set shell sh
|
set shell sh
|
||||||
|
|
||||||
|
# set '-eu' options for shell commands
|
||||||
|
# These options are used to have safer shell commands. Option '-e' is used to
|
||||||
|
# exit on error and option '-u' is used to give error for unset variables.
|
||||||
|
# Option '-f' disables pathname expansion which can be useful when $f, $fs, and
|
||||||
|
# $fx variables contain names with '*' or '?' characters. However, this option
|
||||||
|
# is used selectively within individual commands as it can be limiting at
|
||||||
|
# times.
|
||||||
|
set shellopts '-eu'
|
||||||
|
|
||||||
# set internal field separator (IFS) to "\n" for shell commands
|
# set internal field separator (IFS) to "\n" for shell commands
|
||||||
# This is useful to automatically split file names in $fs and $fx properly
|
# This is useful to automatically split file names in $fs and $fx properly
|
||||||
# since default file separator used in these variables (i.e. 'filesep' option)
|
# since default file separator used in these variables (i.e. 'filesep' option)
|
||||||
@@ -23,16 +32,16 @@ map o &mimeopen $f
|
|||||||
map O $mimeopen --ask $f
|
map O $mimeopen --ask $f
|
||||||
|
|
||||||
# show documentation (overrides 'search-back' command)
|
# show documentation (overrides 'search-back' command)
|
||||||
map ? $lf -doc | less
|
map ? $lf -doc | $PAGER
|
||||||
|
|
||||||
# define a custom 'open-file' command
|
# define a custom 'open' command
|
||||||
# 'open-file' is called by 'open' when current file is not a directory. You may
|
# This command is called when current file is not a directory. You may want to
|
||||||
# want to use either file extensions and/or mime types here. Below uses an
|
# use either file extensions and/or mime types here. Below uses an editor for
|
||||||
# editor for text files and a file opener for the rest.
|
# text files and a file opener for the rest.
|
||||||
cmd open-file ${{
|
cmd open ${{
|
||||||
case $(file --mime-type $f -b) in
|
case $(file --mime-type $f -b) in
|
||||||
text/*) vi $fx;;
|
text/*) $EDITOR $fx;;
|
||||||
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
*) for f in $fx; do $OPENER $f > /dev/null 2> /dev/null & done;;
|
||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
@@ -45,19 +54,21 @@ map r push :rename<space>
|
|||||||
|
|
||||||
# move current file or selected files to trash folder
|
# move current file or selected files to trash folder
|
||||||
# (also see 'man mv' for backup/overwrite options)
|
# (also see 'man mv' for backup/overwrite options)
|
||||||
cmd trash %mv $fx ~/.trash
|
cmd trash %set -f; mv $fx ~/.trash
|
||||||
|
|
||||||
# remove current file or selected files (prompting)
|
# delete current file or selected files (prompting)
|
||||||
cmd remove ${{
|
cmd delete ${{
|
||||||
|
set -f
|
||||||
printf "$fx\n"
|
printf "$fx\n"
|
||||||
printf "remove?[y/n]"
|
printf "delete?[y/n]"
|
||||||
read ans
|
read ans
|
||||||
[ $ans = "y" ] && rm -rf $fx
|
[ $ans = "y" ] && rm -rf $fx
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# extract the current file with the right command
|
# extract the current file with the right command
|
||||||
# (xkcd link: https://xkcd.com/1168/)
|
# (xkcd link: https://xkcd.com/1168/)
|
||||||
cmd extract %{{
|
cmd extract ${{
|
||||||
|
set -f
|
||||||
case $f in
|
case $f in
|
||||||
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
||||||
*.tar.gz|*.tgz) tar xzvf $f;;
|
*.tar.gz|*.tgz) tar xzvf $f;;
|
||||||
@@ -69,9 +80,19 @@ cmd extract %{{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
# compress current file or selected files with tar and gunzip
|
# compress current file or selected files with tar and gunzip
|
||||||
cmd compress %{{
|
cmd tar ${{
|
||||||
|
set -f
|
||||||
mkdir $1
|
mkdir $1
|
||||||
cp -r $fx $1
|
cp -r $fx $1
|
||||||
tar czf $1.tar.gz $1
|
tar czf $1.tar.gz $1
|
||||||
rm -rf $1
|
rm -rf $1
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
# compress current file or selected files with zip
|
||||||
|
cmd zip ${{
|
||||||
|
set -f
|
||||||
|
mkdir $1
|
||||||
|
cp -r $fx $1
|
||||||
|
zip -r $1.zip $1
|
||||||
|
rm -rf $1
|
||||||
|
}}
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@@ -51,15 +52,21 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
case "hidden":
|
case "hidden":
|
||||||
gOpts.sortType.option |= hiddenSort
|
gOpts.sortType.option |= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "nohidden":
|
case "nohidden":
|
||||||
gOpts.sortType.option &= ^hiddenSort
|
gOpts.sortType.option &= ^hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "hidden!":
|
case "hidden!":
|
||||||
gOpts.sortType.option ^= hiddenSort
|
gOpts.sortType.option ^= hiddenSort
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
|
app.nav.position()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
case "ignorecase":
|
case "ignorecase":
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
case "noignorecase":
|
case "noignorecase":
|
||||||
@@ -96,6 +103,23 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.wrapscan
|
gOpts.wrapscan = !gOpts.wrapscan
|
||||||
|
case "period":
|
||||||
|
n, err := strconv.Atoi(e.val)
|
||||||
|
if err != nil {
|
||||||
|
app.ui.printf("period: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n < 0 {
|
||||||
|
app.ui.print("period: value should be a non-negative number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
gOpts.period = n
|
||||||
|
if n == 0 {
|
||||||
|
app.ticker.Stop()
|
||||||
|
} else {
|
||||||
|
app.ticker.Stop()
|
||||||
|
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
|
||||||
|
}
|
||||||
case "scrolloff":
|
case "scrolloff":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -178,6 +202,8 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
gOpts.info = toks
|
gOpts.info = toks
|
||||||
|
case "shellopts":
|
||||||
|
gOpts.shellopts = strings.Split(e.val, ":")
|
||||||
default:
|
default:
|
||||||
app.ui.printf("unknown option: %s", e.opt)
|
app.ui.printf("unknown option: %s", e.opt)
|
||||||
}
|
}
|
||||||
@@ -307,7 +333,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd, ok := gOpts.cmds["open-file"]; ok {
|
if cmd, ok := gOpts.cmds["open"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
}
|
}
|
||||||
case "quit":
|
case "quit":
|
||||||
@@ -330,34 +356,36 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.invert()
|
app.nav.invert()
|
||||||
case "unmark":
|
case "unmark":
|
||||||
app.nav.unmark()
|
app.nav.unmark()
|
||||||
case "yank":
|
case "copy":
|
||||||
if err := app.nav.save(true); err != nil {
|
if err := app.nav.save(true); err != nil {
|
||||||
app.ui.printf("yank: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unmark()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("yank: %s", err)
|
app.ui.printf("copy: %s", err)
|
||||||
}
|
}
|
||||||
case "delete":
|
case "cut":
|
||||||
if err := app.nav.save(false); err != nil {
|
if err := app.nav.save(false); err != nil {
|
||||||
app.ui.printf("delete: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.unmark()
|
app.nav.unmark()
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("delete: %s", err)
|
app.ui.printf("cut: %s", err)
|
||||||
}
|
}
|
||||||
case "put":
|
case "paste":
|
||||||
if cmd, ok := gOpts.cmds["put"]; ok {
|
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
} else if err := app.nav.put(); err != nil {
|
} else if err := app.nav.paste(); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("paste: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.nav.renew()
|
if err := sendRemote("send load"); err != nil {
|
||||||
|
app.ui.printf("paste: %s", err)
|
||||||
|
}
|
||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("put: %s", err)
|
app.ui.printf("paste: %s", err)
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
@@ -372,9 +400,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.sync()
|
app.ui.sync()
|
||||||
app.ui.renew()
|
app.ui.renew()
|
||||||
app.nav.height = app.ui.wins[0].h
|
app.nav.height = app.ui.wins[0].h
|
||||||
|
case "load":
|
||||||
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
app.ui.sync()
|
|
||||||
app.ui.renew()
|
|
||||||
app.nav.reload()
|
app.nav.reload()
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
@@ -436,6 +464,12 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
case "source":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("source: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) != 1 {
|
if len(e.args) != 1 {
|
||||||
app.ui.print("push: requires an argument")
|
app.ui.print("push: requires an argument")
|
||||||
@@ -650,7 +684,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
ind := locs[len(locs)-1][1] - 1
|
ind := locs[len(locs)-1][1] - 1
|
||||||
app.ui.cmdAccRight = append(app.ui.cmdAccLeft[ind:], app.ui.cmdAccRight...)
|
old := app.ui.cmdAccRight
|
||||||
|
app.ui.cmdAccRight = append([]rune{}, app.ui.cmdAccLeft[ind:]...)
|
||||||
|
app.ui.cmdAccRight = append(app.ui.cmdAccRight, old...)
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
case "cmd-capitalize-word":
|
case "cmd-capitalize-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
|
|||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Builds a static stripped binary with version information.
|
||||||
|
#
|
||||||
|
# This script is used to build a binary for the current platform. Cgo is
|
||||||
|
# disabled to make sure the binary is statically linked. Appropriate flags are
|
||||||
|
# given to the go compiler to strip the binary. Current git tag is passed to
|
||||||
|
# the compiler by default to be used as the version in the binary.
|
||||||
|
|
||||||
|
[ -z $version ] && version=$(git describe --tags)
|
||||||
|
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -w -X main.gVersion=$version" "$@"
|
||||||
+5
-4
@@ -3,13 +3,14 @@
|
|||||||
#
|
#
|
||||||
# This script is used to build binaries for all supported platforms. Cgo is
|
# This script is used to build binaries for all supported platforms. Cgo is
|
||||||
# disabled to make sure binaries are statically linked. Appropriate flags are
|
# disabled to make sure binaries are statically linked. Appropriate flags are
|
||||||
# given to the go compiler to strip binaries. These are then compressed in an
|
# given to the go compiler to strip binaries. Current git tag is passed to the
|
||||||
# archive form (`.zip` for windows and `.tar.gz` for the rest) within a folder
|
# compiler by default to be used as the version in binaries. These are then
|
||||||
# named `dist`.
|
# compressed in an archive form (`.zip` for windows and `.tar.gz` for the rest)
|
||||||
|
# within a folder named `dist`.
|
||||||
|
|
||||||
set -o verbose
|
set -o verbose
|
||||||
|
|
||||||
version=$(git describe --tags)
|
[ -z $version ] && version=$(git describe --tags)
|
||||||
|
|
||||||
mkdir -p dist
|
mkdir -p dist
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -42,6 +43,21 @@ func startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkServer() {
|
||||||
|
if gSocketProt == "unix" {
|
||||||
|
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||||
|
startServer()
|
||||||
|
} else if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||||
|
os.Remove(gSocketPath)
|
||||||
|
startServer()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if _, err := net.Dial(gSocketProt, gSocketPath); err != nil {
|
||||||
|
startServer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
showDoc := flag.Bool(
|
showDoc := flag.Bool(
|
||||||
"doc",
|
"doc",
|
||||||
@@ -125,10 +141,7 @@ 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:
|
||||||
// TODO: check if the socket is working
|
checkServer()
|
||||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
|
||||||
startServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
gClientID = 1000
|
gClientID = 1000
|
||||||
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))
|
||||||
|
|||||||
@@ -214,7 +214,21 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
return d
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.sortType != gOpts.sortType {
|
s, err := os.Stat(d.path)
|
||||||
|
if err != nil {
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case s.ModTime().After(d.loadTime):
|
||||||
|
go func() {
|
||||||
|
d.loadTime = time.Now()
|
||||||
|
nd := newDir(path)
|
||||||
|
nd.sort()
|
||||||
|
nd.find(d.name(), nav.height)
|
||||||
|
nav.dirChan <- nd
|
||||||
|
}()
|
||||||
|
case d.sortType != gOpts.sortType:
|
||||||
go func() {
|
go func() {
|
||||||
d.loading = true
|
d.loading = true
|
||||||
name := d.name()
|
name := d.name()
|
||||||
@@ -267,11 +281,6 @@ func newNav(height int) *nav {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) renew() {
|
func (nav *nav) renew() {
|
||||||
nav.dirCache = make(map[string]*dir)
|
|
||||||
for _, d := range nav.dirs {
|
|
||||||
nav.dirCache[d.path] = d
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
go func(d *dir) {
|
go func(d *dir) {
|
||||||
s, err := os.Stat(d.path)
|
s, err := os.Stat(d.path)
|
||||||
@@ -356,7 +365,7 @@ func (nav *nav) preview() {
|
|||||||
reader = f
|
reader = f
|
||||||
}
|
}
|
||||||
|
|
||||||
reg := ®{path: curr.path}
|
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||||
|
|
||||||
buf := bufio.NewScanner(reader)
|
buf := bufio.NewScanner(reader)
|
||||||
|
|
||||||
@@ -382,10 +391,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
|||||||
r, ok := nav.regCache[path]
|
r, ok := nav.regCache[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
go nav.preview()
|
go nav.preview()
|
||||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
r := ®{loading: true, path: path}
|
||||||
nav.regCache[path] = r
|
nav.regCache[path] = r
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s, err := os.Stat(r.path)
|
||||||
|
if err != nil {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.ModTime().After(r.loadTime) {
|
||||||
|
r.loadTime = time.Now()
|
||||||
|
go nav.preview()
|
||||||
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,69 +540,69 @@ func (nav *nav) unmark() {
|
|||||||
nav.markInd = 0
|
nav.markInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) save(copy bool) error {
|
func (nav *nav) save(cp bool) error {
|
||||||
if len(nav.marks) == 0 {
|
if len(nav.marks) == 0 {
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("no file selected")
|
return errors.New("no file selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles([]string{curr.path}, copy); err != nil {
|
if err := saveFiles([]string{curr.path}, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
nav.saves[curr.path] = copy
|
nav.saves[curr.path] = cp
|
||||||
} else {
|
} else {
|
||||||
marks := nav.currMarks()
|
marks := nav.currMarks()
|
||||||
|
|
||||||
if err := saveFiles(marks, copy); err != nil {
|
if err := saveFiles(marks, cp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
for f := range nav.marks {
|
for f := range nav.marks {
|
||||||
nav.saves[f] = copy
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) put() error {
|
func (nav *nav) paste() error {
|
||||||
list, copy, err := loadFiles()
|
list, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return errors.New("no file in yank/delete buffer")
|
return errors.New("no file in copy/cut buffer")
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := nav.currDir()
|
dir := nav.currDir()
|
||||||
|
|
||||||
cmd := putCommand(list, dir, copy)
|
cmd := pasteCommand(list, dir, cp)
|
||||||
|
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
return fmt.Errorf("putting files: %s", err)
|
return fmt.Errorf("pasting files: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
return fmt.Errorf("clearing yank/delete buffer: %s", err)
|
return fmt.Errorf("clearing copy/cut buffer: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) sync() error {
|
func (nav *nav) sync() error {
|
||||||
list, copy, err := loadFiles()
|
list, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
nav.saves = make(map[string]bool)
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
nav.saves[f] = copy
|
nav.saves[f] = cp
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ var gOpts struct {
|
|||||||
preview bool
|
preview bool
|
||||||
smartcase bool
|
smartcase bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
filesep string
|
filesep string
|
||||||
@@ -42,6 +43,7 @@ var gOpts struct {
|
|||||||
timefmt string
|
timefmt string
|
||||||
ratios []int
|
ratios []int
|
||||||
info []string
|
info []string
|
||||||
|
shellopts []string
|
||||||
keys map[string]expr
|
keys map[string]expr
|
||||||
cmdkeys map[string]expr
|
cmdkeys map[string]expr
|
||||||
cmds map[string]expr
|
cmds map[string]expr
|
||||||
@@ -56,6 +58,7 @@ func init() {
|
|||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
gOpts.filesep = "\n"
|
gOpts.filesep = "\n"
|
||||||
@@ -64,6 +67,7 @@ func init() {
|
|||||||
gOpts.timefmt = time.ANSIC
|
gOpts.timefmt = time.ANSIC
|
||||||
gOpts.ratios = []int{1, 2, 3}
|
gOpts.ratios = []int{1, 2, 3}
|
||||||
gOpts.info = nil
|
gOpts.info = nil
|
||||||
|
gOpts.shellopts = nil
|
||||||
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
gOpts.sortType = sortType{naturalSort, dirfirstSort}
|
||||||
|
|
||||||
gOpts.keys = make(map[string]expr)
|
gOpts.keys = make(map[string]expr)
|
||||||
@@ -72,24 +76,28 @@ func init() {
|
|||||||
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
gOpts.keys["<up>"] = &callExpr{"up", nil, 1}
|
||||||
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
gOpts.keys["<c-u>"] = &callExpr{"half-up", nil, 1}
|
||||||
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
gOpts.keys["<c-b>"] = &callExpr{"page-up", nil, 1}
|
||||||
|
gOpts.keys["<pgup>"] = &callExpr{"page-up", nil, 1}
|
||||||
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
gOpts.keys["j"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
gOpts.keys["<down>"] = &callExpr{"down", nil, 1}
|
||||||
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
gOpts.keys["<c-d>"] = &callExpr{"half-down", nil, 1}
|
||||||
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
gOpts.keys["<c-f>"] = &callExpr{"page-down", nil, 1}
|
||||||
|
gOpts.keys["<pgdn>"] = &callExpr{"page-down", nil, 1}
|
||||||
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
gOpts.keys["h"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
gOpts.keys["<left>"] = &callExpr{"updir", nil, 1}
|
||||||
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
gOpts.keys["l"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
gOpts.keys["<right>"] = &callExpr{"open", nil, 1}
|
||||||
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
gOpts.keys["q"] = &callExpr{"quit", nil, 1}
|
||||||
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
gOpts.keys["gg"] = &callExpr{"top", nil, 1}
|
||||||
|
gOpts.keys["<home>"] = &callExpr{"top", nil, 1}
|
||||||
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
gOpts.keys["G"] = &callExpr{"bottom", nil, 1}
|
||||||
|
gOpts.keys["<end>"] = &callExpr{"bottom", nil, 1}
|
||||||
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
|
||||||
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
|
||||||
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
|
||||||
gOpts.keys["y"] = &callExpr{"yank", nil, 1}
|
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
|
||||||
gOpts.keys["d"] = &callExpr{"delete", nil, 1}
|
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
|
||||||
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
|
||||||
gOpts.keys["p"] = &callExpr{"put", nil, 1}
|
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
|
||||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
|
||||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
|
||||||
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
gOpts.keys[":"] = &callExpr{"read", nil, 1}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
envOpener = os.Getenv("OPENER")
|
||||||
envEditor = os.Getenv("EDITOR")
|
envEditor = os.Getenv("EDITOR")
|
||||||
envPager = os.Getenv("PAGER")
|
envPager = os.Getenv("PAGER")
|
||||||
envShell = os.Getenv("SHELL")
|
envShell = os.Getenv("SHELL")
|
||||||
@@ -25,11 +26,31 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gUser *user.User
|
gUser *user.User
|
||||||
gConfigPath string
|
gConfigPaths []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if envOpener == "" {
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
envOpener = "open"
|
||||||
|
} else {
|
||||||
|
envOpener = "xdg-open"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if envEditor == "" {
|
||||||
|
envEditor = "vi"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envPager == "" {
|
||||||
|
envPager = "less"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envShell == "" {
|
||||||
|
envShell = "sh"
|
||||||
|
}
|
||||||
|
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
log.Printf("user: %s", err)
|
||||||
@@ -41,7 +62,10 @@ func init() {
|
|||||||
config = filepath.Join(gUser.HomeDir, ".config")
|
config = filepath.Join(gUser.HomeDir, ".config")
|
||||||
}
|
}
|
||||||
|
|
||||||
gConfigPath = filepath.Join(config, "lf", "lfrc")
|
gConfigPaths = []string{
|
||||||
|
filepath.Join("/etc", "lfrc"),
|
||||||
|
filepath.Join(config, "lf", "lfrc"),
|
||||||
|
}
|
||||||
|
|
||||||
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||||
}
|
}
|
||||||
@@ -65,14 +89,16 @@ func shellCommand(s string, args []string) *exec.Cmd {
|
|||||||
|
|
||||||
args = append([]string{"-c", s, "--"}, args...)
|
args = append([]string{"-c", s, "--"}, args...)
|
||||||
|
|
||||||
|
args = append(gOpts.shellopts, args...)
|
||||||
|
|
||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
||||||
var sh string
|
var sh string
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
if copy {
|
if cp {
|
||||||
sh = "cp"
|
sh = "cp"
|
||||||
args = append(args, "-R")
|
args = append(args, "-R")
|
||||||
} else {
|
} else {
|
||||||
@@ -94,31 +120,16 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
if envEditor == "" {
|
gOpts.cmds["open"] = &execExpr{"&", `$OPENER "$f"`}
|
||||||
gOpts.keys["e"] = &execExpr{"$", `vi "$f"`}
|
gOpts.keys["e"] = &execExpr{"$", `$EDITOR "$f"`}
|
||||||
} else {
|
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
|
||||||
gOpts.keys["e"] = &execExpr{"$", envEditor + ` "$f"`}
|
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}
|
||||||
}
|
|
||||||
|
|
||||||
if envPager == "" {
|
|
||||||
gOpts.keys["i"] = &execExpr{"$", `less "$f"`}
|
|
||||||
} else {
|
|
||||||
gOpts.keys["i"] = &execExpr{"$", envPager + ` "$f"`}
|
|
||||||
}
|
|
||||||
|
|
||||||
if envShell == "" {
|
|
||||||
gOpts.keys["w"] = &execExpr{"$", "sh"}
|
|
||||||
} else {
|
|
||||||
gOpts.keys["w"] = &execExpr{"$", envShell}
|
|
||||||
}
|
|
||||||
|
|
||||||
if runtime.GOOS == "darwin" {
|
|
||||||
gOpts.cmds["open-file"] = &execExpr{"&", `open "$f"`}
|
|
||||||
} else {
|
|
||||||
gOpts.cmds["open-file"] = &execExpr{"&", `xdg-open "$f"`}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
func moveCursor(y, x int) {
|
||||||
fmt.Printf("\033[%d;%dH", y, x)
|
fmt.Printf("\033[%d;%dH", y, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExecutable(f os.FileInfo) bool {
|
||||||
|
return f.Mode()&0111 != 0
|
||||||
|
}
|
||||||
+53
-9
@@ -9,6 +9,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
envOpener = os.Getenv("OPENER")
|
||||||
|
envEditor = os.Getenv("EDITOR")
|
||||||
|
envPager = os.Getenv("PAGER")
|
||||||
|
envShell = os.Getenv("SHELL")
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
envPathExt = os.Getenv("PATHEXT")
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gDefaultShell = "cmd"
|
gDefaultShell = "cmd"
|
||||||
gDefaultSocketProt = "tcp"
|
gDefaultSocketProt = "tcp"
|
||||||
@@ -16,11 +27,27 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gUser *user.User
|
gUser *user.User
|
||||||
gConfigPath string
|
gConfigPaths []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if envOpener == "" {
|
||||||
|
envOpener = "start"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envEditor == "" {
|
||||||
|
envEditor = "notepad"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envPager == "" {
|
||||||
|
envPager = "more"
|
||||||
|
}
|
||||||
|
|
||||||
|
if envShell == "" {
|
||||||
|
envShell = "cmd"
|
||||||
|
}
|
||||||
|
|
||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
log.Printf("user: %s", err)
|
||||||
@@ -30,7 +57,10 @@ func init() {
|
|||||||
// remove domain prefix
|
// remove domain prefix
|
||||||
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
gUser.Username = strings.Split(gUser.Username, `\`)[1]
|
||||||
|
|
||||||
gConfigPath = filepath.Join(gUser.HomeDir, "AppData", "Local", "lf", "lfrc")
|
gConfigPaths = []string{
|
||||||
|
filepath.Join(os.Getenv("ProgramData"), "lf", "lfrc"),
|
||||||
|
filepath.Join(os.Getenv("LOCALAPPDATA"), "lf", "lfrc"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func pauseCommand() *exec.Cmd {
|
func pauseCommand() *exec.Cmd {
|
||||||
@@ -39,14 +69,17 @@ func pauseCommand() *exec.Cmd {
|
|||||||
|
|
||||||
func shellCommand(s string, args []string) *exec.Cmd {
|
func shellCommand(s string, args []string) *exec.Cmd {
|
||||||
args = append([]string{"/c", s}, args...)
|
args = append([]string{"/c", s}, args...)
|
||||||
|
|
||||||
|
args = append(gOpts.shellopts, args...)
|
||||||
|
|
||||||
return exec.Command(gOpts.shell, args...)
|
return exec.Command(gOpts.shell, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
|
||||||
var args []string
|
var args []string
|
||||||
|
|
||||||
sh := "robocopy"
|
sh := "robocopy"
|
||||||
if !copy {
|
if !cp {
|
||||||
args = []string{"/move"}
|
args = []string{"/move"}
|
||||||
}
|
}
|
||||||
for _, f := range list {
|
for _, f := range list {
|
||||||
@@ -70,13 +103,24 @@ func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setDefaults() {
|
func setDefaults() {
|
||||||
gOpts.keys["e"] = &execExpr{"$", `notepad %f%`}
|
gOpts.cmds["open"] = &execExpr{"&", "%OPENER% %f%"}
|
||||||
gOpts.keys["i"] = &execExpr{"$", `more %f%`}
|
gOpts.keys["e"] = &execExpr{"$", "%EDITOR% %f%"}
|
||||||
gOpts.keys["w"] = &execExpr{"$", "cmd"}
|
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
|
||||||
gOpts.cmds["open-file"] = &execExpr{"&", `start %f%`}
|
gOpts.keys["w"] = &execExpr{"$", "%SHELL%"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func moveCursor(y, x int) {
|
func moveCursor(y, x int) {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isExecutable(f os.FileInfo) bool {
|
||||||
|
exts := strings.Split(envPathExt, string(filepath.ListSeparator))
|
||||||
|
for _, e := range exts {
|
||||||
|
if strings.HasSuffix(strings.ToLower(f.Name()), strings.ToLower(e)) {
|
||||||
|
log.Print(f.Name(), e)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
@@ -181,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
|||||||
|
|
||||||
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
fg, bg := termbox.ColorDefault, termbox.ColorDefault
|
||||||
|
|
||||||
|
if reg.loading {
|
||||||
|
fg = termbox.AttrBold
|
||||||
|
win.print(2, 0, fg, bg, "loading...")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for i, l := range reg.lines {
|
for i, l := range reg.lines {
|
||||||
fg, bg = win.print(2, i, fg, bg, l)
|
fg, bg = win.print(2, i, fg, bg, l)
|
||||||
}
|
}
|
||||||
@@ -268,8 +274,8 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
|
|||||||
|
|
||||||
if _, ok := marks[path]; ok {
|
if _, ok := marks[path]; ok {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
||||||
} else if copy, ok := saves[path]; ok {
|
} else if cp, ok := saves[path]; ok {
|
||||||
if copy {
|
if cp {
|
||||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
win.print(0, i, fg, termbox.ColorYellow, " ")
|
||||||
} else {
|
} else {
|
||||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
win.print(0, i, fg, termbox.ColorRed, " ")
|
||||||
@@ -462,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type reg struct {
|
type reg struct {
|
||||||
path string
|
loading bool
|
||||||
lines []string
|
loadTime time.Time
|
||||||
|
path string
|
||||||
|
lines []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) loadFile(nav *nav) {
|
func (ui *ui) loadFile(nav *nav) {
|
||||||
@@ -796,7 +804,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if ok {
|
if ok {
|
||||||
// TODO: use a delay
|
|
||||||
if len(ui.keyCount) > 0 {
|
if len(ui.keyCount) > 0 {
|
||||||
c, err := strconv.Atoi(string(ui.keyCount))
|
c, err := strconv.Atoi(string(ui.keyCount))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -821,8 +828,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
|||||||
}
|
}
|
||||||
case termbox.EventResize:
|
case termbox.EventResize:
|
||||||
ch <- &callExpr{"redraw", nil, 1}
|
ch <- &callExpr{"redraw", nil, 1}
|
||||||
default:
|
|
||||||
// TODO: handle other events
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user