Skip to main content

Enhanced aLiases For Shells (Name subject to change)

Install from PyPI

pip install elfs

Install from source

python setup.py install --user

Enable dynamic tab-completion for fish or xonsh

elfs --reg-fish
elfs --reg-xonsh

Command Line Interface

usage: elfs [options] [command [initial-arguments ...]]

Almost, but not quite, entirely unlike aliases

optional arguments:
  -h, --help         show this help message and exit
  -c name            add the command to your spellbook
  -cc name desc      also add description with command
  -ccc name desc rs  also add replace-str with command
  -d path            add a directory path to your config
  -e .ext path       add an extension and the path to an executable for it
  -l, --list         list entire collection (or specify: cmd, dir, ext, files)
  -s, --search       search entire collection for command
  -n, --dry-run      print command instead of executing it
  --version          show program's version number and exit

Usage Notes

  • Runs on any platform with python 3
  • Unless using search (and select), the default behaviour is to find a command using exact matches only, and is selected in the following order of precedence
    1. files in order of directories listed in config
    2. names of commands from spellbook in order listed
    3. imply file extension if possible and unambiguous
  • Commands without names (or duplicate names of lower precedence) can only be run via search
  • Commands and files with spaces in their names need to be escaped or in quotes
  • The first argument (that is not an option for elfs) is treated as the command or filename and all subsequent arguments are passed to the command or file to be executed (except for commands with a replace-str, see example)
  • Pipes work as expected, you can pipe into or out from any command or file, however if you try piping into a search, it will interpret that as your selection

Examples

  • add a directory
    > elfs -d ~/scripts
  • run your script from any directory
    > elfs myscript.py arg0 arg1 arg2
  • file extension is implied only if unambiguous
    > elfs myscript arg0 arg1 arg2
  • add an extension to run a file with a specific executable
    > elfs -e .py /path/to/alternative/env/for/python
  • add a command
    > elfs -cc spam "echo spam to output 3 times" echo spam spam spam
  • run the command
    > elfs spam

spam spam spam

  • add a command with a replace-str (metavar: rs) and run it
    > elfs -ccc menu "even more spam" {} echo spam {} spam {}
    > elfs menu bacon eggs

spam bacon spam eggs

  • giving fewer arguments causes them to repeat
    > elfs menu bacon

spam bacon spam bacon

  • and extra arguments are passed along as normal
    > elfs menu bacon eggs sausage spam

spam bacon spam eggs sausage spam

  • command chaining (needs to run in a shell, elfs uses Popen shell=False)
    > elfs -c "double spam" bash -c "echo spam && echo spam"
    > elfs "double spam"

spam spam

  • see the command without running it (quotes may appear slightly different)
    > elfs -n "double spam"

Command: bash -c "echo spam && echo spam"

  • list all commands and files
    > elfs -l
  • search commands and files with fuzzy matches, then optionally select from a list of matches to execute
    > elfs -s dble spam
  • add a command to quickly edit your config
    > elfs -c "config" nano ~/.config/elfs/config.json
  • or add a command to edit your spellbook (you can move this file)
    > elfs -c "spells" nano ~/.config/elfs/spellbook.json

Add dynamic tab-completion to your scripts

  • create completion rules in the following json format
[
  {
    "expression": "python_expression_for_rule_1",
    "completions": ["option1", "option2\thello", "option3\tworld"]
  },
  {
    "expression": "python_expression_for_rule_2",
    "completions": ["option1", "option4\toptional description"]
  }
]
  • where the python expression is evaluated in a namespace with the following variables
    • position = current position in the command, where 0 is the current script
      • eg. elfs[None] myscript.py[0] option[1] [2]
      • position does not increment until the next space elfs[None] myscript.py[0] option[1] op[2]
    • command = command so far, as parsed by shlex
      • following the same example with position=2, command=["myscript.py", "option", ""]
      • and command=["myscript.py", "option", "op"]
    • eg. "position == 2 and command[1] in ['option1', 'option2']"
  • the completions are shown for every expression that evaluates as true
  • the completion rules can be placed in either of the following locations
    • inside file_name.ext.elfs.json, eg. myscript.py.elfs.json
    • or directly enclosed in file_name.ext with # TAB-COMPLETION START and # TAB-COMPLETION END
# TAB-COMPLETION START
[
  ...
]
# TAB-COMPLETION END

Metadata

Release files for elfs 1.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for elfs 1.3.6
File Size Uploaded
elfs-1.3.6.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for elfs 1.3.6
File Interpreter ABI Platform
elfs-1.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / elfs-1.3.6.tar.gz

Download URL elfs-1.3.6.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d204fa21e9c59e30e8c1b34d32c0c47cfce6e915638a6400785bc24d77531e12
BLAKE2b-256 checksum
How to use checksums
38dbcdb56896c410bdc8154638522265ab8362f7f0cc499d905bb4204a555501
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Release files / elfs-1.3.6-py3-none-any.whl

Download URL elfs-1.3.6-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6006ade50b132faebcdf84107fb8d6a2bb15f4d590516019d38ce5a5e307e660
BLAKE2b-256 checksum
How to use checksums
0b7d2f0e8b25a65d965298092a484229f94429e0779d8ba8bfc0143e34417882
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

1.3.6 This release

2 release files

1.3.4

2 release files

1.3.2

2 release files

1.3.0

2 release files

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.4.6

1 release file

0.4.4

1 release file

0.4.2

1 release file

0.4.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page