| |
@@ -0,0 +1,100 @@
|
| |
+ diff --git a/xonsh/aliases.py b/xonsh/aliases.py
|
| |
+ index 47502f17..7af245ef 100644
|
| |
+ --- a/xonsh/aliases.py
|
| |
+ +++ b/xonsh/aliases.py
|
| |
+ @@ -609,7 +609,7 @@ def source_cmd(args, stdin=None):
|
| |
+
|
| |
+
|
| |
+ def xexec(args, stdin=None):
|
| |
+ - """exec [-h|--help] command [args...]
|
| |
+ + """exec [-h|--help] [-cl] [-a name] command [args...]
|
| |
+
|
| |
+ exec (also aliased as xexec) uses the os.execvpe() function to
|
| |
+ replace the xonsh process with the specified program. This provides
|
| |
+ @@ -619,6 +619,13 @@ def xexec(args, stdin=None):
|
| |
+ bash $
|
| |
+
|
| |
+ The '-h' and '--help' options print this message and exit.
|
| |
+ + If the '-l' option is supplied, the shell places a dash at the
|
| |
+ + beginning of the zeroth argument passed to command to simulate login
|
| |
+ + shell.
|
| |
+ + The '-c' option causes command to be executed with an empty environment.
|
| |
+ + If '-a' is supplied, the shell passes name as the zeroth argument
|
| |
+ + to the executed command.
|
| |
+ +
|
| |
+
|
| |
+ Notes
|
| |
+ -----
|
| |
+ @@ -632,18 +639,39 @@ def xexec(args, stdin=None):
|
| |
+ """
|
| |
+ if len(args) == 0:
|
| |
+ return (None, "xonsh: exec: no args specified\n", 1)
|
| |
+ - elif args[0] == "-h" or args[0] == "--help":
|
| |
+ +
|
| |
+ + parser = argparse.ArgumentParser(add_help=False)
|
| |
+ + parser.add_argument('-h', '--help', action='store_true')
|
| |
+ + parser.add_argument('-l', dest='login', action='store_true')
|
| |
+ + parser.add_argument('-c', dest='clean', action='store_true')
|
| |
+ + parser.add_argument('-a', dest='name', nargs='?')
|
| |
+ + parser.add_argument('command', nargs=argparse.REMAINDER)
|
| |
+ + args = parser.parse_args(args)
|
| |
+ +
|
| |
+ + if args.help:
|
| |
+ return inspect.getdoc(xexec)
|
| |
+ - else:
|
| |
+ +
|
| |
+ + if len(args.command) == 0:
|
| |
+ + return (None, "xonsh: exec: no command specified\n", 1)
|
| |
+ +
|
| |
+ + command = args.command[0]
|
| |
+ + if args.name is not None:
|
| |
+ + args.command.insert(0, args.name)
|
| |
+ + if args.login:
|
| |
+ + args.command[0] = '-{}'.format(args.command[0])
|
| |
+ +
|
| |
+ + denv = {}
|
| |
+ + if not args.clean:
|
| |
+ denv = builtins.__xonsh__.env.detype()
|
| |
+ - try:
|
| |
+ - os.execvpe(args[0], args, denv)
|
| |
+ - except FileNotFoundError as e:
|
| |
+ - return (
|
| |
+ - None,
|
| |
+ - "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),
|
| |
+ - 1,
|
| |
+ - )
|
| |
+ +
|
| |
+ + try:
|
| |
+ + os.execvpe(command, args.command, denv)
|
| |
+ + except FileNotFoundError as e:
|
| |
+ + return (
|
| |
+ + None,
|
| |
+ + "xonsh: exec: file not found: {}: {}" "\n".format(e.args[1], args[0]),
|
| |
+ + 1,
|
| |
+ + )
|
| |
+
|
| |
+
|
| |
+ class AWitchAWitch(argparse.Action):
|
| |
+ diff --git a/xonsh/main.py b/xonsh/main.py
|
| |
+ index 45ab31a9..8c05ab93 100644
|
| |
+ --- a/xonsh/main.py
|
| |
+ +++ b/xonsh/main.py
|
| |
+ @@ -292,7 +292,7 @@ def start_services(shell_kwargs, args):
|
| |
+ env = builtins.__xonsh__.env
|
| |
+ rc = shell_kwargs.get("rc", None)
|
| |
+ rc = env.get("XONSHRC") if rc is None else rc
|
| |
+ - if args.mode != XonshMode.interactive and not args.force_interactive:
|
| |
+ + if args.mode != XonshMode.interactive and not args.force_interactive and not args.login:
|
| |
+ # Don't load xonshrc if not interactive shell
|
| |
+ rc = None
|
| |
+ events.on_pre_rc.fire()
|
| |
+ @@ -329,7 +329,8 @@ def premain(argv=None):
|
| |
+ "cacheall": args.cacheall,
|
| |
+ "ctx": builtins.__xonsh__.ctx,
|
| |
+ }
|
| |
+ - if args.login:
|
| |
+ + if args.login or sys.argv[0].startswith('-'):
|
| |
+ + args.login = True
|
| |
+ shell_kwargs["login"] = True
|
| |
+ if args.norc:
|
| |
+ shell_kwargs["rc"] = ()
|
| |
If user have xonsh set as login shell following problems are solved:
- Logout from X session is not possible due to '-c' not using execvpe syscall
- Environment variables not set on staring X session