From dba7ac236500f49b03c83ef9b8de16b114e9ab85 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Wed, 27 Feb 2019 17:47:56 +0000 Subject: [PATCH] More fully support zsh Support zshrc, variables, aliases, functions TODO: incorporate dumping_grounds.zsh into functions. --- configs/shared/zsh/.zshrc | 38 +++++++++++++++++++++ configs/shared/zsh/aliases.zsh | 57 ++++++++++++++++++++++++++++++++ configs/shared/zsh/functions.zsh | 36 ++++++++++++++++++++ configs/shared/zsh/variables.zsh | 3 ++ 4 files changed, 134 insertions(+) create mode 100644 configs/shared/zsh/.zshrc create mode 100644 configs/shared/zsh/aliases.zsh create mode 100644 configs/shared/zsh/functions.zsh create mode 100644 configs/shared/zsh/variables.zsh diff --git a/configs/shared/zsh/.zshrc b/configs/shared/zsh/.zshrc new file mode 100644 index 000000000..4c889556a --- /dev/null +++ b/configs/shared/zsh/.zshrc @@ -0,0 +1,38 @@ +source ~/antigen.zsh + +# Load the oh-my-zsh library +antigen use oh-my-zsh + +# Bundles from robbyrussell's oh-my-zsh repo. +antigen bundle git +antigen bundle alias-tips # friendly reminders to prefer an alias if exists +# antigen bundle common-aliases # be careful with the load order here. Can easily eclipse aliases undesirably +antigen bundle extract # extracts archives polymorphically +antigen bundle zsh-completions # extracts archives polymorphically + +# Syntax highlighting +antigen bundle zsh-users/zsh-syntax-highlighting + +# Theming +antigen theme robbyrussell + +# Leave this last +antigen apply + +# Personal Configuration + +# Set environment variables for Nix +source /usr/local/google/home/wpcarro/.nix-profile/etc/profile.d/nix.sh + +# Configure fzf +source "$(fzf-share)/key-bindings.zsh" + +# Configure fasd +eval "$(fasd --init auto)" + +# use full path instead of $DOTFILES, since DOTFILES is set herein +DOTFILES="$HOME/programming/dotfiles" +source "$DOTFILES/configs/shared/zsh/variables.zsh" +source "$DOTFILES/configs/shared/zsh/aliases.zsh" +source "$DOTFILES/configs/shared/zsh/functions.zsh" +source "$DOTFILES/configs/shared/zsh/dumping_grounds.zsh" diff --git a/configs/shared/zsh/aliases.zsh b/configs/shared/zsh/aliases.zsh new file mode 100644 index 000000000..6a47085e8 --- /dev/null +++ b/configs/shared/zsh/aliases.zsh @@ -0,0 +1,57 @@ +# These were haphazardly ported from wpcarro/nixify, so some may be broken. +alias pbcopy="xclip -selection clipboard -i" +alias pbpaste="xclip -selection clipboard -o" +alias md="mkdir_cd" +alias ls="exa" +alias ll="exa -l" +alias la="exa -la" +alias lorem="echo Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +alias e="emacsclient --alternate-editor=${EDITOR}" +alias d="docker" +alias dps="docker ps" +alias dpsa="docker ps -a" +alias drm="docker rm" +alias drmi="docker rmi" +alias drit="docker run -it" +alias drd="docker run -d" +alias di="docker images" +alias m="mix" +alias mc="mix compile" +alias mcf="mix compile --force" +alias ism="iex -S mix" +alias tism="MIX_ENV=test iex -S mix" +alias mdg="mix deps.get" +alias mdu="mix deps.update" +alias mdup="mix docker.up" +alias cat="bat" +alias g="git" +alias git="hub" +alias gprom="git pull --rebase origin master" +alias gcan="git commit --amend --no-edit" +alias gpf="git push --force" +alias gpff="git push --force --no-verify" +alias gds="git diff --staged" +alias gfx="git commit --fixup" +alias gsh="git show" +alias gbm="git branch --merged" +alias gwip="git add . && git commit -m wip" +alias gpr="git pull-request" +alias sb="stack build" +alias se="stack exec --" +alias sc="stack clean" +alias st="stack test" +# Currently broken +# alias haddocks=''open "$(stack path --local-doc-root)/index.html"'' +alias kc="kubectl" +alias kpods="kubectl get pods" +alias knodes="kubectl get nodes" +alias kdeploys="kubectl get deployments" +alias kdns="kubectl get ing" +alias kedit="kubectl edit deployments " +alias kswitch="gcloud container clusters get-credentials " +alias nq="nix_introspect" +alias nsh="nix-shell" +alias nshp="nix-shell --pure" +alias nr="nix repl" +alias md=mkdir_cd +alias j=z # to emulate autojump; my muscle memory is hardened here diff --git a/configs/shared/zsh/functions.zsh b/configs/shared/zsh/functions.zsh new file mode 100644 index 000000000..b328f5c4a --- /dev/null +++ b/configs/shared/zsh/functions.zsh @@ -0,0 +1,36 @@ +# From Google's ZSH Hacks + +# Improvement to fasd's existing `zz` alias +unalias zz +function zz() { + # TODO: Add documentation + local dir + dir="$(fasd -Rdl "$1" | fzf --query="$1" -1 -0 --no-sort +m)" && cd "${dir}" || return 1 +} + +function fv() { + # Usage: fv file pattern + # This is useful when you know the fuzzy name of the file you want to edit + local file + file="$(fzf --exact --height 40% --reverse --query="$1" --select-1 --exit-0)" + [[ -n "$file" ]] && vim "$file" +} + +function bb() { + # Toggle between blaze-bin and your source. + # Useful if you like to cd into the dir where your source lives. + if [[ $PWD =~ '(.*)/blaze-bin(.*)' ]]; then + cd "${match[1]}${match[2]}" + else + cd "${PWD/\/google3//google3/blaze-bin}" + fi +} + +function jt() { + # Toggle between the source dir and test dir. + if [[ $PWD =~ '(.*)/javatests(.*)' ]]; then + cd "${match[1]}/java${match[2]}" + else + cd "${PWD/\/google3\/java//google3/javatests}" + fi +} diff --git a/configs/shared/zsh/variables.zsh b/configs/shared/zsh/variables.zsh new file mode 100644 index 000000000..0aae28694 --- /dev/null +++ b/configs/shared/zsh/variables.zsh @@ -0,0 +1,3 @@ +EDITOR="emacs" +BROWSER="chrome" +NIXIFY="$HOME/programming/nixify"