first commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 gwbeip
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
21
README.md
Normal file
21
README.md
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# ZSH Polyjuice
|
||||||
|
|
||||||
|
[](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.
|
||||||
|
|
||||||
|
## The `Polyjuice` theme
|
||||||
|
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.
|
||||||
|
|
||||||
|
```
|
||||||
|
# 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
|
||||||
|
git clone https://github.com/gwbeip/zsh_polyjuice.git $HOME/.zsh_polyjuice
|
||||||
|
bash $HOME/.zsh_polyjuice/polyjuice.sh
|
||||||
|
```
|
18
install_rust.sh
Normal file
18
install_rust.sh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# 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
|
56
polyjuice.sh
Normal file
56
polyjuice.sh
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Configure ZSH
|
||||||
|
if [ ! -d $HOME/.oh-my-zsh ]; then
|
||||||
|
git clone https://github.com/ohmyzsh/ohmyzsh.git $HOME/.oh-my-zsh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-autosuggestions ]; then
|
||||||
|
git clone https://github.com/zsh-users/zsh-autosuggestions.git $HOME/.oh-my-zsh/plugins/zsh-autosuggestions
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting ]; then
|
||||||
|
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-autocomplete ]; then
|
||||||
|
git clone https://github.com/marlonrichert/zsh-autocomplete.git $HOME/.oh-my-zsh/plugins/zsh-autocomplete
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f $HOME/.zshrc ]; then
|
||||||
|
if [ ! -f $HOME/.zshrc.bkp ]; then
|
||||||
|
mv $HOME/.zshrc $HOME/.zshrc.bkp
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
cp $HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc
|
||||||
|
|
||||||
|
zsh_theme_line_num=$(grep -rn -m 1 ZSH_THEME= $HOME/.zshrc | cut -d ":" -f 1)
|
||||||
|
sed -i $zsh_theme_line_num"c"\ZSH_THEME=\"polyjuice\" $HOME/.zshrc
|
||||||
|
|
||||||
|
zsh_plugin_line_number=$(grep -rn -m 2 plugins=\(git\) $HOME/.zshrc | cut -d : -f 1)
|
||||||
|
sed -i "$zsh_plugin_line_number"c"\plugins=\(zsh-autosuggestions zsh-syntax-highlighting zsh-autocomplete\)" $HOME/.zshrc
|
||||||
|
|
||||||
|
if [ -f $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme ]; then
|
||||||
|
rm -rf $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme
|
||||||
|
fi
|
||||||
|
|
||||||
|
path_to_theme=$(realpath $0 | sed 's/\.sh/\.zsh-theme/')
|
||||||
|
ln -i -s $path_to_theme $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme
|
||||||
|
|
||||||
|
# Configure the software folder: $HOME/.software
|
||||||
|
if [ ! -d $HOME/.software ]; then
|
||||||
|
mkdir $HOME/.software
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f $HOME/.software/software_env.sh ]; then
|
||||||
|
touch $HOME/.software/software_env.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
# if [ ! -f $HOME/.zshenv ]; then
|
||||||
|
# touch $HOME/.zshenv
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# nl $HOME/.zshenv | grep \.software/software_env\.sh > /dev/null
|
||||||
|
# if [ ! $? == 0 ]; then
|
||||||
|
# echo ". $HOME/.software/software_env.sh" >> $HOME/.zshenv
|
||||||
|
# fi
|
122
polyjuice.zsh-theme
Normal file
122
polyjuice.zsh-theme
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
# 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
|
Reference in New Issue
Block a user