This commit is contained in:
Gokcehan 2017-09-08 23:47:37 +03:00
parent 1df7ca3408
commit 6c9f8746c0

View File

@ -8,7 +8,7 @@ lf is a terminal file manager.
Source code can be found in the repository at
https://github.com/gokcehan/lf.
This documentation can either be read from terminal using "lf -doc" or
This documentation can either be read from terminal using 'lf -doc' or
online at https://godoc.org/github.com/gokcehan/lf.
@ -16,32 +16,32 @@ Reference
The following commands are provided by lf with default keybindings:
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")
bot (default "G")
top (default "gg")
read (default ":")
read-shell (default "$")
read-shell-wait (default "!")
read-shell-async (default "&")
search (default "/")
search-back (default "?")
search-next (default "n")
search-prev (default "N")
toggle (default "<space>")
invert (default "v")
yank (default "y")
clear (default "c")
delete (default "d")
put (default "p")
renew (default "<c-l>")
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')
bot (default 'G')
top (default 'gg')
read (default ':')
read-shell (default '$')
read-shell-wait (default '!')
read-shell-async (default '&')
search (default '/')
search-back (default '?')
search-next (default 'n')
search-prev (default 'N')
toggle (default '<space>')
invert (default 'v')
yank (default 'y')
clear (default 'c')
delete (default 'd')
put (default 'p')
renew (default '<c-l>')
The following commands are provided by lf without default keybindings:
@ -53,22 +53,22 @@ The following commands are provided by lf without default keybindings:
The following command line commands are provided by lf with default
keybindings:
cmd-escape (default "<esc>")
cmd-comp (default "<tab>")
cmd-enter (default "<c-j>" and "<enter>")
cmd-hist-next (default "<c-n>")
cmd-hist-prev (default "<c-p>")
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>")
cmd-beg (default "<c-a>" and "<home>")
cmd-end (default "<c-e>" and "<end>")
cmd-delete-end (default "<c-k>")
cmd-delete-beg (default "<c-u>")
cmd-delete-word (default "<c-w>")
cmd-put (default "<c-y>")
cmd-transpose (default "<c-t>")
cmd-escape (default '<esc>')
cmd-comp (default '<tab>')
cmd-enter (default '<c-j>' and '<enter>')
cmd-hist-next (default '<c-n>')
cmd-hist-prev (default '<c-p>')
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>')
cmd-beg (default '<c-a>' and '<home>')
cmd-end (default '<c-e>' and '<end>')
cmd-delete-end (default '<c-k>')
cmd-delete-beg (default '<c-u>')
cmd-delete-word (default '<c-w>')
cmd-put (default '<c-y>')
cmd-transpose (default '<c-t>')
The following options can be used to customize the behavior of lf:
@ -84,13 +84,13 @@ The following options can be used to customize the behavior of lf:
scrolloff integer (default 0)
tabstop integer (default 8)
filesep string (default "\n")
ifs string (default "") (not exported if empty)
previewer string (default "") (not filtered if empty)
shell string (default "/bin/sh")
sortby string (default "natural")
timefmt string (default "Mon Jan _2 15:04:05 2006")
ratios string (default "1:2:3")
info string (default "")
ifs string (default '') (not exported if empty)
previewer string (default '') (not filtered if empty)
shell string (default '/bin/sh')
sortby string (default 'natural')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default '1:2:3')
info string (default '')
The following variables are exported for shell commands:
@ -104,9 +104,9 @@ Configuration
The configuration file should be located at:
$XDG_CONFIG_HOME/lf/lfrc"
$XDG_CONFIG_HOME/lf/lfrc
If "$XDG_CONFIG_HOME" is not set, it defaults to "$HOME/.config" so the
If '$XDG_CONFIG_HOME' is not set, it defaults to '$HOME/.config' so the
location should be:
~/.config/lf/lfrc
@ -134,14 +134,14 @@ that by default these modes are mapped to the prefix keys above.
Syntax
Characters from "#" to "\n" are comments and ignored:
Characters from '#' to newline are comments and ignored:
# comments start with '#'
There are three special commands ("set", "map", and "cmd") and their
There are three special commands ('set', 'map', and 'cmd') and their
variants for configuration.
"set" is used to set an option which can be boolean, integer, or string:
'set' is used to set an option which can be boolean, integer, or string:
set hidden # boolean on
set nohidden # boolean off
@ -151,15 +151,15 @@ variants for configuration.
set sortby 'time' # string value with single quotes (whitespaces)
set sortby "time" # string value with double quotes (backslash escapes)
"map" is used to bind a key to a command which can be builtin command,
'map' is used to bind a key to a command which can be builtin command,
custom command, or shell command:
map gh cd ~ # builtin command
map D trash # custom command
map i $less "$f" # shell command
map i $less $f # shell command
map u !du -h . # waiting shell command
"cmap" is used to bind a key to a command line command which can only be one
'cmap' is used to bind a key to a command line command which can only be one
of the builtin commands:
cmap <c-g> cmd-escape
@ -169,24 +169,24 @@ You can delete an existing binding by leaving the expression empty:
map gh # deletes 'gh' mapping
cmap <c-g> # deletes '<c-g>' mapping
"cmd" is used to define a custom command
'cmd' is used to define a custom command
cmd usage $du -h . | less
You can delete an existing command by leaving the expression empty:
cmd trash # deletes trash command
cmd trash # deletes 'trash' command
If there is no prefix then ":" is assumed:
If there is no prefix then ':' is assumed:
map zt set info time
An explicit ":" can be provided to group statements until a "\n" occurs
which is especially useful for "map" and "cmd" commands:
An explicit ':' can be provided to group statements until a newline which is
especially useful for 'map' and 'cmd' commands:
map st :set sortby time; set info time
If you need multiline you can wrap statements in "{{" and "}}" after the
If you need multiline you can wrap statements in '{{' and '}}' after the
proper prefix.
map st :{{
@ -199,9 +199,9 @@ Mappings
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 commands, it can be limiting at times. For this reason "push" command
other commands, it can be limiting at times. For this reason 'push' command
is provided by lf. This command is used to simulate key pushes given as its
arguments. You can "map" a key to a "push" command with an argument to
arguments. You can 'map' a key to a 'push' command with an argument to
create various keybindings.
This is mainly useful for two purposes. First, it can be used to map a
@ -214,7 +214,7 @@ arguments:
map r push :rename<space>
One thing to be careful is that since "push" command works with keys instead
One thing to be careful is that since 'push' command works with keys instead
of commands it is possible to accidentally create recursive bindings:
map j push 2j
@ -238,9 +238,9 @@ A first attempt to write such a command may look like this:
fi
}}
We check "$fs" to see if there are any marked files. Otherwise we just
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" variable is provided. We can use this variable to get rid of the
'$fx' variable is provided. We can use this variable to get rid of the
conditional:
cmd trash ${{
@ -255,16 +255,16 @@ move it outside of the command so it would only run once at startup:
cmd trash ${{ IFS="'printf '\n\t''"; mv --backup=numbered $fx ~/.trash }}
Since these are one liners, we can drop "{{" and "}}":
Since these are one liners, we can drop '{{' and '}}':
$mkdir -p ~/.trash
cmd trash $IFS="'printf '\n\t''"; mv --backup=numbered $fx ~/.trash
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
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
behave unexpectedly for new users. However, use of this option is highly
recommended and it is assumed in the rest of the documentation.
@ -290,14 +290,14 @@ changes:
lf -remote 'send echo hello world'
In this command "send" is used to send the rest of the string as a command
In this command 'send' is used to send the rest of the string as a command
to all connected clients. You can optionally give it an id number to send a
command to a single client:
lf -remote 'send 1000 echo hello world'
All clients have a unique id number but you may not be aware of the id
number when you are writing a command. For this purpose, an "$id" variable
number when you are writing a command. For this purpose, an '$id' variable
is exported 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
@ -311,45 +311,51 @@ You can implement a safe rename command which does not overwrite an existing
file or directory as such:
cmd rename ${{
if [ -e "$1" ]; then
if [ -e $1 ]; then
lf -remote "send $id echo file exists"
else
mv "$f" "$1"
mv $f $1
fi
}}
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 ":"
character. Setting the file selection is done with "save" command:
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:
lf -remote 'save copy foo.txt:bar.txt:baz.txt'
nc -U /tmp/lf.${USER}.sock << 'EOF'
save
copy
foo.txt
bar.txt
baz.txt
Getting the file selection is similarly done with "load" command. You may
need to parse the response as such to achieve what you need:
EOF
Getting the file selection is similarly done with 'load' command:
resp=$(echo 'load' | nc -U /tmp/lf.${USER}.sock)
mode=$(echo $resp | cut -d' ' -f1)
list=$(echo $resp | cut -d' ' -f2-)
mode=$(echo "$resp" | sed -n '1p')
list=$(echo "$resp" | sed '1d')
if [ $mode = 'copy' ]; then
# do something with the $list
# do something with $list
elif [ $mode = 'move' ]; then
# do something else with the $list
# do something else with $list
fi
Lastly, there is a "conn" command to connect the server as a client. This
Lastly, there is a 'conn' command to connect the server as a client. This
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
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)
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.
By default, lf does not provide an actual file deletion command to protect
@ -360,33 +366,33 @@ files completely are provided in the example configuration file.
Opening Files
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"
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 desired. You can define it just as you would define any other
command:
cmd open-file $vim $fx
cmd open-file $vi $fx
It is possible to use different command types:
cmd open-file &xdg-open $f
You may want to use either file extensions or mime types from "file"
You may want to use either file extensions or mime types from 'file'
command:
cmd open-file ${{
case $(file --mime-type $f -b) in
text/*) vim $fx;;
text/*) vi $fx;;
*) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
esac
}}
lf does not come bundled with a file opener. You can use any of the existing
file openers as you like. Possible options are "open" (for Mac OS X only),
"xdg-utils" (executable name is "xdg-open"), "libfile-mimeinfo-perl"
(executable name is "mimeopen"), "rifle" (ranger's default file opener), or
"mimeo" to name a few.
file openers as you like. Possible options are 'open' (for Mac OS X only),
'xdg-utils' (executable name is 'xdg-open'), 'libfile-mimeinfo-perl'
(executable name is 'mimeopen'), 'rifle' (ranger's default file opener), or
'mimeo' to name a few.
Previewing Files
@ -397,7 +403,7 @@ 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.
In order to use this feature you need to set the value of "previewer" option
In order to use this feature you need to set the value of 'previewer' option
to 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
@ -410,7 +416,7 @@ any:
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 obtaining mime types from "file" command. Extensions can then be used to
to obtaining mime types from 'file' command. Extensions can then be used to
match cleanly within a conditional:
#!/bin/sh
@ -425,8 +431,8 @@ match cleanly within a conditional:
esac
Another important consideration for efficiency is the use of programs with
short startup times for preview. For this reason, "highlight" is recommended
over "pygmentize" for syntax highlighting. Besides, it is also important
short startup times for preview. For this reason, 'highlight' is recommended
over 'pygmentize' for syntax highlighting. Besides, it is also important
that 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