Skip to content

Instantly share code, notes, and snippets.

@vraravam
Last active April 27, 2024 09:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vraravam/9c8d9f335159f90c3fff890bcf3856d6 to your computer and use it in GitHub Desktop.
Save vraravam/9c8d9f335159f90c3fff890bcf3856d6 to your computer and use it in GitHub Desktop.
This is a companion script for the `~/.zshrc` file
#!/usr/bin/env zsh
# vim:syntax=zsh
# vim:filetype=zsh
# file location: ${HOME}/.zshrc.custom
# Note: This file depends on the ${HOME}/.zshrc that is also shared for some shell functions
load_file_if_exists "${HOME}/.aliases"
# Homebrew (path has been setup in ${HOME}/.zprofile)
export MANPATH="${HOMEBREW_PREFIX}/share/man${MANPATH+:$MANPATH}"
export INFOPATH="${HOMEBREW_PREFIX}/share/info${INFOPATH+:$INFOPATH}"
export HOMEBREW_NO_ANALYTICS=1
export HOMEBREW_CLEANUP_MAX_AGE_DAYS=3
export HOMEBREW_CLEANUP_PERIODIC_FULL_DAYS=3
export HOMEBREW_BAT=1
export HOMEBREW_VERBOSE_USING_DOTS=1
export HOMEBREW_BUNDLE_FILE=${HOME}/Brewfile
# Erlang history in iex
export ERL_AFLAGS="-kernel shell_history enabled -kernel shell_history_file_bytes 1024000"
if [[ "${OSTYPE}" =~ "darwin" ]]; then
# setopt glob_dots # no special treatment for file names with a leading dot
# # setopt no_auto_menu # require an extra TAB press to open the completion menu
# setopt auto_menu # automatically use menu completion
# setopt list_beep
# # setopt correct_all # autocorrect commands
# setopt always_to_end # move cursor to end if word had one match
setopt append_history
setopt share_history # share history between different instances of the shell
setopt inc_append_history # append command to history file immediately after execution
setopt hist_ignore_all_dups # do not put duplicated command into history list
setopt hist_ignore_dups
setopt hist_allow_clobber
setopt hist_reduce_blanks # remove unnecessary blanks
setopt hist_save_no_dups # do not save duplicated command
setopt auto_cd # cd into directory if the name is not an alias or function, but matches a directory
setopt auto_pushd # Make cd push the old directory onto the directory stack.
setopt pushd_silent # Do not print the directory stack after pushd or popd.
setopt pushd_ignore_dups # Don’t push multiple copies of the same directo
setopt beep
setopt extended_glob
setopt auto_list # Automatically list choices on an ambiguous completion.
setopt list_ambiguous
setopt list_types # If the file being listed is a directory, show a trailing slash
# console colors
autoload -U colors && colors
# Use modern completion system
mkdir -p ${XDG_CACHE_HOME}
autoload -Uz compinit && compinit -d ${XDG_CACHE_HOME}/zcompdump-${ZSH_VERSION}
# colorize completion
# zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=$color[cyan]=$color[red]"
# zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
# prevent CVS and SVN from being completed
zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'
# ignore completion functions
zstyle ':completion:*:functions' ignored-patterns '_*'
# ignore what's already selected on line
zstyle ':completion:*:(rm|kill|diff):*' ignore-line yes
# hosts completion for some commands
#local knownhosts
#knownhosts=( ${${${${(f)"$(<${HOME}/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
#zstyle ':completion:*:(ssh|scp|sftp):*' hosts $knownhosts
compctl -k hosts ftp lftp ncftp ssh w3m lynx links elinks nc telnet rlogin host
compctl -k hosts -P '@' finger
# manpage completion
man_glob () {
local a
read -cA a
if [[ $a[2] = -s ]]; then
reply=( ${^manpath}/man$a[3]/$1*$2(N:t:r) )
else
reply=( ${^manpath}/man*/$1*$2(N:t:r) )
fi
}
compctl -K man_glob -x 'C[-1,-P]' -m - 'R[-*l*,;]' -g '*.(man|[0-9nlpo](|[a-z]))' + -g '*(-/)' -- man
# fuzzy matching
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric
# completion cache
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ${XDG_CACHE_HOME}/zsh
# remove trailing slash in directory names, useful for ln
zstyle ':completion:*' squeeze-slashes true
# docker completion
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes
# typeset -U fpath
autoload -U _git
# Turn on autocomplete predictions
autoload -U incremental-complete-word predict-on
zle -N incremental-complete-word
zle -N predict-on
zle -N predict-off
bindkey '^Xi' incremental-complete-word
bindkey '^Xp' predict-on
bindkey '^X^P' predict-off
fi
# defines word-boundaries: ensures that deleting word on /path/to/file deletes only 'file' and not the directory, this removes the '/' from $WORDCHARS
export WORDCHARS="${WORDCHARS:s#/#}"
export WORDCHARS="${WORDCHARS:s#.#}"
# Rspec and cucumber
export CUCUMBER_COLORS="pending_param=magenta:failed_param=magenta:passed_param=magenta:skipped_param=magenta"
export RSPEC="true"
### Fix slowness of pastes with zsh-syntax-highlighting.zsh
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert ${OLD_SELF_INSERT}
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
### Fix slowness of pastes
# If brew exists, do the following
command_exists brew
if [ $? -eq 0 ]; then
load_file_if_exists "${HOMEBREW_PREFIX}/opt/git-extras/share/git-extras/git-extras-completion.zsh"
# curl - override default and use from homebrew installation
CURL_DIR=${HOMEBREW_PREFIX}/opt/curl
[ -d ${CURL_DIR} ] && export PATH="${CURL_DIR}/bin:${PATH+:$PATH}"
# Sqlite3 - override default and use from homebrew installation
SQLITE_DIR=${HOMEBREW_PREFIX}/opt/sqlite
if [ -d ${SQLITE_DIR} ]; then
export PATH="${SQLITE_DIR}/bin:${PATH+:$PATH}"
# For compilers to find sqlite you may need to set:
export LDFLAGS="-L${SQLITE_DIR}/lib${LDFLAGS+ $LDFLAGS}"
export CPPFLAGS="-I${SQLITE_DIR}/include${CPPFLAGS+ $CPPFLAGS}"
# For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="${SQLITE_DIR}/lib/pkgconfig${PKG_CONFIG_PATH+:$PKG_CONFIG_PATH}"
fi
# zlib - required for installing python via mise
ZLIB_DIR=${HOMEBREW_PREFIX}/opt/zlib
if [ -d ${ZLIB_DIR} ]; then
export LDFLAGS="-L${ZLIB_DIR}/lib${LDFLAGS+ $LDFLAGS}"
export CPPFLAGS="-I${ZLIB_DIR}/include${CPPFLAGS+ $CPPFLAGS}"
fi
# Note: The following lines have been added while trying to fix the ruby 3.0.0 installation on M1 MBP
OPENSSL_DIR=${HOMEBREW_PREFIX}/opt/openssl@3
if [ -d ${OPENSSL_DIR} ]; then
export PATH="${OPENSSL_DIR}/bin:${PATH+:$PATH}"
# For compilers to find openssl you may need to set:
export LDFLAGS="-L${OPENSSL_DIR}/lib${LDFLAGS+ $LDFLAGS}"
export CPPFLAGS="-I${OPENSSL_DIR}/include${CPPFLAGS+ $CPPFLAGS}"
# For pkg-config to find openssl you may need to set:
export PKG_CONFIG_PATH="${OPENSSL_DIR}/lib/pkgconfig${PKG_CONFIG_PATH+:$PKG_CONFIG_PATH}"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=${OPENSSL_DIR}"
fi
fi
# Load mise path changes
# eval "$(mise activate zsh)"
command_exists mise && _evalcache mise activate zsh
# load devbox completion config
# load_file_if_exists ${HOME}/.config/devbox/lib/use_devbox.sh
# Add the custom scripts folder to the PATH if its available
[ -d ${PERSONAL_CONFIGS_DIR} ] && export PATH="${PATH+:$PATH}:${PERSONAL_CONFIGS_DIR}"
# Make VSCodium use the VS Code marketplace
command_exists codium
if [ $? -eq 0 ]; then
export VSCODE_GALLERY_SERVICE_URL='https://marketplace.visualstudio.com/_apis/public/gallery'
export VSCODE_GALLERY_CACHE_URL='https://vscode.blob.core.windows.net/gallery/index'
export VSCODE_GALLERY_ITEM_URL='https://marketplace.visualstudio.com/items'
export VSCODE_GALLERY_CONTROL_URL=''
export VSCODE_GALLERY_RECOMMENDATIONS_URL=''
fi
# fzy
load_file_if_exists "${HOME}/.fzy-key-bindings.zsh"
# iTerm2 shell integrations
load_file_if_exists "${HOME}/.iterm2_shell_integration.zsh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment