Last active
February 3, 2023 02:20
-
-
Save freemo/6a206087b4380fed93cfc05e366c799b to your computer and use it in GitHub Desktop.
Custom ZSH Prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then | |
source "${ZDOTDIR:-$HOME}/.zprofile" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then | |
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" | |
fi | |
zstyle ':completion:*' completer _complete _ignored | |
zstyle :compinstall filename '/home/freemo/.zshrc' | |
autoload -Uz compinit | |
compinit | |
# End of lines added by compinstall | |
# Lines configured by zsh-newuser-install | |
HISTFILE=~/.histfile | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
unsetopt autocd | |
bindkey -e | |
# End of lines configured by zsh-newuser-install | |
setopt promptsubst | |
setopt prompt_subst | |
autoload -Uz promptinit | |
promptinit | |
prompt freemo | |
###-tns-completion-start-### | |
if [ -f /Users/freemo/.tnsrc ]; then | |
source /Users/freemo/.tnsrc | |
fi | |
###-tns-completion-end-### | |
source ~/.profile | |
export PATH=”$HOME/anaconda3/bin:$HOME/.local/bin:$PATH” |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First you will likely want iterm2, but this is optional. https://www.iterm2.com | |
Install xzsh on OSX: http://sourabhbajaj.com/mac-setup/iTerm/zsh.html | |
once you have zsh installed then run a zsh terminal and inside zsh install oh-my-zsh on top of that: http://ohmyz.sh. The command for this is as follows: | |
```sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"``` | |
Now go to the "prompt_freemo_setup" file and follow the instructions int he comments there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" | |
#place this at /usr/share/zsh/functions/Prompts/prompt_freemo_setup | |
# or at ~/.zprezto/modules/prompt/functions/prompt_freemo_setup | |
# must add the following line to .zshrc: setopt prompt_subst | |
prompt_freemo_help () { | |
cat <<'EOF' | |
prompt freemo [<color1> [<color2> [<color3> [<color4> [<color5>]]]]] | |
defaults are red, cyan, green, yellow, and white, respectively. | |
EOF | |
} | |
prompt_freemo_setup () { | |
local -a pcc | |
local -A pc | |
local p_date p_tty p_plat p_ver p_userpwd p_apm p_shlvlhist p_rc p_end p_win | |
autoload -Uz vcs_info | |
pcc[1]=${1:-${${SSH_CLIENT+'yellow'}:-'red'}} | |
pcc[2]=${2:-'cyan'} | |
pcc[3]=${3:-'green'} | |
pcc[4]=${4:-'yellow'} | |
pcc[5]=${5:-'white'} | |
pc['\[']="%F{$pcc[1]}[" | |
pc['\]']="%F{$pcc[1]}]" | |
pc['<']="%F{$pcc[1]}<" | |
pc['>']="%F{$pcc[1]}>" | |
pc['\(']="%F{$pcc[1]}(" | |
pc['\)']="%F{$pcc[1]})" | |
zstyle ':vcs_info:*' actionformats "%F{red}(%F{green}%s%F{red}:%F{yellow}%r%F{red})-[%F{cyan}%b%F{red}|%F{cyan}%a%F{red}]-[%F{cyan}%u%c%F{red}]%f %m" | |
zstyle ':vcs_info:*' formats "%F{red}(%F{green}%s%F{red}:%F{yellow}%r%F{red})-[%F{cyan}%b%F{red}]-[%F{cyan}%u%c%F{red}]%f %m" | |
zstyle ':vcs_info:*' check-for-changes true | |
zstyle ':vcs_info:*' enable cvs svn git hg bzr cdv darcs fossil mtn p4 svk tla | |
p_date="$pc['\[']%F{$pcc[2]}%D{%a %m/%d/%y %R %Z}$pc['\]']" | |
# p_plat="$pc['\[']%F{$pcc[2]}${MACHTYPE}/${OSTYPE}/$(uname -r)$pc['\]']" | |
p_plat="$pc['\[']%F{$pcc[2]}$(uname -r)$pc['\]']" | |
p_job="$pc['\[']%F{$pcc[5]}%F{$pcc[2]}%j%F{$pcc[5]} jobs$pc['\]']" | |
# p_ver="$pc['\[']%F{$pcc[5]}${ZSH_VERSION}$pc['\]']" | |
p_load="$pc['\[']%F{$pcc[5]}load%F{$pcc[1]}:%F{$pcc[2]}%2v%f$pc['\]']" | |
p_mem="$pc['\[']%F{$pcc[5]}Memory%F{$pcc[1]}:%F{$pcc[2]}%3v%%%f$pc['\]']" | |
p_tty="$pc['\[']%F{$pcc[3]}%y$pc['\]']" | |
[[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']" | |
p_userpwd="$pc['<']%F{$pcc[3]}%n@%m$p_win$p_tty%F{$pcc[1]}:%F{$pcc[4]}%~$pc['>']" | |
p_vcs='${vcs_info_msg_0_}' | |
p_shlvlhist="%fzsh%(2L./$SHLVL.) %B%h%b " | |
p_rc="%(?..$pc['\[']%K{red}%F{$pcc[5]}error %F{$pcc[2]}%?%1v%k$pc['\]'] )" | |
p_end="%f%B%(!.%K{red}#%k.%%)%b " | |
zle_highlight[(r)default:*]=default:$pcc[2] | |
prompt=" | |
$p_job$p_load$p_mem$p_plat$p_date | |
$p_userpwd $p_vcs | |
$p_shlvlhist$p_rc$p_end" | |
PS2='%(4_.\.)%3_> %E' | |
add-zsh-hook precmd prompt_freemo_precmd | |
} | |
prompt_freemo_precmd () { | |
setopt noxtrace noksharrays localoptions | |
local exitstatus=$? | |
local git_dir git_ref | |
psvar=() | |
[[ $exitstatus -ge 128 ]] && psvar[1]=" $signals[$exitstatus-127]" || | |
psvar[1]="" | |
[[ -o interactive ]] && jobs -l | |
vcs_info | |
psvar[2]=`sysctl -n vm.loadavg | sed 's/{ \([0-9.]* [0-9.]* [0-9.]*\) }/\1/'` | |
memtotal=`sysctl -a | grep hw.memsize | awk '{print $2}'` | |
memused=`vm_stat | grep "wired down" | awk '{print $4}' | sed 's/\([0-9]*\)\.*/\1/'` | |
(( memused = $memused * 4096 )) | |
declare -i memfree | |
(( memfree = $memtotal - $memused )) | |
declare -i memperc | |
(( memperc = ( $memfree * 100 ) / $memtotal )) | |
psvar[3]="$memperc" | |
} | |
prompt_freemo_setup "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment