lsd-rs/lsd

[Bug]: `icons.yaml` does not seem to override icons

hawkw opened this issue ยท 6 comments

Version

  • latest

version

eliza@theseus ~ $ lsd --version
lsd 1.1.2

What OS are you seeing the problem on?

Linux

installation

From Nixpkgs

term

eliza@theseus ~ $ echo $TERM
alacritty

ls-colors

eliza@theseus ~ $ echo $LS_COLORS
rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.7z=01;31:*.ace=01;31:*.alz=01;31:*.apk=01;31:*.arc=01;31:*.arj=01;31:*.bz=01;31:*.bz2=01;31:*.cab=01;31:*.cpio=01;31:*.crate=01;31:*.deb=01;31:*.drpm=01;31:*.dwm=01;31:*.dz=01;31:*.ear=01;31:*.egg=01;31:*.esd=01;31:*.gz=01;31:*.jar=01;31:*.lha=01;31:*.lrz=01;31:*.lz=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.lzo=01;31:*.pyz=01;31:*.rar=01;31:*.rpm=01;31:*.rz=01;31:*.sar=01;31:*.swm=01;31:*.t7z=01;31:*.tar=01;31:*.taz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tgz=01;31:*.tlz=01;31:*.txz=01;31:*.tz=01;31:*.tzo=01;31:*.tzst=01;31:*.udeb=01;31:*.war=01;31:*.whl=01;31:*.wim=01;31:*.xz=01;31:*.z=01;31:*.zip=01;31:*.zoo=01;31:*.zst=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:

What happened?

I have an icons.yaml file in $HOME/config/lsd/icons.yaml. The icons.theme key in $HOME/.config/lsd/config.yaml is set to "unicode", and icons.when is set to "auto". However, my specified file type icons in icons.yaml do not seem to override the defaults.

For example:

eliza@theseus ~ $ lsd ~/.config/lsd
๐Ÿ”– config.yaml  ๐Ÿ”– icons.yaml

eliza@theseus ~ $ cat ~/.config/lsd/config.yaml
color:
  when: auto
hyperlink: auto
icons:
  separator: ' '
  theme: unicode
  when: auto

eliza@theseus ~ $ cat ~/.config/lsd/icons.yaml
filetype:
  device_block: ๐Ÿ–ด
  device_char: ๐Ÿ–ต
  dir: ๐Ÿ—€
  executable: ๐Ÿ—”
  file: ๐Ÿ—Ž
  pipe: โญ
  socket: ๐Ÿ–ง

eliza@theseus ~ $ ls
๐Ÿ“‚ Code  ๐Ÿ“‚ Desktop  ๐Ÿ“‚ Documents  ๐Ÿ“‚ Downloads  ๐Ÿ“„ hubris.core.ringbuf-counts  ๐Ÿ“‚ keybase  ๐Ÿ“‚ Music  ๐Ÿ“‚ Pictures  ๐Ÿ“‚ Public  ๐Ÿ“„ se.jpeg  ๐Ÿ“‚ Templates  ๐Ÿ“‚ Videos  ๐Ÿ“„ vudials.log

eliza@theseus ~ $ lsd
๐Ÿ“‚ Code       ๐Ÿ“‚ Downloads                   ๐Ÿ“‚ Music     ๐Ÿ“„ se.jpeg    ๐Ÿ“„ vudials.log
๐Ÿ“‚ Desktop    ๐Ÿ“„ hubris.core.ringbuf-counts  ๐Ÿ“‚ Pictures  ๐Ÿ“‚ Templates
๐Ÿ“‚ Documents  ๐Ÿ“‚ keybase                     ๐Ÿ“‚ Public    ๐Ÿ“‚ Videos

eliza@theseus ~ $ lsd /dev
๐Ÿ–จ autofs           ๐Ÿ–จ hidraw2      ๐Ÿ–จ kvm           ๐Ÿ”– rtc      ๐Ÿ–จ tty26  ๐Ÿ–จ tty54        ๐Ÿ–จ vcs6
๐Ÿ“‚ block           ๐Ÿ–จ hpet         ๐Ÿ”– log          ๐Ÿ–จ rtc0      ๐Ÿ–จ tty27  ๐Ÿ–จ tty55        ๐Ÿ–จ vcs7
๐Ÿ–จ btrfs-control    ๐Ÿ“‚ hugepages   ๐Ÿ–จ loop-control  ๐Ÿ“‚ shm      ๐Ÿ–จ tty28  ๐Ÿ–จ tty56        ๐Ÿ–จ vcsa
๐Ÿ“‚ bus             ๐Ÿ–จ hwrng        ๐Ÿ’ฝ loop0        ๐Ÿ–จ snapshot  ๐Ÿ–จ tty29  ๐Ÿ–จ tty57        ๐Ÿ–จ vcsa1
๐Ÿ“‚ char            ๐Ÿ–จ i2c-0        ๐Ÿ’ฝ loop1        ๐Ÿ“‚ snd      ๐Ÿ–จ tty3   ๐Ÿ–จ tty58        ๐Ÿ–จ vcsa2
๐Ÿ–จ console          ๐Ÿ–จ i2c-1        ๐Ÿ’ฝ loop2        ๐Ÿ”– stderr   ๐Ÿ–จ tty30  ๐Ÿ–จ tty59        ๐Ÿ–จ vcsa3
๐Ÿ”– core            ๐Ÿ–จ i2c-10       ๐Ÿ’ฝ loop3        ๐Ÿ”– stdin    ๐Ÿ–จ tty31  ๐Ÿ–จ tty6         ๐Ÿ–จ vcsa4
๐Ÿ“‚ cpu             ๐Ÿ–จ i2c-11       ๐Ÿ’ฝ loop4        ๐Ÿ”– stdout   ๐Ÿ–จ tty32  ๐Ÿ–จ tty60        ๐Ÿ–จ vcsa5
๐Ÿ–จ cpu_dma_latency  ๐Ÿ–จ i2c-12       ๐Ÿ’ฝ loop5        ๐Ÿ–จ tee0      ๐Ÿ–จ tty33  ๐Ÿ–จ tty61        ๐Ÿ–จ vcsa6
๐Ÿ–จ cuse             ๐Ÿ–จ i2c-13       ๐Ÿ’ฝ loop6        ๐Ÿ–จ tpm0      ๐Ÿ–จ tty34  ๐Ÿ–จ tty62        ๐Ÿ–จ vcsa7
๐Ÿ–จ dbc              ๐Ÿ–จ i2c-14       ๐Ÿ’ฝ loop7        ๐Ÿ–จ tpmrm0    ๐Ÿ–จ tty35  ๐Ÿ–จ tty63        ๐Ÿ–จ vcsu
๐Ÿ“‚ disk            ๐Ÿ–จ i2c-15       ๐Ÿ“‚ mapper       ๐Ÿ–จ tty       ๐Ÿ–จ tty36  ๐Ÿ–จ tty7         ๐Ÿ–จ vcsu1
๐Ÿ’ฝ dm-0            ๐Ÿ–จ i2c-16       ๐Ÿ–จ media0        ๐Ÿ–จ tty0      ๐Ÿ–จ tty37  ๐Ÿ–จ tty8         ๐Ÿ–จ vcsu2
๐Ÿ’ฝ dm-1            ๐Ÿ–จ i2c-17       ๐Ÿ–จ mem           ๐Ÿ–จ tty1      ๐Ÿ–จ tty38  ๐Ÿ–จ tty9         ๐Ÿ–จ vcsu3
๐Ÿ“‚ dri             ๐Ÿ–จ i2c-18       ๐Ÿ“‚ mqueue       ๐Ÿ–จ tty10     ๐Ÿ–จ tty39  ๐Ÿ–จ ttyS0        ๐Ÿ–จ vcsu4
๐Ÿ–จ drm_dp_aux0      ๐Ÿ–จ i2c-19       ๐Ÿ“‚ net          ๐Ÿ–จ tty11     ๐Ÿ–จ tty4   ๐Ÿ–จ ttyS1        ๐Ÿ–จ vcsu5
๐Ÿ–จ drm_dp_aux1      ๐Ÿ–จ i2c-2        ๐Ÿ–จ ng0n1         ๐Ÿ–จ tty12     ๐Ÿ–จ tty40  ๐Ÿ–จ ttyS2        ๐Ÿ–จ vcsu6
๐Ÿ–จ drm_dp_aux2      ๐Ÿ–จ i2c-20       ๐Ÿ–จ null          ๐Ÿ–จ tty13     ๐Ÿ–จ tty41  ๐Ÿ–จ ttyS3        ๐Ÿ–จ vcsu7
๐Ÿ–จ drm_dp_aux3      ๐Ÿ–จ i2c-21       ๐Ÿ–จ nvme0         ๐Ÿ–จ tty14     ๐Ÿ–จ tty42  ๐Ÿ–จ udmabuf      ๐Ÿ“‚ vfio
๐Ÿ–จ drm_dp_aux4      ๐Ÿ–จ i2c-22       ๐Ÿ’ฝ nvme0n1      ๐Ÿ–จ tty15     ๐Ÿ–จ tty43  ๐Ÿ–จ uhid         ๐Ÿ–จ vga_arbiter
๐Ÿ–จ drm_dp_aux5      ๐Ÿ–จ i2c-3        ๐Ÿ’ฝ nvme0n1p1    ๐Ÿ–จ tty16     ๐Ÿ–จ tty44  ๐Ÿ–จ uinput       ๐Ÿ–จ vhci
๐Ÿ–จ drm_dp_aux6      ๐Ÿ–จ i2c-4        ๐Ÿ’ฝ nvme0n1p2    ๐Ÿ–จ tty17     ๐Ÿ–จ tty45  ๐Ÿ–จ urandom      ๐Ÿ–จ vhost-net
๐Ÿ–จ drm_dp_aux7      ๐Ÿ–จ i2c-5        ๐Ÿ’ฝ nvme0n1p3    ๐Ÿ–จ tty18     ๐Ÿ–จ tty46  ๐Ÿ–จ userfaultfd  ๐Ÿ–จ vhost-vsock
๐Ÿ–จ drm_dp_aux8      ๐Ÿ–จ i2c-6        ๐Ÿ–จ nvram         ๐Ÿ–จ tty19     ๐Ÿ–จ tty47  ๐Ÿ–จ userio       ๐Ÿ–จ video0
๐Ÿ–จ fb0              ๐Ÿ–จ i2c-7        ๐Ÿ–จ port          ๐Ÿ–จ tty2      ๐Ÿ–จ tty48  ๐Ÿ“‚ v4l         ๐Ÿ–จ video1
๐Ÿ—‚ fd               ๐Ÿ–จ i2c-8        ๐Ÿ–จ ppp           ๐Ÿ–จ tty20     ๐Ÿ–จ tty49  ๐Ÿ–จ vcs          ๐Ÿ–จ watchdog
๐Ÿ–จ full             ๐Ÿ–จ i2c-9        ๐Ÿ–จ ptmx          ๐Ÿ–จ tty21     ๐Ÿ–จ tty5   ๐Ÿ–จ vcs1         ๐Ÿ–จ watchdog0
๐Ÿ–จ fuse             ๐Ÿ–จ iio:device0  ๐Ÿ“‚ pts          ๐Ÿ–จ tty22     ๐Ÿ–จ tty50  ๐Ÿ–จ vcs2         ๐Ÿ–จ zero
๐Ÿ–จ gpiochip0        ๐Ÿ“‚ input       ๐Ÿ–จ random        ๐Ÿ–จ tty23     ๐Ÿ–จ tty51  ๐Ÿ–จ vcs3
๐Ÿ–จ hidraw0          ๐Ÿ–จ kfd          ๐Ÿ–จ rfkill        ๐Ÿ–จ tty24     ๐Ÿ–จ tty52  ๐Ÿ–จ vcs4
๐Ÿ–จ hidraw1          ๐Ÿ–จ kmsg         ๐Ÿ”– root         ๐Ÿ–จ tty25     ๐Ÿ–จ tty53  ๐Ÿ–จ vcs5

eliza@theseus ~ $

Note that the overridden directory, block device, char device, and file icons in icons.yaml are not used.

What expected?

I would have expected the overridden icons to be used, as described in the README here.

What else?

It seems like the documentation on setting a custom icon theme in the README may no longer describe lsd's actual behavior? Looking at lsd/src/theme.rs, it looks like the Theme struct now attempts to parse an icon theme, color theme, and Git symbols from the same file:

lsd/src/theme.rs

Lines 18 to 26 in 9b310da

#[derive(Debug, Deserialize, Default, PartialEq, Eq)]
#[serde(rename_all = "kebab-case")]
#[serde(deny_unknown_fields)]
#[serde(default)]
pub struct Theme {
pub color: ColorTheme,
pub icon: IconTheme,
pub git_theme: GitThemeSymbols,
}

lsd/src/theme.rs

Lines 39 to 83 in 9b310da

/// Read theme from a file path
/// use the file path as-is if it is absolute
/// search the config paths folders for it if not
pub fn from_path<D>(file: &str) -> Result<D, Error>
where
D: DeserializeOwned + Default,
{
let real = if let Some(path) = config_file::expand_home(file) {
path
} else {
print_error!("Not a valid theme file path: {}.", &file);
return Err(Error::InvalidPath(file.to_string()));
};
let mut paths = if Path::new(&real).is_absolute() {
vec![real].into_iter()
} else {
config_file::Config::config_paths()
.map(|p| p.join(real.clone()))
.collect::<Vec<_>>()
.into_iter()
};
let Some(valid) = paths.find_map(|p| {
let yaml = p.with_extension("yaml");
let yml = p.with_extension("yml");
if yaml.is_file() {
Some(yaml)
} else if yml.is_file() {
Some(yml)
} else {
None
}
}) else {
return Err(Error::InvalidPath("No valid theme file found".to_string()));
};
match fs::read_to_string(valid) {
Ok(yaml) => match Self::with_yaml(&yaml) {
Ok(t) => Ok(t),
Err(e) => Err(Error::InvalidFormat(e)),
},
Err(e) => Err(Error::ReadFailed(e)),
}
}

I'd be happy to open a PR to either update the documentation or fix the implementation so that it does what the documentation says! However, before doing that, it would be great to hear from the maintainers regarding what the intended behavior here is. Is the icon theme still supposed to be parsed from $XDG_CONFIG_HOME/lsd/icons.yaml as described in the README, or is the apparent behavior of parsing both the icons and color theme from the same YAML file correct? If the current behavior is intended, how is the new theme file supposed to be used --- where should it be located, and how do I point lsd at it?

@hawkw FYI, this appears to be fixed as of version 1.1.5. Here are some custom overrides in my icons.yaml file:

Screenshot from 2024-10-01 00-12-07

The custom icons are only applied when the icon theme is fancy, as evidenced by these lines:

lsd/src/icon.rs

Lines 16 to 26 in 82124fd

let icon_theme = match (tty, when, theme) {
(_, IconOption::Never, _) | (false, IconOption::Auto, _) => None,
(_, _, FlagTheme::Fancy) => {
if let Ok(t) = Theme::from_path::<IconTheme>("icons") {
Some(t)
} else {
Some(IconTheme::default())
}
}
(_, _, FlagTheme::Unicode) => Some(IconTheme::unicode()),
};

This should ideally be reflected in the documentation, I spent quite a while trying to figure out why my icons were not working.

@hxlnt , I am not able to reproduce your setup with the same version. Could you please share your icons.yaml file?

@nilp0inter Sure, though the characters won't render correctly here, as they require a Nerdfont. I've also included my config.yaml.

config.yaml:

classic: false
blocks:
  - name
  - size
  - date
color:
  when: auto
  theme: custom
date: relative
dereference: false
icons:
  when: always
  theme: fancy
  separator: " "
indicators: false
layout: tree
recursion:
  enabled: false
  depth: 1
size: short
sorting:
  column: name
  reverse: false
  dir-grouping: first
no-symlink: false
total-size: false
hyperlink: always
symlink-arrow: โ‡’
header: true

icons.yaml

name:
  .bashrc: ๏‘ข
  .eslintrc.js: ๏
  .eslintrc.json: ๏
  .eslintrc.yml: ๏‘ข
  .git: ๏“”
  .gitignore: ๏˜
  .gitlab-ci.yml: ๏‘ข
  .todo: ๏’ 
  .trash: ๏’Ž
  commit_editmsg: ๏˜
  config: ๏‘ข
  desktop: ๏’ฉ
  description: ๏˜
  documents: ๏“”
  downloads: ๏“”
  fetch_head: ๏˜
  go.mod: ๏
  go.sum: ๏
  head: ๏˜
  heroku.yml: ๏‘ข
  index: ๏˜
  lib: ๏“”
  license: ๏ฝ
  makefile: ๏ฃ
  music: ๏“”
  node_modules: ๏“”
  orig_head: ๏˜
  package.json: ๏
  pictures: ๏“”
  public: ๏“”
  pyproject.toml: ๏‘ข
  scripts: ๏“”
  src: ๏“”
  tests: ๏“”
  videos: ๏“”
extension:
  1: ๏‘”
  2: ๏‘”
  3: ๏‘”
  4: ๏‘”
  asm: ๏
  avi: ๏”ฌ
  bak: ๏‘ค
  bat: ๏’‰
  bin: ๏‘ฑ
  bmp: ๏“ฅ
  c: ๏
  cpp: ๏
  cert: ๏“‘
  cfg: ๏‘ข
  cson: ๏
  css: ๏
  csv: ๏”ฅ
  db: ๏‘ฒ
  deb: ๏’‡
  doc: ๏“ป
  docx: ๏“ป
  ejs: ๏
  exe: ๏‘ฑ
  go: ๏
  gif: ๏”ฌ
  git: ๏˜
  h: ๏
  hpp: ๏
  hex: ๏‘ฑ
  htm: ๏
  html: ๏
  img: ๏“ฅ
  ini: ๏‘ข
  ino: ๏
  jpeg: ๏“ฅ
  jpg: ๏“ฅ
  js: ๏
  json: ๏
  jsx: ๏
  key: ๏ฝ
  list: ๏‘‘
  lock: ๏‘–
  log: ๏“ญ
  lua: ๏
  md: ๏’Š
  m4v: ๏”ฌ
  mpeg: ๏”ฌ
  mpg: ๏”ฌ
  nes: ๏‘ฑ
  nfo: ๏‘‰
  old: ๏‘”
  otf: ๏”จ
  png: ๏“ฅ
  ppt: ๏”ž
  pptx: ๏”ž
  py: ๏
  rar: ๏
  rom: ๏‘ฑ
  rs: ๏
  rss: ๏จ
  save: ๏‘”
  sh: ๏’‰
  tar: ๏
  toml: ๏‘ข
  ts: ๏
  tsx: ๏
  ttf: ๏”จ
  txt: ๏“ถ
  vue: ๏
  xls: ๏”ฅ
  xlsx: ๏”ฅ
  xml: ๏
  yaml: ๏‘ข
  yml: ๏‘ข
  zip: ๏
filetype:
  dir: ๏“”
  file: ๏’ฅ

@hxlnt Thanks! I was able to identify the issue. It turned out that I was trying to override the Downloads folder, but it wasn't having the desired effect. Upon further investigation, I discovered that the keys should be in lowercase. To successfully override the icon in the Downloads directory, I had to include a downloads entry.

for @hawkw, there are typos in your config, should be device-block, not device_block.

for @nilp0inter, the lowercase limitation comes from yaml, we currently do not have a good solution for that, I will try to dive deeper when have time.

this issue is overly divergent, so I am closing it.

please feel free to open an issue for specific questions.