-
Notifications
You must be signed in to change notification settings - Fork 92
Open
Description
batpipe fails to detect when it's running inside less on Linux systems with modern procps-ng, causing it to disable color output. It looks like parent_executable function in lib/proc.sh is not dealing with ps output correctly:
❯ ps -f -p 49383 | tail -n 1 | awk '{for(i=8;i<=NF;i++) printf $i" "; printf "\n"}'
/usr/bin/zsh -lThis captures the entire cmdline as BATPIPE_PARENT_EXECUTABLE, and basename fails to isolate the actual binary name.
❯ less /etc/passwd
++ parent_executable 76927
++ local target_pid=76927
++ ps -f -p 76927
++ tail -n 1
++ awk '{for(i=8;i<=NF;i++) printf $i" "; printf "\n"}'
+ BATPIPE_PARENT_EXECUTABLE='less /etc/passwd '
++ basename -- 'less /etc/passwd '
++ cut '-d ' -f1
+ BATPIPE_PARENT_EXECUTABLE_BASENAME=passwd
++ parent_executable_pid 76927
++ local target_pid=76927
++ ps -f -p 76927
++ tail -n 1
++ awk '{print $3}'
+ BATPIPE_PARENT_EXECUTABLE_PID=49383
+ set +x
++ parent_executable 49383
++ local target_pid=49383
++ ps -f -p 49383
++ tail -n 1
++ awk '{for(i=8;i<=NF;i++) printf $i" "; printf "\n"}'
+ BATPIPE_PARENT_EXECUTABLE='/usr/bin/zsh -l '
++ basename -- '/usr/bin/zsh -l '
++ cut '-d ' -f1
...
At a guess, the author most likely dealt with a different ps version (BSD's?) that doesn't put full arguments into 8th field.
I think ps -o comm= would be a good replacement here, as both procps-ng and BSD's ps seem to support it.
Temporary workaround I'm using for the time being:
LESSOPEN="|BATPIPE_DEBUG_PARENT_EXECUTABLE=less /usr/bin/batpipe %s"
Environment:
- OS: Aurora (Fedora 42 Kinoite derivative)
- procps-ng version: 4.0.4
- bat-extras version: 2024.08.24
- bat version: 0.25
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels