mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-04-10 16:32:00 +00:00
Compare commits
2 Commits
795c168490
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c10d9839f | ||
|
|
103246c198 |
@@ -103,11 +103,6 @@ function _omz_git_prompt_status() {
|
||||
local status_lines
|
||||
status_lines=("${(@f)${status_text}}")
|
||||
|
||||
# Use C locale for regex matching to avoid "illegal byte sequence" errors
|
||||
# when branch names or file paths contain non-ASCII characters (e.g. Chinese)
|
||||
local _omz_lc_all=$LC_ALL
|
||||
LC_ALL=C
|
||||
|
||||
# If the tracking line exists, get and parse it
|
||||
if [[ "$status_lines[1]" =~ "^## [^ ]+ \[(.*)\]" ]]; then
|
||||
local branch_statuses
|
||||
@@ -131,8 +126,6 @@ function _omz_git_prompt_status() {
|
||||
fi
|
||||
done
|
||||
|
||||
LC_ALL=$_omz_lc_all
|
||||
|
||||
# Display the seen statuses in the order specified
|
||||
local status_prompt
|
||||
for status_constant in $status_constants; do
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
#!/usr/bin/zsh -df
|
||||
|
||||
# Regression tests for lib/git.zsh
|
||||
|
||||
local -i _failures=0
|
||||
|
||||
run_test() {
|
||||
local description="$1"
|
||||
local got="$2"
|
||||
local expected="$3"
|
||||
|
||||
print -u2 "Test: $description"
|
||||
if [[ "$got" == "$expected" ]]; then
|
||||
print -u2 "\e[32mSuccess\e[0m"
|
||||
else
|
||||
print -u2 "\e[31mError\e[0m"
|
||||
print -u2 " expected: ${(q)expected}"
|
||||
print -u2 " got: ${(q)got}"
|
||||
(( _failures++ ))
|
||||
fi
|
||||
print -u2 ""
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Set up: source git.zsh and override __git_prompt_git with a controllable mock
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
source "${0:h:h}/git.zsh" 2>/dev/null
|
||||
|
||||
# The mock returns canned `git status --porcelain -b` output and denies stash.
|
||||
# Callers set _mock_status_output before calling _omz_git_prompt_status.
|
||||
_mock_status_output=""
|
||||
function __git_prompt_git() {
|
||||
case "$*" in
|
||||
"config --get oh-my-zsh.hide-status") return 1 ;;
|
||||
"rev-parse --verify refs/stash") return 1 ;;
|
||||
"status --porcelain -b") printf "%s\n" "$_mock_status_output" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Bug #13330: _omz_git_prompt_status emits "regex matching error: illegal byte
|
||||
# sequence" when the git branch name contains non-ASCII characters (e.g. Chinese).
|
||||
# Root cause: zsh's =~ operator with [^ ]+ is locale-aware and rejects multibyte
|
||||
# sequences unless LC_ALL=C is set for the match.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Chinese branch with upstream tracking info
|
||||
_mock_status_output="## 中文-1.0.0-中文...origin/中文-1.0.0-中文 [ahead 1]"
|
||||
stderr_output=$( { _omz_git_prompt_status } 2>&1 1>/dev/null )
|
||||
run_test \
|
||||
"no 'illegal byte sequence' error with Chinese branch name (bug #13330)" \
|
||||
"${stderr_output}" \
|
||||
""
|
||||
|
||||
# Chinese branch with no tracking info (the regex should simply not match)
|
||||
_mock_status_output="## 中文-branch"
|
||||
stderr_output=$( { _omz_git_prompt_status } 2>&1 1>/dev/null )
|
||||
run_test \
|
||||
"no error when Chinese branch has no tracking info" \
|
||||
"${stderr_output}" \
|
||||
""
|
||||
|
||||
# Regression: ASCII branch names must still be parsed correctly
|
||||
_mock_status_output="## main...origin/main [behind 3]"
|
||||
ZSH_THEME_GIT_PROMPT_BEHIND="<"
|
||||
output=$( _omz_git_prompt_status 2>/dev/null )
|
||||
run_test \
|
||||
"ASCII branch with 'behind' tracking info still detected" \
|
||||
"${output}" \
|
||||
"<"
|
||||
|
||||
exit $_failures
|
||||
@@ -30,14 +30,20 @@ function tofu_version_prompt_info() {
|
||||
alias tt='tofu'
|
||||
alias tta='tofu apply'
|
||||
alias tta!='tofu apply -auto-approve'
|
||||
alias ttap='tofu apply -parallelism=1'
|
||||
alias ttapp='tofu apply tfplan'
|
||||
alias ttc='tofu console'
|
||||
alias ttd='tofu destroy'
|
||||
alias ttd!='tofu destroy -auto-approve'
|
||||
alias ttf='tofu fmt'
|
||||
alias ttfr='tofu fmt -recursive'
|
||||
alias tti='tofu init'
|
||||
alias ttir='tofu init -reconfigure'
|
||||
alias ttiu='tofu init -upgrade'
|
||||
alias ttiur='tofu init -upgrade -reconfigure'
|
||||
alias tto='tofu output'
|
||||
alias ttp='tofu plan'
|
||||
alias ttpo='tofu plan -out tfplan'
|
||||
alias ttv='tofu validate'
|
||||
alias tts='tofu state'
|
||||
alias ttsh='tofu show'
|
||||
|
||||
@@ -4,21 +4,21 @@ function tf_prompt_info() {
|
||||
# check if in terraform dir and file exists
|
||||
[[ -d "${TF_DATA_DIR:-.terraform}" && -r "${TF_DATA_DIR:-.terraform}/environment" ]] || return
|
||||
|
||||
local workspace="$(< "${TF_DATA_DIR:-.terraform}/environment")"
|
||||
local workspace="$(<"${TF_DATA_DIR:-.terraform}/environment")"
|
||||
echo "${ZSH_THEME_TF_PROMPT_PREFIX-[}${workspace:gs/%/%%}${ZSH_THEME_TF_PROMPT_SUFFIX-]}"
|
||||
}
|
||||
|
||||
function tf_version_prompt_info() {
|
||||
local terraform_version
|
||||
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
|
||||
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
|
||||
local terraform_version
|
||||
terraform_version=$(terraform --version | head -n 1 | cut -d ' ' -f 2)
|
||||
echo "${ZSH_THEME_TF_VERSION_PROMPT_PREFIX-[}${terraform_version:gs/%/%%}${ZSH_THEME_TF_VERSION_PROMPT_SUFFIX-]}"
|
||||
}
|
||||
|
||||
|
||||
alias tf='terraform'
|
||||
alias tfa='terraform apply'
|
||||
alias tfa!='terraform apply -auto-approve'
|
||||
alias tfap='terraform apply -parallelism=1'
|
||||
alias tfapp='terraform apply tfplan'
|
||||
alias tfc='terraform console'
|
||||
alias tfd='terraform destroy'
|
||||
alias tfd!='terraform destroy -auto-approve'
|
||||
@@ -31,6 +31,7 @@ alias tfiu='terraform init -upgrade'
|
||||
alias tfiur='terraform init -upgrade -reconfigure'
|
||||
alias tfo='terraform output'
|
||||
alias tfp='terraform plan'
|
||||
alias tfpo='terraform plan -out tfplan'
|
||||
alias tfv='terraform validate'
|
||||
alias tfs='terraform state'
|
||||
alias tft='terraform test'
|
||||
|
||||
Reference in New Issue
Block a user