【发布时间】:2018-09-20 00:35:25
【问题描述】:
我正在尝试使用为 ubuntu 用户安装的 oh-my-zsh 引导我的 AWS EC2 ubuntu 服务器。我有一个以 root 用户身份(使用 sudo)运行的 cloud-init 脚本(更多信息 here)。因此,在我的脚本中,我以 ubuntu 用户身份运行 oh-my-zsh 安装。
#cloud-config
runcmd:
# omitted other commands specific to my server, install zsh at the end
- apt-get install -y zsh
- su ubuntu -c 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/coreycole/oh-my-zsh/master/tools/install.sh)"'
- chsh -s $(which zsh) ubuntu
# change the prompt to include the server hostname
- su ubuntu -c echo "echo export PROMPT=\''%{$fg[green]%}%n@%{$fg[green]%}%m%{$reset_color%} ${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'\'" >> /home/ubuntu/.zshrc
# get environment variables defined above
- echo "source ~/.profile" >> /home/ubuntu/.zshrc
当 cloud-init 完成并且我 ssh 进入颜色在 $PROMPT 中不起作用时,我看到 [green] 和 [cyan]:
[green]ubuntu@[green]ip-172-31-27-24 [cyan]~
如果我在 ssh 后运行与 ubuntu 用户相同的 PROMPT 命令,颜色将正常工作:
问题似乎是当 cloud-init 脚本运行 echo 命令时如何评估颜色与 ubuntu 用户运行 echo 命令时如何评估颜色。有谁知道我可以如何更改 PROMPT 以便仅在 ubuntu 用户评估 ~/.zshrc 时评估颜色?
【问题讨论】:
标签: bash ubuntu zsh oh-my-zsh cloud-init