I sometimes like to run my system logged into a tty2 console without X, and sometimes I'll keep that open running a console based music player in tty2 while logged into a graphical desktop on tty1, not for any particular reason, but just to see how it works. I like practicing operating from the console.
I also use ranger file manager, especially in a console without X.
I recently installed the bat
command after learning what it could do in terms of highlighted display. Immediately I noticed ranger's preview pane was utilizing bat
and giving me pretty, highlighted previews of files.
Great! Until I ran it without X on tty2, and calling the scope.sh
ranger preview script on these files would cause ranger to CRASH. It seemed to have something to do with colors not available.
So, I changed the scope.sh
lines that called bat
for text/html
previewing to cat
instead, and this FIXED the problem.
My question: Is it possible to either put a test for the terminal environement in the scope.sh
or use different config files for different tty logins, like one config file for tty1, and another for tty2?
The lines in question are below, the problem may be python related, because a lot of the errors thrown when crashing are python errors.
The bat
command (which I changed to cat
to fix the crash) is in the line beginning env COLORTERM=8bit
Code: Select all
## Text
text/* | */xml)
## Syntax highlight
if [[ "$( stat --printf='%s' -- "${FILE_PATH}" )" -gt "${HIGHLIGHT_SIZE_MAX}" ]]; then
exit 2
fi
if [[ "$( tput colors )" -ge 256 ]]; then
local pygmentize_format='terminal256'
local highlight_format='xterm256'
else
local pygmentize_format='terminal'
local highlight_format='ansi'
fi
env HIGHLIGHT_OPTIONS="${HIGHLIGHT_OPTIONS}" highlight \
--out-format="${highlight_format}" \
--force -- "${FILE_PATH}" && exit 5
env COLORTERM=8bit bat --color=always --style="plain" \
-- "${FILE_PATH}" && exit 5
pygmentize -f "${pygmentize_format}" -O "style=${PYGMENTIZE_STYLE}"\
-- "${FILE_PATH}" && exit 5
exit 2;;