Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] new flag to override '-F/--quit-if-one-screen' #467

Closed
LangLangBart opened this issue Jan 9, 2024 · 2 comments
Closed

[FEATURE] new flag to override '-F/--quit-if-one-screen' #467

LangLangBart opened this issue Jan 9, 2024 · 2 comments

Comments

@LangLangBart
Copy link

I suggest the introduction of a new flag that can override the -F/--quit-if-one-screen option.

The reason for this is that I frequently use fzf and its --execute flag to open selected files
with the less pager. However, in my setup, LESS is assigned with the --quit-if-one-screen
option. This causes an issue when I try to view a file with a small number of lines because the
window immediately closes.

Personal LESS setup
# ░█░░░█▀▀░█▀▀░█▀▀
# ░█░░░█▀▀░▀▀█░▀▀█
# ░▀▀▀░▀▀▀░▀▀▀░▀▀▀
# g/ hilite-search - Highlight results when searching with slash key (/)
# w/ hilite-unread - Highlight first line after PgDn
# I/ IGNORE-CASE - Ignore case
# j/ jump-target=n - line/percent on the screen where the target line is to be positioned
# M/ LONG-PROMPT - Long prompts ("Line X of Y")
# mouse - Enables mouse input
# X/ no-init - prevent clearing the screen
# F/ quit-if-one-screen - auto exit if the file can be displayed on the screen
# K/ quit-on-intr - quit less immediately with ^C
# q/ quiet - be more quiet
# R/ RAW-CONTROL-CHARS - Raw color codes in output (don't remove color codes)
# s/ squeeze-blank-lines - Squeeze empty lines to one
# J/ status-column - mark matched lines on the left side
# ~/ tilde - Don't show those weird ~ symbols on lines after EOF
# z/ window - scrolling window size to n lines
export LESS="--hilite-search \
--hilite-unread \
--IGNORE-CASE \
--jump-target=.5 \
--LONG-PROMPT \
--mouse \
--no-init \
--quit-if-one-screen \
--quit-on-intr \
--quiet \
--RAW-CONTROL-CHARS \
--squeeze-blank-lines \
--status-column \
--tilde \
--window=7"

# Less Colors for Man Pages
export LESS_TERMCAP_mb=$'\E[01;31m'      # begin blinking
export LESS_TERMCAP_md=$'\E[01;38;5;74m' # begin bold
export LESS_TERMCAP_me=$'\E[0m'          # end mode
export LESS_TERMCAP_se=$'\E[0m'          # end standout-mode
export LESS_TERMCAP_so=$'\E[01;31m'      # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m'          # end underline
export LESS_TERMCAP_us=$'\E[01;32m'      # begin underline
# disable the creation of the ~/.lesshst file
export LESSHISTFILE=-

To reproduce this issue:

  1. Export your LESS with the --quit-if-one-screen in your .bashrc/.zshrc:
export LESS="--quit-if-one-screen"
  1. Run the following command at the root of this repository or any other directory where you have
    files. If the file contains more lines than can fit on your screen, the file will remain open,
    allowing you to interact with it normally. However, if the number of lines is too small, it will
    immediately close itself:
find . -type f -maxdepth 1 | fzf --bind 'enter:execute:less {}' --preview 'cat {}'

Currently, a workaround is to check if LESS has been set and then unset it. However, this
removes all the user customizations set by LESS.

The introduction of a flag to override the --quit-if-one-screen would be a beneficial solution.

@gwsw
Copy link
Owner

gwsw commented Jan 10, 2024

I'm not familiar with fzf, but I can't seem to reproduce this based on your description. In the last step, fzf opens and displays a file list on the bottom left, and the contents of the first file at the right. It doesn't immediately close.

However, regarding what I think the issue is, you can override any option in your LESS variable by using the -+ or --+ syntax:

less -+F ...
less --+quit-if-one-screen ...

@LangLangBart
Copy link
Author

In the last step, fzf opens and displays a file list on the bottom left, and the contents of the first file at the right. It doesn't immediately close.

Indeed, you need to also press ⏎ Enter on the chosen file. This should open the file in less. If you press q you should be able to return to fzf and select another file to view.


However, regarding what I think the issue is, you can override any option in your LESS variable by using the -+ or --+ syntax:

less -+F ...
less --+quit-if-one-screen ...

Thank you. This is precisely what I was searching for. The issue has been resolved.


The shorter version works fine for me, but the longer version produces an error.

 less --version
# less 643 (PCRE2 regular expressions)
#

cat README.md | less --+quit-if-one-screen
# No +quit-if-one-screen option exists ("less --help" for help)

But I see it has already been reported and fixed. Ref #452.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants