individual zsh configuration
This commit is contained in:
23
README.md
23
README.md
@@ -1,21 +1,16 @@
|
|||||||
# ZSH Polyjuice
|
# TerminalPolyjuice
|
||||||
|
|
||||||
[](https://github.com/trekhleb/state-of-the-art-shitcode)
|
[](https://github.com/trekhleb/state-of-the-art-shitcode)
|
||||||
|
|
||||||
Automatically configure [ZSH](https://github.com/zsh-users/zsh) based on [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) according to my habits.
|
Automatically configure terminal according to my habits.
|
||||||
|
|
||||||
## The `Polyjuice` theme
|
## For `ZSH`
|
||||||
The theme `polyjuice.zsh-theme` is based the [ys](https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/ys.zsh-theme) theme. It will look like this.
|
Using `Oh-My-ZSH` framework to manage plugins, and `Starship` to customize prompt.
|
||||||
|
|
||||||
```
|
|
||||||
# username @ HOST-NAME in ~/.zsh_polyjuice on git:main
|
|
||||||
17:25:06 $
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
Install `ZSH` according the the platform you use. Clone this repository and run `polyjuice.sh`.
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
git clone https://github.com/gwbeip/zsh_polyjuice.git $HOME/.zsh_polyjuice
|
git clone https://gitea.meip.work/gwbeip/TerminalPolyjuice.git $HOME/.TerminalPolyjuice
|
||||||
bash $HOME/.zsh_polyjuice/polyjuice.sh
|
cd $HOME/.TerminalPolyjuice/zsh
|
||||||
|
zsh polyjuice.sh install_ohmyzsh config_starship check
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`zsh/p10k.zsh` includes the configuration for execution time when using `powerlevel10k`
|
@@ -1,18 +0,0 @@
|
|||||||
# colors for outputs
|
|
||||||
error_color="\033[1;31m" # color for errors (bold red)
|
|
||||||
note_color="\033[4;36m" # color for notations (under-line cyan)
|
|
||||||
default_color="\033[m" # default color (e.g., white)
|
|
||||||
|
|
||||||
rustup_path=$(command -v rustup)
|
|
||||||
if [[ $rustup_path = "" ]]; then
|
|
||||||
curl_path=$(command -v curl)
|
|
||||||
if [[ $curl_path = "" ]]; then
|
|
||||||
echo -e $note_color curl is required to install Rust through rustup $default_color
|
|
||||||
else
|
|
||||||
echo -e $note_color Installing Rust using rustup...$default_color
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo -e $note_color Rust has been installed using rustup, installation path is $rustup_path $default_color
|
|
||||||
echo -e "To update Rust, run: rustup update"
|
|
||||||
fi
|
|
38
polyjuice.sh
38
polyjuice.sh
@@ -1,38 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
current_dir=$(dirname "$0")
|
|
||||||
|
|
||||||
[[ ! -f "$HOME/.zshenv" ]] || touch "$HOME/.zshenv"
|
|
||||||
if cat "$HOME/.zshenv" | grep -q "\$TERMINAL_POLYJUICE"; then
|
|
||||||
if $(dirname "$0") != "$TERMINAL_POLYJUICE"; then
|
|
||||||
line_number=$(grep -n "\$TERMINAL_POLYJUICE" "$HOME/.zshenv" | cut -d: -f1)
|
|
||||||
sed -i "${line_number}c\\export TERMINAL_POLYJUICE=$current_dir" "$HOME/.zshenv"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "export TERMINAL_POLYJUICE=$current_dir" >> "$HOME/.zshenv"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$1" = "zsh" ]; then
|
|
||||||
if [ $# -gt 1 ]; then
|
|
||||||
for i in "${@:2}"; do
|
|
||||||
if [ "$i" = "install" ]; then
|
|
||||||
echo "Installing Oh My Zsh..."
|
|
||||||
zsh "$current_dir/zsh/install_ohmyzsh.sh"
|
|
||||||
elif [ "$i" = "ohmyzsh" ]; then
|
|
||||||
echo "Config Oh My Zsh..."
|
|
||||||
zsh "$current_dir/zsh/config_ohmyzsh.sh"
|
|
||||||
elif [ "$i" = "starship" ]; then
|
|
||||||
echo "Config Starship..."
|
|
||||||
zsh "$current_dir/zsh/config_starship.sh"
|
|
||||||
elif [ "$i" = "p10k" ]; then
|
|
||||||
echo "config powerlevel10k..."
|
|
||||||
zsh "$current_dir/zsh/config_p10k.sh"
|
|
||||||
elif [ "$i" = "check" ]; then
|
|
||||||
echo "chcking uninstalled software..."
|
|
||||||
zsh "$current_dir/zsh/check.sh"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
echo "Run \"exec zsh\" to apply changes."
|
|
||||||
exec zsh
|
|
||||||
fi
|
|
@@ -1,122 +0,0 @@
|
|||||||
# VCS
|
|
||||||
YS_VCS_PROMPT_PREFIX1=" %{$reset_color%}on%{$fg[blue]%} "
|
|
||||||
YS_VCS_PROMPT_PREFIX2=":%{$fg[cyan]%}"
|
|
||||||
YS_VCS_PROMPT_SUFFIX="%{$reset_color%}"
|
|
||||||
YS_VCS_PROMPT_DIRTY=" %{$fg[red]%}x"
|
|
||||||
YS_VCS_PROMPT_CLEAN=" %{$fg[green]%}o"
|
|
||||||
|
|
||||||
# Git info
|
|
||||||
git_branch_info () {
|
|
||||||
local git_branch_name=$(git branch --show-current 2&> /dev/null | xargs -I branch echo "branch")
|
|
||||||
if [[ $git_branch_name = "" ]]; then
|
|
||||||
echo ""
|
|
||||||
else
|
|
||||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}$git_branch_name${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
local git_info='$(git_branch_info)'
|
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}git${YS_VCS_PROMPT_PREFIX2}"
|
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
|
||||||
ZSH_THEME_GIT_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
|
||||||
|
|
||||||
# SVN info
|
|
||||||
local svn_info='$(svn_prompt_info)'
|
|
||||||
ZSH_THEME_SVN_PROMPT_PREFIX="${YS_VCS_PROMPT_PREFIX1}svn${YS_VCS_PROMPT_PREFIX2}"
|
|
||||||
ZSH_THEME_SVN_PROMPT_SUFFIX="$YS_VCS_PROMPT_SUFFIX"
|
|
||||||
ZSH_THEME_SVN_PROMPT_DIRTY="$YS_VCS_PROMPT_DIRTY"
|
|
||||||
ZSH_THEME_SVN_PROMPT_CLEAN="$YS_VCS_PROMPT_CLEAN"
|
|
||||||
|
|
||||||
# HG info
|
|
||||||
local hg_info='$(ys_hg_prompt_info)'
|
|
||||||
ys_hg_prompt_info() {
|
|
||||||
# make sure this is a hg dir
|
|
||||||
if [ -d '.hg' ]; then
|
|
||||||
echo -n "${YS_VCS_PROMPT_PREFIX1}hg${YS_VCS_PROMPT_PREFIX2}"
|
|
||||||
echo -n $(hg branch 2>/dev/null)
|
|
||||||
if [[ "$(hg config oh-my-zsh.hide-dirty 2>/dev/null)" != "1" ]]; then
|
|
||||||
if [ -n "$(hg status 2>/dev/null)" ]; then
|
|
||||||
echo -n "$YS_VCS_PROMPT_DIRTY"
|
|
||||||
else
|
|
||||||
echo -n "$YS_VCS_PROMPT_CLEAN"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo -n "$YS_VCS_PROMPT_SUFFIX"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Virtualenv
|
|
||||||
local venv_info='$(virtenv_prompt)'
|
|
||||||
YS_THEME_VIRTUALENV_PROMPT_PREFIX=" %{$fg[green]%}"
|
|
||||||
YS_THEME_VIRTUALENV_PROMPT_SUFFIX=" %{$reset_color%}%"
|
|
||||||
virtenv_prompt() {
|
|
||||||
[[ -n "${VIRTUAL_ENV:-}" ]] || return
|
|
||||||
echo "${YS_THEME_VIRTUALENV_PROMPT_PREFIX}${VIRTUAL_ENV:t}${YS_THEME_VIRTUALENV_PROMPT_SUFFIX}"
|
|
||||||
}
|
|
||||||
|
|
||||||
local exit_code="%(?,,| C:%{$fg[red]%}%?%{$reset_color%})"
|
|
||||||
|
|
||||||
# Prompt format:
|
|
||||||
#
|
|
||||||
# PRIVILEGES USER @ MACHINE in DIRECTORY on git:BRANCH STATE [TIME] C:LAST_EXIT_CODE
|
|
||||||
# $ COMMAND
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#
|
|
||||||
# % ys @ ys-mbp in ~/.oh-my-zsh on git:master x | C:0
|
|
||||||
# [21:47:42] $
|
|
||||||
|
|
||||||
PROMPT="
|
|
||||||
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
|
|
||||||
%(#,%{$bg[yellow]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[cyan]%}%n) \
|
|
||||||
%{$reset_color%}@ \
|
|
||||||
%{$fg[green]%}%m \
|
|
||||||
%{$reset_color%}in \
|
|
||||||
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\
|
|
||||||
${hg_info}\
|
|
||||||
${git_info}\
|
|
||||||
${svn_info}\
|
|
||||||
${venv_info}\
|
|
||||||
\
|
|
||||||
$exit_code
|
|
||||||
%{$terminfo[bold]$fg[red]%}%U%*%u %{$reset_color%}%U$%u %{$reset_color%}"
|
|
||||||
|
|
||||||
# source $HOME/.software/software_env.sh
|
|
||||||
function add_path_to_software_env() {
|
|
||||||
echo -e "\033[4;36mAdd [$(pwd)] to software evn\033[m"
|
|
||||||
grep $(pwd) $HOME/.software/software_env.sh
|
|
||||||
if [[ ! $? == 0 ]]; then
|
|
||||||
echo "export PATH=$(pwd):\$PATH" >> $HOME/.software/software_env.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
source $HOME/.software/software_env.sh
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
. $HOME/.software/software_env.sh
|
|
||||||
|
|
||||||
# Homebrew tsinghua mirror for macOS
|
|
||||||
function brewthu() {
|
|
||||||
if [[ $HOMEBREW_BOTTLE_DOMAIN = "" ]]; then
|
|
||||||
export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"
|
|
||||||
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
|
|
||||||
export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
|
|
||||||
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
|
|
||||||
export HOMEBREW_PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
||||||
# Bottles
|
|
||||||
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
|
|
||||||
else
|
|
||||||
unset HOMEBREW_API_DOMAIN
|
|
||||||
unset HOMEBREW_BOTTLE_DOMAIN
|
|
||||||
unset HOMEBREW_BREW_GIT_REMOTE
|
|
||||||
unset HOMEBREW_CORE_GIT_REMOTE
|
|
||||||
unset HOMEBREW_PIP_INDEX_URL
|
|
||||||
# Bottles
|
|
||||||
unset HOMEBREW_BOTTLE_DOMAIN
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# alias
|
|
||||||
alias py=python3
|
|
||||||
alias ap2se=add_path_to_software_env
|
|
@@ -27,6 +27,7 @@ $conda\
|
|||||||
$time\
|
$time\
|
||||||
$cmd_duration\
|
$cmd_duration\
|
||||||
[ ](fg:color_bg1)\
|
[ ](fg:color_bg1)\
|
||||||
|
$fill\
|
||||||
$line_break$\
|
$line_break$\
|
||||||
character"""
|
character"""
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ color_purple = '#b16286'
|
|||||||
color_red = '#cc241d'
|
color_red = '#cc241d'
|
||||||
color_yellow = '#d79921'
|
color_yellow = '#d79921'
|
||||||
|
|
||||||
|
|
||||||
[os]
|
[os]
|
||||||
disabled = false
|
disabled = false
|
||||||
style = "bg:color_orange fg:color_fg0"
|
style = "bg:color_orange fg:color_fg0"
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
current_dir=$(dirname "$0")
|
|
||||||
|
|
||||||
# copying $HOME/.zshrc
|
|
||||||
if [ -f "$HOME/.zshrc" ]; then
|
|
||||||
if [ ! -f "$HOME/.zshrc.bkp" ]; then
|
|
||||||
mv "$HOME/.zshrc" "$HOME/.zshrc.bkp"
|
|
||||||
cp "$current_dir/zshrc" "$HOME/.zshrc"
|
|
||||||
else
|
|
||||||
echo "Backup file already exists. Please remove $HOME/.zshrc.bkp and try again."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
cp "$current_dir/zshrc" "$HOME/.zshrc"
|
|
||||||
fi
|
|
||||||
|
|
@@ -1,5 +0,0 @@
|
|||||||
#! /bin/bash
|
|
||||||
|
|
||||||
current_dir=$(dirname "$0")
|
|
||||||
|
|
||||||
cp "$current_dir/p10k.zsh" "$HOME/.p10k.zsh"
|
|
@@ -1,5 +1,22 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
current_dir=$(dirname "$0")
|
current_dir=$(dirname $(realpath "$0"))
|
||||||
|
starship_config_file="$HOME/.config/starship.toml"
|
||||||
|
|
||||||
cp "$current_dir/../starship/starship.toml" "$HOME/.config/"
|
if [[ $(file $starship_config_file) ]]; then
|
||||||
|
if $(file "$starship_config_file" | grep -q "symbolic link") ; then
|
||||||
|
if [[ $(readlink "$starship_config_file") != $(realpath "$current_dir/../starship/starship.toml") ]]; then
|
||||||
|
ln -sf "$current_dir/../starship/starship.toml" "$starship_config_file"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if [ ! -f "$starship_config_file.bkp" ]; then
|
||||||
|
mv "$starship_config_file" "$starship_config_file.bkp"
|
||||||
|
ln -s "$current_dir/../starship/starship.toml" "$starship_config_file"
|
||||||
|
else
|
||||||
|
echo "Backup file already exists. Please remove $starship_config_file.bkp and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
ln -sf "$current_dir/../starship/starship.toml" "$starship_config_file"
|
||||||
|
fi
|
||||||
|
@@ -33,9 +33,9 @@ if ! command -v starship >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Path
|
# Path
|
||||||
PATH_OHMYZSH="$HOME"/.oh-my-zsh
|
PATH_OHMYZSH="$HOME/.oh-my-zsh"
|
||||||
PATH_OHMYZSH_CUSTOM_PLUGINS="$PATH_OHMYZSH"/custom/plugins
|
PATH_OHMYZSH_CUSTOM_PLUGINS="$PATH_OHMYZSH/custom/plugins"
|
||||||
PATH_OHMYZSH_CUSTOM_THEMES="$PATH_OHMYZSH"/custom/themes
|
PATH_OHMYZSH_CUSTOM_THEMES="$PATH_OHMYZSH/custom/themes"
|
||||||
|
|
||||||
# git clone oh-my-zsh
|
# git clone oh-my-zsh
|
||||||
if [ ! -d "$PATH_OHMYZSH" ]; then
|
if [ ! -d "$PATH_OHMYZSH" ]; then
|
||||||
@@ -103,17 +103,39 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# git clone powerlevel10k
|
# git clone powerlevel10k
|
||||||
if [ ! -d "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k ]; then
|
# if [ ! -d "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k ]; then
|
||||||
echo "Powerlevel10k is not downloaded. Downloading..."
|
# echo "Powerlevel10k is not downloaded. Downloading..."
|
||||||
# git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k
|
# # git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k
|
||||||
git clone --depth=1 https://gitee.com/gwbeip/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k
|
# git clone --depth=1 https://gitee.com/gwbeip/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k
|
||||||
|
# else
|
||||||
|
# cd "$PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k" || exit 1
|
||||||
|
# if [ ! -d .git ]; then
|
||||||
|
# echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k and try again."
|
||||||
|
# exit 1
|
||||||
|
# else
|
||||||
|
# echo "Powerlevel10k is already exist. Updating..."
|
||||||
|
# git pull
|
||||||
|
# fi
|
||||||
|
# fi
|
||||||
|
|
||||||
|
|
||||||
|
# copying $HOME/.zshrc
|
||||||
|
current_dir=$(dirname $(realpath "$0"))
|
||||||
|
|
||||||
|
if $(file "$HOME/.zshrc"); then
|
||||||
|
if $(file "$HOME/.zshrc" | grep -q "symbolic link") ; then
|
||||||
|
if [[ $(readlink "$HOME/.zshrc") != "$current_dir/zshrc" ]]; then
|
||||||
|
ln -sf "$current_dir/zshrc" "$HOME/.zshrc"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
cd "$PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k" || exit 1
|
if [ ! -f "$HOME/.zshrc.bkp" ]; then
|
||||||
if [ ! -d .git ]; then
|
mv "$HOME/.zshrc" "$HOME/.zshrc.bkp"
|
||||||
echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k and try again."
|
ln -s "$current_dir/zshrc" "$HOME/.zshrc"
|
||||||
|
else
|
||||||
|
echo "Backup file already exists. Please remove $HOME/.zshrc.bkp and try again."
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "Powerlevel10k is already exist. Updating..."
|
ln -s "$current_dir/zshrc" "$HOME/.zshrc"
|
||||||
git pull
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
1731
zsh/p10k.zsh
1731
zsh/p10k.zsh
File diff suppressed because it is too large
Load Diff
40
zsh/polyjuice.sh
Normal file
40
zsh/polyjuice.sh
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
current_dir=$(dirname $(realpath "$0"))
|
||||||
|
|
||||||
|
[[ -f "$HOME/.zshenv" ]] || touch "$HOME/.zshenv"
|
||||||
|
if cat "$HOME/.zshenv" | grep -q "TERMINAL_POLYJUICE"; then
|
||||||
|
if [[ "$current_dir" != "$TERMINAL_POLYJUICE" ]]; then
|
||||||
|
line_number=$(grep -n "TERMINAL_POLYJUICE" "$HOME/.zshenv" | cut -d: -f1)
|
||||||
|
sed -i "${line_number}c\\export TERMINAL_POLYJUICE=$current_dir" "$HOME/.zshenv"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "export TERMINAL_POLYJUICE=$current_dir" >> "$HOME/.zshenv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for i in "$@"; do
|
||||||
|
if [ "$i" = "install_ohmyzsh" ]; then
|
||||||
|
echo "Installing Oh My Zsh..."
|
||||||
|
zsh "$current_dir/install_ohmyzsh.sh"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Oh My Zsh installation failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
elif [ "$i" = "config_starship" ]; then
|
||||||
|
echo "Config Starship..."
|
||||||
|
zsh "$current_dir/config_starship.sh"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Starship configuration failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
elif [ "$i" = "check" ]; then
|
||||||
|
echo "chcking uninstalled software..."
|
||||||
|
zsh "$current_dir/check.sh"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Check failed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "Run \"exec zsh\" to apply changes."
|
||||||
|
# exec zsh
|
Reference in New Issue
Block a user