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

Scroll for terminal supporting it #246

Closed
gjuchault opened this issue Aug 31, 2018 · 12 comments
Closed

Scroll for terminal supporting it #246

gjuchault opened this issue Aug 31, 2018 · 12 comments
Labels
documentation duplicate This issue or pull request already exists

Comments

@gjuchault
Copy link

Hello,

Using iTerm2 "AlternateMouseScroll", I can scroll in less instead of using arrow keys.
Do you think that would work with bat ?

Thanks :)

@sharkdp
Copy link
Owner

sharkdp commented Aug 31, 2018

Thank you for your feedback.

This is a duplicate of #188 (and #193).

You should be able to use the fix suggested in #188. If that works, we should probably add it to the "Troubleshooting" section of the README.

@sharkdp sharkdp added duplicate This issue or pull request already exists documentation labels Aug 31, 2018
@mike-mosher
Copy link

@sharkdp: I tweaked the bash function provided by @achalddave to use RS instead of RF, and was able to get this to work on a Mac using the default Terminal app. Hopefully this helps

@sharkdp
Copy link
Owner

sharkdp commented Sep 1, 2018

Instead of wrapping bat in a script, you can also wrap the pager, as suggested in the README: https://github.com/sharkdp/bat#using-a-different-pager

@mathieutu
Copy link

Hi folks,
Could someone give us the exact best process to resolve this issue?
I've looked at all the old issues and didn't found any definitive good answer.
Then we can document it in the readme.

Thanks!

@gjuchault
Copy link
Author

gjuchault commented Sep 4, 2018

@mike-mosher The only thing with your script is that you always wrap the content into less, where bat has some nice detections about how to render (for example try bat file | pbcopy and you won't have line numbers, etc.)

Here is a working micro-tutorial (for macOS at least):

  1. Write the following to ~/bat.pager.sh
#!/bin/bash

less --tabs 4 -RF "$@"
  1. chmod +x ~/bat.pager.sh
  2. Edit your bashrc/zshrc and add the following alias:
alias cat="PAGER=~/bat.pager.sh bat --theme='mytheme'"
  1. source ~/.[zsh|bash]rc

And this is working nicely

Edit: @sharkdp maybe adding a well-written version of my guide to the README would be a good call, as many of us don't know what PAGER means, especially how it's related to having your terminal support the mouse in it. You may close the issue if you want

@mladenp
Copy link

mladenp commented Sep 5, 2018

@gjuchault solution works for me, but its not perfect because it shows the end of file.
Is there any way to make it scrollable like less is by default?

@sharkdp
Copy link
Owner

sharkdp commented Sep 5, 2018

@gjuchault Thanks!

I would propose the following modification:

  1. Write the following to ~/.bat_pager.sh:

    #!/bin/bash
    
    less --tabs 4 -RF "$@"
  2. Make the file executable:

    chmod +x ~/.bat_pager.sh`
  3. Set the following environment variable (in your shells startup file):

    export BAT_PAGER="$HOME/.bat_pager.sh"

@mladenp It shows the beginning of the file for me. And scrolling also doesn't work for you?

@mike-mosher
Copy link

@gjuchault @sharkdp Thanks for the updated process. However, your suggestions don't work. I'm using Mac OS and Terminal.app with Bash. To get it to work, you need to substitute RF with RS in the .bat_pager.sh script.

@gjuchault
Copy link
Author

@mike-mosher RF works fine with me

@gibfahn
Copy link

gibfahn commented Sep 12, 2018

What does creating a shell script give you over just setting export LESS="--tabs 4 -RF"?

@sharkdp
Copy link
Owner

sharkdp commented Sep 12, 2018

The problem with using the LESS environment variable is that bat will pass command-line options to less. The options on the command-line take precedence over the values in the environment variable.

@sharkdp
Copy link
Owner

sharkdp commented Sep 26, 2018

I hope that things are now well explained in this README section: https://github.com/sharkdp/bat#using-a-different-pager

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants