├── gemrc ├── .gitignore ├── gitignore ├── irbrc ├── zshrc ├── plugins ├── rbates.zsh ├── rails.zsh ├── bundler.zsh ├── init.zsh └── git.zsh ├── gitconfig ├── bin └── install ├── LICENSE └── README.md /gemrc: -------------------------------------------------------------------------------- 1 | gem: --no-document 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vim/.netrwhist 2 | vim/.VimballRecord -------------------------------------------------------------------------------- /gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .svn 3 | *~ 4 | .*.swp 5 | -------------------------------------------------------------------------------- /irbrc: -------------------------------------------------------------------------------- 1 | IRB.conf[:USE_AUTOCOMPLETE] = false 2 | IRB.conf[:PROMPT_MODE] = :SIMPLE 3 | -------------------------------------------------------------------------------- /zshrc: -------------------------------------------------------------------------------- 1 | export PATH="/usr/local/bin:$PATH" 2 | export EDITOR="code -w" 3 | 4 | source ~/.zsh-plugins/init.zsh 5 | source ~/.zsh-plugins/git.zsh 6 | source ~/.zsh-plugins/bundler.zsh 7 | source ~/.zsh-plugins/rails.zsh 8 | source ~/.zsh-plugins/rbates.zsh 9 | -------------------------------------------------------------------------------- /plugins/rbates.zsh: -------------------------------------------------------------------------------- 1 | c() { cd ~/code/$1; } 2 | _c() { _files -W ~/code -/; } 3 | compdef _c c 4 | 5 | h() { cd ~/$1; } 6 | _h() { _files -W ~/ -/; } 7 | compdef _h h 8 | 9 | # autocorrect is more annoying than helpful 10 | unsetopt correct_all 11 | 12 | if [[ -n $SSH_CONNECTION ]]; then 13 | PROMPT='%m:%3~$(git_prompt_info [ ])%# ' 14 | else 15 | PROMPT='%3~$(git_prompt_info [ ])%# ' 16 | fi 17 | -------------------------------------------------------------------------------- /gitconfig: -------------------------------------------------------------------------------- 1 | [color] 2 | diff = auto 3 | status = auto 4 | branch = auto 5 | [core] 6 | excludesfile = ~/.gitignore 7 | editor = code -w 8 | autocrlf = input 9 | pager = less -+$LESS -RSF 10 | [apply] 11 | whitespace = nowarn 12 | [format] 13 | pretty = %C(yellow)%h%Creset %s %C(red)(%an, %cr)%Creset 14 | [push] 15 | default = simple 16 | [merge "theirs"] 17 | driver = true 18 | [merge "ours"] 19 | driver = true 20 | [pull] 21 | rebase = false 22 | [pager] 23 | branch = false 24 | [init] 25 | defaultBranch = main 26 | -------------------------------------------------------------------------------- /plugins/rails.zsh: -------------------------------------------------------------------------------- 1 | # This is based on https://github.com/ohmyzsh/ohmyzsh 2 | 3 | # ALIASES 4 | 5 | alias rc='rails console' 6 | alias rdb='rails dbconsole' 7 | alias rdm='rails db:migrate' 8 | alias rdmd='rails db:migrate:down' 9 | alias rdmu='rails db:migrate:up' 10 | alias rdr='rails db:rollback' 11 | alias rgen='rails generate' 12 | alias rgm='rails generate migration' 13 | 14 | 15 | # RAILS COMMAND WRAPPER 16 | 17 | function _rails_command () { 18 | if [ -e "bin/rails" ]; then 19 | bin/rails $@ 20 | else 21 | command rails $@ 22 | fi 23 | } 24 | 25 | alias rails='_rails_command' 26 | # compdef _rails_command=rails 27 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ln -is $(readlink -f gemrc) ~/.gemrc 4 | ln -is $(readlink -f gitconfig) ~/.gitconfig 5 | ln -is $(readlink -f gitignore) ~/.gitignore 6 | ln -is $(readlink -f irbrc) ~/.irbrc 7 | ln -is $(readlink -f plugins) ~/.zsh-plugins 8 | 9 | cp -i $(readlink -f zshrc) ~/.zshrc 10 | 11 | read -p "Your Name for Git Commits: " git_name 12 | 13 | if [[ -n $git_name ]]; then 14 | read -p "Your Email for Git Commits: " git_email 15 | 16 | echo "" >> ~/.zshrc 17 | echo "# GIT CONFIG" >> ~/.zshrc 18 | echo "export GIT_AUTHOR_NAME=\"$git_name\"" >> ~/.zshrc 19 | echo "export GIT_AUTHOR_EMAIL=\"$git_email\"" >> ~/.zshrc 20 | echo "export GIT_COMMITTER_NAME=\"$git_name\"" >> ~/.zshrc 21 | echo "export GIT_COMMITTER_EMAIL=\"$git_email\"" >> ~/.zshrc 22 | 23 | echo "Git Name and Email have been appended to ~/.zshrc" 24 | fi 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Ryan Bates 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /plugins/bundler.zsh: -------------------------------------------------------------------------------- 1 | # This is based on https://github.com/ohmyzsh/ohmyzsh 2 | 3 | ## ALIASES 4 | 5 | alias be="bundle exec" 6 | 7 | 8 | ## GEM WRAPPER 9 | 10 | bundled_commands=( 11 | cap 12 | capify 13 | cucumber 14 | guard 15 | hanami 16 | irb 17 | jekyll 18 | pry 19 | puma 20 | rackup 21 | rake 22 | rspec 23 | rubocop 24 | sidekiq 25 | spring 26 | thin 27 | unicorn 28 | unicorn_rails 29 | ) 30 | 31 | # Check if in the root or a subdirectory of a bundled project 32 | _within-bundled-project() { 33 | local check_dir="$PWD" 34 | while [[ "$check_dir" != "/" ]]; do 35 | if [[ -f "$check_dir/Gemfile" || -f "$check_dir/gems.rb" ]]; then 36 | return 0 37 | fi 38 | check_dir="${check_dir:h}" 39 | done 40 | return 1 41 | } 42 | 43 | _run-with-bundler() { 44 | if (( ! $+commands[bundle] )) || ! _within-bundled-project; then 45 | "$@" 46 | return $? 47 | fi 48 | 49 | if [[ -f "./bin/${1}" ]]; then 50 | ./bin/${^^@} 51 | else 52 | bundle exec "$@" 53 | fi 54 | } 55 | 56 | for cmd in $bundled_commands; do 57 | # Create wrappers for bundled and unbundled execution 58 | eval "function unbundled_$cmd () { \"$cmd\" \"\$@\"; }" 59 | eval "function bundled_$cmd () { _run-with-bundler \"$cmd\" \"\$@\"; }" 60 | alias "$cmd"="bundled_$cmd" 61 | 62 | # Bind completion function to wrapped gem if available 63 | if (( $+functions[_$cmd] )); then 64 | compdef "_$cmd" "bundled_$cmd"="$cmd" 65 | fi 66 | done 67 | unset cmd bundled_commands 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ryan Bates Dot Files 2 | 3 | These are config files to set up Mac OS X command line the way I like it using [Zsh](https://www.zsh.org). 4 | 5 | For an older version that uses [Oh My Zsh](https://github.com/robbyrussell/oh-my-zsh), check out [this branch](https://github.com/ryanb/dotfiles/tree/oh-my-zsh). 6 | 7 | 8 | ## Installation 9 | 10 | Run the `bin/install` command to copy files over. It will prompt you before replacing if the files already exist. 11 | 12 | ```sh 13 | git clone git@github.com/ryanb/dotfiles ~/.dotfiles 14 | cd ~/.dotfiles 15 | ./bin/install 16 | ``` 17 | 18 | After installing, open a new terminal window to see the effects. 19 | 20 | Feel free to customize the .zshrc file to match your preference. 21 | 22 | 23 | ## Features 24 | 25 | I normally place all of my coding projects in ~/code, so this directory can easily be accessed (and tab completed) with the "c" command. 26 | 27 | ```sh 28 | c railsca 29 | ``` 30 | 31 | There is also an "h" command which behaves similar, but acts on the home path. 32 | 33 | ```sh 34 | h doc 35 | ``` 36 | 37 | If you're using git, you'll notice the current branch name shows up in the prompt while in a git repository. 38 | 39 | 40 | ## Uninstall 41 | 42 | To remove the dotfile configs, run the following commands. Be certain to double check the contents of the files before removing so you don't lose custom settings. 43 | 44 | ``` 45 | unlink ~/.bin 46 | unlink ~/.gitignore 47 | unlink ~/.gitconfig 48 | unlink ~/.gemrc 49 | unlink ~/.gvimrc 50 | unlink ~/.irbrc 51 | unlink ~/.vim 52 | unlink ~/.vimrc 53 | rm ~/.zshrc # careful here 54 | rm -rf ~/.dotfiles 55 | ``` 56 | 57 | Then open a new terminal window to see the effects. 58 | -------------------------------------------------------------------------------- /plugins/init.zsh: -------------------------------------------------------------------------------- 1 | autoload -U +X compinit && compinit 2 | autoload -U +X bashcompinit && bashcompinit 3 | 4 | setopt PROMPT_SUBST 5 | 6 | ## History command configuration 7 | setopt extended_history # record timestamp of command in HISTFILE 8 | setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE 9 | setopt hist_ignore_dups # ignore duplicated commands history list 10 | setopt hist_ignore_space # ignore commands that start with space 11 | setopt hist_verify # show command with history expansion to user before running it 12 | setopt share_history # share command history data 13 | 14 | 15 | # KEY BINDING 16 | 17 | # http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html 18 | 19 | # Make sure that the terminal is in application mode when zle is active, since 20 | # only then values from $terminfo are valid 21 | if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then 22 | function zle-line-init() { 23 | echoti smkx 24 | } 25 | function zle-line-finish() { 26 | echoti rmkx 27 | } 28 | zle -N zle-line-init 29 | zle -N zle-line-finish 30 | fi 31 | 32 | # Use emacs key bindings 33 | bindkey -e 34 | 35 | # Start typing + [Up-Arrow] - fuzzy find history forward 36 | if [[ -n "${terminfo[kcuu1]}" ]]; then 37 | autoload -U up-line-or-beginning-search 38 | zle -N up-line-or-beginning-search 39 | 40 | bindkey -M emacs "${terminfo[kcuu1]}" up-line-or-beginning-search 41 | bindkey -M viins "${terminfo[kcuu1]}" up-line-or-beginning-search 42 | bindkey -M vicmd "${terminfo[kcuu1]}" up-line-or-beginning-search 43 | fi 44 | 45 | # Start typing + [Down-Arrow] - fuzzy find history backward 46 | if [[ -n "${terminfo[kcud1]}" ]]; then 47 | autoload -U down-line-or-beginning-search 48 | zle -N down-line-or-beginning-search 49 | 50 | bindkey -M emacs "${terminfo[kcud1]}" down-line-or-beginning-search 51 | bindkey -M viins "${terminfo[kcud1]}" down-line-or-beginning-search 52 | bindkey -M vicmd "${terminfo[kcud1]}" down-line-or-beginning-search 53 | fi 54 | -------------------------------------------------------------------------------- /plugins/git.zsh: -------------------------------------------------------------------------------- 1 | # This is based on https://github.com/ohmyzsh/ohmyzsh 2 | 3 | # ALIASES 4 | 5 | alias ga='git add' 6 | alias gaa='git add --all' 7 | 8 | alias gb='git branch --sort=committerdate' 9 | 10 | alias gco='git checkout' 11 | 12 | alias gc='git commit --verbose' 13 | alias gca='git commit --verbose --all' 14 | alias gca!='git commit --verbose --all --amend' 15 | alias gcan!='git commit --verbose --all --no-edit --amend' 16 | alias gc!='git commit --verbose --amend' 17 | alias gcn!='git commit --verbose --no-edit --amend' 18 | 19 | alias gd='git diff' 20 | alias gdh='git diff HEAD' 21 | alias gdca='git diff --cached' 22 | alias gds='git diff --staged' 23 | 24 | alias grb='git rebase' 25 | alias grba='git rebase --abort' 26 | alias grbc='git rebase --continue' 27 | alias grbi='git rebase --interactive' 28 | 29 | alias grst='git restore --staged' 30 | 31 | alias gpristine='git reset --hard && git clean --force -dfx' 32 | alias groh='git reset origin/$(git_current_branch) --hard' 33 | 34 | alias gsh='git show' 35 | 36 | alias gst='git status' 37 | 38 | alias gstl='git stash list' 39 | alias gsta='git stash push' 40 | alias gstp='git stash pop' 41 | 42 | alias gsw='git switch' 43 | alias gswc='git switch --create' 44 | 45 | gfix() { 46 | git commit --fixup $1 && git rebase -i --autosquash $1^ 47 | } 48 | 49 | # FUNCTIONS 50 | 51 | # Outputs the name of the current branch 52 | # Usage example: git pull origin $(git_current_branch) 53 | # Using '--quiet' with 'symbolic-ref' will not cause a fatal error (128) if 54 | # it's not a symbolic ref, but in a Git repo. 55 | function git_current_branch() { 56 | local ref 57 | ref=$(git --no-optional-locks symbolic-ref --quiet HEAD 2> /dev/null) 58 | local ret=$? 59 | if [[ $ret != 0 ]]; then 60 | [[ $ret == 128 ]] && return # no git repo. 61 | ref=$(git --no-optional-locks rev-parse --short HEAD 2> /dev/null) || return 62 | fi 63 | echo ${ref#refs/heads/} 64 | } 65 | 66 | # Pass the prefix and suffix as first and second argument 67 | # Example: git_prompt_info [ ] 68 | function git_prompt_info() { 69 | # If we are on a folder not tracked by git, get out. 70 | if !git --no-optional-locks rev-parse --git-dir &> /dev/null; then 71 | return 0 72 | fi 73 | 74 | local ref 75 | ref=$(git --no-optional-locks symbolic-ref --short HEAD 2> /dev/null) \ 76 | || ref=$(git --no-optional-locks describe --tags --exact-match HEAD 2> /dev/null) \ 77 | || ref=$(git --no-optional-locks rev-parse --short HEAD 2> /dev/null) \ 78 | || return 0 79 | 80 | echo "$1${ref:gs/%/%%}$(git_dirty_info "*")$2" 81 | } 82 | 83 | # Checks if working tree is dirty 84 | # The argument passed in is printed when dirty 85 | # Example: git_dirty_info "*" 86 | function git_dirty_info() { 87 | local STATUS 88 | STATUS=$(git --no-optional-locks status --porcelain 2> /dev/null | tail -n 1) 89 | if [[ -n $STATUS ]]; then 90 | echo $1 91 | fi 92 | } 93 | --------------------------------------------------------------------------------