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 Source code can be found in the repository at
https://github.com/gokcehan/lf. 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. online at https://godoc.org/github.com/gokcehan/lf.
@ -16,32 +16,32 @@ Reference
The following commands are provided by lf with default keybindings: The following commands are provided by lf with default keybindings:
up (default "k" and "<up>") up (default 'k' and '<up>')
half-up (default "<c-u>") half-up (default '<c-u>')
page-up (default "<c-b>") page-up (default '<c-b>')
down (default "j" and "<down>") down (default 'j' and '<down>')
half-down (default "<c-d>") half-down (default '<c-d>')
page-down (default "<c-f>") page-down (default '<c-f>')
updir (default "h" and "<left>") updir (default 'h' and '<left>')
open (default "l" and "<right>") open (default 'l' and '<right>')
quit (default "q") quit (default 'q')
bot (default "G") bot (default 'G')
top (default "gg") top (default 'gg')
read (default ":") read (default ':')
read-shell (default "$") read-shell (default '$')
read-shell-wait (default "!") read-shell-wait (default '!')
read-shell-async (default "&") read-shell-async (default '&')
search (default "/") search (default '/')
search-back (default "?") search-back (default '?')
search-next (default "n") search-next (default 'n')
search-prev (default "N") search-prev (default 'N')
toggle (default "<space>") toggle (default '<space>')
invert (default "v") invert (default 'v')
yank (default "y") yank (default 'y')
clear (default "c") clear (default 'c')
delete (default "d") delete (default 'd')
put (default "p") put (default 'p')
renew (default "<c-l>") renew (default '<c-l>')
The following commands are provided by lf without default keybindings: 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 The following command line commands are provided by lf with default
keybindings: keybindings:
cmd-escape (default "<esc>") cmd-escape (default '<esc>')
cmd-comp (default "<tab>") cmd-comp (default '<tab>')
cmd-enter (default "<c-j>" and "<enter>") cmd-enter (default '<c-j>' and '<enter>')
cmd-hist-next (default "<c-n>") cmd-hist-next (default '<c-n>')
cmd-hist-prev (default "<c-p>") cmd-hist-prev (default '<c-p>')
cmd-delete (default "<c-d>" and "<delete>") cmd-delete (default '<c-d>' and '<delete>')
cmd-delete-back (default "<bs>" and "<bs2>") cmd-delete-back (default '<bs>' and '<bs2>')
cmd-left (default "<c-b>" and "<left>") cmd-left (default '<c-b>' and '<left>')
cmd-right (default "<c-f>" and "<right>") cmd-right (default '<c-f>' and '<right>')
cmd-beg (default "<c-a>" and "<home>") cmd-beg (default '<c-a>' and '<home>')
cmd-end (default "<c-e>" and "<end>") cmd-end (default '<c-e>' and '<end>')
cmd-delete-end (default "<c-k>") cmd-delete-end (default '<c-k>')
cmd-delete-beg (default "<c-u>") cmd-delete-beg (default '<c-u>')
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>')
The following options can be used to customize the behavior of lf: 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) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)
filesep string (default "\n") filesep string (default "\n")
ifs string (default "") (not exported if empty) ifs string (default '') (not exported if empty)
previewer string (default "") (not filtered if empty) previewer string (default '') (not filtered if empty)
shell string (default "/bin/sh") shell string (default '/bin/sh')
sortby string (default "natural") sortby string (default 'natural')
timefmt string (default "Mon Jan _2 15:04:05 2006") timefmt string (default 'Mon Jan _2 15:04:05 2006')
ratios string (default "1:2:3") ratios string (default '1:2:3')
info string (default "") info string (default '')
The following variables are exported for shell commands: The following variables are exported for shell commands:
@ -104,9 +104,9 @@ Configuration
The configuration file should be located at: 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: location should be:
~/.config/lf/lfrc ~/.config/lf/lfrc
@ -134,14 +134,14 @@ that by default these modes are mapped to the prefix keys above.
Syntax Syntax
Characters from "#" to "\n" are comments and ignored: Characters from '#' to newline are comments and ignored:
# comments start with '#' # 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. 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 hidden # boolean on
set nohidden # boolean off 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 single quotes (whitespaces)
set sortby "time" # string value with double quotes (backslash escapes) 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: custom command, or shell command:
map gh cd ~ # builtin command map gh cd ~ # builtin command
map D trash # custom 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 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: of the builtin commands:
cmap <c-g> cmd-escape 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 map gh # deletes 'gh' mapping
cmap <c-g> # deletes '<c-g>' 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 cmd usage $du -h . | less
You can delete an existing command by leaving the expression empty: 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 map zt set info time
An explicit ":" can be provided to group statements until a "\n" occurs An explicit ':' can be provided to group statements until a newline which is
which is especially useful for "map" and "cmd" commands: especially useful for 'map' and 'cmd' commands:
map st :set sortby time; set info time 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. proper prefix.
map st :{{ map st :{{
@ -199,9 +199,9 @@ 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
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 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. create various keybindings.
This is mainly useful for two purposes. First, it can be used to map a 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> 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: of commands it is possible to accidentally create recursive bindings:
map j push 2j map j push 2j
@ -238,9 +238,9 @@ A first attempt to write such a command may look like this:
fi 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 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: conditional:
cmd trash ${{ 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 }} 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 $mkdir -p ~/.trash
cmd trash $IFS="'printf '\n\t''"; mv --backup=numbered $fx ~/.trash cmd trash $IFS="'printf '\n\t''"; mv --backup=numbered $fx ~/.trash
Finally note that we set "IFS" variable manually in these commands. Instead 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 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" 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 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 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.
@ -290,14 +290,14 @@ changes:
lf -remote 'send echo hello world' 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 to all connected clients. You can optionally give it an id number to send a
command to a single client: command to a single client:
lf -remote 'send 1000 echo hello world' lf -remote 'send 1000 echo hello world'
All clients have a unique id number but you may not be aware of the id 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 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 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 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: file or directory as such:
cmd rename ${{ cmd rename ${{
if [ -e "$1" ]; then if [ -e $1 ]; then
lf -remote "send $id echo file exists" lf -remote "send $id echo file exists"
else else
mv "$f" "$1" mv $f $1
fi fi
}} }}
Besides "send" command, there are also two commands to get or set the Besides 'send' command, there are also two commands to get or set the
current file selection. Two possible modes "copy" and "move" specify whether current file selection. Two possible modes 'copy' and 'move' specify whether
selected files are to be copied or moved. File names are separated ":" selected files are to be copied or moved. File names are separated by
character. Setting the file selection is done with "save" command: 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 EOF
need to parse the response as such to achieve what you need:
Getting the file selection is similarly done with 'load' command:
resp=$(echo 'load' | nc -U /tmp/lf.${USER}.sock) resp=$(echo 'load' | nc -U /tmp/lf.${USER}.sock)
mode=$(echo $resp | cut -d' ' -f1) mode=$(echo "$resp" | sed -n '1p')
list=$(echo $resp | cut -d' ' -f2-) list=$(echo "$resp" | sed '1d')
if [ $mode = 'copy' ]; then if [ $mode = 'copy' ]; then
# do something with the $list # do something with $list
elif [ $mode = 'move' ]; then elif [ $mode = 'move' ]; then
# do something else with the $list # do something else with $list
fi 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. should not be needed for users.
File Operations File Operations
lf uses the underlying "cp" and "mv" shell commands for file operations. For 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 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 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 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) 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 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) 'put') are picked instead of the other common convention (e.g. copy and cut)
to resemble the default keybinds for these operations. to resemble the default keybinds for these operations.
By default, lf does not provide an actual file deletion command to protect 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 Opening Files
You can use "open-file" command to open a file. This is a special command 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 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" 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 as desired. You can define it just as you would define any other
command: command:
cmd open-file $vim $fx cmd open-file $vi $fx
It is possible to use different command types: It is possible to use different command types:
cmd open-file &xdg-open $f 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: command:
cmd open-file ${{ cmd open-file ${{
case $(file --mime-type $f -b) in 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;; *) for f in $fx; do xdg-open $f > /dev/null 2> /dev/null & done;;
esac esac
}} }}
lf does not come bundled with a file opener. You can use any of the existing 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), file openers as you like. Possible options are 'open' (for Mac OS X only),
"xdg-utils" (executable name is "xdg-open"), "libfile-mimeinfo-perl" 'xdg-utils' (executable name is 'xdg-open'), 'libfile-mimeinfo-perl'
(executable name is "mimeopen"), "rifle" (ranger's default file opener), or (executable name is 'mimeopen'), 'rifle' (ranger's default file opener), or
"mimeo" to name a few. 'mimeo' to name a few.
Previewing Files 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 codes, list contents of archive files or view pdf or image files as text to
name few. For coloring lf recognizes ansi escape codes. 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 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 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 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 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 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 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: match cleanly within a conditional:
#!/bin/sh #!/bin/sh
@ -425,8 +431,8 @@ match cleanly within a conditional:
esac esac
Another important consideration for efficiency is the use of programs with Another important consideration for efficiency is the use of programs with
short startup times for preview. For this reason, "highlight" is recommended short startup times for preview. For this reason, 'highlight' is recommended
over "pygmentize" for syntax highlighting. Besides, it is also important over 'pygmentize' for syntax highlighting. Besides, it is also important
that the application is processing the file on the fly rather than first 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 reading it to the memory and then do the processing afterwards. This is
especially relevant for big files. lf automatically closes the previewer especially relevant for big files. lf automatically closes the previewer