From c5d05b7683c356f06b5f848a7462a8a1f4a6712c Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Mon, 13 Apr 2020 17:58:03 +0300 Subject: [PATCH] add 'on-cd' to the documentation Related #291 --- doc.go | 33 +++++++++++++++++++++++++++++++++ docstring.go | 35 +++++++++++++++++++++++++++++++++++ lf.1 | 27 +++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/doc.go b/doc.go index 350f4dd..e34292e 100644 --- a/doc.go +++ b/doc.go @@ -693,6 +693,39 @@ 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. +Changing Directory + +lf changes the working directory of the process to the current directory so +that shell commands always work in the displayed directory. After quitting, it +returns to the original directory where it is first launched like all shell +programs. If you want to stay in the current directory after quitting, you can +use one of the example wrapper shell scripts provided in the repository. + +There is a special command 'on-cd' that runs a shell command when it is defined +and the directory is changed. You can define it just as you would define any +other command: + + cmd on-cd &{{ + # display git repository status in your prompt + source /usr/share/git/completion/git-prompt.sh + GIT_PS1_SHOWDIRTYSTATE=auto + GIT_PS1_SHOWSTASHSTATE=auto + GIT_PS1_SHOWUNTRACKEDFILES=auto + GIT_PS1_SHOWUPSTREAM=auto + git=$(__git_ps1 " (%s)") || true + fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m" + lf -remote "send $id set promptfmt \"$fmt\"" + }} + +This command runs whenever you change directory but not on startup. You can add +an extra call to make it run on startup as well: + + cmd on-cd &{{ # ... }} + on-cd + +Note that all shell commands are possible but `%` and `&` are usually more +appropriate as `$` and `!` causes flickers and pauses respectively. + Colorschemes lf tries to automatically adapt its colors to the environment. On startup, diff --git a/docstring.go b/docstring.go index f9d5111..7afa386 100644 --- a/docstring.go +++ b/docstring.go @@ -724,6 +724,41 @@ 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. +Changing Directory + +lf changes the working directory of the process to the current directory so +that shell commands always work in the displayed directory. After quitting, +it returns to the original directory where it is first launched like all +shell programs. If you want to stay in the current directory after quitting, +you can use one of the example wrapper shell scripts provided in the +repository. + +There is a special command 'on-cd' that runs a shell command when it is +defined and the directory is changed. You can define it just as you would +define any other command: + + cmd on-cd &{{ + # display git repository status in your prompt + source /usr/share/git/completion/git-prompt.sh + GIT_PS1_SHOWDIRTYSTATE=auto + GIT_PS1_SHOWSTASHSTATE=auto + GIT_PS1_SHOWUNTRACKEDFILES=auto + GIT_PS1_SHOWUPSTREAM=auto + git=$(__git_ps1 " (%s)") || true + fmt="\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f$git\033[0m" + lf -remote "send $id set promptfmt \"$fmt\"" + }} + +This command runs whenever you change directory but not on startup. You can +add an extra call to make it run on startup as well: + + cmd on-cd &{{ # ... }} + on-cd + +Note that all shell commands are possible but '%' and '&' are usually more +appropriate as '$' and '!' causes flickers and pauses respectively. + + Colorschemes lf tries to automatically adapt its colors to the environment. On startup, diff --git a/lf.1 b/lf.1 index 1f733aa..359230b 100644 --- a/lf.1 +++ b/lf.1 @@ -638,6 +638,33 @@ Since this script is called for each file selection change it needs to be as eff .EE .PP 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 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 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. +.SH CHANGING DIRECTORY +lf changes the working directory of the process to the current directory so that shell commands always work in the displayed directory. After quitting, it returns to the original directory where it is first launched like all shell programs. If you want to stay in the current directory after quitting, you can use one of the example wrapper shell scripts provided in the repository. +.PP +There is a special command 'on-cd' that runs a shell command when it is defined and the directory is changed. You can define it just as you would define any other command: +.PP +.EX + cmd on-cd &{{ + # display git repository status in your prompt + source /usr/share/git/completion/git-prompt.sh + GIT_PS1_SHOWDIRTYSTATE=auto + GIT_PS1_SHOWSTASHSTATE=auto + GIT_PS1_SHOWUNTRACKEDFILES=auto + GIT_PS1_SHOWUPSTREAM=auto + git=$(__git_ps1 " (%s)") || true + fmt="\e033[32;1m%u@%h\e033[0m:\e033[34;1m%w/\e033[0m\e033[1m%f$git\e033[0m" + lf -remote "send $id set promptfmt \e"$fmt\e"" + }} +.EE +.PP +This command runs whenever you change directory but not on startup. You can add an extra call to make it run on startup as well: +.PP +.EX + cmd on-cd &{{ # ... }} + on-cd +.EE +.PP +Note that all shell commands are possible but `%` and `&` are usually more appropriate as `$` and `!` causes flickers and pauses respectively. .SH 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. .PP