-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
a
committed
Oct 9, 2020
1 parent
3b8b4d4
commit 473f602
Showing
9 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.xsh text linguist-language=Python |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020, anki-code | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,59 @@ | ||
# xontrib-sh | ||
Paste and run sh-compatible commands. | ||
<p align="center"> | ||
Paste and run commands from bash, zsh, fish in <a href="https://xon.sh">xonsh shell</a>. | ||
</p> | ||
|
||
<p align="center"> | ||
If you like the idea click ⭐ on the repo and stay tuned. | ||
</p> | ||
|
||
|
||
## Install | ||
```bash | ||
xpip install -U xontrib-sh | ||
echo 'xontrib load sh' >> ~/.xonshrc | ||
# Reload xonsh | ||
``` | ||
|
||
## Usage | ||
|
||
Start a line with an exclamation point — `!` — then paste the sh-compatible commands | ||
after it and run. The command syntax will be tested in installed shells (bash, zsh, fish, sh) | ||
and the commands will be run in the first matching shell. | ||
|
||
The commands will be executed in the environment that will be inherited from current | ||
but if the commands modify the environment there will no changes in source xonsh environment. | ||
|
||
## Example | ||
|
||
### One line: brace expansion (bash syntax) | ||
```bash | ||
! echo 01.{05..10} | ||
``` | ||
``` | ||
bash: | ||
01.05 01.06 01.07 01.08 01.09 01.10 | ||
``` | ||
|
||
### Many lines: for loop (zsh syntax) | ||
```zsh | ||
! for x (1 2 3); do | ||
echo $x; | ||
done | ||
|
||
for x (4 5 6); do | ||
echo $x; | ||
done | ||
``` | ||
``` | ||
zsh: | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
6 | ||
``` | ||
|
||
## Credits | ||
|
||
This package was created with [xontrib cookiecutter template](https://github.com/xonsh/xontrib-cookiecutter). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xonsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[metadata] | ||
name = xontrib-sh | ||
version = 0.0.1 | ||
author = anki-code | ||
author_email = anki-code | ||
description = Paste and run sh-compatible commands in xonsh shell. | ||
long_description = file: README.rst | ||
url = https://github.com/anki-code/xontrib-sh | ||
license = MIT | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.5 | ||
Programming Language :: Python :: 3.6 | ||
Programming Language :: Python :: 3.7 | ||
Programming Language :: Python :: 3.8 | ||
License :: OSI Approved :: MIT License | ||
Operating System :: OS Independent | ||
|
||
[options] | ||
include_package_data = True | ||
packages=xontrib | ||
python_requires = >=3.5 | ||
|
||
install_requires = | ||
xonsh>=0.9.23 | ||
|
||
[options.package_data] | ||
xontrib = *.xsh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from setuptools import setup | ||
|
||
setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from shutil import which | ||
|
||
_shells = ['bash', 'zsh', 'fish'] | ||
_installed_shells = [] | ||
|
||
@events.on_transform_command | ||
def onepath(cmd, **kw): | ||
if cmd and cmd[0] == '!': | ||
if not _installed_shells: | ||
for s in _shells: | ||
if which(s): | ||
_installed_shells.append(s) | ||
|
||
cmd = cmd[1:].strip() | ||
|
||
shells = [] | ||
for s in _installed_shells: | ||
if $(@(s) -nc @(cmd) 2>&1).strip() == '': | ||
shells.append(s) | ||
|
||
if shells: | ||
first_compatible_shell = shells[0] | ||
shell_cmd = first_compatible_shell + ' -c' | ||
printx(f'{{BOLD_WHITE}}{first_compatible_shell}:{{RESET}}\n\r', end='') | ||
else: | ||
try_to_install = '' | ||
not_installed_shells = [s for s in _shells if s not in _installed_shells] | ||
if len(not_installed_shells) > 0: | ||
try_to_install = f'Try to install {",".join(not_installed_shells)}.' | ||
printx(f'{{BOLD_WHITE}}Checked {", ".join(_installed_shells)} with no success. {try_to_install}{{RESET}}\n\r', end='') | ||
shell_cmd = 'echo' | ||
|
||
return f'{shell_cmd} @({repr(cmd)})' | ||
return cmd |