Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0175c1bd1b | ||
|
|
01581f902f | ||
|
|
54315ffde2 | ||
|
|
bdf20aa451 | ||
|
|
847c46421c | ||
|
|
f6c99a7d46 | ||
|
|
e55c490bf5 | ||
|
|
c63c8f63ac | ||
|
|
68232c06e3 | ||
|
|
4f05975e77 | ||
|
|
32d729eac1 |
No files matched your search
@@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -17,6 +20,9 @@ type app struct {
|
|||||||
ui *ui
|
ui *ui
|
||||||
nav *nav
|
nav *nav
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
cmd *exec.Cmd
|
||||||
|
cmdIn io.WriteCloser
|
||||||
|
cmdOutBuf []byte
|
||||||
cmdHist []cmdItem
|
cmdHist []cmdItem
|
||||||
cmdHistInd int
|
cmdHistInd int
|
||||||
}
|
}
|
||||||
@@ -168,18 +174,19 @@ func waitKey() error {
|
|||||||
|
|
||||||
// This function is used to run a command in shell. Following modes are used:
|
// This function is used to run a command in shell. Following modes are used:
|
||||||
//
|
//
|
||||||
// Prefix Wait Async Stdin/Stdout/Stderr UI action
|
// Prefix Wait Async Stdin Stdout Stderr UI action
|
||||||
// $ No No Yes Pause and then resume
|
// $ No No Yes Yes Yes Pause and then resume
|
||||||
// ! Yes No Yes Pause and then resume
|
// % No No Yes Yes Yes Use statline for input/output
|
||||||
// & No Yes No Do nothing
|
// ! Yes No Yes Yes Yes Pause and then resume
|
||||||
//
|
// & No Yes No No No Do nothing
|
||||||
// Waiting async commands are not used for now.
|
func (app *app) runShell(s string, args []string, prefix string) {
|
||||||
func (app *app) runShell(s string, args []string, wait bool, async bool) {
|
|
||||||
app.exportVars()
|
app.exportVars()
|
||||||
|
|
||||||
cmd := shellCommand(s, args)
|
cmd := shellCommand(s, args)
|
||||||
|
|
||||||
if !async {
|
var out io.Reader
|
||||||
|
switch prefix {
|
||||||
|
case "$", "!":
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@@ -187,25 +194,69 @@ func (app *app) runShell(s string, args []string, wait bool, async bool) {
|
|||||||
app.ui.pause()
|
app.ui.pause()
|
||||||
defer app.ui.resume()
|
defer app.ui.resume()
|
||||||
defer app.nav.renew(app.ui.wins[0].h)
|
defer app.nav.renew(app.ui.wins[0].h)
|
||||||
|
case "%":
|
||||||
|
stdin, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("writing stdin: %s", err)
|
||||||
|
}
|
||||||
|
app.cmdIn = stdin
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("reading stdout: %s", err)
|
||||||
|
}
|
||||||
|
out = stdout
|
||||||
|
cmd.Stderr = cmd.Stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if async {
|
switch prefix {
|
||||||
err = cmd.Start()
|
case "$", "!":
|
||||||
} else {
|
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
|
case "%", "&":
|
||||||
|
err = cmd.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.ui.printf("running shell: %s", err)
|
app.ui.printf("running shell: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if wait {
|
switch prefix {
|
||||||
|
case "!":
|
||||||
if err := waitKey(); err != nil {
|
if err := waitKey(); err != nil {
|
||||||
app.ui.printf("waiting shell: %s", err)
|
app.ui.printf("waiting key: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.ui.loadFile(app.nav)
|
app.ui.loadFile(app.nav)
|
||||||
app.ui.loadFileInfo(app.nav)
|
app.ui.loadFileInfo(app.nav)
|
||||||
|
|
||||||
|
switch prefix {
|
||||||
|
case "%":
|
||||||
|
go func() {
|
||||||
|
app.cmd = cmd
|
||||||
|
app.cmdOutBuf = nil
|
||||||
|
app.ui.msg = ""
|
||||||
|
app.ui.cmdPrefix = ">"
|
||||||
|
|
||||||
|
reader := bufio.NewReader(out)
|
||||||
|
for {
|
||||||
|
b, err := reader.ReadByte()
|
||||||
|
if err == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
app.cmdOutBuf = append(app.cmdOutBuf, b)
|
||||||
|
app.ui.exprChan <- multiExpr{&callExpr{"echo", []string{string(app.cmdOutBuf)}}, 1}
|
||||||
|
if b == '\n' || b == '\r' {
|
||||||
|
app.cmdOutBuf = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
log.Printf("running shell: %s", err)
|
||||||
|
}
|
||||||
|
app.cmd = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
|
app.ui.exprChan <- multiExpr{&callExpr{"reload", nil}, 1}
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -35,9 +35,10 @@ var (
|
|||||||
"redraw",
|
"redraw",
|
||||||
"reload",
|
"reload",
|
||||||
"read",
|
"read",
|
||||||
"read-shell",
|
"shell",
|
||||||
"read-shell-wait",
|
"shell-pipe",
|
||||||
"read-shell-async",
|
"shell-wait",
|
||||||
|
"shell-async",
|
||||||
"search",
|
"search",
|
||||||
"search-back",
|
"search-back",
|
||||||
"search-next",
|
"search-next",
|
||||||
@@ -45,6 +46,7 @@ var (
|
|||||||
"sync",
|
"sync",
|
||||||
"echo",
|
"echo",
|
||||||
"cd",
|
"cd",
|
||||||
|
"select",
|
||||||
"push",
|
"push",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
read-shell (default '$')
|
shell (default '$')
|
||||||
read-shell-wait (default '!')
|
shell-pipe (default '%')
|
||||||
read-shell-async (default '&')
|
shell-wait (default '!')
|
||||||
|
shell-async (default '&')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -46,6 +47,7 @@ The following commands are provided by lf without default keybindings:
|
|||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
@@ -67,6 +69,7 @@ keybindings:
|
|||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-put (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
cmd-transpose (default '<c-t>')
|
||||||
|
cmd-interrupt (default '<c-c>')
|
||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
@@ -142,9 +145,10 @@ Prefixes
|
|||||||
The following command prefixes are used by lf:
|
The following command prefixes are used by lf:
|
||||||
|
|
||||||
: read (default) builtin/custom command
|
: read (default) builtin/custom command
|
||||||
$ read-shell shell command
|
$ shell shell command
|
||||||
! read-shell-wait shell command waiting for key press
|
% shell-pipe shell command running with the ui
|
||||||
& read-shell-async asynchronous shell command
|
! shell-wait shell command waiting for key press
|
||||||
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
@@ -215,7 +219,7 @@ prefix.
|
|||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Mappings
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
command. While this provides a clean way to remap builtin keys as well as other
|
command. While this provides a clean way to remap builtin keys as well as other
|
||||||
@@ -240,12 +244,11 @@ commands it is possible to accidentally create recursive bindings:
|
|||||||
|
|
||||||
These types of bindings create a deadlock when executed.
|
These types of bindings create a deadlock when executed.
|
||||||
|
|
||||||
Commands
|
Shell Commands
|
||||||
|
|
||||||
For demonstration let us write a shell command to move selected file(s) to
|
Regular shell commands are the most basic command type that is useful for many
|
||||||
trash.
|
purposes. For example, we can write a shell command to move selected file(s) to
|
||||||
|
trash. A first attempt to write such a command may look like this:
|
||||||
A first attempt to write such a command may look like this:
|
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
@@ -285,6 +288,47 @@ could use the 'ifs' option to set it for all shell commands (i.e. 'set ifs
|
|||||||
behave unexpectedly for new users. However, use of this option is highly
|
behave unexpectedly for new users. However, use of this option is highly
|
||||||
recommended and it is assumed in the rest of the documentation.
|
recommended and it is assumed in the rest of the documentation.
|
||||||
|
|
||||||
|
Piping Shell Commands
|
||||||
|
|
||||||
|
Regular shell commands have some limitations in some cases. When an output or
|
||||||
|
error message is given and the command exits afterwards, the ui is immediately
|
||||||
|
resumed and there is no way to see the message without dropping to shell again.
|
||||||
|
Also, even when there is no output or error, the ui still needs to be paused
|
||||||
|
while the command is running. This can cause flickering on the screen for short
|
||||||
|
commands and similar distractions for longer commands.
|
||||||
|
|
||||||
|
Instead of pausing the ui, piping shell commands connects stdin, stdout, and
|
||||||
|
stderr of the command to the statline in the bottom of the ui. This can be
|
||||||
|
useful for programs following the unix philosophy to give no output in the
|
||||||
|
success case, and brief error messages or prompts in other cases.
|
||||||
|
|
||||||
|
For example, following rename command prompts for overwrite in the statline if
|
||||||
|
there is an existing file with the given name:
|
||||||
|
|
||||||
|
cmd rename %mv -i $f $1
|
||||||
|
|
||||||
|
You can also output error messages in the command and it will show up in the
|
||||||
|
statline. For example, an alternative rename command may look like this:
|
||||||
|
|
||||||
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
|
|
||||||
|
One thing to be careful is that although input is still line buffered, output
|
||||||
|
and error are byte buffered and verbose commands will be very slow to display.
|
||||||
|
|
||||||
|
Waiting Shell Commands
|
||||||
|
|
||||||
|
Waiting shell commands are similar to regular shell commands except that they
|
||||||
|
wait for a key press when the command is finished. These can be useful to see
|
||||||
|
the output of a program before the ui is resumed. Waiting shell commands are
|
||||||
|
more appropriate than piping shell commands when the command is verbose and the
|
||||||
|
output is best displayed as multiline.
|
||||||
|
|
||||||
|
Asynchronous Shell Commands
|
||||||
|
|
||||||
|
Asynchronous shell commands are used to start a command in the background and
|
||||||
|
then resume operation without waiting for the command to finish. Stdin, stdout,
|
||||||
|
and stderr of the command is neither connected to the terminal nor to the ui.
|
||||||
|
|
||||||
Remote Commands
|
Remote Commands
|
||||||
|
|
||||||
One of the more advanced features in lf is remote commands. All clients connect
|
One of the more advanced features in lf is remote commands. All clients connect
|
||||||
@@ -321,15 +365,17 @@ a shell command:
|
|||||||
lf -remote "send $id echo hello world"
|
lf -remote "send $id echo hello world"
|
||||||
|
|
||||||
Since lf does not have control flow syntax, remote commands are used for such
|
Since lf does not have control flow syntax, remote commands are used for such
|
||||||
needs. A common use is to display an error message back in the client. You can
|
needs. For example, you can configure the number of columns in the ui with
|
||||||
implement a safe rename command which does not overwrite an existing file or
|
respect to the terminal width as follows:
|
||||||
directory as such:
|
|
||||||
|
|
||||||
cmd rename ${{
|
cmd recol ${{
|
||||||
if [ -e $1 ]; then
|
w=$(tput cols)
|
||||||
lf -remote "send $id echo file exists"
|
if [ $w -le 80 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2"
|
||||||
|
elif [ $w -le 160 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
mv $f $1
|
lf -remote "send $id set ratios 1:2:3:5"
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|||||||
+72
-19
@@ -37,9 +37,10 @@ The following commands are provided by lf with default keybindings:
|
|||||||
redraw (default '<c-l>')
|
redraw (default '<c-l>')
|
||||||
reload (default '<c-r>')
|
reload (default '<c-r>')
|
||||||
read (default ':')
|
read (default ':')
|
||||||
read-shell (default '$')
|
shell (default '$')
|
||||||
read-shell-wait (default '!')
|
shell-pipe (default '%')
|
||||||
read-shell-async (default '&')
|
shell-wait (default '!')
|
||||||
|
shell-async (default '&')
|
||||||
search (default '/')
|
search (default '/')
|
||||||
search-back (default '?')
|
search-back (default '?')
|
||||||
search-next (default 'n')
|
search-next (default 'n')
|
||||||
@@ -50,6 +51,7 @@ The following commands are provided by lf without default keybindings:
|
|||||||
sync synchronizes yanked/deleted files with server
|
sync synchronizes yanked/deleted files with server
|
||||||
echo prints its arguments to the message line
|
echo prints its arguments to the message line
|
||||||
cd changes working directory to its argument
|
cd changes working directory to its argument
|
||||||
|
select changes current file selection to its argument
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following command line commands are provided by lf with default
|
The following command line commands are provided by lf with default
|
||||||
@@ -71,6 +73,7 @@ keybindings:
|
|||||||
cmd-delete-word (default '<c-w>')
|
cmd-delete-word (default '<c-w>')
|
||||||
cmd-put (default '<c-y>')
|
cmd-put (default '<c-y>')
|
||||||
cmd-transpose (default '<c-t>')
|
cmd-transpose (default '<c-t>')
|
||||||
|
cmd-interrupt (default '<c-c>')
|
||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
@@ -149,9 +152,10 @@ Prefixes
|
|||||||
The following command prefixes are used by lf:
|
The following command prefixes are used by lf:
|
||||||
|
|
||||||
: read (default) builtin/custom command
|
: read (default) builtin/custom command
|
||||||
$ read-shell shell command
|
$ shell shell command
|
||||||
! read-shell-wait shell command waiting for key press
|
% shell-pipe shell command running with the ui
|
||||||
& read-shell-async asynchronous shell command
|
! shell-wait shell command waiting for key press
|
||||||
|
& shell-async shell command running asynchronously
|
||||||
/ search search file in current directory
|
/ search search file in current directory
|
||||||
? search-back search file in the reverse order
|
? search-back search file in the reverse order
|
||||||
|
|
||||||
@@ -224,7 +228,7 @@ proper prefix.
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
Mappings
|
Push Mappings
|
||||||
|
|
||||||
The usual way to map a key sequence is to assign it to a named or unnamed
|
The usual way to map a key sequence is to assign it to a named or unnamed
|
||||||
command. While this provides a clean way to remap builtin keys as well as
|
command. While this provides a clean way to remap builtin keys as well as
|
||||||
@@ -251,12 +255,12 @@ of commands it is possible to accidentally create recursive bindings:
|
|||||||
These types of bindings create a deadlock when executed.
|
These types of bindings create a deadlock when executed.
|
||||||
|
|
||||||
|
|
||||||
Commands
|
Shell Commands
|
||||||
|
|
||||||
For demonstration let us write a shell command to move selected file(s) to
|
Regular shell commands are the most basic command type that is useful for
|
||||||
trash.
|
many purposes. For example, we can write a shell command to move selected
|
||||||
|
file(s) to trash. A first attempt to write such a command may look like
|
||||||
A first attempt to write such a command may look like this:
|
this:
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
@@ -298,6 +302,53 @@ behave unexpectedly for new users. However, use of this option is highly
|
|||||||
recommended and it is assumed in the rest of the documentation.
|
recommended and it is assumed in the rest of the documentation.
|
||||||
|
|
||||||
|
|
||||||
|
Piping Shell Commands
|
||||||
|
|
||||||
|
Regular shell commands have some limitations in some cases. When an output
|
||||||
|
or error message is given and the command exits afterwards, the ui is
|
||||||
|
immediately resumed and there is no way to see the message without dropping
|
||||||
|
to shell again. Also, even when there is no output or error, the ui still
|
||||||
|
needs to be paused while the command is running. This can cause flickering
|
||||||
|
on the screen for short commands and similar distractions for longer
|
||||||
|
commands.
|
||||||
|
|
||||||
|
Instead of pausing the ui, piping shell commands connects stdin, stdout, and
|
||||||
|
stderr of the command to the statline in the bottom of the ui. This can be
|
||||||
|
useful for programs following the unix philosophy to give no output in the
|
||||||
|
success case, and brief error messages or prompts in other cases.
|
||||||
|
|
||||||
|
For example, following rename command prompts for overwrite in the statline
|
||||||
|
if there is an existing file with the given name:
|
||||||
|
|
||||||
|
cmd rename %mv -i $f $1
|
||||||
|
|
||||||
|
You can also output error messages in the command and it will show up in the
|
||||||
|
statline. For example, an alternative rename command may look like this:
|
||||||
|
|
||||||
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
|
|
||||||
|
One thing to be careful is that although input is still line buffered,
|
||||||
|
output and error are byte buffered and verbose commands will be very slow to
|
||||||
|
display.
|
||||||
|
|
||||||
|
|
||||||
|
Waiting Shell Commands
|
||||||
|
|
||||||
|
Waiting shell commands are similar to regular shell commands except that
|
||||||
|
they wait for a key press when the command is finished. These can be useful
|
||||||
|
to see the output of a program before the ui is resumed. Waiting shell
|
||||||
|
commands are more appropriate than piping shell commands when the command is
|
||||||
|
verbose and the output is best displayed as multiline.
|
||||||
|
|
||||||
|
|
||||||
|
Asynchronous Shell Commands
|
||||||
|
|
||||||
|
Asynchronous shell commands are used to start a command in the background
|
||||||
|
and then resume operation without waiting for the command to finish. Stdin,
|
||||||
|
stdout, and stderr of the command is neither connected to the terminal nor
|
||||||
|
to the ui.
|
||||||
|
|
||||||
|
|
||||||
Remote Commands
|
Remote Commands
|
||||||
|
|
||||||
One of the more advanced features in lf is remote commands. All clients
|
One of the more advanced features in lf is remote commands. All clients
|
||||||
@@ -335,15 +386,17 @@ calling the following in a shell command:
|
|||||||
lf -remote "send $id echo hello world"
|
lf -remote "send $id echo hello world"
|
||||||
|
|
||||||
Since lf does not have control flow syntax, remote commands are used for
|
Since lf does not have control flow syntax, remote commands are used for
|
||||||
such needs. A common use is to display an error message back in the client.
|
such needs. For example, you can configure the number of columns in the ui
|
||||||
You can implement a safe rename command which does not overwrite an existing
|
with respect to the terminal width as follows:
|
||||||
file or directory as such:
|
|
||||||
|
|
||||||
cmd rename ${{
|
cmd recol ${{
|
||||||
if [ -e $1 ]; then
|
w=$(tput cols)
|
||||||
lf -remote "send $id echo file exists"
|
if [ $w -le 80 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2"
|
||||||
|
elif [ $w -le 160 ]; then
|
||||||
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
mv $f $1
|
lf -remote "send $id set ratios 1:2:3:5"
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|||||||
+9
-20
@@ -12,7 +12,7 @@ set ifs "\n"
|
|||||||
set scrolloff 10
|
set scrolloff 10
|
||||||
|
|
||||||
# use enter for shell commands
|
# use enter for shell commands
|
||||||
map <enter> read-shell
|
map <enter> shell
|
||||||
|
|
||||||
# execute current file (must be executable)
|
# execute current file (must be executable)
|
||||||
map x $$f
|
map x $$f
|
||||||
@@ -37,24 +37,15 @@ cmd open-file ${{
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
# rename current file without overwrite
|
# rename current file without overwrite
|
||||||
cmd rename ${{
|
cmd rename %[ -e $1 ] && printf "file exists" || mv $f $1
|
||||||
if [ -e $1 ]; then
|
|
||||||
lf -remote "send $id echo file exists"
|
|
||||||
else
|
|
||||||
mv $f $1
|
|
||||||
fi
|
|
||||||
}}
|
|
||||||
map r push :rename<space>
|
map r push :rename<space>
|
||||||
|
|
||||||
# show disk usage
|
|
||||||
cmd usage $du -h . | less
|
|
||||||
|
|
||||||
# make sure trash folder exists
|
# make sure trash folder exists
|
||||||
$mkdir -p ~/.trash
|
%mkdir -p ~/.trash
|
||||||
|
|
||||||
# move current file or selected files to trash folder
|
# move current file or selected files to trash folder
|
||||||
# (also see 'man mv' for backup/overwrite options)
|
# (also see 'man mv' for backup/overwrite options)
|
||||||
cmd trash $mv $fx ~/.trash
|
cmd trash %mv $fx ~/.trash
|
||||||
|
|
||||||
# remove current file or selected files (prompting)
|
# remove current file or selected files (prompting)
|
||||||
cmd remove ${{
|
cmd remove ${{
|
||||||
@@ -66,7 +57,7 @@ cmd remove ${{
|
|||||||
|
|
||||||
# extract the current file with the right command
|
# extract the current file with the right command
|
||||||
# (xkcd link: https://xkcd.com/1168/)
|
# (xkcd link: https://xkcd.com/1168/)
|
||||||
cmd extract ${{
|
cmd extract %{{
|
||||||
case $f in
|
case $f in
|
||||||
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar xjvf $f;;
|
||||||
*.tar.gz|*.tgz) tar xzvf $f;;
|
*.tar.gz|*.tgz) tar xzvf $f;;
|
||||||
@@ -77,12 +68,10 @@ cmd extract ${{
|
|||||||
esac
|
esac
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# compress marked files with tar and gunzip
|
# compress current file or selected files with tar and gunzip
|
||||||
# This command takes the output name without '.tar.gz' suffix as an argument
|
cmd compress %{{
|
||||||
# (e.g. 'compress foo' creates 'foo.tar.gz').
|
|
||||||
cmd compress ${{
|
|
||||||
mkdir $1
|
mkdir $1
|
||||||
cp $fs $1
|
cp -r $fx $1
|
||||||
tar czvf $1.tar.gz $1
|
tar czf $1.tar.gz $1
|
||||||
rm -rf $1
|
rm -rf $1
|
||||||
}}
|
}}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -344,11 +345,13 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.nav.reload()
|
app.nav.reload()
|
||||||
case "read":
|
case "read":
|
||||||
app.ui.cmdPrefix = ":"
|
app.ui.cmdPrefix = ":"
|
||||||
case "read-shell":
|
case "shell":
|
||||||
app.ui.cmdPrefix = "$"
|
app.ui.cmdPrefix = "$"
|
||||||
case "read-shell-wait":
|
case "shell-pipe":
|
||||||
|
app.ui.cmdPrefix = "%"
|
||||||
|
case "shell-wait":
|
||||||
app.ui.cmdPrefix = "!"
|
app.ui.cmdPrefix = "!"
|
||||||
case "read-shell-async":
|
case "shell-async":
|
||||||
app.ui.cmdPrefix = "&"
|
app.ui.cmdPrefix = "&"
|
||||||
case "search":
|
case "search":
|
||||||
app.ui.cmdPrefix = "/"
|
app.ui.cmdPrefix = "/"
|
||||||
@@ -385,6 +388,17 @@ 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)
|
||||||
|
case "select":
|
||||||
|
if len(e.args) != 1 {
|
||||||
|
app.ui.print("select: requires an argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := app.nav.find(e.args[0]); err != nil {
|
||||||
|
app.ui.printf("%s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.ui.loadFile(app.nav)
|
||||||
|
app.ui.loadFileInfo(app.nav)
|
||||||
case "push":
|
case "push":
|
||||||
if len(e.args) > 0 {
|
if len(e.args) > 0 {
|
||||||
log.Println("pushing keys", e.args[0])
|
log.Println("pushing keys", e.args[0])
|
||||||
@@ -397,6 +411,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
app.ui.cmdAccLeft = append(app.ui.cmdAccLeft, []rune(e.args[0])...)
|
||||||
}
|
}
|
||||||
case "cmd-escape":
|
case "cmd-escape":
|
||||||
|
if app.ui.cmdPrefix == ">" {
|
||||||
|
return
|
||||||
|
}
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
app.ui.cmdAccLeft = nil
|
app.ui.cmdAccLeft = nil
|
||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
@@ -434,13 +451,22 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s", s)
|
log.Printf("shell: %s", s)
|
||||||
app.runShell(s, nil, false, false)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
case "%":
|
||||||
|
log.Printf("shell-pipe: %s", s)
|
||||||
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
|
app.cmdHist = append(app.cmdHist, cmdItem{"%", s})
|
||||||
|
return
|
||||||
|
case ">":
|
||||||
|
io.WriteString(app.cmdIn, s+"\n")
|
||||||
|
app.cmdOutBuf = nil
|
||||||
|
return
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s", s)
|
log.Printf("shell-wait: %s", s)
|
||||||
app.runShell(s, nil, true, false)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s", s)
|
log.Printf("shell-async: %s", s)
|
||||||
app.runShell(s, nil, false, true)
|
app.runShell(s, nil, app.ui.cmdPrefix)
|
||||||
case "/":
|
case "/":
|
||||||
log.Printf("search: %s", s)
|
log.Printf("search: %s", s)
|
||||||
app.nav.search = s
|
app.nav.search = s
|
||||||
@@ -465,6 +491,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdPrefix, s})
|
app.cmdHist = append(app.cmdHist, cmdItem{app.ui.cmdPrefix, s})
|
||||||
app.ui.cmdPrefix = ""
|
app.ui.cmdPrefix = ""
|
||||||
case "cmd-hist-next":
|
case "cmd-hist-next":
|
||||||
|
if app.ui.cmdPrefix == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
if app.cmdHistInd > 0 {
|
if app.cmdHistInd > 0 {
|
||||||
app.cmdHistInd--
|
app.cmdHistInd--
|
||||||
}
|
}
|
||||||
@@ -481,6 +510,9 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
app.ui.cmdAccRight = nil
|
app.ui.cmdAccRight = nil
|
||||||
app.ui.menuBuf = nil
|
app.ui.menuBuf = nil
|
||||||
case "cmd-hist-prev":
|
case "cmd-hist-prev":
|
||||||
|
if app.ui.cmdPrefix == "" {
|
||||||
|
app.cmdHistInd = 0
|
||||||
|
}
|
||||||
if app.cmdHistInd == len(app.cmdHist) {
|
if app.cmdHistInd == len(app.cmdHist) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -534,6 +566,14 @@ func (e *callExpr) eval(app *app, args []string) {
|
|||||||
if len(app.ui.cmdAccLeft) > 1 {
|
if len(app.ui.cmdAccLeft) > 1 {
|
||||||
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2] = app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-2], app.ui.cmdAccLeft[len(app.ui.cmdAccLeft)-1]
|
||||||
}
|
}
|
||||||
|
case "cmd-interrupt":
|
||||||
|
if app.cmd != nil {
|
||||||
|
app.cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
app.ui.menuBuf = nil
|
||||||
|
app.ui.cmdAccLeft = nil
|
||||||
|
app.ui.cmdAccRight = nil
|
||||||
|
app.ui.cmdPrefix = ""
|
||||||
default:
|
default:
|
||||||
cmd, ok := gOpts.cmds[e.name]
|
cmd, ok := gOpts.cmds[e.name]
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -548,19 +588,16 @@ func (e *execExpr) eval(app *app, args []string) {
|
|||||||
switch e.prefix {
|
switch e.prefix {
|
||||||
case "$":
|
case "$":
|
||||||
log.Printf("shell: %s -- %s", e, args)
|
log.Printf("shell: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, false, false)
|
app.runShell(e.value, args, e.prefix)
|
||||||
|
case "%":
|
||||||
|
log.Printf("shell-pipe: %s -- %s", e, args)
|
||||||
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "!":
|
case "!":
|
||||||
log.Printf("shell-wait: %s -- %s", e, args)
|
log.Printf("shell-wait: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, true, false)
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "&":
|
case "&":
|
||||||
log.Printf("shell-async: %s -- %s", e, args)
|
log.Printf("shell-async: %s -- %s", e, args)
|
||||||
app.runShell(e.value, args, false, true)
|
app.runShell(e.value, args, e.prefix)
|
||||||
case "/":
|
|
||||||
log.Printf("search: %s -- %s", e, args)
|
|
||||||
// TODO: implement
|
|
||||||
case "?":
|
|
||||||
log.Printf("search-back: %s -- %s", e, args)
|
|
||||||
// TODO: implement
|
|
||||||
default:
|
default:
|
||||||
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
log.Printf("evaluating unknown execution prefix: %q", e.prefix)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ func (nav *nav) getDirs(wd string) {
|
|||||||
|
|
||||||
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
for curr, base := wd, ""; !isRoot(base); curr, base = filepath.Dir(curr), filepath.Base(curr) {
|
||||||
dir := nav.loadDir(curr)
|
dir := nav.loadDir(curr)
|
||||||
|
dir.find(base, nav.height)
|
||||||
dirs = append(dirs, dir)
|
dirs = append(dirs, dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -618,6 +619,30 @@ func (nav *nav) cd(wd string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nav *nav) find(path string) error {
|
||||||
|
lstat, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dir := filepath.Dir(path)
|
||||||
|
|
||||||
|
if err := nav.cd(dir); err != nil {
|
||||||
|
return fmt.Errorf("select: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
base := filepath.Base(path)
|
||||||
|
|
||||||
|
last := nav.dirs[len(nav.dirs)-1]
|
||||||
|
if last.loading {
|
||||||
|
last.fi = append(last.fi, &file{FileInfo: lstat})
|
||||||
|
} else {
|
||||||
|
last.find(base, nav.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func match(pattern, name string) (matched bool, err error) {
|
func match(pattern, name string) (matched bool, err error) {
|
||||||
if gOpts.ignorecase {
|
if gOpts.ignorecase {
|
||||||
lpattern := strings.ToLower(pattern)
|
lpattern := strings.ToLower(pattern)
|
||||||
|
|||||||
@@ -75,9 +75,10 @@ func init() {
|
|||||||
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil}
|
gOpts.keys["<c-l>"] = &callExpr{"redraw", nil}
|
||||||
gOpts.keys["<c-r>"] = &callExpr{"reload", nil}
|
gOpts.keys["<c-r>"] = &callExpr{"reload", nil}
|
||||||
gOpts.keys[":"] = &callExpr{"read", nil}
|
gOpts.keys[":"] = &callExpr{"read", nil}
|
||||||
gOpts.keys["$"] = &callExpr{"read-shell", nil}
|
gOpts.keys["$"] = &callExpr{"shell", nil}
|
||||||
gOpts.keys["!"] = &callExpr{"read-shell-wait", nil}
|
gOpts.keys["%"] = &callExpr{"shell-pipe", nil}
|
||||||
gOpts.keys["&"] = &callExpr{"read-shell-async", nil}
|
gOpts.keys["!"] = &callExpr{"shell-wait", nil}
|
||||||
|
gOpts.keys["&"] = &callExpr{"shell-async", nil}
|
||||||
gOpts.keys["/"] = &callExpr{"search", nil}
|
gOpts.keys["/"] = &callExpr{"search", nil}
|
||||||
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
gOpts.keys["?"] = &callExpr{"search-back", nil}
|
||||||
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
gOpts.keys["n"] = &callExpr{"search-next", nil}
|
||||||
@@ -123,6 +124,7 @@ func init() {
|
|||||||
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
|
gOpts.cmdkeys["<c-w>"] = &callExpr{"cmd-delete-word", nil}
|
||||||
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
|
gOpts.cmdkeys["<c-y>"] = &callExpr{"cmd-put", nil}
|
||||||
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
|
gOpts.cmdkeys["<c-t>"] = &callExpr{"cmd-transpose", nil}
|
||||||
|
gOpts.cmdkeys["<c-c>"] = &callExpr{"cmd-interrupt", nil}
|
||||||
|
|
||||||
gOpts.cmds = make(map[string]expr)
|
gOpts.cmds = make(map[string]expr)
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const (
|
|||||||
// no explicit keyword type
|
// no explicit keyword type
|
||||||
tokenIdent // e.g. set, ratios, 1:2:3
|
tokenIdent // e.g. set, ratios, 1:2:3
|
||||||
tokenColon // :
|
tokenColon // :
|
||||||
tokenPrefix // $, !, &, / or ?
|
tokenPrefix // $, %, !, &
|
||||||
tokenLBraces // {{
|
tokenLBraces // {{
|
||||||
tokenRBraces // }}
|
tokenRBraces // }}
|
||||||
tokenCommand // in between a prefix to \n or between {{ and }}
|
tokenCommand // in between a prefix to \n or between {{ and }}
|
||||||
@@ -90,8 +90,7 @@ func isDigit(b byte) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func isPrefix(b byte) bool {
|
func isPrefix(b byte) bool {
|
||||||
// TODO: how to differentiate slash in path vs search?
|
return b == '$' || b == '%' || b == '!' || b == '&'
|
||||||
return b == '$' || b == '!' || b == '&' // || b == '/' || b == '?'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scanner) scan() bool {
|
func (s *scanner) scan() bool {
|
||||||
|
|||||||
@@ -415,6 +415,7 @@ type ui struct {
|
|||||||
msg string
|
msg string
|
||||||
regPrev *reg
|
regPrev *reg
|
||||||
dirPrev *dir
|
dirPrev *dir
|
||||||
|
exprChan chan multiExpr
|
||||||
keyChan chan string
|
keyChan chan string
|
||||||
evChan chan termbox.Event
|
evChan chan termbox.Event
|
||||||
menuBuf *bytes.Buffer
|
menuBuf *bytes.Buffer
|
||||||
@@ -611,14 +612,21 @@ func (ui *ui) draw(nav *nav) {
|
|||||||
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves)
|
ui.wins[woff+i].printDir(nav.dirs[doff+i], nav.marks, nav.saves)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.cmdPrefix != "" {
|
switch ui.cmdPrefix {
|
||||||
|
case "":
|
||||||
|
ui.drawStatLine(nav)
|
||||||
|
termbox.HideCursor()
|
||||||
|
case ">":
|
||||||
|
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, ui.msg)
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg), 0, fg, bg, string(ui.cmdAccLeft))
|
||||||
|
ui.msgWin.print(len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
||||||
|
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+len(ui.msg)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
||||||
|
default:
|
||||||
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
ui.msgWin.printLine(0, 0, fg, bg, ui.cmdPrefix)
|
||||||
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, string(ui.cmdAccLeft))
|
ui.msgWin.print(len(ui.cmdPrefix), 0, fg, bg, string(ui.cmdAccLeft))
|
||||||
ui.msgWin.print(len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
ui.msgWin.print(len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), 0, fg, bg, string(ui.cmdAccRight))
|
||||||
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
termbox.SetCursor(ui.msgWin.x+len(ui.cmdPrefix)+runeSliceWidth(ui.cmdAccLeft), ui.msgWin.y)
|
||||||
} else {
|
|
||||||
ui.drawStatLine(nav)
|
|
||||||
termbox.HideCursor()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gOpts.preview {
|
if gOpts.preview {
|
||||||
@@ -830,6 +838,8 @@ func (ui *ui) readEvent(ch chan<- multiExpr, ev termbox.Event) {
|
|||||||
func (ui *ui) readExpr() <-chan multiExpr {
|
func (ui *ui) readExpr() <-chan multiExpr {
|
||||||
ch := make(chan multiExpr)
|
ch := make(chan multiExpr)
|
||||||
|
|
||||||
|
ui.exprChan = ch
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
ch <- multiExpr{&callExpr{"redraw", nil}, 1}
|
ch <- multiExpr{&callExpr{"redraw", nil}, 1}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user