The escape sequences do not properly make it to the PROMPT_COMMAND environment variable in the mock shell.
Additionally, printing <mock-chroot> via the PROMPT_COMMAND causes spurious line editing issues, as noted in [RHBZ#1126235]. Use PS1 to set the visible '<mock-chroot>' string to fix those issues.
Old output: $ mock -r fedora-rawhide-x86_64 --chroot -- sh -i -c env |& egrep '^(PROMPT_COMMAND|PS1)' PROMPT_COMMAND=printf "<mock-chroot>"
$ mock -r fedora-rawhide-x86_64 --shell ... <mock-chroot>sh-4.3#
New output: $ mock -r fedora-rawhide-x86_64 --chroot -- sh -i -c env |& egrep '^(PROMPT_COMMAND|PS1)' PS1=<mock-chroot> \s-\v$ PROMPT_COMMAND=printf "\033]0;<mock-chroot>\007"
$ mock -r fedora-rawhide-x86_64 --shell ... <mock-chroot> sh-4.3#
The resulting prompt is identical (not counting the space between '<mock-chroot>' and 'sh-4.3#' which improves readability slightly). The terminal title is also set. As can be seen, the PROMPT_COMMAND variable now shows the desired printf command with the escape sequences intact.
This fix is also applied to the systemd-nspawn chroot. ---
Hi,
This is against master. This seemed like a patch which fixes a minor issue and would thus be suitable for an eventual maintenance release. I can rebase it against devel if that's preferred though.
I've been setting config_opts['environment']['PROMPT_COMMAND'] and config_opts['environment']['PS1'] in ~/.mock/user/cfg for a while now, after cursing the way the default PROMPT_COMMAND causes various line editing issues. After looking deeper and following the previous commits handling PROMPT_COMMAND, I can see it's bitten others. :)
I set PS1 to the bash default (\s-\v$) to keep behavior changes to a minimum. It might be worth a follow-up patch to set PS1 to something nicer. In my user.cfg, I add the value of config_opts['root'] to both PROMPT_COMMAND and PS1 so I can easily see what chroot I am using. I didn't test whether that would work as a default value in util.py.
Thanks,
Todd
etc/mock/site-defaults.cfg | 3 ++- py/mockbuild/util.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/etc/mock/site-defaults.cfg b/etc/mock/site-defaults.cfg index 5e1c9fa..454abb1 100644 --- a/etc/mock/site-defaults.cfg +++ b/etc/mock/site-defaults.cfg @@ -202,7 +202,8 @@ # config_opts['environment']['HOME'] = '/builddir' # config_opts['environment']['HOSTNAME'] = 'mock' # config_opts['environment']['PATH'] = '/usr/bin:/bin:/usr/sbin:/sbin' -# config_opts['environment']['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007<mock-chroot>"' +# config_opts['environment']['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007"' +# config_opts['environment']['PS1'] = '<mock-chroot> \s-\v\$ ' # config_opts['environment']['LANG'] = os.environ.setdefault('LANG', 'en_US.UTF-8') # config_opts['environment']['TZ'] = os.environ.setdefault('TZ', 'EST5EDT')
diff --git a/py/mockbuild/util.py b/py/mockbuild/util.py index 26fa557..d8aa55a 100644 --- a/py/mockbuild/util.py +++ b/py/mockbuild/util.py @@ -604,7 +604,8 @@ def _prepare_nspawn_command(chrootPath, user, cmd, private_network=False, env=No nspawn_argv.append('--private-network') if env: # BZ 1312384 workaround - env['PROMPT_COMMAND'] = 'printf "<mock-chroot>"' + env['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007"' + env['PS1'] = '<mock-chroot> \s-\v\$ ' for k, v in env.items(): nspawn_argv.append('--setenv={0}={1}'.format(k, v)) cmd = nspawn_argv + cmd @@ -621,7 +622,9 @@ def doshell(chrootPath=None, environ=None, uid=None, gid=None, user=None, cmd=No if environ is None: environ = clean_env() if 'PROMPT_COMMAND' not in environ: - environ['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007<mock-chroot>"' + environ['PROMPT_COMMAND'] = 'printf "\033]0;<mock-chroot>\007"' + if 'PS1' not in environ: + environ['PS1'] = '<mock-chroot> \s-\v\$ ' if 'SHELL' not in environ: environ['SHELL'] = '/bin/sh' log.debug("doshell environment: %s", environ) @@ -793,7 +796,8 @@ def setup_default_config_opts(unprivUid, version, pkgpythondir): 'HOME': '/builddir', 'HOSTNAME': 'mock', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', - 'PROMPT_COMMAND': 'printf "\033]0;<mock-chroot>\007<mock-chroot>"', + 'PROMPT_COMMAND': 'printf "\033]0;<mock-chroot>\007"', + 'PS1': '<mock-chroot> \s-\v\$ ', 'LANG': os.environ.setdefault('LANG', 'en_US.UTF-8'), }
It's perhaps worth noting that raw strings would be another way to handle the escape sequences, e.g.:
environ['PROMPT_COMMAND'] = r'printf "\033]0;<mock-chroot>\007"'
I don't know if one way or the other is preferred in mock. (I decided against using some of each in the patch. ;)
Dne 16.4.2016 v 03:57 Todd Zullinger napsal(a):
This is against master. This seemed like a patch which fixes a minor issue and would thus be suitable for an eventual maintenance release. I can rebase it against devel if that's preferred though.
Committed as * 72f443b (HEAD -> devel, origin/devel) util: Escape the escape sequences in PROMPT_COMMAND, improve prompt
No regression and it apply to devel cleanly.
Thank you.
buildsys@lists.fedoraproject.org