rename yank-delete-put to copy-cut-paste

This commit is contained in:
Gokcehan committed 2018-06-27 21:17:56 +03:00
1 parent b67b042d43
commit d987c9e439
11 files changed
+63 -69

No files matched your search

+5 -5
View File
@@ -68,7 +68,7 @@ func readExpr() <-chan expr {
return ch
}
func saveFiles(list []string, copy bool) error {
func saveFiles(list []string, cp bool) error {
c, err := net.Dial(gSocketProt, gSocketPath)
if err != nil {
return fmt.Errorf("dialing to save files: %s", err)
@@ -79,7 +79,7 @@ func saveFiles(list []string, copy bool) error {
fmt.Fprintln(c, "save")
if copy {
if cp {
fmt.Fprintln(c, "copy")
} else {
fmt.Fprintln(c, "move")
@@ -93,7 +93,7 @@ func saveFiles(list []string, copy bool) error {
return nil
}
func loadFiles() (list []string, copy bool, err error) {
func loadFiles() (list []string, cp bool, err error) {
c, e := net.Dial(gSocketProt, gSocketPath)
if e != nil {
err = fmt.Errorf("dialing to load files: %s", e)
@@ -109,9 +109,9 @@ func loadFiles() (list []string, copy bool, err error) {
switch s.Text() {
case "copy":
copy = true
cp = true
case "move":
copy = false
cp = false
default:
err = fmt.Errorf("unexpected option to copy file(s): %s", s.Text())
return
+3 -3
View File
@@ -28,9 +28,9 @@ var (
"toggle",
"invert",
"unmark",
"yank",
"delete",
"put",
"copy",
"cut",
"paste",
"clear",
"draw",
"redraw",
+10 -13
View File
@@ -26,9 +26,9 @@ The following commands are provided by lf with default keybindings:
toggle (default '<space>')
invert (default 'v')
unmark (default 'u')
yank (default 'y')
delete (default 'd')
put (default 'p')
copy (default 'y')
cut (default 'd')
paste (default 'p')
clear (default 'c')
redraw (default '<c-l>')
reload (default '<c-r>')
@@ -46,7 +46,7 @@ The following commands are provided by lf without default keybindings:
draw draw the ui
load load modified files and directories
sync synchronizes yanked/deleted files with server
sync synchronizes copied/cut files with server
echo prints its arguments to the message line
cd changes working directory to its argument
select changes current file selection to its argument
@@ -463,19 +463,16 @@ should not be needed for users.
File Operations
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
this purpose, when you 'yank' (i.e. 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 do the 'put' in which case the 'cp' command is
used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and 'put')
are picked instead of the other common convention (e.g. copy and cut) to
resemble the default keybinds for these operations.
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'.
You can customize these operations by defining a 'put' command. This is a
You can customize these operations by defining a 'paste' command. This is a
special command that is called when it is defined instead of the builtin
implementation. The default behavior is similar to the following command:
cmd put ${{
cmd paste ${{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
+10 -13
View File
@@ -30,9 +30,9 @@ The following commands are provided by lf with default keybindings:
toggle (default '<space>')
invert (default 'v')
unmark (default 'u')
yank (default 'y')
delete (default 'd')
put (default 'p')
copy (default 'y')
cut (default 'd')
paste (default 'p')
clear (default 'c')
redraw (default '<c-l>')
reload (default '<c-r>')
@@ -50,7 +50,7 @@ The following commands are provided by lf without default keybindings:
draw draw the ui
load load modified files and directories
sync synchronizes yanked/deleted files with server
sync synchronizes copied/cut files with server
echo prints its arguments to the message line
cd changes working directory to its argument
select changes current file selection to its argument
@@ -487,19 +487,16 @@ should not be needed for users.
File Operations
lf uses the underlying 'cp' and 'mv' shell commands for file operations. For
this purpose, when you 'yank' (i.e. 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 do the 'put' in which case the 'cp' command
is used. Similarly the 'mv' command is used for 'delete' (i.e. cut or kill)
followed by 'put'. These traditional names (e.g. 'yank', 'delete', and
'put') are picked instead of the other common convention (e.g. copy and cut)
to resemble the default keybinds for these operations.
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'.
You can customize these operations by defining a 'put' command. This is a
You can customize these operations by defining a 'paste' command. This is a
special command that is called when it is defined instead of the builtin
implementation. The default behavior is similar to the following command:
cmd put ${{
cmd paste ${{
load=$(lf -remote 'load')
mode=$(echo "$load" | sed -n '1p')
list=$(echo "$load" | sed '1d')
+1 -1
View File
@@ -3,7 +3,7 @@ set shell sh
# set '-eu' options for shell commands
# These options are used to have safer shell commands. Option '-e' is used to
# exit on error and '-u' option is used to give error for unset variables.
# exit on error and option '-u' is used to give error for unset variables.
# Option '-f' disables pathname expansion which can be useful when $f, $fs, and
# $fx variables contain names with '*' or '?' characters. However, this option
# is used selectively within individual commands as it can be limiting at
+12 -12
View File
@@ -356,36 +356,36 @@ func (e *callExpr) eval(app *app, args []string) {
app.nav.invert()
case "unmark":
app.nav.unmark()
case "yank":
case "copy":
if err := app.nav.save(true); err != nil {
app.ui.printf("yank: %s", err)
app.ui.printf("copy: %s", err)
return
}
app.nav.unmark()
if err := sendRemote("send sync"); err != nil {
app.ui.printf("yank: %s", err)
app.ui.printf("copy: %s", err)
}
case "delete":
case "cut":
if err := app.nav.save(false); err != nil {
app.ui.printf("delete: %s", err)
app.ui.printf("cut: %s", err)
return
}
app.nav.unmark()
if err := sendRemote("send sync"); err != nil {
app.ui.printf("delete: %s", err)
app.ui.printf("cut: %s", err)
}
case "put":
if cmd, ok := gOpts.cmds["put"]; ok {
case "paste":
if cmd, ok := gOpts.cmds["paste"]; ok {
cmd.eval(app, e.args)
} else if err := app.nav.put(); err != nil {
app.ui.printf("put: %s", err)
} else if err := app.nav.paste(); err != nil {
app.ui.printf("paste: %s", err)
return
}
if err := sendRemote("send load"); err != nil {
app.ui.printf("put: %s", err)
app.ui.printf("paste: %s", err)
}
if err := sendRemote("send sync"); err != nil {
app.ui.printf("put: %s", err)
app.ui.printf("paste: %s", err)
}
case "clear":
if err := saveFiles(nil, false); err != nil {
+13 -13
View File
@@ -540,69 +540,69 @@ func (nav *nav) unmark() {
nav.markInd = 0
}
func (nav *nav) save(copy bool) error {
func (nav *nav) save(cp bool) error {
if len(nav.marks) == 0 {
curr, err := nav.currFile()
if err != nil {
return errors.New("no file selected")
}
if err := saveFiles([]string{curr.path}, copy); err != nil {
if err := saveFiles([]string{curr.path}, cp); err != nil {
return err
}
nav.saves = make(map[string]bool)
nav.saves[curr.path] = copy
nav.saves[curr.path] = cp
} else {
marks := nav.currMarks()
if err := saveFiles(marks, copy); err != nil {
if err := saveFiles(marks, cp); err != nil {
return err
}
nav.saves = make(map[string]bool)
for f := range nav.marks {
nav.saves[f] = copy
nav.saves[f] = cp
}
}
return nil
}
func (nav *nav) put() error {
list, copy, err := loadFiles()
func (nav *nav) paste() error {
list, cp, err := loadFiles()
if err != nil {
return err
}
if len(list) == 0 {
return errors.New("no file in yank/delete buffer")
return errors.New("no file in copy/cut buffer")
}
dir := nav.currDir()
cmd := putCommand(list, dir, copy)
cmd := pasteCommand(list, dir, cp)
if err := cmd.Run(); err != nil {
return fmt.Errorf("putting files: %s", err)
return fmt.Errorf("pasting files: %s", err)
}
if err := saveFiles(nil, false); err != nil {
return fmt.Errorf("clearing yank/delete buffer: %s", err)
return fmt.Errorf("clearing copy/cut buffer: %s", err)
}
return nil
}
func (nav *nav) sync() error {
list, copy, err := loadFiles()
list, cp, err := loadFiles()
if err != nil {
return err
}
nav.saves = make(map[string]bool)
for _, f := range list {
nav.saves[f] = copy
nav.saves[f] = cp
}
return nil
+3 -3
View File
@@ -90,10 +90,10 @@ func init() {
gOpts.keys["<space>"] = &callExpr{"toggle", nil, 1}
gOpts.keys["v"] = &callExpr{"invert", nil, 1}
gOpts.keys["u"] = &callExpr{"unmark", nil, 1}
gOpts.keys["y"] = &callExpr{"yank", nil, 1}
gOpts.keys["d"] = &callExpr{"delete", nil, 1}
gOpts.keys["y"] = &callExpr{"copy", nil, 1}
gOpts.keys["d"] = &callExpr{"cut", nil, 1}
gOpts.keys["c"] = &callExpr{"clear", nil, 1}
gOpts.keys["p"] = &callExpr{"put", nil, 1}
gOpts.keys["p"] = &callExpr{"paste", nil, 1}
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil, 1}
gOpts.keys["<c-r>"] = &callExpr{"reload", nil, 1}
gOpts.keys[":"] = &callExpr{"read", nil, 1}
+2 -2
View File
@@ -70,11 +70,11 @@ func shellCommand(s string, args []string) *exec.Cmd {
return exec.Command(gOpts.shell, args...)
}
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
var sh string
var args []string
if copy {
if cp {
sh = "cp"
args = append(args, "-R")
} else {
+2 -2
View File
@@ -45,11 +45,11 @@ func shellCommand(s string, args []string) *exec.Cmd {
return exec.Command(gOpts.shell, args...)
}
func putCommand(list []string, dir *dir, copy bool) *exec.Cmd {
func pasteCommand(list []string, dir *dir, cp bool) *exec.Cmd {
var args []string
sh := "robocopy"
if !copy {
if !cp {
args = []string{"/move"}
}
for _, f := range list {
+2 -2
View File
@@ -274,8 +274,8 @@ func (win *win) printDir(dir *dir, marks map[string]int, saves map[string]bool,
if _, ok := marks[path]; ok {
win.print(0, i, fg, termbox.ColorMagenta, " ")
} else if copy, ok := saves[path]; ok {
if copy {
} else if cp, ok := saves[path]; ok {
if cp {
win.print(0, i, fg, termbox.ColorYellow, " ")
} else {
win.print(0, i, fg, termbox.ColorRed, " ")