mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Merge remote-tracking branch 'origin/fix_double_open2' into fix_double_open2
This commit is contained in:
commit
925da0e155
12 changed files with 98 additions and 29 deletions
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
|
@ -79,6 +79,8 @@ jobs:
|
|||
- name: Upload coverage to Codecov
|
||||
if: ${{ startsWith(matrix.python-version, env.DEFAULT_PYTHON_VERSION) }}
|
||||
uses: codecov/codecov-action@v4
|
||||
env:
|
||||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
||||
with:
|
||||
verbose: true
|
||||
flags: ${{ matrix.os }}
|
||||
|
|
|
@ -8,7 +8,7 @@ default_language_version:
|
|||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: 'v0.5.4'
|
||||
rev: 'v0.5.6'
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [., --fix, --exit-non-zero-on-fix]
|
||||
|
@ -18,7 +18,7 @@ repos:
|
|||
pass_filenames: false
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: 'v1.11.0' # Use the sha / tag you want to point at
|
||||
rev: 'v1.11.1' # Use the sha / tag you want to point at
|
||||
hooks:
|
||||
- id: mypy
|
||||
pass_filenames: false
|
||||
|
|
4
docs/_templates/index.html
vendored
4
docs/_templates/index.html
vendored
|
@ -10,13 +10,13 @@
|
|||
<meta name="description" content="The xonsh shell is a Python-powered shell. Full-featured and cross-platform.">
|
||||
<meta name="keywords" content="xonsh, xonsh shell, python shell, terminal, console, bash alternative, zsh alternative, fish alternative, devops tools, hacking tools">
|
||||
|
||||
<meta name="twitter:image:src" content="https://xon.sh/_static/landing2/images/xonsh-landing-preview.png" />
|
||||
<meta name="twitter:image:src" content="https://xon.sh/_static/landing2/images/xonsh_landing_preview.png" />
|
||||
<meta name="twitter:site" content="https://xon.sh/" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta name="twitter:title" content="The Xonsh Shell — Python-powered shell" />
|
||||
<meta name="twitter:description" content="The xonsh shell is a Python-powered shell. Full-featured and cross-platform." />
|
||||
|
||||
<meta property="og:image" content="https://xon.sh/_static/landing2/images/xonsh-landing-preview.png" />
|
||||
<meta property="og:image" content="https://xon.sh/_static/landing2/images/xonsh_landing_preview.png" />
|
||||
<meta property="og:image:alt" content="The xonsh shell is a Python-powered shell. Full-featured and cross-platform." />
|
||||
<meta property="og:site_name" content="The xonsh shell" />
|
||||
<meta property="og:type" content="object" />
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
Bash to Xonsh Translation Guide
|
||||
================================
|
||||
As you have probably figured out by now, xonsh is not ``sh``-lang compliant.
|
||||
If your muscles have memorized all of the Bash prestidigitations, this page
|
||||
will help you put a finger on how to do the equivalent task in xonsh.
|
||||
|
||||
For shell scripts, the recommended file extension is ``xsh``, and shebang
|
||||
line is ``#!/usr/bin/env xonsh``.
|
||||
Xonsh relies primarily on the Python syntax and is not a suitable replacement for `sh` and is thus considered a non-POSIX shell.
|
||||
This page provides xonsh equivalents for common patterns in Bash.
|
||||
|
||||
.. list-table::
|
||||
:widths: 30 30 40
|
||||
|
@ -14,6 +10,16 @@ line is ``#!/usr/bin/env xonsh``.
|
|||
* - Bash
|
||||
- Xonsh
|
||||
- Notes
|
||||
* - No special object for represent session.
|
||||
- ``__xonsh__``
|
||||
- The ``__xonsh__`` object has all about current xonsh session e.g. ``__xonsh__.env``.
|
||||
You can set ``X = __xonsh__`` to have a shortcut for ``X.env`` and similar.
|
||||
* - ``script.sh``
|
||||
- ``script.xsh``
|
||||
- The recommended file extension is ``.xsh``.
|
||||
* - ``#!/bin/bash``
|
||||
- ``#!/usr/bin/env xonsh``
|
||||
- Use ``xonsh`` in the shebang.
|
||||
* - ``echo --arg="val"``
|
||||
|
||||
``echo {}``
|
||||
|
@ -33,7 +39,8 @@ line is ``#!/usr/bin/env xonsh``.
|
|||
characters, words or brackets.
|
||||
* - ``IFS``
|
||||
- ``$XONSH_SUBPROC_OUTPUT_FORMAT``
|
||||
- Changing the output representation and splitting.
|
||||
- Changing the output representation and splitting. Also take a look into ``DecoratorAlias``
|
||||
to have an ability to return object e.g. ``j = $(@json echo '{}')``.
|
||||
* - ``$NAME`` or ``${NAME}``
|
||||
- ``$NAME``
|
||||
- Look up an environment variable by name.
|
||||
|
@ -59,7 +66,7 @@ line is ``#!/usr/bin/env xonsh``.
|
|||
* - ``ENV1=VAL1 command``
|
||||
- ``$ENV1=VAL1 command``
|
||||
|
||||
or ``with ${...}.swap(ENV1=VAL1): command``
|
||||
or ``with __xonsh__.env.swap(ENV1=VAL1): command``
|
||||
- Set temporary environment variable(s) and execute the command.
|
||||
Use the second notation with an indented block to execute many commands in the same context.
|
||||
* - ``alias ll='ls -la'``
|
||||
|
@ -135,7 +142,7 @@ line is ``#!/usr/bin/env xonsh``.
|
|||
- Xonsh publishes a handful of containers, primarily targeting CI and automation use cases.
|
||||
All of them are published on `Docker Hub <https://hub.docker.com/u/xonsh>`_.
|
||||
* - ``exit 1``
|
||||
- ``exit(1)``
|
||||
- ``exit 1`` or ``exit(1)``
|
||||
- Exiting from the current script.
|
||||
|
||||
To understand how xonsh executes the subprocess commands try
|
||||
|
|
23
news/fix_python_only_completion.rst
Normal file
23
news/fix_python_only_completion.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* completer: Fixed exception when in python-only completion context (#5632).
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
23
news/fix_safe_readlines.rst
Normal file
23
news/fix_safe_readlines.rst
Normal file
|
@ -0,0 +1,23 @@
|
|||
**Added:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Changed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Removed:**
|
||||
|
||||
* <news item>
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Fixed exception "object has no attribute readlines" in case of redirect callable alias output.
|
||||
|
||||
**Security:**
|
||||
|
||||
* <news item>
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
**Changed:**
|
||||
|
||||
* ``$MULTILINE_PROMPT`` changed from ``'.'`` to ``'{BACKGROUND_#222222} {RESET}'`` (space with background)
|
||||
to have an ability to copy the multiline functions from shell history without deleting the dot manually (#5624).
|
||||
* ``$MULTILINE_PROMPT`` changed from ``'.'`` to ``' '`` (space)
|
||||
to have an ability to copy the multiline functions from shell history without deleting the dot manually (#5624 #5634).
|
||||
|
||||
**Deprecated:**
|
||||
|
||||
|
|
|
@ -168,3 +168,8 @@ def test_env_completer_sort(completer, completers_mock):
|
|||
"$WOW", "$WOW", 4, 0, {}, multiline_text="'$WOW'", cursor_index=4
|
||||
)
|
||||
assert set(comps[0]) == {"$WOW0", "$WOW1", "$MID_WOW", "$SUPER_WOW"}
|
||||
|
||||
|
||||
def test_python_only_context(completer, completers_mock):
|
||||
assert completer.complete_line("echo @(") != ()
|
||||
assert completer.complete("", "echo @(", 0, 0, {}, "echo @(", 7) != ()
|
||||
|
|
|
@ -48,10 +48,16 @@ class Completer:
|
|||
suffix is not supported; text after last space is parsed as prefix.
|
||||
"""
|
||||
ctx = self.parse(text)
|
||||
cmd_ctx = ctx.command
|
||||
if not cmd_ctx:
|
||||
raise RuntimeError("Only Command context is empty")
|
||||
prefix = cmd_ctx.prefix
|
||||
|
||||
if not ctx:
|
||||
raise RuntimeError("CompletionContext is None")
|
||||
|
||||
if ctx.python is not None:
|
||||
prefix = ctx.python.prefix
|
||||
elif ctx.command is not None:
|
||||
prefix = ctx.command.prefix
|
||||
else:
|
||||
raise RuntimeError("CompletionContext is empty")
|
||||
|
||||
line = text
|
||||
begidx = text.rfind(prefix)
|
||||
|
@ -284,9 +290,14 @@ class Completer:
|
|||
)
|
||||
break
|
||||
|
||||
prefix = None
|
||||
if completion_context:
|
||||
prefix = completion_context.command.prefix
|
||||
if completion_context.python is not None:
|
||||
prefix = completion_context.python.prefix
|
||||
elif completion_context.command is not None:
|
||||
prefix = completion_context.command.prefix
|
||||
else:
|
||||
raise RuntimeError("Completion context is empty")
|
||||
|
||||
if prefix.startswith("$"):
|
||||
prefix = prefix[1:]
|
||||
|
||||
|
|
|
@ -1443,7 +1443,7 @@ class PromptSetting(Xettings):
|
|||
is_string_or_callable,
|
||||
ensure_string,
|
||||
ensure_string,
|
||||
"{BACKGROUND_#222222} {RESET}",
|
||||
" ",
|
||||
"Prompt text for 2nd+ lines of input, may be str or function which "
|
||||
"returns a str.",
|
||||
)
|
||||
|
|
|
@ -283,13 +283,10 @@ class CommandPipeline:
|
|||
lines = b.splitlines(keepends=True)
|
||||
yield from lines
|
||||
self.end(tee_output=False)
|
||||
elif self.captured == "stdout":
|
||||
if stdout:
|
||||
b = stdout.read()
|
||||
s = self._decode_uninew(b, universal_newlines=True)
|
||||
self.lines = s.splitlines(keepends=True)
|
||||
else:
|
||||
self.lines = []
|
||||
elif self.captured == "stdout" and stdout is not None:
|
||||
b = stdout.read()
|
||||
s = self._decode_uninew(b, universal_newlines=True)
|
||||
self.lines = s.splitlines(keepends=True)
|
||||
return
|
||||
# get the correct stderr
|
||||
stderr = proc.stderr
|
||||
|
|
|
@ -58,6 +58,7 @@ from xonsh.platform import (
|
|||
|
||||
@contextmanager
|
||||
def chdir(adir, mkdir=False):
|
||||
adir = pathlib.Path(adir)
|
||||
old_dir = os.getcwd()
|
||||
if mkdir:
|
||||
os.makedirs(adir, exist_ok=True)
|
||||
|
|
Loading…
Add table
Reference in a new issue