Skip to main content

Associate files with app or alias and run it without preceding commands in xonsh shell.

Project description

When you click to a file or folder in graphical OS they will be opened in associated app. The xontrib-onepath brings the same logic for the xonsh shell. Type the filename or path without preceding command and an associated action will be executed. The actions are customizable.

If you like the idea of bar theme click ⭐ on the repo and stay tuned by watching releases.

Install

xpip install -U xontrib-onepath
echo 'xontrib load onepath' >> ~/.xonshrc
# Reload xonsh

Default actions

If file has execution permission it will be executed. If typed command is a registered name (i.e. git) and which command returns the path (i.e. /usr/bin/git) it will be executed. In other case the typed path will be used to make action. Default actions:

Type Action
DIR ls
text/plain vim
image/ xdg-open

Help to add more types and best default actions. PRs are welcome!

Examples

$ /                      # ls /
$ ~/.xonshrc             # vim ~/.xonshrc
$ ~/Downloads/logo.png   # xdg-open ~/Downloads/logo.png
$ git                    # git
$ ./git                  # ls ./git

Type format

Priority Format Example
1 Full path to file. /etc/passwd
2 File name. file.txt
3 File extension. *.txt
4 MIME type/subtype and extension. text/plain.txt
5 MIME type/subtype. text/plain
6 MIME type. text/
7 Any file. FILE (constant)
8 Any directory. DIR (constant)
9 Any file or directory. * (constant)

To get MIME type for the file run file --mime-type --brief <file>.

Customize actions

Use XONTRIB_ONEPATH_ACTIONS environment variable to add new actions:

$XONTRIB_ONEPATH_ACTIONS['.xonshrc'] = 'vim'         # vim for `.xonshrc` file
$XONTRIB_ONEPATH_ACTIONS['*.log'] = 'tail'           # tail for text type *.log files
$XONTRIB_ONEPATH_ACTIONS['text/plain.txt'] = 'less'  # less for plain text *.txt files 
$XONTRIB_ONEPATH_ACTIONS['DIR'] = 'cd'               # the same as xonsh $AUTO_CD=True
$XONTRIB_ONEPATH_ACTIONS['application/zip'] = 'als'  # list files in zip file using atool

Complex actions

If you need more complex actions use callable xonsh aliases:

import pandas as pd
def _view_csv_with_pandas(args):
    print(pd.read_csv(args[0]))

aliases['view_csv_with_pandas'] = _view_csv_with_pandas
del _view_csv_with_pandas

$XONTRIB_ONEPATH_ACTIONS['application/csv'] = 'view_csv_with_pandas'

Known issues

NTFS in Linux: all files have execute permission

If you mount NTFS partition with default permissions then all files will have execute permission and onepath will execute them instead of action. The right way is to change default /etc/fstab settings. Example:

sudo umount /d
sudo mount -o uid=1000,gid=1000,dmask=027,fmask=137 /d 
ls -la /d

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xontrib-onepath-0.1.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

xontrib_onepath-0.1.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file xontrib-onepath-0.1.2.tar.gz.

File metadata

  • Download URL: xontrib-onepath-0.1.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for xontrib-onepath-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3df203cf3a131a2b2f7cad157e8f4ef2c848af97a8b9cf4a93278d696edf9dda
MD5 4cef488049dc1bea9d0e12a0f0d49863
BLAKE2b-256 68a49976ea734cde00cbd23d2622251596265f0cddc3bbbac1fdd16d9e4570a2

See more details on using hashes here.

File details

Details for the file xontrib_onepath-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: xontrib_onepath-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for xontrib_onepath-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 18eccc648d92780c73e88855210e939de4e3a5f2a5a17126cabf2567a2d7a008
MD5 7252d82bb17881d0719320a14af768ac
BLAKE2b-256 54a529d543f195ba220c96a76a493fc8a03ea7fe1ee336dc8abb7df6d5c40743

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page