Export mode for use in scripting keybindings (#1594)
* Export mode * Add pipe mode * Add documentation
This commit is contained in:
1 parent
ab54329570
commit
cf996263bb
5 files changed
+64
-1
No files matched your search
@@ -500,6 +500,7 @@ func (app *app) runCmdSync(cmd *exec.Cmd, pause_after bool) {
|
||||
func (app *app) runShell(s string, args []string, prefix string) {
|
||||
app.nav.exportFiles()
|
||||
app.ui.exportSizes()
|
||||
app.ui.exportMode()
|
||||
exportOpts()
|
||||
|
||||
gState.mutex.Lock()
|
||||
|
||||
@@ -224,6 +224,7 @@ The following environment variables are exported for shell commands:
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
lf_mode
|
||||
|
||||
The following special shell commands are used to customize the behavior of lf when defined:
|
||||
|
||||
@@ -1090,6 +1091,12 @@ Width/Height of the terminal.
|
||||
|
||||
Value of the count associated with the current command.
|
||||
|
||||
## lf_mode
|
||||
|
||||
Current mode that `lf` is operating in.
|
||||
This is useful for customizing keybindings depending on what the current mode is.
|
||||
Possible values are `delete`, `rename`, `filter`, `find`, `mark`, `search`, `command`, `shell`, `pipe` (when running a shell-pipe command), `normal`, and `unknown`.
|
||||
|
||||
# SPECIAL COMMANDS
|
||||
|
||||
This section shows information about special shell commands.
|
||||
|
||||
@@ -214,6 +214,7 @@ The following environment variables are exported for shell commands:
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
lf_mode
|
||||
|
||||
The following special shell commands are used to customize the behavior
|
||||
of lf when defined:
|
||||
@@ -1201,6 +1202,13 @@ lf_count
|
||||
|
||||
Value of the count associated with the current command.
|
||||
|
||||
lf_mode
|
||||
|
||||
Current mode that lf is operating in. This is useful for customizing
|
||||
keybindings depending on what the current mode is. Possible values are
|
||||
delete, rename, filter, find, mark, search, command, shell, pipe (when
|
||||
running a shell-pipe command), normal, and unknown.
|
||||
|
||||
SPECIAL COMMANDS
|
||||
|
||||
This section shows information about special shell commands.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
.\" Automatically generated by Pandoc 2.11.4
|
||||
.\"
|
||||
.TH "LF" "1" "2024-01-18" "" "DOCUMENTATION"
|
||||
.TH "LF" "1" "2024-02-02" "" "DOCUMENTATION"
|
||||
.hy
|
||||
.SH NAME
|
||||
.PP
|
||||
@@ -236,6 +236,7 @@ lf_user_{option}
|
||||
lf_width
|
||||
lf_height
|
||||
lf_count
|
||||
lf_mode
|
||||
\f[R]
|
||||
.fi
|
||||
.PP
|
||||
@@ -1216,6 +1217,15 @@ Width/Height of the terminal.
|
||||
.SS lf_count
|
||||
.PP
|
||||
Value of the count associated with the current command.
|
||||
.SS lf_mode
|
||||
.PP
|
||||
Current mode that \f[C]lf\f[R] is operating in.
|
||||
This is useful for customizing keybindings depending on what the current
|
||||
mode is.
|
||||
Possible values are \f[C]delete\f[R], \f[C]rename\f[R],
|
||||
\f[C]filter\f[R], \f[C]find\f[R], \f[C]mark\f[R], \f[C]search\f[R],
|
||||
\f[C]command\f[R], \f[C]shell\f[R], \f[C]pipe\f[R] (when running a
|
||||
shell-pipe command), \f[C]normal\f[R], and \f[C]unknown\f[R].
|
||||
.SH SPECIAL COMMANDS
|
||||
.PP
|
||||
This section shows information about special shell commands.
|
||||
|
||||
@@ -1512,6 +1512,43 @@ func (ui *ui) resume() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (ui *ui) exportMode() {
|
||||
getMode := func() string {
|
||||
if strings.HasPrefix(ui.cmdPrefix, "delete") {
|
||||
return "delete"
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ui.cmdPrefix, "replace") || strings.HasPrefix(ui.cmdPrefix, "create") {
|
||||
return "rename"
|
||||
}
|
||||
|
||||
switch ui.cmdPrefix {
|
||||
case "filter: ":
|
||||
return "filter"
|
||||
case "find: ", "find-back: ":
|
||||
return "find"
|
||||
case "mark-save: ", "mark-load: ", "mark-remove: ":
|
||||
return "mark"
|
||||
case "rename: ":
|
||||
return "rename"
|
||||
case "/", "?":
|
||||
return "search"
|
||||
case ":":
|
||||
return "command"
|
||||
case "$", "%", "!", "&":
|
||||
return "shell"
|
||||
case ">":
|
||||
return "pipe"
|
||||
case "":
|
||||
return "normal"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
|
||||
os.Setenv("lf_mode", getMode())
|
||||
}
|
||||
|
||||
func (ui *ui) exportSizes() {
|
||||
w, h := ui.screen.Size()
|
||||
os.Setenv("lf_width", strconv.Itoa(w))
|
||||
|
||||
Reference in new issue
Block a user