2016-09-13 21:40:14 +00:00
|
|
|
//go:generate gen/docstring.sh
|
|
|
|
|
|
|
|
/*
|
|
|
|
lf is a terminal file manager.
|
|
|
|
|
2016-09-14 23:18:50 +00:00
|
|
|
Source code can be found in the repository at https://github.com/gokcehan/lf.
|
2016-09-13 21:40:14 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
This documentation can either be read from terminal using 'lf -doc' or online
|
2016-09-14 23:18:50 +00:00
|
|
|
at https://godoc.org/github.com/gokcehan/lf.
|
|
|
|
|
|
|
|
Reference
|
|
|
|
|
2016-12-19 21:19:07 +00:00
|
|
|
The following commands are provided by lf with default keybindings:
|
|
|
|
|
2018-03-27 18:23:34 +00:00
|
|
|
up (default 'k' and '<up>')
|
|
|
|
half-up (default '<c-u>')
|
|
|
|
page-up (default '<c-b>')
|
|
|
|
down (default 'j' and '<down>')
|
|
|
|
half-down (default '<c-d>')
|
|
|
|
page-down (default '<c-f>')
|
|
|
|
updir (default 'h' and '<left>')
|
|
|
|
open (default 'l' and '<right>')
|
|
|
|
quit (default 'q')
|
|
|
|
top (default 'gg')
|
2018-05-15 21:20:05 +00:00
|
|
|
bottom (default 'G')
|
2018-03-27 18:23:34 +00:00
|
|
|
toggle (default '<space>')
|
|
|
|
invert (default 'v')
|
|
|
|
unmark (default 'u')
|
|
|
|
yank (default 'y')
|
|
|
|
delete (default 'd')
|
|
|
|
put (default 'p')
|
|
|
|
clear (default 'c')
|
|
|
|
redraw (default '<c-l>')
|
|
|
|
reload (default '<c-r>')
|
|
|
|
read (default ':')
|
|
|
|
shell (default '$')
|
|
|
|
shell-pipe (default '%')
|
|
|
|
shell-wait (default '!')
|
|
|
|
shell-async (default '&')
|
|
|
|
search (default '/')
|
|
|
|
search-back (default '?')
|
|
|
|
search-next (default 'n')
|
|
|
|
search-prev (default 'N')
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-12 13:51:30 +00:00
|
|
|
The following commands are provided by lf without default keybindings:
|
|
|
|
|
2018-04-12 18:48:32 +00:00
|
|
|
draw draw the ui
|
2017-11-18 23:36:01 +00:00
|
|
|
sync synchronizes yanked/deleted files with server
|
|
|
|
echo prints its arguments to the message line
|
|
|
|
cd changes working directory to its argument
|
2018-03-27 17:47:17 +00:00
|
|
|
select changes current file selection to its argument
|
2017-11-18 23:36:01 +00:00
|
|
|
push simulate key pushes given in its argument
|
2017-03-12 13:51:30 +00:00
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
The following command line commands are provided by lf with default
|
|
|
|
keybindings:
|
|
|
|
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-escape (default '<esc>')
|
2018-05-15 21:05:06 +00:00
|
|
|
cmd-complete (default '<tab>')
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-enter (default '<c-j>' and '<enter>')
|
2018-05-15 21:16:49 +00:00
|
|
|
cmd-history-next (default '<c-n>')
|
|
|
|
cmd-history-prev (default '<c-p>')
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-delete (default '<c-d>' and '<delete>')
|
|
|
|
cmd-delete-back (default '<bs>' and '<bs2>')
|
|
|
|
cmd-left (default '<c-b>' and '<left>')
|
|
|
|
cmd-right (default '<c-f>' and '<right>')
|
2018-05-15 21:00:20 +00:00
|
|
|
cmd-home (default '<c-a>' and '<home>')
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-end (default '<c-e>' and '<end>')
|
2018-05-15 21:02:06 +00:00
|
|
|
cmd-delete-home (default '<c-u>')
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-delete-end (default '<c-k>')
|
|
|
|
cmd-delete-unix-word (default '<c-w>')
|
2018-05-15 21:28:11 +00:00
|
|
|
cmd-yank (default '<c-y>')
|
2018-05-13 22:19:26 +00:00
|
|
|
cmd-transpose (default '<c-t>')
|
|
|
|
cmd-interrupt (default '<c-c>')
|
|
|
|
cmd-word (default '<a-f>')
|
|
|
|
cmd-word-back (default '<a-b>')
|
|
|
|
cmd-capitalize-word (default '<a-c>')
|
2018-05-13 22:25:26 +00:00
|
|
|
cmd-delete-word (default '<a-d>')
|
2018-05-13 22:30:53 +00:00
|
|
|
cmd-uppercase-word (default '<a-u>')
|
2018-05-13 22:38:19 +00:00
|
|
|
cmd-lowercase-word (default '<a-l>')
|
2018-05-14 16:38:35 +00:00
|
|
|
cmd-transpose-word (default '<a-t>')
|
2017-03-10 15:53:21 +00:00
|
|
|
|
2016-12-19 21:19:07 +00:00
|
|
|
The following options can be used to customize the behavior of lf:
|
|
|
|
|
2017-07-15 14:06:18 +00:00
|
|
|
dircounts boolean (default off)
|
|
|
|
dirfirst boolean (default on)
|
2018-04-15 16:26:51 +00:00
|
|
|
drawbox boolean (default off)
|
2017-07-15 14:06:18 +00:00
|
|
|
globsearch boolean (default off)
|
|
|
|
hidden boolean (default off)
|
2017-10-30 21:35:31 +00:00
|
|
|
ignorecase boolean (default on)
|
2017-07-15 14:06:18 +00:00
|
|
|
preview boolean (default on)
|
|
|
|
reverse boolean (default off)
|
2017-10-30 21:35:31 +00:00
|
|
|
smartcase boolean (default on)
|
2017-07-15 14:06:18 +00:00
|
|
|
wrapscan boolean (default on)
|
|
|
|
scrolloff integer (default 0)
|
|
|
|
tabstop integer (default 8)
|
2017-09-07 20:01:57 +00:00
|
|
|
filesep string (default "\n")
|
2017-09-08 20:46:31 +00:00
|
|
|
ifs string (default '') (not exported if empty)
|
|
|
|
previewer string (default '') (not filtered if empty)
|
2018-02-22 15:18:30 +00:00
|
|
|
promptfmt string (default "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m")
|
2018-02-17 17:04:30 +00:00
|
|
|
shell string (default 'sh')
|
2017-09-08 20:46:31 +00:00
|
|
|
sortby string (default 'natural')
|
|
|
|
timefmt string (default 'Mon Jan _2 15:04:05 2006')
|
|
|
|
ratios string (default '1:2:3')
|
|
|
|
info string (default '')
|
2016-12-19 21:19:07 +00:00
|
|
|
|
|
|
|
The following variables are exported for shell commands:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
$f current file
|
2017-09-07 20:01:57 +00:00
|
|
|
$fs marked file(s) separated with 'filesep'
|
2017-03-10 13:15:16 +00:00
|
|
|
$fx current file or marked file(s) if any
|
|
|
|
$id id number of the client
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-03-02 20:15:36 +00:00
|
|
|
The following additional keybindings are provided by default:
|
|
|
|
|
|
|
|
map zh set hidden!
|
|
|
|
map zr set reverse!
|
|
|
|
map zn set info
|
|
|
|
map zs set info size
|
|
|
|
map zt set info time
|
|
|
|
map za set info size:time
|
|
|
|
map sn :set sortby natural; set info
|
|
|
|
map ss :set sortby size; set info size
|
|
|
|
map st :set sortby time; set info time
|
|
|
|
map gh cd ~
|
|
|
|
|
|
|
|
The following keybindings to applications are provided by default on unix:
|
|
|
|
|
|
|
|
map e $$EDITOR $f ('vi' if empty)
|
|
|
|
map i $$PAGER $f ('less' if empty)
|
|
|
|
map w $$SHELL ('sh' if empty)
|
|
|
|
|
|
|
|
The following keybindings to applications are provided by default on windows:
|
|
|
|
|
2018-04-28 15:34:24 +00:00
|
|
|
map e $notepad %f%
|
|
|
|
map i $more %f%
|
2018-03-02 20:15:36 +00:00
|
|
|
map w $cmd
|
|
|
|
|
2016-09-15 14:08:05 +00:00
|
|
|
Configuration
|
|
|
|
|
2016-12-19 21:19:07 +00:00
|
|
|
The configuration file should be located at:
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
$XDG_CONFIG_HOME/lf/lfrc
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
|
2016-12-19 21:19:07 +00:00
|
|
|
location should be:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
~/.config/lf/lfrc
|
2016-12-19 21:19:07 +00:00
|
|
|
|
|
|
|
A sample configuration file can be found at
|
2016-09-14 23:18:50 +00:00
|
|
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
|
|
|
|
|
|
|
Prefixes
|
|
|
|
|
|
|
|
The following command prefixes are used by lf:
|
|
|
|
|
2018-03-27 18:23:34 +00:00
|
|
|
: read (default) builtin/custom command
|
|
|
|
$ shell shell command
|
2018-04-06 19:49:50 +00:00
|
|
|
% shell-pipe shell command running with the ui
|
2018-03-27 18:23:34 +00:00
|
|
|
! shell-wait shell command waiting for key press
|
2018-04-06 19:49:50 +00:00
|
|
|
& shell-async shell command running asynchronously
|
2018-03-27 18:23:34 +00:00
|
|
|
/ search search file in current directory
|
|
|
|
? search-back search file in the reverse order
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-05-20 17:30:41 +00:00
|
|
|
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.
|
2016-09-14 23:18:50 +00:00
|
|
|
|
|
|
|
Syntax
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Characters from '#' to newline are comments and ignored:
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
# comments start with '#'
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
There are three special commands ('set', 'map', and 'cmd') and their variants
|
2017-03-10 15:53:21 +00:00
|
|
|
for configuration.
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
'set' is used to set an option which can be boolean, integer, or string:
|
2017-03-10 15:53:21 +00:00
|
|
|
|
|
|
|
set hidden # boolean on
|
|
|
|
set nohidden # boolean off
|
|
|
|
set hidden! # boolean toggle
|
|
|
|
set scrolloff 10 # integer value
|
|
|
|
set sortby time # string value w/o quotes
|
|
|
|
set sortby 'time' # string value with single quotes (whitespaces)
|
|
|
|
set sortby "time" # string value with double quotes (backslash escapes)
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
'map' is used to bind a key to a command which can be builtin command, custom
|
2017-03-10 15:53:21 +00:00
|
|
|
command, or shell command:
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
map gh cd ~ # builtin command
|
2017-03-10 15:53:21 +00:00
|
|
|
map D trash # custom command
|
2017-09-08 20:46:31 +00:00
|
|
|
map i $less $f # shell command
|
2017-03-10 15:53:21 +00:00
|
|
|
map u !du -h . # waiting shell command
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
'cmap' is used to bind a key to a command line command which can only be one of
|
|
|
|
the builtin commands:
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
cmap <c-g> cmd-escape
|
2016-12-19 21:19:07 +00:00
|
|
|
|
|
|
|
You can delete an existing binding by leaving the expression empty:
|
|
|
|
|
2017-03-10 15:53:21 +00:00
|
|
|
map gh # deletes 'gh' mapping
|
|
|
|
cmap <c-g> # deletes '<c-g>' mapping
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
'cmd' is used to define a custom command
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
cmd usage $du -h . | less
|
2016-12-19 21:19:07 +00:00
|
|
|
|
|
|
|
You can delete an existing command by leaving the expression empty:
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
cmd trash # deletes 'trash' command
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
If there is no prefix then ':' is assumed:
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map zt set info time
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
An explicit ':' can be provided to group statements until a newline which is
|
|
|
|
especially useful for 'map' and 'cmd' commands:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map st :set sortby time; set info time
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
If you need multiline you can wrap statements in '{{' and '}}' after the proper
|
2016-12-19 21:19:07 +00:00
|
|
|
prefix.
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map st :{{
|
|
|
|
set sortby time
|
|
|
|
set info time
|
|
|
|
}}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-06-06 18:39:44 +00:00
|
|
|
Key Mappings
|
|
|
|
|
|
|
|
Regular keys are assigned to a command with the usual syntax:
|
|
|
|
|
|
|
|
map a down
|
|
|
|
|
|
|
|
Keys combined with the shift key simply use the uppercase letter:
|
|
|
|
|
|
|
|
map A down
|
|
|
|
|
|
|
|
Special keys are written in between '<' and '>' characters and always use
|
|
|
|
lowercase letters:
|
|
|
|
|
|
|
|
map <enter> down
|
|
|
|
|
|
|
|
Angle brackets can be assigned with their special names:
|
|
|
|
|
|
|
|
map <lt> down
|
|
|
|
map <gt> down
|
|
|
|
|
|
|
|
Function keys are prefixed with 'f' character:
|
|
|
|
|
|
|
|
map <f-1> down
|
|
|
|
|
|
|
|
Keys combined with the control key are prefixed with 'c' character:
|
|
|
|
|
|
|
|
map <c-a> down
|
|
|
|
|
|
|
|
Keys combined with the alt key are assigned in two different ways depending on
|
|
|
|
the behavior of your terminal. Older terminals (e.g. xterm) may set the 8th bit
|
|
|
|
of a character when the alt key is pressed. On these terminals, you can use the
|
|
|
|
corresponding byte for the mapping:
|
|
|
|
|
|
|
|
map á down
|
|
|
|
|
|
|
|
Newer terminals (e.g. gnome-terminal) may prefix the key with an escape key
|
2018-06-06 18:50:15 +00:00
|
|
|
when the alt key is pressed. lf uses the escape delaying mechanism to recognize
|
2018-06-06 18:39:44 +00:00
|
|
|
alt keys in these terminals (delay is 100ms). On these terminals, keys combined
|
|
|
|
with the alt key are prefixed with 'a' character:
|
|
|
|
|
|
|
|
map <a-a> down
|
|
|
|
|
|
|
|
Please note that, some key combinations are not possible due to the way
|
2018-06-06 18:50:15 +00:00
|
|
|
terminals work (e.g. control and h combination sends a backspace key instead).
|
|
|
|
The easiest way to find the name of a key combination is to press the key while
|
|
|
|
lf is running and read the name of the key from the unknown mapping error.
|
2018-06-06 18:39:44 +00:00
|
|
|
|
2018-04-06 19:49:50 +00:00
|
|
|
Push Mappings
|
2016-09-18 16:21:24 +00:00
|
|
|
|
|
|
|
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
|
2017-09-08 20:46:31 +00:00
|
|
|
commands, it can be limiting at times. For this reason 'push' command is
|
2016-09-18 16:21:24 +00:00
|
|
|
provided by lf. This command is used to simulate key pushes given as its
|
2017-09-08 20:46:31 +00:00
|
|
|
arguments. You can 'map' a key to a 'push' command with an argument to create
|
2016-09-18 16:21:24 +00:00
|
|
|
various keybindings.
|
|
|
|
|
|
|
|
This is mainly useful for two purposes. First, it can be used to map a command
|
2016-12-19 21:19:07 +00:00
|
|
|
with a command count:
|
2016-09-18 16:21:24 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map <c-j> push 10j
|
2016-09-18 16:21:24 +00:00
|
|
|
|
2016-12-19 21:19:07 +00:00
|
|
|
Second, it can be used to avoid typing the name when a command takes arguments:
|
2016-09-18 16:21:24 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map r push :rename<space>
|
2016-09-18 16:21:24 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
One thing to be careful is that since 'push' command works with keys instead of
|
2016-12-19 21:19:07 +00:00
|
|
|
commands it is possible to accidentally create recursive bindings:
|
2016-09-18 16:21:24 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
map j push 2j
|
2016-09-18 16:21:24 +00:00
|
|
|
|
|
|
|
These types of bindings create a deadlock when executed.
|
|
|
|
|
2018-04-06 19:52:15 +00:00
|
|
|
Shell Commands
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-04-06 19:49:50 +00:00
|
|
|
Regular shell commands are the most basic command type that is useful for 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 this:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
cmd trash ${{
|
|
|
|
mkdir -p ~/.trash
|
2017-09-07 20:01:57 +00:00
|
|
|
if [ -z "$fs" ]; then
|
2017-09-16 19:11:43 +00:00
|
|
|
mv "$f" ~/.trash
|
2017-03-10 13:15:16 +00:00
|
|
|
else
|
2017-09-16 19:11:43 +00:00
|
|
|
IFS="`printf '\n\t'`"; mv $fs ~/.trash
|
2017-03-10 13:15:16 +00:00
|
|
|
fi
|
|
|
|
}}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
We check '$fs' to see if there are any marked files. Otherwise we just delete
|
|
|
|
the current file. Since this is such a common pattern, a separate '$fx'
|
2016-12-19 21:19:07 +00:00
|
|
|
variable is provided. We can use this variable to get rid of the conditional:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
cmd trash ${{
|
|
|
|
mkdir -p ~/.trash
|
2017-09-16 19:11:43 +00:00
|
|
|
IFS="`printf '\n\t'`"; mv $fx ~/.trash
|
2017-03-10 13:15:16 +00:00
|
|
|
}}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
|
|
|
The trash directory is checked each time the command is executed. We can move
|
2016-12-19 21:19:07 +00:00
|
|
|
it outside of the command so it would only run once at startup:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
${{ mkdir -p ~/.trash }}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-16 19:11:43 +00:00
|
|
|
cmd trash ${{ IFS="`printf '\n\t'`"; mv $fx ~/.trash }}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Since these are one liners, we can drop '{{' and '}}':
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
$mkdir -p ~/.trash
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-16 19:11:43 +00:00
|
|
|
cmd trash $IFS="`printf '\n\t'`"; mv $fx ~/.trash
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Finally note that we set 'IFS' variable manually in these commands. Instead we
|
|
|
|
could use the 'ifs' option to set it for all shell commands (i.e. 'set ifs
|
|
|
|
"\n"'). This can be especially useful for interactive use (e.g. '$rm $f' or
|
|
|
|
'$rm $fs' would simply work). This option is not set by default as it can
|
2017-09-07 20:01:57 +00:00
|
|
|
behave unexpectedly for new users. However, use of this option is highly
|
|
|
|
recommended and it is assumed in the rest of the documentation.
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-04-06 19:52:15 +00:00
|
|
|
Piping Shell Commands
|
2018-04-06 19:49:50 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2018-04-06 19:52:15 +00:00
|
|
|
Waiting Shell Commands
|
2018-04-06 19:49:50 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2018-04-06 19:52:15 +00:00
|
|
|
Asynchronous Shell Commands
|
2018-04-06 19:49:50 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2017-02-11 13:14:41 +00:00
|
|
|
Remote Commands
|
|
|
|
|
|
|
|
One of the more advanced features in lf is remote commands. All clients connect
|
|
|
|
to a server on startup. It is possible to send commands to all or any of the
|
|
|
|
connected clients over the common server. This is used internally to notify
|
|
|
|
file selection changes to other clients.
|
|
|
|
|
|
|
|
To use this feature, you need to use a client which supports communicating with
|
|
|
|
a UNIX-domain socket. OpenBSD implementation of netcat (nc) is one such
|
|
|
|
example. You can use it to send a command to the socket file:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-02-11 13:34:48 +00:00
|
|
|
Since such a client may not be available everywhere, lf comes bundled with a
|
2017-02-11 13:14:41 +00:00
|
|
|
command line flag to be used as such. When using lf, you do not need to specify
|
|
|
|
the address of the socket file. This is the recommended way of using remote
|
|
|
|
commands since it is shorter and immune to socket file address changes:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
lf -remote 'send echo hello world'
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
In this command 'send' is used to send the rest of the string as a command to
|
2017-02-11 13:14:41 +00:00
|
|
|
all connected clients. You can optionally give it an id number to send a
|
|
|
|
command to a single client:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
lf -remote 'send 1000 echo hello world'
|
2017-02-11 13:14:41 +00:00
|
|
|
|
|
|
|
All clients have a unique id number but you may not be aware of the id number
|
2017-09-08 20:46:31 +00:00
|
|
|
when you are writing a command. For this purpose, an '$id' variable is exported
|
2017-02-11 13:14:41 +00:00
|
|
|
to the environment for shell commands. You can use it to send a remote command
|
|
|
|
from a client to the server which in return sends a command back to itself. So
|
|
|
|
now you can display a message in the current client by calling the following in
|
|
|
|
a shell command:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
lf -remote "send $id echo hello world"
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Since lf does not have control flow syntax, remote commands are used for such
|
2018-04-06 19:49:50 +00:00
|
|
|
needs. For example, you can configure the number of columns in the ui with
|
|
|
|
respect to the terminal width as follows:
|
|
|
|
|
|
|
|
cmd recol ${{
|
|
|
|
w=$(tput cols)
|
|
|
|
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"
|
2017-03-10 13:15:16 +00:00
|
|
|
else
|
2018-04-06 19:49:50 +00:00
|
|
|
lf -remote "send $id set ratios 1:2:3:5"
|
2017-03-10 13:15:16 +00:00
|
|
|
fi
|
|
|
|
}}
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Besides 'send' command, there are also two commands to get or set the current
|
|
|
|
file selection. Two possible modes 'copy' and 'move' specify whether selected
|
|
|
|
files are to be copied or moved. File names are separated by newline character.
|
|
|
|
Setting the file selection is done with 'save' command:
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-17 12:01:53 +00:00
|
|
|
lf -remote "$(printf 'save\ncopy\nfoo.txt\nbar.txt\nbaz.txt\n')"
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Getting the file selection is similarly done with 'load' command:
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-17 12:01:53 +00:00
|
|
|
resp=$(lf -remote 'load')
|
2017-09-08 20:46:31 +00:00
|
|
|
mode=$(echo "$resp" | sed -n '1p')
|
|
|
|
list=$(echo "$resp" | sed '1d')
|
2017-03-10 13:15:16 +00:00
|
|
|
if [ $mode = 'copy' ]; then
|
2017-09-08 20:46:31 +00:00
|
|
|
# do something with $list
|
2017-03-10 13:15:16 +00:00
|
|
|
elif [ $mode = 'move' ]; then
|
2017-09-08 20:46:31 +00:00
|
|
|
# do something else with $list
|
2017-03-10 13:15:16 +00:00
|
|
|
fi
|
2017-02-11 13:14:41 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
Lastly, there is a 'conn' command to connect the server as a client. This
|
2017-02-11 13:14:41 +00:00
|
|
|
should not be needed for users.
|
|
|
|
|
2016-09-15 14:08:05 +00:00
|
|
|
File Operations
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
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
|
2016-09-15 14:08:05 +00:00
|
|
|
file on the disk, but only records its name to memory. The actual file
|
2017-09-08 20:46:31 +00:00
|
|
|
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')
|
2016-11-06 15:09:18 +00:00
|
|
|
are picked instead of the other common convention (e.g. copy and cut) to
|
|
|
|
resemble the default keybinds for these operations.
|
2016-09-15 14:08:05 +00:00
|
|
|
|
2017-09-17 16:36:37 +00:00
|
|
|
You can customize these operations by defining a 'put' 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 ${{
|
|
|
|
load=$(lf -remote 'load')
|
|
|
|
mode=$(echo "$load" | sed -n '1p')
|
|
|
|
list=$(echo "$load" | sed '1d')
|
|
|
|
if [ $mode = 'copy' ]; then
|
2017-10-26 18:37:16 +00:00
|
|
|
cp -R -n $list .
|
2017-09-17 16:36:37 +00:00
|
|
|
elif [ $mode = 'move' ]; then
|
2017-10-26 18:37:16 +00:00
|
|
|
mv -n $list .
|
2017-09-17 16:36:37 +00:00
|
|
|
fi
|
2018-01-29 15:08:51 +00:00
|
|
|
lf -remote "send $id reload"
|
2017-10-26 18:37:16 +00:00
|
|
|
lf -remote "$(printf 'save\nmove\n\n')"
|
|
|
|
lf -remote "send sync"
|
2017-09-17 16:36:37 +00:00
|
|
|
}}
|
|
|
|
|
2017-10-26 18:37:16 +00:00
|
|
|
Some useful things are to use the backup option ('--backup') with 'cp' and 'mv'
|
|
|
|
commands if they support it (i.e. GNU implementation), change the command type
|
|
|
|
to asynchronous, or use 'rsync' command with progress bar option for copying
|
|
|
|
and feed the progress to the client periodically with remote 'echo' calls.
|
2017-09-17 16:36:37 +00:00
|
|
|
|
2017-02-11 13:28:45 +00:00
|
|
|
By default, lf does not provide an actual file deletion command to protect new
|
|
|
|
users. You can define such a command and optionally assign a key if you like.
|
|
|
|
An example command to move selected files to a trash folder and remove files
|
|
|
|
completely are provided in the example configuration file.
|
|
|
|
|
2016-09-14 23:18:50 +00:00
|
|
|
Opening Files
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
You can use 'open-file' command to open a file. This is a special command
|
|
|
|
called by 'open' when the current file is not a directory. Normally a user maps
|
|
|
|
the 'open' command to a key (default 'l') and customize 'open-file' command as
|
2016-12-19 21:19:07 +00:00
|
|
|
desired. You can define it just as you would define any other command:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
cmd open-file $vi $fx
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2016-12-19 21:19:07 +00:00
|
|
|
It is possible to use different command types:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-07 20:01:57 +00:00
|
|
|
cmd open-file &xdg-open $f
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
You may want to use either file extensions or mime types from 'file' command:
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
cmd open-file ${{
|
2017-09-07 20:01:57 +00:00
|
|
|
case $(file --mime-type $f -b) in
|
2017-09-08 20:46:31 +00:00
|
|
|
text/*) vi $fx;;
|
2017-09-07 20:01:57 +00:00
|
|
|
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
|
2017-03-10 13:15:16 +00:00
|
|
|
esac
|
|
|
|
}}
|
2016-09-14 23:18:50 +00:00
|
|
|
|
2018-03-02 20:15:36 +00:00
|
|
|
Following commands are provided by default:
|
|
|
|
|
2018-04-28 15:34:24 +00:00
|
|
|
cmd open-file &start %f% # windows
|
|
|
|
cmd open-file &open "$f" # mac
|
|
|
|
cmd open-file &xdg-open "$f" # others
|
2018-03-02 20:15:36 +00:00
|
|
|
|
|
|
|
You may also use any other existing file openers as you like. Possible options
|
|
|
|
are 'libfile-mimeinfo-perl' (executable name is 'mimeopen'), 'rifle' (ranger's
|
|
|
|
default file opener), or 'mimeo' to name a few.
|
2016-09-15 18:44:06 +00:00
|
|
|
|
|
|
|
Previewing Files
|
|
|
|
|
|
|
|
lf previews files on the preview pane by printing the file until the end or the
|
|
|
|
preview pane is filled. This output can be enhanced by providing a custom
|
|
|
|
preview script for filtering. This can be used to highlight source codes, list
|
|
|
|
contents of archive files or view pdf or image files as text to name few. For
|
|
|
|
coloring lf recognizes ansi escape codes.
|
|
|
|
|
2017-09-08 20:46:31 +00:00
|
|
|
In order to use this feature you need to set the value of 'previewer' option to
|
2016-09-15 18:44:06 +00:00
|
|
|
the path of an executable file. lf passes the current file name as the first
|
|
|
|
argument and the height of the preview pane as the second argument when running
|
|
|
|
this file. Output of the execution is printed in the preview pane. You may want
|
2016-12-19 21:19:07 +00:00
|
|
|
to use the same script in your pager mapping as well if any:
|
2016-09-15 18:44:06 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
set previewer ~/.config/lf/pv.sh
|
2017-09-07 20:01:57 +00:00
|
|
|
map i $~/.config/lf/pv.sh $f | less -R
|
2016-09-15 18:44:06 +00:00
|
|
|
|
|
|
|
Since this script is called for each file selection change it needs to be as
|
|
|
|
efficient as possible and this responsibility is left to the user. You may use
|
|
|
|
file extensions to determine the type of file more efficiently compared to
|
2017-09-08 20:46:31 +00:00
|
|
|
obtaining mime types from 'file' command. Extensions can then be used to match
|
2016-12-19 21:19:07 +00:00
|
|
|
cleanly within a conditional:
|
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
#!/bin/sh
|
2016-12-19 21:19:07 +00:00
|
|
|
|
2017-03-10 13:15:16 +00:00
|
|
|
case "$1" in
|
|
|
|
*.tar*) tar tf "$1";;
|
|
|
|
*.zip) unzip -l "$1";;
|
|
|
|
*.rar) unrar l "$1";;
|
|
|
|
*.7z) 7z l "$1";;
|
|
|
|
*.pdf) pdftotext "$1" -;;
|
|
|
|
*) highlight -O ansi "$1" || cat "$1";;
|
|
|
|
esac
|
2016-09-15 18:44:06 +00:00
|
|
|
|
|
|
|
Another important consideration for efficiency is the use of programs with
|
2017-09-08 20:46:31 +00:00
|
|
|
short startup times for preview. For this reason, 'highlight' is recommended
|
|
|
|
over 'pygmentize' for syntax highlighting. Besides, it is also important that
|
2016-09-15 18:44:06 +00:00
|
|
|
the application is processing the file on the fly rather than first reading it
|
|
|
|
to the memory and then do the processing afterwards. This is especially
|
|
|
|
relevant for big files. lf automatically closes the previewer script output
|
|
|
|
pipe with a SIGPIPE when enough lines are read. When everything else fails, you
|
|
|
|
can make use of the height argument to only feed the first portion of the file
|
|
|
|
to a program for preview.
|
2018-04-20 21:11:54 +00:00
|
|
|
|
|
|
|
Colorschemes
|
|
|
|
|
|
|
|
lf tries to automatically adapt its colors to the environment. On startup,
|
|
|
|
first '$LS_COLORS' environment variable is checked. This variable is used by
|
|
|
|
GNU ls to configure its colors based on file types and extensions. The value of
|
|
|
|
this variable is often set by GNU dircolors in a shell configuration file.
|
|
|
|
dircolors program itself can be configured with a configuration file. dircolors
|
|
|
|
supports 256 colors along with common attributes such as bold and underline.
|
|
|
|
|
|
|
|
If '$LS_COLORS' variable is not set, '$LSCOLORS' variable is checked instead.
|
|
|
|
This variable is used by ls programs on unix systems such as Mac and BSDs. This
|
|
|
|
variable has a simple syntax and supports 8 colors and bold attribute.
|
|
|
|
|
|
|
|
If both of these environment variables are not set, then lf fallbacks to its
|
|
|
|
default colorscheme. Default lf colors are taken from GNU dircolors defaults.
|
|
|
|
These defaults use 8 basic colors and bold attribute.
|
|
|
|
|
|
|
|
Keeping this mechanism in mind, you can configure lf colors in two different
|
|
|
|
ways. First, you can configure 8 basic colors used by your terminal and lf
|
|
|
|
should pick up those colors automatically. Depending on your terminal, you
|
|
|
|
should be able to select your colors from a 24-bit palette. This is the
|
|
|
|
recommended approach as colors used by other programs will also match each
|
|
|
|
other.
|
|
|
|
|
|
|
|
Second, you can set the values of environmental variables mentioned above for
|
|
|
|
fine grained customization. This is useful to change colors used for different
|
|
|
|
file types and extensions. '$LS_COLORS' is more powerful than '$LSCOLORS' and
|
|
|
|
it can be used even when GNU programs are not installed on the system. You can
|
|
|
|
combine this second method with the first method for best results.
|
2016-09-13 21:40:14 +00:00
|
|
|
*/
|
|
|
|
package main
|