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

bug: default icons not working as expected #381

Closed
3 tasks done
andreafspeziale opened this issue May 18, 2024 · 7 comments
Closed
3 tasks done

bug: default icons not working as expected #381

andreafspeziale opened this issue May 18, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@andreafspeziale
Copy link

andreafspeziale commented May 18, 2024

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

v0.9.5

Operating system/version

MacOS 14.4.1 (23E224)

Describe the bug

Hello and thank you for your hard work!

I just started my nvim customization journey and I'm quite new to nvim, lua etc. so I could be definitely wrong.

Based on my understanding I should be able to set the default folder icon and a fallback icon for all those files "not recognized" by NerdFont like follows:

-- Directory explorer
  {
    'stevearc/oil.nvim',
    dependencies = { 'nvim-tree/nvim-web-devicons', enabled = vim.g.have_nerd_font },
    config = function()
      require('oil').setup {
        columns = { 'icon', directory = '🚀', default_file = '🚀' },
        view_options = {
          show_hidden = true,
          -- This function defines what will never be shown, even when `show_hidden` is set
          is_always_hidden = function(name, bufnr)
            return vim.startswith(name, '..')
          end,
        },
      }

      -- Open parent directory in current window
      vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
    end,
  },

So I would expect to see the rocket icon as folder icon and "unknown" files

Screenshot 2024-05-18 alle 09 50 40

If it is just me not understanding how it works I would be happy to understand how I can achieve my goal which is having a custom icon especially for files regardless its extension.

Plus, based on the above my feeling is that default_file can be misleading as property name for its "fallback" purpose.

I would really love to end up with something like the following:

Screenshot 2024-05-18 alle 10 16 31

The base folder icon and the same icon for all kind of files.

Thank you in advance!

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

Just apply the configuration with custom icons for directory and file

Expected Behavior

Displays the icons when nvim .

Directory structure

No response

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify('./.repro', ':p')

-- set stdpaths to use .repro
for _, name in ipairs { 'config', 'data', 'state', 'runtime', 'cache' } do
  vim.env[('XDG_%s_HOME'):format(name:upper())] = root .. '/' .. name
end

-- bootstrap lazy
local lazypath = root .. '/plugins/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system {
    'git',
    'clone',
    '--filter=blob:none',
    '--single-branch',
    'https://github.com/folke/lazy.nvim.git',
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  'folke/tokyonight.nvim',
  {
    'stevearc/oil.nvim',
    dependencies = { 'nvim-tree/nvim-web-devicons', enabled = true },
    config = function()
      require('oil').setup {
        columns = { 'icon', directory = '🚀', default_file = '🚀' },
        view_options = {
          show_hidden = true,
          -- This function defines what will never be shown, even when `show_hidden` is set
          is_always_hidden = function(name, bufnr)
            return vim.startswith(name, '..')
          end,
        },
      }

      -- Open parent directory in current window
      vim.keymap.set('n', '-', '<CMD>Oil<CR>', { desc = 'Open parent directory' })
    end,
  },
  -- add any other plugins here
}
require('lazy').setup(plugins, {
  root = root .. '/plugins',
})

vim.cmd.colorscheme 'tokyonight'
-- add anything else here

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@andreafspeziale andreafspeziale added the bug Something isn't working label May 18, 2024
@andreafspeziale
Copy link
Author

andreafspeziale commented May 18, 2024

Ok let's go I was missing the "table" part!

{ 'icon', directory = '🚀', default_file = '🚀' }, => { { 'icon', directory = '🚀', default_file = '🚀' } },

Screenshot 2024-05-19 alle 00 43 49

Now, I still have a question:
do we have something like "directory" for files? Actually it doesn't seem to me...

I believe it would be possible to add something like "directory" in terms of feature but named "file" for files.

Maybe it wouldn't be great as name since "default_file" is already there (which I still feel misleading being a fallback... but I think you wouldn't like any renaming => breaking change)

Let me know your thoughts!

@stevearc
Copy link
Owner

stevearc commented Jun 6, 2024

You want to give all files the same icon, ignoring what we get back from nvim-devicons? For what purpose? If you want you could create a custom column for this.

local constants = require("oil.constants")
local FIELD_TYPE = constants.FIELD_TYPE
local FIELD_META = constants.FIELD_META
require("oil.columns").register("simple_icon", {
  render = function(entry, conf)
    local field_type = entry[FIELD_TYPE]
    local meta = entry[FIELD_META]
    if field_type == "link" and meta then
      if meta.link_stat then
        field_type = meta.link_stat.type
      end
    end
    local icon, hl
    if field_type == "directory" then
      icon = "🚀"
      hl = "OilDirIcon"
    else
      icon = "🚀"
    end
    return { icon, hl }
  end,

  parse = function(line, conf) return line:match("^(%S+)%s+(.*)$") end,
})

@stevearc stevearc added the question Further information is requested label Jun 6, 2024
@andreafspeziale
Copy link
Author

Sorry I literally missed your response, I'll read it asap and eventually continue the conversation or closing the issue. Thanks for your patience 🙏

@github-actions github-actions bot removed the question Further information is requested label Aug 20, 2024
@andreafspeziale
Copy link
Author

Hi Steven and happy new year! Sorry if I've not been hanging around lately.

First of all I want to clarify that I believe there is no bug here. I was just doing some try and fail to get some level of customization.

You want to give all files the same icon, ignoring what we get back from nvim-devicons?

Basically yes, what I would like to achieve is the same icon for everything that is not a folder.

Screenshot 2025-01-07 alle 23 52 01

Like it is already possible with the folder icons

Screenshot 2025-01-07 alle 23 55 55

If the answer is already in your last comment please bear with me in expanding it, I'm happy to learn and understand

@stevearc
Copy link
Owner

stevearc commented Jan 8, 2025

Yeah, if you just want the same icon for all files you can use the snippet I posted above and replace your icon column with the new simple_icon column.

@andreafspeziale
Copy link
Author

All right, this is working great. I created a new col as suggested keeping the directory option business logic and defaulting files to my favorite icon. I love this simple look and feel.

Screenshot 2025-01-08 alle 12 24 02

BTW I believe this could be turn into a feature in order to avoid all that "boilerplate", what do you think? Based on my noob understanding I believe that the business logic is already greatly encapsulated here

and we could have a new option like in here to override the file icon.

Let me know your thoughts! Maybe it's just a dumb idea. In this case feel free to "Close with comment" this issue. Thx again for the plugin and the support!

@stevearc
Copy link
Owner

stevearc commented Jan 8, 2025

I think this is a relatively niche use case; most people either don't want icons or they want the filetype icons provided by the icon plugins. If a larger demand for this appears I'll consider it, but for now I think it's best to leave it as user config.

@stevearc stevearc closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants