├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── pyproject.toml └── xontrib └── broot.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.xsh text linguist-language=Python 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | .idea/ 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020, Noortheen Raja NJ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [broot](https://github.com/Canop/broot) support function for xonsh shell 3 | 4 | 5 | ## Installation 6 | 7 | To install use pip: 8 | 9 | ``` bash 10 | xpip install xontrib-broot 11 | # or: xpip install -U git+https://github.com/jnoortheen/xontrib-broot 12 | ``` 13 | 14 | ## Usage 15 | It adds `br` alias function. So commands like `cd` will work from broot. 16 | ``` bash 17 | $ xontrib load broot 18 | $ br 19 | ``` 20 | 21 | `broot` can also be launched with shortcut `Ctrl+N`. 22 | This can be changed by `$XONSH_BROOT_KEY="c-n"` or disabled with `$XONSH_BROOT_KEY=""`. 23 | (PS [PTK's keybinding guide](https://python-prompt-toolkit.readthedocs.io/en/master/pages/advanced_topics/key_bindings.html#list-of-special-keys) 24 | for full list of key names.) 25 | 26 | ## Credits 27 | 28 | This package was created with [xontrib cookiecutter template](https://github.com/jnoortheen/xontrib-cookiecutter). 29 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project.optional-dependencies] 2 | dev = [ 3 | "pytest", 4 | "black", 5 | ] 6 | 7 | [tool.pdm.build] 8 | includes = ["xontrib"] 9 | 10 | [build-system] 11 | requires = ["pdm-pep517>=1.0.0"] 12 | build-backend = "pdm.pep517.api" 13 | 14 | [project] 15 | # PEP 621 project metadata 16 | # See https://www.python.org/dev/peps/pep-0621/ 17 | authors = [ 18 | {name = "Noortheen Raja NJ", email = "jnoortheen@gmail.com"}, 19 | ] 20 | license = {text = "MIT"} 21 | requires-python = ">=3.7" 22 | dependencies = [ 23 | "xonsh>=0.12", 24 | ] 25 | name = "xontrib-broot" 26 | version = "0.2.1" 27 | description = "broot support function for xonsh shell" 28 | readme = "README.md" 29 | keywords = ["xontrib", "xonsh"] 30 | classifiers = ["Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Topic :: System :: Shells", "Topic :: System :: System Shells", "Topic :: Terminals", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8"] 31 | 32 | [project.urls] 33 | Documentation = "https://github.com/jnoortheen/xontrib-broot/blob/master/README.md" 34 | Code = "https://github.com/jnoortheen/xontrib-broot" 35 | "Issue tracker" = "https://github.com/jnoortheen/xontrib-broot/issues" 36 | repository = "https://github.com/jnoortheen/xontrib-broot" 37 | -------------------------------------------------------------------------------- /xontrib/broot.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import tempfile 4 | from xonsh.built_ins import XSH 5 | from xonsh.tools import uncapturable 6 | from contextlib import contextmanager 7 | 8 | 9 | @contextmanager 10 | def mk_temp_file() -> str: 11 | fd, file_name = tempfile.mkstemp() 12 | os.close(fd) 13 | yield file_name 14 | os.remove(file_name) 15 | 16 | 17 | @uncapturable 18 | def _br(args, stdin=None, stdout=None, stderr=None): 19 | with mk_temp_file() as cmd_file: 20 | cmds = ("broot", "--outcmd", cmd_file) + tuple(args) 21 | status_code: int = subprocess.call( 22 | cmds, 23 | stdin=stdin, 24 | stderr=stderr, 25 | stdout=stdout, 26 | ) 27 | if status_code == 0: 28 | with open(cmd_file) as fr: 29 | content = fr.read() 30 | if content: 31 | XSH.builtins.evalx(content) 32 | 33 | return status_code 34 | 35 | 36 | XSH.aliases["br"] = _br 37 | 38 | 39 | @XSH.builtins.events.on_ptk_create 40 | def custom_keybindings(bindings, **kw): 41 | def handler(key_name: str, default: str): 42 | def do_nothing(_): 43 | pass 44 | 45 | if key_name not in XSH.env: 46 | key = default 47 | else: 48 | key = XSH.env.get(key_name) 49 | if key: 50 | return bindings.add(key) 51 | return do_nothing 52 | 53 | @handler("XONSH_BROOT_KEY", "c-n") 54 | def start_broot(event): 55 | _br([]) 56 | 57 | 58 | if __name__ == "__main__": 59 | from xonsh.built_ins import XSH 60 | 61 | XSH.load() 62 | data = XSH.execer.eval("") 63 | --------------------------------------------------------------------------------