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 to set a environment variable for bat #228

Closed
smartding opened this issue Nov 7, 2020 · 18 comments · Fixed by #260
Closed

how to set a environment variable for bat #228

smartding opened this issue Nov 7, 2020 · 18 comments · Fixed by #260

Comments

@smartding
Copy link
Contributor

telescope and fzf.vim have the same problem when using bat for previewing: the color in preview looks more saturated than running bat directly in command line. See this issue in fzf.vim repo for screenshots from many users.

The short term solution (as discussed here ) is to set the environment variable COLORTERM=truecolor each time we run bat. How can we do this in telescope?

@smartding
Copy link
Contributor Author

I tried setting the COLORTERM environment variable as follows in previewers.lua, but no luck.

    local term_opts = {
      cwd = opts.cwd or vim.fn.getcwd(),
      env = {
        COLORTERM = 'truecolor'
      }
    }

    with_preview_window(status, bufnr, function()
      set_term_id(
        self,
        vim.fn.termopen(opts.get_command(entry, status), term_opts)
      )
    end)

@tjdevries
Copy link
Member

Hmmm, env didn't work? That's what my suggested solution would have been.

Make sure you completely reload the plugin in between to ensure that env is getting passed.

@smartding
Copy link
Contributor Author

I restarted neovim several times, so telescope is definitely reloaded.
I'm using the gruvbox theme in neovim and bat, with alacrity terminal (which can handle truecolor)
After setting COLORTERM with env, here's what it's like in neovim:

pic-selected-201114-0729-54

And here is what it's like in telescope's bat preview, the color is obviously wrong:

pic-selected-201114-0729-31

And if I run bat in terminal, the color is correct.

@kkharji
Copy link
Member

kkharji commented Nov 17, 2020

I can confirm having the same issue with bat, perhaps it is something todo with bat, please check sharkdp/bat#979

@smartding
Copy link
Contributor Author

I can confirm having the same issue with bat, perhaps it is something todo with bat, please check sharkdp/bat#979

bat needs external help to decide whether to use truecolor or not.
The current solution is to set the COLORTERM env variable, which works for previews in fzf.vim, but for some reason doesn't work with telescope. The bat community is also talking about adding a flag such as --color-mode=24-bit to force bat to use true color.

@ThomasFeher
Copy link

Why is Neovim removing COLORTERM from the environment in the first place? I'm
using a patched version that does not remove COLORTERM, as suggested by me
here.
That fixes the issue for fzf and for telescope.nvim and it doesn't seem to break
anything in my case (using Alacritty and Tmux on Linux).

Should I open a PR for that patch?

@kkharji
Copy link
Member

kkharji commented Nov 18, 2020

Ohhh thats why, sure @ThomasFeher

@Conni2461
Copy link
Member

Conni2461 commented Nov 18, 2020

I don't know what the neovim core guys want so i don't know if you should open a PR.
The underlining issue is that we can't set an env with termopen. This is a neovim bug with issue neovim/neovim#11751 and PR neovim/neovim#12937
But i have an idea how to fix this issue here. I would provide you with a config value like set_env({ 'COLORTERM=truecolor' }).
But i have a meeting now so i can implement it in like 2 hours or so :)
I will ping you in the PR.

@kkharji
Copy link
Member

kkharji commented Nov 18, 2020

@Conni2461 coming to the rescue 😆 appreciate you bro

Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 18, 2020
- Set env vars for previewer with set_env({ key = value } nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
@Conni2461
Copy link
Member

Please checkout #260 and report back if it is working for you. Thanks :)

@smartding
Copy link
Contributor Author

Please checkout #260 and report back if it is working for you. Thanks :)

I tested bat preview with builtin git_files and buffer, it works!
Nice work :)

@kkharji kkharji closed this as completed Nov 19, 2020
@Conni2461
Copy link
Member

@tami5 can we keep issues around until the pr is merged? Maybe someone will have the same issue in the future and only does an open issue search, this way he can't find that this issue is already been worked on and has a working solution :)

@Conni2461 Conni2461 reopened this Nov 19, 2020
@kkharji
Copy link
Member

kkharji commented Nov 19, 2020

@Conni2461 ohhh sorry I thought its merged. I can create FAQ entry

@smartding
Copy link
Contributor Author

@Conni2461 ohhh sorry I thought its merged. I can create FAQ entry

I was waiting for #260 to be merged, suddenly the issue gets closed.... :)

@kkharji
Copy link
Member

kkharji commented Nov 19, 2020

@smartding ohhh sorry for shocking you 🤣 . if you want to test it now and assure us it is working okay you can do git fetch origin pull/260/head:previewer_fixes then git switch previewer_fixes

@smartding
Copy link
Contributor Author

@smartding ohhh sorry for shocking you . if you want to test it now and assure us it is working okay you can do git fetch origin pull/260/head:previewer_fixes then git switch previewer_fixes

already tested the PR 21 hours ago and it worked, as I mentioned above.
I was just waiting to test the merged version in case there's any change.

@kkharji
Copy link
Member

kkharji commented Nov 19, 2020

Oh so thats why I closed it. :D I was like hmm this issue if fixed for me and for smartding, let me close it, silly me :P

Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 19, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 20, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit to Conni2461/telescope.nvim that referenced this issue Nov 22, 2020
- Set env vars for previewer with set_env({ key = value } fix nvim-telescope#228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see nvim-telescope#253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix nvim-telescope#253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
Conni2461 added a commit that referenced this issue Nov 22, 2020
- Set env vars for previewer with set_env({ key = value } fix #228)
- Set pager for git previewes (default is GIT_PAGER=less so users can scroll see #253)
- Use less for people who don't have bat but less installed
- Reset less env to only '-RS' because '-X' will break scrolling(fix #253, thanks @eth3lbert)
- Scrolling for buffer previewer(thanks @tami5 for helping)
  - Also new function to create buffer previewers (which has scrolling by default). Used for tags and help_tags previewer.
- Add new setting set_env to readme
@smartding
Copy link
Contributor Author

neovim is no longer resetting COLORTERM, thanks to the change made by @ThomasFeher.
I did some testing, there's no need to set_env = { ['COLORTERM'] = 'truecolor' } in telescope's setup now.

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 a pull request may close this issue.

5 participants