diff --git a/zshrc/merlin_devbox.zsh b/zshrc/merlin_devbox.zsh index 5328c67..e1f397e 100644 --- a/zshrc/merlin_devbox.zsh +++ b/zshrc/merlin_devbox.zsh @@ -1,40 +1,21 @@ -# Merlin devbox specific aliases -alias l=ls -alias ll='ls -l --color=auto' -alias infosys='cd ~/repos/infosys; pushonline -minfosys' -export PATH=/opt/tiger/tce/tce_tools/bin:/home/tiger/.local/bin:/opt/common_tools:/usr/local/go/bin:$PATH +# Patch prep_env.sh for zsh compatibility before sourcing +source <(sed -e 's/^shopt -s histappend$/[[ -n "${BASH_VERSION}" ]] \&\& shopt -s histappend/' \ + -e 's/\${!\([^}]*\)}/${(P)\1}/g' \ + /workspace/mlx/../vscode/prep_env.sh) -alias cp='cp -i' -alias mv='mv -i' -alias m='more' -alias ll='ls -l' -alias lsl='ls -lrt' -alias lm='ls -al|more' -alias l='ls -lrt' -alias c='cat' -alias v='vi' -alias cl='clear' -alias pg='ps -ef| grep ' - -# Set terminal type to xterm for better compatibility with terminal features -# export TERM=xterm - -# Customize command prompt to show: hostname(TCE_info):current_directory$ -# \h = hostname, \W = current working directory basename, \$ = $ for user/# for root -# export PS1='\h($TCE_PSM@$TCE_CLUSTER:$TCE_ENV):\W\$ ' - -source /workspace/mlx/../vscode/prep_env.sh # sh -c /opt/tiger/mlx_deploy/greeting.sh -source /opt/tiger/mlx_deploy/mlxrc -if [ -f /opt/tiger/mlx_deploy/pythonpath_rc ]; then + +if [ -f "/opt/tiger/mlx_deploy/pythonpath_rc" ]; then source /opt/tiger/mlx_deploy/pythonpath_rc fi -if command -v import_hdfs_envs.sh > /dev/null 2>&1 && [ -z ]; then source import_hdfs_envs.sh; fi -if [ -f /opt/tiger/rh2_bashrc ]; then + +if [ -f "/opt/tiger/rh2_bashrc" ]; then source /opt/tiger/rh2_bashrc fi + source /opt/tiger/mlx_deploy/userrc +. "$HOME/.cargo/env" # huggingface proxy export HF_NETWORK_PROXY=http://huggingface-proxy-sg.byted.org diff --git a/zshrc/prep_env.sh b/zshrc/prep_env.sh index 14f8681..71533bf 100644 --- a/zshrc/prep_env.sh +++ b/zshrc/prep_env.sh @@ -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