Repository: ChesterYue/ohmyzsh-theme-passion
Branch: main
Commit: 7f06398c0a3c
Files: 6
Total size: 18.9 KB
Directory structure:
gitextract_ket5bkj2/
├── LICENSE
├── README.md
├── demo/
│ └── README.md
├── image/
│ └── image.sketch
├── passion.zsh-theme
└── passsion.itermcolors
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2020 ChesterYue
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.
================================================
FILE: README.md
================================================
# ohmyzsh-theme-passion
## Introduction
An oh-my-zsh theme;

### Feature
* real time prompt;
* command running time cost prompt;
* command running error hint;
* git status prompt;
## Usage
### Basic Zsh Theme
#### Install
1. clone repo: ```git clone https://github.com/ChesterYue/ohmyzsh-theme-passion```;
2. copy theme: ```cp ./ohmyzsh-theme-passion/passion.zsh-theme ~/.oh-my-zsh/themes/passion.zsh-theme```;
3. modify rc: open ```~/.zshrc``` find ```ZSH_THEME``` edit to ```ZSH_THEME="passion"```;
4. execute rc: ```source ~/.zshrc```;
* see also: [Overriding and adding themes](https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes);
#### Trouble Shooting
##### macOS, command not found: gdate
* passion.zsh-theme depends on cmd ```gdate``` to get current time in milliseconds. get ```gdate``` on macOS by running ```brew install coreutils``` then ```source ~/.zshrc```;
* see also: [#12](https://github.com/ChesterYue/ohmyzsh-theme-passion/issues/12);
##### Linux, command not found: bc
* passion.zsh-theme depends on cmd ```bc``` to calculate the command running time cost. [get bc on Linux](https://www.tecmint.com/bc-command-examples/#:~:text=If%20you%20don%E2%80%99t%20have%20bc%20on%20your%20system%2C,command%20prompt%20and%20simply%20start%20calculating%20your%20expressions.) then ```source ~/.zshrc```;
* see also: [#13](https://github.com/ChesterYue/ohmyzsh-theme-passion/issues/13);
##### Centos 7, shell exit
* may caused by [set timer to zsh prompt](https://github.com/ChesterYue/ohmyzsh-theme-passion/blob/8f71c43c2df91810249ab00ff40fc4ca63207467/passion.zsh-theme#L197-L208);
* see also: [#4](https://github.com/ChesterYue/ohmyzsh-theme-passion/issues/4);
Extra Preferences
#### Zsh Plugins
1. [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions);
2. [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting);
#### iTerm2 Preferences
##### Color
* iTerm2: settings -> Profiles -> Colors -> Color Presets -> import ```./passion.itermcolors``` 
* alternate terminal: try [Alternate terminal installation and configuration](https://iterm2colorschemes.com/);
##### Status Bar
* iTerm2: settings -> Appearance && settings -> Profiles -> Session -> Configure Status Bar  
##### Font
* install [JetBrains Mono](https://www.jetbrains.com/lp/mono/);
* iTerm2: settings -> Appearance && settings -> Profiles -> Text -> Font 
================================================
FILE: demo/README.md
================================================
# demo
## warning
make sure image refed by [External-themes](https://github.com/ohmyzsh/ohmyzsh/wiki/External-themes) exist;
## iTerm title
Settings - Profiles - Window - Custom tab title - ohmyzsh-theme-passion
## cmd
``` shell
# mkdir demo; cd demo; mkdir demo-git; cd demo-git; git init;
# git config --local user.name / user.email ...
# cd ..
echo real time prompt
echo command running time cost prompt
test command running error hint
cd demo-git
echo git status prompt
touch test.txt
git st
git add -A
git ci -m "test"
# enter twice
```
================================================
FILE: passion.zsh-theme
================================================
# gdate for macOS
# REF: https://apple.stackexchange.com/questions/135742/time-in-milliseconds-since-epoch-in-the-terminal
if [[ "$OSTYPE" == "darwin"* ]]; then
{
gdate
} || {
echo "\n$fg_bold[yellow]passion.zsh-theme depends on cmd [gdate] to get current time in milliseconds$reset_color"
echo "$fg_bold[yellow][gdate] is not installed by default in macOS$reset_color"
echo "$fg_bold[yellow]to get [gdate] by running:$reset_color"
echo "$fg_bold[green]brew install coreutils;$reset_color";
echo "$fg_bold[yellow]\nREF: https://github.com/ChesterYue/ohmyzsh-theme-passion#macos\n$reset_color"
}
fi
# time
function real_time() {
local color="%{$fg_no_bold[cyan]%}"; # color in PROMPT need format in %{XXX%} which is not same with echo
local time="[$(date +%H:%M:%S)]";
local color_reset="%{$reset_color%}";
echo "${color}${time}${color_reset}";
}
# login_info
function login_info() {
local color="%{$fg_no_bold[cyan]%}"; # color in PROMPT need format in %{XXX%} which is not same with echo
local ip
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# Linux
ip="$(ifconfig | grep ^eth1 -A 1 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)";
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
ip="$(ifconfig | grep ^en1 -A 4 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)";
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
elif [[ "$OSTYPE" == "freebsd"* ]]; then
# ...
else
# Unknown.
fi
local color_reset="%{$reset_color%}";
echo "${color}[%n@${ip}]${color_reset}";
}
# directory
function directory() {
local color="%{$fg_no_bold[cyan]%}";
# REF: https://stackoverflow.com/questions/25944006/bash-current-working-directory-with-replacing-path-to-home-folder
local directory="${PWD/#$HOME/~}";
local color_reset="%{$reset_color%}";
echo "${color}[${directory}]${color_reset}";
}
# git
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_no_bold[cyan]%}[";
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} ";
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg_no_bold[red]%}✖%{$fg_no_bold[cyan]%}]";
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_no_bold[cyan]%}]";
function update_git_status() {
GIT_STATUS=$(_omz_git_prompt_info);
}
function git_status() {
echo "${GIT_STATUS}"
}
# command
function update_command_status() {
local arrow="";
local color_reset="%{$reset_color%}";
local reset_font="%{$fg_no_bold[white]%}";
COMMAND_RESULT=$1;
export COMMAND_RESULT=$COMMAND_RESULT
if $COMMAND_RESULT;
then
arrow="%{$fg_bold[red]%}❱%{$fg_bold[yellow]%}❱%{$fg_bold[green]%}❱";
else
arrow="%{$fg_bold[red]%}❱❱❱";
fi
COMMAND_STATUS="${arrow}${reset_font}${color_reset}";
}
update_command_status true;
function command_status() {
echo "${COMMAND_STATUS}"
}
# output command execute after
output_command_execute_after() {
if [ "$COMMAND_TIME_BEGIN" = "-20200325" ] || [ "$COMMAND_TIME_BEGIN" = "" ];
then
return 1;
fi
# cmd
local cmd="$(fc -ln -1)";
local color_cmd="";
if $1;
then
color_cmd="$fg_no_bold[green]";
else
color_cmd="$fg_bold[red]";
fi
local color_reset="$reset_color";
cmd="${color_cmd}${cmd}${color_reset}"
# time
local time="[$(date +%H:%M:%S)]"
local color_time="$fg_no_bold[cyan]";
time="${color_time}${time}${color_reset}";
# cost
local time_end="$(current_time_millis)";
local cost=$(bc -l <<<"${time_end}-${COMMAND_TIME_BEGIN}");
COMMAND_TIME_BEGIN="-20200325"
local length_cost=${#cost};
if [ "$length_cost" = "4" ];
then
cost="0${cost}"
fi
cost="[cost ${cost}s]"
local color_cost="$fg_no_bold[cyan]";
cost="${color_cost}${cost}${color_reset}";
echo -e "${time} ${cost} ${cmd}";
echo -e "";
}
# command execute before
# REF: http://zsh.sourceforge.net/Doc/Release/Functions.html
preexec() { # cspell:disable-line
COMMAND_TIME_BEGIN="$(current_time_millis)";
}
current_time_millis() {
local time_millis;
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# Linux
time_millis="$(date +%s.%3N)";
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
time_millis="$(gdate +%s.%3N)";
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
elif [[ "$OSTYPE" == "freebsd"* ]]; then
# ...
else
# Unknown.
fi
echo $time_millis;
}
# command execute after
# REF: http://zsh.sourceforge.net/Doc/Release/Functions.html
precmd() { # cspell:disable-line
# last_cmd
local last_cmd_return_code=$?;
local last_cmd_result=true;
if [ "$last_cmd_return_code" = "0" ];
then
last_cmd_result=true;
else
last_cmd_result=false;
fi
# update_git_status
update_git_status;
# update_command_status
update_command_status $last_cmd_result;
# output command execute after
output_command_execute_after $last_cmd_result;
}
# set option
setopt PROMPT_SUBST; # cspell:disable-line
# timer
#REF: https://stackoverflow.com/questions/26526175/zsh-menu-completion-causes-problems-after-zle-reset-prompt
TMOUT=1;
TRAPALRM() { # cspell:disable-line
# $(git_prompt_info) cost too much time which will raise stutters when inputting. so we need to disable it in this occurrence.
# if [ "$WIDGET" != "expand-or-complete" ] && [ "$WIDGET" != "self-insert" ] && [ "$WIDGET" != "backward-delete-char" ]; then
# black list will not enum it completely. even some pipe broken will appear.
# so we just put a white list here.
if [ "$WIDGET" = "" ] || [ "$WIDGET" = "accept-line" ] ; then
zle reset-prompt;
fi
}
# prompt
# PROMPT='$(real_time) $(login_info) $(directory) $(git_status)$(command_status) ';
PROMPT='$(real_time) $(directory) $(git_status)$(command_status) ';
================================================
FILE: passsion.itermcolors
================================================
Ansi 0 Color
Alpha Component
1
Blue Component
0.0
Color Space
sRGB
Green Component
0.0
Red Component
0.0
Ansi 1 Color
Alpha Component
1
Blue Component
0.44705623388290405
Color Space
sRGB
Green Component
0.43135684728622437
Red Component
0.99215370416641235
Ansi 10 Color
Alpha Component
1
Blue Component
0.66666203737258911
Color Space
sRGB
Green Component
0.77253597974777222
Red Component
0.23532116413116455
Ansi 11 Color
Alpha Component
1
Blue Component
0.403959721326828
Color Space
sRGB
Green Component
0.98755413293838501
Red Component
0.99950617551803589
Ansi 12 Color
Alpha Component
1
Blue Component
0.97254163026809692
Color Space
sRGB
Green Component
0.68626147508621216
Red Component
0.41177588701248169
Ansi 13 Color
Alpha Component
1
Blue Component
0.66274034976959229
Color Space
sRGB
Green Component
0.43920052051544189
Red Component
0.9333309531211853
Ansi 14 Color
Alpha Component
1
Blue Component
0.78430771827697754
Color Space
sRGB
Green Component
0.55293065309524536
Red Component
0.27844303846359253
Ansi 15 Color
Alpha Component
1
Blue Component
0.99999994039535522
Color Space
sRGB
Green Component
0.99999994039535522
Red Component
1
Ansi 2 Color
Alpha Component
1
Blue Component
0.60783892869949341
Color Space
sRGB
Green Component
0.73332113027572632
Red Component
0.11377807706594467
Ansi 3 Color
Alpha Component
1
Blue Component
0.20784869790077209
Color Space
sRGB
Green Component
0.94115859270095825
Red Component
0.99608057737350464
Ansi 4 Color
Alpha Component
1
Blue Component
0.97254163026809692
Color Space
sRGB
Green Component
0.68626147508621216
Red Component
0.41177588701248169
Ansi 5 Color
Alpha Component
1
Blue Component
0.65097540616989136
Color Space
sRGB
Green Component
0.39606726169586182
Red Component
0.65097981691360474
Ansi 6 Color
Alpha Component
1
Blue Component
0.90196079015731812
Color Space
sRGB
Green Component
0.67843139171600342
Red Component
0.19607843458652496
Ansi 7 Color
Alpha Component
1
Blue Component
0.78104287385940552
Color Space
sRGB
Green Component
0.78104287385940552
Red Component
0.78104299306869507
Ansi 8 Color
Alpha Component
1
Blue Component
0.40781933069229126
Color Space
sRGB
Green Component
0.40781933069229126
Red Component
0.40781933069229126
Ansi 9 Color
Alpha Component
1
Blue Component
0.44313725829124451
Color Space
sRGB
Green Component
0.42745098471641541
Red Component
0.99215686321258545
Background Color
Alpha Component
1
Blue Component
0.12156862765550613
Color Space
sRGB
Green Component
0.11764705926179886
Red Component
0.11372549086809158
Badge Color
Alpha Component
0.5
Blue Component
0.0
Color Space
sRGB
Green Component
0.1491314172744751
Red Component
1
Bold Color
Alpha Component
1
Blue Component
0.99999994039535522
Color Space
sRGB
Green Component
0.99999994039535522
Red Component
1
Cursor Color
Alpha Component
1
Blue Component
0.78104287385940552
Color Space
sRGB
Green Component
0.78104287385940552
Red Component
0.78104299306869507
Cursor Guide Color
Alpha Component
0.25
Blue Component
1
Color Space
sRGB
Green Component
0.9268307089805603
Red Component
0.70213186740875244
Cursor Text Color
Alpha Component
1
Blue Component
0.99999994039535522
Color Space
sRGB
Green Component
0.99999994039535522
Red Component
1
Foreground Color
Alpha Component
1
Blue Component
0.61176472902297974
Color Space
sRGB
Green Component
0.61176472902297974
Red Component
0.61176472902297974
Link Color
Alpha Component
1
Blue Component
0.73423302173614502
Color Space
sRGB
Green Component
0.35916060209274292
Red Component
0.0
Selected Text Color
Alpha Component
1
Blue Component
0.0
Color Space
sRGB
Green Component
0.0
Red Component
0.0
Selection Color
Alpha Component
1
Blue Component
1
Color Space
sRGB
Green Component
0.86968445777893066
Red Component
0.75813823938369751