Skip to content

fix(batpipe): parent process detection on Linux with procps-ng and gawk 5.x#145

Open
markrustad wants to merge 1 commit intoeth-p:masterfrom
markrustad:fix/procps-ng-gawk-compat
Open

fix(batpipe): parent process detection on Linux with procps-ng and gawk 5.x#145
markrustad wants to merge 1 commit intoeth-p:masterfrom
markrustad:fix/procps-ng-gawk-compat

Conversation

@markrustad
Copy link

Summary

Fix batpipe failing to detect when running inside less on modern Linux systems with procps-ng (e.g., Fedora 42+).

The Problem

On systems with modern procps-ng, parent_executable() returns the full command line (e.g., less /etc/passwd ) instead of just the program name. When basename operates on this, it returns passwd instead of less, causing batpipe to incorrectly detect the parent process and disable color output.

Additionally, GNU Awk 5.x is stricter about printf format strings, causing errors like:

awk: fatal: not enough arguments to satisfy format string '%s'

Changes

  1. lib/proc.sh: Move cut -d' ' -f1 into parent_executable() to extract just the program name
  2. src/batpipe.sh: Remove now-redundant cut calls (handled by proc.sh)
  3. lib/proc.sh: Fix gawk 5.x compatibility by changing printf $i" " to printf "%s ", $i

Testing

Tested on Fedora with:

  • procps-ng 4.0.4
  • GNU Awk 5.3.2
  • bat 0.24.0

Before fix:

$ less ~/.zshrc
# Shows plain text, no syntax highlighting

After fix:

$ less ~/.zshrc
# Shows syntax-highlighted code with file header

Related Issues

Compatibility

The printf "%s ", $i syntax is POSIX-compliant and works on all awk implementations (gawk, mawk, nawk, busybox awk).

Fix batpipe failing to detect when running inside `less` on modern Linux
systems with procps-ng.

The issue was that `parent_executable()` returned the full command line
(e.g., "less /etc/passwd ") instead of just the program name. When
`basename` operated on this, it returned "passwd" instead of "less",
causing batpipe to disable color output.

Changes:
- Move `cut -d' ' -f1` into `parent_executable()` to extract just the
  program name before returning
- Remove now-redundant `cut` calls in batpipe.sh
- Fix gawk 5.x compatibility: change `printf $i" "` to `printf "%s ", $i`
  (GNU Awk 5.x requires format strings for printf)

Fixes eth-p#142
Incorporates fix from eth-p#96 with additional gawk compatibility fix.
Copilot AI review requested due to automatic review settings January 26, 2026 10:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Successfully merging this pull request may close these issues.

batpipe parent process detection is broken on Linux with procps-ng

2 participants