From c5f2c408e7c8172035036e2024d84a566c73eb1b Mon Sep 17 00:00:00 2001 From: Dan Wendorf Date: Sun, 6 Aug 2017 12:55:46 -0700 Subject: [PATCH] SCM_CURRENT_USER supports accented characters `tr 'A-Z' 'a-z'` will only convert non-accented characters. Switching to `[:upper:]` and `[:lower:]` adds support for accents. See https://github.com/koalaman/shellcheck/wiki/SC2018 Additionally, printf's character splitting does not support accented characters, so output isn't as expected. Using bash's variable expansion syntax instead will correctly get the full accented character. --- test/themes/base.theme.git.bats | 5 +++++ themes/base.theme.bash | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index 2f3950b0..4547a6e3 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -362,6 +362,11 @@ setup_repo_with_upstream() { git_prompt_vars assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu" + git config user.name "Çool Üser" + + git_prompt_vars + assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü" + # show initials set by `git pair` git config user.initials "ab cd" diff --git a/themes/base.theme.bash b/themes/base.theme.bash index b6106d00..e83d7c47 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -325,7 +325,7 @@ function git_user_info { # support two or more initials, set by 'git pair' plugin SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%') # if `user.initials` weren't set, attempt to extract initials from `user.name` - [[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | tr 'A-Z' 'a-z'); do printf "%1.1s" $word; done)) + [[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done)) [[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX" }