Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79b05dc365 | ||
|
|
c7fe60c541 | ||
|
|
ec5fac3274 | ||
|
|
90f0339fa9 | ||
|
|
e0e5977008 | ||
|
|
85a6fe95c5 | ||
|
|
55955fa5c1 | ||
|
|
993b227682 | ||
|
|
d8b9bab3ea | ||
|
|
c5297d6b6b | ||
|
|
8dd3f692b8 | ||
|
|
7e3f92f049 | ||
|
|
3efdfd3bca | ||
|
|
b101603a4a | ||
|
|
c693b7eae4 | ||
|
|
4ee6488a09 | ||
|
|
8229d972b9 | ||
|
|
6193885a55 | ||
|
|
6b1748240c | ||
|
|
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:
|
case d := <-app.nav.dirChan:
|
||||||
prev, ok := app.nav.dirCache[d.path]
|
prev, ok := app.nav.dirCache[d.path]
|
||||||
if ok {
|
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
|
app.nav.dirCache[d.path] = d
|
||||||
@@ -242,6 +243,15 @@ func (app *app) exportVars() {
|
|||||||
os.Setenv("EDITOR", envEditor)
|
os.Setenv("EDITOR", envEditor)
|
||||||
os.Setenv("PAGER", envPager)
|
os.Setenv("PAGER", envPager)
|
||||||
os.Setenv("SHELL", envShell)
|
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 {
|
func waitKey() error {
|
||||||
@@ -342,7 +352,7 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
}
|
}
|
||||||
app.cmd = nil
|
app.cmd = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
app.ui.exprChan <- &callExpr{"reload", nil, 1}
|
app.ui.exprChan <- &callExpr{"load", nil, 1}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
"github.com/nsf/termbox-go"
|
||||||
)
|
)
|
||||||
@@ -28,7 +29,7 @@ func run() {
|
|||||||
}
|
}
|
||||||
defer termbox.Close()
|
defer termbox.Close()
|
||||||
|
|
||||||
termbox.SetOutputMode(termbox.Output256)
|
setColorMode()
|
||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
|
||||||
@@ -53,10 +54,14 @@ func readExpr() <-chan expr {
|
|||||||
ch := make(chan expr)
|
ch := make(chan expr)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
duration := 1 * time.Second
|
||||||
|
|
||||||
c, err := net.Dial(gSocketProt, gSocketPath)
|
c, err := net.Dial(gSocketProt, gSocketPath)
|
||||||
if err != nil {
|
for err != nil {
|
||||||
log.Printf(fmt.Sprintf("connecting server: %s", err))
|
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)
|
fmt.Fprintf(c, "conn %d\n", gClientID)
|
||||||
|
|||||||
+38
-1
@@ -31,6 +31,7 @@ var (
|
|||||||
"copy",
|
"copy",
|
||||||
"cut",
|
"cut",
|
||||||
"paste",
|
"paste",
|
||||||
|
"delete",
|
||||||
"clear",
|
"clear",
|
||||||
"draw",
|
"draw",
|
||||||
"redraw",
|
"redraw",
|
||||||
@@ -41,6 +42,10 @@ var (
|
|||||||
"shell-pipe",
|
"shell-pipe",
|
||||||
"shell-wait",
|
"shell-wait",
|
||||||
"shell-async",
|
"shell-async",
|
||||||
|
"find",
|
||||||
|
"find-back",
|
||||||
|
"find-next",
|
||||||
|
"find-prev",
|
||||||
"search",
|
"search",
|
||||||
"search-back",
|
"search-back",
|
||||||
"search-next",
|
"search-next",
|
||||||
@@ -56,6 +61,12 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
gOptWords = []string{
|
gOptWords = []string{
|
||||||
|
"anchorfind",
|
||||||
|
"noanchorfind",
|
||||||
|
"anchorfind!",
|
||||||
|
"color256",
|
||||||
|
"nocolor256",
|
||||||
|
"color256!",
|
||||||
"dircounts",
|
"dircounts",
|
||||||
"nodircounts",
|
"nodircounts",
|
||||||
"dircounts!",
|
"dircounts!",
|
||||||
@@ -74,6 +85,12 @@ var (
|
|||||||
"ignorecase",
|
"ignorecase",
|
||||||
"noignorecase",
|
"noignorecase",
|
||||||
"ignorecase!",
|
"ignorecase!",
|
||||||
|
"ignoredia",
|
||||||
|
"noignoredia",
|
||||||
|
"ignoredia!",
|
||||||
|
"incsearch",
|
||||||
|
"noincsearch",
|
||||||
|
"incsearch!",
|
||||||
"preview",
|
"preview",
|
||||||
"nopreview",
|
"nopreview",
|
||||||
"preview!",
|
"preview!",
|
||||||
@@ -83,9 +100,19 @@ var (
|
|||||||
"smartcase",
|
"smartcase",
|
||||||
"nosmartcase",
|
"nosmartcase",
|
||||||
"smartcase!",
|
"smartcase!",
|
||||||
|
"smartdia",
|
||||||
|
"nosmartdia",
|
||||||
|
"smartdia!",
|
||||||
"wrapscan",
|
"wrapscan",
|
||||||
"nowrapscan",
|
"nowrapscan",
|
||||||
"wrapscan!",
|
"wrapscan!",
|
||||||
|
"number",
|
||||||
|
"nonumber",
|
||||||
|
"number!",
|
||||||
|
"relativenumber",
|
||||||
|
"norelativenumber",
|
||||||
|
"relativenumber!",
|
||||||
|
"findlen",
|
||||||
"period",
|
"period",
|
||||||
"scrolloff",
|
"scrolloff",
|
||||||
"tabstop",
|
"tabstop",
|
||||||
@@ -190,9 +217,10 @@ func matchFile(s string) (matches []string, longest string) {
|
|||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting current directory: %s", err)
|
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))
|
dir = unescape(filepath.Dir(dir))
|
||||||
|
|
||||||
@@ -256,6 +284,15 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
|||||||
words = append(words, c)
|
words = append(words, c)
|
||||||
}
|
}
|
||||||
sort.Strings(words)
|
sort.Strings(words)
|
||||||
|
j := 0
|
||||||
|
for i := 1; i < len(words); i++ {
|
||||||
|
if words[j] == words[i] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
j++
|
||||||
|
words[i], words[j] = words[j], words[i]
|
||||||
|
}
|
||||||
|
words = words[:j+1]
|
||||||
matches, longest = matchWord(s, words)
|
matches, longest = matchWord(s, words)
|
||||||
longestAcc = []rune(longest)
|
longestAcc = []rune(longest)
|
||||||
case 2:
|
case 2:
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var normMap map[rune]rune
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
normMap = make(map[rune]rune)
|
||||||
|
|
||||||
|
// (not only) european
|
||||||
|
appendTransliterate(
|
||||||
|
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||||
|
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Vietnamese
|
||||||
|
appendTransliterate(
|
||||||
|
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||||
|
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func appendTransliterate(base, norm string, uppercase bool) {
|
||||||
|
normRunes := []rune(norm)
|
||||||
|
baseRunes := []rune(base)
|
||||||
|
|
||||||
|
lenNorm := len(normRunes)
|
||||||
|
lenBase := len(baseRunes)
|
||||||
|
if lenNorm != lenBase {
|
||||||
|
panic("Base and normalized strings have differend lenght: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant lenght
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, baseRune := range baseRunes {
|
||||||
|
normMap[baseRune] = normRunes[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
if uppercase {
|
||||||
|
upperBase := strings.ToUpper(base)
|
||||||
|
upperNorm := strings.ToUpper(norm)
|
||||||
|
normRune := []rune(upperNorm)
|
||||||
|
for i, baseRune := range []rune(upperBase) {
|
||||||
|
normMap[baseRune] = normRune[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove diacritics and make lowercase.
|
||||||
|
func removeDiacritics(baseString string) string {
|
||||||
|
var normalizedRunes []rune
|
||||||
|
for _, baseRune := range []rune(baseString) {
|
||||||
|
if normRune, ok := normMap[baseRune]; ok {
|
||||||
|
normalizedRunes = append(normalizedRunes, normRune)
|
||||||
|
} else {
|
||||||
|
normalizedRunes = append(normalizedRunes, baseRune)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(normalizedRunes)
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// typical czech test sentence ;-)
|
||||||
|
const baseTestString = "Příliš žluťoučký kůň příšerně úpěl ďábelské ódy"
|
||||||
|
|
||||||
|
func TestRemoveDiacritics(t *testing.T) {
|
||||||
|
testStr := baseTestString
|
||||||
|
expStr := "Prilis zlutoucky kun priserne upel dabelske ody"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
// other accents (non comlete, but all I founded)
|
||||||
|
testStr = "áéíóúýčďěňřšťžůåøĉĝĥĵŝŭšžõäöüàâçéèêëîïôùûüÿžščćđáéíóúąęėįųūčšžāēīūčšžļķņģáéíóúöüőűäöüëïąćęłńóśźżáàãâçéêíóõôăâîșțáäčďéíĺľňóôŕšťúýžáéíñóúüåäöâçîşûğăâđêôơưáàãảạ"
|
||||||
|
expStr = "aeiouycdenrstzuaocghjsuszoaouaaceeeeiiouuuyzsccdaeiouaeeiuucszaeiucszlkngaeiouououaoueiacelnoszzaaaaceeioooaaistaacdeillnoorstuyzaeinouuaaoacisugaadeoouaaaaa"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "ÁÉÍÓÚÝČĎĚŇŘŠŤŽŮÅØĈĜĤĴŜŬŠŽÕÄÖÜÀÂÇÉÈÊËÎÏÔÙÛÜŸŽŠČĆĐÁÉÍÓÚĄĘĖĮŲŪČŠŽĀĒĪŪČŠŽĻĶŅĢÁÉÍÓÚÖÜŐŰÄÖÜËÏĄĆĘŁŃÓŚŹŻÁÀÃÂÇÉÊÍÓÕÔĂÂÎȘȚÁÄČĎÉÍĹĽŇÓÔŔŠŤÚÝŽÁÉÍÑÓÚÜÅÄÖÂÇÎŞÛĞĂÂĐÊÔƠƯÁÀÃẢẠ"
|
||||||
|
expStr = "AEIOUYCDENRSTZUAOCGHJSUSZOAOUAACEEEEIIOUUUYZSCCDAEIOUAEEIUUCSZAEIUCSZLKNGAEIOUOUOUAOUEIACELNOSZZAAAACEEIOOOAAISTAACDEILLNOORSTUYZAEINOUUAAOACISUGAADEOOUAAAAA"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ"
|
||||||
|
expStr = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
|
||||||
|
testStr = "ÁẠÀẢÃĂẮẶẰẲẴÂẤẬẦẨẪÉẸÈẺẼÊẾỆỀỂỄÍỊÌỈĨÓỌÒỎÕÔỐỘỒỔỖƠỚỢỜỞỠÚỤÙỦŨƯỨỰỪỬỮÝỴỲỶỸĐ"
|
||||||
|
expStr = "AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD"
|
||||||
|
checkRemoveDiacritics(testStr, expStr, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkRemoveDiacritics(testStr string, expStr string, t *testing.T) {
|
||||||
|
resultStr := removeDiacritics(testStr)
|
||||||
|
if resultStr != expStr {
|
||||||
|
t.Errorf("at input '%v' expected '%v' but got '%v'", testStr, expStr, resultStr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSearchSettings(t *testing.T) {
|
||||||
|
runSearch(t, true, false, true, true, "Veřejný", "vere", true)
|
||||||
|
|
||||||
|
runSearch(t, true, false, true, false, baseTestString, "Zlutoucky", true)
|
||||||
|
runSearch(t, true, false, true, false, baseTestString, "zlutoucky", true)
|
||||||
|
runSearch(t, true, true, true, false, baseTestString, "Zlutoucky", false)
|
||||||
|
runSearch(t, true, true, true, true, baseTestString, "zlutoucky", true)
|
||||||
|
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "žlutoucky", true)
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "Žlutoucky", false)
|
||||||
|
|
||||||
|
runSearch(t, false, false, true, true, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, true, false, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, false, false, baseTestString, "žluťoučký", true)
|
||||||
|
runSearch(t, false, false, false, false, baseTestString, "zlutoucky", false)
|
||||||
|
runSearch(t, false, false, true, true, baseTestString, "zlutoucky", true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacritics bool, base, pattern string, expected bool) {
|
||||||
|
gOpts.ignorecase = ignorecase
|
||||||
|
gOpts.smartcase = smartcase
|
||||||
|
gOpts.ignoredia = ignorediacritics
|
||||||
|
gOpts.smartdia = smartdiacritics
|
||||||
|
matched, _ := searchMatch(base, pattern)
|
||||||
|
if matched != expected {
|
||||||
|
t.Errorf("False search for" +
|
||||||
|
" ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " +
|
||||||
|
" smartcase = " + strconv.FormatBool(gOpts.smartcase) + ", " +
|
||||||
|
" ignoredia = " + strconv.FormatBool(gOpts.ignoredia) + ", " +
|
||||||
|
" smartdia = " + strconv.FormatBool(gOpts.smartdia) + ", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,6 +41,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -57,7 +61,8 @@ The following commands are provided by lf without default keybindings:
|
|||||||
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
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulates key pushes given in its argument
|
||||||
|
delete deletes the current file or selected file(s)
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
@@ -89,17 +94,25 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -120,6 +133,10 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or selected file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$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
|
The following default values are set to the environmental variables on unix
|
||||||
when they are not set or empty:
|
when they are not set or empty:
|
||||||
|
|
||||||
@@ -491,6 +508,10 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
# do something else with $list
|
# do something else with $list
|
||||||
fi
|
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
|
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||||
should not be needed for users.
|
should not be needed for users.
|
||||||
|
|
||||||
@@ -524,17 +545,56 @@ commands if they support it (i.e. GNU implementation), change the command type
|
|||||||
to asynchronous, or use 'rsync' command with progress bar option for copying
|
to asynchronous, or use 'rsync' command with progress bar option for copying
|
||||||
and feed the progress to the client periodically with remote 'echo' calls.
|
and feed the progress to the client periodically with remote 'echo' calls.
|
||||||
|
|
||||||
By default, lf does not provide an actual file deletion command to protect new
|
By default, lf does not assign 'delete' command to a key to protect new users.
|
||||||
users. You can define such a command and optionally assign a key if you like.
|
You can customize file deletion by defining a 'delete' command. You can also
|
||||||
An example command to move selected files to a trash folder and remove files
|
assign a key to this command if you like. An example command to move selected
|
||||||
completely are provided in the example configuration file.
|
files to a trash folder and remove files completely after a prompt are provided
|
||||||
|
in the example configuration file.
|
||||||
|
|
||||||
|
Searching Files
|
||||||
|
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current
|
||||||
|
directory. Searching is the traditional method to move the selection to a file
|
||||||
|
matching a given pattern. Finding is an alternative way to search for a pattern
|
||||||
|
possibly using fewer keystrokes.
|
||||||
|
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||||
|
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||||
|
(default 'N'). You can enable 'globsearch' option to match with a glob pattern.
|
||||||
|
Globbing supports '*' to match any sequence, '?' to match any character, and
|
||||||
|
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||||
|
'incsearch' option to jump to the current match at each keystroke while typing.
|
||||||
|
In this mode, you can either use 'cmd-enter' to accept the search or use
|
||||||
|
'cmd-escape' to cancel the search. Alternatively, you can also map some other
|
||||||
|
commands with 'cmap' to accept the search and execute the command immediately
|
||||||
|
afterwards. For example, you can use arrow keys to finish the search with the
|
||||||
|
following mappings:
|
||||||
|
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||||
|
position in the filename instead of the beginning. You can set the number of
|
||||||
|
keys to match using 'findlen' option. If you set this value to zero, then the
|
||||||
|
the keys are read until there is only a single match. Default values of these
|
||||||
|
two options are set to jump to the first file with the given initial.
|
||||||
|
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||||
|
option to prevent searches to wrap around at the end of the file list. You can
|
||||||
|
disable 'ignorecase' option to match cases in the pattern and the filename.
|
||||||
|
This option is already automatically overridden if the pattern contains upper
|
||||||
|
case characters. You can disable 'smartcase' option to disable this behavior.
|
||||||
|
Two similar options 'ignoredia' and 'smartdia' are provided to control matching
|
||||||
|
diacritics in latin letters.
|
||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can define a an 'open' command (default 'l') to configure file opening.
|
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||||
This command is only called when the current file is not a directory, otherwise
|
file opening. This command is only called when the current file is not a
|
||||||
the directory is entered instead. You can define it just as you would define
|
directory, otherwise the directory is entered instead. You can define it just
|
||||||
any other command:
|
as you would define any other command:
|
||||||
|
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
@@ -620,6 +680,13 @@ If both of these environment variables are not set, then lf fallbacks to its
|
|||||||
default colorscheme. Default lf colors are taken from GNU dircolors defaults.
|
default colorscheme. Default lf colors are taken from GNU dircolors defaults.
|
||||||
These defaults use 8 basic colors and bold attribute.
|
These defaults use 8 basic colors and bold attribute.
|
||||||
|
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr 3-bit
|
||||||
|
color escapes (e.g. '\033[34m'). If you want to use 256 colors, you need to
|
||||||
|
enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g.
|
||||||
|
'\033[38;5;4m'). This option is intended to eliminate differences between
|
||||||
|
default colors used by ls and lf since terminals may render 3-bit and 8-bit
|
||||||
|
escapes differently even for the same color.
|
||||||
|
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different
|
Keeping this mechanism in mind, you can configure lf colors in two different
|
||||||
ways. First, you can configure 8 basic colors used by your terminal and lf
|
ways. First, you can configure 8 basic colors used by your terminal and lf
|
||||||
should pick up those colors automatically. Depending on your terminal, you
|
should pick up those colors automatically. Depending on your terminal, you
|
||||||
@@ -632,5 +699,10 @@ fine grained customization. This is useful to change colors used for different
|
|||||||
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and
|
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and
|
||||||
it can be used even when GNU programs are not installed on the system. You can
|
it can be used even when GNU programs are not installed on the system. You can
|
||||||
combine this second method with the first method for best results.
|
combine this second method with the first method for best results.
|
||||||
|
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to match
|
||||||
|
the rest of the colors. Colors of the prompt line can be configured using the
|
||||||
|
'promptfmt' option which can include hardcoded colors as ansi escapes. See the
|
||||||
|
default value of this option to have an idea about how to color this line.
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
+84
-10
@@ -44,6 +44,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -60,7 +64,8 @@ The following commands are provided by lf without default keybindings:
|
|||||||
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
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulates key pushes given in its argument
|
||||||
|
delete deletes the current file or selected file(s)
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
keybindings:
|
keybindings:
|
||||||
@@ -92,17 +97,25 @@ keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\n")
|
filesep string (default "\n")
|
||||||
@@ -123,6 +136,10 @@ The following variables are exported for shell commands:
|
|||||||
$fx current file or selected file(s) if any
|
$fx current file or selected file(s) if any
|
||||||
$id id number of the client
|
$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
|
The following default values are set to the environmental variables on unix
|
||||||
when they are not set or empty:
|
when they are not set or empty:
|
||||||
|
|
||||||
@@ -512,6 +529,10 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
# do something else with $list
|
# do something else with $list
|
||||||
fi
|
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
|
Lastly, there is a 'conn' command to connect the server as a client. This
|
||||||
should not be needed for users.
|
should not be needed for users.
|
||||||
|
|
||||||
@@ -547,18 +568,58 @@ command type to asynchronous, or use 'rsync' command with progress bar
|
|||||||
option for copying and feed the progress to the client periodically with
|
option for copying and feed the progress to the client periodically with
|
||||||
remote 'echo' calls.
|
remote 'echo' calls.
|
||||||
|
|
||||||
By default, lf does not provide an actual file deletion command to protect
|
By default, lf does not assign 'delete' command to a key to protect new
|
||||||
new users. You can define such a command and optionally assign a key if you
|
users. You can customize file deletion by defining a 'delete' command. You
|
||||||
like. An example command to move selected files to a trash folder and remove
|
can also assign a key to this command if you like. An example command to
|
||||||
files completely are provided in the example configuration file.
|
move selected files to a trash folder and remove files completely after a
|
||||||
|
prompt are provided in the example configuration file.
|
||||||
|
|
||||||
|
|
||||||
|
Searching Files
|
||||||
|
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current
|
||||||
|
directory. Searching is the traditional method to move the selection to a
|
||||||
|
file matching a given pattern. Finding is an alternative way to search for a
|
||||||
|
pattern possibly using fewer keystrokes.
|
||||||
|
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'),
|
||||||
|
'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev'
|
||||||
|
(default 'N'). You can enable 'globsearch' option to match with a glob
|
||||||
|
pattern. Globbing supports '*' to match any sequence, '?' to match any
|
||||||
|
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||||
|
enable 'incsearch' option to jump to the current match at each keystroke
|
||||||
|
while typing. In this mode, you can either use 'cmd-enter' to accept the
|
||||||
|
search or use 'cmd-escape' to cancel the search. Alternatively, you can also
|
||||||
|
map some other commands with 'cmap' to accept the search and execute the
|
||||||
|
command immediately afterwards. For example, you can use arrow keys to
|
||||||
|
finish the search with the following mappings:
|
||||||
|
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
','). You can disable 'anchorfind' option to match a pattern at an arbitrary
|
||||||
|
position in the filename instead of the beginning. You can set the number of
|
||||||
|
keys to match using 'findlen' option. If you set this value to zero, then
|
||||||
|
the the keys are read until there is only a single match. Default values of
|
||||||
|
these two options are set to jump to the first file with the given initial.
|
||||||
|
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan'
|
||||||
|
option to prevent searches to wrap around at the end of the file list. You
|
||||||
|
can disable 'ignorecase' option to match cases in the pattern and the
|
||||||
|
filename. This option is already automatically overridden if the pattern
|
||||||
|
contains upper case characters. You can disable 'smartcase' option to
|
||||||
|
disable this behavior. Two similar options 'ignoredia' and 'smartdia' are
|
||||||
|
provided to control matching diacritics in latin letters.
|
||||||
|
|
||||||
|
|
||||||
Opening Files
|
Opening Files
|
||||||
|
|
||||||
You can define a an 'open' command (default 'l') to configure file opening.
|
You can define a an 'open' command (default 'l' and '<right>') to configure
|
||||||
This command is only called when the current file is not a directory,
|
file opening. This command is only called when the current file is not a
|
||||||
otherwise the directory is entered instead. You can define it just as you
|
directory, otherwise the directory is entered instead. You can define it
|
||||||
would define any other command:
|
just as you would define any other command:
|
||||||
|
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
|
|
||||||
@@ -650,6 +711,13 @@ If both of these environment variables are not set, then lf fallbacks to its
|
|||||||
default colorscheme. Default lf colors are taken from GNU dircolors
|
default colorscheme. Default lf colors are taken from GNU dircolors
|
||||||
defaults. These defaults use 8 basic colors and bold attribute.
|
defaults. These defaults use 8 basic colors and bold attribute.
|
||||||
|
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr
|
||||||
|
3-bit color escapes (e.g. '\033[34m'). If you want to use 256 colors, you
|
||||||
|
need to enable 'color256' option which then makes lf use sgr 8-bit color
|
||||||
|
escapes (e.g. '\033[38;5;4m'). This option is intended to eliminate
|
||||||
|
differences between default colors used by ls and lf since terminals may
|
||||||
|
render 3-bit and 8-bit escapes differently even for the same color.
|
||||||
|
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different
|
Keeping this mechanism in mind, you can configure lf colors in two different
|
||||||
ways. First, you can configure 8 basic colors used by your terminal and lf
|
ways. First, you can configure 8 basic colors used by your terminal and lf
|
||||||
should pick up those colors automatically. Depending on your terminal, you
|
should pick up those colors automatically. Depending on your terminal, you
|
||||||
@@ -663,4 +731,10 @@ different file types and extensions. '$LS_COLORS' is more powerful than
|
|||||||
'$LSCOLORS' and it can be used even when GNU programs are not installed on
|
'$LSCOLORS' and it can be used even when GNU programs are not installed on
|
||||||
the system. You can combine this second method with the first method for
|
the system. You can combine this second method with the first method for
|
||||||
best results.
|
best results.
|
||||||
|
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to
|
||||||
|
match the rest of the colors. Colors of the prompt line can be configured
|
||||||
|
using the 'promptfmt' option which can include hardcoded colors as ansi
|
||||||
|
escapes. See the default value of this option to have an idea about how to
|
||||||
|
color this line.
|
||||||
`
|
`
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
# Autocompletion for Fish shell
|
||||||
|
# Put this file somewhere in $fish_complete_path
|
||||||
|
# for example in ~/.config/fish/completions/
|
||||||
|
|
||||||
|
complete -c lf -o cpuprofile -r -d 'path to the file to write the CPU profile'
|
||||||
|
complete -c lf -o doc -d 'show documentation'
|
||||||
|
complete -c lf -o last-dir-path -r -d 'path to the file to write the last dir on exit (to use for cd)'
|
||||||
|
complete -c lf -o memprofile -r -d 'path to the file to write the memory profile'
|
||||||
|
complete -c lf -o remote -x -d 'send remote command to server'
|
||||||
|
complete -c lf -o selection-path -r -d 'path to the file to write selected files on open (to use as open file dialog)'
|
||||||
|
complete -c lf -o server -d 'start server (automatic)'
|
||||||
|
complete -c lf -o version -d 'show version'
|
||||||
|
complete -c lf -s h -d "short help"
|
||||||
@@ -14,6 +14,27 @@ import (
|
|||||||
|
|
||||||
func (e *setExpr) eval(app *app, args []string) {
|
func (e *setExpr) eval(app *app, args []string) {
|
||||||
switch e.opt {
|
switch e.opt {
|
||||||
|
case "anchorfind":
|
||||||
|
gOpts.anchorfind = true
|
||||||
|
case "noanchorfind":
|
||||||
|
gOpts.anchorfind = false
|
||||||
|
case "anchorfind!":
|
||||||
|
gOpts.anchorfind = !gOpts.anchorfind
|
||||||
|
case "color256":
|
||||||
|
gOpts.color256 = true
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
|
case "nocolor256":
|
||||||
|
gOpts.color256 = false
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
|
case "color256!":
|
||||||
|
gOpts.color256 = !gOpts.color256
|
||||||
|
setColorMode()
|
||||||
|
app.ui.pause()
|
||||||
|
app.ui.resume()
|
||||||
case "dircounts":
|
case "dircounts":
|
||||||
gOpts.dircounts = true
|
gOpts.dircounts = true
|
||||||
case "nodircounts":
|
case "nodircounts":
|
||||||
@@ -74,6 +95,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.ignorecase = false
|
gOpts.ignorecase = false
|
||||||
case "ignorecase!":
|
case "ignorecase!":
|
||||||
gOpts.ignorecase = !gOpts.ignorecase
|
gOpts.ignorecase = !gOpts.ignorecase
|
||||||
|
case "ignoredia":
|
||||||
|
gOpts.ignoredia = true
|
||||||
|
case "noignoredia":
|
||||||
|
gOpts.ignoredia = false
|
||||||
|
case "ignoredia!":
|
||||||
|
gOpts.ignoredia = !gOpts.ignoredia
|
||||||
|
case "incsearch":
|
||||||
|
gOpts.incsearch = true
|
||||||
|
case "noincsearch":
|
||||||
|
gOpts.incsearch = false
|
||||||
|
case "incsearch!":
|
||||||
|
gOpts.incsearch = !gOpts.incsearch
|
||||||
case "preview":
|
case "preview":
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
case "nopreview":
|
case "nopreview":
|
||||||
@@ -98,12 +131,41 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
gOpts.smartcase = false
|
gOpts.smartcase = false
|
||||||
case "smartcase!":
|
case "smartcase!":
|
||||||
gOpts.smartcase = !gOpts.smartcase
|
gOpts.smartcase = !gOpts.smartcase
|
||||||
|
case "smartdia":
|
||||||
|
gOpts.smartdia = true
|
||||||
|
case "nosmartdia":
|
||||||
|
gOpts.smartdia = false
|
||||||
|
case "smartdia!":
|
||||||
|
gOpts.smartdia = !gOpts.smartdia
|
||||||
case "wrapscan":
|
case "wrapscan":
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
case "nowrapscan":
|
case "nowrapscan":
|
||||||
gOpts.wrapscan = false
|
gOpts.wrapscan = false
|
||||||
case "wrapscan!":
|
case "wrapscan!":
|
||||||
gOpts.wrapscan = !gOpts.wrapscan
|
gOpts.wrapscan = !gOpts.wrapscan
|
||||||
|
case "number":
|
||||||
|
gOpts.number = true
|
||||||
|
case "nonumber":
|
||||||
|
gOpts.number = false
|
||||||
|
case "number!":
|
||||||
|
gOpts.number = !gOpts.number
|
||||||
|
case "relativenumber":
|
||||||
|
gOpts.relativenumber = true
|
||||||
|
case "norelativenumber":
|
||||||
|
gOpts.relativenumber = false
|
||||||
|
case "relativenumber!":
|
||||||
|
gOpts.relativenumber = !gOpts.relativenumber
|
||||||
|
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":
|
case "period":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -253,7 +315,172 @@ func splitKeys(s string) (keys []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func update(app *app) {
|
||||||
|
switch {
|
||||||
|
case gOpts.incsearch && app.ui.cmdPrefix == "/":
|
||||||
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
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 gOpts.incsearch && app.ui.cmdPrefix == "?":
|
||||||
|
app.nav.search = string(app.ui.cmdAccLeft) + string(app.ui.cmdAccRight)
|
||||||
|
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
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)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func insert(app *app, arg string) {
|
||||||
|
switch {
|
||||||
|
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
||||||
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||||
|
update(app)
|
||||||
|
case app.ui.cmdPrefix == "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 app.ui.cmdPrefix == "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 app.ui.cmdPrefix == "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 app.ui.cmdPrefix == "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) {
|
func (e *callExpr) eval(app *app, args []string) {
|
||||||
|
if app.ui.cmdPrefix != "" && e.name != "redraw" && !strings.HasPrefix(e.name, "cmd-") {
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
}
|
||||||
switch e.name {
|
switch e.name {
|
||||||
case "up":
|
case "up":
|
||||||
app.nav.up(e.count)
|
app.nav.up(e.count)
|
||||||
@@ -388,6 +615,17 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if err := sendRemote("send sync"); err != nil {
|
if err := sendRemote("send sync"); err != nil {
|
||||||
app.ui.printf("paste: %s", err)
|
app.ui.printf("paste: %s", err)
|
||||||
}
|
}
|
||||||
|
case "delete":
|
||||||
|
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||||
|
cmd.eval(app, e.args)
|
||||||
|
} else if err := app.nav.deleteFiles(); err != nil {
|
||||||
|
app.ui.printf("delete: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.nav.unselect()
|
||||||
|
if err := sendRemote("send load"); err != nil {
|
||||||
|
app.ui.printf("delete: %s", err)
|
||||||
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
app.ui.printf("clear: %s", err)
|
app.ui.printf("clear: %s", err)
|
||||||
@@ -404,7 +642,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "load":
|
case "load":
|
||||||
app.nav.renew()
|
app.nav.renew()
|
||||||
case "reload":
|
case "reload":
|
||||||
app.nav.reload()
|
if err := app.nav.reload(); err != nil {
|
||||||
|
app.ui.printf("reload: %s", err)
|
||||||
|
}
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
case "shell":
|
case "shell":
|
||||||
@@ -415,26 +655,74 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdPrefix = "!"
|
app.ui.cmdPrefix = "!"
|
||||||
case "shell-async":
|
case "shell-async":
|
||||||
app.ui.cmdPrefix = "&"
|
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":
|
case "search":
|
||||||
app.ui.cmdPrefix = "/"
|
app.ui.cmdPrefix = "/"
|
||||||
|
last := app.nav.currDir()
|
||||||
|
app.nav.searchInd = last.ind
|
||||||
|
app.nav.searchPos = last.pos
|
||||||
|
app.nav.searchBack = false
|
||||||
case "search-back":
|
case "search-back":
|
||||||
app.ui.cmdPrefix = "?"
|
app.ui.cmdPrefix = "?"
|
||||||
|
last := app.nav.currDir()
|
||||||
|
app.nav.searchInd = last.ind
|
||||||
|
app.nav.searchPos = last.pos
|
||||||
|
app.nav.searchBack = true
|
||||||
case "search-next":
|
case "search-next":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
|
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 {
|
if err := app.nav.searchNext(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "search-prev":
|
case "search-prev":
|
||||||
for i := 0; i < e.count; i++ {
|
for i := 0; i < e.count; i++ {
|
||||||
|
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 {
|
if err := app.nav.searchPrev(); err != nil {
|
||||||
app.ui.printf("search: %s: %s", err, app.nav.search)
|
app.ui.printf("search: %s: %s", err, app.nav.search)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "mark-save":
|
case "mark-save":
|
||||||
@@ -487,7 +775,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
log.Printf("getting current directory: %s", err)
|
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)
|
app.ui.printf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -524,55 +812,19 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if len(e.args) == 0 {
|
if len(e.args) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch app.ui.cmdPrefix {
|
insert(app, e.args[0])
|
||||||
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])...)
|
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
if app.ui.cmdPrefix == ">" {
|
if app.ui.cmdPrefix == ">" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?") {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
}
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
@@ -633,6 +885,11 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "/":
|
case "/":
|
||||||
|
if gOpts.incsearch {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
}
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
if err := app.nav.searchNext(); err != nil {
|
if err := app.nav.searchNext(); err != nil {
|
||||||
@@ -643,10 +900,15 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "?":
|
case "?":
|
||||||
|
if gOpts.incsearch {
|
||||||
|
last := app.nav.currDir()
|
||||||
|
last.ind = app.nav.searchInd
|
||||||
|
last.pos = app.nav.searchPos
|
||||||
|
}
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
if err := app.nav.searchPrev(); err != nil {
|
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 {
|
} else {
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
@@ -695,11 +957,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[1:]
|
||||||
|
update(app)
|
||||||
case "cmd-delete-back":
|
case "cmd-delete-back":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:len(app.ui.cmdAccLeft)-1]
|
||||||
|
update(app)
|
||||||
case "cmd-left":
|
case "cmd-left":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
@@ -724,23 +988,28 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
|
update(app)
|
||||||
case "cmd-delete-end":
|
case "cmd-delete-end":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
app.ui.cmdYankBuf = app.ui.cmdAccRight
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
|
update(app)
|
||||||
case "cmd-delete-unix-word":
|
case "cmd-delete-unix-word":
|
||||||
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
ind := strings.LastIndex(strings.TrimRight(string(app.ui.cmdAccLeft), " "), " ") + 1
|
||||||
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]
|
app.ui.cmdYankBuf = app.ui.cmdAccLeft[ind:]
|
||||||
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
app.ui.cmdAccLeft = app.ui.cmdAccLeft[:ind]
|
||||||
|
update(app)
|
||||||
case "cmd-yank":
|
case "cmd-yank":
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdYankBuf...)
|
||||||
|
update(app)
|
||||||
case "cmd-transpose":
|
case "cmd-transpose":
|
||||||
if len(app.ui.cmdAccLeft) < 2 {
|
if len(app.ui.cmdAccLeft) < 2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
||||||
|
update(app)
|
||||||
case "cmd-interrupt":
|
case "cmd-interrupt":
|
||||||
if app.cmd != nil {
|
if app.cmd != nil {
|
||||||
app.cmd.Process.Kill()
|
app.cmd.Process.Kill()
|
||||||
@@ -791,6 +1060,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind = loc[0] + 1
|
ind = loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, app.ui.cmdAccRight[:ind]...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-delete-word":
|
case "cmd-delete-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -801,6 +1071,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-uppercase-word":
|
case "cmd-uppercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -812,6 +1083,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToUpper(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-lowercase-word":
|
case "cmd-lowercase-word":
|
||||||
if len(app.ui.cmdAccRight) == 0 {
|
if len(app.ui.cmdAccRight) == 0 {
|
||||||
return
|
return
|
||||||
@@ -823,6 +1095,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
ind := loc[0] + 1
|
ind := loc[0] + 1
|
||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(strings.ToLower(string(app.ui.cmdAccRight[:ind])))...)
|
||||||
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
app.ui.cmdAccRight = app.ui.cmdAccRight[ind:]
|
||||||
|
update(app)
|
||||||
case "cmd-transpose-word":
|
case "cmd-transpose-word":
|
||||||
if len(app.ui.cmdAccLeft) == 0 {
|
if len(app.ui.cmdAccLeft) == 0 {
|
||||||
return
|
return
|
||||||
@@ -856,6 +1129,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
acc = append(acc, app.ui.cmdAccLeft[end2:]...)
|
||||||
|
|
||||||
app.ui.cmdAccLeft = acc
|
app.ui.cmdAccLeft = acc
|
||||||
|
update(app)
|
||||||
default:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
shell-pipe (default '%')
|
shell-pipe (default '%')
|
||||||
shell-wait (default '!')
|
shell-wait (default '!')
|
||||||
shell-async (default '&')
|
shell-async (default '&')
|
||||||
|
find (default 'f')
|
||||||
|
find-back (default 'F')
|
||||||
|
find-next (default ';')
|
||||||
|
find-prev (default ',')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -69,7 +73,8 @@ The following commands are provided by lf without default keybindings:
|
|||||||
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
|
source reads the configuration file in its argument
|
||||||
push simulate key pushes given in its argument
|
push simulates key pushes given in its argument
|
||||||
|
delete deletes the current file or selected file(s)
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.PP
|
||||||
The following command line commands are provided by lf with default keybindings:
|
The following command line commands are provided by lf with default keybindings:
|
||||||
@@ -104,17 +109,25 @@ The following command line commands are provided by lf with default keybindings:
|
|||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
|
anchorfind boolean (default on)
|
||||||
|
color256 boolean (default off)
|
||||||
dircounts boolean (default off)
|
dircounts boolean (default off)
|
||||||
dirfirst boolean (default on)
|
dirfirst boolean (default on)
|
||||||
drawbox boolean (default off)
|
drawbox boolean (default off)
|
||||||
globsearch boolean (default off)
|
globsearch boolean (default off)
|
||||||
hidden boolean (default off)
|
hidden boolean (default off)
|
||||||
ignorecase boolean (default on)
|
ignorecase boolean (default on)
|
||||||
|
ignoredia boolean (default off)
|
||||||
|
incsearch boolean (default off)
|
||||||
preview boolean (default on)
|
preview boolean (default on)
|
||||||
reverse boolean (default off)
|
reverse boolean (default off)
|
||||||
smartcase boolean (default on)
|
smartcase boolean (default on)
|
||||||
|
smartdia boolean (default off)
|
||||||
wrapscan boolean (default on)
|
wrapscan boolean (default on)
|
||||||
period integer (default 0)
|
number boolean (default off)
|
||||||
|
relativenumber boolean (default off)
|
||||||
|
findlen integer (default 1) (zero to prompt until single match)
|
||||||
|
period integer (default 0) (zero to disable periodic loading)
|
||||||
scrolloff integer (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop integer (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default "\en")
|
filesep string (default "\en")
|
||||||
@@ -138,6 +151,12 @@ The following variables are exported for shell commands:
|
|||||||
$id id number of the client
|
$id id number of the client
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.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:
|
The following default values are set to the environmental variables on unix when they are not set or empty:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
@@ -501,6 +520,12 @@ Getting the file selection is similarly done with 'load' command:
|
|||||||
fi
|
fi
|
||||||
.EE
|
.EE
|
||||||
.PP
|
.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.
|
Lastly, there is a 'conn' command to connect the server as a client. This should not be needed for users.
|
||||||
.SH FILE OPERATIONS
|
.SH FILE OPERATIONS
|
||||||
lf uses 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'.
|
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'.
|
||||||
@@ -524,9 +549,22 @@ You can customize these operations by defining a 'paste' command. This is a spec
|
|||||||
.PP
|
.PP
|
||||||
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv' commands if they support it (i.e. GNU implementation), change the command type to asynchronous, or use 'rsync' command with progress bar option for copying and feed the progress to the client periodically with remote 'echo' calls.
|
||||||
.PP
|
.PP
|
||||||
By default, lf does not provide an actual file deletion command to protect new users. You can define such a command and optionally assign a key if you like. An example command to move selected files to a trash folder and remove files completely are provided in the example configuration file.
|
By default, lf does not assign 'delete' command to a key to protect new users. You can customize file deletion by defining a 'delete' command. You can also assign a key to this command if you like. An example command to move selected files to a trash folder and remove files completely after a prompt are provided in the example configuration file.
|
||||||
|
.SH SEARCHING FILES
|
||||||
|
There are two mechanisms implemented in lf to search a file in the current directory. Searching is the traditional method to move the selection to a file matching a given pattern. Finding is an alternative way to search for a pattern possibly using fewer keystrokes.
|
||||||
|
.PP
|
||||||
|
Searching mechanism is implemented with commands 'search' (default '/'), 'search-back' (default '?'), 'search-next' (default 'n'), and 'search-prev' (default 'N'). You can enable 'globsearch' option to match with a glob pattern. Globbing supports '*' to match any sequence, '?' to match any character, and '[...]' or '[^...] to match character sets or ranges. You can enable 'incsearch' option to jump to the current match at each keystroke while typing. In this mode, you can either use 'cmd-enter' to accept the search or use 'cmd-escape' to cancel the search. Alternatively, you can also map some other commands with 'cmap' to accept the search and execute the command immediately afterwards. For example, you can use arrow keys to finish the search with the following mappings:
|
||||||
|
.PP
|
||||||
|
.EX
|
||||||
|
cmap <up> up
|
||||||
|
cmap <down> down
|
||||||
|
.EE
|
||||||
|
.PP
|
||||||
|
Finding mechanism is implemented with commands 'find' (default 'f'), 'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default ','). You can disable 'anchorfind' option to match a pattern at an arbitrary position in the filename instead of the beginning. You can set the number of keys to match using 'findlen' option. If you set this value to zero, then the the keys are read until there is only a single match. Default values of these two options are set to jump to the first file with the given initial.
|
||||||
|
.PP
|
||||||
|
Some options effect both searching and finding. You can disable 'wrapscan' option to prevent searches to wrap around at the end of the file list. You can disable 'ignorecase' option to match cases in the pattern and the filename. This option is already automatically overridden if the pattern contains upper case characters. You can disable 'smartcase' option to disable this behavior. Two similar options 'ignoredia' and 'smartdia' are provided to control matching diacritics in latin letters.
|
||||||
.SH OPENING FILES
|
.SH OPENING FILES
|
||||||
You can define a an 'open' command (default 'l') to configure file opening. This command is only called when the current file is not a directory, otherwise the directory is entered instead. You can define it just as you would define any other command:
|
You can define a an 'open' command (default 'l' and '<right>') to configure file opening. This command is only called when the current file is not a directory, otherwise the directory is entered instead. You can define it just as you would define any other command:
|
||||||
.PP
|
.PP
|
||||||
.EX
|
.EX
|
||||||
cmd open $vi $fx
|
cmd open $vi $fx
|
||||||
@@ -591,6 +629,10 @@ If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead. Th
|
|||||||
.PP
|
.PP
|
||||||
If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute.
|
If both of these environment variables are not set, then lf fallbacks to its default colorscheme. Default lf colors are taken from GNU dircolors defaults. These defaults use 8 basic colors and bold attribute.
|
||||||
.PP
|
.PP
|
||||||
|
You should also note that lf uses 8 color mode by default which uses sgr 3-bit color escapes (e.g. '\e033[34m'). If you want to use 256 colors, you need to enable 'color256' option which then makes lf use sgr 8-bit color escapes (e.g. '\e033[38;5;4m'). This option is intended to eliminate differences between default colors used by ls and lf since terminals may render 3-bit and 8-bit escapes differently even for the same color.
|
||||||
|
.PP
|
||||||
Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other.
|
Keeping this mechanism in mind, you can configure lf colors in two different ways. First, you can configure 8 basic colors used by your terminal and lf should pick up those colors automatically. Depending on your terminal, you should be able to select your colors from a 24-bit palette. This is the recommended approach as colors used by other programs will also match each other.
|
||||||
.PP
|
.PP
|
||||||
Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results.
|
Second, you can set the values of environmental variables mentioned above for fine grained customization. This is useful to change colors used for different file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and it can be used even when GNU programs are not installed on the system. You can combine this second method with the first method for best results.
|
||||||
|
.PP
|
||||||
|
Lastly, you may also want to configure the colors of the prompt line to match the rest of the colors. Colors of the prompt line can be configured using the 'promptfmt' option which can include hardcoded colors as ansi escapes. See the default value of this option to have an idea about how to color this line.
|
||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
@@ -14,6 +13,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
envPath = os.Getenv("PATH")
|
envPath = os.Getenv("PATH")
|
||||||
|
envLevel = os.Getenv("LF_LEVEL")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -34,10 +34,14 @@ func init() {
|
|||||||
log.Printf("hostname: %s", err)
|
log.Printf("hostname: %s", err)
|
||||||
}
|
}
|
||||||
gHostname = h
|
gHostname = h
|
||||||
|
|
||||||
|
if envLevel == "" {
|
||||||
|
envLevel = "0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer() {
|
func startServer() {
|
||||||
cmd := exec.Command(os.Args[0], "-server")
|
cmd := detachedCommand(os.Args[0], "-server")
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
log.Printf("starting server: %s", err)
|
log.Printf("starting server: %s", err)
|
||||||
}
|
}
|
||||||
@@ -115,19 +119,6 @@ func main() {
|
|||||||
defer pprof.StopCPUProfile()
|
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 {
|
switch {
|
||||||
case *showDoc:
|
case *showDoc:
|
||||||
fmt.Print(genDocString)
|
fmt.Print(genDocString)
|
||||||
@@ -150,6 +141,24 @@ func main() {
|
|||||||
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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ func (dir *dir) name() string {
|
|||||||
return dir.files[dir.ind].Name()
|
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 {
|
if len(dir.files) == 0 {
|
||||||
dir.ind, dir.pos = 0, 0
|
dir.ind, dir.pos = 0, 0
|
||||||
return
|
return
|
||||||
@@ -198,7 +198,12 @@ type nav struct {
|
|||||||
selections map[string]int
|
selections map[string]int
|
||||||
selectionInd int
|
selectionInd int
|
||||||
height int
|
height int
|
||||||
|
find string
|
||||||
|
findBack bool
|
||||||
search string
|
search string
|
||||||
|
searchBack bool
|
||||||
|
searchInd int
|
||||||
|
searchPos int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) loadDir(path string) *dir {
|
func (nav *nav) loadDir(path string) *dir {
|
||||||
@@ -226,7 +231,7 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
d.loadTime = time.Now()
|
d.loadTime = time.Now()
|
||||||
nd := newDir(path)
|
nd := newDir(path)
|
||||||
nd.sort()
|
nd.sort()
|
||||||
nd.find(d.name(), nav.height)
|
nd.sel(d.name(), nav.height)
|
||||||
nav.dirChan <- nd
|
nav.dirChan <- nd
|
||||||
}()
|
}()
|
||||||
case d.sortType != gOpts.sortType:
|
case d.sortType != gOpts.sortType:
|
||||||
@@ -234,7 +239,7 @@ func (nav *nav) loadDir(path string) *dir {
|
|||||||
d.loading = true
|
d.loading = true
|
||||||
name := d.name()
|
name := d.name()
|
||||||
d.sort()
|
d.sort()
|
||||||
d.find(name, nav.height)
|
d.sel(name, nav.height)
|
||||||
d.loading = false
|
d.loading = false
|
||||||
nav.dirChan <- d
|
nav.dirChan <- d
|
||||||
}()
|
}()
|
||||||
@@ -248,7 +253,7 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
dir := nav.loadDir(curr)
|
dir := nav.loadDir(curr)
|
||||||
dir.find(base, nav.height)
|
dir.sel(base, nav.height)
|
||||||
dirs = append(dirs, dir)
|
dirs = append(dirs, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,6 +293,7 @@ func (nav *nav) renew() {
|
|||||||
s, err := os.Stat(d.path)
|
s, err := os.Stat(d.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting directory info: %s", err)
|
log.Printf("getting directory info: %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if d.loadTime.After(s.ModTime()) {
|
if d.loadTime.After(s.ModTime()) {
|
||||||
return
|
return
|
||||||
@@ -309,13 +315,13 @@ func (nav *nav) renew() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) reload() {
|
func (nav *nav) reload() error {
|
||||||
nav.dirCache = make(map[string]*dir)
|
nav.dirCache = make(map[string]*dir)
|
||||||
nav.regCache = make(map[string]*reg)
|
nav.regCache = make(map[string]*reg)
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("getting current directory: %s", err)
|
return fmt.Errorf("getting current directory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
@@ -324,12 +330,14 @@ func (nav *nav) reload() {
|
|||||||
last := nav.dirs[len(nav.dirs)-1]
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
last.files = append(last.files, curr)
|
last.files = append(last.files, curr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) position() {
|
func (nav *nav) position() {
|
||||||
path := nav.currDir().path
|
path := nav.currDir().path
|
||||||
for i := len(nav.dirs) - 2; i >= 0; i-- {
|
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)
|
path = filepath.Dir(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -415,7 +423,7 @@ func (nav *nav) sort() {
|
|||||||
for _, d := range nav.dirs {
|
for _, d := range nav.dirs {
|
||||||
name := d.name()
|
name := d.name()
|
||||||
d.sort()
|
d.sort()
|
||||||
d.find(name, nav.height)
|
d.sel(name, nav.height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -542,6 +550,22 @@ func (nav *nav) unselect() {
|
|||||||
nav.selectionInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// effectiveSelection is a pure function that returns the selected files's paths.
|
||||||
|
// In case the user has not selected a file it returns the file on the user's cursor.
|
||||||
|
// If the function can't return a selection it returns an error.
|
||||||
|
func (nav *nav) effectiveSelection() (list []string, err error) {
|
||||||
|
if len(nav.selections) == 0 {
|
||||||
|
curr, err := nav.currFile()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("no file selected")
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{curr.path}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nav.currSelections(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) save(cp bool) error {
|
func (nav *nav) save(cp bool) error {
|
||||||
if len(nav.selections) == 0 {
|
if len(nav.selections) == 0 {
|
||||||
curr, err := nav.currFile()
|
curr, err := nav.currFile()
|
||||||
@@ -596,6 +620,24 @@ func (nav *nav) paste() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deleteFiles deletes the user's selected files
|
||||||
|
// it returns an error if no files are selected or if the OS fails to delete a file
|
||||||
|
func (nav *nav) deleteFiles() error {
|
||||||
|
list, err := nav.effectiveSelection()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range list {
|
||||||
|
if err := os.RemoveAll(path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) sync() error {
|
func (nav *nav) sync() error {
|
||||||
list, cp, err := loadFiles()
|
list, cp, err := loadFiles()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -627,7 +669,7 @@ func (nav *nav) cd(wd string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) find(path string) error {
|
func (nav *nav) sel(path string) error {
|
||||||
lstat, err := os.Stat(path)
|
lstat, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("select: %s", err)
|
return fmt.Errorf("select: %s", err)
|
||||||
@@ -645,13 +687,13 @@ func (nav *nav) find(path string) error {
|
|||||||
if last.loading {
|
if last.loading {
|
||||||
last.files = append(last.files, &file{FileInfo: lstat})
|
last.files = append(last.files, &file{FileInfo: lstat})
|
||||||
} else {
|
} else {
|
||||||
last.find(base, nav.height)
|
last.sel(base, nav.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func match(pattern, name string) (matched bool, err error) {
|
func findMatch(name, pattern string) bool {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
if !gOpts.smartcase || lpattern == pattern {
|
if !gOpts.smartcase || lpattern == pattern {
|
||||||
@@ -659,6 +701,95 @@ func match(pattern, name string) (matched bool, err error) {
|
|||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if gOpts.ignoredia {
|
||||||
|
lpattern := removeDiacritics(pattern)
|
||||||
|
if !gOpts.smartdia || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = removeDiacritics(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 {
|
||||||
|
pattern = lpattern
|
||||||
|
name = strings.ToLower(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gOpts.ignoredia {
|
||||||
|
lpattern := removeDiacritics(pattern)
|
||||||
|
if !gOpts.smartdia || lpattern == pattern {
|
||||||
|
pattern = lpattern
|
||||||
|
name = removeDiacritics(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
if gOpts.globsearch {
|
if gOpts.globsearch {
|
||||||
return filepath.Match(pattern, name)
|
return filepath.Match(pattern, name)
|
||||||
}
|
}
|
||||||
@@ -668,7 +799,7 @@ func match(pattern, name string) (matched bool, err error) {
|
|||||||
func (nav *nav) searchNext() error {
|
func (nav *nav) searchNext() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind + 1; i < len(last.files); i++ {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -679,7 +810,7 @@ func (nav *nav) searchNext() error {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := 0; i < last.ind; i++ {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -695,7 +826,7 @@ func (nav *nav) searchNext() error {
|
|||||||
func (nav *nav) searchPrev() error {
|
func (nav *nav) searchPrev() error {
|
||||||
last := nav.currDir()
|
last := nav.currDir()
|
||||||
for i := last.ind - 1; i >= 0; i-- {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -706,7 +837,7 @@ func (nav *nav) searchPrev() error {
|
|||||||
}
|
}
|
||||||
if gOpts.wrapscan {
|
if gOpts.wrapscan {
|
||||||
for i := len(last.files) - 1; i > last.ind; i-- {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,13 +25,21 @@ type sortType struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var gOpts struct {
|
var gOpts struct {
|
||||||
|
anchorfind bool
|
||||||
|
color256 bool
|
||||||
dircounts bool
|
dircounts bool
|
||||||
drawbox bool
|
drawbox bool
|
||||||
globsearch bool
|
globsearch bool
|
||||||
ignorecase bool
|
ignorecase bool
|
||||||
|
incsearch bool
|
||||||
preview bool
|
preview bool
|
||||||
smartcase bool
|
smartcase bool
|
||||||
|
ignoredia bool
|
||||||
|
smartdia bool
|
||||||
wrapscan bool
|
wrapscan bool
|
||||||
|
number bool
|
||||||
|
relativenumber bool
|
||||||
|
findlen int
|
||||||
period int
|
period int
|
||||||
scrolloff int
|
scrolloff int
|
||||||
tabstop int
|
tabstop int
|
||||||
@@ -51,13 +59,19 @@ var gOpts struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
gOpts.anchorfind = true
|
||||||
|
gOpts.color256 = false
|
||||||
gOpts.dircounts = false
|
gOpts.dircounts = false
|
||||||
gOpts.drawbox = false
|
gOpts.drawbox = false
|
||||||
gOpts.globsearch = false
|
gOpts.globsearch = false
|
||||||
gOpts.ignorecase = true
|
gOpts.ignorecase = true
|
||||||
|
gOpts.incsearch = false
|
||||||
gOpts.preview = true
|
gOpts.preview = true
|
||||||
gOpts.smartcase = true
|
gOpts.smartcase = true
|
||||||
|
gOpts.ignoredia = false
|
||||||
|
gOpts.smartdia = false
|
||||||
gOpts.wrapscan = true
|
gOpts.wrapscan = true
|
||||||
|
gOpts.findlen = 1
|
||||||
gOpts.period = 0
|
gOpts.period = 0
|
||||||
gOpts.scrolloff = 0
|
gOpts.scrolloff = 0
|
||||||
gOpts.tabstop = 8
|
gOpts.tabstop = 8
|
||||||
@@ -105,6 +119,10 @@ func init() {
|
|||||||
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil, 1}
|
||||||
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil, 1}
|
||||||
gOpts.keys["&"] = &callExpr{"shell-async", 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", nil, 1}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
gOpts.keys["?"] = &callExpr{"search-back", nil, 1}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
gOpts.keys["n"] = &callExpr{"search-next", nil, 1}
|
||||||
|
|||||||
@@ -56,6 +56,12 @@ func init() {
|
|||||||
u, err := user.Current()
|
u, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("user: %s", err)
|
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
|
gUser = u
|
||||||
|
|
||||||
@@ -80,6 +86,10 @@ func init() {
|
|||||||
gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username))
|
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 {
|
func pauseCommand() *exec.Cmd {
|
||||||
cmd := `echo
|
cmd := `echo
|
||||||
echo -n 'Press any key to continue'
|
echo -n 'Press any key to continue'
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -70,6 +71,12 @@ func init() {
|
|||||||
gHistoryPath = filepath.Join(data, "lf", "history")
|
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 {
|
func pauseCommand() *exec.Cmd {
|
||||||
return exec.Command("cmd", "/c", "pause")
|
return exec.Command("cmd", "/c", "pause")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ var (
|
|||||||
gCopyFile bool
|
gCopyFile bool
|
||||||
gFileList []string
|
gFileList []string
|
||||||
gConnList = make(map[int]net.Conn)
|
gConnList = make(map[int]net.Conn)
|
||||||
|
gQuitChan = make(chan bool, 1)
|
||||||
|
gListener net.Listener
|
||||||
)
|
)
|
||||||
|
|
||||||
func serve() {
|
func serve() {
|
||||||
@@ -32,6 +34,8 @@ func serve() {
|
|||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
|
gListener = l
|
||||||
|
|
||||||
listen(l)
|
listen(l)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,8 +43,14 @@ func listen(l net.Listener) {
|
|||||||
for {
|
for {
|
||||||
c, err := l.Accept()
|
c, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
select {
|
||||||
|
case <-gQuitChan:
|
||||||
|
log.Printf("bye!")
|
||||||
|
return
|
||||||
|
default:
|
||||||
log.Printf("accepting connection: %s", err)
|
log.Printf("accepting connection: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
go handleConn(c)
|
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:
|
default:
|
||||||
log.Printf("listen: unexpected command: %s", word)
|
log.Printf("listen: unexpected command: %s", word)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,18 +267,45 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lnwidth int = 0
|
||||||
|
var lnformat string = ""
|
||||||
|
|
||||||
|
if gOpts.number || gOpts.relativenumber {
|
||||||
|
lnwidth = 1
|
||||||
|
for j := 10; j < len(dir.files); j *= 10 {
|
||||||
|
lnwidth++
|
||||||
|
}
|
||||||
|
lnformat = fmt.Sprintf("%%%d.d ", lnwidth)
|
||||||
|
}
|
||||||
|
|
||||||
for i, f := range dir.files[beg:end] {
|
for i, f := range dir.files[beg:end] {
|
||||||
fg, bg = colors.get(f)
|
fg, bg = colors.get(f)
|
||||||
|
|
||||||
|
if lnwidth > 0 {
|
||||||
|
var ln string
|
||||||
|
|
||||||
|
if gOpts.number && (!gOpts.relativenumber || i == dir.pos) {
|
||||||
|
ln = fmt.Sprintf(lnformat, i+1+beg)
|
||||||
|
} else if gOpts.relativenumber {
|
||||||
|
if i < dir.pos {
|
||||||
|
ln = fmt.Sprintf(lnformat, dir.pos-i)
|
||||||
|
} else {
|
||||||
|
ln = fmt.Sprintf(lnformat, i-dir.pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
win.print(0, i, termbox.ColorYellow, bg, ln)
|
||||||
|
}
|
||||||
|
|
||||||
path := filepath.Join(dir.path, f.Name())
|
path := filepath.Join(dir.path, f.Name())
|
||||||
|
|
||||||
if _, ok := selections[path]; ok {
|
if _, ok := selections[path]; ok {
|
||||||
win.print(0, i, fg, termbox.ColorMagenta, " ")
|
win.print(lnwidth, i, fg, termbox.ColorMagenta, " ")
|
||||||
} else if cp, ok := saves[path]; ok {
|
} else if cp, ok := saves[path]; ok {
|
||||||
if cp {
|
if cp {
|
||||||
win.print(0, i, fg, termbox.ColorYellow, " ")
|
win.print(lnwidth, i, fg, termbox.ColorYellow, " ")
|
||||||
} else {
|
} else {
|
||||||
win.print(0, i, fg, termbox.ColorRed, " ")
|
win.print(lnwidth, i, fg, termbox.ColorRed, " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +348,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
|||||||
|
|
||||||
s = append(s, ' ')
|
s = append(s, ' ')
|
||||||
|
|
||||||
win.print(1, i, fg, bg, string(s))
|
win.print(lnwidth+1, i, fg, bg, string(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,7 +482,7 @@ func (ui *ui) sort() {
|
|||||||
}
|
}
|
||||||
name := ui.dirPrev.name()
|
name := ui.dirPrev.name()
|
||||||
ui.dirPrev.sort()
|
ui.dirPrev.sort()
|
||||||
ui.dirPrev.find(name, ui.wins[0].h)
|
ui.dirPrev.sel(name, ui.wins[0].h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) print(msg string) {
|
func (ui *ui) print(msg string) {
|
||||||
@@ -892,6 +919,14 @@ func (ui *ui) readExpr() <-chan expr {
|
|||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setColorMode() {
|
||||||
|
if gOpts.color256 {
|
||||||
|
termbox.SetOutputMode(termbox.Output256)
|
||||||
|
} else {
|
||||||
|
termbox.SetOutputMode(termbox.OutputNormal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (ui *ui) pause() {
|
func (ui *ui) pause() {
|
||||||
termbox.Close()
|
termbox.Close()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user