Giter Site home page Giter Site logo

cafehaine / xontrib-xlsd Goto Github PK

View Code? Open in Web Editor NEW
21.0 3.0 4.0 159 KB

xontrib-xlsd is the next gen ls command for xonsh shell, inspired by lsd.

License: GNU General Public License v3.0

Python 100.00%
xonsh xontrib terminal ls lsd emojis python

xontrib-xlsd's Introduction

xontrib-xlsd is the next gen ls command for xonsh shell, inspired by lsd.

Preview image

Contents

  1. How to install xontrib-xlsd
  2. Features
  3. Customizing

How to install xontrib-xlsd

Release version

Install the xontrib

xpip install xontrib-xlsd

And load it in your .xonshrc:

xontrib load xlsd

From git (might be unstable)

xpip install git+https://github.com/cafehaine/xontrib-xlsd

And load it in your .xonshrc:

xontrib load xlsd

Features

  • Emojis
  • Colors
  • A tree-like display when called recursively
  • Customizable
  • Written in python so it doesn't need to run a separate binary

Customizing

Icons

Registering an icon

In xlsd, icons are registered using a name. The name is then used by the different rules to get an icon for an PathEntry.

You can view the built-in icons in xlsd/icons.py.

Here is how to add an icon (for example a rainbow). Put this in your .xonshrc

import xlsd.icons

xlsd.icons.LS_ICONS.add('rainbow', "๐ŸŒˆ")

Icon sources can now use your fancy icon.

You can also override built-in icons this way.

Extension based icon source

The extension based rules are the fastest to run, and thus are the prefered way of setting icons.

For example, to use your previously defined rainbow icon as the icon for .txt files, you can add the following snippet in your .xonshrc:

import xlsd.icons

xlsd.icons.EXTENSION_ICONS.insert(0, ({'txt'}, 'rainbow'))

Libmagic based icon source

IMPORTANT NOTE: This source seems to only work on Arch Linux systems at the moment.

The libmagic (used by the file command on *nix) based rules are slower, but allow getting an icon when no extension matched.

For example, here we're going to use the xonsh icon for all folders. Add the following snippet in your .xonshrc:

import xlsd.icons

xlsd.icons.MIMETYPE_ICONS.insert(0, ("inode/directory", 'xonsh'))

Note that this won't work unless you set the icon source order with libmagic as the first source, since the extension source already defines an icon for directory entries.

Creating a custom icon source and changing the order

The following snipped registers a new icon source (that simply returns the xonsh icon for everything), and makes it the first checked source. Put this in your .xonshrc.

@xlsd_register_icon_source('my_source')
def my_icon_source(direntry):
    return 'xonsh'

$XLSD_ICON_SOURCES = ['my_source', 'extension', 'libmagic']

File order

Setting the file order

In your .xonshrc, define a $XLSD_SORT_METHOD environment variable with one of the following values:

  • "directories_first": The default: alphabetical order, with directories first
  • "alphabetical": Simple alphabetical order
  • "as_is": The default order of your OS.

Creating your own sort function

You can create a simple alphabetical (case sensitive) sort function with the snippet:

import xlsd

@xlsd.xlsd_register_sort_method('alpha_case_sensitive')
def my_sort_method(entries):
    entries.sort(key=lambda e: e.name)
    return entries

-l mode columns

Changing the columns/the order

In your .xonshrc, define a $XLSD_LIST_COLUMNS environment variable and set it's value to your desires.

The default value (similar to coreutil's ls) is the following:

$XLSD_LIST_COLUMNS = ['mode', 'hardlinks', 'uid', 'gid', 'size', 'mtime', 'name']

All the built-in columns are used in this config.

Writing your own column

A column is a function taking for only argument an PathEntry and that outputs a string.

A simple filename column could be registered like this:

@xlsd_register_column('filename', ColumnAlignment.LEFT)
def _xlsd_column_filename(direntry):
    return direntry.name

Colors

There are multiple colors/text effects that you can change in xlsd.

The full list of used colors is available in xlsd/__init__.py.

Here is a small example: we're going to make the size unit in -l mode appear red.

import xlsd

xlsd.COLORS['size_unit'] = '{INTENSE_RED}'

You can use any valid xonsh color.

For a quick list of colors/text effects, check out the xonsh tutorial on colors.

Item Name

By default, xlsd prints the item name with {icon} {name} format. You can update the $XLSD_NAME_FORMAT environment variable to change the format of the item. For example $XLSD_NAME_FORMAT={icon}{name} will remove the single space between icon & name.

xontrib-xlsd's People

Contributors

anki-code avatar cafehaine avatar deeuu avatar jd-solanki avatar scopatz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xontrib-xlsd's Issues

Can the sort order match ls?

Right now all directories are listed before regular files. Is it possible to enable everything to be sorted alphabetically or lexicographically? Thanks!

Use a buffer to speed up printing

The current behavior flushes at every new line, which can be quite slow especially when using the list or tree mode.

Switch to a manual flush if possible.

Simple releasing PyPi package with Github Actions

Hi! Great xontrib!

If you want simple way to release the xontrib to PyPi there is a way:

  1. Click Actions

Screenshot_20200916_115026

  1. Click Set up workflow on Publish Python Action

Screenshot_20200916_114928

  1. Commit the config without any changes

  2. Go to repo Settings - Secrets and add:

Screenshot_20200916_115332

  1. Now when you create Release and the Actions will publish the package to PyPi automatically (look at Actions link)

Enjoy :)

targeting a file throws NotADirectoryErrorr

@ ls -la ~/foo

Traceback (most recent call last):
  File "/home/me/.local/lib/python3.9/site-packages/xonsh/procs/proxies.py", line 522, in run
    r = self.f(self.args, sp_stdin, sp_stdout, sp_stderr, spec, spec.stack)
  File "/home/me/.local/lib/python3.9/site-packages/xonsh/procs/proxies.py", line 318, in proxy_five
    return f(args, stdin, stdout, stderr, spec)
  File "/usr/local/lib/python3.9/site-packages/xontrib/xlsd.xsh", line 643, in _ls
    _long_list(path, arguments.all)
  File "/usr/local/lib/python3.9/site-packages/xontrib/xlsd.xsh", line 582, in _long_list
    direntries = _get_entries(path, show_hidden)
  File "/usr/local/lib/python3.9/site-packages/xontrib/xlsd.xsh", line 362, in _get_entries
    with os.scandir(path) as iterator:
NotADirectoryError: [Errno 20] Not a directory: '/home/me/foo'
Return 1

Not sure if this is a issue or not. I wasn't able to find any references anywhere, so please let me know if this is a config issue on my end, or if I need to help debug further.

doesn't work

xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
The xonsh.proc module has been deprecated in favor of the xonsh.procs subpackage.
โ•ญโ”€i530566(xonsh) at C17ZL21PMD6M in ~/.dotfiles
โ•ฐโ”€ $ ls
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
AttributeError: module 'xonsh.platform' has no attribute 'scandir'
xonsh: For full traceback set: $XONSH_SHOW_TRACEBACK = True
xonsh.proc.STDOUT_CAPTURE_KINDS has been deprecated. please use xonsh.procs.pipelines.STDOUT_CAPTURE_KINDS instead.
โ•ญโ”€i530566(xonsh) at C17ZL21PMD6M in ~/.dotfiles
โ•ฐโ”€ $ xonfig
+------------------+----------------------+
| xonsh            | 0.9.27               |
| Git SHA          | 71fe9014             |
| Commit Date      | Jan 29 08:58:58 2021 |
| Python           | 3.8.7                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.16               |
| shell type       | prompt_toolkit       |
| pygments         | 2.8.0                |
| on posix         | True                 |
| on linux         | False                |
| on darwin        | True                 |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| on jupyter       | False                |
| jupyter kernel   | None                 |
| xontrib 1        | abbrevs              |
| xontrib 2        | argcomplete          |
| xontrib 3        | autovox              |
| xontrib 4        | autoxsh              |
| xontrib 5        | avox                 |
| xontrib 6        | avox_poetry          |
| xontrib 7        | back2dir             |
| xontrib 8        | cmd_done             |
| xontrib 9        | commands             |
| xontrib 10       | coreutils            |
| xontrib 11       | direnv               |
| xontrib 12       | docker_tabcomplete   |
| xontrib 13       | fzf-widgets          |
| xontrib 14       | gitinfo              |
| xontrib 15       | histcpy              |
| xontrib 16       | vox                  |
| xontrib 17       | voxapi               |
| xontrib 18       | xlsd                 |
| xontrib 19       | z                    |
+------------------+----------------------+

Make the icon selection architecture more modular

The current code is hardcoded into doing the following:

  • File extension check
  • Libmagic check

However, the libmagic used is the one packaged in the libmagic arch linux package, so it might not be available everywhere.

We should allow registering multiple icon sources with a specified priority (and also guard the import for libmagic in a try catch).

Add social preview to the repo

Hi! Thank you for the xontrib!

If you open xontrib topic on Github and scroll down you'll see the cute preview images for some xontribs. This is "Social preview" image that could be uploaded in the Settings of the repo.

Please take a common screenshot of your prompt and put it to the preview image.

Thanks!

LS_COLORS Support

I realized what else was causing me issues here. Basically, this does not support LS_COLORS, so all file types come out with the same base text color. This should be relatively easy to add with the use of $LS_COLORS, which is a special mapping in xonsh from globs to xonsh color names, and the use of xonsh.tools.print_color() or format_color().

-p preview or -i icon mode

Using the kitty graphics protocol, we could show thumbnails for files using the installed thumbnailers.

This could be nice especially for photo directories.

Install an xlsd executable in setup.py

This would allow running xlsd without xonsh.

Not really something I would see myself doing, but hey, I might as well give the users the freedom to choose their shells.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.