lib: urlencode hostname in update_terminalapp_cwd (#6245)
Apple's Terminal doesn't open a new tab in your current directory if your hostname has UTF-8 characters in it. Percent encoding the host in addition to the path in update_terminalapp_cwd appears to solve this issue.
Co-authored-by: Marc Cornellà <marc.cornella@live.com>
Diff
1diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
2index f5e367fcbc8a0391f3ed2b3cf28f6fa36fea91b5..19fd57b9de5167e1348c91c55a5ecc8094c0e65b 100644
3--- a/lib/termsupport.zsh
4+++ b/lib/termsupport.zsh
5@@ -91,12 +91,13 @@ if [[ "$TERM_PROGRAM" == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]]; then
6 function update_terminalapp_cwd() {
7 emulate -L zsh
8 9- # Percent-encode the pathname.
10- local URL_PATH="$(omz_urlencode -P $PWD)"
11- [[ $? != 0 ]] && return 1
12+ # Percent-encode the host and path names.
13+ local URL_HOST URL_PATH
14+ URL_HOST="$(omz_urlencode -P $HOST)" || return 1
15+ URL_PATH="$(omz_urlencode -P $PWD)" || return 1
1617 # Undocumented Terminal.app-specific control sequence
18- printf '\e]7;%s\a' "file://$HOST$URL_PATH"
19+ printf '\e]7;%s\a' "file://$URL_HOST$URL_PATH"
20 }
2122 # Use a precmd hook instead of a chpwd hook to avoid contaminating output