Skip to content
forked from lVoidi/Icon-ls

A highly customizable file listing script

Notifications You must be signed in to change notification settings

miway08/Icon-ls

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 

Repository files navigation

Icon ls

image


Installation

The first thing that we need, are the nerd fonts, so we can see and personalize the icons in the script

So to do this, we will download any font from here and copy them to your fonts directory

If you dont have the .fonts directory...

    mkdir ~/.fonts
    mv any-font.zip ~/.fonts
    unzip ~/.fonts/any-font.zip
  

and you'll have your font installed

then, you need to change your terminal font to the installed one, so check your terminal emulator wiki to do that


After installing the font, you can install the script now

    curl https://raw.githubusercontent.com/MrJakeSir/Icon-ls/master/ls.py -o path/to/script
  

after you install the script, you have two options:

  • You can create a binary file by using pyinstaller or py2bin
  • Or you can create a simple alias in your .zshrc to call the script

I will explain the second option because it is way easier and its the same thing

we need to go our home directory

    cd
  

and then edit your shell config file. For this, you can use vim, neovim, emacs, nano or any other

    # USE YOUR TEXT EDITOR HERE
    
    # For zsh
    nvim .zshrc

    # bash shell
    nvim .bashrc
  

then, add this line to the end of your file, changing the path/to/script.py to your actual path

    alias ls="python3 path/to/script.py"
  

restart your terminal and you're done!


Usage

Type in your terminal ls

You can also see what's inside a directory ls directory/

Options

      -h  --help                      Shows this dialog
      -sh -a --show-hidden            Shows the hidden files
      -oh -hi --only-hidden           Shows ONLY the hidden files
      -ex --exclude                   Excludes a file extension, for example:
                                              ls -ex 'py'
                                              This will exclude all the python files
      -od -d --only-dirs              This will display only the directories
  

Configuration

All you need is in the class Extensions It contains all the configuration options, you don't have to create any directory in .config, you just modify the script itself.

Changing icons

All the icons are in the variable called self.extensions, it is just a python dictionary, you can add filetypes there with its icon, you just need to add the dictionary item
    self.extensions = {
      #... some items here
      'filetype': ''
    }
  

Changing colors

For this, will be a little more complex than just changing the icons. First of all, we need to search for this line of code:
    # Change this to custom if you want                                                                                                                                                       
    # to specify a color for each filetype
    # if it is custom, it will use self.filetype_color dictionary
    # to the colorscheme                                                                                                                                                                      
    self.colortype = 'rainbow'
    # self.colortype = 'custom'  
  

Once found, you have to comment the line self.colortype = 'rainbow' by adding a hash symbol at the start of the line, then, you need to remove the comment from the line below of it.

after doing that, it will look something like this

    # Change this to custom if you want                                                                                                                                                       
    # to specify a color for each filetype
    # if it is custom, it will use self.filetype_color dictionary                                                                                                                             
    # to the colorscheme                                                                                                                                                                      
    # self.colortype = 'rainbow'
    self.colortype = 'custom'
  

After doing this, we also need to find this line of code

    # You can change the filetype color here
    # or you can also add more customized filetypes
    # the colors are in Red, Green and Blue format
    #   filetype    =    (r, g, b)
    self.filetype_color = dict(
        directory = (230, 255, 230),
        file = (255, 230, 230),
        # Examples for different filetypes
        # python = (252, 244, 3),
        # lua = (0, 0, 255)
    )

  

'file' is the default colour of the files

As you can see in the commented lines, there are examples of how you can add a specific color to the filetype you want, the colors are in rgb format, so the first element in the tupple represents RED value, second element in the tupple represents GREEN value and the last element in the tupple represents blue value

for example, this line: python = (252, 244, 3)

This will show a yellow colour, based on python scheme

we can add this to our dictionary to make it look something like

    self.filetype_color = dict(
      # some lines of code..
      python = (252, 244, 3)
    )
  

In order to this to work, we'll need to specify the file extension that this item is related to

To do this, we just need to go to the python function right below it and add a condition for this extension. Don't worry! it's very easy! also, there are commented examples that you can use to guide.

the condition has this syntax

    elif extension == 'filetype-extension':
      return 'filetype'
  

yo need to add that line of code here

codeline

Is that easy! using python example...

    elif extension == 'py':
      return 'python'
  

If the filetype you are refering to, has more than one extensions, you can simply use a python list and the in statement

    elif extension in ['py',
                       'pyc']:
      return 'python'
  

and that's it!

Default options

End

You can change the separator between each line, the default separator is a newline \n, but you can use any other

just modify this line of code and change the end for whatever you want end

Hidden files or dotfiles

You can set the script to show hidden files by default, by just changing SHOW_HIDDEN variable to True showhidden


Thanks for using my script!

About

A highly customizable file listing script

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%