Bashisms shopt, complete

This commit is contained in:
a 2020-09-25 09:57:36 +03:00
parent 9eef76fcad
commit 19ea4d3af9
3 changed files with 36 additions and 2 deletions

View file

@ -1,6 +1,6 @@
**Added:** **Added:**
* Added ``unset``, ``export``, ``set -e``, ``set -x`` to xontrib bashisms. * Added ``unset``, ``export``, ``set -e``, ``set -x``, ``shopt``, ``complete`` to xontrib bashisms.
**Changed:** **Changed:**

View file

@ -55,7 +55,7 @@
"**Warning:** This xontrib may modify user command line input to implement ", "**Warning:** This xontrib may modify user command line input to implement ",
"its behavior. To see the modifications as they are applied (in unified diff", "its behavior. To see the modifications as they are applied (in unified diff",
"format), please set ``$XONSH_DEBUG`` to ``2`` or higher.\n\n", "format), please set ``$XONSH_DEBUG`` to ``2`` or higher.\n\n",
"Limited support of bash commands: ``alias``, ``export``, ``unset``, ``set``."] "The xontrib also adds commands: ``alias``, ``export``, ``unset``, ``set``, ``shopt``, ``complete``."]
}, },
{"name": "base16_shell", {"name": "base16_shell",
"package": "xontrib-base16-shell", "package": "xontrib-base16-shell",

View file

@ -113,3 +113,37 @@ def _set(args):
aliases["set"] = _set aliases["set"] = _set
def _shopt(args):
supported_shopt = ["DOTGLOB"]
args_len = len(args)
if args_len == 0:
for so in supported_shopt:
onoff = "on" if so in __xonsh__.env and __xonsh__.env[so] else "off"
print(f"dotglob\t{onoff}")
return
elif args_len < 2 or args[0] in ["-h", "--help"]:
print(f'Usage: shopt <-s|-u> <{"|".join(supported_shopt).lower()}>')
return
opt = args[0]
optname = args[1]
if opt == "-s" and optname == "dotglob":
__xonsh__.env["DOTGLOB"] = True
elif opt == "-u" and optname == "dotglob":
__xonsh__.env["DOTGLOB"] = False
else:
print(
"Not supported in xontrib bashisms.\nPRs are welcome - https://github.com/xonsh/xonsh/blob/master/xontrib/bashisms.py",
file=sys.stderr,
)
aliases["shopt"] = _shopt
aliases["complete"] = "completer list"