diff --git a/news/bashisms.rst b/news/bashisms.rst index 49db62d0d..9ce4db3a7 100644 --- a/news/bashisms.rst +++ b/news/bashisms.rst @@ -1,6 +1,6 @@ **Added:** -* Added ``unset``, ``export``, ``set -e``, ``set -x`` to xontrib bashisms. +* Added ``unset``, ``export``, ``set -e``, ``set -x``, ``shopt``, ``complete`` to xontrib bashisms. **Changed:** diff --git a/xonsh/xontribs.json b/xonsh/xontribs.json index f4917779e..a05f544a9 100644 --- a/xonsh/xontribs.json +++ b/xonsh/xontribs.json @@ -55,7 +55,7 @@ "**Warning:** This xontrib may modify user command line input to implement ", "its behavior. To see the modifications as they are applied (in unified diff", "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", "package": "xontrib-base16-shell", diff --git a/xontrib/bashisms.py b/xontrib/bashisms.py index 532aa56ce..aedbbd351 100644 --- a/xontrib/bashisms.py +++ b/xontrib/bashisms.py @@ -113,3 +113,37 @@ def _set(args): 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"