mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
Zsh setup script and organization
This commit is contained in:
1
zsh/config/.zshenv
Normal file
1
zsh/config/.zshenv
Normal file
@@ -0,0 +1 @@
|
||||
export ZDOTDIR="$HOME/.config/zsh"
|
||||
176
zsh/config/.zshrc
Normal file
176
zsh/config/.zshrc
Normal file
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
# _
|
||||
# _______| |__ _ __ ___
|
||||
# |_ / __| '_ \| '__/ __|
|
||||
# / /\__ \ | | | | | (__
|
||||
# /___|___/_| |_|_| \___|
|
||||
#
|
||||
#
|
||||
#------------------------------ utilites ------------------------------
|
||||
|
||||
_source_if() { test -r "$1" && source "$1" || return 0 }
|
||||
|
||||
#------------------------------ exports ------------------------------
|
||||
export ZDOTDIR="$HOME/.config/zsh"
|
||||
export SHELL="$(which zsh)"
|
||||
export GITUSER="m-housh"
|
||||
export BUCKET="/Volumes/Bucket"
|
||||
export ARCHIVE="/Volumes/Archive"
|
||||
export REPOS="$BUCKET/Repos"
|
||||
export GHREPOS="$REPOS/github.com/$GITUSER"
|
||||
export LOCAL_REPOS="$REPOS/local"
|
||||
export DOCUMENTS="$HOME/Documents"
|
||||
export DOWNLOADS="$HOME/Downloads"
|
||||
export PDFS="$HOME/Library/Mobile Documents/com~apple~Preview/Documents"
|
||||
export SCREENSHOTS="$BUCKET/Pictures/Screenshots"
|
||||
export DOTFILES="$HOME/.dotfiles"
|
||||
export DESKTOP="$HOME/Desktop"
|
||||
export SCRIPTS="$HOME/.local/scripts"
|
||||
export WORK="$HOME/Library/Mobile Documents/com~apple~CloudDocs/Work"
|
||||
export TERM=xterm-256color
|
||||
export EDITOR=vi
|
||||
export VISUAL=vi
|
||||
export EDITOR_PREFIX=vi
|
||||
export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
|
||||
export VIMINIT='source $MYVIMRC'
|
||||
export MYVIMRC="$HOME/.vim/vimrc"
|
||||
|
||||
autoload -U up-line-or-beginning-search
|
||||
autoload -U down-line-or-beginning-search
|
||||
zle -N up-line-or-beginning-search
|
||||
zle -N down-line-or-beginning-search
|
||||
|
||||
# Colors
|
||||
autoload -Uz colors && colors
|
||||
|
||||
#------------------------------ path ------------------------------
|
||||
|
||||
path_append() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
test -d "$arg" || continue
|
||||
PATH=${PATH//":$arg:"/:}
|
||||
PATH=${PATH/#"$arg:"/}
|
||||
PATH=${PATH/%":$arg"/}
|
||||
export PATH="${PATH:+"$PATH:"}$arg"
|
||||
done
|
||||
} && export path_append
|
||||
|
||||
path_prepend() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
test -d "$arg" || continue
|
||||
PATH=${PATH//:"$arg:"/:}
|
||||
PATH=${PATH/#"$arg:"/}
|
||||
PATH=${PATH/%":$arg"/}
|
||||
export PATH="$arg${PATH:+":$PATH"}"
|
||||
done
|
||||
} && export path_prepend
|
||||
|
||||
fpath_prepend() {
|
||||
declare arg
|
||||
for arg in "$@"; do
|
||||
test -d "$arg" || continue
|
||||
FPATH=${FPATH//:"$arg:"/:}
|
||||
FPATH=${FPATH/#"$arg:"/}
|
||||
FPATH=${FPATH/%":$arg"/}
|
||||
export FPATH="$arg${FPATH:+":$FPATH"}"
|
||||
done
|
||||
} && export fpath_prepend
|
||||
|
||||
|
||||
# last arg will be first in path
|
||||
path_prepend \
|
||||
"/usr/local/sbin" \
|
||||
"/usr/local/bin" \
|
||||
"/opt/homebrew/bin" \
|
||||
"/opt/homebrew/sbin" \
|
||||
"$HOME/.local/bin" \
|
||||
"$SCRIPTS"
|
||||
|
||||
fpath_prepend \
|
||||
"$(brew --prefix)/share/zsh/site-functions" \
|
||||
"$(brew --prefix)/share/zsh-completions" \
|
||||
"$ZDOTDIR/completions"
|
||||
|
||||
#------------------------------ history ------------------------------
|
||||
setopt appendhistory # append to history
|
||||
setopt sharehistory # share history across multiple sessions
|
||||
setopt incappendhistory # adds commands as typed, not at shell exit
|
||||
setopt hist_expire_dups_first # expire duplicates first
|
||||
setopt hist_ignore_dups # do not store duplicates
|
||||
setopt hist_find_no_dups # ignore duplicates when searching
|
||||
setopt hist_reduce_blanks # do not store blank lines.
|
||||
|
||||
export HISTSIZE=5000
|
||||
export HISTFILESIZE=10000
|
||||
export HISTFILE=$ZDOTDIR/history
|
||||
|
||||
#set -o vi
|
||||
|
||||
#------------------------------ cdpath ------------------------------
|
||||
setopt autocd
|
||||
export CDPATH=".:$GHREPOS:$DOTFILES:$LOCAL_REPOS:$HOME"
|
||||
|
||||
#------------------------------ options ------------------------------
|
||||
# (see `man zshoptions`)
|
||||
setopt chaselinks
|
||||
setopt extended_glob
|
||||
setopt glob_dots
|
||||
setopt glob_star_short
|
||||
setopt clobber
|
||||
setopt interactive_comments
|
||||
setopt aliases
|
||||
|
||||
# Enable vi mode
|
||||
bindkey -v
|
||||
|
||||
# Load Useful Functions
|
||||
_source_if "${ZDOTDIR}/zsh-functions"
|
||||
|
||||
|
||||
# Plugins
|
||||
zsh_add_plugin "zsh-users/zsh-autosuggestions"
|
||||
zsh_add_plugin "zsh-users/zsh-syntax-highlighting"
|
||||
|
||||
#------------------------------ completions ------------------------------
|
||||
# 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
|
||||
|
||||
zstyle ':completion:*' menu select
|
||||
autoload -Uz compinit; compinit # zstyle(s) should be added before this.
|
||||
zmodload zsh/complist
|
||||
_comp_options+=(globdots) # Include hidden files.
|
||||
|
||||
#------------------------------ prompt ------------------------------
|
||||
|
||||
# Prompt / managed by brew. (`brew install pure`)
|
||||
autoload -Uz promptinit; promptinit
|
||||
prompt pure
|
||||
|
||||
#------------------------------ aliases ------------------------------
|
||||
|
||||
alias bk='cd "${OLDPWD}"'
|
||||
alias cdots='cd "${DOTFILES}"'
|
||||
alias cl='printf "\e[H\e[2J"'
|
||||
alias clear='printf "\e[H\e[2J"'
|
||||
alias g='git'
|
||||
alias ga='git add'
|
||||
alias gcb='git checkout -b'
|
||||
alias gco='git checkout'
|
||||
alias gcm='git commit -m'
|
||||
#alias gma() { git add . && git commit -m "$1" }
|
||||
#alias gp() { git push }
|
||||
alias gp='git push'
|
||||
alias gs='git status'
|
||||
alias vi='vim'
|
||||
|
||||
#------------------------------ local configs ------------------------------
|
||||
_source_if "$ZDOTDIR/.zshrc-local"
|
||||
|
||||
|
||||
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
|
||||
65
zsh/config/zsh-aliases
Normal file
65
zsh/config/zsh-aliases
Normal file
@@ -0,0 +1,65 @@
|
||||
#!/bin/zsh
|
||||
# configure aliases
|
||||
# _ _
|
||||
# ( ) (_ ) _
|
||||
# ____ ___ | |__ ______ _ _ | | (_) _ _ ___ __ ___
|
||||
# (_ ,)/',__)| _ `\(______) /'_` ) | | | | /'_` )/',__) /'__`\/',__)
|
||||
# /'/_ \__, \| | | | ( (_| | | | | |( (_| |\__, \( ___/\__, \
|
||||
# (____)(____/(_) (_) `\__,_)(___)(_)`\__,_)(____/`\____)(____/
|
||||
|
||||
|
||||
# clear the terminal
|
||||
alias cl() {
|
||||
if [[ "$TMUX_PANE" ]]; then
|
||||
tmux send-keys -R\; clear-history
|
||||
else
|
||||
clear
|
||||
fi
|
||||
}
|
||||
|
||||
# move into the ~/.dotfiles directory
|
||||
alias cdots() { cd "${HOME}/.dotfiles" }
|
||||
|
||||
# move into zsh config files
|
||||
alias zdots="vi ${ZDOTDIR}"
|
||||
|
||||
# open dotfiles in nvim editor
|
||||
alias dots="vi $DOTFILES"
|
||||
|
||||
# print the banner
|
||||
#alias banner() { clear && cat < "$ZDOTDIR/banner" }
|
||||
|
||||
# create a directory and move into it.
|
||||
#alias mkcd() { mkdir $1 && cd $1 }
|
||||
|
||||
# list files and directories, including hidden files
|
||||
#alias l() { ls -lah --color "$@" }
|
||||
|
||||
# editor
|
||||
alias vim() { nvim "$@" }
|
||||
alias vi() { nvim "$@" }
|
||||
|
||||
# git
|
||||
alias g() { git "$@" }
|
||||
alias ga() { git add . }
|
||||
alias gcb() { git checkout -b "$@" }
|
||||
alias gco() { git checkout "$@" }
|
||||
alias gl() { git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit }
|
||||
alias gma() { git add . && git commit -m "$1" }
|
||||
alias gp() { git push }
|
||||
alias gs() { git status }
|
||||
|
||||
# move back to old cwd
|
||||
alias bk="cd $OLDPWD"
|
||||
|
||||
# My mac-mini specific aliases
|
||||
# if [ $(hostname -s) = "Michaels-Mac-mini" ]; then
|
||||
# alias projects() { cd "/Volumes/M1 Mac-Mini External Drive/Projects" }
|
||||
# fi
|
||||
|
||||
# change file to be executable
|
||||
#alias chmox() { chmod +x "$@" }
|
||||
|
||||
# tmux
|
||||
#alias ta() { tmux -f ~/.config/tmux/tmux.config attach "$@" }
|
||||
|
||||
32
zsh/config/zsh-functions
Normal file
32
zsh/config/zsh-functions
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/zsh
|
||||
# Function to source files if they exist
|
||||
function zsh_add_file() {
|
||||
[ -f "$ZDOTDIR/$1" ] && source "$ZDOTDIR/$1"
|
||||
}
|
||||
|
||||
function zsh_add_plugin() {
|
||||
PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2)
|
||||
if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
|
||||
# For plugins
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh" || \
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.zsh"
|
||||
else
|
||||
git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
|
||||
fi
|
||||
}
|
||||
|
||||
function zsh_add_completion() {
|
||||
PLUGIN_NAME=$(echo $1 | cut -d "/" -f 2)
|
||||
if [ -d "$ZDOTDIR/plugins/$PLUGIN_NAME" ]; then
|
||||
# For completions
|
||||
completion_file_path=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*)
|
||||
fpath+="$(dirname "${completion_file_path}")"
|
||||
zsh_add_file "plugins/$PLUGIN_NAME/$PLUGIN_NAME.plugin.zsh"
|
||||
else
|
||||
git clone "https://github.com/$1.git" "$ZDOTDIR/plugins/$PLUGIN_NAME"
|
||||
fpath+=$(ls $ZDOTDIR/plugins/$PLUGIN_NAME/_*)
|
||||
[ -f $ZDOTDIR/.zccompdump ] && $ZDOTDIR/.zccompdump
|
||||
fi
|
||||
completion_file="$(basename "${completion_file_path}")"
|
||||
if [ "$2" = true ] && compinit "${completion_file:1}"
|
||||
}
|
||||
Reference in New Issue
Block a user