use spaces for indentation in documentation
This commit is contained in:
parent
20f38b96f1
commit
0969514f10
291
doc.go
291
doc.go
@ -12,74 +12,74 @@ 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:
|
||||||
|
|
||||||
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
|
||||||
push simulate key pushes given in its argument
|
push simulate key pushes given in its argument
|
||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dirfirst bool (default on)
|
dirfirst boolean (default on)
|
||||||
hidden bool (default off)
|
hidden boolean (default off)
|
||||||
preview bool (default on)
|
preview boolean (default on)
|
||||||
reverse bool (default off)
|
reverse boolean (default off)
|
||||||
scrolloff int (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop int (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default ":")
|
filesep string (default ":")
|
||||||
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:
|
||||||
|
|
||||||
$f current file
|
$f current file
|
||||||
$fs marked file(s) separated with ':'
|
$fs marked file(s) separated with ':'
|
||||||
$fx current file or marked file(s) if any
|
$fx current file or marked file(s) if any
|
||||||
$id id number of the client
|
$id id number of the client
|
||||||
|
|
||||||
Configuration
|
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
|
||||||
|
|
||||||
A sample configuration file can be found at
|
A sample configuration file can be found at
|
||||||
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
https://github.com/gokcehan/lf/blob/master/etc/lfrc.example.
|
||||||
@ -88,12 +88,12 @@ Prefixes
|
|||||||
|
|
||||||
The following command prefixes are used by lf:
|
The following command prefixes are used by lf:
|
||||||
|
|
||||||
: read (default) built-in command
|
: read (default) built-in command
|
||||||
$ read-shell shell command
|
$ read-shell shell command
|
||||||
! read-shell-wait shell command waiting for key press
|
! read-shell-wait shell command waiting for key press
|
||||||
& read-shell-async asynchronous shell command
|
& read-shell-async asynchronous shell command
|
||||||
/ 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
|
||||||
|
|
||||||
The same evaluator is used for the command line and the configuration file. The
|
The same evaluator is used for the command line and the configuration file. The
|
||||||
difference is that prefixes are not necessary in the command line. Instead
|
difference is that prefixes are not necessary in the command line. Instead
|
||||||
@ -104,54 +104,55 @@ Syntax
|
|||||||
|
|
||||||
Characters from "#" to "\n" are comments and ignored:
|
Characters from "#" to "\n" are comments and ignored:
|
||||||
|
|
||||||
# comments start with '#'
|
# comments start with '#'
|
||||||
|
|
||||||
There are three special commands for configuration.
|
There are three special commands for configuration.
|
||||||
|
|
||||||
"set" is used to set an option which could be boolean, integer, or string:
|
"set" is used to set an option which could be boolean, integer, or string:
|
||||||
|
|
||||||
set hidden # boolean on
|
set hidden # boolean on
|
||||||
set nohidden # boolean off
|
set nohidden # boolean off
|
||||||
set hidden! # boolean toggle
|
set hidden! # boolean toggle
|
||||||
set scrolloff 10 # integer value
|
set scrolloff 10 # integer value
|
||||||
set sortby time # string value w/o quotes
|
set sortby time # string value w/o quotes
|
||||||
|
set sortby 'time' # string value with quotes
|
||||||
|
|
||||||
"map" is used to bind a key to a command which could be built-in command,
|
"map" is used to bind a key to a command which could be built-in command,
|
||||||
custom command, or shell command:
|
custom command, or shell command:
|
||||||
|
|
||||||
map gh cd ~ # built-in command
|
map gh cd ~ # built-in 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
|
||||||
|
|
||||||
You can delete an existing binding by leaving the expression empty:
|
You can delete an existing binding by leaving the expression empty:
|
||||||
|
|
||||||
map gh # deletes 'gh' mapping
|
map gh # deletes 'gh' 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 ":" could be provided to group statements until a "\n" occurs which
|
An explicit ":" could be provided to group statements until a "\n" occurs which
|
||||||
is especially useful for "map" and "cmd" commands:
|
is 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 proper
|
If you need multiline you can wrap statements in "{{" and "}}" after the proper
|
||||||
prefix.
|
prefix.
|
||||||
|
|
||||||
map st :{{
|
map st :{{
|
||||||
set sortby time
|
set sortby time
|
||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Mappings
|
Mappings
|
||||||
|
|
||||||
@ -165,16 +166,16 @@ various keybindings.
|
|||||||
This is mainly useful for two purposes. First, it can be used to map a command
|
This is mainly useful for two purposes. First, it can be used to map a command
|
||||||
with a command count:
|
with a command count:
|
||||||
|
|
||||||
map <c-j> push 10j
|
map <c-j> push 10j
|
||||||
|
|
||||||
Second, it can be used to avoid typing the name when a command takes arguments:
|
Second, it can be used to avoid typing the name when a command takes 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 of
|
One thing to be careful is that since "push" command works with keys instead of
|
||||||
commands it is possible to accidentally create recursive bindings:
|
commands it is possible to accidentally create recursive bindings:
|
||||||
|
|
||||||
map j push 2j
|
map j push 2j
|
||||||
|
|
||||||
These types of bindings create a deadlock when executed.
|
These types of bindings create a deadlock when executed.
|
||||||
|
|
||||||
@ -185,36 +186,36 @@ 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
|
||||||
if [ -z $fs ]; then
|
if [ -z $fs ]; then
|
||||||
mv --backup=numbered "$f" $HOME/.trash
|
mv --backup=numbered "$f" $HOME/.trash
|
||||||
else
|
else
|
||||||
IFS=':'; mv --backup=numbered $fs $HOME/.trash
|
IFS=':'; mv --backup=numbered $fs $HOME/.trash
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
We check "$fs" to see if there are any marked files. Otherwise we just delete
|
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"
|
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 conditional:
|
variable is provided. We can use this variable to get rid of the conditional:
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
IFS=':'; mv --backup=numbered $fx $HOME/.trash
|
IFS=':'; mv --backup=numbered $fx $HOME/.trash
|
||||||
}}
|
}}
|
||||||
|
|
||||||
The trash directory is checked each time the command is executed. We can move
|
The trash directory is checked each time the command is executed. We can move
|
||||||
it outside of the command so it would only run once at startup:
|
it outside of the command so it would only run once at startup:
|
||||||
|
|
||||||
${{ mkdir -p ~/.trash }}
|
${{ mkdir -p ~/.trash }}
|
||||||
|
|
||||||
cmd trash ${{ IFS=':'; mv --backup=numbered $fx $HOME/.trash }}
|
cmd trash ${{ IFS=':'; mv --backup=numbered $fx $HOME/.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=':'; mv --backup=numbered $fx $HOME/.trash
|
cmd trash $IFS=':'; mv --backup=numbered $fx $HOME/.trash
|
||||||
|
|
||||||
Finally note that we set "IFS" variable accordingly in the command. Instead we
|
Finally note that we set "IFS" variable accordingly in the command. Instead we
|
||||||
could use the "ifs" option to set it for all commands (e.g. "set ifs ':'").
|
could use the "ifs" option to set it for all commands (e.g. "set ifs ':'").
|
||||||
@ -233,20 +234,20 @@ 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
|
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:
|
example. You can use it to send a command to the socket file:
|
||||||
|
|
||||||
echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock
|
echo 'send echo hello world' | nc -U /tmp/lf.${USER}.sock
|
||||||
|
|
||||||
Since such a client may not be available everywhere, lf comes bundled with a
|
Since such a client may not be available everywhere, lf comes bundled with a
|
||||||
command line flag to be used as such. When using lf, you do not need to specify
|
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
|
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:
|
commands since it is shorter and immune to socket file address 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 to
|
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
|
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 number
|
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 is exported
|
when you are writing a command. For this purpose, an "$id" variable is exported
|
||||||
@ -255,53 +256,53 @@ 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
|
now you can display a message in the current client by calling the following in
|
||||||
a shell command:
|
a shell command:
|
||||||
|
|
||||||
lf -remote "send $id echo hello world"
|
lf -remote "send $id echo hello world"
|
||||||
|
|
||||||
A common use for this feature is to display an error message back in the
|
A common use for this feature is to display an error message back in the
|
||||||
client. You can implement a safe rename command which does not overwrite an
|
client. You can implement a safe rename command which does not overwrite an
|
||||||
existing file or directory as such:
|
existing 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
|
||||||
}}
|
}}
|
||||||
|
|
||||||
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. Following example can be used to dynamically set the number of columns
|
needs. Following example can be used to dynamically set the number of columns
|
||||||
on startup based on terminal width:
|
on startup based on terminal width:
|
||||||
|
|
||||||
${{
|
${{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
elif [ $w -le 160 ]; then
|
elif [ $w -le 160 ]; then
|
||||||
lf -remote "send $id set ratios 1:2:3"
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
lf -remote "send $id set ratios 1:2:3:4"
|
lf -remote "send $id set ratios 1:2:3:4"
|
||||||
fi
|
fi
|
||||||
}}
|
}}
|
||||||
|
|
||||||
Besides "send" command, there are also two commands to get or set the current
|
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
|
file selection. Two possible modes "copy" and "move" specify whether selected
|
||||||
files are to be copied or moved. File names are separated ":" character.
|
files are to be copied or moved. File names are separated ":" character.
|
||||||
Setting the file selection is done with "save" command:
|
Setting the file selection is done with "save" command:
|
||||||
|
|
||||||
lf -remote 'save copy foo.txt:bar.txt:baz.txt'
|
lf -remote 'save copy foo.txt:bar.txt:baz.txt'
|
||||||
|
|
||||||
Getting the file selection is similarly done with "load" command. You may need
|
Getting the file selection is similarly done with "load" command. You may need
|
||||||
to parse the response as such to achieve what you need:
|
to parse the response as such to achieve what you need:
|
||||||
|
|
||||||
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 | cut -d' ' -f1)
|
||||||
list=$(echo $resp | cut -d' ' -f2-)
|
list=$(echo $resp | cut -d' ' -f2-)
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
# do something with the $list
|
# do something with the $list
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
# do something else with the $list
|
# do something else with the $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.
|
||||||
@ -329,20 +330,24 @@ 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
|
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:
|
desired. You can define it just as you would define any other command:
|
||||||
|
|
||||||
cmd open-file $IFS=':'; vim $fx
|
cmd open-file $IFS=':'; vim $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" command:
|
You may want to use either file extensions or mime types from "file" command:
|
||||||
|
|
||||||
cmd open-file ${{
|
cmd open-file ${{
|
||||||
case $(file --mime-type "$f" -b) in
|
case $(file --mime-type "$f" -b) in
|
||||||
text/*) IFS=':'; vim $fx;;
|
text/*)
|
||||||
*) IFS=':'; for f in $fx; do xdg-open "$f" > /dev/null 2> /dev/null & done;;
|
IFS=':'; vim $fx;;
|
||||||
esac
|
*)
|
||||||
}}
|
IFS=':'; 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
|
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),
|
||||||
@ -364,8 +369,8 @@ 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
|
this file. Output of the execution is printed in the preview pane. You may want
|
||||||
to use the same script in your pager mapping as well if any:
|
to use the same script in your pager mapping as well if any:
|
||||||
|
|
||||||
set previewer ~/.config/lf/pv.sh
|
set previewer ~/.config/lf/pv.sh
|
||||||
map i $~/.config/lf/pv.sh "$f" | less -R
|
map i $~/.config/lf/pv.sh "$f" | less -R
|
||||||
|
|
||||||
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 use
|
efficient as possible and this responsibility is left to the user. You may use
|
||||||
@ -373,16 +378,16 @@ file extensions to determine the type of file more efficiently compared to
|
|||||||
obtaining mime types from "file" command. Extensions can then be used to match
|
obtaining mime types from "file" command. Extensions can then be used to match
|
||||||
cleanly within a conditional:
|
cleanly within a conditional:
|
||||||
|
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
*.tar*) tar tf "$1";;
|
*.tar*) tar tf "$1";;
|
||||||
*.zip) unzip -l "$1";;
|
*.zip) unzip -l "$1";;
|
||||||
*.rar) unrar l "$1";;
|
*.rar) unrar l "$1";;
|
||||||
*.7z) 7z l "$1";;
|
*.7z) 7z l "$1";;
|
||||||
*.pdf) pdftotext "$1" -;;
|
*.pdf) pdftotext "$1" -;;
|
||||||
*) highlight -O ansi "$1" || cat "$1";;
|
*) highlight -O ansi "$1" || cat "$1";;
|
||||||
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
|
||||||
|
87
docstring.go
87
docstring.go
@ -52,12 +52,12 @@ The following commands are provided by lf without default keybindings:
|
|||||||
|
|
||||||
The following options can be used to customize the behavior of lf:
|
The following options can be used to customize the behavior of lf:
|
||||||
|
|
||||||
dirfirst bool (default on)
|
dirfirst boolean (default on)
|
||||||
hidden bool (default off)
|
hidden boolean (default off)
|
||||||
preview bool (default on)
|
preview boolean (default on)
|
||||||
reverse bool (default off)
|
reverse boolean (default off)
|
||||||
scrolloff int (default 0)
|
scrolloff integer (default 0)
|
||||||
tabstop int (default 8)
|
tabstop integer (default 8)
|
||||||
filesep string (default ":")
|
filesep string (default ":")
|
||||||
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)
|
||||||
@ -122,6 +122,7 @@ There are three special commands for configuration.
|
|||||||
set hidden! # boolean toggle
|
set hidden! # boolean toggle
|
||||||
set scrolloff 10 # integer value
|
set scrolloff 10 # integer value
|
||||||
set sortby time # string value w/o quotes
|
set sortby time # string value w/o quotes
|
||||||
|
set sortby 'time' # string value with quotes
|
||||||
|
|
||||||
"map" is used to bind a key to a command which could be built-in command,
|
"map" is used to bind a key to a command which could be built-in command,
|
||||||
custom command, or shell command:
|
custom command, or shell command:
|
||||||
@ -156,8 +157,8 @@ If you need multiline you can wrap statements in "{{" and "}}" after the
|
|||||||
proper prefix.
|
proper prefix.
|
||||||
|
|
||||||
map st :{{
|
map st :{{
|
||||||
set sortby time
|
set sortby time
|
||||||
set info time
|
set info time
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
||||||
@ -196,12 +197,12 @@ 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
|
||||||
if [ -z $fs ]; then
|
if [ -z $fs ]; then
|
||||||
mv --backup=numbered "$f" $HOME/.trash
|
mv --backup=numbered "$f" $HOME/.trash
|
||||||
else
|
else
|
||||||
IFS=':'; mv --backup=numbered $fs $HOME/.trash
|
IFS=':'; mv --backup=numbered $fs $HOME/.trash
|
||||||
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
|
||||||
@ -210,8 +211,8 @@ delete the current file. Since this is such a common pattern, a separate
|
|||||||
conditional:
|
conditional:
|
||||||
|
|
||||||
cmd trash ${{
|
cmd trash ${{
|
||||||
mkdir -p ~/.trash
|
mkdir -p ~/.trash
|
||||||
IFS=':'; mv --backup=numbered $fx $HOME/.trash
|
IFS=':'; mv --backup=numbered $fx $HOME/.trash
|
||||||
}}
|
}}
|
||||||
|
|
||||||
The trash directory is checked each time the command is executed. We can
|
The trash directory is checked each time the command is executed. We can
|
||||||
@ -275,11 +276,11 @@ client. You can implement a safe rename command which does not overwrite an
|
|||||||
existing file or directory as such:
|
existing 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
|
||||||
}}
|
}}
|
||||||
|
|
||||||
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
|
||||||
@ -287,14 +288,14 @@ such needs. Following example can be used to dynamically set the number of
|
|||||||
columns on startup based on terminal width:
|
columns on startup based on terminal width:
|
||||||
|
|
||||||
${{
|
${{
|
||||||
w=$(tput cols)
|
w=$(tput cols)
|
||||||
if [ $w -le 80 ]; then
|
if [ $w -le 80 ]; then
|
||||||
lf -remote "send $id set ratios 1:2"
|
lf -remote "send $id set ratios 1:2"
|
||||||
elif [ $w -le 160 ]; then
|
elif [ $w -le 160 ]; then
|
||||||
lf -remote "send $id set ratios 1:2:3"
|
lf -remote "send $id set ratios 1:2:3"
|
||||||
else
|
else
|
||||||
lf -remote "send $id set ratios 1:2:3:4"
|
lf -remote "send $id set ratios 1:2:3:4"
|
||||||
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
|
||||||
@ -311,9 +312,9 @@ need to parse the response as such to achieve what you need:
|
|||||||
mode=$(echo $resp | cut -d' ' -f1)
|
mode=$(echo $resp | cut -d' ' -f1)
|
||||||
list=$(echo $resp | cut -d' ' -f2-)
|
list=$(echo $resp | cut -d' ' -f2-)
|
||||||
if [ $mode = 'copy' ]; then
|
if [ $mode = 'copy' ]; then
|
||||||
# do something with the $list
|
# do something with the $list
|
||||||
elif [ $mode = 'move' ]; then
|
elif [ $mode = 'move' ]; then
|
||||||
# do something else with the $list
|
# do something else with the $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
|
||||||
@ -355,10 +356,14 @@ 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/*) IFS=':'; vim $fx;;
|
text/*)
|
||||||
*) IFS=':'; for f in $fx; do xdg-open "$f" > /dev/null 2> /dev/null & done;;
|
IFS=':'; vim $fx;;
|
||||||
esac
|
*)
|
||||||
|
IFS=':'; 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
|
lf does not come bundled with a file opener. You can use any of the existing
|
||||||
@ -395,12 +400,12 @@ match cleanly within a conditional:
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
*.tar*) tar tf "$1";;
|
*.tar*) tar tf "$1";;
|
||||||
*.zip) unzip -l "$1";;
|
*.zip) unzip -l "$1";;
|
||||||
*.rar) unrar l "$1";;
|
*.rar) unrar l "$1";;
|
||||||
*.7z) 7z l "$1";;
|
*.7z) 7z l "$1";;
|
||||||
*.pdf) pdftotext "$1" -;;
|
*.pdf) pdftotext "$1" -;;
|
||||||
*) highlight -O ansi "$1" || cat "$1";;
|
*) highlight -O ansi "$1" || cat "$1";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
Another important consideration for efficiency is the use of programs with
|
Another important consideration for efficiency is the use of programs with
|
||||||
|
Loading…
Reference in New Issue
Block a user