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

How can I use batpipe with nushell? #14691

Closed
oscarvarto opened this issue Dec 28, 2024 · 1 comment
Closed

How can I use batpipe with nushell? #14691

oscarvarto opened this issue Dec 28, 2024 · 1 comment
Labels
question the issue author asks something

Comments

@oscarvarto
Copy link

Question

Title is selfdescriptive.

Additional context and details

Trying

config nu --doc | nu-highlight | less -R | batpipe

Returns this:

There is no -l option ("less --help" for help)
# batpipe, a bat-based preprocessor for less and bat.
# Version: 2024.08.24
# Homepage: https://github.com/eth-p/bat-extras
# Copyright (C) 2019-2021 eth-p | MIT License
#
# To use batpipe, eval the output of this command in your shell init script.
LESSOPEN="|/opt/homebrew/Cellar/bat-extras/2024.08.24/bin/batpipe %s";
export LESSOPEN;
unset LESSCLOSE;

# The following will enable colors when using batpipe with less:
LESS="$LESS -R";
BATPIPE="color";
export LESS;
export BATPIPE;

which of course is not valid nu code.
Everything I've tried fails misserably :(

@oscarvarto oscarvarto added the question the issue author asks something label Dec 28, 2024
@NotTheDr01ds
Copy link
Contributor

The Nushell equivalent should be:

$env.LESSOPEN = "|/opt/homebrew/Cellar/bat-extras/2024.08.24/bin/batpipe %s"
$env.LESS = "$LESS -R"
$env.BATPIPE = "color"

To get that handled dynamically, you should be able to use something like:

batpipe
| lines                 # convert to Nushell list
| where $it =~ '='      # find lines with an assignment (equals)
| parse '{var}={val};'  # turn it into a table with var and value
| transpose -dr         # turn that into a record
| load-env              # load that record into the environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question the issue author asks something
Projects
None yet
Development

No branches or pull requests

2 participants