Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bat --wrap word #3079

Open
oficsu opened this issue Sep 1, 2024 · 3 comments
Open

Add bat --wrap word #3079

oficsu opened this issue Sep 1, 2024 · 3 comments
Labels
feature-request New feature or request

Comments

@oficsu
Copy link

oficsu commented Sep 1, 2024

The current --wrap character behavior

echo Lorem ipsum dolor sit a met,   \
     consectetur adipiscing elit.  \
     Nullam venenatis nec est     \
     eu tristique                \
| bat --decorations=never       \
    --paging=never             \
    --language bash           \
    --theme Nord             \
    --color=always          \
    --terminal-width 11    \
    --wrap character      \
    -

image

Suggestion

I suggest a new word mode for the --wrap option, which will split lines only by spaces (except in cases where a word is too long for a single line). These spaces should then be stripped

An example of how it should look with --wrap word:

image

@oficsu oficsu added the feature-request New feature or request label Sep 1, 2024
@einfachIrgendwer0815
Copy link
Contributor

Issue #2751 is related and this comment also provides a shell workaround.

@oficsu
Copy link
Author

oficsu commented Sep 2, 2024

@einfachIrgendwer0815, unfortunately, this workaround will break syntax highlighting, which goes completely against the initial purpose of using bat for syntax highlighting:

echo Lorem ipsum dolor sit a met,   \
     consectetur adipiscing elit.  \
     Nullam venenatis nec est     \
     eu tristique                \
| bat -p                        \
| fold -w 12 -s                \
| bat --decorations=never     \
    --paging=never           \
    --language bash         \
    --theme Nord           \
    --color=always        \
    -

image

@oficsu
Copy link
Author

oficsu commented Sep 2, 2024

Ok, I just have found a better workaround that works in my case:

echo Lorem ipsum dolor sit a met,   \
     consectetur adipiscing elit.  \
     Nullam venenatis nec est     \
     eu tristique                \
| fold -w 12 -s                 \
`# replace newlines by unique` \
`# invisible character that ` \
`# is ignored by syntax    ` \
`# highlighting           ` \
| sed -zE "s/\n/\x2062/g"  \
| bat --decorations=never \
    --paging=never       \
    --language bash     \
    --theme Nord       \
    --color=always    \
    -                \
`# revert it back ` \
| sed -zE "s/\x2062/\n/g"

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants