Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f661344ed | ||
|
|
bfd01e5ed8 | ||
|
|
27861f06e2 | ||
|
|
cb36e87b80 | ||
|
|
30d3078559 | ||
|
|
db224f04fe | ||
|
|
afca893153 | ||
|
|
16db95707e | ||
|
|
bf39c7c63b | ||
|
|
eb8e516cfb | ||
|
|
34f39f90b2 | ||
|
|
4c6241ca42 | ||
|
|
8388b4f385 | ||
|
|
80ab2e4fc4 | ||
|
|
f071a3ae70 | ||
|
|
f3407b2d61 | ||
|
|
a5199960ed | ||
|
|
e69a229578 | ||
|
|
e815adc6a6 | ||
|
|
13fe1931cd | ||
|
|
2c87b0dcfe | ||
|
|
b2b22fb674 | ||
|
|
45270e389e | ||
|
|
fee016f406 | ||
|
|
29de45e466 | ||
|
|
791b704257 | ||
|
|
e3bc11408f | ||
|
|
6f35abb4ca | ||
|
|
0eedb71d6c | ||
|
|
1eedd29546 | ||
|
|
866a7e6a2b |
No files matched your search
Generated
-21
@@ -1,21 +0,0 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
packages = ["."]
|
||||
revision = "ce7b0b5c7b45a81508558cd1dba6bb1e4ddb51bb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/nsf/termbox-go"
|
||||
packages = ["."]
|
||||
revision = "5c94acc5e6eb520f1bcd183974e01171cc4c23b3"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "8508b73787d4948edb76ccc25789c311a4ab84d4c8c0b96b267857e2e88d974e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/nsf/termbox-go"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -138,7 +137,14 @@ func (app *app) loop() {
|
||||
|
||||
if gSelect != "" {
|
||||
go func() {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
stat, err := os.Stat(gSelect)
|
||||
if err != nil {
|
||||
app.ui.exprChan <- &callExpr{"echoerr", []string{err.Error()}, 1}
|
||||
} else if stat.IsDir() {
|
||||
app.ui.exprChan <- &callExpr{"cd", []string{gSelect}, 1}
|
||||
} else {
|
||||
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -175,10 +181,6 @@ func (app *app) loop() {
|
||||
|
||||
log.Print("bye!")
|
||||
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
log.Printf("writing marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := app.writeHistory(); err != nil {
|
||||
log.Printf("writing history file: %s", err)
|
||||
}
|
||||
@@ -283,40 +285,15 @@ func (app *app) loop() {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *app) exportVars() {
|
||||
var envFile string
|
||||
func (app *app) exportFiles() {
|
||||
var currFile string
|
||||
if f, err := app.nav.currFile(); err == nil {
|
||||
envFile = f.path
|
||||
currFile = f.path
|
||||
}
|
||||
|
||||
selections := app.nav.currSelections()
|
||||
currSelections := app.nav.currSelections()
|
||||
|
||||
envFiles := strings.Join(selections, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(selections) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
|
||||
os.Setenv("OPENER", envOpener)
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
exportFiles(currFile, currSelections)
|
||||
}
|
||||
|
||||
func waitKey() error {
|
||||
@@ -341,7 +318,7 @@ func waitKey() error {
|
||||
// ! Yes No Yes Yes Yes Pause and then resume
|
||||
// & No Yes No No No Do nothing
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.exportVars()
|
||||
app.exportFiles()
|
||||
|
||||
cmd := shellCommand(s, args)
|
||||
|
||||
|
||||
@@ -199,6 +199,10 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
@@ -207,10 +211,6 @@ func (cm colorMap) get(f *file) (termbox.Attribute, termbox.Attribute) {
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
|
||||
+49
@@ -51,13 +51,17 @@ var (
|
||||
"search-next",
|
||||
"search-prev",
|
||||
"mark-save",
|
||||
"mark-remove",
|
||||
"mark-load",
|
||||
"rename",
|
||||
"sync",
|
||||
"echo",
|
||||
"echomsg",
|
||||
"echoerr",
|
||||
"cd",
|
||||
"select",
|
||||
"glob-select",
|
||||
"glob-unselect",
|
||||
"source",
|
||||
"push",
|
||||
}
|
||||
@@ -81,6 +85,9 @@ var (
|
||||
"globsearch",
|
||||
"noglobsearch",
|
||||
"globsearch!",
|
||||
"icons",
|
||||
"noicons",
|
||||
"icons!",
|
||||
"hidden",
|
||||
"nohidden",
|
||||
"hidden!",
|
||||
@@ -108,6 +115,9 @@ var (
|
||||
"wrapscan",
|
||||
"nowrapscan",
|
||||
"wrapscan!",
|
||||
"wrapscroll",
|
||||
"nowrapscroll",
|
||||
"wrapscroll!",
|
||||
"number",
|
||||
"nonumber",
|
||||
"number!",
|
||||
@@ -118,6 +128,7 @@ var (
|
||||
"period",
|
||||
"scrolloff",
|
||||
"tabstop",
|
||||
"errorfmt",
|
||||
"filesep",
|
||||
"ifs",
|
||||
"previewer",
|
||||
@@ -321,6 +332,44 @@ func completeCmd(acc []rune) (matches []string, longestAcc []rune) {
|
||||
return
|
||||
}
|
||||
|
||||
func completeFile(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(wd)
|
||||
if err != nil {
|
||||
log.Printf("reading directory: %s", err)
|
||||
}
|
||||
|
||||
var longest string
|
||||
|
||||
for _, f := range files {
|
||||
if !strings.HasPrefix(f.Name(), s) {
|
||||
continue
|
||||
}
|
||||
|
||||
matches = append(matches, f.Name())
|
||||
|
||||
if longest != "" {
|
||||
longest = matchLongest(longest, f.Name())
|
||||
} else if s != "" {
|
||||
longest = f.Name()
|
||||
}
|
||||
}
|
||||
|
||||
if longest == "" {
|
||||
longest = s
|
||||
}
|
||||
|
||||
longestAcc = []rune(longest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func completeShell(acc []rune) (matches []string, longestAcc []rune) {
|
||||
s := string(acc)
|
||||
f := tokenize(s)
|
||||
|
||||
+9
-15
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var normMap map[rune]rune
|
||||
@@ -14,19 +14,17 @@ func init() {
|
||||
appendTransliterate(
|
||||
"ěřůøĉĝĥĵŝŭèùÿėįųāēīūļķņģőűëïąćęłńśźżõșțčďĺľňŕšťýžéíñóúüåäöçîşûğăâđêôơưáàãảạ",
|
||||
"eruocghjsueuyeiuaeiulkngoueiacelnszzostcdllnrstyzeinouuaaocisugaadeoouaaaaa",
|
||||
true,
|
||||
)
|
||||
|
||||
// Vietnamese
|
||||
appendTransliterate(
|
||||
"áạàảãăắặằẳẵâấậầẩẫéẹèẻẽêếệềểễiíịìỉĩoóọòỏõôốộồổỗơớợờởỡúụùủũưứựừửữyýỵỳỷỹđ",
|
||||
"aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiioooooooooooooooooouuuuuuuuuuuyyyyyyd",
|
||||
true,
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
func appendTransliterate(base, norm string, uppercase bool) {
|
||||
func appendTransliterate(base, norm string) {
|
||||
normRunes := []rune(norm)
|
||||
baseRunes := []rune(base)
|
||||
|
||||
@@ -36,24 +34,20 @@ func appendTransliterate(base, norm string, uppercase bool) {
|
||||
panic("Base and normalized strings have differend length: base=" + strconv.Itoa(lenBase) + ", norm=" + strconv.Itoa(lenNorm)) // programmer error in constant length
|
||||
}
|
||||
|
||||
for i, baseRune := range baseRunes {
|
||||
normMap[baseRune] = normRunes[i]
|
||||
}
|
||||
for i := 0; i < lenBase; i++ {
|
||||
normMap[baseRunes[i]] = 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]
|
||||
}
|
||||
baseUpper := unicode.ToUpper(baseRunes[i])
|
||||
normUpper := unicode.ToUpper(normRunes[i])
|
||||
|
||||
normMap[baseUpper] = normUpper
|
||||
}
|
||||
}
|
||||
|
||||
// Remove diacritics and make lowercase.
|
||||
func removeDiacritics(baseString string) string {
|
||||
var normalizedRunes []rune
|
||||
for _, baseRune := range []rune(baseString) {
|
||||
for _, baseRune := range baseString {
|
||||
if normRune, ok := normMap[baseRune]; ok {
|
||||
normalizedRunes = append(normalizedRunes, normRune)
|
||||
} else {
|
||||
|
||||
@@ -37,6 +37,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -51,6 +52,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default `"`)
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
@@ -62,6 +64,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -102,6 +106,7 @@ The following options can be used to customize the behavior of lf:
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
icons boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -111,12 +116,14 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
wrapscroll boolean (default off)
|
||||
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)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default '') (not exported if empty)
|
||||
previewer string (default '') (not filtered if empty)
|
||||
@@ -213,14 +220,11 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file for
|
||||
read and shell commands. The difference is that prefixes are not necessary in
|
||||
the command line. Instead, different modes are provided to read corresponding
|
||||
commands. These modes are mapped to the prefix keys above by default. Searching
|
||||
commands are only used from the command line.
|
||||
commands. These modes are mapped to the prefix keys above by default.
|
||||
|
||||
Syntax
|
||||
|
||||
@@ -534,7 +538,7 @@ manually. Operation errors are shown in the message line as well as the log
|
||||
file and they do not preemptively finish the corresponding file operation.
|
||||
|
||||
File operations can be performed on the current selected file or alternatively
|
||||
on multiple files by marking them first. When you 'copy' a file, lf doesn't
|
||||
on multiple files by selecting them first. When you 'copy' a file, lf doesn't
|
||||
actually copy the file on the disk, but only records its name to memory. The
|
||||
actual file copying takes place when you 'paste'. Similarly 'paste' after a
|
||||
'cut' operation moves the file.
|
||||
@@ -582,7 +586,16 @@ 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.
|
||||
'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. Possible candidates are 'up', 'down' and their variants, 'updir',
|
||||
and 'open' commands. For example, you can use arrow keys to finish the search
|
||||
with the following mappings:
|
||||
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
|
||||
+19
-5
@@ -40,6 +40,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -54,6 +55,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default '"')
|
||||
|
||||
The following commands are provided by lf without default keybindings:
|
||||
|
||||
@@ -65,6 +67,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -105,6 +109,7 @@ The following options can be used to customize the behavior of lf:
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
icons boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -114,12 +119,14 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
wrapscroll boolean (default off)
|
||||
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)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\033[7;31;47m%s\033[0m")
|
||||
filesep string (default "\n")
|
||||
ifs string (default ”) (not exported if empty)
|
||||
previewer string (default ”) (not filtered if empty)
|
||||
@@ -218,14 +225,12 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
|
||||
The same evaluator is used for the command line and the configuration file
|
||||
for read and shell commands. The difference is that prefixes are not
|
||||
necessary in the command line. Instead, different modes are provided to read
|
||||
corresponding commands. These modes are mapped to the prefix keys above by
|
||||
default. Searching commands are only used from the command line.
|
||||
default.
|
||||
|
||||
|
||||
Syntax
|
||||
@@ -557,7 +562,7 @@ as well as the log file and they do not preemptively finish the
|
||||
corresponding file operation.
|
||||
|
||||
File operations can be performed on the current selected file or
|
||||
alternatively on multiple files by marking them first. When you 'copy' a
|
||||
alternatively on multiple files by selecting them first. When you 'copy' a
|
||||
file, lf doesn't actually copy the file on the disk, but only records its
|
||||
name to memory. The actual file copying takes place when you 'paste'.
|
||||
Similarly 'paste' after a 'cut' operation moves the file.
|
||||
@@ -607,7 +612,16 @@ 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.
|
||||
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. Possible candidates are 'up', 'down' and
|
||||
their variants, 'updir', and 'open' commands. For example, you can use arrow
|
||||
keys to finish the search with the following mappings:
|
||||
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
|
||||
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||
|
||||
+16
-12
@@ -42,25 +42,29 @@ cmd open ${{
|
||||
esac
|
||||
}}
|
||||
|
||||
# rename current file without overwrite
|
||||
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
map r push :rename<space>
|
||||
# define a custom 'rename' command without prompt for overwrite
|
||||
# cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||
# map r push :rename<space>
|
||||
|
||||
# make sure trash folder exists
|
||||
%mkdir -p ~/.trash
|
||||
# %mkdir -p ~/.trash
|
||||
|
||||
# move current file or selected files to trash folder
|
||||
# (also see 'man mv' for backup/overwrite options)
|
||||
cmd trash %set -f; mv $fx ~/.trash
|
||||
|
||||
# delete current file or selected files (prompting)
|
||||
cmd delete ${{
|
||||
set -f
|
||||
printf "$fx\n"
|
||||
printf "delete?[y/n]"
|
||||
read ans
|
||||
[ $ans = "y" ] && rm -rf $fx
|
||||
}}
|
||||
# define a custom 'delete' command
|
||||
# cmd delete ${{
|
||||
# set -f
|
||||
# printf "$fx\n"
|
||||
# printf "delete?[y/n]"
|
||||
# read ans
|
||||
# [ $ans = "y" ] && rm -rf $fx
|
||||
# }}
|
||||
|
||||
# use '<delete>' key for either 'trash' or 'delete' command
|
||||
# map <delete> trash
|
||||
# map <delete> delete
|
||||
|
||||
# extract the current file with the right command
|
||||
# (xkcd link: https://xkcd.com/1168/)
|
||||
|
||||
@@ -71,6 +71,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.globsearch = false
|
||||
case "globsearch!":
|
||||
gOpts.globsearch = !gOpts.globsearch
|
||||
case "icons":
|
||||
gOpts.icons = true
|
||||
case "noicons":
|
||||
gOpts.icons = false
|
||||
case "icons!":
|
||||
gOpts.icons = !gOpts.icons
|
||||
case "hidden":
|
||||
gOpts.sortType.option |= hiddenSort
|
||||
app.nav.sort()
|
||||
@@ -108,10 +114,18 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
case "incsearch!":
|
||||
gOpts.incsearch = !gOpts.incsearch
|
||||
case "preview":
|
||||
if len(gOpts.ratios) < 2 {
|
||||
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||
return
|
||||
}
|
||||
gOpts.preview = true
|
||||
case "nopreview":
|
||||
gOpts.preview = false
|
||||
case "preview!":
|
||||
if len(gOpts.ratios) < 2 {
|
||||
app.ui.echoerr("preview: 'ratios' should consist of at least two numbers before enabling 'preview'")
|
||||
return
|
||||
}
|
||||
gOpts.preview = !gOpts.preview
|
||||
case "reverse":
|
||||
gOpts.sortType.option |= reverseSort
|
||||
@@ -143,6 +157,12 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.wrapscan = false
|
||||
case "wrapscan!":
|
||||
gOpts.wrapscan = !gOpts.wrapscan
|
||||
case "wrapscroll":
|
||||
gOpts.wrapscroll = true
|
||||
case "nowrapscroll":
|
||||
gOpts.wrapscroll = false
|
||||
case "wrapscroll!":
|
||||
gOpts.wrapscroll = !gOpts.wrapscroll
|
||||
case "number":
|
||||
gOpts.number = true
|
||||
case "nonumber":
|
||||
@@ -205,6 +225,8 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
return
|
||||
}
|
||||
gOpts.tabstop = n
|
||||
case "errorfmt":
|
||||
gOpts.errorfmt = e.val
|
||||
case "filesep":
|
||||
gOpts.filesep = e.val
|
||||
case "ifs":
|
||||
@@ -269,31 +291,36 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
gOpts.shellopts = strings.Split(e.val, ":")
|
||||
default:
|
||||
app.ui.echoerrf("unknown option: %s", e.opt)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *mapExpr) eval(app *app, args []string) {
|
||||
if e.expr == nil {
|
||||
delete(gOpts.keys, e.keys)
|
||||
return
|
||||
} else {
|
||||
gOpts.keys[e.keys] = e.expr
|
||||
}
|
||||
gOpts.keys[e.keys] = e.expr
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *cmapExpr) eval(app *app, args []string) {
|
||||
if e.cmd == "" {
|
||||
delete(gOpts.cmdkeys, e.key)
|
||||
return
|
||||
} else {
|
||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||
}
|
||||
gOpts.cmdkeys[e.key] = &callExpr{e.cmd, nil, 1}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *cmdExpr) eval(app *app, args []string) {
|
||||
if e.expr == nil {
|
||||
delete(gOpts.cmds, e.name)
|
||||
return
|
||||
} else {
|
||||
gOpts.cmds[e.name] = e.expr
|
||||
}
|
||||
gOpts.cmds[e.name] = e.expr
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func splitKeys(s string) (keys []string) {
|
||||
@@ -362,6 +389,13 @@ func update(app *app) {
|
||||
}
|
||||
}
|
||||
|
||||
func normal(app *app) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
}
|
||||
|
||||
func insert(app *app, arg string) {
|
||||
switch {
|
||||
case gOpts.incsearch && (app.ui.cmdPrefix == "/" || app.ui.cmdPrefix == "?"):
|
||||
@@ -395,10 +429,7 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case app.ui.cmdPrefix == "find-back: ":
|
||||
app.nav.find = string(app.ui.cmdAccLeft) + arg + string(app.ui.cmdAccRight)
|
||||
|
||||
@@ -427,15 +458,9 @@ func insert(app *app, arg string) {
|
||||
}
|
||||
}
|
||||
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case app.ui.cmdPrefix == "delete?[y/N]: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
if arg == "y" {
|
||||
if err := app.nav.del(); err != nil {
|
||||
@@ -445,13 +470,29 @@ func insert(app *app, arg string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case strings.HasPrefix(app.ui.cmdPrefix, "replace") ||
|
||||
strings.HasPrefix(app.ui.cmdPrefix, "create path"):
|
||||
normal(app)
|
||||
|
||||
if arg == "y" {
|
||||
if err := app.nav.rename(app.ui); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-save: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -459,11 +500,14 @@ func insert(app *app, arg string) {
|
||||
return
|
||||
}
|
||||
app.nav.marks[arg] = wd
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
app.ui.echoerrf("mark-save: %s", err)
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("mark-save: %s", err)
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-load: ":
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -485,38 +529,73 @@ func insert(app *app, arg string) {
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
case app.ui.cmdPrefix == "mark-remove: ":
|
||||
normal(app)
|
||||
if err := app.nav.removeMark(arg); err != nil {
|
||||
app.ui.echoerrf("mark-remove: %s", err)
|
||||
return
|
||||
}
|
||||
if err := app.nav.writeMarks(); err != nil {
|
||||
app.ui.echoerrf("mark-remove: %s", err)
|
||||
return
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("mark-remove: %s", err)
|
||||
}
|
||||
default:
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(arg)...)
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
|
||||
func (e *callExpr) eval(app *app, args []string) {
|
||||
switch e.name {
|
||||
case "up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "half-up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count * app.nav.height / 2)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "page-up":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.up(e.count * app.nav.height)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "half-down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count * app.nav.height / 2)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "page-down":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
app.nav.down(e.count * app.nav.height)
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "updir":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
for i := 0; i < e.count; i++ {
|
||||
if err := app.nav.updir(); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
@@ -526,6 +605,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "open":
|
||||
if app.ui.cmdPrefix != "" && app.ui.cmdPrefix != ">" {
|
||||
normal(app)
|
||||
}
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.echoerrf("opening: %s", err)
|
||||
@@ -589,8 +671,10 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "invert":
|
||||
app.nav.invert()
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "unselect":
|
||||
app.nav.unselect()
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "copy":
|
||||
if err := app.nav.save(true); err != nil {
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
@@ -599,7 +683,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("copy: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "cut":
|
||||
if err := app.nav.save(false); err != nil {
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
@@ -608,7 +694,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.nav.unselect()
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("cut: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "paste":
|
||||
if cmd, ok := gOpts.cmds["paste"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
@@ -616,12 +704,15 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.echoerrf("paste: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "delete":
|
||||
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
app.nav.unselect()
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("delete: %s", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err := app.nav.currFileOrSelections(); err != nil {
|
||||
@@ -630,6 +721,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
app.ui.cmdPrefix = "delete?[y/N]: "
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "clear":
|
||||
if err := saveFiles(nil, false); err != nil {
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
@@ -637,18 +730,24 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
}
|
||||
if err := remote("send sync"); err != nil {
|
||||
app.ui.echoerrf("clear: %s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "draw":
|
||||
case "redraw":
|
||||
app.ui.sync()
|
||||
app.ui.renew()
|
||||
app.nav.height = app.ui.wins[0].h
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "load":
|
||||
app.nav.renew()
|
||||
case "reload":
|
||||
if err := app.nav.reload(); err != nil {
|
||||
app.ui.echoerrf("reload: %s", err)
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "read":
|
||||
app.ui.cmdPrefix = ":"
|
||||
case "shell":
|
||||
@@ -734,6 +833,27 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
case "mark-load":
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-load: "
|
||||
case "mark-remove":
|
||||
app.ui.menuBuf = listMarks(app.nav.marks)
|
||||
app.ui.cmdPrefix = "mark-remove: "
|
||||
case "rename":
|
||||
if cmd, ok := gOpts.cmds["rename"]; ok {
|
||||
cmd.eval(app, e.args)
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
curr, err := app.nav.currFile()
|
||||
if err != nil {
|
||||
app.ui.echoerrf("rename: %s:", err)
|
||||
return
|
||||
}
|
||||
app.ui.cmdPrefix = "rename: "
|
||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(curr.Name())...)
|
||||
}
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "sync":
|
||||
if err := app.nav.sync(); err != nil {
|
||||
app.ui.echoerrf("sync: %s", err)
|
||||
@@ -801,12 +921,33 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if wd != path {
|
||||
app.nav.marks["'"] = wd
|
||||
}
|
||||
case "glob-select":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("glob-select: requires a pattern to match")
|
||||
return
|
||||
}
|
||||
if err := app.nav.globSel(e.args[0], false); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "glob-unselect":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("glob-unselect: requires a pattern to match")
|
||||
return
|
||||
}
|
||||
if err := app.nav.globSel(e.args[0], true); err != nil {
|
||||
app.ui.echoerrf("%s", err)
|
||||
return
|
||||
}
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "source":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("source: requires an argument")
|
||||
return
|
||||
}
|
||||
app.readFile(strings.Replace(e.args[0], "~", gUser.HomeDir, -1))
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
case "push":
|
||||
if len(e.args) != 1 {
|
||||
app.ui.echoerr("push: requires an argument")
|
||||
@@ -833,16 +974,18 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
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 = ""
|
||||
normal(app)
|
||||
case "cmd-complete":
|
||||
var matches []string
|
||||
if app.ui.cmdPrefix == ":" {
|
||||
switch app.ui.cmdPrefix {
|
||||
case ":":
|
||||
matches, app.ui.cmdAccLeft = completeCmd(app.ui.cmdAccLeft)
|
||||
} else {
|
||||
case "/", "?":
|
||||
matches, app.ui.cmdAccLeft = completeFile(app.ui.cmdAccLeft)
|
||||
case "$", "%", "!", "&":
|
||||
matches, app.ui.cmdAccLeft = completeShell(app.ui.cmdAccLeft)
|
||||
default:
|
||||
return
|
||||
}
|
||||
app.ui.draw(app.nav)
|
||||
if len(matches) > 1 {
|
||||
@@ -919,6 +1062,45 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if err := app.nav.searchPrev(); err != nil {
|
||||
app.ui.echoerrf("search-back: %s: %s", err, app.nav.search)
|
||||
} else {
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
case "rename: ":
|
||||
app.ui.cmdPrefix = ""
|
||||
if curr, err := app.nav.currFile(); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
} else {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
log.Printf("getting current directory: %s", err)
|
||||
return
|
||||
}
|
||||
oldPathTo := filepath.Join(wd, curr.Name())
|
||||
newPathTo := filepath.Join(wd, s)
|
||||
app.nav.renameCache = []string{oldPathTo, newPathTo}
|
||||
|
||||
if dir, _ := filepath.Split(s); dir != "" {
|
||||
if _, err := os.Stat(filepath.Join(wd, dir)); err != nil {
|
||||
app.ui.cmdPrefix = "create path " + dir + "?[y/N]"
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat(newPathTo); err == nil { // file exists
|
||||
app.ui.cmdPrefix = "replace " + s + "?[y/N]"
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.nav.rename(app.ui); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := remote("send load"); err != nil {
|
||||
app.ui.echoerrf("rename: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
app.ui.loadFile(app.nav)
|
||||
app.ui.loadFileInfo(app.nav)
|
||||
}
|
||||
@@ -936,7 +1118,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
app.ui.cmdPrefix = ":"
|
||||
return
|
||||
}
|
||||
cmd := app.cmdHistory[len(app.cmdHistory)-app.cmdHistoryInd]
|
||||
@@ -1022,10 +1204,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
||||
if app.cmd != nil {
|
||||
app.cmd.Process.Kill()
|
||||
}
|
||||
app.ui.menuBuf = nil
|
||||
app.ui.cmdAccLeft = nil
|
||||
app.ui.cmdAccRight = nil
|
||||
app.ui.cmdPrefix = ""
|
||||
normal(app)
|
||||
case "cmd-word":
|
||||
if len(app.ui.cmdAccRight) == 0 {
|
||||
return
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module github.com/gokcehan/lf
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
|
||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb h1:YahEjAGkJtCrkqgVHhX6n8ZX+CZ3hDRL9fjLYugLfSs=
|
||||
github.com/nsf/termbox-go v0.0.0-20180613055208-5c94acc5e6eb/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e h1:Vbib8wJAaMEF9jusI/kMSYMr/LtRzM7+F9MJgt/nH8k=
|
||||
github.com/nsf/termbox-go v0.0.0-20190325093121-288510b9734e/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
@@ -0,0 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type iconMap map[string]string
|
||||
|
||||
func parseIcons() iconMap {
|
||||
if env := os.Getenv("LF_ICONS"); env != "" {
|
||||
return parseIconsEnv(env)
|
||||
}
|
||||
|
||||
defaultIcons := []string{
|
||||
"di=🗀",
|
||||
"fi=🗎",
|
||||
}
|
||||
|
||||
return parseIconsEnv(strings.Join(defaultIcons, ":"))
|
||||
}
|
||||
|
||||
func parseIconsEnv(env string) iconMap {
|
||||
icons := make(iconMap)
|
||||
|
||||
entries := strings.Split(env, ":")
|
||||
for _, entry := range entries {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
pair := strings.Split(entry, "=")
|
||||
if len(pair) != 2 {
|
||||
log.Printf("invalid $LF_ICONS entry: %s", entry)
|
||||
return icons
|
||||
}
|
||||
key, val := pair[0], pair[1]
|
||||
icons[key] = val
|
||||
}
|
||||
|
||||
return icons
|
||||
}
|
||||
|
||||
func (im iconMap) get(f *file) string {
|
||||
var key string
|
||||
|
||||
switch {
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0 && f.Mode()&0002 != 0:
|
||||
key = "tw"
|
||||
case f.IsDir() && f.Mode()&os.ModeSticky != 0:
|
||||
key = "st"
|
||||
case f.IsDir() && f.Mode()&0002 != 0:
|
||||
key = "ow"
|
||||
case f.IsDir():
|
||||
key = "di"
|
||||
case f.linkState == working:
|
||||
key = "ln"
|
||||
case f.linkState == broken:
|
||||
key = "or"
|
||||
case f.Mode()&os.ModeNamedPipe != 0:
|
||||
key = "pi"
|
||||
case f.Mode()&os.ModeSocket != 0:
|
||||
key = "so"
|
||||
case f.Mode()&os.ModeCharDevice != 0:
|
||||
key = "cd"
|
||||
case f.Mode()&os.ModeDevice != 0:
|
||||
key = "bd"
|
||||
case f.Mode()&os.ModeSetuid != 0:
|
||||
key = "su"
|
||||
case f.Mode()&os.ModeSetgid != 0:
|
||||
key = "sg"
|
||||
case f.Mode().IsRegular() && f.Mode()&0111 != 0:
|
||||
key = "ex"
|
||||
default:
|
||||
key = "*" + filepath.Ext(f.Name())
|
||||
}
|
||||
|
||||
if val, ok := im[key]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
if val, ok := im["fi"]; ok {
|
||||
return val
|
||||
}
|
||||
|
||||
return " "
|
||||
}
|
||||
@@ -47,6 +47,7 @@ The following commands are provided by lf with default keybindings:
|
||||
redraw (default '<c-l>')
|
||||
reload (default '<c-r>')
|
||||
read (default ':')
|
||||
rename (default 'r')
|
||||
shell (default '$')
|
||||
shell-pipe (default '%')
|
||||
shell-wait (default '!')
|
||||
@@ -61,6 +62,7 @@ The following commands are provided by lf with default keybindings:
|
||||
search-prev (default 'N')
|
||||
mark-save (default 'm')
|
||||
mark-load (default "'")
|
||||
mark-remove (default `"`)
|
||||
.EE
|
||||
.PP
|
||||
The following commands are provided by lf without default keybindings:
|
||||
@@ -74,6 +76,8 @@ The following commands are provided by lf without default keybindings:
|
||||
echoerr same as echomsg but red color
|
||||
cd change working directory to the argument
|
||||
select change current file selection to the argument
|
||||
glob-select select files that match the given glob
|
||||
glob-unselect unselect files that match the given glob
|
||||
source read the configuration file in the argument
|
||||
push simulate key pushes given in the argument
|
||||
delete remove the current file or selected file(s)
|
||||
@@ -117,6 +121,7 @@ The following options can be used to customize the behavior of lf:
|
||||
dirfirst boolean (default on)
|
||||
drawbox boolean (default off)
|
||||
globsearch boolean (default off)
|
||||
icons boolean (default off)
|
||||
hidden boolean (default off)
|
||||
ignorecase boolean (default on)
|
||||
ignoredia boolean (default off)
|
||||
@@ -126,12 +131,14 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase boolean (default on)
|
||||
smartdia boolean (default off)
|
||||
wrapscan boolean (default on)
|
||||
wrapscroll boolean (default off)
|
||||
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)
|
||||
tabstop integer (default 8)
|
||||
errorfmt string (default "\e033[7;31;47m%s\e033[0m")
|
||||
filesep string (default "\en")
|
||||
ifs string (default ”) (not exported if empty)
|
||||
previewer string (default ”) (not filtered if empty)
|
||||
@@ -242,11 +249,9 @@ The following command prefixes are used by lf:
|
||||
% shell-pipe shell command running with the ui
|
||||
! shell-wait shell command waiting for key press
|
||||
& shell-async shell command running asynchronously
|
||||
/ search search file in current directory
|
||||
? search-back search file in the reverse order
|
||||
.EE
|
||||
.PP
|
||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default. Searching commands are only used from the command line.
|
||||
The same evaluator is used for the command line and the configuration file for read and shell commands. The difference is that prefixes are not necessary in the command line. Instead, different modes are provided to read corresponding commands. These modes are mapped to the prefix keys above by default.
|
||||
.SH SYNTAX
|
||||
Characters from '#' to newline are comments and ignored:
|
||||
.PP
|
||||
@@ -532,7 +537,7 @@ Lastly, there is a 'conn' command to connect the server as a client. This should
|
||||
.SH FILE OPERATIONS
|
||||
lf uses its own builtin copy and move operations by default. These are implemented as asynchronous operations and progress is shown in the bottom ruler. These commands do not overwrite existing files or directories with the same name. Instead, a suffix that is compatible with '--backup=numbered' option in GNU cp is added to the new files or directories. Only file modes are preserved and all other attributes are ignored including ownership, timestamps, context, links, and xattr. Special files such as character and block devices, named pipes, and sockets are skipped and links are followed. Moving is performed using the rename operation of the underlying OS. This can fail to move files between different partitions when it needs to copy files. For these cases, users are expected to explicitly copy files and then delete the old ones manually. Operation errors are shown in the message line as well as the log file and they do not preemptively finish the corresponding file operation.
|
||||
.PP
|
||||
File operations can be performed on the current selected file or alternatively on multiple files by marking them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
|
||||
File operations can be performed on the current selected file or alternatively on multiple files by selecting them first. When you 'copy' a file, lf doesn't actually copy the file on the disk, but only records its name to memory. The actual file copying takes place when you 'paste'. Similarly 'paste' after a 'cut' operation moves the file.
|
||||
.PP
|
||||
You can customize copy and move operations by defining a 'paste' command. This is a special command that is called when it is defined instead of the builtin implementation. You can use the following example as a starting point:
|
||||
.PP
|
||||
@@ -557,7 +562,14 @@ By default, lf does not assign 'delete' command to a key to protect new users. Y
|
||||
.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.
|
||||
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. Possible candidates are 'up', 'down' and their variants, 'updir', and 'open' commands. For example, you can use arrow keys to finish the search with the following mappings:
|
||||
.PP
|
||||
.EX
|
||||
cmap <up> up
|
||||
cmap <down> down
|
||||
cmap <left> updir
|
||||
cmap <right> open
|
||||
.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
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,6 +43,24 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func exportEnvVars() {
|
||||
os.Setenv("id", strconv.Itoa(gClientID))
|
||||
|
||||
os.Setenv("OPENER", envOpener)
|
||||
os.Setenv("EDITOR", envEditor)
|
||||
os.Setenv("PAGER", envPager)
|
||||
os.Setenv("SHELL", envShell)
|
||||
|
||||
level, err := strconv.Atoi(envLevel)
|
||||
if err != nil {
|
||||
log.Printf("reading lf level: %s", err)
|
||||
}
|
||||
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
}
|
||||
|
||||
func startServer() {
|
||||
cmd := detachedCommand(os.Args[0], "-server")
|
||||
if err := cmd.Start(); err != nil {
|
||||
@@ -162,6 +181,8 @@ func main() {
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
exportEnvVars()
|
||||
|
||||
run()
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ type dir struct {
|
||||
files []*file // displayed files in directory including or excluding hidden ones
|
||||
allFiles []*file // all files in directory including hidden ones (same array as files)
|
||||
sortType sortType // sort method and options from last sort
|
||||
noPerm bool // whether lf has no permission to open the directory
|
||||
}
|
||||
|
||||
func newDir(path string) *dir {
|
||||
@@ -97,6 +98,7 @@ func newDir(path string) *dir {
|
||||
path: path,
|
||||
files: files,
|
||||
allFiles: files,
|
||||
noPerm: os.IsPermission(err),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,13 +146,13 @@ func (dir *dir) sort() {
|
||||
// files to the first non-hidden file in the list
|
||||
if gOpts.sortType.option&hiddenSort == 0 {
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if dir.files[i].Name()[0] == '.' && dir.files[j].Name()[0] == '.' {
|
||||
if isHidden(dir.files[i]) && isHidden(dir.files[j]) {
|
||||
return i < j
|
||||
}
|
||||
return dir.files[i].Name()[0] == '.'
|
||||
return isHidden(dir.files[i])
|
||||
})
|
||||
for i, f := range dir.files {
|
||||
if f.Name()[0] != '.' {
|
||||
if !isHidden(f) {
|
||||
dir.files = dir.files[i:]
|
||||
return
|
||||
}
|
||||
@@ -205,6 +207,7 @@ type nav struct {
|
||||
regCache map[string]*reg
|
||||
saves map[string]bool
|
||||
marks map[string]string
|
||||
renameCache []string
|
||||
selections map[string]int
|
||||
selectionInd int
|
||||
height int
|
||||
@@ -291,6 +294,7 @@ func newNav(height int) *nav {
|
||||
regCache: make(map[string]*reg),
|
||||
saves: make(map[string]bool),
|
||||
marks: make(map[string]string),
|
||||
renameCache: make([]string, 2),
|
||||
selections: make(map[string]int),
|
||||
selectionInd: 0,
|
||||
height: height,
|
||||
@@ -445,6 +449,9 @@ func (nav *nav) up(dist int) {
|
||||
dir := nav.currDir()
|
||||
|
||||
if dir.ind == 0 {
|
||||
if gOpts.wrapscroll {
|
||||
nav.bottom()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -462,6 +469,9 @@ func (nav *nav) down(dist int) {
|
||||
maxind := len(dir.files) - 1
|
||||
|
||||
if dir.ind >= maxind {
|
||||
if gOpts.wrapscroll {
|
||||
nav.top()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -730,6 +740,30 @@ func (nav *nav) del() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) rename(ui *ui) error {
|
||||
oldPath := nav.renameCache[0]
|
||||
newPath := nav.renameCache[1]
|
||||
dir, _ := filepath.Split(newPath)
|
||||
os.MkdirAll(dir, os.ModePerm)
|
||||
|
||||
if _, err := os.Stat(newPath); err == nil { // file exists
|
||||
if err := os.Remove(newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Rename(oldPath, newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: change selection
|
||||
if err := nav.sel(newPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) sync() error {
|
||||
list, cp, err := loadFiles()
|
||||
if err != nil {
|
||||
@@ -741,7 +775,7 @@ func (nav *nav) sync() error {
|
||||
nav.saves[f] = cp
|
||||
}
|
||||
|
||||
return nil
|
||||
return nav.readMarks()
|
||||
}
|
||||
|
||||
func (nav *nav) cd(wd string) error {
|
||||
@@ -762,6 +796,9 @@ func (nav *nav) cd(wd string) error {
|
||||
}
|
||||
|
||||
func (nav *nav) sel(path string) error {
|
||||
path = strings.Replace(path, "~", gUser.HomeDir, -1)
|
||||
path = filepath.Clean(path)
|
||||
|
||||
lstat, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("select: %s", err)
|
||||
@@ -785,6 +822,30 @@ func (nav *nav) sel(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) globSel(pattern string, invert bool) error {
|
||||
curDir := nav.currDir()
|
||||
anyMatches := false
|
||||
|
||||
for i := 0; i < len(curDir.files); i++ {
|
||||
match, err := filepath.Match(pattern, curDir.files[i].Name())
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("glob-select: %s", err)
|
||||
}
|
||||
if match {
|
||||
anyMatches = true
|
||||
fpath := filepath.Join(curDir.path, curDir.files[i].Name())
|
||||
if _, ok := nav.selections[fpath]; ok == invert {
|
||||
nav.toggleSelection(fpath)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !anyMatches {
|
||||
return fmt.Errorf("glob-select: pattern not found: %s", pattern)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func findMatch(name, pattern string) bool {
|
||||
if gOpts.ignorecase {
|
||||
lpattern := strings.ToLower(pattern)
|
||||
@@ -942,7 +1003,17 @@ func (nav *nav) searchPrev() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nav *nav) removeMark(mark string) error {
|
||||
if _, ok := nav.marks[mark]; ok {
|
||||
delete(nav.marks, mark)
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("no such mark")
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) readMarks() error {
|
||||
nav.marks = make(map[string]string)
|
||||
f, err := os.Open(gMarksPath)
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@@ -968,14 +1039,6 @@ func (nav *nav) readMarks() error {
|
||||
}
|
||||
|
||||
func (nav *nav) writeMarks() error {
|
||||
if len(nav.marks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := nav.readMarks(); err != nil {
|
||||
return fmt.Errorf("reading marks file: %s", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(gMarksPath), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating data directory: %s", err)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ var gOpts struct {
|
||||
dircounts bool
|
||||
drawbox bool
|
||||
globsearch bool
|
||||
icons bool
|
||||
ignorecase bool
|
||||
incsearch bool
|
||||
preview bool
|
||||
@@ -37,12 +38,14 @@ var gOpts struct {
|
||||
ignoredia bool
|
||||
smartdia bool
|
||||
wrapscan bool
|
||||
wrapscroll bool
|
||||
number bool
|
||||
relativenumber bool
|
||||
findlen int
|
||||
period int
|
||||
scrolloff int
|
||||
tabstop int
|
||||
errorfmt string
|
||||
filesep string
|
||||
ifs string
|
||||
previewer string
|
||||
@@ -64,6 +67,7 @@ func init() {
|
||||
gOpts.dircounts = false
|
||||
gOpts.drawbox = false
|
||||
gOpts.globsearch = false
|
||||
gOpts.icons = false
|
||||
gOpts.ignorecase = true
|
||||
gOpts.incsearch = false
|
||||
gOpts.preview = true
|
||||
@@ -71,11 +75,17 @@ func init() {
|
||||
gOpts.ignoredia = false
|
||||
gOpts.smartdia = false
|
||||
gOpts.wrapscan = true
|
||||
gOpts.wrapscroll = false
|
||||
gOpts.number = false
|
||||
gOpts.relativenumber = false
|
||||
gOpts.findlen = 1
|
||||
gOpts.period = 0
|
||||
gOpts.scrolloff = 0
|
||||
gOpts.tabstop = 8
|
||||
gOpts.errorfmt = "\033[7;31;47m%s\033[0m"
|
||||
gOpts.filesep = "\n"
|
||||
gOpts.ifs = ""
|
||||
gOpts.previewer = ""
|
||||
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.timefmt = time.ANSIC
|
||||
@@ -129,6 +139,8 @@ func init() {
|
||||
gOpts.keys["N"] = &callExpr{"search-prev", nil, 1}
|
||||
gOpts.keys["m"] = &callExpr{"mark-save", nil, 1}
|
||||
gOpts.keys["'"] = &callExpr{"mark-load", nil, 1}
|
||||
gOpts.keys[`"`] = &callExpr{"mark-remove", nil, 1}
|
||||
gOpts.keys[`r`] = &callExpr{"rename", nil, 1}
|
||||
gOpts.keys["<c-n>"] = &callExpr{"cmd-history-next", nil, 1}
|
||||
gOpts.keys["<c-p>"] = &callExpr{"cmd-history-prev", nil, 1}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -131,3 +132,21 @@ func moveCursor(y, x int) {
|
||||
func isExecutable(f os.FileInfo) bool {
|
||||
return f.Mode()&0111 != 0
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo) bool {
|
||||
return f.Name()[0] == '.'
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := f
|
||||
envFiles := strings.Join(fs, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
+26
-1
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -36,7 +37,7 @@ var (
|
||||
|
||||
func init() {
|
||||
if envOpener == "" {
|
||||
envOpener = "start"
|
||||
envOpener = `start ""`
|
||||
}
|
||||
|
||||
if envEditor == "" {
|
||||
@@ -114,3 +115,27 @@ func isExecutable(f os.FileInfo) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isHidden(f os.FileInfo) bool {
|
||||
// TODO: implement
|
||||
return false
|
||||
}
|
||||
|
||||
func exportFiles(f string, fs []string) {
|
||||
envFile := fmt.Sprintf(`"%s"`, f)
|
||||
|
||||
var quotedFiles []string
|
||||
for _, f := range fs {
|
||||
quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f))
|
||||
}
|
||||
envFiles := strings.Join(quotedFiles, gOpts.filesep)
|
||||
|
||||
os.Setenv("f", envFile)
|
||||
os.Setenv("fs", envFiles)
|
||||
|
||||
if len(fs) == 0 {
|
||||
os.Setenv("fx", envFile)
|
||||
} else {
|
||||
os.Setenv("fx", envFiles)
|
||||
}
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func fileInfo(f *file, d *dir) string {
|
||||
return info
|
||||
}
|
||||
|
||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap) {
|
||||
func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]bool, colors colorMap, icons iconMap) {
|
||||
if win.w < 5 || dir == nil {
|
||||
return
|
||||
}
|
||||
@@ -251,6 +251,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
return
|
||||
}
|
||||
|
||||
if dir.noPerm {
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "permission denied")
|
||||
return
|
||||
}
|
||||
|
||||
if len(dir.files) == 0 {
|
||||
win.print(2, 0, termbox.AttrReverse, termbox.ColorDefault, "empty")
|
||||
return
|
||||
@@ -313,6 +318,11 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b
|
||||
|
||||
s = append(s, ' ')
|
||||
|
||||
if gOpts.icons {
|
||||
s = append(s, []rune(icons.get(f))...)
|
||||
s = append(s, ' ')
|
||||
}
|
||||
|
||||
for _, r := range f.Name() {
|
||||
s = append(s, r)
|
||||
}
|
||||
@@ -367,6 +377,7 @@ type ui struct {
|
||||
keyAcc []rune
|
||||
keyCount []rune
|
||||
colors colorMap
|
||||
icons iconMap
|
||||
}
|
||||
|
||||
func getWidths(wtot int) []int {
|
||||
@@ -448,6 +459,7 @@ func newUI() *ui {
|
||||
keyChan: make(chan string, 1000),
|
||||
evChan: evChan,
|
||||
colors: parseColors(),
|
||||
icons: parseIcons(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,7 +511,7 @@ func (ui *ui) echomsgf(format string, a ...interface{}) {
|
||||
}
|
||||
|
||||
func (ui *ui) echoerr(msg string) {
|
||||
ui.msg = fmt.Sprintf("\033[7;31;47m%s\033[0m", msg)
|
||||
ui.msg = fmt.Sprintf(gOpts.errorfmt, msg)
|
||||
log.Printf("error: %s", msg)
|
||||
}
|
||||
|
||||
@@ -653,7 +665,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
|
||||
doff := len(nav.dirs) - length
|
||||
for i := 0; i < length; i++ {
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors)
|
||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.selections, nav.saves, ui.colors, ui.icons)
|
||||
}
|
||||
|
||||
switch ui.cmdPrefix {
|
||||
@@ -679,7 +691,7 @@ func (ui *ui) draw(nav *nav) {
|
||||
preview := ui.wins[len(ui.wins)-1]
|
||||
|
||||
if f.IsDir() {
|
||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors)
|
||||
preview.printDir(ui.dirPrev, nav.selections, nav.saves, ui.colors, ui.icons)
|
||||
} else if f.Mode().IsRegular() {
|
||||
preview.printReg(ui.regPrev)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user