From 0302c99abdc1c65e39c84e7506c06181ab236ce2 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Tue, 13 Nov 2018 18:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=99=E7=82=B9=E6=9B=B4=E6=96=B0=EF=BC=9A20?= =?UTF-8?q?18-11-13=2018:58:18?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/gnzh.zsh-theme | 53 +++++++++++++++++++++++++++++++++++++++++++ config/init.sh | 1 + config/zshrc | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 config/gnzh.zsh-theme diff --git a/config/gnzh.zsh-theme b/config/gnzh.zsh-theme new file mode 100644 index 0000000..58258ee --- /dev/null +++ b/config/gnzh.zsh-theme @@ -0,0 +1,53 @@ +# Based on bira theme + +setopt prompt_subst + +() { + +local PR_USER PR_USER_OP PR_PROMPT PR_HOST + +# Check the UID +if [[ $UID -ne 0 ]]; then # normal user + PR_USER='%F{green}%n%f' + PR_USER_OP='%F{green}%#%f' + PR_PROMPT='%f> %f' +else # root + PR_USER='%F{yellow}%n%f' + PR_USER_OP='%F{yellow}%#%f' + PR_PROMPT='%f> %f' +fi + +# Check if we are on SSH or not +if [[ -n "$SSH_CLIENT" || -n "$SSH2_CLIENT" ]]; then + PR_HOST='%F{red}%M%f' # SSH +else + PR_HOST='%F{green}%M%f' # no SSH +fi + + +local return_code="%(?..%F{red}%? ↵%f)" + +local user_host="${PR_USER}%F{cyan}@${PR_HOST}" +local current_dir="%B%F{blue}%~%f%b" +local rvm_ruby='' +if ${HOME}/.rvm/bin/rvm-prompt &> /dev/null; then # detect user-local rvm installation + rvm_ruby='%F{red}‹$(${HOME}/.rvm/bin/rvm-prompt i v g s)›%f' +elif which rvm-prompt &> /dev/null; then # detect system-wide rvm installation + rvm_ruby='%F{red}‹$(rvm-prompt i v g s)›%f' +elif which rbenv &> /dev/null; then # detect Simple Ruby Version Management + rvm_ruby='%F{red}‹$(rbenv version | sed -e "s/ (set.*$//")›%f' +fi + +local git_branch='$(git_prompt_info)' + +PROMPT="╭─${user_host} ${current_dir} [%*] ${git_branch} ${rvm_ruby} +╰─$PR_PROMPT" +RPROMPT="${return_code}" + +ZSH_THEME_GIT_PROMPT_PREFIX="%F{green}(" +#ZSH_THEME_GIT_PROMPT_PREFIX="%F{yellow}‹" +ZSH_THEME_GIT_PROMPT_SUFFIX="%F{green})" +ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}x" +ZSH_THEME_GIT_PROMPT_CLEAN=" %{$fg[green]%}o" + +} diff --git a/config/init.sh b/config/init.sh index 6ea081b..6e05900 100755 --- a/config/init.sh +++ b/config/init.sh @@ -28,6 +28,7 @@ git clone https://github.com/zsh-users/zsh-history-substring-search.git /root/.o echo -e "\033[1;33mConfig oh-my-zsh...\033[0m" cp -f /vagrant/config/zshrc ~/.zshrc cp -f /vagrant/config/my.zsh ~/.oh-my-zsh/custom/ +cp -f /vagrant/config/gnzh.zsh-theme ~/.oh-my-zsh/themes/ echo -e "\033[1;33mConfig ssh...\033[0m" mkdir -p ~/.ssh && cat /vagrant/config/authorized.key >> ~/.ssh/authorized_keys diff --git a/config/zshrc b/config/zshrc index 9a2b795..2a3e97b 100644 --- a/config/zshrc +++ b/config/zshrc @@ -1,6 +1,6 @@ export ZSH=~/.oh-my-zsh -ZSH_THEME="robbyrussell" +ZSH_THEME="gnzh" plugins=(git wd sudo zsh-syntax-highlighting zsh-autosuggestions extract history-substring-search)