'Broken terminal after piping fzf + xargs + less on Kitty + Bash
I'm trying to combine fzf output with a command launched through xargs whose output needs to be paginated with less.
The simplest example using basic commands is the following:
echo test | fzf | xargs echo | less
In the example, I use echo and the string test to make it self-contained.
The whole command allows the selection of the string test using fzf, then launches the simplest useful command (echo) using xargs, whose output is expected to be paginated using less.
However, when less is run, the terminal results "broken" and requires a reset to be usable again.
Is there a way to make it working without "breaking" the terminal?
Interestingly, the following variants, where one single pipe is removed, do not cause any problem:
echo test | fzf | less
echo test | xargs echo | less
echo test | fzf | xargs echo
so it seems that it is the combination of the three programs that causes the problem.
--- ADDEDUM ---
After some more tests, I found that the problem arises when the command is run under Kitty as terminal emulator and Bash as shell.
Tried under Kitty + Zsh -> it works. Tried under xterm + Bash -> it works.
I would now mark this question as too narrow scope to be interesting! I refined the title to reflect this specificity.
Solution 1:[1]
I had this problem with Kitty + fzf (on macOS) and solved it by prefixing the fzf command line to set the TERM environment variable to "xterm", for example this solves the issue for me in zsh at least:
TERM=xterm $(echo test | fzf | xargs echo | less)
I'm not sure why it works, but every so often something breaks kitty and adding a TERM=xterm often seems to help, which is odd because echo $TERM returns "xterm" for me in a new shell anyway.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barney |
