From 018ce10b0b5170b7af291b794ef6592b105463cb Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Thu, 9 Mar 2017 10:23:55 +0100 Subject: [PATCH] Add RELEASE_CWD_ON_WIN environment variable --- xonsh/environ.py | 11 +++++++++++ xonsh/ptk/shell.py | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/xonsh/environ.py b/xonsh/environ.py index b0bca48bf..60967bdf0 100644 --- a/xonsh/environ.py +++ b/xonsh/environ.py @@ -159,6 +159,7 @@ def DEFAULT_ENSURERS(): 'PRETTY_PRINT_RESULTS': (is_bool, to_bool, bool_to_str), 'PROMPT': (is_string_or_callable, ensure_string, ensure_string), 'RAISE_SUBPROC_ERROR': (is_bool, to_bool, bool_to_str), + 'RELEASE_CWD_ON_WIN': (is_bool, to_bool, bool_to_str), 'RIGHT_PROMPT': (is_string_or_callable, ensure_string, ensure_string), 'BOTTOM_TOOLBAR': (is_string_or_callable, ensure_string, ensure_string), 'SUBSEQUENCE_PATH_COMPLETION': (is_bool, to_bool, bool_to_str), @@ -297,6 +298,7 @@ def DEFAULT_VALUES(): 'PUSHD_MINUS': False, 'PUSHD_SILENT': False, 'RAISE_SUBPROC_ERROR': False, + 'RELEASE_CWD_ON_WIN': False, 'RIGHT_PROMPT': '', 'BOTTOM_TOOLBAR': '', 'SHELL_TYPE': 'best', @@ -536,6 +538,15 @@ def DEFAULT_DOCS(): 'This is most useful in xonsh scripts or modules where failures ' 'should cause an end to execution. This is less useful at a terminal. ' 'The error that is raised is a ``subprocess.CalledProcessError``.'), + 'RELEASE_CWD_ON_WIN': VarDocs( + 'This will release the lock on the current directory whenever the ' + 'prompt is shown. Enabling this will allow the other programs or ' + 'Windows Explorer to delete or rename the current or parent ' + 'directories. Internally, it is accomplished by temporarily resetting ' + 'CWD to the root drive folder while waiting at the prompt. So it can ' + 'cause problems if any extensions are enabled which hooks the prompt ' + 'and relies on ``os.getcwd()``.',configurable=ON_WINDOWS + ), 'RIGHT_PROMPT': VarDocs( 'Template string for right-aligned text ' 'at the prompt. This may be parameterized in the same way as ' diff --git a/xonsh/ptk/shell.py b/xonsh/ptk/shell.py index fa78d3718..962e86d8c 100644 --- a/xonsh/ptk/shell.py +++ b/xonsh/ptk/shell.py @@ -93,7 +93,8 @@ class PromptToolkitShell(BaseShell): get_rprompt_tokens = self.rprompt_tokens get_bottom_toolbar_tokens = self.bottom_toolbar_tokens - if ON_WINDOWS and not env.get('UPDATE_PROMPT_ON_KEYPRESS'): + if (ON_WINDOWS and env.get('RELEASE_CWD_ON_WIN') and + not env.get('UPDATE_PROMPT_ON_KEYPRESS')): # Wrap the prompt method to release the cwd while showing the prompt self.prompter.prompt = cwd_release_wrapper(self.prompter.prompt) if self.completer: