Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da126a3959 | ||
|
|
6d20887b16 | ||
|
|
078dc47e34 | ||
|
|
8070cd82b7 | ||
|
|
52974615f2 | ||
|
|
76a725eaf2 | ||
|
|
2e014b3c0a | ||
|
|
51101f7020 | ||
|
|
ba01f85340 | ||
|
|
723357fe3d | ||
|
|
e025c68130 | ||
|
|
7acc85f81c | ||
|
|
4846a74320 | ||
|
|
9177ddd406 | ||
|
|
9d21a4f359 | ||
|
|
20720c832d | ||
|
|
448f2a3cb2 |
No files matched your search
@@ -39,6 +39,7 @@ See [faq](https://github.com/gokcehan/lf/wiki/FAQ) for more information.
|
||||
## May-Futures
|
||||
|
||||
- Bookmarks
|
||||
- Mouse control
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -52,6 +53,8 @@ See [packages](https://github.com/gokcehan/lf/wiki/Packages) for community maint
|
||||
|
||||
## 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.
|
||||
|
||||
Run `lf -help` to see command line options.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type cmdItem struct {
|
||||
@@ -19,6 +20,7 @@ type cmdItem struct {
|
||||
type app struct {
|
||||
ui *ui
|
||||
nav *nav
|
||||
ticker *time.Ticker
|
||||
quitChan chan bool
|
||||
cmd *exec.Cmd
|
||||
cmdIn io.WriteCloser
|
||||
@@ -34,6 +36,7 @@ func newApp() *app {
|
||||
return &app{
|
||||
ui: ui,
|
||||
nav: nav,
|
||||
ticker: new(time.Ticker),
|
||||
quitChan: make(chan bool, 1),
|
||||
}
|
||||
}
|
||||
@@ -132,6 +135,10 @@ func (app *app) loop() {
|
||||
case e := <-serverChan:
|
||||
e.eval(app, nil)
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.ticker.C:
|
||||
app.nav.renew()
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.draw(app.nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ var (
|
||||
"clear",
|
||||
"draw",
|
||||
"redraw",
|
||||
"load",
|
||||
"reload",
|
||||
"read",
|
||||
"shell",
|
||||
@@ -82,6 +83,7 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"filesep",
|
||||
|
||||
@@ -45,6 +45,7 @@ The following commands are provided by lf with default keybindings:
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes yanked/deleted files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
@@ -91,6 +92,7 @@ The following options can be used to customize the behavior of lf:
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
period integer (default 0)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -192,7 +194,7 @@ command, or shell command:
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom 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
|
||||
the builtin commands:
|
||||
@@ -206,7 +208,7 @@ You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
'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:
|
||||
|
||||
@@ -229,6 +231,53 @@ prefix.
|
||||
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
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -378,7 +427,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
|
||||
respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -434,9 +483,9 @@ implementation. The default behavior is similar to the following command:
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
fi
|
||||
lf -remote "send $id reload"
|
||||
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'
|
||||
|
||||
+56
-5
@@ -49,6 +49,7 @@ The following commands are provided by lf with default keybindings:
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
draw draw the ui
|
||||
load load modified files and directories
|
||||
sync synchronizes yanked/deleted files with server
|
||||
echo prints its arguments to the message line
|
||||
cd changes working directory to its argument
|
||||
@@ -95,6 +96,7 @@ The following options can be used to customize the behavior of lf:
|
||||
reverse boolean (default off)
|
||||
smartcase boolean (default on)
|
||||
wrapscan boolean (default on)
|
||||
period integer (default 0)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -200,7 +202,7 @@ custom command, or shell command:
|
||||
map gh cd ~ # builtin command
|
||||
map D trash # custom 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 the builtin commands:
|
||||
@@ -214,7 +216,7 @@ You can delete an existing binding by leaving the expression empty:
|
||||
|
||||
'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:
|
||||
|
||||
@@ -238,6 +240,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
|
||||
|
||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||
@@ -399,7 +450,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 respect to the terminal width as follows:
|
||||
|
||||
cmd recol ${{
|
||||
cmd recol %{{
|
||||
w=$(tput cols)
|
||||
if [ $w -le 80 ]; then
|
||||
lf -remote "send $id set ratios 1:2"
|
||||
@@ -456,9 +507,9 @@ implementation. The default behavior is similar to the following command:
|
||||
elif [ $mode = 'move' ]; then
|
||||
mv -n $list .
|
||||
fi
|
||||
lf -remote "send $id reload"
|
||||
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
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
@@ -51,15 +52,21 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "hidden":
|
||||
gOpts.sortType.option |= hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "nohidden":
|
||||
gOpts.sortType.option &= ^hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "hidden!":
|
||||
gOpts.sortType.option ^= hiddenSort
|
||||
app.nav.sort()
|
||||
app.nav.position()
|
||||
app.ui.sort()
|
||||
app.ui.loadFile(app.nav)
|
||||
case "ignorecase":
|
||||
gOpts.ignorecase = true
|
||||
case "noignorecase":
|
||||
@@ -96,6 +103,23 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "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":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
@@ -355,7 +379,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.printf("put: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.renew()
|
||||
if err := sendRemote("send load"); err != nil {
|
||||
app.ui.printf("put: %s", err)
|
||||
}
|
||||
if err := sendRemote("send sync"); err != nil {
|
||||
app.ui.printf("put: %s", err)
|
||||
}
|
||||
@@ -372,9 +398,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.height = app.ui.wins[0].h
|
||||
case "load":
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.reload()
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
@@ -650,7 +676,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
return
|
||||
}
|
||||
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]
|
||||
case "cmd-capitalize-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"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() {
|
||||
showDoc := flag.Bool(
|
||||
"doc",
|
||||
@@ -125,10 +141,7 @@ func main() {
|
||||
gServerLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.server.log", gUser.Username))
|
||||
serve()
|
||||
default:
|
||||
// TODO: check if the socket is working
|
||||
if _, err := os.Stat(gSocketPath); os.IsNotExist(err) {
|
||||
startServer()
|
||||
}
|
||||
checkServer()
|
||||
|
||||
gClientID = 1000
|
||||
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
|
||||
}
|
||||
|
||||
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() {
|
||||
d.loading = true
|
||||
name := d.name()
|
||||
@@ -267,11 +281,6 @@ func newNav(height int) *nav {
|
||||
}
|
||||
|
||||
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 {
|
||||
go func(d *dir) {
|
||||
s, err := os.Stat(d.path)
|
||||
@@ -356,7 +365,7 @@ func (nav *nav) preview() {
|
||||
reader = f
|
||||
}
|
||||
|
||||
reg := ®{path: curr.path}
|
||||
reg := ®{loadTime: time.Now(), path: curr.path}
|
||||
|
||||
buf := bufio.NewScanner(reader)
|
||||
|
||||
@@ -382,10 +391,21 @@ func (nav *nav) loadReg(ui *ui, path string) *reg {
|
||||
r, ok := nav.regCache[path]
|
||||
if !ok {
|
||||
go nav.preview()
|
||||
r := ®{path: path, lines: []string{"\033[1mloading...\033[0m"}}
|
||||
r := ®{loading: true, path: path}
|
||||
nav.regCache[path] = r
|
||||
return r
|
||||
}
|
||||
|
||||
s, err := os.Stat(r.path)
|
||||
if err != nil {
|
||||
return r
|
||||
}
|
||||
|
||||
if s.ModTime().After(r.loadTime) {
|
||||
r.loadTime = time.Now()
|
||||
go nav.preview()
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ var gOpts struct {
|
||||
preview bool
|
||||
smartcase bool
|
||||
wrapscan bool
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
filesep string
|
||||
@@ -56,6 +57,7 @@ func init() {
|
||||
gOpts.preview = true
|
||||
gOpts.smartcase = true
|
||||
gOpts.wrapscan = true
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.filesep = "\n"
|
||||
|
||||
@@ -181,6 +181,12 @@ func (win *win) printReg(reg *reg) {
|
||||
|
||||
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 {
|
||||
fg, bg = win.print(2, i, fg, bg, l)
|
||||
}
|
||||
@@ -462,8 +468,10 @@ func (ui *ui) printf(format string, a ...interface{}) {
|
||||
}
|
||||
|
||||
type reg struct {
|
||||
path string
|
||||
lines []string
|
||||
loading bool
|
||||
loadTime time.Time
|
||||
path string
|
||||
lines []string
|
||||
}
|
||||
|
||||
func (ui *ui) loadFile(nav *nav) {
|
||||
@@ -796,7 +804,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
}
|
||||
default:
|
||||
if ok {
|
||||
// TODO: use a delay
|
||||
if len(ui.keyCount) > 0 {
|
||||
c, err := strconv.Atoi(string(ui.keyCount))
|
||||
if err != nil {
|
||||
@@ -821,8 +828,6 @@ func (ui *ui) readEvent(ch chan<- expr, ev termbox.Event) {
|
||||
}
|
||||
case termbox.EventResize:
|
||||
ch <- &callExpr{"redraw", nil, 1}
|
||||
default:
|
||||
// TODO: handle other events
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user