Skip to content

Instantly share code, notes, and snippets.

@davidbgk davidbgk/.zshrc
Last active Jun 11, 2020

Embed
What would you like to do?
Configuration file for ZSH (macOS), current status
# to avoid Last login blah
# touch .hushlogin
# https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/
PROMPT='%(?.%F{green}√.%F{red}?%?)%f %B%F{235}%2~%f%b %# '
# case insensitive path-completion
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*'
# partial completion suggestions
zstyle ':completion:*' list-suffixes
zstyle ':completion:*' expand prefix suffix
# if you have errors related to that command
# https://stackoverflow.com/a/20303502
# cd /usr/local/share/
# sudo chmod -R 755 zsh
# sudo chown -R root:staff zsh
autoload -U compinit && compinit
# https://scriptingosx.com/2019/06/moving-to-zsh-part-3-shell-options/
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
SAVEHIST=5000
HISTSIZE=2000
setopt EXTENDED_HISTORY
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_FIND_NO_DUPS
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY
# git-related stuff
autoload -Uz vcs_info
precmd_vcs_info() { vcs_info }
precmd_functions+=( precmd_vcs_info )
setopt prompt_subst
RPROMPT='$vcs_info_msg_0_'
zstyle ':vcs_info:git:*' formats '%F{240}(%b)%f'
zstyle ':vcs_info:*' enable git
# aliases
alias -g ll='ls -al'
alias -g subl='open -a "Sublime Text"'
alias server='python3 -m http.server'
alias venv='python3 -m venv venv'
alias activate='source venv/bin/activate'
alias requirements='python3 -m pip install -r requirements.txt'
# python virtualenv auto de/activation
function cd() {
if [[ -d ./venv ]] ; then
deactivate
fi
builtin cd $1
if [[ -d ./venv ]] ; then
. ./venv/bin/activate
fi
}
# duration of a command
# https://github.com/popstas/zsh-command-time
_command_time_preexec() {
timer=${timer:-$SECONDS}
ZSH_COMMAND_TIME_MSG=${ZSH_COMMAND_TIME_MSG-"Durée: %s"}
ZSH_COMMAND_TIME_COLOR=${ZSH_COMMAND_TIME_COLOR-"237"}
export ZSH_COMMAND_TIME=""
}
_command_time_precmd() {
if [ $timer ]; then
timer_show=$(($SECONDS - $timer))
if [ -n "$TTY" ] && [ $timer_show -ge ${ZSH_COMMAND_TIME_MIN_SECONDS:-3} ]; then
export ZSH_COMMAND_TIME="$timer_show"
if [ ! -z ${ZSH_COMMAND_TIME_MSG} ]; then
zsh_command_time
fi
fi
unset timer
fi
}
zsh_command_time() {
if [ -n "$ZSH_COMMAND_TIME" ]; then
timer_show=$(printf '%dh:%02dm:%02ds\n' $(($ZSH_COMMAND_TIME/3600)) $(($ZSH_COMMAND_TIME%3600/60)) $(($ZSH_COMMAND_TIME%60)))
print -P "%F{$ZSH_COMMAND_TIME_COLOR}$(printf "${ZSH_COMMAND_TIME_MSG}\n" "$timer_show")%f"
fi
}
precmd_functions+=(_command_time_precmd)
preexec_functions+=(_command_time_preexec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.