From bc1bd4f5e6bc483fa73d2257980fab6a14288ed0 Mon Sep 17 00:00:00 2001 From: Thomas Ruoff Date: Sun, 13 Aug 2017 23:14:19 +0200 Subject: [PATCH] start out with thoughtbots version --- aliases | 19 +++++ zplug | 1 - zprofile | 38 --------- zsh/completion/_ag | 7 ++ zsh/completion/_bundler | 72 +++++++++++++++++ zsh/completion/_g | 2 + zsh/completion/_production | 2 + zsh/completion/_rspec | 3 + zsh/completion/_staging | 2 + zsh/configs/color.zsh | 6 ++ zsh/configs/editor.zsh | 2 + zsh/configs/history.zsh | 4 + zsh/configs/keybindings.zsh | 17 ++++ zsh/configs/options.zsh | 9 +++ zsh/configs/post/completion.zsh | 6 ++ zsh/configs/post/path.zsh | 12 +++ zsh/configs/prompt.zsh | 9 +++ zsh/functions/_git_delete_branch | 4 + zsh/functions/change-extension | 9 +++ zsh/functions/envup | 10 +++ zsh/functions/g | 9 +++ zsh/functions/mcd | 5 ++ zshenv | 29 +++++++ zshrc | 128 ++++++++++--------------------- 24 files changed, 279 insertions(+), 126 deletions(-) create mode 100644 aliases delete mode 160000 zplug delete mode 100644 zprofile create mode 100644 zsh/completion/_ag create mode 100644 zsh/completion/_bundler create mode 100644 zsh/completion/_g create mode 100644 zsh/completion/_production create mode 100644 zsh/completion/_rspec create mode 100644 zsh/completion/_staging create mode 100644 zsh/configs/color.zsh create mode 100644 zsh/configs/editor.zsh create mode 100644 zsh/configs/history.zsh create mode 100644 zsh/configs/keybindings.zsh create mode 100644 zsh/configs/options.zsh create mode 100644 zsh/configs/post/completion.zsh create mode 100644 zsh/configs/post/path.zsh create mode 100644 zsh/configs/prompt.zsh create mode 100644 zsh/functions/_git_delete_branch create mode 100644 zsh/functions/change-extension create mode 100644 zsh/functions/envup create mode 100644 zsh/functions/g create mode 100644 zsh/functions/mcd create mode 100644 zshenv diff --git a/aliases b/aliases new file mode 100644 index 0000000..102caca --- /dev/null +++ b/aliases @@ -0,0 +1,19 @@ +# Unix +alias ll="ls -al" +alias ln="ln -v" +alias mkdir="mkdir -p" +alias e="$EDITOR" +alias v="$VISUAL" + +# Bundler +alias b="bundle" + +# Rails +alias migrate="rake db:migrate db:rollback && rake db:migrate db:test:prepare" +alias s="rspec" + +# Pretty print the path +alias path='echo $PATH | tr -s ":" "\n"' + +# Include custom aliases +[[ -f ~/.aliases.local ]] && source ~/.aliases.local diff --git a/zplug b/zplug deleted file mode 160000 index ac6012d..0000000 --- a/zplug +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ac6012d80df3f0dd327dfe0d274273a40e2f0a16 diff --git a/zprofile b/zprofile deleted file mode 100644 index 698c902..0000000 --- a/zprofile +++ /dev/null @@ -1,38 +0,0 @@ -# extend path -export PATH="$HOME/local/bin:$PATH" - -export EDITOR=$(which vim) - -# nvm -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" - -# rbenv -if [ -s "$HOME/.rbenv/bin/rbenv" ] ; then - export PATH="$HOME/.rbenv/bin:$PATH" - eval "$(rbenv init -)" -fi - -# in case there are local settings needed -if [ -s "$HOME/.zprofile.local" ] ; then - source $HOME/.zprofile.local -fi - -# Dist related settings -case $OSTYPE in - "darwin14.0"|"darwin15.0" ) - export PATH="$(brew --prefix coreutils)/libexec/gnubin:/usr/local/bin:$PATH" - export MANPATH="$(brew --prefix coreutils)/libexec/gnuman:$MANPATH" - #eval $(ssh-agent -s) - ;; - "linux-gnu" ) - export ANDROID_HOME=~/local/android-sdk - export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools - ;; -esac - -case $HOSTNAME in - "cassiopeia.uberspace.de" ) - export PATH=/package/host/localhost/nodejs-6/bin:$PATH - ;; -esac diff --git a/zsh/completion/_ag b/zsh/completion/_ag new file mode 100644 index 0000000..0d990d6 --- /dev/null +++ b/zsh/completion/_ag @@ -0,0 +1,7 @@ +#compdef ag + +if (( CURRENT == 2 )); then + compadd $(cut -f 1 tmp/tags .git/tags 2>/dev/null) +else; + _files +fi diff --git a/zsh/completion/_bundler b/zsh/completion/_bundler new file mode 100644 index 0000000..bb8cbf1 --- /dev/null +++ b/zsh/completion/_bundler @@ -0,0 +1,72 @@ +#compdef bundle + +local curcontext="$curcontext" state line _gems _opts ret=1 + +_arguments -C -A "-v" -A "--version" \ + '(- 1 *)'{-v,--version}'[display version information]' \ + '1: :->cmds' \ + '*:: :->args' && ret=0 + +case $state in + cmds) + _values "bundle command" \ + "install[Install the gems specified by the Gemfile or Gemfile.lock]" \ + "update[Update dependencies to their latest versions]" \ + "package[Package the .gem files required by your application]" \ + "exec[Execute a script in the context of the current bundle]" \ + "config[Specify and read configuration options for bundler]" \ + "check[Determine whether the requirements for your application are installed]" \ + "list[Show all of the gems in the current bundle]" \ + "show[Show the source location of a particular gem in the bundle]" \ + "console[Start an IRB session in the context of the current bundle]" \ + "open[Open an installed gem in the editor]" \ + "lock[Generate a lockfile for your dependencies]" \ + "viz[Generate a visual representation of your dependencies]" \ + "init[Generate a simple Gemfile, placed in the current directory]" \ + "gem[Create a simple gem, suitable for development with bundler]" \ + "help[Describe available tasks or one specific task]" \ + "platform[Displays platform compatibility information]" \ + "outdated[Show all of the outdated gems in the current bundle]" \ + "clean[Cleans up unused gems in your bundler directory]" + ret=0 + ;; + args) + case $line[1] in + help) + _values 'commands' 'install' 'update' 'package' 'exec' 'config' 'check' 'list' 'show' 'console' 'open' 'lock' 'viz' 'init' 'gem' 'help' 'platform' 'outdated' 'clean' && ret=0 + ;; + install) + _arguments \ + '(--no-color)--no-color[disable colorization in output]' \ + '(--local)--local[do not attempt to connect to rubygems.org]' \ + '(--quiet)--quiet[only output warnings and errors]' \ + '(--gemfile)--gemfile=-[use the specified gemfile instead of Gemfile]:gemfile' \ + '(--system)--system[install to the system location]' \ + '(--deployment)--deployment[install using defaults tuned for deployment environments]' \ + '(--frozen)--frozen[do not allow the Gemfile.lock to be updated after this install]' \ + '(--path)--path=-[specify a different path than the system default]:path:_files' \ + '(--binstubs)--binstubs=-[generate bin stubs for bundled gems to ./bin]:directory:_files' \ + '(--without)--without=-[exclude gems that are part of the specified named group]:groups' + ret=0 + ;; + exec) + _normal && ret=0 + ;; + (open|show) + _gems=( $(bundle show 2> /dev/null | sed -e '/^ \*/!d; s/^ \* \([^ ]*\) .*/\1/') ) + if [[ $_gems != "" ]]; then + _values 'gems' $_gems && ret=0 + fi + ;; + *) + _opts=( $(bundle help $line[1] | sed -e '/^ \[-/!d; s/^ \[\(-[^=]*\)=.*/\1/') ) + _opts+=( $(bundle help $line[1] | sed -e '/^ -/!d; s/^ \(-.\), \[\(-[^=]*\)=.*/\1 \2/') ) + if [[ $_opts != "" ]]; then + _values 'options' $_opts && ret=0 + fi + ;; + esac + ;; +esac + +return ret diff --git a/zsh/completion/_g b/zsh/completion/_g new file mode 100644 index 0000000..f600877 --- /dev/null +++ b/zsh/completion/_g @@ -0,0 +1,2 @@ +#compdef g +compdef g=git diff --git a/zsh/completion/_production b/zsh/completion/_production new file mode 100644 index 0000000..a124346 --- /dev/null +++ b/zsh/completion/_production @@ -0,0 +1,2 @@ +#compdef production +compdef production=heroku diff --git a/zsh/completion/_rspec b/zsh/completion/_rspec new file mode 100644 index 0000000..e75c182 --- /dev/null +++ b/zsh/completion/_rspec @@ -0,0 +1,3 @@ +#compdef rspec + +compadd -P spec/ $(ls spec/**/*_spec.rb | sed -E "s/spec\///g") diff --git a/zsh/completion/_staging b/zsh/completion/_staging new file mode 100644 index 0000000..fdcd38f --- /dev/null +++ b/zsh/completion/_staging @@ -0,0 +1,2 @@ +#compdef staging +compdef staging=heroku diff --git a/zsh/configs/color.zsh b/zsh/configs/color.zsh new file mode 100644 index 0000000..07fcb6b --- /dev/null +++ b/zsh/configs/color.zsh @@ -0,0 +1,6 @@ +# makes color constants available +autoload -U colors +colors + +# enable colored output from ls, etc. on FreeBSD-based systems +export CLICOLOR=1 diff --git a/zsh/configs/editor.zsh b/zsh/configs/editor.zsh new file mode 100644 index 0000000..4d6ef2a --- /dev/null +++ b/zsh/configs/editor.zsh @@ -0,0 +1,2 @@ +export VISUAL=vim +export EDITOR=$VISUAL diff --git a/zsh/configs/history.zsh b/zsh/configs/history.zsh new file mode 100644 index 0000000..1d5e184 --- /dev/null +++ b/zsh/configs/history.zsh @@ -0,0 +1,4 @@ +setopt hist_ignore_all_dups inc_append_history +HISTFILE=~/.zhistory +HISTSIZE=4096 +SAVEHIST=4096 diff --git a/zsh/configs/keybindings.zsh b/zsh/configs/keybindings.zsh new file mode 100644 index 0000000..5e209aa --- /dev/null +++ b/zsh/configs/keybindings.zsh @@ -0,0 +1,17 @@ +# give us access to ^Q +stty -ixon + +# vi mode +bindkey -v +bindkey "^F" vi-cmd-mode + +# handy keybindings +bindkey "^A" beginning-of-line +bindkey "^E" end-of-line +bindkey "^K" kill-line +bindkey "^R" history-incremental-search-backward +bindkey "^P" history-search-backward +bindkey "^Y" accept-and-hold +bindkey "^N" insert-last-word +bindkey "^Q" push-line-or-edit +bindkey -s "^T" "^[Isudo ^[A" # "t" for "toughguy" diff --git a/zsh/configs/options.zsh b/zsh/configs/options.zsh new file mode 100644 index 0000000..4d56c07 --- /dev/null +++ b/zsh/configs/options.zsh @@ -0,0 +1,9 @@ +# awesome cd movements from zshkit +setopt autocd autopushd pushdminus pushdsilent pushdtohome cdablevars +DIRSTACKSIZE=5 + +# Enable extended globbing +setopt extendedglob + +# Allow [ or ] whereever you want +unsetopt nomatch diff --git a/zsh/configs/post/completion.zsh b/zsh/configs/post/completion.zsh new file mode 100644 index 0000000..889200b --- /dev/null +++ b/zsh/configs/post/completion.zsh @@ -0,0 +1,6 @@ +# load our own completion functions +fpath=(~/.zsh/completion /usr/local/share/zsh/site-functions $fpath) + +# completion +autoload -U compinit +compinit diff --git a/zsh/configs/post/path.zsh b/zsh/configs/post/path.zsh new file mode 100644 index 0000000..427a171 --- /dev/null +++ b/zsh/configs/post/path.zsh @@ -0,0 +1,12 @@ +# ensure dotfiles bin directory is loaded first +PATH="$HOME/.bin:/usr/local/sbin:$PATH" + +# load rbenv if available +if command -v rbenv >/dev/null; then + eval "$(rbenv init - --no-rehash)" +fi + +# mkdir .git/safe in the root of repositories you trust +PATH=".git/safe/../../bin:$PATH" + +export -U PATH diff --git a/zsh/configs/prompt.zsh b/zsh/configs/prompt.zsh new file mode 100644 index 0000000..27a01d0 --- /dev/null +++ b/zsh/configs/prompt.zsh @@ -0,0 +1,9 @@ +# modify the prompt to contain git branch name if applicable +git_prompt_info() { + current_branch=$(git current-branch 2> /dev/null) + if [[ -n $current_branch ]]; then + echo " %{$fg_bold[green]%}$current_branch%{$reset_color%}" + fi +} +setopt promptsubst +PS1='${SSH_CONNECTION+"%{$fg_bold[green]%}%n@%m:"}%{$fg_bold[blue]%}%c%{$reset_color%}$(git_prompt_info) %# ' diff --git a/zsh/functions/_git_delete_branch b/zsh/functions/_git_delete_branch new file mode 100644 index 0000000..32648ea --- /dev/null +++ b/zsh/functions/_git_delete_branch @@ -0,0 +1,4 @@ +_git_delete_branch () +{ + __gitcomp "$(__git_heads)" +} diff --git a/zsh/functions/change-extension b/zsh/functions/change-extension new file mode 100644 index 0000000..596b9c5 --- /dev/null +++ b/zsh/functions/change-extension @@ -0,0 +1,9 @@ +# Change file extensions recursively in current directory +# +# change-extension erb haml + +function change-extension() { + foreach f (**/*.$1) + mv $f $f:r.$2 + end +} diff --git a/zsh/functions/envup b/zsh/functions/envup new file mode 100644 index 0000000..4ae3a1c --- /dev/null +++ b/zsh/functions/envup @@ -0,0 +1,10 @@ +# Load .env file into shell session for environment variables + +function envup() { + if [ -f .env ]; then + export $(cat .env) + else + echo 'No .env file found' 1>&2 + return 1 + fi +} diff --git a/zsh/functions/g b/zsh/functions/g new file mode 100644 index 0000000..438db75 --- /dev/null +++ b/zsh/functions/g @@ -0,0 +1,9 @@ +# No arguments: `git status` +# With arguments: acts like `git` +g() { + if [[ $# -gt 0 ]]; then + git "$@" + else + git status + fi +} diff --git a/zsh/functions/mcd b/zsh/functions/mcd new file mode 100644 index 0000000..4154b02 --- /dev/null +++ b/zsh/functions/mcd @@ -0,0 +1,5 @@ +# Make directory and change into it. + +function mcd() { + mkdir -p "$1" && cd "$1"; +} diff --git a/zshenv b/zshenv new file mode 100644 index 0000000..5d2d258 --- /dev/null +++ b/zshenv @@ -0,0 +1,29 @@ +local _old_path="$PATH" + +# Local config +[[ -f ~/.zshenv.local ]] && source ~/.zshenv.local + +if [[ $PATH != $_old_path ]]; then + # `colors` isn't initialized yet, so define a few manually + typeset -AHg fg fg_bold + if [ -t 2 ]; then + fg[red]=$'\e[31m' + fg_bold[white]=$'\e[1;37m' + reset_color=$'\e[m' + else + fg[red]="" + fg_bold[white]="" + reset_color="" + fi + + cat <&2 +${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries. +Please move that configuration to \`.zshrc.local' like so: + ${fg_bold[white]}cat ~/.zshenv.local >> ~/.zshrc.local && rm ~/.zshenv.local${reset_color} + +(called from ${(%):-%N:%i}) + +MSG +fi + +unset _old_path diff --git a/zshrc b/zshrc index ed5b3bc..7a6e378 100644 --- a/zshrc +++ b/zshrc @@ -1,92 +1,46 @@ -source ~/.dotfiles/zplug/init.zsh +# load custom executable functions +for function in ~/.zsh/functions/*; do + source $function +done +# extra files in ~/.zsh/configs/pre , ~/.zsh/configs , and ~/.zsh/configs/post +# these are loaded first, second, and third, respectively. +_load_settings() { + _dir="$1" + if [ -d "$_dir" ]; then + if [ -d "$_dir/pre" ]; then + for config in "$_dir"/pre/**/*(N-.); do + . $config + done + fi -zplug "lib/spectrum", from:oh-my-zsh -zplug "lib/directories", from:oh-my-zsh -zplug "lib/grep", from:oh-my-zsh -zplug "lib/history", from:oh-my-zsh -zplug "lib/misc", from:oh-my-zsh -zplug "plugins/common-aliases", from:oh-my-zsh -zplug "plugins/frontend-search", from:oh-my-zsh + for config in "$_dir"/**/*(N-.); do + case "$config" in + "$_dir"/pre/*) + : + ;; + "$_dir"/post/*) + : + ;; + *) + if [ -f $config ]; then + . $config + fi + ;; + esac + done -zplug "zsh-users/zsh-completions", use:"src/*.zsh" -zplug "zsh-users/zsh-syntax-highlighting", defer:2 + if [ -d "$_dir/post" ]; then + for config in "$_dir"/post/**/*(N-.); do + . $config + done + fi + fi +} +_load_settings "$HOME/.zsh/configs" -zplug "peterhurford/git-it-on.zsh" -zplug "gerges/oh-my-zsh-jira-plus" +# Local config +[[ -f ~/.zshrc.local ]] && source ~/.zshrc.local -zplug "mafredri/zsh-async" -zplug "sindresorhus/pure" - -######################## -# Other settings -######################## -setopt auto_cd -setopt multios -setopt cdablevars - - -######################## -# vi mode -######################## -bindkey -v -zle -N edit-command-line -autoload -Uz edit-command-line -bindkey -M vicmd 'v' edit-command-line - -######################## -# Aliases -######################## -alias _=sudo -alias g=git -alias nohist='unset HISTFILE' - -alias reset='reset && base16_gruvbox-dark-medium' - -alias ta='tmux attach -t' -alias ts='tmux new-session -s' -alias tl='tmux list-sessions' -rl () { $(npm bin)/$* } - -# utt time tracking -alias ua='uttr --add' -alias uah='uttr --add hello' -alias uas='uttr --add standup' -alias ual='uttr --add "lunch**"' -alias ue='uttr --edit' -alias urw='uttr --report=week' -alias urlw='uttr --report=lastWeek' -alias urm='uttr --report=month' -alias urlm='uttr --report=lastMonth' - -# dead simple todo list -alias todo="mkdir -p ~/todos/\$(date +"%Y"); vim ~/todos/\$(date +"%Y")/todo-\$(date +"%m-%d").md" - -# colors -autoload -U colors && colors -alias ls='ls --color=tty' - -# keybindings - -export KEYTIMEOUT=1 - -# prevent 2*ESC-i insert-mode switch failure -noop () { } -zle -N noop -bindkey -M vicmd '\e' noop - -bindkey '^P' up-history -bindkey '^N' down-history - -bindkey '^r' history-incremental-search-backward -bindkey ' ' magic-space - -# fzf -[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh - -# zplug -if ! zplug check; then - zplug install -fi - -zplug load +# aliases +[[ -f ~/.aliases ]] && source ~/.aliases