Skip to content

Instantly share code, notes, and snippets.

@ebullient
Created February 4, 2022 13:13
Show Gist options
  • Select an option

  • Save ebullient/a480ccaf7bdb87aaaaa7dcaefa00fbeb to your computer and use it in GitHub Desktop.

Select an option

Save ebullient/a480ccaf7bdb87aaaaa7dcaefa00fbeb to your computer and use it in GitHub Desktop.
zsh-config-without-oh-my-zsh
# ZSH configuration without oh-my-zsh
I stuff everything into a .zsh directory to keep the dir tree slimmer, which means I have a `.zshenv` file that contains:
```
ZDOTDIR=~/.zsh
```
All of the files and settings below then live in the `~/.zsh` directory
The referenced git-prompt.sh file is from
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
# Execute code in the background to not affect the current session
{
# Compile zcompdump, if modified, to increase startup speed.
zcompdump="${ZDOTDIR:-$HOME}/.zcompdump"
if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then
zcompile "$zcompdump"
fi
} &!
zmodload zsh/zprof
ulimit -n 1024000
local ZSH_CONF=$HOME/.zsh # Define the place I store all my zsh config stuff
local ZSH_CACHE=$ZSH_CONF/cache # for storing files like history and zcompdump
# Load external config files and tools
# Set important shell variables
export EDITOR=vim # Set default editor
export WORDCHARS='' # This is the oh-my-zsh default, I think I'd like it to be a bit different
export PAGER=less # Set default pager
export LESS="-R" # Set the default options for less
export LANG="en_US.UTF-8"
# Misc
setopt ZLE # Enable the ZLE line editor, which is default behavior, but to be sure
declare -U path # prevent duplicate entries in path
#eval $(gdircolors $ZSH_CONF/dircolors) # Uses custom colors for LS, as outlined in dircolors
eval $(gdircolors) # Uses custom colors for LS, as outlined in dircolors
LESSHISTFILE="/dev/null" # Prevent the less hist file from being made, I don't want it
umask 002 # Default permissions for new files, subract from 777 to understand
#setopt AUTO_CD # Sends cd commands without the need for 'cd'
setopt AUTO_PUSHD # Make cd push the old directory onto the directory stack.
setopt PUSHD_IGNORE_DUPS # Don’t push multiple copies of the same directory onto the directory stack.
setopt COMBINING_CHARS # Assume that the terminal displays combining characters correctly.
setopt NO_BEEP # Disable beeps
#setopt MULTI_OS # Can pipe to mulitple outputs
#unsetopt NO_HUP # Kill all child processes when we exit, don't leave them running
setopt INTERACTIVE_COMMENTS # Allows comments in interactive shell.
#setopt RC_EXPAND_PARAM # Abc{$cool}efg where $cool is an array surrounds all array variables individually
#unsetopt FLOW_CONTROL # Ctrl+S and Ctrl+Q usually disable/enable tty input. This disables those inputs
setopt LONG_LIST_JOBS # List jobs in the long format by default. (I don't know what this does but it sounds good)
#setopt vi # Make the shell act like vi if i hit escape
# ZSH History
alias history='fc -fl 1'
HISTFILE=$ZSH_CACHE/history # Keep our home directory neat by keeping the histfile somewhere else
SAVEHIST=10000 # Big history
HISTSIZE=10000 # Big history
setopt EXTENDED_HISTORY # Include more information about when the command was executed, etc
setopt APPEND_HISTORY # Allow multiple terminal sessions to all append to one zsh command history
setopt HIST_EXPIRE_DUPS_FIRST # When duplicates are entered, get rid of the duplicates first when we hit $HISTSIZE
setopt HIST_IGNORE_DUPS # Do not write events to history that are duplicates of the immediately previous event
setopt HIST_IGNORE_ALL_DUPS # If a new command line being added to the history list duplicates an older one, the older command is removed from the list
setopt HIST_IGNORE_SPACE # Don't enter commands into history if they start with a space
setopt HIST_FIND_NO_DUPS # When searching history don't display results already cycled through twice
setopt HIST_SAVE_NO_DUPS # When writing out the history file, older commands that duplicate newer ones are omitted.
setopt HIST_VERIFY # makes history substitution commands a bit nicer. I don't fully understand
setopt SHARE_HISTORY # Shares history across multiple zsh sessions, in real time
setopt INC_APPEND_HISTORY # Add commands to history as they are typed, don't wait until shell exit
setopt HIST_REDUCE_BLANKS # Remove extra blanks from each command line being added to history
# ZSH Auto Completion
autoload -Uz compinit # Autoload auto completion
compinit
zstyle ':completion:*' menu select # Have the menu highlight as we cycle through options
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # Case-insensitive (uppercase from lowercase) completion
setopt COMPLETE_IN_WORD # the cursor stays in the word and completion is tried from both ends
setopt ALWAYS_TO_END # the cursor is moved to the end of the word if either a single match is inserted or menu completion is performed.
#setopt MENU_COMPLETE # When using auto-complete, put the first option on the line immediately
setopt COMPLETE_ALIASES # Turn on completion for aliases as well
#setopt LIST_ROWS_FIRST # Cycle through menus horizontally instead of vertically
# Key Bindings
bindkey "^K" kill-whole-line # [Ctrl-K] erase whole line
bindkey '^[[1;5C' forward-word # [Ctrl-RightArrow] - move forward one word
bindkey '^[[1;5D' backward-word # [Ctrl-LeftArrow] - move backward one word
bindkey '^?' backward-delete-char # [Backspace] - delete backward
bindkey "${terminfo[kdch1]}" delete-char # [Delete] - delete forward
bindkey "${terminfo[kpp]}" up-line-or-history # [PageUp] - Up a line of history
bindkey "${terminfo[knp]}" down-line-or-history # [PageDown] - Down a line of history
bindkey "^[[A" history-search-backward # start typing + [Up-Arrow] - fuzzy find history forward
bindkey "^[[B" history-search-forward # start typing + [Down-Arrow] - fuzzy find history backward
bindkey '\e[H' beginning-of-line # Note: this works on cygwin/mintty, may not work on other systems
bindkey '\e[F' end-of-line # Note: this works on cygwin/mintty, may not work on other systems
# set up grep
source $ZSH_CONF/grep.zsh
# set up prompt
source $ZSH_CONF/prompt.zsh
# Setup grep to be a bit more nice
# check if 'x' grep argument available
grep-flag-available() {
echo | grep $1 "" >/dev/null 2>&1
}
local GREP_OPTIONS=""
# color grep results
if grep-flag-available --color=auto; then
GREP_OPTIONS+=" --color=auto"
fi
# ignore VCS folders (if the necessary grep flags are available)
local VCS_FOLDERS="{.bzr,CVS,.git,.hg,.svn}"
local JS_FOLDERS="{bower_components,node_modules}"
local FILES="{swp,class,jar}"
if grep-flag-available --exclude-dir=.cvs; then
GREP_OPTIONS+=" --exclude=\*.$FILES --exclude-dir=$VCS_FOLDERS --exclude-dir=$JS_FOLDERS"
elif grep-flag-available --exclude=.cvs; then
GREP_OPTIONS+=" --exclude=\*.$FILES --exclude=$VCS_FOLDERS --exclude=$JS_FOLDERS"
fi
# export grep settings
alias grep="grep $GREP_OPTIONS"
# clean up
unfunction grep-flag-available
autoload -U colors && colors
source ~/bin/git-prompt.sh
setopt PROMPT_SUBST
GIT_PS1_SHOWCOLORHINTS=
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWSTASHSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="auto"
## Add some additional indicators so I know if I've tweaked env vars
## in that shell
function elh_env {
local exit=$?
local output=
if [[ $DOCKER_HOST == *"192.168"* ]]; then
output='minikube:'
fi
if [[ $DOCKER_HOST == *"podman"* ]]; then
output='podman:'
fi
if [[ $JAVA_HOME =~ 'graal' ]]; then
output="${output}graalvm:"
fi
echo $output
return $exit
}
function git_prompt_info() {
__git_ps1 "(%s) "
}
function set_my_prompt {
local color_prompt=
local blue=
local green=
local bold_green=
local magenta=
local reset=
local return_code=
if [ -x /usr/bin/tput ] && [[ `tput colors` != "0" ]]; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt="yes"
elif [ -x /ffp/bin/tput ] && [[ `tput colors` != "0" ]]; then
color_prompt="yes"
fi
if [[ "$color_prompt" == "yes" ]]; then
blue="%{${reset_color}%}%{$fg[blue]%}"
green="%{${reset_color}%}%{$fg[green]%}"
bold_green="%{${reset_color}%}%{$fg_bold[green]%}"
magenta="%{${reset_color}%}%{$fg[magenta]%}"
reset="%{${reset_color}%}"
return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
fi
export PS1="${blue}\$(elh_docker_env)${green}%m${blue}{${bold_green}%n${blue}} ${magenta}%2~${blue} \$(git_prompt_info)%#${reset} "
export RPS1="${RETURN_CODE}"
}
set_my_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment