fzf-tab icon indicating copy to clipboard operation
fzf-tab copied to clipboard

Display zstyle list-colors in matches

Open patrick96 opened this issue 4 years ago • 41 comments

This plugin is really neat! :smiley:

One thing I cannot get to work is the way files are color coded depending on the type of "file" and its permissions when you use regular zsh completion.

I set list-colors like this:

zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} 

When disabling fzf-tab the completion looks like this: 2020-02-08-164803_644x412_scrot

Notice how the symlink has a different color. Now with fzf-tab enabled that color is not displayed:

2020-02-08-164739_644x412_scrot

Is it possible to have this functionality with fzf-tab? I have not found any option that would do something like that and I have also looked through the source code and tried to figure out if and where this color information would be provided by _fzf_tab_orig_widget but I couldn't find a place where those colors appear.

patrick96 avatar Feb 08 '20 16:02 patrick96

Sorry for the late reply.

Yes, it is possible. In fact, it is on my plan.

But the file list given to fzf-tab has no color information. To accomplish this fzf-tab may need to parse LS_COLORS by itself.

Aloxaf avatar Feb 17 '20 02:02 Aloxaf

To accomplish this fzf-tab may need to parse LS_COLORS by itself.

I was afraid this was the case. Kind of weird that there is no way to get the colors from zsh directly.

patrick96 avatar Feb 18 '20 13:02 patrick96

There is https://github.com/xPMo/zsh-ls-colors. MIT licensed, so easy to copy stuff over.

romkatv avatar Feb 18 '20 13:02 romkatv

@xPMo Maybe you can help?

romkatv avatar Feb 18 '20 13:02 romkatv

@Aloxaf Let me know. ~~I think the easiest option would be to bring in my project as a submodule or subtree, and then you can load the functions after fpath+=(${0:h}/zsh-ls-colors/lib).~~ EDIT: nope, thanks @romkatv.

If you have any questions, feel free to open an issue over at my project.

xPMo avatar Feb 18 '20 15:02 xPMo

This sounds cool but doesn't work in practice for two reasons.

  1. Users have already cloned this repo without initializing submodules. If you start using stuff from submodules, it'll break users when they pull.
  2. If more than one plugin decides to embed zsh-ls-colors in this way, there will be clashes when different plugins are using different incompatible versions.

The only safe way to embed another plugin is to copy its sources and rename all symbols.

romkatv avatar Feb 18 '20 15:02 romkatv

Yeah, you're right. For (1) subtree would still work afaik. Unfortunately, I don't see a way out of (2).

Oh wait, I do see a way out of (2), hold on.

xPMo avatar Feb 18 '20 16:02 xPMo

Unfortunately, I don't see a way out of (2).

I thought of doing it like this in zsh-defer. When you source zsh-defer.plugin.zsh, you can pass an optional parameter. If you do, all symbols (functions and global parameters) defined by zsh-defer will have this prefix. So, if someone wants to use zsh-defer in a plugin, they would bundle the unchanged zsh-defer.plugin.zsh (either as git submodule, subtree, or whatever) and call source zsh-defer.plugin.zsh _my_plugin_. It would define function _my_plugin_zsh-defer.

romkatv avatar Feb 18 '20 16:02 romkatv

Yeah, I just realized that prefixing would work after posting that, and whipped up a quick fix for it. The sacrifice is that now all the functions have to be in one file instead of autoloaded. But I think it's worth the tradeoff of being able to

source ls-color-subtree/ls-colors.zsh fzf-tab::ls-colors
fzf-tab::ls-colors::init
...

xPMo avatar Feb 18 '20 16:02 xPMo

Thanks @romkatv and @xPMo. zsh-ls-colors is cool, it helps a lot.

Aloxaf avatar Feb 19 '20 05:02 Aloxaf

A basic support has been done with the help of @xPMo 's zsh-ls-colors

image

Aloxaf avatar Mar 14 '20 12:03 Aloxaf

I use https://github.com/trapd00r/LS_COLORS

But I just can’t figure out what needs to be written in .zshrc so that the colors are displayed.

Tried so: zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

But the colors are not displayed correctly and the Symbolic link is not displayed correctly, it can be seen in the screenshot: https://i.imgur.com/aGVRZNu.png

If in .zhsrc is not set zstyle ': completion: *' list-colors $ {(s.:.)LS_COLORS} then the colors are not displayed at all.

webmastak avatar Mar 16 '20 07:03 webmastak

@webmastak What is wrong with the colors?

zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

This sets the zstyle to the current value of LS_COLORS as far as I know, so you need to call this after you actually set LS_COLORS.

patrick96 avatar Mar 16 '20 08:03 patrick96

Also @Aloxaf, this works very nicely for me, thank you so much :smiley:

You say this is "basic support", is there anything missing? If not, I think we can close this.

patrick96 avatar Mar 16 '20 08:03 patrick96

I can confirm that it works as advertised.

romkatv avatar Mar 16 '20 08:03 romkatv

I can confirm that it works as advertised.

Understood, I had zstyle ': completion: *: default' list-colors $ {(s.:.)LS_COLORS}

But the symbolic link is buggy: https://i.imgur.com/oiGclDB.png

webmastak avatar Mar 16 '20 08:03 webmastak

@webmastak Does the buggy symbolic link go away if you remove the zstyle command?

patrick96 avatar Mar 16 '20 08:03 patrick96

@webmastak Does the buggy symbolic link go away if you remove the zstyle command?

https://i.imgur.com/xzYGydQ.png

webmastak avatar Mar 16 '20 09:03 webmastak

Figured out.

In the plugin file fzf-tab.zsh you need to replace on line 257: rsv_color=$reply[2] with rsv_color=$reply[1]

https://i.imgur.com/OItX07E.png

webmastak avatar Mar 16 '20 10:03 webmastak

But the symbolic link is buggy

@webmastak Yes...it's a bug introduced in f81cee85dc1cb955f1dd981f58839a825856073c and has been fixed in https://github.com/Aloxaf/fzf-tab/commit/749e86b28f777a173f7307df312d2a78b8c7c661. I think I should write some tests for it.

You say this is "basic support", is there anything missing? If not, I think we can close this.

@patrick96 An example:

zstyle ':completion:*' list-colors '=(#b)(--[^ ]#)(*)=38;5;220;1=38;5;216'

图片

But I'm not sure how many people need it and whether is it necessary after installing fzf-tab.

I won't try to implement it in the short term. Feel free to close the issue if you don't need it. Then I can put it aside without any pressure. XD

Aloxaf avatar Mar 16 '20 12:03 Aloxaf

On linux it works perfectly. Does it work on mac os? Right now on catalina zsh 5.7.1 there is no color fzf output of directory listing.

cradesto avatar May 03 '20 17:05 cradesto

@cradesto I'm not sure. Have you set list-colors correctly?

Aloxaf avatar May 04 '20 08:05 Aloxaf

It seems that yes. Below you can see cleared zshrc (On macosx dircolors is provided as gdircolors by homebrew).

eval "$(dircolors -b)"
source path/to/antigen.zsh
antigen use oh-my-zsh
antigen bundle fzf
antigen bundle Aloxaf/fzf-tab
antigen apply
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

On linux this zshrc works ok. But I can't figure out why it doesn't work on macos.

cradesto avatar May 04 '20 16:05 cradesto

Changes last string to zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} solves the problem for macos.

cradesto avatar May 04 '20 21:05 cradesto

This new update is broken on my machine. It emits this error on startup:

/Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-Aloxaf-SLASH-fzf-tab/fzf-tab.plugin.zsh:source:15: no such file or directory: /Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-SLASH-zbrowse/lib/zsh-ls-colors/ls-colors.zsh

I don't want this colorization stuff. I think it should not be the default, as it'll probably slows things down. How can I turn this off?

NightMachinery avatar Jul 28 '20 12:07 NightMachinery

This new update is broken on my machine. It emits this error on startup:

/Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-Aloxaf-SLASH-fzf-tab/fzf-tab.plugin.zsh:source:15: no such file or directory: /Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-SLASH-zbrowse/lib/zsh-ls-colors/ls-colors.zsh

This looks like a bug in your plugin manager.

I don't want this colorization stuff. I think it should not be the default

It's not on by default.

How can I turn this off?

Don't set list-colors zstyle.

romkatv avatar Jul 28 '20 12:07 romkatv

/Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-Aloxaf-SLASH-fzf-tab/fzf-tab.plugin.zsh:source:15: no such file or directory: /Users/evar/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-SLASH-zbrowse/lib/zsh-ls-colors/ls-colors.zsh

This looks like a bug in your plugin manager.

Apparently, fzf-tab is following https://zdharma.org/zinit/wiki/zsh-plugin-standard/#1_standardized_0_handling and gets tripped by https://github.com/zdharma/zbrowse/blob/09b4a6e2d0161efbac786cfa60e7161389194dd1/zbrowse.plugin.zsh#L8.

Consider using plain ${(%):-%N} in fzf-tab, like in all respectable plugins.

romkatv avatar Jul 28 '20 12:07 romkatv

@romkatv

This looks like a bug in your plugin manager.

I fixed this issue by changing the order of installations:

antibody bundle Aloxaf/fzf-tab
antibody bundle zdharma/fast-syntax-highlighting 
antibody bundle zdharma/zbrowse 

Adding this info to the readme will probably be helpful for at least antibody users.

NightMachinery avatar Jul 28 '20 12:07 NightMachinery

Mac OS: 11.1

I'm on the verge of giving up, but wanted to share my experience as I got everything to work that I wanted on my machine in relation to zsh, fzf, fzf-tab, zstyle, and the myriad of options therein. The only thing that isn't happening for me is different colors for different columns of output.

The configuration page listed in the README seems to not mention list-colors but mentions group-colors. I tried both but it seems that while multiple colors appear horizontally, each particular line in the fzf browser is of the same color.

After brew install coreutils, I tried to follow along with this stackoverflow answer, but I don't see different colors for different columns as explained.

Is there something obvious I am not doing or have not installed?

startakovsky avatar Jan 24 '21 09:01 startakovsky

I've implemented zstyle lookup in the dev branch of zsh-ls-colors. Currently it doesn't respond with the symlink target (or its colorization). Just trying to figure out the best way to add that back into the new all-in-one function.

xPMo avatar Jan 24 '21 13:01 xPMo