Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
184762d83a | ||
|
|
27f104b3e6 | ||
|
|
35930924a7 | ||
|
|
4a1388a5c7 | ||
|
|
92e994ebf6 | ||
|
|
245db502cc | ||
|
|
ca95bcf1d8 | ||
|
|
dd6a85f480 | ||
|
|
db8f535b61 | ||
|
|
52be0b3aab | ||
|
|
bd889a9e06 | ||
|
|
951529ebc0 | ||
|
|
0fc14e3b2d |
No files matched your search
@@ -136,6 +136,30 @@ func (app *app) loop() {
|
|||||||
clientChan := app.ui.readExpr()
|
clientChan := app.ui.readExpr()
|
||||||
serverChan := readExpr()
|
serverChan := readExpr()
|
||||||
|
|
||||||
|
if gSelect != "" {
|
||||||
|
go func() {
|
||||||
|
app.ui.exprChan <- &callExpr{"select", []string{gSelect}, 1}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range gConfigPaths {
|
||||||
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
app.readFile(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if gCommand != "" {
|
||||||
|
p := newParser(strings.NewReader(gCommand))
|
||||||
|
|
||||||
|
for p.parse() {
|
||||||
|
p.expr.eval(app, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.err != nil {
|
||||||
|
app.ui.printf("%s", p.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-app.quitChan:
|
case <-app.quitChan:
|
||||||
@@ -328,12 +352,12 @@ func (app *app) runShell(s string, args []string, prefix string) {
|
|||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "%":
|
case "%":
|
||||||
go func() {
|
app.cmd = cmd
|
||||||
app.cmd = cmd
|
app.cmdOutBuf = nil
|
||||||
app.cmdOutBuf = nil
|
app.ui.msg = ""
|
||||||
app.ui.msg = ""
|
app.ui.cmdPrefix = ">"
|
||||||
app.ui.cmdPrefix = ">"
|
|
||||||
|
|
||||||
|
go func() {
|
||||||
reader := bufio.NewReader(out)
|
reader := bufio.NewReader(out)
|
||||||
for {
|
for {
|
||||||
b, err := reader.ReadByte()
|
b, err := reader.ReadByte()
|
||||||
|
|||||||
@@ -33,12 +33,6 @@ func run() {
|
|||||||
|
|
||||||
app := newApp()
|
app := newApp()
|
||||||
|
|
||||||
for _, path := range gConfigPaths {
|
|
||||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
|
||||||
app.readFile(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.nav.readMarks(); err != nil {
|
if err := app.nav.readMarks(); err != nil {
|
||||||
app.ui.printf("reading marks file: %s", err)
|
app.ui.printf("reading marks file: %s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,25 +51,25 @@ func parseColors() colorMap {
|
|||||||
return parseColorsBSD(env)
|
return parseColorsBSD(env)
|
||||||
}
|
}
|
||||||
|
|
||||||
// default values from dircolors
|
// default values from dircolors with removed background colors
|
||||||
defaultColors := []string{
|
defaultColors := []string{
|
||||||
// "rs=0",
|
// "rs=0",
|
||||||
"di=01;34",
|
"di=01;34",
|
||||||
"ln=01;36",
|
"ln=01;36",
|
||||||
// "mh=00",
|
// "mh=00",
|
||||||
"pi=40;33",
|
"pi=33", // "pi=40;33",
|
||||||
"so=01;35",
|
"so=01;35",
|
||||||
"do=01;35",
|
"do=01;35",
|
||||||
"bd=40;33;01",
|
"bd=33;01", // "bd=40;33;01",
|
||||||
"cd=40;33;01",
|
"cd=33;01", // "cd=40;33;01",
|
||||||
"or=40;31;01",
|
"or=31;01", // "or=40;31;01",
|
||||||
// "mi=00",
|
// "mi=00",
|
||||||
"su=37;41",
|
"su=01;32", // "su=37;41",
|
||||||
"sg=30;43",
|
"sg=01;32", // "sg=30;43",
|
||||||
"ca=30;41",
|
// "ca=30;41",
|
||||||
"tw=30;42",
|
"tw=01;34", // "tw=30;42",
|
||||||
"ow=34;42",
|
"ow=01;34", // "ow=34;42",
|
||||||
"st=37;44",
|
"st=01;34", // "st=37;44",
|
||||||
"ex=01;32",
|
"ex=01;32",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -565,13 +565,7 @@ Globbing supports '*' to match any sequence, '?' to match any character, and
|
|||||||
'[...]' or '[^...] to match character sets or ranges. You can enable
|
'[...]' or '[^...] to match character sets or ranges. You can enable
|
||||||
'incsearch' option to jump to the current match at each keystroke while typing.
|
'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
|
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
|
'cmd-escape' to cancel the search.
|
||||||
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'),
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
|||||||
+1
-7
@@ -589,13 +589,7 @@ pattern. Globbing supports '*' to match any sequence, '?' to match any
|
|||||||
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
character, and '[...]' or '[^...] to match character sets or ranges. You can
|
||||||
enable 'incsearch' option to jump to the current match at each keystroke
|
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
|
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
|
search or use 'cmd-escape' to cancel the search.
|
||||||
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'),
|
Finding mechanism is implemented with commands 'find' (default 'f'),
|
||||||
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
'find-back' (default 'F'), 'find-next' (default ';'), 'find-prev' (default
|
||||||
|
|||||||
@@ -431,6 +431,22 @@ func insert(app *app, arg string) {
|
|||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
case app.ui.cmdPrefix == "delete?[y/N]: ":
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
|
||||||
|
if arg == "y" {
|
||||||
|
if err := app.nav.del(); 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 app.ui.cmdPrefix == "mark-save: ":
|
case app.ui.cmdPrefix == "mark-save: ":
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
@@ -475,12 +491,6 @@ func insert(app *app, arg string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -542,11 +552,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
defer out.Close()
|
defer out.Close()
|
||||||
|
|
||||||
var path string
|
var path string
|
||||||
if len(app.nav.selections) != 0 {
|
if list, err := app.nav.currFileOrSelections(); err == nil {
|
||||||
selections := app.nav.currSelections()
|
path = strings.Join(list, "\n")
|
||||||
path = strings.Join(selections, "\n")
|
|
||||||
} else if curr, err := app.nav.currFile(); err == nil {
|
|
||||||
path = curr.path
|
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -618,13 +625,16 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
case "delete":
|
case "delete":
|
||||||
if cmd, ok := gOpts.cmds["delete"]; ok {
|
if cmd, ok := gOpts.cmds["delete"]; ok {
|
||||||
cmd.eval(app, e.args)
|
cmd.eval(app, e.args)
|
||||||
} else if err := app.nav.deleteFiles(); err != nil {
|
app.nav.unselect()
|
||||||
app.ui.printf("delete: %s", err)
|
if err := sendRemote("send load"); err != nil {
|
||||||
return
|
app.ui.printf("delete: %s", err)
|
||||||
}
|
}
|
||||||
app.nav.unselect()
|
} else {
|
||||||
if err := sendRemote("send load"); err != nil {
|
if _, err := app.nav.currFileOrSelections(); err != nil {
|
||||||
app.ui.printf("delete: %s", err)
|
app.ui.printf("delete: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.cmdPrefix = "delete?[y/N]: "
|
||||||
}
|
}
|
||||||
case "clear":
|
case "clear":
|
||||||
if err := saveFiles(nil, false); err != nil {
|
if err := saveFiles(nil, false); err != nil {
|
||||||
@@ -853,6 +863,8 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
switch app.ui.cmdPrefix {
|
switch app.ui.cmdPrefix {
|
||||||
case ":":
|
case ":":
|
||||||
log.Printf("command: %s", s)
|
log.Printf("command: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{":", s})
|
||||||
p := newParser(strings.NewReader(s))
|
p := newParser(strings.NewReader(s))
|
||||||
for p.parse() {
|
for p.parse() {
|
||||||
p.expr.eval(app, nil)
|
p.expr.eval(app, nil)
|
||||||
@@ -860,30 +872,28 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if p.err != nil {
|
if p.err != nil {
|
||||||
app.ui.printf("%s", p.err)
|
app.ui.printf("%s", p.err)
|
||||||
}
|
}
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s", s)
|
log.Printf("shell: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"$", s})
|
||||||
|
app.runShell(s, nil, "$")
|
||||||
case "%":
|
case "%":
|
||||||
log.Printf("shell-pipe: %s", s)
|
log.Printf("shell-pipe: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"%", s})
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
app.runShell(s, nil, "%")
|
||||||
case ">":
|
case ">":
|
||||||
io.WriteString(app.cmdIn, s+"\n")
|
io.WriteString(app.cmdIn, s+"\n")
|
||||||
app.cmdOutBuf = nil
|
app.cmdOutBuf = nil
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s", s)
|
log.Printf("shell-wait: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"!", s})
|
||||||
|
app.runShell(s, nil, "!")
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s", s)
|
log.Printf("shell-async: %s", s)
|
||||||
app.runShell(s, nil, app.ui.cmdPrefix)
|
|
||||||
app.cmdHistory = append(app.cmdHistory, cmdItem{app.ui.cmdPrefix, s})
|
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
|
app.cmdHistory = append(app.cmdHistory, cmdItem{"&", s})
|
||||||
|
app.runShell(s, nil, "&")
|
||||||
case "/":
|
case "/":
|
||||||
if gOpts.incsearch {
|
if gOpts.incsearch {
|
||||||
last := app.nav.currDir()
|
last := app.nav.currDir()
|
||||||
@@ -891,6 +901,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
last.pos = app.nav.searchPos
|
last.pos = app.nav.searchPos
|
||||||
}
|
}
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
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)
|
||||||
@@ -898,7 +909,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
case "?":
|
case "?":
|
||||||
if gOpts.incsearch {
|
if gOpts.incsearch {
|
||||||
last := app.nav.currDir()
|
last := app.nav.currDir()
|
||||||
@@ -906,6 +916,7 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
last.pos = app.nav.searchPos
|
last.pos = app.nav.searchPos
|
||||||
}
|
}
|
||||||
log.Printf("search-back: %s", s)
|
log.Printf("search-back: %s", s)
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
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-back: %s: %s", err, app.nav.search)
|
app.ui.printf("search-back: %s: %s", err, app.nav.search)
|
||||||
@@ -913,7 +924,6 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
}
|
}
|
||||||
app.ui.cmdPrefix = ""
|
|
||||||
default:
|
default:
|
||||||
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
log.Printf("entering unknown execution prefix: %q", app.ui.cmdPrefix)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -553,12 +553,7 @@ By default, lf does not assign 'delete' command to a key to protect new users. Y
|
|||||||
.SH SEARCHING FILES
|
.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.
|
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
|
.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:
|
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.
|
||||||
.PP
|
|
||||||
.EX
|
|
||||||
cmap <up> up
|
|
||||||
cmap <down> down
|
|
||||||
.EE
|
|
||||||
.PP
|
.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.
|
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
|
.PP
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ var (
|
|||||||
gSocketPath string
|
gSocketPath string
|
||||||
gLogPath string
|
gLogPath string
|
||||||
gServerLogPath string
|
gServerLogPath string
|
||||||
|
gSelect string
|
||||||
|
gCommand string
|
||||||
gVersion string
|
gVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -103,6 +105,11 @@ func main() {
|
|||||||
"",
|
"",
|
||||||
"path to the file to write selected files on open (to use as open file dialog)")
|
"path to the file to write selected files on open (to use as open file dialog)")
|
||||||
|
|
||||||
|
flag.StringVar(&gCommand,
|
||||||
|
"command",
|
||||||
|
"",
|
||||||
|
"command to execute on client initialization")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
gSocketProt = gDefaultSocketProt
|
gSocketProt = gDefaultSocketProt
|
||||||
@@ -149,13 +156,9 @@ func main() {
|
|||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
dir := flag.Arg(0)
|
gSelect = flag.Arg(0)
|
||||||
if err := os.Chdir(dir); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "only single directory is allowed\n")
|
fmt.Fprintf(os.Stderr, "only single file or directory is allowed\n")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -550,46 +550,19 @@ func (nav *nav) unselect() {
|
|||||||
nav.selectionInd = 0
|
nav.selectionInd = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// effectiveSelection is a pure function that returns the selected files's paths.
|
func (nav *nav) save(cp bool) error {
|
||||||
// In case the user has not selected a file it returns the file on the user's cursor.
|
list, err := nav.currFileOrSelections()
|
||||||
// If the function can't return a selection it returns an error.
|
if err != nil {
|
||||||
func (nav *nav) effectiveSelection() (list []string, err error) {
|
return err
|
||||||
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
|
if err := saveFiles(list, cp); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (nav *nav) save(cp bool) error {
|
nav.saves = make(map[string]bool)
|
||||||
if len(nav.selections) == 0 {
|
for _, f := range list {
|
||||||
curr, err := nav.currFile()
|
nav.saves[f] = cp
|
||||||
if err != nil {
|
|
||||||
return errors.New("no file selected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := saveFiles([]string{curr.path}, cp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
|
||||||
nav.saves[curr.path] = cp
|
|
||||||
} else {
|
|
||||||
selections := nav.currSelections()
|
|
||||||
|
|
||||||
if err := saveFiles(selections, cp); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.saves = make(map[string]bool)
|
|
||||||
for f := range nav.selections {
|
|
||||||
nav.saves[f] = cp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -620,10 +593,8 @@ func (nav *nav) paste() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteFiles deletes the user's selected files
|
func (nav *nav) del() error {
|
||||||
// it returns an error if no files are selected or if the OS fails to delete a file
|
list, err := nav.currFileOrSelections()
|
||||||
func (nav *nav) deleteFiles() error {
|
|
||||||
list, err := nav.effectiveSelection()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -850,19 +821,6 @@ func (nav *nav) searchPrev() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nav *nav) currDir() *dir {
|
|
||||||
return nav.dirs[len(nav.dirs)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) currFile() (*file, error) {
|
|
||||||
last := nav.dirs[len(nav.dirs)-1]
|
|
||||||
|
|
||||||
if len(last.files) == 0 {
|
|
||||||
return nil, fmt.Errorf("empty directory")
|
|
||||||
}
|
|
||||||
return last.files[last.ind], nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (nav *nav) readMarks() error {
|
func (nav *nav) readMarks() error {
|
||||||
f, err := os.Open(gMarksPath)
|
f, err := os.Open(gMarksPath)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@@ -923,6 +881,19 @@ func (nav *nav) writeMarks() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currDir() *dir {
|
||||||
|
return nav.dirs[len(nav.dirs)-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currFile() (*file, error) {
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
|
||||||
|
if len(last.files) == 0 {
|
||||||
|
return nil, fmt.Errorf("empty directory")
|
||||||
|
}
|
||||||
|
return last.files[last.ind], nil
|
||||||
|
}
|
||||||
|
|
||||||
type indexedSelections struct {
|
type indexedSelections struct {
|
||||||
paths []string
|
paths []string
|
||||||
indices []int
|
indices []int
|
||||||
@@ -947,3 +918,16 @@ func (nav *nav) currSelections() []string {
|
|||||||
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
sort.Sort(indexedSelections{paths: paths, indices: indices})
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) currFileOrSelections() (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
|
||||||
|
}
|
||||||
Reference in new issue
Block a user