xonsh.lib.completion_quoting

Shared helper for deciding whether a completion candidate needs shell-quoting in xonsh.

Used by both the built-in path completer (xonsh.completers.path) and the bash-completion bridge (xonsh.completers.bash_completion), which historically carried near-identical copies of this regex that drifted over time.

Pure-Python, no side effects on import — safe for standalone use, as xonsh.completers.bash_completion requires.

xonsh.lib.completion_quoting.name_needs_quotes(name: str, sep: str | None = None) bool[source]

Return True if name would be mangled by the xonsh parser and therefore needs to be wrapped in quotes when emitted as a completion.

Parameters:
name

The candidate completion string (a path, an executable name, …).

sep

The path separator the caller treats as safe (os.sep on POSIX, os.altsep in forced-POSIX mode on Windows). When a backslash appears in name but sep is not backslash, the backslash is a shell metacharacter and forces quoting. Defaults to os.sep.