Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
629a7f3297 | ||
|
|
5e67147204 | ||
|
|
266a583adb | ||
|
|
b22384d634 | ||
|
|
4ba3c3cda9 | ||
|
|
4420e41c76 | ||
|
|
a59a5aa712 | ||
|
|
170e39b95e | ||
|
|
011cca76d1 | ||
|
|
0b8de7c77e | ||
|
|
d3f9a3588f | ||
|
|
a0935fabcb | ||
|
|
e82cbb820f | ||
|
|
9234bcd5b8 | ||
|
|
7dbb61f295 | ||
|
|
40002a7752 |
No files matched your search
@@ -168,7 +168,8 @@ func (app *app) loop() {
|
||||
case d := <-app.nav.dirChan:
|
||||
prev, ok := app.nav.dirCache[d.path]
|
||||
if ok {
|
||||
d.find(prev.name(), app.nav.height)
|
||||
d.ind = prev.ind
|
||||
d.sel(prev.name(), app.nav.height)
|
||||
}
|
||||
|
||||
app.nav.dirCache[d.path] = d
|
||||
@@ -242,6 +243,15 @@ func (app *app) exportVars() {
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
func waitKey() error {
|
||||
@@ -342,7 +352,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
||||
}
|
||||
app.cmd = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
app.ui.exprChan <- &callExpr{"reload", nil, 1}
|
||||
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
@@ -53,10 +54,14 @@ func readExpr() <-chan expr {
|
||||
ch := make(chan expr)
|
||||
|
||||
go func() {
|
||||
duration := 1 * time.Second
|
||||
|
||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||
if err != nil {
|
||||
for err != nil {
|
||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
||||
return
|
||||
time.Sleep(duration)
|
||||
duration *= 2
|
||||
c, err = net.Dial(gSocketProt, gSocketPath)
|
||||
}
|
||||
|
||||
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||
|
||||
+10
-1
@@ -41,6 +41,10 @@ var (
|
||||
"shell-pipe",
|
||||
"shell-wait",
|
||||
"shell-async",
|
||||
"find",
|
||||
"find-back",
|
||||
"find-next",
|
||||
"find-prev",
|
||||
"search",
|
||||
"search-back",
|
||||
"search-next",
|
||||
@@ -56,6 +60,9 @@ var (
|
||||
}
|
||||
|
||||
gOptWords = []string{
|
||||
"anchorfind",
|
||||
"noanchorfind",
|
||||
"anchorfind!",
|
||||
"dircounts",
|
||||
"nodircounts",
|
||||
"dircounts!",
|
||||
@@ -86,6 +93,7 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"findlen",
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
@@ -190,8 +198,9 @@ func matchFile(s string) (matches []string, longest string) {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
} else {
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
dir = wd + string(filepath.Separator) + dir
|
||||
}
|
||||
|
||||
dir = unescape(filepath.Dir(dir))
|
||||
|
||||
@@ -41,6 +41,10 @@ The following commands are provided by lf with default keybindings:
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
@@ -89,6 +93,7 @@ keybindings:
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
anchorfind boolean (default on)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
@@ -99,7 +104,8 @@ 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)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -120,6 +126,10 @@ The following variables are exported for shell commands:
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
The following variables are set to the corresponding values:
|
||||
|
||||
$LF_LEVEL current nesting level
|
||||
|
||||
The following default values are set to the environmental variables on unix
|
||||
when they are not set or empty:
|
||||
|
||||
@@ -491,6 +501,10 @@ Getting the file selection is similarly done with 'load' command:
|
||||
# do something else with $list
|
||||
fi
|
||||
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
|
||||
lf -remote 'quit'
|
||||
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||
should not be needed for users.
|
||||
|
||||
|
||||
+15
-1
@@ -44,6 +44,10 @@ The following commands are provided by lf with default keybindings:
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
@@ -92,6 +96,7 @@ keybindings:
|
||||
|
||||
The following options can be used to customize the behavior of lf:
|
||||
|
||||
anchorfind boolean (default on)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
@@ -102,7 +107,8 @@ 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)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\n")
|
||||
@@ -123,6 +129,10 @@ The following variables are exported for shell commands:
|
||||
$fx current file or selected file(s) if any
|
||||
$id id number of the client
|
||||
|
||||
The following variables are set to the corresponding values:
|
||||
|
||||
$LF_LEVEL current nesting level
|
||||
|
||||
The following default values are set to the environmental variables on unix
|
||||
when they are not set or empty:
|
||||
|
||||
@@ -512,6 +522,10 @@ Getting the file selection is similarly done with 'load' command:
|
||||
# do something else with $list
|
||||
fi
|
||||
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
|
||||
lf -remote 'quit'
|
||||
|
||||
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||
should not be needed for users.
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ import (
|
||||
|
||||
func (e *setExpr) eval(app *app, args []string) {
|
||||
switch e.opt {
|
||||
case "anchorfind":
|
||||
gOpts.anchorfind = true
|
||||
case "noanchorfind":
|
||||
gOpts.anchorfind = false
|
||||
case "anchorfind!":
|
||||
gOpts.anchorfind = !gOpts.anchorfind
|
||||
case "dircounts":
|
||||
gOpts.dircounts = true
|
||||
case "nodircounts":
|
||||
@@ -104,6 +110,17 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "wrapscan!":
|
||||
gOpts.wrapscan = !gOpts.wrapscan
|
||||
case "findlen":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
app.ui.printf("findlen: %s", err)
|
||||
return
|
||||
}
|
||||
if n < 0 {
|
||||
app.ui.print("findlen: value should be a non-negative number")
|
||||
return
|
||||
}
|
||||
gOpts.findlen = n
|
||||
case "period":
|
||||
n, err := strconv.Atoi(e.val)
|
||||
if err != nil {
|
||||
@@ -253,6 +270,115 @@ func splitKeys(s string) (keys []string) {
|
||||
return
|
||||
}
|
||||
|
||||
func insert(app *app, arg string) {
|
||||
switch app.ui.cmdPrefix {
|
||||
case "find: ":
|
||||
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||
|
||||
if gOpts.findlen == 0 {
|
||||
switch app.nav.findSingle() {
|
||||
case 0:
|
||||
app.ui.printf("find: pattern not found: %s", app.nav.find)
|
||||
case 1:
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
default:
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if len(app.nav.find) < gOpts.findlen {
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
return
|
||||
}
|
||||
|
||||
if !app.nav.findNext() {
|
||||
app.ui.printf("find: pattern not found: %s", app.nav.find)
|
||||
} else {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
case "find-back: ":
|
||||
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||
|
||||
if gOpts.findlen == 0 {
|
||||
switch app.nav.findSingle() {
|
||||
case 0:
|
||||
app.ui.printf("find-back: pattern not found: %s", app.nav.find)
|
||||
case 1:
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
default:
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if len(app.nav.find) < gOpts.findlen {
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
return
|
||||
}
|
||||
|
||||
if !app.nav.findPrev() {
|
||||
app.ui.printf("find-back: pattern not found: %s", app.nav.find)
|
||||
} else {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
case "mark-save: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.marks[arg] = wd
|
||||
case "mark-load: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
path, ok := app.nav.marks[arg]
|
||||
if !ok {
|
||||
app.ui.print("mark-load: no such mark")
|
||||
return
|
||||
}
|
||||
if err := app.nav.cd(path); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
default:
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *callExpr) eval(app *app, args []string) {
|
||||
switch e.name {
|
||||
case "up":
|
||||
@@ -404,7 +530,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
case "load":
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
app.nav.reload()
|
||||
if err := app.nav.reload(); err != nil {
|
||||
app.ui.printf("reload: %s", err)
|
||||
}
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
case "shell":
|
||||
@@ -415,24 +543,66 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.cmdPrefix = "!"
|
||||
case "shell-async":
|
||||
app.ui.cmdPrefix = "&"
|
||||
case "find":
|
||||
app.ui.cmdPrefix = "find: "
|
||||
app.nav.findBack = false
|
||||
case "find-back":
|
||||
app.ui.cmdPrefix = "find-back: "
|
||||
app.nav.findBack = true
|
||||
case "find-next":
|
||||
for i := 0; i < e.count; i++ {
|
||||
if app.nav.findBack {
|
||||
app.nav.findPrev()
|
||||
} else {
|
||||
app.nav.findNext()
|
||||
}
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "find-prev":
|
||||
for i := 0; i < e.count; i++ {
|
||||
if app.nav.findBack {
|
||||
app.nav.findNext()
|
||||
} else {
|
||||
app.nav.findPrev()
|
||||
}
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "search":
|
||||
app.ui.cmdPrefix = "/"
|
||||
app.nav.searchBack = false
|
||||
case "search-back":
|
||||
app.ui.cmdPrefix = "?"
|
||||
app.nav.searchBack = true
|
||||
case "search-next":
|
||||
for i := 0; i < e.count; i++ {
|
||||
if err := app.nav.searchNext(); err != nil {
|
||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||
return
|
||||
if app.nav.searchBack {
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := app.nav.searchNext(); err != nil {
|
||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "search-prev":
|
||||
for i := 0; i < e.count; i++ {
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||
return
|
||||
if app.nav.searchBack {
|
||||
if err := app.nav.searchNext(); err != nil {
|
||||
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
@@ -487,7 +657,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
if err := app.nav.find(e.args[0]); err != nil {
|
||||
if err := app.nav.sel(e.args[0]); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
return
|
||||
}
|
||||
@@ -524,51 +694,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if len(e.args) == 0 {
|
||||
return
|
||||
}
|
||||
switch app.ui.cmdPrefix {
|
||||
case "mark-save: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return
|
||||
}
|
||||
app.nav.marks[e.args[0]] = wd
|
||||
|
||||
return
|
||||
case "mark-load: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
path, ok := app.nav.marks[e.args[0]]
|
||||
if !ok {
|
||||
app.ui.print("mark-load: no such mark")
|
||||
return
|
||||
}
|
||||
if err := app.nav.cd(path); err != nil {
|
||||
app.ui.printf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||
insert(app, e.args[0])
|
||||
case "cmd-escape":
|
||||
if app.ui.cmdPrefix == ">" {
|
||||
return
|
||||
@@ -646,7 +772,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
log.Printf("search-back: %s", s)
|
||||
app.nav.search = s
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||
} else {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
|
||||
@@ -51,6 +51,10 @@ The following commands are provided by lf with default keybindings:
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
shell-async (default '&')
|
||||
find (default 'f')
|
||||
find-back (default 'F')
|
||||
find-next (default ';')
|
||||
find-prev (default ',')
|
||||
search (default '/')
|
||||
search-back (default '?')
|
||||
search-next (default 'n')
|
||||
@@ -104,6 +108,7 @@ The following command line commands are provided by lf with default keybindings:
|
||||
The following options can be used to customize the behavior of lf:
|
||||
.PP
|
||||
.EX
|
||||
anchorfind boolean (default on)
|
||||
dircounts boolean (default off)
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
@@ -114,7 +119,8 @@ 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)
|
||||
findlen integer (default 1) (zero to prompt until single match)
|
||||
period integer (default 0) (zero to disable periodic loading)
|
||||
scrolloff integer (default 0)
|
||||
tabstop integer (default 8)
|
||||
filesep string (default "\en")
|
||||
@@ -138,6 +144,12 @@ The following variables are exported for shell commands:
|
||||
$id id number of the client
|
||||
.EE
|
||||
.PP
|
||||
The following variables are set to the corresponding values:
|
||||
.PP
|
||||
.EX
|
||||
$LF_LEVEL current nesting level
|
||||
.EE
|
||||
.PP
|
||||
The following default values are set to the environmental variables on unix when they are not set or empty:
|
||||
.PP
|
||||
.EX
|
||||
@@ -501,6 +513,12 @@ Getting the file selection is similarly done with 'load' command:
|
||||
fi
|
||||
.EE
|
||||
.PP
|
||||
There is a 'quit' command to close client connections and quit the server:
|
||||
.PP
|
||||
.EX
|
||||
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 the underlying 'cp' and 'mv' shell commands for file operations. For this purpose, when you 'copy' a file, it doesn't actually copy the file on the disk, but only records its name to memory. The actual file operation takes place when you 'paste' in which case the 'cp' command is used. Similarly the 'mv' command is used for 'cut' followed by 'paste'.
|
||||
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
var (
|
||||
envPath = os.Getenv("PATH")
|
||||
envPath = os.Getenv("PATH")
|
||||
envLevel = os.Getenv("LF_LEVEL")
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -34,10 +34,14 @@ func init() {
|
||||
log.Printf("hostname: %s", err)
|
||||
}
|
||||
gHostname = h
|
||||
|
||||
if envLevel == "" {
|
||||
envLevel = "0"
|
||||
}
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
cmd := exec.Command(os.Args[0], "-server")
|
||||
cmd := detachedCommand(os.Args[0], "-server")
|
||||
if err := cmd.Start(); err != nil {
|
||||
log.Printf("starting server: %s", err)
|
||||
}
|
||||
@@ -115,19 +119,6 @@ func main() {
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
case 1:
|
||||
dir := flag.Arg(0)
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "only single directory is allowed\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
switch {
|
||||
case *showDoc:
|
||||
fmt.Print(genDocString)
|
||||
@@ -150,6 +141,24 @@ func main() {
|
||||
gLogPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.%d.log", gUser.Username, gClientID))
|
||||
}
|
||||
|
||||
switch flag.NArg() {
|
||||
case 0:
|
||||
_, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
case 1:
|
||||
dir := flag.Arg(0)
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "only single directory is allowed\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ func (dir *dir) name() string {
|
||||
return dir.files[dir.ind].Name()
|
||||
}
|
||||
|
||||
func (dir *dir) find(name string, height int) {
|
||||
func (dir *dir) sel(name string, height int) {
|
||||
if len(dir.files) == 0 {
|
||||
dir.ind, dir.pos = 0, 0
|
||||
return
|
||||
@@ -198,7 +198,10 @@ type nav struct {
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
find string
|
||||
findBack bool
|
||||
search string
|
||||
searchBack bool
|
||||
}
|
||||
|
||||
func (nav *nav) loadDir(path string) *dir {
|
||||
@@ -226,7 +229,7 @@ func (nav *nav) loadDir(path string) *dir {
|
||||
d.loadTime = time.Now()
|
||||
nd := newDir(path)
|
||||
nd.sort()
|
||||
nd.find(d.name(), nav.height)
|
||||
nd.sel(d.name(), nav.height)
|
||||
nav.dirChan <- nd
|
||||
}()
|
||||
case d.sortType != gOpts.sortType:
|
||||
@@ -234,7 +237,7 @@ func (nav *nav) loadDir(path string) *dir {
|
||||
d.loading = true
|
||||
name := d.name()
|
||||
d.sort()
|
||||
d.find(name, nav.height)
|
||||
d.sel(name, nav.height)
|
||||
d.loading = false
|
||||
nav.dirChan <- d
|
||||
}()
|
||||
@@ -248,7 +251,7 @@ func (nav *nav) getDirs(wd string) {
|
||||
|
||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||
dir := nav.loadDir(curr)
|
||||
dir.find(base, nav.height)
|
||||
dir.sel(base, nav.height)
|
||||
dirs = append(dirs, dir)
|
||||
}
|
||||
|
||||
@@ -288,6 +291,7 @@ func (nav *nav) renew() {
|
||||
s, err := os.Stat(d.path)
|
||||
if err != nil {
|
||||
log.Printf("getting directory info: %s", err)
|
||||
return
|
||||
}
|
||||
if d.loadTime.After(s.ModTime()) {
|
||||
return
|
||||
@@ -309,13 +313,13 @@ func (nav *nav) renew() {
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) reload() {
|
||||
func (nav *nav) reload() error {
|
||||
nav.dirCache = make(map[string]*dir)
|
||||
nav.regCache = make(map[string]*reg)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return fmt.Errorf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
curr, err := nav.currFile()
|
||||
@@ -324,12 +328,14 @@ func (nav *nav) reload() {
|
||||
last := nav.dirs[len(nav.dirs)-1]
|
||||
last.files = append(last.files, curr)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) position() {
|
||||
path := nav.currDir().path
|
||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
||||
nav.dirs[i].find(filepath.Base(path), nav.height)
|
||||
nav.dirs[i].sel(filepath.Base(path), nav.height)
|
||||
path = filepath.Dir(path)
|
||||
}
|
||||
}
|
||||
@@ -415,7 +421,7 @@ func (nav *nav) sort() {
|
||||
for _, d := range nav.dirs {
|
||||
name := d.name()
|
||||
d.sort()
|
||||
d.find(name, nav.height)
|
||||
d.sel(name, nav.height)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,7 +633,7 @@ func (nav *nav) cd(wd string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) find(path string) error {
|
||||
func (nav *nav) sel(path string) error {
|
||||
lstat, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select: %s", err)
|
||||
@@ -645,13 +651,88 @@ func (nav *nav) find(path string) error {
|
||||
if last.loading {
|
||||
last.files = append(last.files, &file{FileInfo: lstat})
|
||||
} else {
|
||||
last.find(base, nav.height)
|
||||
last.sel(base, nav.height)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func match(pattern, name string) (matched bool, err error) {
|
||||
func findMatch(name, pattern string) bool {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
if !gOpts.smartcase || lpattern == pattern {
|
||||
pattern = lpattern
|
||||
name = strings.ToLower(name)
|
||||
}
|
||||
}
|
||||
if gOpts.anchorfind {
|
||||
return strings.HasPrefix(name, pattern)
|
||||
}
|
||||
return strings.Contains(name, pattern)
|
||||
}
|
||||
|
||||
func (nav *nav) findSingle() int {
|
||||
count := 0
|
||||
index := 0
|
||||
last := nav.currDir()
|
||||
for i := 0; i < len(last.files); i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
count++
|
||||
if count > 1 {
|
||||
return count
|
||||
}
|
||||
index = i
|
||||
}
|
||||
}
|
||||
if count == 1 {
|
||||
if index > last.ind {
|
||||
nav.down(index - last.ind)
|
||||
} else {
|
||||
nav.up(last.ind - index)
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func (nav *nav) findNext() bool {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.files); i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.down(i - last.ind)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := 0; i < last.ind; i++ {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.up(last.ind - i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (nav *nav) findPrev() bool {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i >= 0; i-- {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.up(last.ind - i)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||
if findMatch(last.files[i].Name(), nav.find) {
|
||||
nav.down(i - last.ind)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func searchMatch(name, pattern string) (matched bool, err error) {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
if !gOpts.smartcase || lpattern == pattern {
|
||||
@@ -668,7 +749,7 @@ func match(pattern, name string) (matched bool, err error) {
|
||||
func (nav *nav) searchNext() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind + 1; i < len(last.files); i++ {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -679,7 +760,7 @@ func (nav *nav) searchNext() error {
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := 0; i < last.ind; i++ {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -695,7 +776,7 @@ func (nav *nav) searchNext() error {
|
||||
func (nav *nav) searchPrev() error {
|
||||
last := nav.currDir()
|
||||
for i := last.ind - 1; i >= 0; i-- {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -706,7 +787,7 @@ func (nav *nav) searchPrev() error {
|
||||
}
|
||||
if gOpts.wrapscan {
|
||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
||||
matched, err := match(nav.search, last.files[i].Name())
|
||||
matched, err := searchMatch(last.files[i].Name(), nav.search)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type sortType struct {
|
||||
}
|
||||
|
||||
var gOpts struct {
|
||||
anchorfind bool
|
||||
dircounts bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
@@ -32,6 +33,7 @@ var gOpts struct {
|
||||
preview bool
|
||||
smartcase bool
|
||||
wrapscan bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
@@ -51,6 +53,7 @@ var gOpts struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
gOpts.anchorfind = true
|
||||
gOpts.dircounts = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.globsearch = false
|
||||
@@ -58,6 +61,7 @@ func init() {
|
||||
gOpts.preview = true
|
||||
gOpts.smartcase = true
|
||||
gOpts.wrapscan = true
|
||||
gOpts.findlen = 1
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
@@ -105,6 +109,10 @@ func init() {
|
||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||
gOpts.keys["&"] = &callExpr{"shell-async", nil, 1}
|
||||
gOpts.keys["f"] = &callExpr{"find", nil, 1}
|
||||
gOpts.keys["F"] = &callExpr{"find-back", nil, 1}
|
||||
gOpts.keys[";"] = &callExpr{"find-next", nil, 1}
|
||||
gOpts.keys[","] = &callExpr{"find-prev", nil, 1}
|
||||
gOpts.keys["/"] = &callExpr{"search", nil, 1}
|
||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||
|
||||
@@ -56,6 +56,12 @@ func init() {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("user: %s", err)
|
||||
if os.Getenv("HOME") == "" {
|
||||
log.Print("$HOME variable is empty or not set")
|
||||
}
|
||||
if os.Getenv("USER") == "" {
|
||||
log.Print("$USER variable is empty or not set")
|
||||
}
|
||||
}
|
||||
gUser = u
|
||||
|
||||
@@ -80,6 +86,10 @@ func init() {
|
||||
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
||||
}
|
||||
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
return exec.Command(name, arg...)
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
cmd := `echo
|
||||
echo -n 'Press any key to continue'
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -70,6 +71,12 @@ func init() {
|
||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
||||
}
|
||||
|
||||
func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 8}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func pauseCommand() *exec.Cmd {
|
||||
return exec.Command("cmd", "/c", "pause")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ var (
|
||||
gCopyFile bool
|
||||
gFileList []string
|
||||
gConnList = make(map[int]net.Conn)
|
||||
gQuitChan = make(chan bool, 1)
|
||||
gListener net.Listener
|
||||
)
|
||||
|
||||
func serve() {
|
||||
@@ -32,6 +34,8 @@ func serve() {
|
||||
}
|
||||
defer l.Close()
|
||||
|
||||
gListener = l
|
||||
|
||||
listen(l)
|
||||
}
|
||||
|
||||
@@ -39,7 +43,13 @@ func listen(l net.Listener) {
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accepting connection: %s", err)
|
||||
select {
|
||||
case <-gQuitChan:
|
||||
log.Printf("bye!")
|
||||
return
|
||||
default:
|
||||
log.Printf("accepting connection: %s", err)
|
||||
}
|
||||
}
|
||||
go handleConn(c)
|
||||
}
|
||||
@@ -103,6 +113,14 @@ func handleConn(c net.Conn) {
|
||||
}
|
||||
}
|
||||
}
|
||||
case "quit":
|
||||
gQuitChan <- true
|
||||
for _, c := range gConnList {
|
||||
fmt.Fprintln(c, "echo server is quitting...")
|
||||
c.Close()
|
||||
}
|
||||
gListener.Close()
|
||||
break
|
||||
default:
|
||||
log.Printf("listen: unexpected command: %s", word)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user