1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-25 21:40:08 +00:00

survive files with windows EOL (on linux, yes; people do that); see #827

This commit is contained in:
Roman Perepelitsa 2020-06-16 19:51:53 +02:00
parent eda706c8ff
commit 8854cb6000

View file

@ -193,6 +193,7 @@ function _p9k_read_word() {
local rest local rest
_p9k__ret= _p9k__ret=
{ read _p9k__ret rest <$1 } 2>/dev/null { read _p9k__ret rest <$1 } 2>/dev/null
_p9k__ret=${_p9k__ret%$'\r'}
_p9k__read_word_cache[$1]=$stat[1]:$_p9k__ret _p9k__read_word_cache[$1]=$stat[1]:$_p9k__ret
fi fi
[[ -n $_p9k__ret ]] [[ -n $_p9k__ret ]]
@ -2078,7 +2079,7 @@ prompt_package() {
# Redneck json parsing. Yields correct results for any well-formed json document. # Redneck json parsing. Yields correct results for any well-formed json document.
# Produces random garbage for invalid json. # Produces random garbage for invalid json.
{ data="$(<$file)" || return } 2>/dev/null { data="$(<$file)" || return } 2>/dev/null
data=${data##[[:space:]]#} data=${${data//$'\r'}##[[:space:]]#}
[[ $data == '{'* ]] || return [[ $data == '{'* ]] || return
data[1]= data[1]=
local -i depth=1 local -i depth=1
@ -2301,6 +2302,7 @@ function _p9k_nvm_ls_default() {
while [[ -r $NVM_DIR/alias/$v ]]; do while [[ -r $NVM_DIR/alias/$v ]]; do
local target= local target=
IFS='' read -r target <$NVM_DIR/alias/$v IFS='' read -r target <$NVM_DIR/alias/$v
target=${target%$'\r'}
[[ -z $target ]] && break [[ -z $target ]] && break
(( $seen[(I)$target] )) && return (( $seen[(I)$target] )) && return
seen+=$target seen+=$target
@ -5012,7 +5014,7 @@ function _p9k_asdf_init_meta() {
# legacy_version_file = yes # legacy_version_file = yes
# #
# We do the same. # We do the same.
local lines=(${(@M)${(f)"$(<$cfg)"}:#[[:space:]]#legacy_version_file[[:space:]]#=*}) local lines=(${(@M)${(@)${(f)"$(<$cfg)"}%$'\r'}:#[[:space:]]#legacy_version_file[[:space:]]#=*})
if [[ $#lines == 1 && ${${(s:=:)lines[1]}[2]} == [[:space:]]#yes[[:space:]]# ]]; then if [[ $#lines == 1 && ${${(s:=:)lines[1]}[2]} == [[:space:]]#yes[[:space:]]# ]]; then
legacy_enabled=1 legacy_enabled=1
fi fi
@ -5092,6 +5094,7 @@ function _p9k_asdf_parse_version_file() {
local v=($(${ASDF_DATA_DIR:-~/.asdf}/plugins/$plugin/bin/parse-legacy-file $file 2>/dev/null)) local v=($(${ASDF_DATA_DIR:-~/.asdf}/plugins/$plugin/bin/parse-legacy-file $file 2>/dev/null))
else else
{ local v=($(<$file)) } 2>/dev/null { local v=($(<$file)) } 2>/dev/null
v=(${v%$'\r'})
fi fi
v=${v[(r)$_p9k_asdf_plugins[$plugin]]:-$v[1]} v=${v[(r)$_p9k_asdf_plugins[$plugin]]:-$v[1]}
_p9k_asdf_file2versions[$plugin:$file]=$stat[1]:"$v" _p9k_asdf_file2versions[$plugin:$file]=$stat[1]:"$v"
@ -5105,7 +5108,7 @@ function _p9k_asdf_parse_version_file() {
local file_versions=(${(0)${cached#*:}}) local file_versions=(${(0)${cached#*:}})
else else
local file_versions=() local file_versions=()
{ local lines=(${(@)${(f)"$(<$file)"}/\#*}) } 2>/dev/null { local lines=(${(@)${(@)${(f)"$(<$file)"}%$'\r'}/\#*}) } 2>/dev/null
local line local line
for line in $lines; do for line in $lines; do
local words=($=line) local words=($=line)