merlin zsh compatible

This commit is contained in:
Yuhao Qing
2025-12-18 17:42:46 +08:00
parent a7dcd7c271
commit 76549f5438
2 changed files with 38 additions and 39 deletions

View File

@@ -13,7 +13,7 @@ export HISTSIZE=100000
export HISTFILESIZE=200000
# 2. 在关闭终端时追加历史记录,而不是覆盖
shopt -s histappend
[[ -n "${BASH_VERSION}" ]] && shopt -s histappend
# 3. 忽略重复及以空格开头的命令
export HISTCONTROL=ignoreboth
@@ -100,7 +100,11 @@ export SEC_KV_AUTH=1
_base_no_proxy=".byted.org,byted.org,.bytedance.net,bytedance.net"
for _v in NO_PROXY no_proxy; do
_cur="${!_v}"
if [[ -n "${BASH_VERSION}" ]]; then
_cur="${!_v}"
else
_cur="${(P)_v}"
fi
if [[ -z "${_cur}" ]]; then
export ${_v}="${_base_no_proxy}"
else
@@ -150,10 +154,12 @@ if [[ "$WORKSPACE_ENVS_SET" != "1" ]]; then
envfile="/etc/.container_env"
if [[ -f $envfile ]]; then
while IFS= read -r line; do
if [[ ! -v ${line%%=*} ]]; then # env is not set
export "${line%%=*}=${line#*=}"
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$envfile"
unset _varname
fi
if [[ -n "${ZSH_VERSION}" ]]; then
@@ -220,16 +226,20 @@ worker_envfile="/etc/worker_envs_$ARNOLD_WORKER_ID"
user_worker_envfile="$HOME/.worker_envs/worker_envs_$ARNOLD_WORKER_ID"
if [[ -f $user_worker_envfile ]]; then
while IFS= read -r line; do
if [[ ! -v ${line%%=*} ]]; then # env is not set
export "${line%%=*}=${line#*=}"
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$user_worker_envfile"
unset _varname
elif [[ -f $worker_envfile ]]; then
while IFS= read -r line; do
if [[ ! -v ${line%%=*} ]]; then # env is not set
export "${line%%=*}=${line#*=}"
_varname="${line%%=*}"
if eval "[[ -z \"\${${_varname}+x}\" ]]"; then # env is not set
export "${_varname}=${line#*=}"
fi
done <"$worker_envfile"
unset _varname
fi
############################################################
@@ -276,7 +286,11 @@ if [[ -f "$envfile" ]]; then
if [[ " $env_white_list " == *" $var_name "* ]]; then
# 变量已设置且在白名单中,追加新值并去重
existing_value="${!var_name}"
if [[ -n "${BASH_VERSION}" ]]; then
existing_value="${!var_name}"
else
existing_value="${(P)var_name}"
fi
if [[ -n "$existing_value" ]]; then
new_value="$var_value:$existing_value"
dedup_value=$(deduplicate_env "$new_value")
@@ -292,6 +306,10 @@ fi
# GPU 相关(原 prep_env.sh
############################################################
if [[ -n $NVIDIA_VISIBLE_DEVICES && $NVIDIA_VISIBLE_DEVICES != 'none' ]]; then
cur_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ -n "${ZSH_VERSION}" ]]; then
cur_dir="$(cd "$(dirname "$0")" && pwd)"
else
cur_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
source "$cur_dir"/nvidia.sh
fi