Skip to content

LS_COLORS with optional icons and 256 or 24 bit color

License

Notifications You must be signed in to change notification settings

ranebrown/ls-icons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

Custom build of ls

Default ls

If you don't want to go through the trouble of modifying ls.c and rebuilding ls then you can use the below alias in your .bashrc:

alias ls='ls --color=always --group-directories-first -N -w $(expr $(tput cols) - 18)'

The -N flag tells ls to not use quotes around names with spaces. The -w $(...) is used to set the column width. This is necessary since adding in icons adds extra characters that ls does not account for. Without this the output of ls can run off then end of the screen and wrap to the next line making things very ugly. The number 18 was picked as a value that works for me but feel free to adjust it based on your screen size and if you are using something like tmux.

Information

LS Info

Special types:

  • no: Normal: non-filename text, global default (unset by default)
  • fi: File: normal file that doesn't have a color associated with it
  • di: Directory
  • ex: Executable
  • ln: Symbolic link: can set to 'target' to make the color match the pointed to file
  • mh: multihardlink: files with more than one link
  • mi: Missing file: non-existent file pointed to by symlink (the file the link points to when using -l)
  • or: orphaned: symlink pointing to an orphaned non-existent file
  • bd: Block device: buffered special file (stuff in /dev)
  • cd: Character device: unbuffered special file (stuff in /dev)
  • pi: Named pipe (fifo file)
  • so: Socket file
  • do: Door: special file for inter-process communication between a client and server (currently implemented only in Solaris)
  • su: setuid: file that is (u+s)
  • sg: setgid: file that is (g+s)
  • st: sticky: directory with sticky bit set (+t) and not other-writable
  • ow: other-writeable: Directory that is other-writable (o+w) and not sticky
  • tw: directory that is sticky w/ other-writable (+t,o+w)
  • ca: capability: file with capability

Escape Sequence:

  • lc: left code: opening terminal code (default \e[ - escape)
  • rc: right code: closing terminal code (default 'm' - end escape)
  • ec: end code: none-filename text (replaces lc+no+rc) (default undefined)
  • rs: Reset to ordinary colors (default '0')
  • cl: clear to end of line (not sure how this works)
  • Prints out like this: ec lc rc ec lc rc

Default Escape Sequence:
type_code is the escape sequence to define the text attribute and color.

${lc}${type_code}${rc}FILENAME${lc}${no}${rc}

Escape Sequence if ec is defined:

${lc}${type_code}${rc}FILENAME${ec}

ANSI Escape Sequence

Troubleshooting

  • Use ls | less to see ls output with escape sequences including what gets added by ls such as the lc,rc,ec items.
    • This can be useful to see if there are weird/extra escape sequences messing things up.
  • Use the print_ls_colors.sh script to print each item in the LS_COLORS variable on its own line.
    • This made it easier to see specific icons that were causing problems.
    • Using certain icons caused that type to print on the right side of the screen.
    • NOTE: make sure to run this in a full screen terminal

How to create special file types

ln: ln -s source_file link_name
mh: ln source_file link_name
or: delete the file pointed to by a symbolic link
mi: this is the deleted file pointed to by the symbolic link (only visible with -l option)
cd: mknod dcharacter 1 5 (1 5 is major minor rev which is required)
bd: mknod dblock b 1 5 (1 5 is major minor rev which is required)
pi: mkfifo pipe_name
so: python -c "import socket as s; sock = s.socket(s.AF_UNIX); sock.bind('dsocket')"
su: create file and run chmod 4750 file_name
sg: create file and run chmod 2750 file_name
st: create directory then run chmod +t dir_name
ow: create directory then run chmod o+w dir_name
tw: create directory then run chmod +t,o+w dir_name

Unable to create

do: ??? Solaris only
ca: use setcap http://www.andy-pearce.com/blog/posts/2013/Mar/file-capabilities-in-linux/

Known Issues

Certain icons seems to make the listing not display correctly ie large amount of whitespace and icon on the above line. When using tmux with multiple panes have seen the listing get printed across to another pane or mess with the text displayed in vim when it is open. Both of these issues seem to be caused by specific icons. See the troubleshooting section to help determine which icons might be causing issues. Adding/removing extra files in the directory changes how things are printed and can potentially mask the issue.

Known bad icons

Using SauceCodePro NF

  • fc45
  • fb25
  • fb71
  • fd18
  • fce6
  • fce3
  • fbb7
  • fd2c

ToDo

  • Add 256 colors
    • Script to convert rgb colors to 256 palette
  • Allow settings control through command line options
  • Script to generate test filetypes (in test dir) based on COLORS array?
    • Probably want to remove test/ directory so anyone cloning repo doesn't have to download a bunch of files that could be malicious.
  • Add ability to print filetype/icons based on color to test what is set the same
  • Look into cleaning up loop when generating LS_COLORS. Probably a better way to handle things.
  • Add ability to store generated LS_COLORS data in a file so that can be loaded instead of running script each time a shell is started.
    • Document/test/verify speed improvement?
    • Update readme with instructions on using this option
    • Add option to pass in filename where data should be written to
  • Complete/cleanup readme
    • Move some of the info in readme to wiki or other file?
  • Add screenshots of what happens when using bad icons

Done

  • Add support for disabling icons

Acknowledgments

Thanks to the following for inspiration and sources of information:

About

LS_COLORS with optional icons and 256 or 24 bit color

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages