smartless is a pager that behaves just like less, but will show the file (or input) directly in the terminal if it is short enough to fit in the terminal height. For longer files (or if multiple files are passed), the pager is still invoked, and only the first and last few lines will be kept in the terminal (so everything is still visible without scrolling), with a truncation message in the middle. The full contents can optionally be recorded and later recalled via a short ID.
Here is a small demo:
The original author (Stefan Heule) wrote a blog post about his project.
smartlessrequiresbash, common shell toolscat,sed,rev,tac,tee,wc, and a pager likeless. All are available by default on most Unix systems.- To consider wrapping of lines that are longer than the terminal width the
nowrapcommand is needed. Without that, full physical lines will be counted, and this can lead to scrolling of output in the terminal. The nowrap implementation also relies onpkill, and ideally hasstdbuforunbufferto reduce process spawning. - For recalling captured output,
grepis needed. - To save disk space by de-duplicating captures, the
rdfindcommand is used if available.
Download or clone the Git repository (cloning allows easy updating via git pull):
git clone [--branch stable] https://github.com/inkarkat/smartless.git
- The
./binsubdirectory is supposed to be added toPATH. - The optional
./profile/exports.shscript sets up the pager and capture directory. It needs to be sourced from a shell startup script (e.g..profileor.bashrc). - Also see the aliases section below.
smartless is designed as a drop-in replacement for less. For instance, to view the output of a command cmd, use
cmd | smartlessIt is also possible to pass filename(s) directly:
smartless file.txtMultiple files will always launch the pager. All other parameters are forwarded to the pager. For instance, smartless +G will jump to the end of the file in less.
To replace less completely, it is possible to define an alias in most shells. For bash and zsh, the following line will allow the usage of smartless when typing less.
alias less='/path/to/smartless'It can be useful to define an additional alias for jumping directly to the end of the input. I like to call that alias more, but other more descriptive names are imaginable:
alias more='/path/to/smartless +G'Several optional environment variables control smartless. These are described here, including their default values.
# number of lines to directly display before entering the pager
SMARTLESS_NUM_LINES= # (terminal height - 5) or 15, if terminal height cannot be discovered automatically
# the pager to be used
SMARTLESS_PAGER='less'
# the default arguments to the pager
SMARTLESS_PAGER_ARGUMENTS='-iR'
# hinted command name to recall full output; this can be overridden if you define a shorter alias and want to use that in the truncation message
SMARTLESS_RECALL_COMMAND=smartless-recall
# highlighting of messages
SMARTLESS_COLOR=$'\e[38;5;2m'
SMARTLESS_COLOR_OFF=$'\e[0m'
# enable capturing of the full output to uniquely named files in the capture directory
SMARTLESS_CAPTURE_DIR=
# template for naming the capture files, cp. "man mktemp"
SMARTLESS_CAPTURE_TEMPLATE='XXXXXX'
# clean up captured output after it hasn't been accessed for 14 days; any
# arguments to "find" can be used here
SMARTLESS_CAPTURE_PRUNE_FINDARGS='-atime +14'Pull requests to improve smartless are welcome.
This project was originally based on an answer on StackExchange, but has changed significantly since.
This is an independently maintained fork of the original version by Stefan Heule.
Copyright (c) 2015, Stefan Heule
Copyright (c) 2017-2026 Ingo Karkat
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.