From a2174689afa0397723d16d3c89e46ac6eaaff3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20=F0=9F=91=A8=F0=9F=8F=BD=E2=80=8D=F0=9F=92=BB=20Copl?= =?UTF-8?q?an?= Date: Tue, 3 Dec 2024 12:08:11 -0800 Subject: [PATCH] fix(scm-prompt): suppress cd output (#985) Summary: If a user has a `chpwd` hook that prints output, it will be prepended to the `dir` variable which breaks the prompt. This change suppresses the output of `cd` to prevent this. Alternatively I considered doing `cd -q` to skip running the chpwd hook, but decided against it. Pull Request resolved: https://github.com/facebook/sapling/pull/985 Test Plan: ```zsh $ zsh --no-rcs $ source ~/workspace/github.com/facebook/sapling/eden/scm/contrib/scm-prompt.sh && _scm_prompt # things should be fine $ say_hi() { echo hello } && chpwd_functions+=(say_hi) && _scm_prompt ``` prior to this commit, the prompt would be broken. After this commit, it should be fine. Background: in my particular case, I have a `chpwd` hook that [sources custom scripts](https://github.com/vegerot/dotfiles/blob/032f88715fa2911bec6b3c09aa012145bb1dae7e/.zshrc#L250-L252) depending on the directory, and will tell me if it does so. This was breaking the prompt, so I added this change to fix it. Reviewed By: quark-zju Differential Revision: D66384725 fbshipit-source-id: e03d18887a27fc6c55da1dc7347eacf0fa38cde7 --- eden/scm/contrib/scm-prompt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eden/scm/contrib/scm-prompt.sh b/eden/scm/contrib/scm-prompt.sh index 015932da5ce7a..9ea7989b83719 100644 --- a/eden/scm/contrib/scm-prompt.sh +++ b/eden/scm/contrib/scm-prompt.sh @@ -257,7 +257,7 @@ _scm_prompt() { fi [[ "$dir" = "/" ]] && break # portable "realpath" equivalent - dir="$(builtin cd -P "$dir/.." && builtin echo "$PWD")" + dir="$(builtin cd -P "$dir/.." >/dev/null && builtin echo "$PWD")" done if [[ -n "$br" ]]; then