Skip to content

Instantly share code, notes, and snippets.

@lavish10
Created December 6, 2019 06:12
Show Gist options
  • Select an option

  • Save lavish10/24b9ab2b4dc30f4d57f857592c57aa99 to your computer and use it in GitHub Desktop.

Select an option

Save lavish10/24b9ab2b4dc30f4d57f857592c57aa99 to your computer and use it in GitHub Desktop.
Companion to ~/.zshrc
load_file_if_exists "$HOME/.aliases"
#setopt emacs
if [[ "$OSTYPE" = darwin* ]] ; then
setopt inc_append_history hist_ignore_all_dups hist_ignore_dups hist_allow_clobber hist_reduce_blanks share_history autocd beep extendedglob
fi
#setopt auto_list list_ambiguous
if [[ "$OSTYPE" = darwin* ]] ; then
setopt list_types
# directory options
setopt auto_cd
setopt auto_pushd
fi
export GREP_OPTIONS="-Hn --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}"
# console colors
if [[ "$OSTYPE" = darwin* ]] ; then
autoload -U colors && colors
# Use modern completion system
autoload -U compinit && compinit
# 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 ~/.zsh/cache
# remove trailing slash in directory names, useful for ln
zstyle ':completion:*' squeeze-slashes true
fi
# ensures that deleting word on /path/to/file deletes only 'file', this removes the '/' from $WORDCHARS
export WORDCHARS="${WORDCHARS:s#/#}"
export WORDCHARS="${WORDCHARS:s#.#}"
# Show current time on RHS for each cne of command
# local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
# PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
RPROMPT="[%D{%y/%m/%f}|%@]"
function reals () {
ls -la "$(print `which $1`)"
}
function capture {
sudo tcpdump -A -s 0 -i lo0 "(src and dst localhost) and ( tcp port `echo $1` ) and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)"
}
if [[ "$OSTYPE" = darwin* ]] ; then
#typeset -U fpath
autoload -U _git
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
# Turn on autocomplete predictions
#autoload predict-on
#predict-on
fi
# Rspec and cucumber
export CUCUMBER_COLORS="pending_param=magenta:failed_param=magenta:passed_param=magenta:skipped_param=magenta"
export RSPEC="true"
# Postgres
export PSQL_HOME="/Applications/Postgres.app/Contents/Versions/latest"
export PATH=$PSQL_HOME/bin:$PATH
# Sqlite3
export PATH="/usr/local/opt/sqlite/bin:$PATH"
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
# Android
# export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"
export ANDROID_HOME="/Users/vijay/Library/Android/sdk"
export PATH="$ANDROID_HOME/bin:$PATH"
# zlib - required for installing python via asdf
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
# fzf - bind 'ctrl+o' to open selected file in VS Code
export FZF_DEFAULT_OPTS="--preview 'bat --color always {}' --bind='ctrl-o:execute(code {})+abort'"
# asdf
export ASDF_DIR=$(brew --prefix asdf)
# export ASDF_DIR="$HOME/.asdf"
load_file_if_exists "$ASDF_DIR/asdf.sh"
load_file_if_exists "$HOME/.asdf/plugins/java/asdf-java-wrapper.zsh" # NOTE: it aliases 'asdf' command into the java language itself!
# Java using asdf - on top of the above script
asdf_update_java_home() {
local current
if current=$(\asdf current java); then
local version=$(echo $current | cut -d ' ' -f 1 | cut -d'(' -f 1)
export JAVA_HOME="$(\asdf where java $version)"
export PATH="$JAVA_HOME/bin:$PATH"
else
echo "No java version set. Type 'asdf list-all java' for all available versions."
fi
}
asdf_update_java_home
# dotnet development
export PATH="$PATH:$HOME/.dotnet/tools"
### 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment