Last active
December 25, 2023 06:41
-
-
Save rcarmo/80b94e2f8e6cd7d8e95739b1aa0d9fb7 to your computer and use it in GitHub Desktop.
My zsh configuration
This file contains 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
# ======= | |
# GLOBALS | |
# ======= | |
if [[ "$(uname)" == "Darwin" ]]; then | |
platform="Darwin" | |
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then | |
platform="Linux" | |
else | |
platform="POSIX" | |
fi | |
# =========================== | |
# LOCALE, TERMINAL AND COLORS | |
# =========================== | |
export LC_CTYPE=en_US.UTF-8 | |
export LANG=en_US.UTF-8 | |
autoload -Uz colors && colors | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color|*-256color) color_prompt=yes;; | |
esac | |
if [[ "$color_prompt" = yes ]]; then | |
case $platform in | |
"Darwin") | |
PS1="%{$fg_bold[cyan]%}%n@%m%{%f%}:%{$fg_bold[magenta]%}%~%{$reset_color%}%# " | |
;; | |
"Linux") | |
PS1="%{$fg_bold[green]%}%n@%m%{%f%}:%{$fg_bold[blue]%}%~%{$reset_color%}%# " | |
;; | |
esac | |
else | |
PS1="%n@%m:%~%# " | |
fi | |
unset color_prompt | |
# If this is an xterm set the title to user@host:dir | |
case $TERM in | |
xterm*|rxvt*) | |
precmd () {print -Pn "\e]0;%n@%m:%~%#\a"} | |
;; | |
*) | |
;; | |
esac | |
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
export LS_OPTIONS='--color=auto' | |
case $platform in | |
"Darwin") | |
export CLICOLOR=1 | |
export LSCOLORS="exgxfxdacxDaDaxbadacex" | |
export LS_COLORS="di=34;40:ln=36;40:so=35;40:pi=33;40:ex=32;40:bd=1;33;40:cd=1;33;40:su=0;41:sg=0;43:tw=0;42:ow=34;40:" | |
alias grep='grep --colour=auto' | |
alias fgrep='fgrep --colour=auto' | |
alias egrep='egrep --colour=auto' | |
;; | |
"Linux") | |
eval "$(dircolors -b)" | |
alias ls='ls --color' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
;; | |
esac | |
# ================= | |
# EDITING & HISTORY | |
# ================= | |
setopt histignorealldups sharehistory | |
# Use emacs keybindings even if our EDITOR is set to vi | |
bindkey -e | |
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history: | |
HISTSIZE=1000 | |
SAVEHIST=10000 | |
HISTFILE=~/.zsh_history | |
# ================= | |
# SHELL COMPLETION | |
# ================= | |
# Use modern completion system | |
autoload -Uz compinit && compinit -i # ignore permission differences in macOS/brew | |
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} | |
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} | |
zstyle ':completion:*' auto-description 'specify: %d' | |
zstyle ':completion:*' completer _expand _complete _correct _approximate | |
zstyle ':completion:*' format 'Completing %d' | |
zstyle ':completion:*' group-name '' | |
zstyle ':completion:*' menu select=2 | |
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s | |
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' | |
zstyle ':completion:*' menu select=long | |
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s | |
zstyle ':completion:*' use-compctl false | |
zstyle ':completion:*' verbose true | |
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' | |
case $platform in | |
"Darwin") | |
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,comm' | |
;; | |
"Linux") | |
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' | |
;; | |
esac | |
autoload -U +X bashcompinit && bashcompinit # Bash completion compatibility | |
# Azure CLI completion | |
# (you should have run activate-global-python-argcomplete --user first) | |
[ -e $HOME/.bash_completion.d/python-argcomplete.sh ] && source $HOME/.bash_completion.d/python-argcomplete.sh | |
[ $(type register-python-argcomplete > /dev/null 2>&1) ] && eval "$(register-python-argcomplete az)" | |
# ================= | |
# LANGUAGE RUNTIMES | |
# ================= | |
# Python | |
[ $(type pyenv > /dev/null 2>&1) ] && eval "$(pyenv init -)" | |
[ -e /usr/local/opt/pyenv/completions/pyenv.bash ] && source /usr/local/opt/pyenv/completions/pyenv.bash | |
# Golang | |
export GOPATH=$HOME/Developer/gocode | |
export PATH=$PATH:$GOPATH/bin | |
# NodeJS | |
NPM_PACKAGES="${HOME}/.npm-packages" | |
if [ -d $NPM_PACKAGES ]; then | |
# Make private binaries take precedence | |
export PATH=$NPM_PACKAGES/bin:$PATH | |
# Unset manpath so we can inherit from /etc/manpath via the `manpath` command | |
unset MANPATH # delete if you already modified MANPATH elsewhere in your config | |
export MANPATH="$NPM_PACKAGES/share/man:$(manpath)" | |
fi | |
export NODE_PATH=$NODE_PATH:/usr/local/lib/node | |
export PATH=$PATH:/usr/local/share/npm/bin | |
# ======= | |
# ALIASES | |
# ======= | |
export EDITOR=vim | |
if type nvim > /dev/null 2>&1; then | |
alias vi='nvim' | |
alias vim='nvim' | |
fi | |
# make less more friendly for non-text input files, see lesspipe(1) | |
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" | |
case $platform in | |
"Darwin") | |
alias brew="echo 'REMEMBER TO RUN HOMEBREW AS ADMIN'" | |
export PATH=$PATH:/Aplications/Xcode.app/Contents/Developer/usr/bin | |
alias code='open -a Visual\ Studio\ Code "$@"' | |
alias tt='open -a Textastic "$@"' | |
# Go from brew | |
export PATH=$PATH:/usr/local/opt/go/libexec/bin | |
# Clipboard | |
test -z "$(type -p putclip)" -a -n "$(type -p pbcopy)" && alias putclip=pbcopy | |
test -z "$(type -p getclip)" -a -n "$(type -p pbpaste)" && alias getclip=pbpaste | |
;; | |
"Linux") | |
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' | |
[ -x /usr/bin/keychain ] && eval `keychain --agents ssh --eval id_rsa --quiet -Q` | |
# Clipboard | |
if [ -n "$(type -p xclip)" ]; then | |
test -z "$(type -p putclip)" && alias putclip="$(type -p xclip) -sel clip -i" | |
test -z "$(type -p getclip)" && alias getclip="$(type -p xclip) -sel clip -o" | |
alias xclip='xclip -sel clip' | |
fi | |
if [ -c /dev/clipboard -a -w /dev/clipboard ]; then | |
test -z "$(type -p getclip)" && alias getclip="cat /dev/clipboard" | |
test -z "$(type -p putclip)" && alias putclip="cat > /dev/clipboard" | |
fi | |
;; | |
esac | |
unset platform | |
# ====== | |
# EXTRAS | |
# ====== | |
[ -e $HOME/Dropbox/Scripts/z.sh ] && source $HOME/Dropbox/Scripts/z.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment