From 59e6a8a96010d3161f0ea75cec09b8c8e02bde4e Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Sun, 31 Jul 2022 02:15:51 -0700 Subject: [PATCH] full zsh reconfig --- dotfiles/bash/bashrc | 9 --- dotfiles/zsh/README.md | 19 +++++++ dotfiles/zsh/aliases.zsh | 41 ++++++++++++++ dotfiles/zsh/exports.zsh | 33 +++++++++++ dotfiles/zsh/functions.zsh | 12 ++++ dotfiles/zsh/initializations.zsh | 17 ++++++ dotfiles/zsh/ps1.zsh | 10 ++++ dotfiles/zsh/zprofile | 26 +++++++++ dotfiles/zsh/zshrc | 75 +++++++++++++++++++++++++ dotfiles/zshrc | 118 --------------------------------------- 10 files changed, 233 insertions(+), 127 deletions(-) create mode 100644 dotfiles/zsh/README.md create mode 100644 dotfiles/zsh/aliases.zsh create mode 100644 dotfiles/zsh/exports.zsh create mode 100644 dotfiles/zsh/functions.zsh create mode 100644 dotfiles/zsh/initializations.zsh create mode 100644 dotfiles/zsh/ps1.zsh create mode 100644 dotfiles/zsh/zprofile create mode 100644 dotfiles/zsh/zshrc delete mode 100644 dotfiles/zshrc diff --git a/dotfiles/bash/bashrc b/dotfiles/bash/bashrc index c9cb256..b9e30ee 100644 --- a/dotfiles/bash/bashrc +++ b/dotfiles/bash/bashrc @@ -188,15 +188,6 @@ then fi fi -######### -# Other functions -######### - -aws-sso () { - aws sso login --profile $1 - aws2-wrap --profile $1 --exec "~/aws-save-creds" -} - # Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin" diff --git a/dotfiles/zsh/README.md b/dotfiles/zsh/README.md new file mode 100644 index 0000000..81fed43 --- /dev/null +++ b/dotfiles/zsh/README.md @@ -0,0 +1,19 @@ +# ZSH Configuration + +The ZSH configuration is completely modularized to make management easier. The following are brief descriptions of each +file: + +* `zshrc`: The main ZSH configuration sourced for non-login interactive terminals. +* `zprofile`: The main ZSH configuration sourced for login interactive terminals. Also sources `zshrc`. +* `functions.zsh`: A file containing function definitions for utilities. +* `aliases.zsh`: A file containing aliases sourced into the terminal. +* `exports.zsh`: A file containing all exports not found in `zprofile`. +* `initializations.zsh`: A file containing initialization code for various tasks such as RVM directories, pyenv, etc. +* `ps1.zsh`: Defines the terminal prompt. + +## Git Completion + +Git completion is automatically installed on first run to `.zsh` in the users home. This is all created for you and nothing +needs to be done. Should the curl commands fail to pull the correct files from the `git` github repository you will need +to source both `git-completion.bash` and `git-completion.zsh` and adjust the script appropriately or place them in a +`.zsh` directory in `$HOME`. \ No newline at end of file diff --git a/dotfiles/zsh/aliases.zsh b/dotfiles/zsh/aliases.zsh new file mode 100644 index 0000000..22619b9 --- /dev/null +++ b/dotfiles/zsh/aliases.zsh @@ -0,0 +1,41 @@ +# Alias +if [[ "$OS_TYPE" != "gnu-linux" ]]; then + alias python='python3' +fi + +# rlwrap provides readline wrapping for programs. +# This alias makes the SBCL REPL usable. +alias sbcl='rlwrap sbcl' + +# Useful git aliases +alias gita='git add' +alias gitap='git add -p' +alias gitc='git commit' +alias gitp='git push' +alias gits='git status' +alias gitd='git diff' + +alias k8='kubectl' + +# Good overrides + +# Don't nuke the computer +alias rm='rm -i' + +# Better ls - lists more information for each file +alias ll='ls -lh' + +# Human readable ls for the current directory +if [[ "$OS_TYPE" != "gnu-linux" ]]; then + # OS X lt + alias lt='du -sh * | sort -h' +else + alias lt='ls --human-readable --size -1 -S --classify' +fi + + +# Count files in the current directory +alias count='find . -type f | wc -l' + +# Generate sha1 hashes on the fly +alias sha1='openssl sha1' diff --git a/dotfiles/zsh/exports.zsh b/dotfiles/zsh/exports.zsh new file mode 100644 index 0000000..f588ee4 --- /dev/null +++ b/dotfiles/zsh/exports.zsh @@ -0,0 +1,33 @@ +#!/bin/zsh + +if hash vim 2>/dev/null; then + export EDITOR=vim +else + export EDITOR=vi +fi + +if hash clang 2>/dev/null; then + export CC=$(which clang) +else + export CC=$(which gcc) +fi + +if hash clang++ 2>/dev/null; then + export CXX=$(which clang++) +else + export CXX=$(which g++) +fi + +export OPENSSL_ROOT_DIR=$(which openssl) + +# Add openJDK to path +export PATH="/usr/local/opt/openjdk/bin:$PATH" + +# Ignore duplicates in history to make history less of a hassle to use. +export HISTCONTROL=ignoredups + +# If go is installed, set the $GOPATH to the projects directory created above. +if which go > /dev/null; then export GOPATH=$HOME/.go; fi + +export PATH="$PATH:$HOME/.rvm/bin" +. "$HOME/.cargo/env" diff --git a/dotfiles/zsh/functions.zsh b/dotfiles/zsh/functions.zsh new file mode 100644 index 0000000..870997a --- /dev/null +++ b/dotfiles/zsh/functions.zsh @@ -0,0 +1,12 @@ +#!/usr/zsh + +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /' +} + +# If you ever needed weather... +weather() { + curl wttr.in +} + + diff --git a/dotfiles/zsh/initializations.zsh b/dotfiles/zsh/initializations.zsh new file mode 100644 index 0000000..3d9c154 --- /dev/null +++ b/dotfiles/zsh/initializations.zsh @@ -0,0 +1,17 @@ +#!/bin/zsh + +if [[ "$OSTYPE" == "linux-gnu" ]]; then + export PATH="$HOME/.pyenv/bin:$PATH" + + # For whatever reason the linux version of pyenv doesnt install `pyenv-virtualenv-init`. + eval "$(pyenv init -)" + eval "$(pyenv virtualenv-init -)" +fi + +if which pyenv-virtualenv-init > /dev/null; then + eval "$(pyenv init -)" + eval "$(pyenv virtualenv-init -)" +fi + +# RVM configuration +[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" diff --git a/dotfiles/zsh/ps1.zsh b/dotfiles/zsh/ps1.zsh new file mode 100644 index 0000000..b38e1ab --- /dev/null +++ b/dotfiles/zsh/ps1.zsh @@ -0,0 +1,10 @@ +#!/bin/zsh + +setopt prompt_subst +autoload -Uz vcs_info +precmd () { vcs_info } + +# Format = [] +zstyle ':vcs_info:*' formats ' %F{green}[%b]%f' + +PS1='%B%n@%m%b %F{blue}%2~%f${vcs_info_msg_0_} %B⇨%b ' \ No newline at end of file diff --git a/dotfiles/zsh/zprofile b/dotfiles/zsh/zprofile new file mode 100644 index 0000000..a9b7243 --- /dev/null +++ b/dotfiles/zsh/zprofile @@ -0,0 +1,26 @@ +#!/bin/zsh + +if [[ -f ~/.zshrc ]]; then + source ~/.zshrc +fi + +if [[ "$OSTYPE" == "darwin"* ]]; then + # Enable homebrew openssl support + export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ + export PATH="/usr/local/opt/openjdk/bin:$PATH" + export PATH="/usr/local/opt/llvm/bin:$PATH" + export PATH="/usr/local/opt/qt/bin:$PATH" + export PATH="/usr/local/opt/tcl-tk/bin:$PATH" +fi + +if hash pyenv 2>/dev/null; then + export PYENV_ROOT="$HOME/.pyenv" + command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init -)" +fi + +# Local bin +export PATH=$HOME/bin:/usr/local/bin:$PATH + +test -r /home/vm/.opam/opam-init/init.sh && . /home/vm/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true +. "$HOME/.cargo/env" diff --git a/dotfiles/zsh/zshrc b/dotfiles/zsh/zshrc new file mode 100644 index 0000000..49e96b3 --- /dev/null +++ b/dotfiles/zsh/zshrc @@ -0,0 +1,75 @@ +#!/bin/zsh + +if [[ "$OSTYPE" == "linux-gnu" ]]; then + symlink_dir=$(cd "$( dirname "`readlink -f ${(%):-%N}`" )" && pwd) +else + # OS X is not a fan of `readlink -f` + symlink_dir=$(cd "$( dirname "`readlink ${(%):-%N}`" )" && pwd) +fi + +# -------------------------------- SETUP -------------------------------- # + +# Store private information (exports, keys, etc) in .bash_private. +if [[ -f $HOME/.bash_private ]]; then + source $HOME/.bash_private + echo ".bash_private loaded" +fi + +# Or alternatively .private... +if [[ -f $HOME/.private ]]; then + source $HOME/.private + echo ".private loaded" +fi + +if [ -f $HOME/.inputrc ]; then + source $HOME/.inputrc +else + echo "No .inputrc detected" +fi + +if [[ "$OSTYPE" == "darwin"* ]]; then + if [ -f $HOME/.macrc ]; then + source $HOME/.macrc + fi +fi + +# Set up projects and gopath folder properly for the export in the export section. + +if [[ ! -d $HOME/projects ]]; then + echo "Making $HOME/projects" + mkdir -p $HOME/projects +fi + +if [[ -x go ]]; then + echo "Making $HOME/.go" + mkdir -p $HOME/.go +fi + + +# Install zsh completion in ~/.zsh if it doesn't exist +if [[ ! -d $HOME/.zsh ]]; then + echo "Installing zsh git completion scripts" + mkdir -p $HOME/.zsh + cd $HOME/.zsh + + curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash + curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh + + cd $HOME +fi + +zstyle ':completion:*:*:git:*' script $HOME/.zsh/git-completion.bash +fpath=(~/.zsh $fpath) + +autoload -Uz compinit && compinit + + +# Pull in other configurations +source $symlink_dir/aliases.zsh +source $symlink_dir/functions.zsh +source $symlink_dir/exports.zsh +source $symlink_dir/initializations.zsh +source $symlink_dir/ps1.zsh + +# ------------------------------ END SETUP ------------------------------ # + diff --git a/dotfiles/zshrc b/dotfiles/zshrc deleted file mode 100644 index bc5d9df..0000000 --- a/dotfiles/zshrc +++ /dev/null @@ -1,118 +0,0 @@ -source ~/.bash_profile - -#Portable across both mac and linux now -export LC_ALL=en_US.UTF-8 -export LANG=en_US.UTF-8 -if [[ "$OSTYPE" == "linux-gnu" ]]; then - # Linux - export VISUAL="nvim" - alias vim="$VISUAL" -elif [[ "$OSTYPE" == "darwin"* ]]; then - # Mac OSX - export VISUAL="/usr/local/bin/nvim" - alias vim="$VISUAL" - - # Give access to mono (if installed via the .pkg) early on - export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:${PATH} -fi -export EDITOR="$VISUAL" -export ITERM_24BIT=1 -export TERM=xterm-256color -export GOPATH=$HOME/go -export GOBIN=$GOPATH/bin -export PATH=$PATH:$GOBIN - -# TODO: PUT THIS IN AN IF PYENV EXISTS CHECK -eval "$(pyenv init -)" - -# Emacs needs to be setup different on Linux and Mac -if [[ "$OSTYPE" == "darwin"* ]]; then - alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw' -else - alias emacs='emacs -nw' -fi - -alias irssi='TERM=screen-256color irssi' -alias scheme='rlwrap mit-scheme' -alias startpg='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start' -alias stoppg='pg_ctl -D /usr/local/var/postgres stop' - -# This is for the mac GUI version of emacs. -alias emacs-gui='open -a /Applications/Emacs.app $1' - -# Git specific aliases -alias gp='git push' -alias gs='git status' -alias gd='git diff' -alias gc='git commit -v' -alias gb='git branch' -alias gbd='git branch -d' -alias gbdd='git branch -D' -alias gpu='git pull' -alias gm='git merge' -alias gf='git fetch' -alias ga='git add .' - -gblame() { - builtin git blame $1 -} - -parse_git_branch() { - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' -} - -HISTFILE=~/.histfile -HISTSIZE=10000 -SAVEHIST=10000 - -autoload -U colors && colors -autoload -U promptinit -autoload -U compinit && compinit -autoload -Uz vcs_info -zstyle ':completion:*' menu select -zstyle ':vcs_info:git*' formats "%{$fg[white]%}[%{$reset_color%}%{$fg[blue]%}%b%{$fg[white]%}]%{$reset_color%} %a" - -promptinit -plugins=(git brew npm coffee) - -# User configuration -if [[ "$OSTYPE" == "darwin"* ]]; then - export MYSQL_PATH=/usr/local/Cellar/mysql/5.6.27 - export PATH=$PATH:$MYSQL_PATH/bin - - # Brew - export PATH=$PATH:/usr/local/bin - - # Haskell stuff - export PATH=~/.cabal/bin:$PATH - export PATH=.cabal-sandbox/bin:$PATH - - # Groovy - export GROOVY_HOME=/usr/local/opt/groovy/libexec - - # Gradle - export GRADLE_HOME=/usr/local/opt/gradle/4.5/libexec - export PATH=$PATH:/usr/local/opt/gradle/4.5/libexec - -fi - -precmd(){ - vcs_info -} - -# Set up custom prompt -setopt PROMPT_SUBST - -RPROMPT="%{$fg[white]%}\${vcs_info_msg_0_}%{$reset_color%}" - -PROMPT="%{$fg[white]%}┌%{$reset_color%}[%{$fg[yellow]%}%n%{$reset_color%}@%{$fg[cyan]%}%m%{$reset_color%}]─[%{$fg[green]%}%d%{$reset_color%}] -%{$fg[white]%}└─╼%{$reset_color%} " - -# Run opam init -if hash opam 2>/dev/null; then - ~/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true - eval `opam config env` -fi - -export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting -export PATH="/usr/local/opt/cython/bin:$PATH"