# # ~/.zshrc # ANTIGEN_CACHE=$HOME/.antigen-cache.zsh typeset -a ANTIGEN_CHECK_FILES=($HOME/.zshrc) source ~/.antigen.zsh antigen use oh-my-zsh antigen bundle mkcd antigen bundle zsh-users/zsh-syntax-highlighting antigen bundle zsh-users/zsh-autosuggestions antigen bundle zsh-users/zsh-completions antigen apply bindkey "[1;5D" backward-word bindkey "[1;5C" forward-word bindkey '^H' backward-kill-word autoload -Uz compinit; compinit hostname_color() { case $(hostname) in blue*) echo "%{\e[01;34m%}" ;; green*) echo "%{\e[01;32m%}" ;; pink*) echo "%{\e[01;35m%}" ;; red*) echo "%{\e[01;31m%}" ;; *) echo "%{\e[01;37m%}" ;; esac } parse_git_branch() { if git rev-parse --is-inside-work-tree 2> /dev/null | grep -q 'true' ; then echo -ne " " RES=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) if [[ $(git status --short | wc -l) -gt 0 ]]; then RES+="+"$(git status --short | wc -l) fi echo $RES fi } status_color() { if [[ ${EUID} == 0 ]] ; then echo "%{\e[01;31m%}" else if [[ $(whoami) == "sheychen" ]] ; then if [[ $(sudo -n uptime 2>&1|grep "load"|wc -l) -gt 0 ]] ; then echo "%{\e[01;33m%}" else echo "%{\e[01;32m%}" fi else echo "%{\e[01;35m%}" fi fi } parse_user() { if [[ ${EUID} != 0 ]] ; then case "$(whoami)" in "sheychen") echo "@" ;; "shu") ;; *) echo "$(whoami)@" ;; esac fi } function spwd { echo $PWD | sed "s:${HOME}:~:" | sed "s:/\(.\)[^/]*:/\1:g" | sed "s:/[^/]*$:/$(basename "$PWD"):" } setopt promptsubst PROMPT=$'$(status_color)[$(parse_user)$(hostname_color)%M%{\e[01;37m%} $(spwd)$(parse_git_branch)$(status_color)]%{\e[0m%} ' unset HISTFILE cl() { local dir="$1" local dir="${dir:=$HOME}" if [[ -d "$dir" ]]; then cd "$dir" >/dev/null; ls else echo "cl: $dir: Directory not found" fi } ssh-load() { local key="$HOME/.ssh/keys/${1}_ed25519" if [ -f $key ]; then ssh-add -k $key else echo "$key not found" fi } mkcd () { case "$1" in */..|*/../) cd -- "$1";; # that doesn't make any sense unless the directory already exists /*/../*) (cd "${1%/../*}/.." && mkdir -p "./${1##*/../}") && cd -- "$1";; /*) mkdir -p "$1" && cd "$1";; */../*) (cd "./${1%/../*}/.." && mkdir -p "./${1##*/../}") && cd "./$1";; ../*) (cd .. && mkdir -p "${1#.}") && cd "$1";; *) mkdir -p "./$1" && cd "./$1";; esac } [[ -f ~/.shrc ]] && source ~/.shrc