├── .agignore ├── .asdfrc ├── .config └── kitty │ └── kitty.conf ├── .ctags ├── .curlrc ├── .gemrc ├── .git_template └── hooks │ ├── ctags │ ├── post-checkout │ ├── post-commit │ ├── post-merge │ └── post-rewrite ├── .gitconfig ├── .gitignore ├── .gitignore_global ├── .gitmodules ├── .irbrc ├── .rspec ├── .tmux.conf ├── .tool-versions ├── .vim ├── after │ └── plugin │ │ └── vimrc_after.vim ├── plugin │ ├── autocmd.vim │ ├── common.vim │ ├── ctrlp.vim │ ├── format.vim │ ├── go.vim │ ├── goyo.vim │ ├── ruby.vim │ ├── settings │ │ ├── ctrl-p.vim │ │ ├── gist.vim │ │ ├── mappings.vim │ │ ├── nerdtree.vim │ │ └── zoomwin.vim │ ├── shortcuts.vim │ ├── tmux.vim │ ├── vimwiki.vim │ └── writing.vim ├── snippets │ ├── elixir.snippets │ ├── go.snippets │ ├── html.snippets │ ├── make.snippets │ ├── ruby.snippets │ ├── scss.snippets │ ├── sh.snippets │ └── zsh.snippets └── spell │ ├── en.utf-8.add │ └── en.utf-8.add.spl ├── .vimrc ├── .zshrc ├── Brewfile ├── README.md ├── bin ├── addr ├── argv ├── battery ├── chr ├── colordump ├── db-up ├── dc ├── ddns ├── e ├── esv ├── git-amend ├── git-churn ├── git-ci ├── git-conflicts ├── git-contributors ├── git-credential-envvar ├── git-credit ├── git-edit-conflicts ├── git-exclude ├── git-go ├── git-grab ├── git-nwo ├── git-outgoing ├── git-pr ├── git-prune-merged-branches ├── git-rank-contributors ├── git-rel ├── git-reup ├── git-sweep ├── git-thanks ├── git-undo ├── git-wtf ├── hint ├── hissuegram ├── intersect ├── ipsum ├── ish ├── iso8601 ├── license ├── lsrb ├── movieme ├── mx ├── new-tmux-project-window ├── osx ├── pkg-mgr ├── remote-clip ├── rfc ├── spark ├── tcolors ├── termcolors ├── tmux-github-status ├── tmux-ssh-split ├── treed ├── tusers └── unwrap ├── setup ├── asdf.sh └── vim.sh └── zsh ├── aliases.zsh ├── common.zsh ├── completion.sh ├── config.zsh ├── functions ├── _apex ├── _brew ├── _c ├── _docker-compose ├── _gcd ├── _gem ├── _git-rm ├── _rake ├── _yarn ├── c ├── last_modified ├── verbose_completion └── zsh_stats ├── git.zsh ├── go.zsh ├── homebrew.zsh ├── ruby.zsh ├── tmux.zsh └── window.zsh /.agignore: -------------------------------------------------------------------------------- 1 | log/* 2 | -------------------------------------------------------------------------------- /.asdfrc: -------------------------------------------------------------------------------- 1 | legacy_version_file = yes 2 | -------------------------------------------------------------------------------- /.ctags: -------------------------------------------------------------------------------- 1 | --languages=-javascript,sql 2 | --exclude=.git 3 | --langdef=css 4 | --langmap=css:.css 5 | --regex-css=/^[ \t]*([^\t {][^{]{1,100})(\t| )*{/\1/d,definition/ 6 | --langdef=scss 7 | --langmap=scss:.scss 8 | --regex-scss=/^[ \t]*([^\t {][^{]{1,100})(\t| )*{/| \1/d,definition/ 9 | -------------------------------------------------------------------------------- /.curlrc: -------------------------------------------------------------------------------- 1 | silent=true 2 | -------------------------------------------------------------------------------- /.gemrc: -------------------------------------------------------------------------------- 1 | install: --no-rdoc --no-ri 2 | update: --no-rdoc --no-ri 3 | -------------------------------------------------------------------------------- /.git_template/hooks/ctags: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | rm -f .git/tags 3 | ctags --tag-relative -Rf.git/tags 4 | -------------------------------------------------------------------------------- /.git_template/hooks/post-checkout: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | .git/hooks/ctags >/dev/null 2>&1 & 3 | -------------------------------------------------------------------------------- /.git_template/hooks/post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | .git/hooks/ctags >/dev/null 2>&1 & -------------------------------------------------------------------------------- /.git_template/hooks/post-merge: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | .git/hooks/ctags >/dev/null 2>&1 & -------------------------------------------------------------------------------- /.git_template/hooks/post-rewrite: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | case "$1" in 3 | rebase) exec .git/hooks/post-merge ;; 4 | esac -------------------------------------------------------------------------------- /.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | name = Wynn Netherland 3 | email = wynn.netherland@gmail.com 4 | signingkey = 8CE799D8B3EE3EE9 5 | [color] 6 | ui = auto 7 | [color "branch"] 8 | current = yellow reverse 9 | local = yellow 10 | remote = green 11 | [color "diff"] 12 | meta = yellow bold 13 | frag = magenta bold 14 | old = red bold 15 | new = green bold 16 | [color "status"] 17 | added = yellow 18 | changed = blue 19 | untracked = cyan 20 | [alias] 21 | # show all branches, even across remotes 22 | branches = branch -a --color -v 23 | # remove all local branches included in the current branch 24 | cleanup = !sh -c 'git branch --merged | grep -E "^[^*]" --exclude "^\\s*master" | xargs -n1 git branch -d' 25 | co = checkout 26 | ctags = !.git/hooks/ctags 27 | # Get short SHA-1 for object 28 | hash = rev-parse --short HEAD 29 | lc = log ORIG_HEAD.. --stat --no-merges 30 | # just for fun 31 | lol = log --graph --decorate --pretty=oneline --abbrev-commit 32 | lola = log --graph --decorate --pretty=oneline --abbrev-commit --all 33 | ls = ls-files 34 | mybranches = "!f() { if test $# = 0 ; then set -- refs/remotes ; fi ; git for-each-ref --format='%(authordate:relative)\t%(refname:short)\t%(authoremail)' --sort=authordate \"$@\" | sed -ne \"s/\t<$(git config user.email)>//p\" | column -s '\t' -t ; } ; f" 35 | # depends on hub 36 | mypulls = browse -- pulls/pengwynn 37 | safe = !mkdir -p .git/safe && echo "Repository marked safe!" 38 | # track a remote branch 39 | track = checkout -t 40 | # update all submodules 41 | subs = submodule foreach git pull origin master 42 | # clean up fully merged branches 43 | sweep = !git-sweep 44 | # list only untracked files 45 | untracked = ls-files --others --exclude-standard 46 | # remove a file from the index 47 | unstage = reset HEAD -- 48 | up = "!git remote update -p; git merge --ff-only @{u}" 49 | wdiff = diff --color-words 50 | wip = "!$EDITOR $(git ls-files -m)" 51 | 52 | ri = rebase -i --autosquash 53 | mri = rebase -i 54 | fix = commit --fixup 55 | squ = commit --squash 56 | 57 | [init] 58 | templatedir = ~/.git_template 59 | 60 | [push] 61 | default = upstream 62 | 63 | [hub] 64 | protocol = https 65 | 66 | [branch] 67 | 68 | [github] 69 | user = pengwynn 70 | 71 | [difftool] 72 | prompt = false 73 | 74 | [diff] 75 | tool = vimdiff 76 | 77 | [credential] 78 | helper = osxkeychain 79 | 80 | [web] 81 | browser = open 82 | 83 | [filter "media"] 84 | clean = git-media-clean %f 85 | smudge = git-media-smudge %f 86 | 87 | [core] 88 | excludesfile = ~/.gitignore_global 89 | 90 | ; [commit] 91 | ; gpgsign = true 92 | 93 | [gpg] 94 | program = /usr/local/bin/gpg 95 | 96 | # vim: ft=gitconfig sw=2 ts=2 et 97 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *_private.zsh 2 | *_creds.zsh 3 | .netrwhist 4 | vim/vim.symlink/bundle/** 5 | .vim/bundle 6 | plug.vim.old 7 | .vim/autoload/plug.vim 8 | -------------------------------------------------------------------------------- /.gitignore_global: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Thumbnails 4 | ._* 5 | 6 | # completion caches 7 | .rake_tasks 8 | 9 | # Files that might appear on external disk 10 | .Spotlight-V100 11 | .Trashes 12 | 13 | # Foreman 14 | .env 15 | 16 | .netrwhist 17 | 18 | # Gem builds 19 | pkg 20 | 21 | # Cached rake tasks 22 | .rake_tasks 23 | 24 | # per-project scratchpad 25 | .scratch 26 | 27 | # projectionist 28 | .projections.json 29 | 30 | .localrc 31 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "base16-shell"] 2 | path = base16-shell 3 | url = https://github.com/chriskempson/base16-shell.git 4 | [submodule "zsh/pure"] 5 | path = zsh/pure 6 | url = https://github.com/sindresorhus/pure 7 | -------------------------------------------------------------------------------- /.irbrc: -------------------------------------------------------------------------------- 1 | require 'irb/completion' 2 | require 'irb/ext/save-history' 3 | 4 | IRB.conf[:SAVE_HISTORY] = 1000 5 | 6 | if defined?(::Rails) 7 | IRB.conf[:HISTORY_FILE] = File.join(ENV['PWD'], '.irb-history') 8 | else 9 | IRB.conf[:HISTORY_FILE] = File.join(ENV['HOME'], '.irb-history') 10 | end 11 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color -------------------------------------------------------------------------------- /.tmux.conf: -------------------------------------------------------------------------------- 1 | # Don't lose ENV 2 | set -ga update-environment ' ITERM_PROFILE TMUX_STATUS_LEFT' 3 | set-window-option -g mode-keys vi 4 | 5 | set -g default-terminal "tmux-256color" 6 | set -g default-shell $SHELL 7 | 8 | ## keybindings 9 | unbind C-b 10 | unbind C-a 11 | unbind , 12 | unbind . 13 | unbind n 14 | unbind p 15 | unbind [ 16 | unbind '"' 17 | unbind l 18 | unbind & 19 | unbind "'" 20 | 21 | set-option -g prefix C-a # C-a for prefix just like screen 22 | 23 | bind-key C-a last-window 24 | 25 | bind-key + resize-pane -Z 26 | bind-key = resize-pane -Z 27 | bind-key | split-window -h 28 | bind-key \ split-window -h 29 | bind-key - split-window -v 30 | 31 | # windows and panes 32 | bind-key S command-prompt -p ssh: "new-window -n %1 'ssh %1'" 33 | bind-key u select-window -t :1 34 | bind-key W split-window -h \; choose-window 'kill-pane ; join-pane -hs %%' 35 | bind-key x kill-pane 36 | bind-key X kill-window 37 | bind-key q confirm-before kill-session 38 | bind-key Q confirm-before kill-server 39 | bind-key , previous-window # < 40 | bind-key . next-window # > 41 | bind-key < swap-window -t :- 42 | bind-key > swap-window -t :+ 43 | bind-key BSpace switch-client -l 44 | 45 | # vi mode 46 | bind-key -Tcopy-mode-vi 'v' send -X begin-selection 47 | bind-key -Tcopy-mode-vi 'y' send -X copy-selection 48 | 49 | # Smart pane switching with awareness of Vim splits 50 | # See: https://github.com/christoomey/vim-tmux-navigator 51 | is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ 52 | | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" 53 | bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L' 54 | bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D' 55 | bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U' 56 | bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R' 57 | tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")' 58 | if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \ 59 | "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'" 60 | if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \ 61 | "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'" 62 | 63 | bind-key -T copy-mode-vi 'C-h' select-pane -L 64 | bind-key -T copy-mode-vi 'C-j' select-pane -D 65 | bind-key -T copy-mode-vi 'C-k' select-pane -U 66 | bind-key -T copy-mode-vi 'C-l' select-pane -R 67 | bind-key -T copy-mode-vi 'C-\' select-pane -l 68 | 69 | # Bring back clear screen under tmux prefix 70 | bind C-l send-keys 'C-l' 71 | # Bring back kill line under tmux prefix 72 | bind C-k send-keys 'C-k' 73 | 74 | bind-key n command-prompt 'rename-window "%%"' 75 | bind-key N command-prompt 'rename-session "%%"' 76 | bind-key Escape copy-mode -u 77 | bind-key Up copy-mode -u 78 | bind-key r source-file $HOME/.tmux.conf\; display "The matrix has been reloaded" 79 | bind-key R refresh-client 80 | bind-key a send-key C-a 81 | # -r: can be repeated without pressing prefix# again (500ms after last '-r' action or prefix) 82 | bind-key -r h select-pane -t :.- 83 | bind-key -r l select-pane -t :.+ 84 | 85 | set -g history-limit 10000 86 | 87 | ## messages 88 | set-option -g message-style fg=colour0,bg=colour4 89 | set-option -g display-time 5000 90 | 91 | ## set status bar 92 | set-option -g status-interval 10 93 | set-option -g status-style fg=colour08,bg=colour0 94 | set-option -g status-left-style fg=colour0,bg=colour8 95 | set-option -g status-right-style bg=colour0 96 | bind-key / set-option status 97 | 98 | # "I' == current window index 99 | # 'H' == Hostname 100 | # 'F' == current window flag 101 | # 'P' == current pane index 102 | # 'S' == Session name 103 | # 'T' == current window title 104 | # 'W' == current window name 105 | # '#' == a literal "#" 106 | # Where appropriate, special character sequences may be prefixed with a 107 | # number to specify the maximum length, in this line "#10W'. 108 | set -g status-left "" 109 | set-option -g status-right '#(hostname) #[fg=colour3]#S#[fg=default] [#I:#P] /// #(battery -o tmux -m default -g default)#[fg=default]#(TZ="America/Chicago" date +"%%a %%d %%b %%H:%%M %%z" )' 110 | 111 | set-option -g status-right-length 100 112 | set-option -g status-left-length 120 113 | 114 | set-window-option -g window-status-format ' #I:#W ' 115 | set-window-option -g window-status-style default 116 | 117 | ## highlight active window 118 | set-window-option -g window-status-current-style fg=colour4,bg=default,bold 119 | set-window-option -g window-status-current-format '[ #I:#W ]' 120 | 121 | set-window-option -g window-status-bell-style fg=colour21,bg=colour9,blink 122 | 123 | # renumber windows 124 | set-option -g renumber-windows on 125 | 126 | # starts windows at 1 not 0 127 | set-option -g base-index 1 128 | 129 | set-option -g visual-activity off 130 | set-option -g set-titles on 131 | set-option -gw automatic-rename on 132 | set-option -gw monitor-activity off 133 | 134 | ## pane border and colors 135 | set-option -g pane-active-border-style fg=colour4,bg=default 136 | 137 | ## chooser colors 138 | set-window-option -g mode-style fg=black,bg=colour04 139 | 140 | set -g mouse on 141 | bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'" 142 | bind -n WheelDownPane select-pane -t= \; send-keys -M 143 | 144 | # vim: set ft=tmux: 145 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 2.5.3 2 | nodejs 8.12.0 3 | golang 1.12.7 4 | -------------------------------------------------------------------------------- /.vim/after/plugin/vimrc_after.vim: -------------------------------------------------------------------------------- 1 | if filereadable(expand("~/.vimrc.after")) 2 | source ~/.vimrc.after 3 | endif 4 | -------------------------------------------------------------------------------- /.vim/plugin/autocmd.vim: -------------------------------------------------------------------------------- 1 | " Automatically reload vimrc when it's saved 2 | autocmd! BufWritePost vimrc.symlink so ~/.vimrc 3 | 4 | " Show relative paths in buffer list 5 | autocmd BufReadPost * silent! lcd . 6 | 7 | " Help gf find some things 8 | autocmd Filetype javascript,typescript set path=.,src 9 | autocmd Filetype javascript,typescript set suffixesadd+=.ts,.tsx 10 | 11 | " Strip whitespace on save 12 | "autocmd BufWritePre * :%s/\s\+$//e 13 | 14 | " Filetype overrides 15 | " ================== 16 | 17 | autocmd! BufRead,BufNewFile *.jbuilder,Gemfile,Rakefile,Procfile,Guardfile setf ruby 18 | au BufRead,BufNewFile *.thor set filetype=ruby 19 | au BufRead,BufNewFile Guardfile set filetype=ruby 20 | au BufRead,BufNewFile */nginx/*.conf set filetype=nginx 21 | au BufRead,BufNewFile *.jbuilder setf ruby 22 | au BufRead,BufNewFile *.jeco setf html 23 | au BufRead,BufNewFile *.jss set filetype=css 24 | au BufRead,BufNewFile *.hbs set filetype=mustache 25 | au BufRead,BufNewFile *.md set filetype=markdown 26 | 27 | " Resize splits on window resize 28 | au VimResized * exe "normal! \=" 29 | 30 | " Markdown 31 | augroup markdown 32 | au! 33 | autocmd Syntax markdown setlocal textwidth=79 34 | if exists("&colorcolumn") 35 | autocmd Syntax markdown setlocal colorcolumn=80 36 | endif 37 | augroup END 38 | 39 | -------------------------------------------------------------------------------- /.vim/plugin/common.vim: -------------------------------------------------------------------------------- 1 | 2 | " Navigation 3 | " ========== 4 | " Move between wrapped lines as though they were physical lines. 5 | " noremap k gk 6 | " noremap j gj 7 | noremap g 8 | noremap g 9 | 10 | " Easier start & end of line. 11 | noremap H ^ 12 | nnoremap L $ 13 | vnoremap L $h 14 | 15 | " Selection 16 | " ========== 17 | " 18 | " select all 19 | map a ggVG 20 | 21 | " Go to matching symbol with tab 22 | nnoremap % 23 | vnoremap % 24 | 25 | 26 | " Windows 27 | " ========== 28 | 29 | " easier navigation between split windows 30 | nnoremap j 31 | nnoremap k 32 | nnoremap h 33 | nnoremap l 34 | 35 | " Toggle paste 36 | nnoremap p :set invpaste paste? 37 | set showmode 38 | 39 | " Toggle case 40 | nmap :set ignorecase! ignorecase? 41 | 42 | " Tagbar 43 | let g:tagbar_ctags_bin = '/opt/github/homebrew/bin/ctags' 44 | " Toggle tagbar 45 | nmap t :TagbarToggle 46 | 47 | " Yank from cursor to end of line 48 | nnoremap Y y$ 49 | 50 | " Select the text that was last edited/pasted. 51 | " http://vimcasts.org/episodes/bubbling-text/ 52 | nmap gV `[v`] 53 | 54 | " Use Vim settings, rather then Vi settings (much better!). 55 | " This must be first, because it changes other options as a side effect. 56 | set nocompatible 57 | inoremap jj 58 | 59 | " wrap current paragraph 60 | nnoremap w gqip 61 | 62 | " Duplicate a selection 63 | " Visual mode: D 64 | vmap D y'>p 65 | 66 | " Visual find/replace 67 | vnoremap "hy:%s/h//g 68 | 69 | " Remove whitespace 70 | map W :%s/\s\+$//e 71 | 72 | " Reselect visual block after indent/outdent 73 | vnoremap < >gv 75 | 76 | " Clear last search 77 | nnoremap :set hlsearch! hlsearch? 78 | 79 | " Allow saving of files as sudo when I forgot to start vim using sudo. 80 | cmap w!! %!sudo tee > /dev/null % 81 | 82 | " :Dispatch 83 | map d :Dispatch 84 | -------------------------------------------------------------------------------- /.vim/plugin/ctrlp.vim: -------------------------------------------------------------------------------- 1 | if executable('ag') 2 | " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore 3 | let g:ctrlp_user_command = 'ag %s --files-with-matches -g "" --ignore "\.git$\|\.hg$\|\.svn$"' 4 | 5 | " ag is fast enough that CtrlP doesn't need to cache 6 | let g:ctrlp_use_caching = 0 7 | endif 8 | -------------------------------------------------------------------------------- /.vim/plugin/format.vim: -------------------------------------------------------------------------------- 1 | " Reformat visual selection as JSON 2 | vnoremap j !jq '.' 3 | 4 | " Github => GitHub 5 | map gh :%s/Github/GitHub/g 6 | 7 | " Per-language tab settings 8 | " ========================= 9 | autocmd FileType go setlocal shiftwidth=4 tabstop=4 noexpandtab 10 | autocmd FileType * setlocal formatprg= 11 | 12 | 13 | " Neoformat 14 | " autocmd BufWritePre *.js,*.jsx Neoformat 15 | autocmd BufWritePre *.graphql Neoformat 16 | 17 | let g:ale_linter_aliases = {'svelte': ['css', 'javascript']} 18 | let g:ale_linter_aliases = {'jasmine': ['javascript']} 19 | let g:ale_linters = { 20 | \ 'javascript': ['eslint', 'prettier'], 21 | \ 'svelte': ['stylelint', 'eslint'], 22 | \ 'markdown': ['write-good'], 23 | \ 'typescript': ['eslint', 'tslint', 'tsserver'], 24 | \} 25 | 26 | let g:ale_fixers = { 27 | \ 'javascript': ['prettier'], 28 | \ 'svelte': ['prettier'], 29 | \ 'typescript': ['prettier', 'tslint'], 30 | \ 'ruby': ['rubocop'], 31 | \} 32 | let g:ale_enabled = 1 33 | highlight ALEWarning ctermbg=Yellow ctermfg=Red 34 | highlight ALEError ctermbg=Red ctermfg=LightRed 35 | 36 | let g:ale_sign_error = '=>' 37 | let g:ale_sign_warning = '->' 38 | let g:ale_statusline_format = ['✖ %d', '⚠ %d', ''] 39 | " let g:ale_completion_enabled = 1 40 | 41 | nnoremap ]r :ALENextWrap 42 | nnoremap [r :ALEPreviousWrap 43 | nnoremap f :ALEFix 44 | let g:neoformat_try_formatprg = 1 45 | 46 | let g:neoformat_sql_sqlfmt = { 47 | \ 'exe': 'sqlfmt', 48 | \ 'args': ['-u'], 49 | \ 'stdin': 1, 50 | \ } 51 | 52 | let g:neoformat_enabled_sql = ['sqlfmt'] 53 | 54 | let g:neoformat_typescriptreact_prettier = { 55 | \ 'exe': 'prettier', 56 | \ 'args': ['--stdin', '--stdin-filepath', '"%:p"', '--parser', 'typescript'], 57 | \ 'stdin': 1 58 | \ } 59 | let g:neoformat_enabled_typescriptreact = ['tsfmt', 'prettier'] 60 | let g:neoformat_svelte_prettier = { 61 | \ 'exe': 'prettier', 62 | \ 'args': ['--stdin', '--stdin-filepath', '"%:p"'], 63 | \ 'stdin': 1, 64 | \ } 65 | 66 | let g:neoformat_enabled_svelte = ['prettier'] 67 | 68 | let g:neoformat_jasmine_prettier = { 69 | \ 'exe': 'prettier', 70 | \ 'args': ['--stdin', '--stdin-filepath', '"%:p"'], 71 | \ 'stdin': 1, 72 | \ } 73 | 74 | let g:neoformat_enabled_jasmine = ['prettier'] 75 | 76 | let g:neoformat_liquid_prettier = { 77 | \ 'exe': 'prettier', 78 | \ 'args': ['--stdin', '--stdin-filepath', '"%:p"'], 79 | \ 'stdin': 1, 80 | \ } 81 | 82 | let g:neoformat_enabled_liquid = ['prettier'] 83 | 84 | let g:javascript_plugin_jsdoc = 1 85 | 86 | highlight Comment cterm=italic 87 | 88 | augroup mkjs_ft 89 | au! 90 | autocmd BufNewFile,BufRead *.mkjs set syntax=javascript 91 | augroup END 92 | 93 | " Liquid 94 | au BufNewFile,BufRead *.liquid set ft=liquid 95 | 96 | au BufNewFile,BufRead */_layouts/*.html,*/_includes/*.html set ft=liquid 97 | au BufNewFile,BufRead *.html,*.xml,*.textile 98 | \ if getline(1) == '---' | set ft=liquid | endif 99 | au BufNewFile,BufRead *.markdown,*.mkd,*.mkdn,*.md 100 | \ if getline(1) == '---' | 101 | \ let b:liquid_subtype = 'markdown' | 102 | \ set ft=liquid | 103 | \ endif 104 | -------------------------------------------------------------------------------- /.vim/plugin/go.vim: -------------------------------------------------------------------------------- 1 | " Show type info for the word under your cursor 2 | au FileType go nmap i (go-info) 3 | 4 | " Open the relevant Godoc for the word under the cursor 5 | au FileType go nmap gd (go-doc) 6 | au FileType go nmap gv (go-doc-vertical) 7 | 8 | " Or open the Godoc in browser 9 | au FileType go nmap gb (go-doc-browser) 10 | 11 | au FileType go nmap r (go-run) 12 | au FileType go nmap b (go-build) 13 | au FileType go nmap t (go-test) 14 | 15 | " Replace gd (Goto Declaration) for the word under your cursor (replaces 16 | " current buffer) 17 | au FileType go nmap gd (go-def) 18 | 19 | " Or open the definition/declaration in a new vertical, horizontal or tab for 20 | " the word under your cursor 21 | au FileType go nmap ds (go-def-split) 22 | au FileType go nmap dv (go-def-vertical) 23 | au FileType go nmap dt (go-def-tab) 24 | 25 | let g:go_fmt_fail_silently = 1 26 | let g:go_fmt_command = "gofmt" 27 | -------------------------------------------------------------------------------- /.vim/plugin/goyo.vim: -------------------------------------------------------------------------------- 1 | function! s:goyo_enter() 2 | silent !tmux set status off 3 | set noshowmode 4 | set noshowcmd 5 | set scrolloff=999 6 | Limelight 7 | " ... 8 | endfunction 9 | 10 | function! s:goyo_leave() 11 | silent !tmux set status on 12 | set showmode 13 | set showcmd 14 | set scrolloff=5 15 | Limelight! 16 | " ... 17 | endfunction 18 | 19 | autocmd! User GoyoEnter 20 | autocmd! User GoyoLeave 21 | autocmd User GoyoEnter nested call goyo_enter() 22 | autocmd User GoyoLeave nested call goyo_leave() 23 | 24 | map G :Goyo 25 | -------------------------------------------------------------------------------- /.vim/plugin/ruby.vim: -------------------------------------------------------------------------------- 1 | " Ruby 2 | " ========== 3 | 4 | " Run spec under current line 5 | nnoremap s :!bundle exec rake spec SPEC=%:=line('.') 6 | " Run current spec file 7 | nnoremap S :!bundle exec rake spec SPEC=% 8 | 9 | function! Privatize() 10 | let priorMethod = PriorMethodDefinition() 11 | exec "normal iprivate :" . priorMethod . "\==" 12 | endfunction 13 | 14 | function! PriorMethodDefinition() 15 | let lineNumber = search('def', 'bn') 16 | let line = getline(lineNumber) 17 | if line == 0 18 | echo "No prior method definition found" 19 | endif 20 | return matchlist(line, 'def \(\w\+\).*')[1] 21 | endfunction 22 | 23 | map p :call Privatize() 24 | -------------------------------------------------------------------------------- /.vim/plugin/settings/ctrl-p.vim: -------------------------------------------------------------------------------- 1 | let g:ctrlp_max_height = 5 2 | let g:ctrlp_dotfiles = 1 3 | "let g:ctrlp_max_depth = 40 4 | -------------------------------------------------------------------------------- /.vim/plugin/settings/gist.vim: -------------------------------------------------------------------------------- 1 | let g:gist_clip_command = 'pbcopy' 2 | let g:gist_open_browser_after_post = 1 3 | let g:gist_show_privates = 1 4 | let g:github_token = $GITHUB_TOKEN 5 | -------------------------------------------------------------------------------- /.vim/plugin/settings/mappings.vim: -------------------------------------------------------------------------------- 1 | " Insert Mode 2 | inoremap jk 3 | -------------------------------------------------------------------------------- /.vim/plugin/settings/nerdtree.vim: -------------------------------------------------------------------------------- 1 | map n :NERDTreeToggle 2 | let NERDTreeMinimalUI = 1 3 | let NERDTreeDirArrows = 1 4 | let g:NERDTreeWinSize = 30 5 | -------------------------------------------------------------------------------- /.vim/plugin/settings/zoomwin.vim: -------------------------------------------------------------------------------- 1 | map :ZoomWin 2 | -------------------------------------------------------------------------------- /.vim/plugin/shortcuts.vim: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengwynn/dotfiles/30a8087059deefaad95847c0c3edc057b1c65fba/.vim/plugin/shortcuts.vim -------------------------------------------------------------------------------- /.vim/plugin/tmux.vim: -------------------------------------------------------------------------------- 1 | let g:tmux_is_last_pane = 0 2 | au WinEnter * let g:tmux_is_last_pane = 0 3 | 4 | " Like `wincmd` but also change tmux panes instead of vim windows when needed. 5 | function! TmuxWinCmd(direction) 6 | let nr = winnr() 7 | let tmux_last_pane = (a:direction == 'p' && g:tmux_is_last_pane) 8 | if !tmux_last_pane 9 | " try to switch windows within vim 10 | exec 'wincmd ' . a:direction 11 | endif 12 | " Forward the switch panes command to tmux if: 13 | " a) we're toggling between the last tmux pane; 14 | " b) we tried switching windows in vim but it didn't have effect. 15 | if tmux_last_pane || nr == winnr() 16 | let cmd = 'tmux select-pane -' . tr(a:direction, 'phjkl', 'lLDUR') 17 | call system(cmd) 18 | redraw! " because `exec` fucked up the screen. why is this needed?? arrghh 19 | let g:tmux_is_last_pane = 1 20 | else 21 | let g:tmux_is_last_pane = 0 22 | endif 23 | endfunction 24 | 25 | " navigate between split windows/tmux panes 26 | nmap :call TmuxWinCmd('j') 27 | nmap :call TmuxWinCmd('k') 28 | nmap :call TmuxWinCmd('h') 29 | nmap :call TmuxWinCmd('l') 30 | nmap :call TmuxWinCmd('p') 31 | -------------------------------------------------------------------------------- /.vim/plugin/vimwiki.vim: -------------------------------------------------------------------------------- 1 | " vimwiki/vimwiki 2 | 3 | let work = {} 4 | let work.path = '~/notes' 5 | let work.syntax = 'markdown' 6 | let work.ext = '.md' 7 | let work.diary_rel_path = 'log/' 8 | 9 | let personal = {} 10 | let personal.path = '~/brain' 11 | let personal.syntax = 'markdown' 12 | let personal.ext = '.md' 13 | let personal.diary_rel_path = 'journal/' 14 | 15 | let g:vimwiki_list = [personal, work] 16 | -------------------------------------------------------------------------------- /.vim/plugin/writing.vim: -------------------------------------------------------------------------------- 1 | " Highlight words to avoid in tech writing 2 | " ======================================= 3 | " 4 | " obviously, basically, simply, of course, clearly, 5 | " just, everyone knows, However, So, easy 6 | 7 | " http://css-tricks.com/words-avoid-educational-writing/ 8 | 9 | highlight TechWordsToAvoid ctermbg=red ctermfg=white 10 | function! MatchTechWordsToAvoid() 11 | match TechWordsToAvoid /\c\<\(obviously\|basically\|simply\|of\scourse\|clearly\|just\|everyone\sknows\|however\|so,\|easy\)\>/ 12 | endfunction 13 | autocmd FileType markdown call MatchTechWordsToAvoid() 14 | autocmd BufWinEnter *.md call MatchTechWordsToAvoid() 15 | autocmd InsertEnter *.md call MatchTechWordsToAvoid() 16 | autocmd InsertLeave *.md call MatchTechWordsToAvoid() 17 | autocmd BufWinLeave *.md call clearmatches() 18 | autocmd FileType asciidoc nnoremap z :silent exec '!open -a Firefox %:p &' | exec ':redraw!' 19 | 20 | command! -nargs=* Wrap set wrap linebreak nolist 21 | 22 | " VimWiki 23 | nmap ts :.! TZ='America/Chicago' date -R 24 | -------------------------------------------------------------------------------- /.vim/snippets/elixir.snippets: -------------------------------------------------------------------------------- 1 | snippet do 2 | do 3 | ${0:${VISUAL}} 4 | end 5 | snippet put IO.puts 6 | IO.puts "${0}" 7 | snippet ins IO.inspect 8 | IO.inspect ${0} 9 | snippet insl IO.inspect with label 10 | IO.inspect(${0}label: "${1:label}") 11 | snippet if if .. do .. end 12 | if ${1} do 13 | ${0:${VISUAL}} 14 | end 15 | snippet if: if .. do: .. 16 | if ${1:condition}, do: ${0} 17 | snippet ife if .. do .. else .. end 18 | if ${1:condition} do 19 | ${2:${VISUAL}} 20 | else 21 | ${0} 22 | end 23 | snippet ife: if .. do: .. else: 24 | if ${1:condition}, do: ${2}, else: ${0} 25 | snippet unless unless .. do .. end 26 | unless ${1} do 27 | ${0:${VISUAL}} 28 | end 29 | snippet unless: unless .. do: .. 30 | unless ${1:condition}, do: ${0} 31 | snippet unlesse unless .. do .. else .. end 32 | unless ${1:condition} do 33 | ${2:${VISUAL}} 34 | else 35 | ${0} 36 | end 37 | snippet unlesse: unless .. do: .. else: 38 | unless ${1:condition}, do: ${2}, else: ${0} 39 | snippet cond 40 | cond do 41 | ${1} -> 42 | ${0:${VISUAL}} 43 | end 44 | snippet case 45 | case ${1} do 46 | ${2} -> 47 | ${0} 48 | end 49 | snippet for 50 | for ${1:item} <- ${2:items} do 51 | ${0} 52 | end 53 | snippet for: 54 | for ${1:item} <- ${2:items}, do: ${0} 55 | snippet fori 56 | for ${1:item} <- ${2:items}, into: ${3} do 57 | ${0} 58 | end 59 | snippet wi 60 | with ${1:item} <- ${2:items} do 61 | ${0} 62 | end 63 | snippet wie 64 | with( 65 | ${1:item} <- ${2:items} 66 | ) do 67 | ${3} 68 | else 69 | ${4} -> 70 | ${0} 71 | end 72 | snippet sp 73 | @spec ${1:name}(${2:args}) :: ${3:returns} 74 | snippet op 75 | @opaque ${1:type_name} :: ${2:type} 76 | snippet ty 77 | @type ${1:type_name} :: ${2:type} 78 | snippet typ 79 | @typep ${1:type_name} :: ${2:type} 80 | snippet cb 81 | @callback ${1:name}(${2:args}) :: ${3:returns} 82 | snippet df 83 | def ${1:name}, do: ${2} 84 | snippet def 85 | def ${1:name} do 86 | ${0} 87 | end 88 | snippet defd 89 | @doc """ 90 | ${1:doc string} 91 | 92 | """ 93 | def ${2:name} do 94 | ${0} 95 | end 96 | snippet defsd 97 | @doc """ 98 | ${1:doc string} 99 | 100 | """ 101 | @spec ${2:name} :: ${3:no_return} 102 | def ${2} do 103 | ${0} 104 | end 105 | snippet defim 106 | defimpl ${1:protocol_name}, for: ${2:data_type} do 107 | ${0} 108 | end 109 | snippet defma 110 | defmacro ${1:name} do 111 | ${0} 112 | end 113 | snippet defmo 114 | defmodule ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} do 115 | ${0} 116 | end 117 | snippet dfp 118 | defp ${1:name}, do: ${2} 119 | snippet defp 120 | defp ${1:name} do 121 | ${0} 122 | end 123 | snippet defpr 124 | defprotocol ${1:name}, [${0:function}] 125 | snippet defr 126 | defrecord ${1:record_name}, ${0:fields} 127 | snippet doc 128 | @doc """ 129 | ${0} 130 | 131 | """ 132 | snippet docf 133 | @doc false 134 | snippet fn 135 | fn ${1:args} -> ${0} end 136 | snippet mdoc 137 | @moduledoc """ 138 | ${0} 139 | 140 | """ 141 | snippet mdocf 142 | @moduledoc false 143 | snippet rec 144 | receive do 145 | ${1} -> 146 | ${0} 147 | end 148 | snippet req 149 | require ${0:module_name} 150 | snippet imp 151 | import ${0:module_name} 152 | snippet ali 153 | alias ${0:module_name} 154 | snippet test 155 | test "${1:test name}" do 156 | ${0} 157 | end 158 | snippet testa 159 | test "${1:test_name}", %{${2:arg: arg}} do 160 | ${0} 161 | end 162 | snippet des 163 | describe "${1:test group subject}" do 164 | ${0} 165 | end 166 | snippet exunit 167 | defmodule ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} do 168 | use ExUnit.Case, async: true 169 | 170 | ${0} 171 | end 172 | snippet try try .. rescue .. end 173 | try do 174 | ${1:${VISUAL}} 175 | rescue 176 | ${2} -> ${0} 177 | end 178 | snippet pry 179 | require IEx; IEx.pry 180 | ${0} 181 | snippet qu 182 | quote do 183 | ${1} 184 | end 185 | snippet beh 186 | @behaviour ${1:Mix.Task} 187 | ${0} 188 | snippet >e pipe to each 189 | |> Enum.each(fn ${1} -> ${0} end) 190 | snippet >m pipe to map 191 | |> Enum.map(fn ${1} -> ${0} end) 192 | snippet >f pipe to filter 193 | |> Enum.filter(fn ${1} -> ${0} end) 194 | snippet >r pipe to reduce 195 | |> Enum.reduce(${1:acc}, fn ${2}, ${3:acc} -> ${0} end) 196 | snippet >i pipe to inspect 197 | |> IO.inspect 198 | snippet >il pipe to inspect with label 199 | |> IO.inspect(label: "${1:label}") 200 | -------------------------------------------------------------------------------- /.vim/snippets/go.snippets: -------------------------------------------------------------------------------- 1 | # shorthand variable declaration 2 | snippet v 3 | ${1} := ${2} 4 | # variable initialization 5 | snippet vr 6 | var ${1:t} ${0:string} 7 | # variable declaration 8 | snippet var 9 | var ${1} ${2} = ${3} 10 | # variables declaration 11 | snippet vars 12 | var ( 13 | ${1} ${2} = ${3} 14 | ) 15 | # append 16 | snippet ap 17 | append(${1:slice}, ${0:value}) 18 | # bool 19 | snippet bl 20 | bool 21 | # byte 22 | snippet bt 23 | byte 24 | # break 25 | snippet br 26 | break 27 | # channel 28 | snippet ch 29 | chan ${0:int} 30 | # case 31 | snippet cs 32 | case ${1:value}: 33 | ${0:${VISUAL}} 34 | # const 35 | snippet c 36 | const ${1:NAME} = ${0:0} 37 | # constants with iota 38 | snippet co 39 | const ( 40 | ${1:NAME1} = iota 41 | ${0:NAME2} 42 | ) 43 | # continue 44 | snippet cn 45 | continue 46 | # defer 47 | snippet df 48 | defer ${0:func}() 49 | # defer recover 50 | snippet dfr 51 | defer func() { 52 | if err := recover(); err != nil { 53 | ${0:${VISUAL}} 54 | } 55 | }() 56 | # int 57 | snippet i 58 | int 59 | # import 60 | snippet im 61 | import ( 62 | "${1:package}" 63 | ) 64 | # interface 65 | snippet in 66 | interface{} 67 | # full interface snippet 68 | snippet inf 69 | interface ${1:name} { 70 | ${2:/* methods */} 71 | } 72 | # if condition 73 | snippet if 74 | if ${1:/* condition */} { 75 | ${2:${VISUAL}} 76 | } 77 | snippet ife 78 | if ${1:/* condition */} { 79 | ${2:${VISUAL}} 80 | } else { 81 | ${0} 82 | } 83 | # else snippet 84 | snippet el 85 | else { 86 | ${0:${VISUAL}} 87 | } 88 | # error snippet 89 | snippet ir 90 | if err != nil { 91 | return err 92 | } 93 | ${0} 94 | # false 95 | snippet f 96 | false 97 | # fallthrough 98 | snippet ft 99 | fallthrough 100 | # float 101 | snippet fl 102 | float32 103 | # float32 104 | snippet f3 105 | float32 106 | # float64 107 | snippet f6 108 | float64 109 | # for int loop 110 | snippet for 111 | for ${1}{ 112 | ${0:${VISUAL}} 113 | } 114 | # for int loop 115 | snippet fori 116 | for ${2:i} := 0; $2 < ${1:count}; $2${3:++} { 117 | ${0:${VISUAL}} 118 | } 119 | # for range loop 120 | snippet forr 121 | for ${1:e} := range ${2:collection} { 122 | ${0:${VISUAL}} 123 | } 124 | # function simple 125 | snippet fun 126 | func ${1:funcName}(${2}) ${3:error} { 127 | ${4} 128 | } 129 | ${0} 130 | # function on receiver 131 | snippet fum 132 | func (${1:receiver} ${2:type}) ${3:funcName}(${4}) ${5:error} { 133 | ${6} 134 | } 135 | ${0} 136 | # log printf 137 | snippet lf 138 | log.Printf("%${1:s}", ${2:var}) 139 | # log printf 140 | snippet lp 141 | log.Println("${1}") 142 | # make 143 | snippet mk 144 | make(${1:[]string}, ${0:0}) 145 | # map 146 | snippet mp 147 | map[${1:string}]${0:int} 148 | # main() 149 | snippet main 150 | func main() { 151 | ${1} 152 | } 153 | ${0} 154 | # new 155 | snippet nw 156 | new(${0:type}) 157 | # package 158 | snippet pa 159 | package ${1:main} 160 | # panic 161 | snippet pn 162 | panic("${0:msg}") 163 | # print 164 | snippet pr 165 | fmt.Printf("%${1:s}\n", ${2:var}) 166 | # println 167 | snippet pl 168 | fmt.Println("${1:s}") 169 | # range 170 | snippet rn 171 | range ${0} 172 | # return 173 | snippet rt 174 | return ${0} 175 | # result 176 | snippet rs 177 | result 178 | # select 179 | snippet sl 180 | select { 181 | case ${1:v1} := <-${2:chan1} 182 | ${3} 183 | default: 184 | ${0} 185 | } 186 | # string 187 | snippet sr 188 | string 189 | # struct 190 | snippet st 191 | struct ${1:name} { 192 | ${2:/* data */} 193 | } 194 | ${0} 195 | # switch 196 | snippet sw 197 | switch ${1:var} { 198 | case ${2:value1}: 199 | ${3} 200 | case ${4:value2}: 201 | ${5} 202 | default: 203 | ${0} 204 | } 205 | snippet sp 206 | fmt.Sprintf("%${1:s}", ${2:var}) 207 | # true 208 | snippet t 209 | true 210 | # goroutine named function 211 | snippet g 212 | go ${1:funcName}(${0}) 213 | # goroutine anonymous function 214 | snippet ga 215 | go func(${1} ${2:type}) { 216 | ${3:/* code */} 217 | }(${0}) 218 | snippet test test function 219 | func Test${1:name}(t *testing.T) { 220 | ${0:${VISUAL}} 221 | } 222 | snippet bench benchmark function 223 | func Benchmark${1:name}(b *testing.B) { 224 | for i := 0; i < b.N; i++ { 225 | ${2} 226 | } 227 | } 228 | ${0} 229 | # composite literals 230 | snippet cl 231 | type ${1:name} struct { 232 | ${2:attrName} ${3:attrType} 233 | } 234 | # if key in a map 235 | snippet om 236 | if ${1:value}, ok := ${2:map}[${3:key}]; ok == true { 237 | ${4:/* code */} 238 | } 239 | 240 | # Grouped globals with anonymous struct 241 | snippet gg 242 | var ${1:var} = struct{ 243 | ${2:name} ${3:type} 244 | }{ 245 | $2: ${4:value}, 246 | } 247 | 248 | # Marshalable json alias 249 | snippet ja 250 | type ${1:parentType}Alias $1 251 | 252 | func (p *$1) MarshalJSON() ([]byte, error) { 253 | return json.Marshal(&struct{ *$1Alias }{(*$1Alias)(p)}) 254 | } 255 | -------------------------------------------------------------------------------- /.vim/snippets/make.snippets: -------------------------------------------------------------------------------- 1 | # base 2 | snippet base 3 | .PHONY: clean, mrproper 4 | CC = gcc 5 | CFLAGS = -g -Wall 6 | 7 | all: $1 8 | 9 | %.o: %.c 10 | $(CC) $(CFLAGS) -c -o $@ $< 11 | 12 | ${1:out}: $1.o 13 | $(CC) $(CFLAGS) -o $@ $+ 14 | 15 | clean: 16 | rm -f *.o core.* 17 | 18 | mrproper: clean 19 | rm -f $1 20 | # add 21 | snippet add 22 | ${1:out}: $1.o 23 | $(CC) $(CFLAGS) -o $@ $+ 24 | # print 25 | snippet print 26 | print-%: ; @echo $*=$($*) 27 | # ifeq 28 | snippet if 29 | ifeq (${1:cond0}, ${2:cond1}) 30 | ${0:${VISUAL}} 31 | endif 32 | # ifeq ... else ... endif 33 | snippet ife 34 | ifeq (${1:cond0}, ${2:cond1}) 35 | ${3:${VISUAL}} 36 | else 37 | ${0} 38 | endif 39 | # else ... 40 | snippet el 41 | else 42 | ${0:${VISUAL}} 43 | # .DEFAULT_GOAL := target 44 | snippet default 45 | .DEFAULT_GOAL := ${1} 46 | # help target for self-documented Makefile 47 | snippet help 48 | help: ## Prints help for targets with comments 49 | @cat $(MAKEFILE_LIST) | grep -E '^[a-zA-Z_-]+:.*?## .*$$' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $\$1, $\$2}' 50 | ${0} 51 | -------------------------------------------------------------------------------- /.vim/snippets/ruby.snippets: -------------------------------------------------------------------------------- 1 | snippet enc 2 | # encoding: utf-8 3 | snippet frozen 4 | # frozen_string_literal: true 5 | snippet #! 6 | #!/usr/bin/env ruby 7 | # New Block 8 | snippet =b 9 | =begin rdoc 10 | ${0} 11 | =end 12 | snippet prot 13 | protected 14 | 15 | ${0} 16 | snippet priv 17 | private 18 | 19 | ${0} 20 | snippet y 21 | :yields: ${0:arguments} 22 | snippet rb 23 | #!/usr/bin/env ruby -wKU 24 | snippet beg 25 | begin 26 | ${0} 27 | rescue ${1:Exception} => ${2:e} 28 | end 29 | snippet req require 30 | require '${1}' 31 | snippet reqr 32 | require_relative '${1}' 33 | snippet # 34 | # => 35 | snippet case 36 | case ${1:object} 37 | when ${2:condition} 38 | ${0} 39 | end 40 | snippet when 41 | when ${1:condition} 42 | ${0:${VISUAL}} 43 | snippet def 44 | def ${1:method_name} 45 | ${0} 46 | end 47 | snippet deft 48 | def test_${1:case_name} 49 | ${0} 50 | end 51 | snippet descendants 52 | class Class 53 | def descendants 54 | ObjectSpace.each_object(::Class).select { |klass| klass < self } 55 | end 56 | end 57 | snippet if 58 | if ${1:condition} 59 | ${0:${VISUAL}} 60 | end 61 | snippet ife 62 | if ${1:condition} 63 | ${2:${VISUAL}} 64 | else 65 | ${0} 66 | end 67 | snippet eif 68 | elsif ${1:condition} 69 | ${0:${VISUAL}} 70 | snippet ifee 71 | if ${1:condition} 72 | $2 73 | elsif ${3:condition} 74 | $4 75 | else 76 | $0 77 | end 78 | snippet unless 79 | unless ${1:condition} 80 | ${0:${VISUAL}} 81 | end 82 | snippet unlesse 83 | unless ${1:condition} 84 | $2 85 | else 86 | $0 87 | end 88 | snippet unlesee 89 | unless ${1:condition} 90 | $2 91 | elsif ${3:condition} 92 | $4 93 | else 94 | $0 95 | end 96 | snippet wh 97 | while ${1:condition} 98 | ${0:${VISUAL}} 99 | end 100 | snippet for 101 | for ${1:e} in ${2:c} 102 | ${0} 103 | end 104 | snippet until 105 | until ${1:condition} 106 | ${0:${VISUAL}} 107 | end 108 | snippet cla class .. end 109 | class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} 110 | ${0} 111 | end 112 | snippet clai class .. initialize .. end 113 | class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} 114 | def initialize(${2:args}) 115 | ${0} 116 | end 117 | end 118 | snippet cla< class .. < ParentClass .. initialize .. end 119 | class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < ${2:ParentClass} 120 | def initialize(${3:args}) 121 | ${0} 122 | end 123 | end 124 | snippet blankslate class BlankSlate .. initialize .. end 125 | class ${0:BlankSlate} 126 | instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ } 127 | end 128 | snippet claself class << self .. end 129 | class << ${1:self} 130 | ${0} 131 | end 132 | # class .. < DelegateClass .. initialize .. end 133 | snippet cla- 134 | class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < DelegateClass(${2:ParentClass}) 135 | def initialize(${3:args}) 136 | super(${4:del_obj}) 137 | 138 | ${0} 139 | end 140 | end 141 | snippet mod module .. end 142 | module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} 143 | ${0} 144 | end 145 | # attr_reader 146 | snippet r 147 | attr_reader :${0:attr_names} 148 | # attr_writer 149 | snippet w 150 | attr_writer :${0:attr_names} 151 | # attr_accessor 152 | snippet rw 153 | attr_accessor :${0:attr_names} 154 | snippet atp 155 | attr_protected :${0:attr_names} 156 | snippet ata 157 | attr_accessible :${0:attr_names} 158 | snippet ana 159 | accepts_nested_attributes_for :${0:association} 160 | # ivc == instance variable cache 161 | snippet ivc 162 | @${1:variable_name} ||= ${0:cached_value} 163 | # include Enumerable 164 | snippet Enum 165 | include Enumerable 166 | 167 | def each(&block) 168 | ${0} 169 | end 170 | # include Comparable 171 | snippet Comp 172 | include Comparable 173 | 174 | def <=>(other) 175 | ${0} 176 | end 177 | # extend Forwardable 178 | snippet Forw- 179 | extend Forwardable 180 | # def self 181 | snippet defs 182 | def self.${1:class_method_name} 183 | ${0} 184 | end 185 | # def initialize 186 | snippet definit 187 | def initialize(${1:args}) 188 | ${0} 189 | end 190 | # def method_missing 191 | snippet defmm 192 | def method_missing(meth, *args, &blk) 193 | ${0} 194 | end 195 | snippet defd 196 | def_delegator :${1:@del_obj}, :${2:del_meth}, :${0:new_name} 197 | snippet defds 198 | def_delegators :${1:@del_obj}, :${0:del_methods} 199 | snippet am 200 | alias_method :${1:new_name}, :${0:old_name} 201 | snippet app 202 | if __FILE__ == $PROGRAM_NAME 203 | ${0} 204 | end 205 | # usage_if() 206 | snippet usai 207 | if ARGV.${1} 208 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${0} 209 | end 210 | # usage_unless() 211 | snippet usau 212 | unless ARGV.${1} 213 | abort "Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}"${0} 214 | end 215 | snippet array 216 | Array.new(${1:10}) { |${2:i}| ${0} } 217 | snippet hash 218 | Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${0} } 219 | snippet file File.foreach() { |line| .. } 220 | File.foreach(${1:'path/to/file'}) { |${2:line}| ${0} } 221 | snippet file File.read() 222 | File.read(${1:'path/to/file'}) 223 | snippet Dir Dir.global() { |file| .. } 224 | Dir.glob(${1:'dir/glob/*'}) { |${2:file}| ${0} } 225 | snippet Dir Dir[".."] 226 | Dir[${1:'glob/**/*.rb'}] 227 | snippet dir 228 | Filename.dirname(__FILE__) 229 | snippet deli 230 | delete_if { |${1:e}| ${0} } 231 | snippet fil 232 | fill(${1:range}) { |${2:i}| ${0} } 233 | # flatten_once() 234 | snippet flao 235 | reduce(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2) } 236 | snippet zip 237 | zip(${1:enums}) { |${2:row}| ${0} } 238 | # downto(0) { |n| .. } 239 | snippet dow 240 | downto(${1:0}) { |${2:n}| ${0} } 241 | snippet ste 242 | step(${1:2}) { |${2:n}| ${0} } 243 | snippet tim 244 | times { |${1:n}| ${0} } 245 | snippet upt 246 | upto(${1:1.0/0.0}) { |${2:n}| ${0} } 247 | snippet loo 248 | loop { ${0} } 249 | snippet ea 250 | each { |${1:e}| ${0} } 251 | snippet ead 252 | each do |${1:e}| 253 | ${0} 254 | end 255 | snippet eab 256 | each_byte { |${1:byte}| ${0} } 257 | snippet eac- each_char { |chr| .. } 258 | each_char { |${1:chr}| ${0} } 259 | snippet eac- each_cons(..) { |group| .. } 260 | each_cons(${1:2}) { |${2:group}| ${0} } 261 | snippet eai 262 | each_index { |${1:i}| ${0} } 263 | snippet eaid 264 | each_index do |${1:i}| 265 | ${0} 266 | end 267 | snippet eak 268 | each_key { |${1:key}| ${0} } 269 | snippet eakd 270 | each_key do |${1:key}| 271 | ${0} 272 | end 273 | snippet eal 274 | each_line { |${1:line}| ${0} } 275 | snippet eald 276 | each_line do |${1:line}| 277 | ${0} 278 | end 279 | snippet eap 280 | each_pair { |${1:name}, ${2:val}| ${0} } 281 | snippet eapd 282 | each_pair do |${1:name}, ${2:val}| 283 | ${0} 284 | end 285 | snippet eas- 286 | each_slice(${1:2}) { |${2:group}| ${0} } 287 | snippet easd- 288 | each_slice(${1:2}) do |${2:group}| 289 | ${0} 290 | end 291 | snippet eav 292 | each_value { |${1:val}| ${0} } 293 | snippet eavd 294 | each_value do |${1:val}| 295 | ${0} 296 | end 297 | snippet eawi 298 | each_with_index { |${1:e}, ${2:i}| ${0} } 299 | snippet eawid 300 | each_with_index do |${1:e}, ${2:i}| 301 | ${0} 302 | end 303 | snippet eawo 304 | each_with_object(${1:init}) { |${2:e}, ${3:var}| ${0} } 305 | snippet eawod 306 | each_with_object(${1:init}) do |${2:e}, ${3:var}| 307 | ${0} 308 | end 309 | snippet reve 310 | reverse_each { |${1:e}| ${0} } 311 | snippet reved 312 | reverse_each do |${1:e}| 313 | ${0} 314 | end 315 | snippet inj 316 | inject(${1:init}) { |${2:mem}, ${3:var}| ${0} } 317 | snippet injd 318 | inject(${1:init}) do |${2:mem}, ${3:var}| 319 | ${0} 320 | end 321 | snippet red 322 | reduce(${1:init}) { |${2:mem}, ${3:var}| ${0} } 323 | snippet redd 324 | reduce(${1:init}) do |${2:mem}, ${3:var}| 325 | ${0} 326 | end 327 | snippet map 328 | map { |${1:e}| ${0} } 329 | snippet mapd 330 | map do |${1:e}| 331 | ${0} 332 | end 333 | snippet mapwi- 334 | enum_with_index.map { |${1:e}, ${2:i}| ${0} } 335 | snippet sor 336 | sort { |a, b| ${0} } 337 | snippet sorb 338 | sort_by { |${1:e}| ${0} } 339 | snippet ran 340 | sort_by { rand } 341 | snippet all 342 | all? { |${1:e}| ${0} } 343 | snippet any 344 | any? { |${1:e}| ${0} } 345 | snippet cl 346 | classify { |${1:e}| ${0} } 347 | snippet col 348 | collect { |${1:e}| ${0} } 349 | snippet cold 350 | collect do |${1:e}| 351 | ${0} 352 | end 353 | snippet det 354 | detect { |${1:e}| ${0} } 355 | snippet detd 356 | detect do |${1:e}| 357 | ${0} 358 | end 359 | snippet fet 360 | fetch(${1:name}) { |${2:key}| ${0} } 361 | snippet fin 362 | find { |${1:e}| ${0} } 363 | snippet find 364 | find do |${1:e}| 365 | ${0} 366 | end 367 | snippet fina 368 | find_all { |${1:e}| ${0} } 369 | snippet finad 370 | find_all do |${1:e}| 371 | ${0} 372 | end 373 | snippet gre 374 | grep(${1:/pattern/}) { |${2:match}| ${0} } 375 | snippet sub 376 | ${1:g}sub(${2:/pattern/}) { |${3:match}| ${0} } 377 | snippet sca 378 | scan(${1:/pattern/}) { |${2:match}| ${0} } 379 | snippet scad 380 | scan(${1:/pattern/}) do |${2:match}| 381 | ${0} 382 | end 383 | snippet max 384 | max { |a, b| ${0} } 385 | snippet min 386 | min { |a, b| ${0} } 387 | snippet par 388 | partition { |${1:e}| ${0} } 389 | snippet pard 390 | partition do |${1:e}| 391 | ${0} 392 | end 393 | snippet rej 394 | reject { |${1:e}| ${0} } 395 | snippet rejd 396 | reject do |${1:e}| 397 | ${0} 398 | end 399 | snippet sel 400 | select { |${1:e}| ${0} } 401 | snippet seld 402 | select do |${1:e}| 403 | ${0} 404 | end 405 | snippet lam 406 | lambda { |${1:args}| ${0} } 407 | snippet -> 408 | -> { ${0} } 409 | snippet ->a 410 | ->(${1:args}) { ${0} } 411 | # I'm pretty sure that ruby users expect do to expand to do .. end 412 | snippet do 413 | do 414 | ${0} 415 | end 416 | # this is for one or more variables. typing a ", " is that cheap that it may 417 | # not be worth adding another snippet. should 0/1 placeholders change order? 418 | # its a good idea to think about the var name, so use it first 419 | snippet dov 420 | do |${1:v}| 421 | ${2} 422 | end 423 | snippet : 424 | ${1:key}: ${2:'value'} 425 | snippet ope 426 | open('${1:path/or/url/or/pipe}', '${2:w}') { |${3:io}| ${0} } 427 | # path_from_here() 428 | snippet fpath 429 | File.join(File.dirname(__FILE__), *['${1:rel path here}']) 430 | # unix_filter {} 431 | snippet unif 432 | ARGF.each_line${1} do |${2:line}| 433 | ${0} 434 | end 435 | # option_parse {} 436 | snippet optp 437 | require 'optparse' 438 | 439 | options = { ${0:default: 'args'} } 440 | 441 | ARGV.options do |opts| 442 | opts.banner = "Usage: #{File.basename($PROGRAM_NAME)}" 443 | end 444 | snippet opt 445 | opts.on('-${1:o}', '--${2:long-option-name}', ${3:String}, '${4:Option description.}') do |${5:opt}| 446 | ${0} 447 | end 448 | snippet tc 449 | require 'test/unit' 450 | 451 | require '${1:library_file_name}' 452 | 453 | class Test${2:$1} < Test::Unit::TestCase 454 | def test_${3:case_name} 455 | ${0} 456 | end 457 | end 458 | snippet ts 459 | require 'test/unit' 460 | 461 | require 'tc_${1:test_case_file}' 462 | require 'tc_${2:test_case_file}' 463 | snippet as 464 | assert ${1:test}, '${2:Failure message.}' 465 | snippet ase 466 | assert_equal ${1:expected}, ${2:actual} 467 | snippet asne 468 | assert_not_equal ${1:unexpected}, ${2:actual} 469 | snippet asid 470 | assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2**-20} 471 | snippet asi 472 | assert_includes ${1:collection}, ${2:object} 473 | snippet asio 474 | assert_instance_of ${1:ExpectedClass}, ${2:actual_instance} 475 | snippet asko 476 | assert_kind_of ${1:ExpectedKind}, ${2:actual_instance} 477 | snippet asn 478 | assert_nil ${1:instance} 479 | snippet asnn 480 | assert_not_nil ${1:instance} 481 | snippet asm 482 | assert_match(/${1:expected_pattern}/, ${2:actual_string}) 483 | snippet asnm 484 | assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string}) 485 | snippet aso 486 | assert_operator ${1:left}, :${2:operator}, ${3:right} 487 | snippet asr 488 | assert_raise ${1:Exception} { ${0} } 489 | snippet asrd 490 | assert_raise ${1:Exception} do 491 | ${0} 492 | end 493 | snippet asnr 494 | assert_nothing_raised ${1:Exception} { ${0} } 495 | snippet asnrd 496 | assert_nothing_raised ${1:Exception} do 497 | ${0} 498 | end 499 | snippet asrt 500 | assert_respond_to ${1:object}, :${2:method} 501 | snippet ass assert_same(..) 502 | assert_same ${1:expected}, ${2:actual} 503 | snippet ass assert_send(..) 504 | assert_send [${1:object}, :${2:message}, ${3:args}] 505 | snippet asns 506 | assert_not_same ${1:unexpected}, ${2:actual} 507 | snippet ast 508 | assert_throws :${1:expected}, -> { ${0} } 509 | snippet astd 510 | assert_throws :${1:expected} do 511 | ${0} 512 | end 513 | snippet asnt 514 | assert_nothing_thrown { ${0} } 515 | snippet asntd 516 | assert_nothing_thrown do 517 | ${0} 518 | end 519 | snippet fl 520 | flunk '${1:Failure message.}' 521 | # Benchmark.bmbm do .. end 522 | snippet bm- 523 | TESTS = ${1:10_000} 524 | Benchmark.bmbm do |results| 525 | ${0} 526 | end 527 | snippet rep 528 | results.report('${1:name}:') { TESTS.times { ${0} } } 529 | # Marshal.dump(.., file) 530 | snippet Md 531 | File.open('${1:path/to/file.dump}', 'wb') { |${2:file}| Marshal.dump(${3:obj}, $2) } 532 | # Mashal.load(obj) 533 | snippet Ml 534 | File.open('${1:path/to/file.dump}', 'rb') { |${2:file}| Marshal.load($2) } 535 | # deep_copy(..) 536 | snippet deec 537 | Marshal.load(Marshal.dump(${1:obj_to_copy})) 538 | snippet Pn- 539 | PStore.new('${1:file_name.pstore}') 540 | snippet tra 541 | transaction(${1:true}) { ${0} } 542 | # xmlread(..) 543 | snippet xml- 544 | REXML::Document.new(File.read('${1:path/to/file}')) 545 | # xpath(..) { .. } 546 | snippet xpa 547 | elements.each('${1://Xpath}') do |${2:node}| 548 | ${0} 549 | end 550 | # class_from_name() 551 | snippet clafn 552 | split('::').inject(Object) { |par, const| par.const_get(const) } 553 | # singleton_class() 554 | snippet sinc 555 | class << self; self end 556 | snippet nam 557 | namespace :${1:`vim_snippets#Filename()`} do 558 | ${0} 559 | end 560 | snippet tas 561 | desc '${1:Task description}' 562 | task ${2:task_name: [:dependent, :tasks]} do 563 | ${0} 564 | end 565 | # block 566 | snippet b 567 | { |${1:var}| ${0} } 568 | snippet begin 569 | begin 570 | fail 'A test exception.' 571 | rescue Exception => e 572 | puts e.message 573 | puts e.backtrace.inspect 574 | else 575 | # other exception 576 | ensure 577 | # always executed 578 | end 579 | 580 | #debugging 581 | snippet debug 582 | require 'byebug'; byebug 583 | snippet debug19 584 | require 'debugger'; debugger 585 | snippet debug18 586 | require 'ruby-debug'; debugger 587 | snippet pry 588 | require 'pry'; binding.pry 589 | snippet strf 590 | strftime('${1:%Y-%m-%d %H:%M:%S %z}')${0} 591 | # 592 | # Minitest snippets 593 | # 594 | snippet mb 595 | must_be ${0} 596 | snippet wb 597 | wont_be ${0} 598 | snippet mbe 599 | must_be_empty 600 | snippet wbe 601 | wont_be_empty 602 | snippet mbio 603 | must_be_instance_of ${0:Class} 604 | snippet wbio 605 | wont_be_instance_of ${0:Class} 606 | snippet mbko 607 | must_be_kind_of ${0:Class} 608 | snippet wbko 609 | wont_be_kind_of ${0:Class} 610 | snippet mbn 611 | must_be_nil 612 | snippet wbn 613 | wont_be_nil 614 | snippet mbsa 615 | must_be_same_as ${0:other} 616 | snippet wbsa 617 | wont_be_same_as ${0:other} 618 | snippet mbsi 619 | -> { ${0} }.must_be_silent 620 | snippet mbwd 621 | must_be_within_delta ${1:0.1}, ${2:0.1} 622 | snippet wbwd 623 | wont_be_within_delta ${1:0.1}, ${2:0.1} 624 | snippet mbwe 625 | must_be_within_epsilon ${1:0.1}, ${2:0.1} 626 | snippet wbwe 627 | wont_be_within_epsilon ${1:0.1}, ${2:0.1} 628 | snippet me 629 | must_equal ${0:other} 630 | snippet we 631 | wont_equal ${0:other} 632 | snippet mi 633 | must_include ${0:what} 634 | snippet wi 635 | wont_include ${0:what} 636 | snippet mm 637 | must_match /${0:regex}/ 638 | snippet wm 639 | wont_match /${0:regex}/ 640 | snippet mout 641 | -> { ${1} }.must_output '${0}' 642 | snippet mra 643 | -> { ${1} }.must_raise ${0:Exception} 644 | snippet mrt 645 | must_respond_to :${0:method} 646 | snippet wrt 647 | wont_respond_to :${0:method} 648 | snippet msend 649 | must_send [ ${1:what}, :${2:method}, ${3:args} ] 650 | snippet mthrow 651 | -> { throw :${1:error} }.must_throw :${2:error} 652 | ########################## 653 | # Rspec snippets # 654 | ########################## 655 | snippet desc 656 | describe ${1:`substitute(substitute(vim_snippets#Filename(), '_spec$', '', ''), '\(_\|^\)\(.\)', '\u\2', 'g')`} do 657 | ${0} 658 | end 659 | snippet descm 660 | describe '${1:#method}' do 661 | ${0:pending 'Not implemented'} 662 | end 663 | snippet cont 664 | context '${1:message}' do 665 | ${0} 666 | end 667 | snippet bef 668 | before :${1:each} do 669 | ${0} 670 | end 671 | snippet aft 672 | after :${1:each} do 673 | ${0} 674 | end 675 | snippet let 676 | let(:${1:object}) { ${0} } 677 | snippet let! 678 | let!(:${1:object}) { ${0} } 679 | snippet subj 680 | subject { ${0} } 681 | snippet s. 682 | subject.${0:method} 683 | snippet spec 684 | specify { subject.${0} } 685 | snippet exp 686 | expect(${1:object}).to ${0} 687 | snippet expb 688 | expect { ${1:object} }.to ${0} 689 | snippet experr 690 | expect { ${1:object} }.to raise_error ${2:StandardError}, /${0:message_regex}/ 691 | snippet shared 692 | shared_examples ${0:'shared examples name'} 693 | snippet ibl 694 | it_behaves_like ${0:'shared examples name'} 695 | snippet it 696 | it '${1:spec_name}' do 697 | ${0} 698 | end 699 | snippet its 700 | its(:${1:method}) { should ${0} } 701 | snippet is 702 | it { should ${0} } 703 | snippet isn 704 | it { should_not ${0} } 705 | snippet iexp 706 | it { expect(${1:object}).${2} ${0} } 707 | snippet iexpb 708 | it { expect { ${1:object} }.${2} ${0} } 709 | snippet iiexp 710 | it { is_expected.to ${0} } 711 | snippet iiexpn 712 | it { is_expected.not_to ${0} } 713 | snippet agg 714 | aggregate_failures '${1:message}' do 715 | ${0} 716 | end 717 | -------------------------------------------------------------------------------- /.vim/snippets/scss.snippets: -------------------------------------------------------------------------------- 1 | # CSS & SASS Snippets for VIM's Snipmate 2 | # Original Author: Chris Batchelor, Firegoby Design 3 | # https://github.com/firegoby/SASS-Snippets 4 | # 5 | # Install: - 6 | # Put in your SnipMate's snippets/ dir 7 | # :set filetype=scss 8 | # or 9 | # 'filetype on' in your .vimrc 10 | # Notes: - 11 | # most used features use single letter abbreviations 12 | # standard CSS declarations use two letters (occasionally three) 13 | # SASS functions use the first three letters of the function (occ. four) 14 | 15 | # element 16 | snippet e 17 | ${1:element} { 18 | ${2} 19 | } 20 | # class 21 | snippet c 22 | .${1:class} { 23 | ${2} 24 | } 25 | # id 26 | snippet i 27 | #${1:id} { 28 | ${2} 29 | } 30 | # Define a variable 31 | snippet v 32 | $${1:name}: ${2:value}; 33 | ${3} 34 | # @extend - Selector Inheritance 35 | snippet ex 36 | @extend .${1:class}; 37 | ${2} 38 | # @mixin - Define a mixin 39 | snippet mix 40 | @mixin ${1:name} { 41 | ${2} 42 | } 43 | # @include - Use a mixin 44 | snippet inc 45 | @include ${1:mixin}; 46 | ${2} 47 | # Standard CSS Declarations 48 | # positioning 49 | snippet di 50 | display: ${1:none}; 51 | ${2} 52 | snippet po 53 | position: ${1:relative}; 54 | ${2} 55 | snippet poa 56 | position: ${1:absolute}; 57 | ${2} 58 | snippet fl 59 | float: ${1:left}; 60 | ${2} 61 | snippet cl 62 | clear: ${1:left}; 63 | ${2} 64 | snippet top 65 | top: ${1:0}; 66 | ${2} 67 | snippet bot 68 | bottom: ${1:0}; 69 | ${2} 70 | snippet lef 71 | left: ${1:0}; 72 | ${2} 73 | snippet rig 74 | right: ${1:0}; 75 | ${2} 76 | # sizing 77 | snippet hi 78 | height: ${1:100%}; 79 | ${2} 80 | snippet wi 81 | width: ${1:80%}; 82 | ${2} 83 | snippet maw 84 | max-width: ${1:80%}; 85 | ${2} 86 | snippet miw 87 | min-width: ${1:25%}; 88 | ${2} 89 | # margins 90 | snippet m 91 | margin: ${1:0} ${2:auto}; 92 | ${3} 93 | snippet mt 94 | margin-top: ${1:0}; 95 | ${2} 96 | snippet mb 97 | margin-bottom: ${1:0}; 98 | ${2} 99 | snippet ml 100 | margin-left: ${1:0}; 101 | ${2} 102 | snippet mr 103 | margin-right: ${1:0}; 104 | ${2} 105 | # padding 106 | snippet p 107 | padding: ${1:0} ${2:0}; 108 | ${3} 109 | snippet pt 110 | padding-top: ${1:0}; 111 | ${2} 112 | snippet pb 113 | padding-bottom: ${1:0}; 114 | ${2} 115 | snippet pl 116 | padding-left: ${1:0}; 117 | ${2} 118 | snippet pr 119 | padding-right: ${1:0}; 120 | ${2} 121 | #borders 122 | snippet b 123 | border: ${1:1px} ${2:solid} ${3:#000}; 124 | ${4} 125 | snippet bt 126 | border-top: ${1:1px} ${2:solid} ${3:#000}; 127 | ${4} 128 | snippet bb 129 | border-bottom: ${1:1px} ${2:solid} ${3:#000}; 130 | ${4} 131 | snippet bl 132 | border-left: ${1:1px} ${2:solid} ${3:#000}; 133 | ${4} 134 | snippet br 135 | border-right: ${1:1px} ${2:solid} ${3:#000}; 136 | ${4} 137 | # backgrounds 138 | snippet ba 139 | background: ${1:#fff} ${2:url} ${3:repeat} ${4:left} ${5:top}; 140 | ${6} 141 | snippet bc 142 | background-color: ${1:#fff}; 143 | ${2} 144 | snippet bi 145 | background-image: url('${1}'); 146 | ${2} 147 | snippet bp 148 | background-position: ${1:left} ${2:top}; 149 | ${3} 150 | # fonts 151 | snippet f 152 | font: ${1:size}em/${2:1.5} ${3:"Helvetica Neue", Helvetica, Arial, sans-serif}; 153 | ${4} 154 | snippet font 155 | font: ${1:weight} ${2:style} ${3:variant} ${4:size}/${5:line-height} ${6:family}; 156 | ${7} 157 | snippet ff 158 | font-family: ${1:"Helvetica Neue", Helvetica, Arial, sans-serif}; 159 | ${2} 160 | snippet fs 161 | font-size: ${1:1.2em}; 162 | ${2} 163 | snippet fst 164 | font-style: ${1:italic}; 165 | ${2} 166 | snippet fv 167 | font-variant: ${1:small-caps}; 168 | ${2} 169 | snippet fw 170 | font-weight: ${1:bold}; 171 | ${2} 172 | snippet @ff 173 | @font-face { 174 | font-family: ${1:name}; 175 | src: ${2:url}; 176 | } 177 | ${3} 178 | # text- & lettering 179 | snippet co 180 | color: ${1:#000}; 181 | ${2} 182 | snippet ta 183 | text-align: ${1:center}; 184 | ${2} 185 | snippet td 186 | text-decoration: ${1:none}; 187 | ${2} 188 | snippet ti 189 | text-indent: ${1:length}; 190 | ${2} 191 | snippet to 192 | text-overflow: ${1:ellipsis}; 193 | ${2} 194 | snippet tr 195 | text-rendering: ${1:optimizeLegibility}; 196 | ${2} 197 | snippet ts 198 | text-shadow: ${1:color} ${2:x} ${3:y} ${4:blur}; 199 | ${5} 200 | snippet tt 201 | text-transform: ${1:uppercase}; 202 | ${2} 203 | snippet lh 204 | line-height: ${1:1.5em}; 205 | ${2} 206 | snippet ls 207 | letter-spacing: ${1:0.025em}; 208 | ${2} 209 | # SASS RGB Functions 210 | # Converts an rgb(red, green, blue) triplet into a color. 211 | snippet rgb 212 | rgb(${1:red}, ${2:green}, ${3:blue}) 213 | # Converts an rgba(red, green, blue, alpha) quadruplet into a color. 214 | snippet rgba 215 | rgba(${1:red}, ${2:green}, ${3:blue}, ${4:alpha}) 216 | # Adds an alpha layer to any color value. 217 | snippet rgbc 218 | rgba(${1:color}, ${2:alpha}) 219 | # Gets the red component of a color. 220 | snippet red 221 | red(${1:color}) 222 | # Gets the green component of a color. 223 | snippet gre 224 | green(${1:color}) 225 | # Gets the blue component of a color. 226 | snippet blu 227 | blue(${1:color}) 228 | # Mixes two colors together. 229 | snippet mixc 230 | mix(${1:color1}, ${2:color2}) 231 | # Mixes two colors together (weighted) 232 | snippet mixcw 233 | mix(${1:color1}, ${2:color2}, ${3:weight}) 234 | # SASS HSL Functions 235 | # Converts an hsl(hue, saturation, lightness) triplet into a color. 236 | snippet hsl 237 | hsl(${1:hue}, ${2:saturation}, ${3:lightness}) 238 | # Converts an hsla(hue, saturation, lightness, alpha) quadruplet into a color. 239 | snippet hsla 240 | hsla(${1:hue}, ${2:saturation}, ${3:lightness}, ${4:alpha}) 241 | # Gets the hue component of a color. 242 | snippet hue 243 | hue(${1:color}) 244 | # Gets the saturation component of a color. 245 | snippet satc 246 | saturation(${1:color}) 247 | # Gets the lightness component of a color. 248 | snippet ligc 249 | lightness(${1:color}) 250 | # Changes the hue of a color. 251 | snippet adj 252 | adjust-hue(${1:color}, ${2:degrees}) 253 | # Makes a color lighter. 254 | snippet lig 255 | lighten(${1:color}, ${2:amount}) 256 | # Makes a color darker. 257 | snippet dar 258 | darken(${1:color}, ${2:amount}) 259 | # Makes a color more saturated. 260 | snippet sat 261 | saturate(${1:color}, ${2:amount}) 262 | # Makes a color less saturated. 263 | snippet des 264 | desaturate(${1:color}, ${2:amount}) 265 | # Converts a color to grayscale. 266 | snippet gra 267 | grayscale(${1:color}) 268 | # Returns the complement of a color. 269 | snippet com 270 | complement(${1:color}) 271 | # Returns the inverse of a color. 272 | snippet inv 273 | invert(${1:color}) 274 | # SASS Opacity Functions 275 | # Gets the alpha component (opacity) of a color. 276 | snippet alp 277 | alpha(${1:color}) 278 | # Add or change an alpha layer for any color value. 279 | # - already defined, see 'rgbc' 280 | # Makes a color more opaque. 281 | snippet opa 282 | opacify(${1:color}, ${2:amount}) 283 | # Makes a color more transparent. 284 | snippet tra 285 | transparentize(${1:color}, ${2:amount}) 286 | # SASS Number Functions 287 | # Converts a unitless number to a percentage. 288 | snippet per 289 | percentage(${1:value}) 290 | # Rounds a number to the nearest whole number. 291 | snippet rou 292 | round(${1:value}) 293 | # Rounds a number up to the nearest whole number. 294 | snippet cei 295 | ceil(${1:value}) 296 | # Rounds a number down to the nearest whole number. 297 | snippet flo 298 | floor(${1:value}) 299 | # Returns the absolute value of a number. 300 | snippet abs 301 | abs(${1:value}) 302 | # section 303 | snippet /// 304 | //----------------------------------------------------------- 305 | // \`${1:Section} 306 | //----------------------------------------------------------- 307 | 308 | -------------------------------------------------------------------------------- /.vim/snippets/sh.snippets: -------------------------------------------------------------------------------- 1 | # Shebang. Executing bash via /usr/bin/env makes scripts more portable. 2 | snippet #! 3 | #!/usr/bin/env sh 4 | 5 | snippet s#! 6 | #!/usr/bin/env sh 7 | set -euo pipefail 8 | 9 | snippet safe 10 | set -euo pipefail 11 | 12 | snippet bash 13 | #!/usr/bin/env bash 14 | 15 | snippet sbash 16 | #!/usr/bin/env bash 17 | set -euo pipefail 18 | IFS=$'\n\t' 19 | 20 | snippet if 21 | if [[ ${1:condition} ]]; then 22 | ${0:${VISUAL}} 23 | fi 24 | snippet elif 25 | elif [[ ${1:condition} ]]; then 26 | ${0:${VISUAL}} 27 | snippet for 28 | for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do 29 | ${0:${VISUAL}} 30 | done 31 | snippet fori 32 | for ${1:needle} in ${2:haystack} ; do 33 | ${0:${VISUAL}} 34 | done 35 | snippet wh 36 | while [[ ${1:condition} ]]; do 37 | ${0:${VISUAL}} 38 | done 39 | snippet until 40 | until [[ ${1:condition} ]]; do 41 | ${0:${VISUAL}} 42 | done 43 | snippet case 44 | case ${1:word} in 45 | ${2:pattern}) 46 | ${0};; 47 | esac 48 | snippet go 49 | while getopts '${1:o}' ${2:opts} 50 | do 51 | case $$2 in 52 | ${3:o0}) 53 | ${0:#staments};; 54 | esac 55 | done 56 | # Set SCRIPT_DIR variable to directory script is located. 57 | snippet sdir 58 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 59 | # getopt 60 | snippet getopt 61 | __ScriptVersion="${1:version}" 62 | 63 | #=== FUNCTION ================================================================ 64 | # NAME: usage 65 | # DESCRIPTION: Display usage information. 66 | #=============================================================================== 67 | function usage () 68 | { 69 | echo "Usage : $${0:0} [options] [--] 70 | 71 | Options: 72 | -h|help Display this message 73 | -v|version Display script version" 74 | 75 | } # ---------- end of function usage ---------- 76 | 77 | #----------------------------------------------------------------------- 78 | # Handle command line arguments 79 | #----------------------------------------------------------------------- 80 | 81 | while getopts ":hv" opt 82 | do 83 | case $opt in 84 | 85 | h|help ) usage; exit 0 ;; 86 | 87 | v|version ) echo "$${0:0} -- Version $__ScriptVersion"; exit 0 ;; 88 | 89 | * ) echo -e "\n Option does not exist : $OPTARG\n" 90 | usage; exit 1 ;; 91 | 92 | esac # --- end of case --- 93 | done 94 | shift $(($OPTIND-1)) 95 | snippet root 96 | if [ \$(id -u) -ne 0 ]; then exec sudo \$0; fi 97 | 98 | snippet fun-sh 99 | ${1:function_name}() { 100 | ${0:#function_body} 101 | } 102 | 103 | snippet fun 104 | function ${1:function_name}() { 105 | ${0:#function_body} 106 | } 107 | -------------------------------------------------------------------------------- /.vim/snippets/zsh.snippets: -------------------------------------------------------------------------------- 1 | # #!/bin/zsh 2 | snippet #! 3 | #!/bin/zsh 4 | 5 | snippet if 6 | if ${1:condition}; then 7 | ${0:${VISUAL}} 8 | fi 9 | snippet ife 10 | if ${1:condition}; then 11 | ${2:${VISUAL}} 12 | else 13 | ${0:# statements} 14 | fi 15 | snippet eif 16 | elif ${1:condition}; then 17 | ${0:${VISUAL}} 18 | snippet for 19 | for (( ${2:i} = 0; $2 < ${1:count}; $2++ )); do 20 | ${0:${VISUAL}} 21 | done 22 | snippet fori 23 | for ${1:needle} in ${2:haystack}; do 24 | ${0:${VISUAL}} 25 | done 26 | snippet fore 27 | for ${1:item} in ${2:list}; do 28 | ${0:${VISUAL}} 29 | done 30 | snippet wh 31 | while ${1:condition}; do 32 | ${0:${VISUAL}} 33 | done 34 | snippet until 35 | until ${1:condition}; do 36 | ${0:${VISUAL}} 37 | done 38 | snippet repeat 39 | repeat ${1:integer}; do 40 | ${0:${VISUAL}} 41 | done 42 | snippet case 43 | case ${1:word} in 44 | ${2:pattern}) 45 | ${0};; 46 | esac 47 | snippet select 48 | select ${1:answer} in ${2:choices}; do 49 | ${0:${VISUAL}} 50 | done 51 | snippet ( 52 | ( ${0:#statements} ) 53 | snippet { 54 | { ${0:#statements} } 55 | snippet [ 56 | [[ ${0:test} ]] 57 | snippet always 58 | { ${1:try} } always { ${0:always} } 59 | snippet fun 60 | ${1:function_name}() { 61 | ${0:# function_body} 62 | } 63 | snippet ffun 64 | function ${1:function_name}() { 65 | ${0:# function_body} 66 | } 67 | -------------------------------------------------------------------------------- /.vim/spell/en.utf-8.add: -------------------------------------------------------------------------------- 1 | RevGraph 2 | -------------------------------------------------------------------------------- /.vim/spell/en.utf-8.add.spl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengwynn/dotfiles/30a8087059deefaad95847c0c3edc057b1c65fba/.vim/spell/en.utf-8.add.spl -------------------------------------------------------------------------------- /.vimrc: -------------------------------------------------------------------------------- 1 | " Vim 2 | " === 3 | 4 | set nocompatible " be iMproved 5 | filetype off " required! 6 | 7 | " Install vim-plug 8 | if empty(glob('~/.vim/autoload/plug.vim')) 9 | silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs 10 | \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 11 | autocmd VimEnter * PlugInstall --sync | source $MYVIMRC 12 | endif 13 | 14 | call plug#begin('~/.vim/bundle') 15 | 16 | Plug '/usr/local/opt/fzf' | Plug 'junegunn/fzf.vim' 17 | Plug 'airblade/vim-gitgutter' 18 | Plug 'andyl/vim-textobj-elixir' 19 | " Plug 'chriskempson/base16-vim' 20 | Plug 'danielwe/base16-vim' 21 | Plug 'christoomey/vim-tmux-navigator' 22 | Plug 'ctrlpvim/ctrlp.vim' 23 | Plug 'epmatsw/ag.vim' 24 | Plug 'ervandew/supertab' 25 | Plug 'fatih/vim-go' 26 | Plug 'styled-components/vim-styled-components', { 'branch': 'main' } 27 | Plug 'gcmt/wildfire.vim' 28 | Plug 'godlygeek/tabular' 29 | Plug 'inside/vim-textobj-jsxattr' 30 | Plug 'jayflo/vim-skip' 31 | Plug 'jparise/vim-graphql' 32 | Plug 'junegunn/goyo.vim' 33 | Plug 'junegunn/limelight.vim' 34 | Plug 'junegunn/vim-github-dashboard' 35 | Plug 'justinmk/vim-gtfo' 36 | Plug 'kana/vim-textobj-user' 37 | Plug 'mattn/gist-vim' 38 | Plug 'mattn/webapi-vim' 39 | Plug 'reedes/vim-textobj-sentence' 40 | Plug 'sbdchd/neoformat' 41 | Plug 'scrooloose/nerdtree' 42 | Plug 'sheerun/vim-polyglot' 43 | Plug 'tek/vim-textobj-ruby' 44 | Plug 'tmux-plugins/vim-tmux' 45 | Plug 'tmux-plugins/vim-tmux-focus-events' 46 | Plug 'tpope/vim-abolish' 47 | Plug 'tpope/vim-commentary' 48 | Plug 'tpope/vim-dispatch' 49 | Plug 'tpope/vim-fugitive' 50 | Plug 'tpope/vim-projectionist' 51 | Plug 'tpope/vim-rails' 52 | Plug 'tpope/vim-rake' 53 | Plug 'tpope/vim-rbenv' 54 | Plug 'tpope/vim-repeat' 55 | Plug 'tpope/vim-rhubarb' 56 | Plug 'tpope/vim-surround' 57 | Plug 'vim-scripts/L9' 58 | Plug 'vim-scripts/ZoomWin' 59 | Plug 'vim-scripts/gem.vim' 60 | Plug 'w0rp/ale' 61 | Plug 'kristijanhusak/vim-carbon-now-sh' 62 | Plug 'Valloric/YouCompleteMe', { 'do': './install.py --go-completer --ts-completer --rust-completer ' } 63 | Plug 'hotoo/jsgf.vim' 64 | Plug 'metakirby5/codi.vim' 65 | Plug 'tpope/vim-scriptease' 66 | Plug 'jxnblk/vim-mdx-js' 67 | Plug 'vimwiki/vimwiki' 68 | call plug#end() 69 | 70 | 71 | " Per-directory .vimrc files 72 | set exrc 73 | set secure 74 | 75 | " Syntax 76 | " ====== 77 | 78 | syntax on 79 | syntax enable 80 | set t_Co=256 81 | 82 | " General Config 83 | " ============== 84 | 85 | let mapleader='\' 86 | set gfn=Menlo:h14 87 | set encoding=utf-8 88 | set number " Line numbers are good 89 | set backspace=indent,eol,start " Allow backspace in insert mode 90 | set history=1000 " Store lots of :cmdline history 91 | set showcmd " Show incomplete cmds down the bottom 92 | set showmode " Show current mode down the bottom 93 | set gcr=a:blinkon0 " Disable cursor blink 94 | set autoread " Reload files changed outside vim 95 | set laststatus=2 " Always show status line 96 | set clipboard=unnamed " Use system clipboard 97 | set hidden " Buffers can exist in the background 98 | set splitright " Opens vertical split right of current window 99 | set splitbelow " Opens horizontal split below current window 100 | 101 | " Send more characters for redraws 102 | set ttyfast 103 | 104 | " Enable mouse use in all modes 105 | set mouse=a 106 | 107 | " Set this to the name of your terminal that supports mouse codes. 108 | " Must be one of: xterm, xterm2, netterm, dec, jsbterm, pterm 109 | set ttymouse=xterm2 110 | 111 | 112 | " Search Settings 113 | " =============== 114 | 115 | set incsearch " Find the next match as we type the search 116 | set hlsearch " Hilight searches by default 117 | set viminfo='100,f1 " Save up to 100 marks, enable capital marks 118 | 119 | " Turn Off Swap Files 120 | " =================== 121 | 122 | set noswapfile 123 | set nobackup 124 | set nowritebackup 125 | set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp 126 | set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp 127 | 128 | " Persistent Undo 129 | " =============== 130 | 131 | " Keep undo history across sessions, by storing in file 132 | " Only works in MacVim (gui) mode 133 | if has('gui_running') 134 | set undodir=~/.vim/backups 135 | set undofile 136 | " Hide the toolbar 137 | set guioptions-=T 138 | endif 139 | 140 | " Indentation and Display 141 | " ======================= 142 | 143 | set autoindent 144 | set smartindent 145 | set smarttab 146 | set shiftwidth=2 147 | set softtabstop=2 148 | set tabstop=2 149 | set expandtab 150 | 151 | filetype plugin on 152 | filetype indent on 153 | 154 | set list listchars=tab:\ \ ,trail:· " Display tabs and trailing spaces visually 155 | set nowrap " Don't wrap lines 156 | set linebreak " Wrap lines at convenient points 157 | 158 | " Folds 159 | " ===== 160 | 161 | set foldmethod=indent " Fold based on indent 162 | set foldnestmax=3 " Deepest fold is 3 levels 163 | set nofoldenable " Don't fold by default 164 | 165 | " Completion 166 | " ========== 167 | 168 | "set wildmode=list:longest 169 | set wildmode=longest,list,full 170 | set wildmenu " Enable ctrl-n and ctrl-p to scroll thru matches 171 | set wildignore=*.o,*.obj,*~ " Stuff to ignore when tab completing 172 | set wildignore+=*vim/backups* 173 | 174 | " Scrolling 175 | " ========= 176 | 177 | " Start scrolling when we're getting close to margins 178 | set scrolloff=10 179 | set sidescrolloff=15 180 | set sidescroll=1 181 | 182 | " Status Line 183 | " =========== 184 | 185 | set statusline= " Override default 186 | set statusline+=%{fugitive#statusline()[4:-2]} " Show fugitive git info 187 | set statusline+=\ %f\ %m\ %r " Show filename/path 188 | set statusline+=%= " Set right-side status info after this line 189 | set statusline+=%l/%L:%v " Set /: 190 | set statusline+=\ " Set ending space 191 | 192 | let base16colorspace=256 193 | 194 | if filereadable(expand("~/.vimrc_background")) 195 | let base16colorspace=256 196 | source ~/.vimrc_background 197 | endif 198 | 199 | " NERDTree 200 | " ======== 201 | function! ShowFileInNERDTree() 202 | if exists("t:NERDTreeBufName") 203 | NERDTreeFind 204 | else 205 | NERDTree 206 | wincmd l 207 | NERDTreeFind 208 | endif 209 | endfunction 210 | map r :call ShowFileInNERDTree() 211 | let g:NERDTreeDirArrowExpandable = '+' 212 | let g:NERDTreeDirArrowCollapsible = '-' 213 | let g:NERDTreeIgnore=['node_modules$[[dir]]'] 214 | 215 | " Git Gutter 216 | " ========== 217 | if exists('&signcolumn') " Vim 7.4.2201 218 | set signcolumn=yes 219 | else 220 | let g:gitgutter_sign_column_always = 1 221 | endif 222 | 223 | " GH Dashboard 224 | " ========== 225 | let g:github_dashboard = { 'username': 'pengwynn', 'password': $GITHUB_TOKEN } 226 | 227 | " JSX in .js files 228 | " ========== 229 | let g:jsx_ext_required = 0 230 | 231 | " Searching 232 | " ========== 233 | if executable('ag') 234 | " Use ag over grep 235 | set grepprg=ag\ --nogroup\ --nocolor 236 | 237 | " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore 238 | let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' 239 | 240 | " ag is fast enough that CtrlP doesn't need to cache 241 | let g:ctrlp_use_caching = 0 242 | 243 | nnoremap K :grep! "\b\b":cw 244 | endif 245 | 246 | " Committing 247 | " ========= 248 | " 249 | " BufRead seems more appropriate here but for some reason the final `wincmd p` doesn't work if we do that. 250 | autocmd VimEnter COMMIT_EDITMSG call OpenCommitMessageDiff() 251 | function OpenCommitMessageDiff() 252 | " Save the contents of the z register 253 | let old_z = getreg("z") 254 | let old_z_type = getregtype("z") 255 | 256 | try 257 | call cursor(1, 0) 258 | let diff_start = search("^diff --git") 259 | if diff_start == 0 260 | " There's no diff in the commit message; generate our own. 261 | let @z = system("git diff --cached -M -C") 262 | else 263 | " Yank diff from the bottom of the commit message into the z register 264 | :.,$yank z 265 | call cursor(1, 0) 266 | endif 267 | 268 | " Paste into a new buffer 269 | vnew 270 | normal! V"zP 271 | finally 272 | " Restore the z register 273 | call setreg("z", old_z, old_z_type) 274 | endtry 275 | 276 | " Configure the buffer 277 | set filetype=diff noswapfile nomodified readonly 278 | silent file [Changes\ to\ be\ committed] 279 | 280 | " Get back to the commit message 281 | wincmd p 282 | endfunction 283 | 284 | let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } } 285 | -------------------------------------------------------------------------------- /.zshrc: -------------------------------------------------------------------------------- 1 | export PATH="$GOPATH/bin:$HOME/.cargo/bin:$HOME/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:$PATH" 2 | 3 | # shortcut to this dotfiles path is $ZSH 4 | export ZSH=~/zsh 5 | export DOTFILES=$HOME 6 | 7 | # your project folder that we can `c [tab]` to 8 | export CODE=~/code 9 | export PROJECTS=~/code 10 | 11 | # source every .zsh file in this repo 12 | for config_file ($ZSH/**/*.zsh) source $config_file 13 | 14 | # use .localrc for SUPER SECRET STUFF that you don't 15 | # want in your public, versioned repo. 16 | if [[ -a ~/.localrc ]] 17 | then 18 | source ~/.localrc 19 | fi 20 | 21 | # initialize autocomplete here, otherwise functions won't be loaded 22 | autoload -U compinit 23 | compinit 24 | 25 | # quote pasted URLs 26 | autoload -U url-quote-magic 27 | zle -N self-insert url-quote-magic 28 | 29 | # fun 30 | autoload -U tetris 31 | zle -N tetris 32 | bindkey ^T tetris 33 | 34 | # Fix history search in tmux 35 | bindkey '^R' history-incremental-search-backward 36 | bindkey "^[[A" history-beginning-search-backward 37 | bindkey "^[[B" history-beginning-search-forward 38 | bindkey "^P" history-beginning-search-backward 39 | bindkey "^N" history-beginning-search-forward 40 | 41 | # load every completion after autocomplete loads 42 | for config_file ($ZSH/**/completion.sh) source $config_file 43 | 44 | # asdf 45 | if [ -s "$HOME/.asdf/asdf.sh" ]; then 46 | source $HOME/.asdf/asdf.sh 47 | fi 48 | if [ -s "$HOME/.asdf/completions/asdf.bash" ]; then 49 | source $HOME/.asdf/completions/asdf.bash 50 | fi 51 | 52 | # awsam 53 | if [ -s "$HOME/.awsam/bash.rc" ]; then 54 | source $HOME/.awsam/bash.rc 55 | fi 56 | 57 | [[ $TMUX != "" ]] && export TERM="tmux-256color" 58 | 59 | BASE16_SHELL="$HOME/.config/base16-shell/" 60 | [ -n "$PS1" ] && \ 61 | [ -s "$BASE16_SHELL/profile_helper.sh" ] && \ 62 | eval "$("$BASE16_SHELL/profile_helper.sh")" 63 | 64 | autoload -U promptinit; promptinit 65 | prompt pure 66 | 67 | 68 | export GH_LOGIN="pengwynn" 69 | 70 | [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh 71 | 72 | ZSH_SYNTAX_HIGHLIGHT_PATH="/usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" 73 | [ -f $ZSH_SYNTAX_HIGHLIGHT_PATH ] && source $ZSH_SYNTAX_HIGHLIGHT_PATH 74 | 75 | archey -o 76 | -------------------------------------------------------------------------------- /Brewfile: -------------------------------------------------------------------------------- 1 | tap 'caskroom/cask' 2 | tap 'caskroom/fonts' 3 | tap 'caskroom/versions' 4 | tap 'homebrew/bundle' 5 | tap 'homebrew/dev-tools' 6 | tap 'homebrew/services' 7 | tap 'vektorlab/slackcat', 'https://github.com/vektorlab/slackcat' 8 | tap 'caius/jo' 9 | tap 'simeji/jid' 10 | cask 'java' 11 | cask 'font-jetbrains-mono' 12 | cask 'monodraw' 13 | 14 | brew 'ack' 15 | brew 'archey' 16 | brew 'autoconf' 17 | brew 'automake' 18 | brew 'awscli' 19 | brew 'bash-completion' 20 | brew 'chruby' 21 | brew 'coreutils' 22 | brew 'cowsay' 23 | brew 'ctop' 24 | brew 'docker-completion' 25 | brew 'elixir' 26 | brew 'ffmpeg' 27 | brew 'figlet' 28 | brew 'fzf' 29 | brew 'gawk' 30 | brew 'glide' 31 | brew 'go' 32 | brew 'gpg' 33 | brew 'hub' 34 | brew 'hugo' 35 | brew 'icu4c' 36 | brew 'imagemagick' 37 | brew 'jid' 38 | brew 'jo' 39 | brew 'jq' 40 | brew 'jrnl' 41 | brew 'libtool' 42 | brew 'libxslt' 43 | brew 'libyaml' 44 | brew 'luajit' 45 | brew 'macvim', args: ['with-override-system-vim', 'with-python3', 'without-python'] 46 | brew 'mas' 47 | brew 'npm' 48 | brew 'openssl' 49 | brew 'pcre' 50 | brew 'phantomjs' 51 | brew 'pv' 52 | brew 'python3' 53 | brew 'readline' 54 | brew 'reattach-to-user-namespace' 55 | brew 'redis' 56 | brew 'ruby-build' 57 | brew 'screenfetch' 58 | brew 'shellcheck' 59 | brew 'slackcat' 60 | brew 'slugify' 61 | brew 'ssh-copy-id' 62 | brew 'the_silver_searcher' 63 | brew 'tmux' 64 | brew 'tree' 65 | brew 'vim' 66 | brew 'wget' 67 | brew 'wifi-password' 68 | brew 'yarn' 69 | brew 'youtube-dl' 70 | brew 'zsh' 71 | brew 'zsh-syntax-highlighting' 72 | 73 | cask '1password' 74 | cask 'aerial' 75 | cask 'anybar' 76 | cask 'atom' 77 | cask 'boxer' 78 | cask 'cathode' 79 | cask 'chrome-devtools' 80 | cask 'docker' 81 | cask 'dropbox' 82 | cask 'firefox' 83 | cask 'font-fira-code' 84 | cask 'font-hack' 85 | cask 'font-inconsolata' 86 | cask 'font-input' 87 | cask 'font-oxygen' 88 | cask 'font-oxygen-mono' 89 | cask 'font-press-start2p' 90 | cask 'font-roboto' 91 | cask 'font-roboto-mono' 92 | cask 'font-roboto-slab' 93 | cask 'font-source-code-pro' 94 | cask 'font-ubuntu-mono-derivative-powerline' 95 | cask 'google-chrome' 96 | cask 'graphiql' 97 | cask 'hammerspoon' 98 | cask 'hyper' 99 | cask 'iterm2-nightly' 100 | cask 'karabiner-elements' 101 | cask 'kap' 102 | cask 'kindle' 103 | cask 'launchbar' 104 | cask 'openemu' 105 | cask 'qlcolorcode' 106 | cask 'qlmarkdown' 107 | cask 'qlprettypatch' 108 | cask 'qlstephen' 109 | cask 'quicklook-csv' 110 | cask 'quicklook-json' 111 | cask 'sequel-pro' 112 | cask 'slack' 113 | cask 'textexpander' 114 | cask 'wkhtmltopdf' 115 | cask 'visual-studio-code' 116 | cask 'zoomus' 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## There's no place like ~/ 2 | 3 | These are my personal [dotfiles][]. They turn ordinary stock applications into 4 | my own carefully crafted lightsaber. 5 | 6 | {///////\\\\\\\<#>}============================================= 7 | 8 | [Yonk][] and I scour the galaxy looking for nanosecond timesavers for all our 9 | favorite tools. If you've got a tip [let us know][octodots]. 10 | 11 | ![screencap][] 12 | 13 | ## Get your own ## 14 | 15 | If you're new to dotfiles, this probably isn't the best starter repository for 16 | you. While these started as a clone of [Holman's][holman/dotfiles], many 17 | utilities are unique to my workflow. I recommend other [dotfile frameworks][dotfiles] 18 | out there. 19 | 20 | ### Installation ### 21 | 22 | If you're crazy and want to clone my dots anyway: 23 | 24 | - `git clone https://github.com/pengwynn/dotfiles.git ~/.dotfiles` 25 | - `cd ~/.dotfiles` 26 | - `script/bootstrap` 27 | 28 | The install script will symlink the appropriate files in `.dotfiles` to your 29 | home directory. Everything is configured and tweaked within `~/.dotfiles`, 30 | though. All files and folders ending in `.symlink` get, you guessed it, 31 | symlinked. For example: `~/.dotfiles/vim/vimrc.symlink` gets symlinked to 32 | `~/.vimrc`. 33 | 34 | ## Main elements ## 35 | 36 | There's a few special files in the hierarchy. 37 | 38 | - **bin/**: Anything in `bin/` will get added to your `$PATH` and be made 39 | available everywhere. 40 | - **topic/\*.zsh**: Any files ending in `.zsh` get loaded into your 41 | environment. 42 | - **topic/\*.symlink**: Any files ending in `*.symlink` get symlinked into 43 | your `$HOME`. This is so you can keep all of those versioned in your dotfiles 44 | but still keep those autoloaded files in your home directory. These get 45 | symlinked in when you run `script/bootstrap`. 46 | - **topic/\*.completion.sh**: Any files ending in `completion.sh` get loaded 47 | last so that they get loaded after we set up zsh autocomplete functions. 48 | 49 | ## Prior art ## 50 | 51 | This project began as a fork of (and is heavily inspired by) 52 | [Zach Holman's dotfiles][holman/dotfiles], whose topic-based symlinking 53 | approach makes this so easy. I also have stolen freely from: 54 | 55 | * [Mathias Bynens](http://github.com/mathiasbynens/dotfiles) 56 | * [Yan Pritzker](http://github.com/skwp/dotfiles) 57 | * [Josh Clayton](http://github.com/joshuaclayton/dotfiles) 58 | * [Adam Jahnke](http://github.com/adamyonk/dotfiles) 59 | * [Tom Ryder](https://sanctum.geek.nz/cgit/dotfiles.git/about/) 60 | * [Steve Losh](http://github.com/sjl/dotfiles) 61 | 62 | ## Share your dots 63 | 64 | If you've got a great set of dots (or want to get started), check out 65 | [dotfiles.github.com][dotfiles]. Ping @[octodots][] with great dot sets you've 66 | found or tips and tricks for your favorite tools. 67 | 68 | [dotfiles]: http://dotfiles.github.com 69 | [Yonk]: https://twitter.com/adamyonk 70 | [octodots]: https://twitter.com/octodots 71 | [holman/dotfiles]: https://github.com/holman/dotfiles 72 | [screencap]: 73 | http://cl.ly/image/3k171S3E3k2q/Screen%20Shot%202013-02-07%20at%2011.06.41%20AM.png 74 | -------------------------------------------------------------------------------- /bin/addr: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: addr [] 3 | # Show IPv4 address for interface or all interfaces with 4 | # no given. 5 | 6 | ifconfig $* | 7 | grep 'inet ' | 8 | grep broadcast | 9 | awk '{ print $2 }' 10 | -------------------------------------------------------------------------------- /bin/argv: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: argv 3 | # Dump arguments 4 | set -e 5 | count=0 6 | for a in "$@" 7 | do 8 | count=$(( count + 1 )) 9 | echo "$count: $a" 10 | done 11 | -------------------------------------------------------------------------------- /bin/battery: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Author: Nicolas Goles 4 | # url: https://github.com/Goles/Battery 5 | 6 | battery_charge() 7 | { 8 | ioreg -c AppleSmartBattery -w0 | \ 9 | grep -o '"[^"]*" = [^ ]*' | \ 10 | sed -e 's/= //g' -e 's/"//g' | \ 11 | sort | \ 12 | while read key value; do 13 | case $key in 14 | "MaxCapacity") 15 | export maxcap=$value;; 16 | "CurrentCapacity") 17 | export curcap=$value;; 18 | esac 19 | if [[ -n "$maxcap" && -n $curcap ]]; then 20 | CAPACITY=$(( 100 * curcap / maxcap)) 21 | printf "%d" $CAPACITY 22 | break 23 | fi 24 | done 25 | } 26 | 27 | # 28 | # Run Battery 29 | # 30 | 31 | if [[ "$(uname)" != "Darwin" ]]; then 32 | exit 0 33 | fi 34 | 35 | BATTERY_STATUS=$(battery_charge) 36 | [ -z "$BATTERY_STATUS" ] && exit 37 | 38 | # 39 | # Read args 40 | # 41 | 42 | while getopts ":g:m:w:o:h" opt; do 43 | case $opt in 44 | g) 45 | if [ "$good_color" == "" ]; then 46 | good_color=$OPTARG 47 | fi 48 | ;; 49 | m) 50 | if [ "$middle_color" == "" ]; then 51 | middle_color=$OPTARG 52 | fi 53 | ;; 54 | w) 55 | if [ "$warn_color" == "" ]; then 56 | warn_color=$OPTARG 57 | fi 58 | ;; 59 | o) 60 | if [ "$output" == "" ]; then 61 | output=$OPTARG 62 | fi 63 | ;; 64 | h) 65 | echo "Usage: battery [-g good battery status color, default green or 1;32] [-m middle battery status color, default yellow or 1;33] [-w warn batttery status color, default red or 0;31] [-o specifies output format, use -o tmux to specify tmux status bar format]" 66 | exit 0 67 | ;; 68 | \?) 69 | echo "Invalid option: -$OPTARG" 70 | exit 1 71 | ;; 72 | :) 73 | echo "Option -$OPTARG requires an argument" 74 | exit 1 75 | ;; 76 | esac 77 | done 78 | 79 | tmux=false 80 | 81 | if [ "$output" == "tmux" ]; then 82 | tmux=true 83 | fi 84 | 85 | # 86 | # For default behavior when no different colors are specified 87 | # 88 | 89 | if [ "$good_color" == "" ]; then 90 | case "$tmux" in 91 | true) good_color="green" ;; 92 | false) good_color="1;32" ;; 93 | esac 94 | fi 95 | 96 | if [ "$middle_color" == "" ]; then 97 | case "$tmux" in 98 | true) middle_color="yellow" ;; 99 | false) middle_color="1;33" ;; 100 | esac 101 | fi 102 | 103 | if [ "$warn_color" == "" ]; then 104 | case "$tmux" in 105 | true) warn_color="red" ;; 106 | false) warn_color="0;31" ;; 107 | esac 108 | fi 109 | 110 | # 111 | # Apply the correct color to the battery status prompt 112 | # 113 | 114 | if [ "$BATTERY_STATUS" -ge 75 ]; then 115 | 116 | # Green 117 | case "$tmux" in 118 | true) COLOR="#[fg=$good_color]" ;; 119 | false) COLOR=$good_color ;; 120 | esac 121 | 122 | elif [ "$BATTERY_STATUS" -ge 25 ] && [ "$BATTERY_STATUS" -lt 75 ]; then 123 | 124 | # Yellow 125 | case "$tmux" in 126 | true) COLOR="#[fg=$middle_color]" ;; 127 | false) COLOR=$middle_color ;; 128 | esac 129 | 130 | elif [ "$BATTERY_STATUS" -lt 25 ]; then 131 | 132 | # Red 133 | case "$tmux" in 134 | true) COLOR="#[fg=$warn_color]" ;; 135 | false) COLOR=$warn_color ;; 136 | esac 137 | 138 | fi 139 | 140 | # 141 | # Print the battery status 142 | # 143 | 144 | GRAPH=$(spark 0 "${BATTERY_STATUS}" 100 | awk '{print substr($0,4,3)}') 145 | 146 | if [ "$tmux" == "false" ]; then 147 | printf "\e[0;%sm%s %s \e[m\n" "$COLOR" "[$BATTERY_STATUS%]" "$GRAPH" 148 | else 149 | printf "%s%s %s" "$COLOR" "[$BATTERY_STATUS%]" "$GRAPH" 150 | fi 151 | -------------------------------------------------------------------------------- /bin/chr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pengwynn/dotfiles/30a8087059deefaad95847c0c3edc057b1c65fba/bin/chr -------------------------------------------------------------------------------- /bin/colordump: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: colordump 3 | # Dump 256 ansi colors to the terminal. 4 | 5 | printf "How each ANSI color is displayed on your terminal:\n\n" 6 | 7 | i=0 8 | row=0 9 | while [ $i -lt 255 ]; 10 | do 11 | newrow=$((i / 10)) 12 | test $newrow -ne $row && printf "\n" 13 | row=$newrow 14 | printf "\e[%dm %03d \e[0m" $i $i 15 | i=$((i + 1)) 16 | done 17 | 18 | printf '\n\n e.g., "\\e[41mTEXT\\e[0m" ' 19 | printf "\e[41m(for TEXT like this)\e[0m\n" 20 | -------------------------------------------------------------------------------- /bin/db-up: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Migrate the local Rails database, prepare the test database, 4 | # and forget about the changes to db/schema.rb 5 | # 6 | # USAGE: 7 | # 8 | # $ db-up 9 | 10 | bin/rake db:migrate db:test:prepare && git checkout db 11 | -------------------------------------------------------------------------------- /bin/dc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #/ Usage: dc [args] 3 | #/ 4 | #/ Useful shortcuts for working with `docker` and `docker-compose`. 5 | #/ 6 | #/ `dc` also accepts `docker-compose` commands in addition to the commands 7 | #/ listed below. In this sense the `dc` script as a shorthand notation for the 8 | #/ more lengthy `docker-compose`. 9 | #/ 10 | #/ COMMANDS: 11 | #/ clean Remove stopped containers and dangling images 12 | #/ console Attach a bash console to a running container 13 | #/ cycle Stop a container and then start it up again 14 | #/ ports Show mapped ports for a running container 15 | #/ rebuild Build the image, stop, and then start the container 16 | #/ activate Start the Docker for Mac application 17 | #/ deactivate Stop the Docker for Mac application 18 | #/ screen Attach a `screen` session to the Docker VM 19 | #/ -h, --help Show this message. 20 | #/ 21 | #/ EXAMPLES: 22 | #/ dc clean 23 | #/ dc console 170fe7469429 24 | #/ dc cycle mysql 25 | #/ dc ports elasticsearch 26 | #/ dc rebuild redis 27 | #/ dc --file docker-compose.test.yml up -d 28 | #/ 29 | #------------------------------------------------------------------------------ 30 | 31 | function usage { 32 | grep '^#/' <"$0" | cut -c 4- 33 | } 34 | 35 | function dc_clean { 36 | docker rm $(docker ps -aqf status=exited) 2>/dev/null || true 37 | docker rmi $(docker images -qf dangling=true) 2>/dev/null || true 38 | } 39 | 40 | function dc_console { 41 | docker exec -it "$1" /bin/bash 42 | } 43 | 44 | function dc_cycle { 45 | docker-compose stop "$@" && 46 | docker-compose up -d "$@" 47 | } 48 | 49 | function dc_ports { 50 | docker ps --filter name="$1" --format "{{.Names}}: {{.Ports}}" 51 | } 52 | 53 | function dc_rebuild { 54 | docker-compose build "$@" && 55 | docker-compose stop "$@" && 56 | docker-compose up -d "$@" 57 | } 58 | 59 | function dc_activate { 60 | open "/Applications/Docker.app" 61 | } 62 | 63 | function dc_deactivate { 64 | osascript -e "quit app \"docker\"" 65 | } 66 | 67 | function dc_screen { 68 | screen "${HOME}/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty" 69 | } 70 | 71 | if [[ $# -gt 0 ]]; then 72 | case "$1" in 73 | --help ) 74 | usage 75 | ;; 76 | -h ) 77 | usage 78 | ;; 79 | clean ) 80 | dc_clean 81 | ;; 82 | console ) 83 | shift 84 | dc_console "$@" 85 | ;; 86 | cycle ) 87 | shift 88 | dc_cycle "$@" 89 | ;; 90 | ports ) 91 | shift 92 | dc_ports "$@" 93 | ;; 94 | rebuild ) 95 | shift 96 | dc_rebuild "$@" 97 | ;; 98 | activate ) 99 | dc_activate 100 | ;; 101 | deactivate ) 102 | dc_deactivate 103 | ;; 104 | screen ) 105 | dc_screen 106 | ;; 107 | *) 108 | docker-compose "$@" 109 | ;; 110 | esac 111 | else 112 | docker-compose 113 | fi 114 | -------------------------------------------------------------------------------- /bin/ddns: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | source ~/.localrc 4 | 5 | IP=`curl -s http://icanhazip.com/` 6 | 7 | curl -H "Authorization: Bearer $DNSIMPLE_TOKEN" \ 8 | -H "Content-Type: application/json" \ 9 | -H "Accept: application/json" \ 10 | -X "PATCH" \ 11 | -i "https://api.dnsimple.com/v2/5138/zones/wynn.fm/records/201010" \ 12 | -d "{\"content\":\"$IP\"}" 13 | -------------------------------------------------------------------------------- /bin/e: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Quick shortcut to an editor. 4 | # 5 | # This means that as I travel back and forth between editors, hey, I don't have 6 | # to re-learn any arcane commands. Neat. 7 | # 8 | # USAGE: 9 | # 10 | # $ e 11 | # # => opens the current directory in your editor 12 | # 13 | # $ e . 14 | # $ e /usr/local 15 | # # => opens the specified directory in your editor 16 | # 17 | # $ e ag PATTERN [FOLDER] 18 | # # => opens the files matching PATTERN in your editor 19 | 20 | if [[ $# -gt 0 ]]; then 21 | case "$1" in 22 | ag ) 23 | shift 24 | $EDITOR $(ag -l "$@") 25 | ;; 26 | *) 27 | $EDITOR "$@" 28 | ;; 29 | esac 30 | else 31 | $EDITOR . 32 | fi 33 | -------------------------------------------------------------------------------- /bin/esv: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # From @pengwynn https://github.com/pengwynn/dotfiles/blob/f17bd6d5685a1b001d4d16ca91daef7b110ecc4f/bin/esv 4 | # with updates for v3 of the esv API. 5 | 6 | command -v jq >/dev/null 2>&1 || { echo >&2 "This command needs jq installed and in PATH. Install with brew install jq"; exit 1; } 7 | 8 | if [ -z $ESV_TOKEN ]; then 9 | echo "ESV_TOKEN environment variable must be set"; 10 | echo "This can be obtained from https://api.esv.org/" 11 | exit 1 12 | fi 13 | 14 | URL="https://api.esv.org/v3/passage/text/" 15 | 16 | # Option defaults 17 | DEBUG=0 18 | REFERENCES=true 19 | FIRST_VERSES=true 20 | VERSES=true 21 | FOOTNOTES=false 22 | COPYRIGHT=false 23 | PASSAGE_LINES=false 24 | HEADING_LINES=false 25 | HEADINGS=true 26 | SUBHEADINGS=true 27 | SELAHS=true 28 | LINE_LENGTH=74 29 | 30 | # Gets the command name without path 31 | cmd(){ echo `basename $0`; } 32 | 33 | # Help command output 34 | usage(){ 35 | echo "\ 36 | `cmd` [OPTION...] 37 | 38 | Display Bible passage from English Standard Version. 39 | This requires jq to be installed and a valid ESV_TOKEN 40 | environment variable. 41 | 42 | Example: `cmd` prov3:5-6 43 | 44 | -f, --first-verse; Show first verse of chapter references 45 | -r, --references; Show passage references 46 | -t, --footnotes; Show footnotes 47 | -p, --passage-lines; Show passage horizontal rules 48 | -l, --heading-lines; Show heading horizontal rules 49 | --lines; Set an option with argument (default: $LINE_LENGTH) 50 | --no-references; Hide passage references 51 | --no-headings; Hide passage headings 52 | --no-subheadings; Hide passage subheadings 53 | --no-verses; Hide verse numbers 54 | --no-selahs; Hide "Selah." in Psalms 55 | " | column -t -s ";" 56 | } 57 | 58 | # Error message 59 | error(){ 60 | echo "`cmd`: invalid option -- '$1'"; 61 | echo "Try '`cmd` -h' for more information."; 62 | exit 1; 63 | } 64 | 65 | # getopt string 66 | opts="frtc:" 67 | 68 | for pass in 1 2; do 69 | while [ -n "$1" ]; do 70 | case $1 in 71 | --) shift; break;; 72 | -*) case $1 in 73 | -h|--help) usage; exit 1;; 74 | -d|--debug) DEBUG=1;; 75 | -f|--first-verses) FIRST_VERSES=true;; 76 | -r|--references) REFERENCES=true;; 77 | -t|--footnotes) FOOTNOTES=true;; 78 | -p|--passage-lines) PASSAGE_LINES=true;; 79 | -l|--heading-lines) HEADING_LINES=true;; 80 | --lines) LINE_LENGTH=$2; shift;; 81 | --no-references) REFERENCES=false;; 82 | --no-headings) HEADINGS=false;; 83 | --no-subheadings) SUBHEADINGS=false;; 84 | --no-verses) FIRST_VERSES=false;VERSES=false;; 85 | --no-selahs) SELAHS=false;; 86 | --*) error $1;; 87 | -*) if [ $pass -eq 1 ]; then ARGS="$ARGS $1"; 88 | else error $1; fi;; 89 | esac;; 90 | *) if [ $pass -eq 1 ]; then ARGS="$ARGS $1"; 91 | else error $1; fi;; 92 | esac 93 | shift 94 | done 95 | if [ $pass -eq 1 ]; then ARGS=`getopt $opts $ARGS` 96 | if [ $? != 0 ]; then usage; exit 2; fi; set -- $ARGS 97 | fi 98 | done 99 | 100 | PASSAGE="$1" 101 | URL+="?include-passage-references=$REFERENCES" 102 | URL+="&include-first-verse-numbers=$FIRST_VERSES" 103 | URL+="&include-verse-numbers=$VERSES" 104 | URL+="&include-footnotes=$FOOTNOTES" 105 | URL+="&include-short-copyright=$COPYRIGHT" 106 | URL+="&include-passage-horizontal-lines=$PASSAGE_LINES" 107 | URL+="&include-heading-horizontal-lines=$HEADING_LINES" 108 | URL+="&include-headings=$HEADINGS" 109 | URL+="&include-subheadings=$SUBHEADINGS" 110 | URL+="&line-length=$LINE_LENGTH" 111 | URL+="&include-selahs=$SELAHS" 112 | URL+="&q=$PASSAGE" 113 | 114 | if [[ $DEBUG -eq 1 ]]; then 115 | echo "DEBUGGING URL:" 116 | echo $URL 117 | echo 118 | fi 119 | 120 | RESPONSE=$(curl -s -H"Authorization: Token $ESV_TOKEN" $URL) 121 | TEXT=$( echo $RESPONSE | jq -r '.passages' | jq -r 'join(" ")' ) 122 | 123 | echo $TEXT 124 | -------------------------------------------------------------------------------- /bin/git-amend: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Use the last commit message and amend your stuffs. 4 | 5 | git commit --amend -C HEAD 6 | -------------------------------------------------------------------------------- /bin/git-churn: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Written by Corey Haines 4 | # Scriptified by Gary Bernhardt 5 | # 6 | # Put this anywhere on your $PATH (~/bin is recommended). Then git will see it 7 | # and you'll be able to do `git churn`. 8 | # 9 | # Show churn for whole repo: 10 | # $ git churn 11 | # 12 | # Show churn for specific directories: 13 | # $ git churn app lib 14 | # 15 | # Show churn for a time range: 16 | # $ git churn --since='1 month ago' 17 | # 18 | # (These are all standard arguments to `git log`.) 19 | 20 | set -e 21 | git log --all -M -C --name-only --format='format:' "$@" | sort | grep -v '^$' | uniq -c | sort -n | awk 'BEGIN {print "count\tfile"} {print $1 "\t" $2}' 22 | -------------------------------------------------------------------------------- /bin/git-ci: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | command -v git >/dev/null 2>&1 || { echo >&2 "This command needs git installed and in PATH."; exit 1; } 3 | command -v jq >/dev/null 2>&1 || { echo >&2 "This command needs jq installed and in PATH. Install with brew install jq"; exit 1; } 4 | 5 | GREEN="\e[0;32;7m" 6 | YELLOW="\e[0;33;7m" 7 | RED="\e[0;31;7m" 8 | NOCOLOR="\e[0m" 9 | 10 | function usage { 11 | read -d '' USAGE <<"BLOCK" 12 | USAGE: git-ci [OPTION] [SHA1] 13 | 14 | SYNOPSIS: 15 | 16 | Display CI status for a GitHub commit 17 | 18 | OPTIONS: 19 | 20 | -o Open the target URL for the build 21 | -d Debug, show the API response 22 | 23 | BLOCK 24 | 25 | echo "$USAGE" 26 | } 27 | 28 | while getopts ":odh" opt; do 29 | case $opt in 30 | o) 31 | OPEN_TARGET=1 32 | ;; 33 | d) 34 | DEBUG=1 35 | ;; 36 | h) 37 | usage 38 | exit 1 39 | ;; 40 | \?) 41 | echo "Invalid option: -$OPTARG" >&2 42 | ;; 43 | esac 44 | done 45 | 46 | # Clear all options and reset the command line 47 | shift $(( OPTIND -1 )) 48 | 49 | if [ -n "$1" ]; then 50 | SHA="$1" 51 | else 52 | if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1 ; then 53 | SHA=$(git rev-parse HEAD) 54 | else 55 | echo "Please supply commit SHA or run from a git Repository" 56 | echo "" 57 | usage 58 | exit 1 59 | fi 60 | fi 61 | 62 | if [ -z "$SHA" ]; then 63 | echo "Commit SHA not found" 64 | echo "" 65 | usage 66 | exit 1 67 | fi 68 | 69 | REPO=$(git config remote.origin.url | cut -d/ -f4- | sed s/.git$//g) 70 | REPO=$(git config --get remote.origin.url | perl -pe's/(git@|https:\/\/)?github.com(:|\/)([-\.\w]+)\/([-\w]+)(\.git)?/$3\/$4/') 71 | API_URL="https://api.github.com/repos/$REPO/statuses/$SHA" 72 | 73 | RESPONSE=$(curl -H"Authorization: bearer $GITHUB_TOKEN" $API_URL) 74 | 75 | STATE=$(echo $RESPONSE | jq -r '.[0].state') 76 | TARGET=$(echo $RESPONSE | jq -r '.[0].target_url') 77 | 78 | case "$STATE" in 79 | pending ) 80 | printf "$YELLOW%s$NOCOLOR %s\n" $STATE $TARGET 81 | ;; 82 | failure ) 83 | printf "$RED%s$NOCOLOR %s\n" $STATE $TARGET 84 | ;; 85 | success ) 86 | printf "$GREEN%s$NOCOLOR %s\n" $STATE $TARGET 87 | ;; 88 | esac 89 | 90 | if [[ -n $OPEN_TARGET ]] && [[ -n $TARGET ]]; then 91 | open $TARGET; 92 | fi 93 | 94 | if [[ -n $DEBUG ]]; then 95 | echo $API_URL 96 | echo $RESPONSE 97 | fi 98 | -------------------------------------------------------------------------------- /bin/git-conflicts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: git-conflicts 3 | # Show list of files in a conflict state. 4 | git ls-files -u | awk '{print $4}' | sort -u 5 | -------------------------------------------------------------------------------- /bin/git-contributors: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Usage: git-contributors 3 | # Show list of contributors sorted by line count 4 | 5 | git --no-pager shortlog -s -n 6 | -------------------------------------------------------------------------------- /bin/git-credential-envvar: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "username=$GITHUB_USER" 4 | echo "password=$GITHUB_TOKEN" 5 | -------------------------------------------------------------------------------- /bin/git-credit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # A very slightly quicker way to credit an author on the latest commit. 4 | # 5 | # $1 - The full name of the author. 6 | # $2 - The email address of the author. 7 | # 8 | # Examples 9 | # 10 | # git credit "Zach Holman" zach@example.com 11 | # 12 | 13 | git commit --amend --author "$1 <$2>" -C HEAD 14 | -------------------------------------------------------------------------------- /bin/git-edit-conflicts: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: git-edit-conflicts 3 | # Edit files in a conflict state. 4 | $EDITOR $(git-conflicts) 5 | -------------------------------------------------------------------------------- /bin/git-exclude: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | mkdir -p .git/info 4 | for pattern in "$@" 5 | do 6 | echo "$pattern" >> .git/info/exclude 7 | done 8 | -------------------------------------------------------------------------------- /bin/git-go: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | command -v hub >/dev/null 2>&1 || { echo >&2 "This command needs hub installed and in PATH. http://defunkt.io/hub"; exit 1; } 3 | 4 | # TODO make login resolution a function call 5 | if [ -z "$GH_LOGIN" ]; then 6 | echo >&2 "Please define GH_LOGIN with your GitHub user to let me know who you are."; exit 1; 7 | fi 8 | 9 | 10 | function gh_browse { 11 | open "https://github.com/$1" 12 | } 13 | 14 | function repo_browse { 15 | if [ -d .git ]; then 16 | hub browse $1 17 | else 18 | echo "Must be in a git repository to run that command." 19 | exit 1 20 | fi 21 | } 22 | 23 | function usage { 24 | read -d '' usage <<"BLOCK" 25 | USAGE: git-go [OPTION] [COMMAND] 26 | 27 | SYNOPSIS: 28 | 29 | CLI helper for GitHub.com, inspired by the CommandBar 30 | http://git.io/_OnQ3Q 31 | 32 | OPTIONS: 33 | 34 | -g Perform command globally, not scoped to current git repository 35 | 36 | COMMANDS: 37 | 38 | search "q" - Perform a search 39 | @user - Browse a user 40 | explore - Explore GitHub 41 | 42 | my [SUBCOMMAND] - Browse your personal items 43 | dashboard 44 | issues [assigned|mentioned|created] 45 | notifications 46 | profile 47 | pulls 48 | settings 49 | stars 50 | 51 | - Everything else forwards to `hub browse` 52 | BLOCK 53 | 54 | echo "$usage" 55 | } 56 | 57 | 58 | [ $# -eq 0 ] && { 59 | usage 60 | exit 1 61 | } 62 | 63 | while getopts ":g" opt; do 64 | case $opt in 65 | g) 66 | global_browse=1 67 | ;; 68 | \?) 69 | echo "Invalid option: -$OPTARG" >&2 70 | ;; 71 | esac 72 | done 73 | 74 | # Clear all options and reset the command line 75 | shift $(( OPTIND -1 )) 76 | 77 | case "$1" in 78 | search ) 79 | gh_browse "search?q=$2" 80 | ;; 81 | @* ) 82 | target=$(echo "$1" | sed 's/@//g') 83 | gh_browse $target 84 | ;; 85 | explore ) 86 | gh_browse 'explore' 87 | ;; 88 | my*) 89 | case $2 in 90 | dashboard ) 91 | gh_browse "dashboard" 92 | ;; 93 | issues ) 94 | if [[ -z $global_browse ]]; then 95 | case $3 in 96 | m* ) 97 | filter="mentioned";; 98 | c* ) 99 | filter="created_by";; 100 | * ) 101 | filter="assigned";; 102 | esac 103 | repo_browse "-- issues/$filter/$GH_LOGIN" 104 | else 105 | gh_browse "dashboard/issues" 106 | fi 107 | ;; 108 | notifications ) 109 | if [[ -z $global_browse ]]; then 110 | repo_browse "-- notifications/$GH_LOGIN" 111 | else 112 | gh_browse "dashboard/notifications" 113 | fi 114 | ;; 115 | profile ) 116 | gh_browse "$GH_LOGIN" 117 | ;; 118 | pulls ) 119 | if [[ -z $global_browse ]]; then 120 | repo_browse "-- pulls/$GH_LOGIN" 121 | else 122 | gh_browse "dashboard/pulls" 123 | fi 124 | ;; 125 | settings ) 126 | gh_browse "settings/profile" 127 | ;; 128 | stars ) 129 | gh_browse "stars" 130 | ;; 131 | esac 132 | ;; 133 | *) 134 | repo_browse "-- $1" 135 | ;; 136 | esac 137 | 138 | -------------------------------------------------------------------------------- /bin/git-grab: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | [ $# -eq 0 ] && { 4 | echo "Clones a repository to $CODE/name@owner" 5 | echo "usage: git-grab " 6 | exit 1 7 | } 8 | 9 | 10 | IFS=' ' read owner name <<< "$(git-nwo $1)" 11 | 12 | dest="$CODE/$name@$owner" 13 | git clone https://github.com/$owner/$name $dest; 14 | -------------------------------------------------------------------------------- /bin/git-nwo: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'octokit' 4 | 5 | target = ARGV.shift 6 | 7 | 8 | def clone(name, owner) 9 | system "echo #{repo} #{path}" 10 | end 11 | 12 | nwo = case target 13 | when /:\/\// 14 | require 'uri' 15 | URI.parse(target).path[1..-1] 16 | else 17 | target 18 | end 19 | 20 | name, owner = nwo.split("/").reverse 21 | 22 | dest = ENV.fetch("CODE", "~/code") 23 | dest = File.join(dest, [name, owner].join("@")) 24 | 25 | puts "%s %s" % [owner, name] 26 | 27 | 28 | # TODO: Look for a repo under my account 29 | # TODO: Look for a repo I have access to 30 | # TODO: Search for repo name 31 | -------------------------------------------------------------------------------- /bin/git-outgoing: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: git-outgoing [-d] [] [ []] 3 | # Show commits on current branch that do not exist on branch . 4 | 5 | # bail out with message to stderr and exit status 1 6 | die() { 7 | echo "$(basename $0):" "$@" 1>&2 8 | exit 1 9 | } 10 | 11 | # colors 12 | SHA=$(git config --get-color 'color.branch.local') 13 | ADD=$(git config --get-color 'color.diff.new') 14 | REM=$(git config --get-color 'color.diff.old') 15 | RESET=$(git config --get-color '' 'reset') 16 | 17 | # check for -d / --diff argument 18 | diff=false 19 | if [ "$1" = '-d' -o "$1" = '--diff' ] 20 | then diff=true 21 | shift 22 | fi 23 | 24 | # get the current branch in refs/heads/ form 25 | ref=$(git symbolic-ref -q HEAD) 26 | test -n "$ref" || 27 | die "you're not on a branch" 28 | 29 | # just the branch name please 30 | branch=$(echo "$ref" | sed 's@^refs/heads/@@') 31 | test -n "$branch" || 32 | die "you're in a weird place; get on a local branch" 33 | 34 | # use tracking branch if no upstream given 35 | if [ $# -eq 0 ] 36 | then 37 | remote=$(git config --get "branch.$branch.remote" || true) 38 | 39 | merge=$(git config branch.$branch.merge) || 40 | die "branch $branch isn't tracking a remote branch and no given" 41 | 42 | set -- "$remote/$(echo "$merge" |sed 's@^refs/heads/@@')" 43 | fi 44 | 45 | if $diff 46 | then git diff "$1"...HEAD 47 | else git cherry -v "$@" | 48 | cut -c1-9 -c43- | 49 | sed -e "s/^\(.\) \(.......\)/\1 $SHA\2$RESET/" | 50 | sed -e "s/^-/$REM-$RESET/" -e "s/^+/$ADD+$RESET/" 51 | fi 52 | -------------------------------------------------------------------------------- /bin/git-pr: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #/ Usage: git pr [] 3 | #/ Open the pull request page for , or the current branch if not 4 | #/ specified. Lands on the new pull request page when no PR exists yet. 5 | #/ The branch must already be pushed 6 | 7 | # Based on script from @rtomayko 8 | set -e 9 | 10 | # usage message 11 | if [ "$1" == "--help" -o "$1" == '-h' ]; then 12 | grep ^#/ "$0" | cut -c4- 13 | exit 14 | fi 15 | 16 | remote_url=$(git config --get remote.origin.url) 17 | repo_with_owner=$(echo $remote_url | perl -pe's/(git@|https:\/\/)?github.com(:|\/)([-\.\w]+)\/([-\w]+)(\.git)?/$3\/$4/') 18 | 19 | # figure out the branch 20 | branch=${1:-"$(git symbolic-ref HEAD | sed 's@refs/heads/@@')"} 21 | 22 | # check that the branch exists in the origin remote first 23 | if git rev-parse "refs/remotes/origin/$branch" 1>/dev/null 2>&1; then 24 | # escape forward slashes 25 | branch=${branch//\//\%2f} 26 | 27 | exec open "https://github.com/$repo_with_owner/pull/$branch" 28 | else 29 | echo "error: branch '$branch' does not exist on the origin remote." 1>&2 30 | echo " try again after pushing the branch" 31 | fi 32 | -------------------------------------------------------------------------------- /bin/git-prune-merged-branches: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #/ Usage: git prune-merged-branches [-fu] [-r ] 3 | #/ Delete all branches that are fully merged into . 4 | #/ 5 | #/ Options: 6 | #/ -f Really delete the branches. Without this, branches are shown but 7 | #/ not actually deleted. 8 | #/ -r Name of remote to operate on. Operate locally when not specified. 9 | #/ -u Fetch before determining merged branch status. 10 | #/ 11 | #/ Examples: 12 | #/ List local branches already merged into master for inspection: 13 | #/ git prune-merged-branches master 14 | #/ 15 | #/ Delete local branches already merged into master: 16 | #/ git prune-merged-branches -f master 17 | #/ 18 | #/ List branches in origin remote already merged into origin/master: 19 | #/ git prune-merged-branches -u -r origin master 20 | #/ 21 | #/ Delete branches in origin remote already merged into origin/master: 22 | #/ git prune-merged-branches -f -r origin/master 23 | set -e 24 | 25 | # show usage message and exit 26 | usage () { 27 | status=${1:-0} 28 | grep '^#/' <"$0"| cut -c4- 29 | exit $status 30 | } 31 | [ $# -eq 0 -o "$1" = "--help" ] && usage 32 | 33 | # parse arguments 34 | force=false 35 | update=false 36 | remote= 37 | while getopts hfur: name 38 | do 39 | case $name in 40 | f) force=true;; 41 | r) remote="$OPTARG";; 42 | u) update=true;; 43 | ?) usage 2;; 44 | esac 45 | done 46 | shift $(($OPTIND - 1)) 47 | 48 | # remaining arg must be a branch name 49 | branch="$1" 50 | [ -n "$branch" ] || usage 2 51 | 52 | # determine branches to delete based on local or remote mode 53 | if [ -n "$remote" ] 54 | then 55 | $update && git fetch "$remote" --prune 56 | mode=Remote 57 | branch_name="$remote/$branch" 58 | branches=$( 59 | git branch --no-color -a --merged "$remote/$branch" | 60 | grep "^..remotes/$remote/" | 61 | grep -v "^..remotes/$remote/$branch$" | 62 | grep -v " -> " | 63 | sed 's|^\(..\)remotes/'$remote'/|\1|' 64 | ) 65 | else 66 | mode=Local 67 | branch_name="$branch" 68 | branches=$( 69 | git branch --no-color --merged "$branch" | 70 | grep -v "^..$branch$" | 71 | grep -v " -> " 72 | ) 73 | fi 74 | 75 | # bail out with no branches 76 | [ -z "$branches" ] && { 77 | echo "no merged branches detected" 1>&2 78 | exit 0 79 | } 80 | 81 | # with no -f option, just show branches that would be deleted 82 | if ! $force 83 | then echo "$mode branches fully merged into $branch_name:" 1>&2 84 | echo "$branches" 85 | echo "Use \`$(basename "$0") -f' if you're sure." 1>&2 86 | exit 87 | fi 88 | 89 | # actually delete the branches via push if remote or via branch -D if local 90 | if [ -n "$remote" ] 91 | then git push origin $(echo "$branches" | sed 's/^../:/') 92 | else git branch -D $(echo "$branches" | cut -c2-) 93 | fi 94 | -------------------------------------------------------------------------------- /bin/git-rank-contributors: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ## git-rank-contributors: a simple script to trace through the logs and 4 | ## rank contributors by the total size of the diffs they're responsible for. 5 | ## A change counts twice as much as a plain addition or deletion. 6 | ## 7 | ## Output may or may not be suitable for inclusion in a CREDITS file. 8 | ## Probably not without some editing, because people often commit from more 9 | ## than one address. 10 | ## 11 | ## git-rank-contributors Copyright 2008 William Morgan . 12 | ## This program is free software: you can redistribute it and/or modify 13 | ## it under the terms of the GNU General Public License as published by 14 | ## the Free Software Foundation, either version 3 of the License, or (at 15 | ## your option) any later version. 16 | ## 17 | ## This program is distributed in the hope that it will be useful, 18 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | ## GNU General Public License for more details. 21 | ## 22 | ## You can find the GNU General Public License at: 23 | ## http://www.gnu.org/licenses/ 24 | 25 | class String 26 | def obfuscate; gsub(/@/, " at the ").gsub(/\.(\w+)(>|$)/, ' dot \1s\2') end 27 | def htmlize; gsub("&", "&").gsub("<", "<").gsub(">", ">") end 28 | end 29 | 30 | lines = {} 31 | verbose = ARGV.delete("-v") 32 | obfuscate = ARGV.delete("-o") 33 | htmlize = ARGV.delete("-h") 34 | 35 | author = nil 36 | state = :pre_author 37 | `git log -M -C -C -p --no-color`.split("\n").each do |l| 38 | case 39 | when (state == :pre_author || state == :post_author) && l =~ /Author: (.*)$/ 40 | author = $1 41 | state = :post_author 42 | lines[author] ||= 0 43 | when state == :post_author && l =~ /^\+\+\+/ 44 | state = :in_diff 45 | when state == :in_diff && l =~ /^[\+\-]/ 46 | lines[author] += 1 47 | when state == :in_diff && l =~ /^commit / 48 | state = :pre_author 49 | end 50 | end 51 | 52 | lines.sort_by { |a, c| -c }.each do |a, c| 53 | a = a.obfuscate if obfuscate 54 | a = a.htmlize if htmlize 55 | if verbose 56 | puts "#{a}: #{c} lines of diff" 57 | else 58 | puts a 59 | end 60 | end -------------------------------------------------------------------------------- /bin/git-rel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: git-rel [] 3 | # Shows the relationship between the current branch and . With no , 4 | # the current branch's remote tracking branch is used. 5 | # 6 | # Examples: 7 | # 8 | # $ git-rel 9 | # 15 ahead 10 | # 11 behind 11 | # 12 | # $ git-rel v1.1 13 | # 230 ahead 14 | 15 | strip_prefix () { 16 | echo "$@" | 17 | sed 's@refs/heads/@@' 18 | } 19 | 20 | current_branch () { 21 | git symbolic-ref -q HEAD | 22 | sed 's@refs/heads/@@' 23 | } 24 | 25 | tracking_branch () { 26 | remote=$(git config --get branch.$(current_branch).remote) 27 | merge=$(git config --get branch.$(current_branch).merge) 28 | echo "$remote/$(strip_prefix $merge)" 29 | } 30 | 31 | ref="${1:-$(tracking_branch)}" 32 | 33 | git rev-list --left-right --abbrev-commit --abbrev $ref...HEAD | 34 | cut -c1 | 35 | sort | 36 | uniq -c | 37 | tr '\n' ',' | 38 | sed " 39 | s/>/ahead/ 40 | s/.. 3 | # 4 | # All commits on master, ever: 5 | # git-thanks master 6 | # 7 | # All commits on master since the 0.9.0 tag: 8 | # git-thanks 0.9.0..master 9 | 10 | git log "$1" | 11 | grep Author: | 12 | sed 's/Author: \(.*\) <.*/\1/' | 13 | sort | 14 | uniq -c | 15 | sort -rn | 16 | sed 's/ *\([0-9]\{1,\}\) \(.*\)/\2 (\1)/' 17 | -------------------------------------------------------------------------------- /bin/git-undo: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Undo your last commit, but don't throw away your changes 4 | 5 | git reset --soft HEAD^ 6 | -------------------------------------------------------------------------------- /bin/git-wtf: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | HELP = < 54 | .git-wtfrc" and edit it. The config file is a YAML file that specifies the 55 | integration branches, any branches to ignore, and the max number of commits to 56 | display when --all-commits isn't used. git-wtf will look for a .git-wtfrc file 57 | starting in the current directory, and recursively up to the root. 58 | 59 | IMPORTANT NOTE: all local branches referenced in .git-wtfrc must be prefixed 60 | with heads/, e.g. "heads/master". Remote branches must be of the form 61 | remotes//. 62 | EOS 63 | 64 | COPYRIGHT = <. 66 | This program is free software: you can redistribute it and/or modify it 67 | under the terms of the GNU General Public License as published by the Free 68 | Software Foundation, either version 3 of the License, or (at your option) 69 | any later version. 70 | 71 | This program is distributed in the hope that it will be useful, but WITHOUT 72 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 74 | more details. 75 | 76 | You can find the GNU General Public License at: http://www.gnu.org/licenses/ 77 | EOS 78 | 79 | require 'yaml' 80 | CONFIG_FN = ".git-wtfrc" 81 | 82 | class Numeric; def pluralize s; "#{to_s} #{s}" + (self != 1 ? "s" : "") end end 83 | 84 | if ARGV.delete("--help") || ARGV.delete("-h") 85 | puts USAGE 86 | exit 87 | end 88 | 89 | ## poor man's trollop 90 | $long = ARGV.delete("--long") || ARGV.delete("-l") 91 | $short = ARGV.delete("--short") || ARGV.delete("-s") 92 | $all = ARGV.delete("--all") || ARGV.delete("-a") 93 | $all_commits = ARGV.delete("--all-commits") || ARGV.delete("-A") 94 | $dump_config = ARGV.delete("--dump-config") 95 | $key = ARGV.delete("--key") || ARGV.delete("-k") 96 | $show_relations = ARGV.delete("--relations") || ARGV.delete("-r") 97 | ARGV.each { |a| abort "Error: unknown argument #{a}." if a =~ /^--/ } 98 | 99 | ## search up the path for a file 100 | def find_file fn 101 | while true 102 | return fn if File.exist? fn 103 | fn2 = File.join("..", fn) 104 | return nil if File.expand_path(fn2) == File.expand_path(fn) 105 | fn = fn2 106 | end 107 | end 108 | 109 | want_color = `git config color.wtf` 110 | want_color = `git config color.ui` if want_color.empty? 111 | $color = case want_color.chomp 112 | when "true"; true 113 | when "auto"; $stdout.tty? 114 | end 115 | 116 | def red s; $color ? "\033[31m#{s}\033[0m" : s end 117 | def green s; $color ? "\033[32m#{s}\033[0m" : s end 118 | def yellow s; $color ? "\033[33m#{s}\033[0m" : s end 119 | def cyan s; $color ? "\033[36m#{s}\033[0m" : s end 120 | def grey s; $color ? "\033[1;30m#{s}\033[0m" : s end 121 | def purple s; $color ? "\033[35m#{s}\033[0m" : s end 122 | 123 | ## the set of commits in 'to' that aren't in 'from'. 124 | ## if empty, 'to' has been merged into 'from'. 125 | def commits_between from, to 126 | if $long 127 | `git log --pretty=format:"- %s [#{yellow "%h"}] (#{purple "%ae"}; %ar)" #{from}..#{to}` 128 | else 129 | `git log --pretty=format:"- %s [#{yellow "%h"}]" #{from}..#{to}` 130 | end.split(/[\r\n]+/) 131 | end 132 | 133 | def show_commits commits, prefix=" " 134 | if commits.empty? 135 | puts "#{prefix} none" 136 | else 137 | max = $all_commits ? commits.size : $config["max_commits"] 138 | max -= 1 if max == commits.size - 1 # never show "and 1 more" 139 | commits[0 ... max].each { |c| puts "#{prefix}#{c}" } 140 | puts grey("#{prefix}... and #{commits.size - max} more (use -A to see all).") if commits.size > max 141 | end 142 | end 143 | 144 | def ahead_behind_string ahead, behind 145 | [ahead.empty? ? nil : "#{ahead.size.pluralize 'commit'} ahead", 146 | behind.empty? ? nil : "#{behind.size.pluralize 'commit'} behind"]. 147 | compact.join("; ") 148 | end 149 | 150 | def widget merged_in, remote_only=false, local_only=false, local_only_merge=false 151 | left, right = case 152 | when remote_only; %w({ }) 153 | when local_only; %w{( )} 154 | else %w([ ]) 155 | end 156 | middle = case 157 | when merged_in && local_only_merge; green("~") 158 | when merged_in; green("x") 159 | else " " 160 | end 161 | print left, middle, right 162 | end 163 | 164 | def show b 165 | have_both = b[:local_branch] && b[:remote_branch] 166 | 167 | pushc, pullc, oosync = if have_both 168 | [x = commits_between(b[:remote_branch], b[:local_branch]), 169 | y = commits_between(b[:local_branch], b[:remote_branch]), 170 | !x.empty? && !y.empty?] 171 | end 172 | 173 | if b[:local_branch] 174 | puts "Local branch: " + green(b[:local_branch].sub(/^heads\//, "")) 175 | 176 | if have_both 177 | if pushc.empty? 178 | puts "#{widget true} in sync with remote" 179 | else 180 | action = oosync ? "push after rebase / merge" : "push" 181 | puts "#{widget false} NOT in sync with remote (you should #{action})" 182 | show_commits pushc unless $short 183 | end 184 | end 185 | end 186 | 187 | if b[:remote_branch] 188 | puts "Remote branch: #{cyan b[:remote_branch]} (#{b[:remote_url]})" 189 | 190 | if have_both 191 | if pullc.empty? 192 | puts "#{widget true} in sync with local" 193 | else 194 | action = pushc.empty? ? "merge" : "rebase / merge" 195 | puts "#{widget false} NOT in sync with local (you should #{action})" 196 | show_commits pullc unless $short 197 | end 198 | end 199 | end 200 | 201 | puts "\n#{red "WARNING"}: local and remote branches have diverged. A merge will occur unless you rebase." if oosync 202 | end 203 | 204 | def show_relations b, all_branches 205 | ibs, fbs = all_branches.partition { |name, br| $config["integration-branches"].include?(br[:local_branch]) || $config["integration-branches"].include?(br[:remote_branch]) } 206 | if $config["integration-branches"].include? b[:local_branch] 207 | puts "\nFeature branches:" unless fbs.empty? 208 | fbs.each do |name, br| 209 | next if $config["ignore"].member?(br[:local_branch]) || $config["ignore"].member?(br[:remote_branch]) 210 | next if br[:ignore] 211 | local_only = br[:remote_branch].nil? 212 | remote_only = br[:local_branch].nil? 213 | name = if local_only 214 | purple br[:name] 215 | elsif remote_only 216 | cyan br[:name] 217 | else 218 | green br[:name] 219 | end 220 | 221 | ## for remote_only branches, we'll compute wrt the remote branch head. otherwise, we'll 222 | ## use the local branch head. 223 | head = remote_only ? br[:remote_branch] : br[:local_branch] 224 | 225 | remote_ahead = b[:remote_branch] ? commits_between(b[:remote_branch], head) : [] 226 | local_ahead = b[:local_branch] ? commits_between(b[:local_branch], head) : [] 227 | 228 | if local_ahead.empty? && remote_ahead.empty? 229 | puts "#{widget true, remote_only, local_only} #{name} #{local_only ? "(local-only) " : ""}is merged in" 230 | elsif local_ahead.empty? 231 | puts "#{widget true, remote_only, local_only, true} #{name} merged in (only locally)" 232 | else 233 | behind = commits_between head, (br[:local_branch] || br[:remote_branch]) 234 | ahead = remote_only ? remote_ahead : local_ahead 235 | puts "#{widget false, remote_only, local_only} #{name} #{local_only ? "(local-only) " : ""}is NOT merged in (#{ahead_behind_string ahead, behind})" 236 | show_commits ahead unless $short 237 | end 238 | end 239 | else 240 | puts "\nIntegration branches:" unless ibs.empty? # unlikely 241 | ibs.sort_by { |v, br| v }.each do |v, br| 242 | next if $config["ignore"].member?(br[:local_branch]) || $config["ignore"].member?(br[:remote_branch]) 243 | next if br[:ignore] 244 | local_only = br[:remote_branch].nil? 245 | remote_only = br[:local_branch].nil? 246 | name = remote_only ? cyan(br[:name]) : green(br[:name]) 247 | 248 | ahead = commits_between v, (b[:local_branch] || b[:remote_branch]) 249 | if ahead.empty? 250 | puts "#{widget true, local_only} merged into #{name}" 251 | else 252 | #behind = commits_between b[:local_branch], v 253 | puts "#{widget false, local_only} NOT merged into #{name} (#{ahead.size.pluralize 'commit'} ahead)" 254 | show_commits ahead unless $short 255 | end 256 | end 257 | end 258 | end 259 | 260 | #### EXECUTION STARTS HERE #### 261 | 262 | ## find config file and load it 263 | $config = { "integration-branches" => %w(heads/master heads/next heads/edge), "ignore" => [], "max_commits" => 5 }.merge begin 264 | fn = find_file CONFIG_FN 265 | if fn && (h = YAML::load_file(fn)) # yaml turns empty files into false 266 | h["integration-branches"] ||= h["versions"] # support old nomenclature 267 | h 268 | else 269 | {} 270 | end 271 | end 272 | 273 | if $dump_config 274 | puts $config.to_yaml 275 | exit 276 | end 277 | 278 | ## first, index registered remotes 279 | remotes = `git config --get-regexp ^remote\.\*\.url`.split(/[\r\n]+/).inject({}) do |hash, l| 280 | l =~ /^remote\.(.+?)\.url (.+)$/ or next hash 281 | hash[$1] ||= $2 282 | hash 283 | end 284 | 285 | ## next, index followed branches 286 | branches = `git config --get-regexp ^branch\.`.split(/[\r\n]+/).inject({}) do |hash, l| 287 | case l 288 | when /branch\.(.*?)\.remote (.+)/ 289 | name, remote = $1, $2 290 | 291 | hash[name] ||= {} 292 | hash[name].merge! :remote => remote, :remote_url => remotes[remote] 293 | when /branch\.(.*?)\.merge ((refs\/)?heads\/)?(.+)/ 294 | name, remote_branch = $1, $4 295 | hash[name] ||= {} 296 | hash[name].merge! :remote_mergepoint => remote_branch 297 | end 298 | hash 299 | end 300 | 301 | ## finally, index all branches 302 | remote_branches = {} 303 | `git show-ref`.split(/[\r\n]+/).each do |l| 304 | sha1, ref = l.chomp.split " refs/" 305 | 306 | if ref =~ /^heads\/(.+)$/ # local branch 307 | name = $1 308 | next if name == "HEAD" 309 | branches[name] ||= {} 310 | branches[name].merge! :name => name, :local_branch => ref 311 | elsif ref =~ /^remotes\/(.+?)\/(.+)$/ # remote branch 312 | remote, name = $1, $2 313 | remote_branches["#{remote}/#{name}"] = true 314 | next if name == "HEAD" 315 | ignore = !($all || remote == "origin") 316 | 317 | branch = name 318 | if branches[name] && branches[name][:remote] == remote 319 | # nothing 320 | else 321 | name = "#{remote}/#{branch}" 322 | end 323 | 324 | branches[name] ||= {} 325 | branches[name].merge! :name => name, :remote => remote, :remote_branch => "#{remote}/#{branch}", :remote_url => remotes[remote], :ignore => ignore 326 | end 327 | end 328 | 329 | ## assemble remotes 330 | branches.each do |k, b| 331 | next unless b[:remote] && b[:remote_mergepoint] 332 | b[:remote_branch] = if b[:remote] == "." 333 | b[:remote_mergepoint] 334 | else 335 | t = "#{b[:remote]}/#{b[:remote_mergepoint]}" 336 | remote_branches[t] && t # only if it's still alive 337 | end 338 | end 339 | 340 | show_dirty = ARGV.empty? 341 | targets = if ARGV.empty? 342 | [`git symbolic-ref HEAD`.chomp.sub(/^refs\/heads\//, "")] 343 | else 344 | ARGV.map { |x| x.sub(/^heads\//, "") } 345 | end.map { |t| branches[t] or abort "Error: can't find branch #{t.inspect}." } 346 | 347 | targets.each do |t| 348 | show t 349 | show_relations t, branches if $show_relations || t[:remote_branch].nil? 350 | end 351 | 352 | modified = show_dirty && `git ls-files -m` != "" 353 | uncommitted = show_dirty && `git diff-index --cached HEAD` != "" 354 | 355 | if $key 356 | puts 357 | puts KEY 358 | end 359 | 360 | puts if modified || uncommitted 361 | puts "#{red "NOTE"}: working directory contains modified files." if modified 362 | puts "#{red "NOTE"}: staging area contains staged but uncommitted files." if uncommitted 363 | 364 | # the end! -------------------------------------------------------------------------------- /bin/hint: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | SITE="https://devhints.io" 4 | STATUS=$(curl -w "%{http_code}" -s --output /dev/null "$SITE/$1") 5 | 6 | case "$STATUS" in 7 | 404) open "$SITE/?q=$1";; 8 | *) open "$SITE/$1";; 9 | esac 10 | -------------------------------------------------------------------------------- /bin/hissuegram: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # Usage: GITHUB_TOKEN=yourtoken hissuegram owner/repo 4 | # 5 | # Lifted from @aroben https://gist.github.com/aroben/5b1eaf5318b04183231b 6 | 7 | def usage 8 | "GITHUB_TOKEN=yourtoken hissuegram owner/repo" 9 | end 10 | 11 | begin 12 | require "octokit" 13 | rescue LoadError 14 | puts "hissuegram requires the octokit gem. Please run\n\ngem install octokit" 15 | exit 1 16 | end 17 | 18 | unless access_token = ENV.fetch("GITHUB_TOKEN") 19 | usage 20 | exit 1 21 | end 22 | 23 | unless repo = ARGV[0] 24 | usage 25 | exit 1 26 | end 27 | 28 | 29 | client = Octokit::Client.new \ 30 | :access_token => access_token, 31 | :auto_paginate => true 32 | 33 | begin 34 | issues = client.issues repo, :state => :open 35 | rescue Octokit::NotFound 36 | puts "Repository #{repo} not found." 37 | exit 1 38 | end 39 | 40 | dates = issues.map { |i| i["created_at"] } 41 | days_ago = dates.map { |d| ((Time.now - d) / (60 * 60 * 24)).round } 42 | buckets = days_ago.group_by { |d| d / 7 }.map { |bucket, contents| [bucket, contents.length] }.sort 43 | 44 | puts sprintf("%10s %7s", "weeks ago", "count") 45 | puts buckets.map { |bucket, count| sprintf("% 10d % 7d %s", bucket, count, "=" * count) }.join("\n") 46 | -------------------------------------------------------------------------------- /bin/intersect: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | comm -12 <(sort $1) <(sort $2) 4 | -------------------------------------------------------------------------------- /bin/ipsum: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | URL="http://loripsum.net/api" 4 | 5 | # Option defaults 6 | PLAIN=0 7 | DEBUG=0 8 | HEADINGS=0 9 | DECORATE=0 10 | LINKS=0 11 | OL=0 12 | UL=0 13 | DL=0 14 | BLOCKQUOTE=0 15 | CODE=0 16 | ALLCAPS=0 17 | PRUDE=0 18 | 19 | 20 | # Gets the command name without path 21 | cmd(){ echo `basename $0`; } 22 | 23 | # Help command output 24 | usage(){ 25 | echo "\ 26 | `cmd` [OPTION...] 27 | 28 | Grab some placeholder copy from http://loripsum.net/ 29 | 30 | Example: `cmd` --headings --long --plain 31 | 32 | --headings; Add headings 33 | --short; Use short paragraph length 34 | --medium; Use medium paragraph length 35 | --long; Use long paragraph length 36 | --verylong; Use verylong paragraph length 37 | --decorate; Add bold, italic and marked text 38 | --links; Add links 39 | --ol; Add ordered lists 40 | --ul; Add unordered lists 41 | --dl; Add description lists 42 | --bq; Add blockquotes 43 | --code; Add code blocks 44 | --caps; Use ALL CAPS 45 | --prude; Use prude version 46 | --[no-]plain; Return plain text 47 | --[no-]html; Return html 48 | " | column -t -s ";" 49 | } 50 | 51 | # Error message 52 | error(){ 53 | echo "`cmd`: invalid option -- '$1'"; 54 | echo "Try '`cmd` -h' for more information."; 55 | exit 1; 56 | } 57 | 58 | # getopt string 59 | opts="hd:" 60 | 61 | for pass in 1 2; do 62 | while [ -n "$1" ]; do 63 | case $1 in 64 | --) shift; break;; 65 | -*) case $1 in 66 | -h|--help) usage; exit 1;; 67 | -d|--debug) DEBUG=1;; 68 | --headings) HEADINGS=1;; 69 | --short) LENGTH="short";; 70 | --medium) LENGTH="medium";; 71 | --long) LENGTH="long";; 72 | --verylong) LENGTH="verylong";; 73 | --decorate) DECORATE=1;; 74 | --links) LINKS=1;; 75 | --ol) OL=1;; 76 | --ul) UL=1;; 77 | --dl) DL=1;; 78 | --bq|--blockquote) BLOCKQUOTE=1;; 79 | --code) CODE=1;; 80 | --caps) ALLCAPS=1;; 81 | --prude) PRUDE=1;; 82 | --plain|--no-html) PLAIN=1;; 83 | --no-plain|--html) PLAIN=0;; 84 | --*) error $1;; 85 | -*) if [ $pass -eq 1 ]; then ARGS="$ARGS $1"; 86 | else error $1; fi;; 87 | esac;; 88 | *) if [ $pass -eq 1 ]; then ARGS="$ARGS $1"; 89 | else error $1; fi;; 90 | esac 91 | shift 92 | done 93 | if [ $pass -eq 1 ]; then ARGS=`getopt $opts $ARGS` 94 | if [ $? != 0 ]; then usage; exit 2; fi; set -- $ARGS 95 | fi 96 | done 97 | 98 | if [[ $PLAIN -eq 1 ]]; then 99 | URL+="/plaintext" 100 | fi 101 | 102 | if [[ $HEADINGS -eq 1 ]]; then 103 | URL+="/headers" 104 | fi 105 | 106 | if [[ ! -z $LENGTH ]]; then 107 | URL+="/$LENGTH" 108 | fi 109 | 110 | if [[ $DECORATE -eq 1 ]]; then 111 | URL+="/decorate" 112 | fi 113 | 114 | if [[ $LINKS -eq 1 ]]; then 115 | URL+="/links" 116 | fi 117 | 118 | if [[ $OL -eq 1 ]]; then 119 | URL+="/ol" 120 | fi 121 | 122 | if [[ $UL -eq 1 ]]; then 123 | URL+="/ul" 124 | fi 125 | 126 | if [[ $DL -eq 1 ]]; then 127 | URL+="/dl" 128 | fi 129 | 130 | if [[ $BLOCKQUOTE -eq 1 ]]; then 131 | URL+="/bq" 132 | fi 133 | 134 | if [[ $CODE -eq 1 ]]; then 135 | URL+="/code" 136 | fi 137 | 138 | if [[ $ALLCAPS -eq 1 ]]; then 139 | URL+="/allcaps" 140 | fi 141 | 142 | if [[ $PRUDE -eq 1 ]]; then 143 | URL+="/prude" 144 | fi 145 | 146 | 147 | if [[ $DEBUG -eq 1 ]]; then 148 | echo "URL:" 149 | echo $URL 150 | echo 151 | fi 152 | 153 | curl -s $URL 154 | echo 155 | -------------------------------------------------------------------------------- /bin/ish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | let chalk, fetch, owner, repo; 4 | try { 5 | chalk = require("chalk"); 6 | fetch = require("cross-fetch"); 7 | } catch (e) { 8 | console.log( 9 | "Please ensure `chalk` and `cross-fetch` are installed from npm and NODE_PATH is set in this environment." 10 | ); 11 | process.exit(1); 12 | } 13 | 14 | if (!process.env.GITHUB_TOKEN) { 15 | console.log("Please ensure GITHUB_TOKEN is set in this environment."); 16 | process.exit(1); 17 | } 18 | 19 | function resolveRepo(target) { 20 | if (target) { 21 | [owner, repo] = target.split("/"); 22 | return; 23 | } 24 | const { spawnSync } = require("child_process"); 25 | const getOriginUrl = spawnSync("git", [ 26 | "config", 27 | "--get", 28 | "remote.origin.url" 29 | ]); 30 | const originUrl = getOriginUrl.stdout.toString().trim(); 31 | [, owner, repo] = originUrl 32 | .split(/\.com/)[1] 33 | .replace(".git", "") 34 | .split(/[:/]/); 35 | } 36 | 37 | try { 38 | resolveRepo(process.argv.slice(2)[0]); 39 | } catch (e) { 40 | console.log(`ish 41 | 42 | Displays the GitHub issues you're subscribed to for the specified repository. 43 | 44 | Usage: 45 | ish [/] 46 | `); 47 | process.exit(1); 48 | } 49 | 50 | (async () => { 51 | try { 52 | const res = await fetch("https://api.github.com/graphql", { 53 | headers: { Authorization: `bearer ${process.env.GITHUB_TOKEN}` }, 54 | method: "POST", 55 | body: JSON.stringify({ 56 | query: ` 57 | query { 58 | repository(owner: "${owner}", name: "${repo}") { 59 | issues(first: 100, filterBy: {viewerSubscribed: true}) { 60 | edges { 61 | node { 62 | title 63 | url 64 | } 65 | } 66 | } 67 | } 68 | } 69 | ` 70 | }) 71 | }); 72 | 73 | if (res.status >= 400) { 74 | throw new Error("Bad response from server"); 75 | } 76 | 77 | const { data } = await res.json(); 78 | 79 | if (!data.repository) { 80 | console.error(chalk.red(`Could not resolve repository ${owner}/${repo}`)); 81 | process.exit(1); 82 | } 83 | 84 | const { 85 | repository: { 86 | issues: { edges } 87 | } 88 | } = data; 89 | 90 | edges.forEach(({ node: { title, url } }) => { 91 | console.log(); 92 | console.log(chalk.green(title)); 93 | console.log(url); 94 | }); 95 | } catch (err) { 96 | console.error(err); 97 | } 98 | })(); 99 | -------------------------------------------------------------------------------- /bin/iso8601: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Usage: iso8601 [] 3 | # Show a date in iso8601 format 4 | 5 | set -e 6 | if [[ -z "$1" ]]; then 7 | date -u +"%Y-%m-%dT%H:%M:%SZ" 8 | else 9 | date -r "$1" +"%Y-%m-%dT%H:%M:%SZ" 10 | fi 11 | -------------------------------------------------------------------------------- /bin/license: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: license 3 | # Prints an MIT license appropriate for totin' around. 4 | # 5 | # $ license > COPYING 6 | # 7 | # Original version by Chris Wanstrath: 8 | # http://gist.github.com/287717 9 | exec sh -c "tail -n +$(($LINENO + 2)) < $0" 10 | 11 | Copyright (c) Wynn Netherland 12 | 13 | Permission is hereby granted, free of charge, to any person ob- 14 | taining a copy of this software and associated documentation 15 | files (the "Software"), to deal in the Software without restric- 16 | tion, including without limitation the rights to use, copy, modi- 17 | fy, merge, publish, distribute, sublicense, and/or sell copies of 18 | the Software, and to permit persons to whom the Software is fur- 19 | nished to do so, subject to the following conditions: 20 | 21 | The above copyright notice and this permission notice shall be 22 | included in all copies or substantial portions of the Software. 23 | 24 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 26 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN- 27 | FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 | SOFTWARE. 32 | -------------------------------------------------------------------------------- /bin/lsrb: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #/ Usage: lsrb ... 3 | #/ List class, module, and method definitions in Ruby . 4 | set -e 5 | 6 | # show usage 7 | [ -z "$1" -o "$1" = "--help" ] && { 8 | grep ^#/ <"$0" |cut -c4- 9 | exit 2 10 | } 11 | 12 | # run over files and grep out interesting bits 13 | for f in "$@" 14 | do echo "$f:" 15 | grep -e '^[ ]*\(class\|module\|def\|alias\|alias_method\|private\)\(\s\|$\)' "$f" | 16 | sed 's/^/ /' 17 | done 18 | -------------------------------------------------------------------------------- /bin/movieme: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # MOVIE ME as in: "MOVIE ME AN ANIMATED GIF FROM THIS MOVIE, DAMMIT" 4 | # 5 | # Creates an animated gif from a movie file. Uploads to CloudApp. You must also 6 | # have `gifme` and `cloudapp` in your $PATH. 7 | # 8 | # $1 - the path to the movie we're converting. 9 | # $2 - the start time of the finished product. 10 | # This can be in seconds, or it also accepts the "hh:mm:ss[.xxx]" format. 11 | # $3 - the duration of the video sequence. 12 | # This can be in seconds, or it also accepts the "hh:mm:ss[.xxx]" format. 13 | # 14 | # Examples: 15 | # 16 | # movieme 17 | # ~/Desktop/dr-strangelove.mp4 23:12 3 18 | # ~/Desktop/holman-backflip-on-fire.mov 3.9 1.75 19 | 20 | # cleanup 21 | rm -rf /tmp/movieme 22 | 23 | # create tmp dir 24 | mkdir -p /tmp/movieme 25 | 26 | # split the movie into constituent frames 27 | ffmpeg -i $1 -f image2 -ss $2 -t $3 -r 7 /tmp/movieme/d-%05d.png 28 | 29 | # ANIMATE 30 | gifme /tmp/movieme/* -d 0 31 | -------------------------------------------------------------------------------- /bin/mx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # mx 4 | # version 0.4 5 | 6 | # Contributors: 7 | # Wynn Netherland - http://github.com/pengwynn 8 | # Adam Jahnke - http://github.com/adamyonk 9 | 10 | # Usage: 11 | # mx [session] 12 | 13 | # To 'auto-launch' projects, you'll need a $PROJECTS dir where you keep code 14 | # sorted like so: $PROJECTS//. 15 | # So, a typical workflow would look like: 16 | # $ hub clone pengwynn/octonaut $PROJECTS/pengwynn/octonaut 17 | # $ mx octonaut 18 | 19 | # If `mx` is called with a name, and there is no valid repo inside 20 | # $PROJECTS, a new tmux session will be initialized in the current working 21 | # directory with a name of 22 | 23 | # If the target directory has a .tmux file, that file will be executed 24 | # (and sent the name as the first argument) instead of the default 25 | # window setup (explained below). An example .tmux file may look like 26 | # so: 27 | # #!/usr/bin/env sh 28 | # SESSION="$1" 29 | # cd ~/.dotfiles 30 | # tmux new-session -s "$SESSION" -n editor -d 31 | # tmux send-keys 'e' C-m ':CtrlP' C-m 32 | # tmux select-window -t "$SESSION":1 33 | 34 | # If there is no .tmux file, the default window setup is as follows: 35 | # editor/shell - runs $EDITOR right away and a new shell in a 50/50 split 36 | # console - if script/console is available 37 | # server - if script/server is available 38 | 39 | set -e 40 | 41 | if [ -z "$1" ]; then 42 | SESSION="${PWD##*/}" 43 | else 44 | SESSION="$1" 45 | fi 46 | 47 | # tmux 1.9a+ doesn't like .'s in session names 48 | SESSION="${SESSION//./_}" 49 | 50 | _safe_window() { 51 | if [ -x "$2" ]; then 52 | tmux new-window -n "$1" -t "$SESSION" 53 | tmux send-keys "$2" C-m 54 | fi 55 | } 56 | 57 | if ! (tmux list-sessions | cut -d':' -f1 | grep -q ^"$SESSION"\$); then 58 | if [ -d "$PROJECTS"/"$SESSION" ]; then 59 | cd "$PROJECTS"/"$SESSION" 60 | fi 61 | 62 | if [ -f "$PWD"/.tmux ]; then 63 | bash "$PWD"/.tmux "$SESSION" 64 | else 65 | tmux new-session -s "$SESSION" -n editor -d 66 | tmux send-keys "$EDITOR" C-m #':CtrlP' C-m 67 | tmux split-window -h 68 | _safe_window console script/console 69 | _safe_window server script/server 70 | 71 | tmux select-window -t "$SESSION":1 72 | tmux select-pane -t0 73 | fi 74 | fi 75 | 76 | if [ -z "$TMUX" ]; then 77 | tmux attach -t "$SESSION" 78 | else 79 | tmux switch-client -t "$SESSION" 80 | fi 81 | -------------------------------------------------------------------------------- /bin/new-tmux-project-window: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | if [ "$2" ]; then 6 | NEW_WINDOW_NAME="$2" 7 | else 8 | NEW_WINDOW_NAME="$(basename $1)" 9 | fi 10 | 11 | 12 | if tmux list-windows -F"#W" | grep $1 -q 13 | then 14 | index=$(tmux list-windows -F"#I") 15 | tmux select-window -t $index 16 | else 17 | tmux new-window -c "$1" -n $NEW_WINDOW_NAME 18 | tmux send-keys "$EDITOR" C-m 19 | tmux split-window -h -c "$1" 20 | tmux select-pane -t0 21 | tmux resize-pane -Z 22 | fi 23 | 24 | 25 | -------------------------------------------------------------------------------- /bin/osx: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Via https://raw.github.com/mathiasbynens/dotfiles/master/.osx 4 | 5 | # Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs) 6 | defaults write NSGlobalDomain AppleKeyboardUIMode -int 3 7 | 8 | # Enable subpixel font rendering on non-Apple LCDs 9 | defaults write NSGlobalDomain AppleFontSmoothing -int 2 10 | 11 | # Enable the 2D Dock 12 | # defaults write com.apple.dock no-glass -bool true 13 | 14 | # Automatically hide and show the Dock 15 | defaults write com.apple.dock autohide -bool true 16 | 17 | # Make Dock icons of hidden applications translucent 18 | #defaults write com.apple.dock showhidden -bool false 19 | 20 | # Disable menu bar transparency 21 | defaults write NSGlobalDomain AppleEnableMenuBarTransparency -bool false 22 | 23 | # Show remaining battery time; hide percentage 24 | defaults write com.apple.menuextra.battery ShowPercent -string "NO" 25 | defaults write com.apple.menuextra.battery ShowTime -string "YES" 26 | 27 | # Always show scrollbars 28 | #defaults write NSGlobalDomain AppleShowScrollBars -string "Always" 29 | 30 | # Allow quitting Finder via ⌘ + Q; doing so will also hide desktop icons 31 | defaults write com.apple.finder QuitMenuItem -bool true 32 | 33 | # Show all filename extensions in Finder 34 | defaults write NSGlobalDomain AppleShowAllExtensions -bool true 35 | 36 | # Expand save panel by default 37 | defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true 38 | 39 | # Expand print panel by default 40 | defaults write NSGlobalDomain PMPrintingExpandedStateForPrint -bool true 41 | 42 | # Disable the “Are you sure you want to open this application?” dialog 43 | defaults write com.apple.LaunchServices LSQuarantine -bool false 44 | 45 | # Disable shadow in screenshots 46 | defaults write com.apple.screencapture disable-shadow -bool true 47 | 48 | # Enable highlight hover effect for the grid view of a stack (Dock) 49 | defaults write com.apple.dock mouse-over-hilte-stack -bool true 50 | 51 | # Enable spring loading for all Dock items 52 | defaults write enable-spring-load-actions-on-all-items -bool true 53 | 54 | # Show indicator lights for open applications in the Dock 55 | defaults write com.apple.dock show-process-indicators -bool true 56 | 57 | # Don’t animate opening applications from the Dock 58 | defaults write com.apple.dock launchanim -bool false 59 | 60 | # Disable press-and-hold for keys in favor of key repeat 61 | defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false 62 | 63 | # Set a blazingly fast keyboard repeat rate 64 | defaults write NSGlobalDomain KeyRepeat -int 0 65 | 66 | # Disable auto-correct 67 | defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false 68 | 69 | # Disable window animations 70 | defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false 71 | 72 | # Enable AirDrop over Ethernet and on unsupported Macs running Lion 73 | defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true 74 | 75 | # Disable disk image verification 76 | defaults write com.apple.frameworks.diskimages skip-verify -bool true 77 | defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true 78 | defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true 79 | 80 | # Automatically open a new Finder window when a volume is mounted 81 | defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true 82 | defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true 83 | 84 | # Display full POSIX path as Finder window title 85 | defaults write com.apple.finder _FXShowPosixPathInTitle -bool true 86 | 87 | # Increase window resize speed for Cocoa applications 88 | defaults write NSGlobalDomain NSWindowResizeTime -float 0.001 89 | 90 | # Avoid creating .DS_Store files on network volumes 91 | defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true 92 | 93 | # Disable the warning when changing a file extension 94 | defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false 95 | 96 | # Show item info below desktop icons 97 | /usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist 98 | 99 | # Disable the warning before emptying the Trash 100 | defaults write com.apple.finder WarnOnEmptyTrash -bool false 101 | 102 | # Empty Trash securely by default 103 | # defaults write com.apple.finder EmptyTrashSecurely -bool false 104 | 105 | # Require password immediately after sleep or screen saver begins 106 | # defaults write com.apple.screensaver askForPassword -int 1 107 | # defaults write com.apple.screensaver askForPasswordDelay -int 0 108 | 109 | # Enable tap to click (Trackpad) 110 | defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true 111 | 112 | # Map bottom right Trackpad corner to right-click 113 | # defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2 114 | # defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true 115 | 116 | # Disable Safari’s thumbnail cache for History and Top Sites 117 | defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2 118 | 119 | # Enable Safari’s debug menu 120 | defaults write com.apple.Safari IncludeInternalDebugMenu -bool true 121 | 122 | # Remove useless icons from Safari’s bookmarks bar 123 | # defaults write com.apple.Safari ProxiesInBookmarksBar "()" 124 | 125 | # Only use UTF-8 in Terminal.app 126 | defaults write com.apple.terminal StringEncodings -array 4 127 | 128 | # Disable the Ping sidebar in iTunes 129 | defaults write com.apple.iTunes disablePingSidebar -bool true 130 | 131 | # Disable all the other Ping stuff in iTunes 132 | defaults write com.apple.iTunes disablePing -bool true 133 | 134 | # Disable send and reply animations in Mail.app 135 | defaults write com.apple.Mail DisableReplyAnimations -bool true 136 | defaults write com.apple.Mail DisableSendAnimations -bool true 137 | 138 | # Disable Resume system-wide 139 | # defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false 140 | 141 | # Enable Dashboard dev mode (allows keeping widgets on the desktop) 142 | defaults write com.apple.dashboard devmode -bool true 143 | 144 | # Reset Launchpad 145 | # [ -e ~/Library/Application\ Support/Dock/*.db ] && rm ~/Library/Application\ Support/Dock/*.db 146 | 147 | # Show the ~/Library folder 148 | chflags nohidden ~/Library 149 | 150 | # Disable local Time Machine backups 151 | # hash tmutil &> /dev/null && sudo tmutil disablelocal 152 | 153 | # Remove Dropbox’s green checkmark icons in Finder.app 154 | #file=/Applications/Dropbox.app/Contents/Resources/check.icns 155 | #[ -e "$file" ] && mv -f "$file" "$file.bak" 156 | #unset file 157 | 158 | # Kill affected applications 159 | -------------------------------------------------------------------------------- /bin/pkg-mgr: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Usage: $0 3 | # Install global homebrew and node modules 4 | 5 | set -e 6 | 7 | # Homebrew 8 | brew bundle --file="$HOME/Brewfile" 9 | 10 | # Go 11 | cat $DOTFILES/go/packages | xargs go get 12 | 13 | # Node 14 | cat $DOTFILES/node/packages | xargs yarn global add 15 | 16 | # Ruby 17 | 18 | cat $DOTFILES/ruby/default-gems | xargs gem install 19 | -------------------------------------------------------------------------------- /bin/remote-clip: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | while (true); do nc -l 5556 | pbcopy; done 4 | 5 | 6 | -------------------------------------------------------------------------------- /bin/rfc: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | # 3 | # rfc 4 | # 5 | # Author: Baptiste Fontaine 6 | # License: MIT 7 | # Version: 0.1.0 8 | # 9 | # URI: github.com/bfontaine/rfc 10 | # 11 | 12 | __rfc() { 13 | 14 | local VERSION='0.1.0' 15 | local COMMIT='' 16 | local PAGER=${PAGER:-less} 17 | local fetch_cmd=${CURL:-curl} 18 | local rfc_dir="$HOME/.RFCs" 19 | local code= 20 | 21 | # Error codes 22 | local NOT_FOUND=1 23 | local UNRECOGNIZED_CMD=2 24 | local NETWORK_ERROR=3 25 | local NO_CURL_WGET=4 26 | 27 | # URLs 28 | local GITHUB_HEAD_URL="\ 29 | https://api.github.com/repos/bfontaine/rfc/git/refs/heads/master" 30 | local RFC_REMOTE_URL='https://raw.github.com/bfontaine/rfc/master/rfc' 31 | local REPO_HOME='https://github.com/bfontaine/rfc' 32 | local RFCS_BASEURL='http://www.rfc-editor.org/rfc/' 33 | local DRAFTS_BASEURL='http://www.ietf.org/id/' 34 | 35 | print_rfc() { 36 | $PAGER "$rfc_dir/$1" 37 | } 38 | 39 | fetch_url() { 40 | case $fetch_cmd in 41 | curl) 42 | curl -fs "$1" > "$2"; 43 | case "$?" in 44 | 6|7) return $NETWORK_ERROR ;; 45 | 22) return $NOT_FOUND ;; 46 | *) return 0 ;; 47 | esac ;; 48 | 49 | wget) 50 | wget -q "$1" -O "$2"; 51 | case "$?" in 52 | 4) return $NETWORK_ERROR ;; 53 | 8) return $NOT_FOUND ;; 54 | *) return 0 ;; 55 | esac ;; 56 | esac 57 | } 58 | 59 | get_rfc() { 60 | fetch_url "$RFCS_BASEURL/rfc${1}.txt" "$rfc_dir/${1}" 61 | return $? 62 | } 63 | 64 | get_draft() { 65 | fetch_url "$DRAFTS_BASEURL/${1}.txt" "$rfc_dir/${1}" 66 | return $? 67 | } 68 | 69 | init_rfc_dir() { 70 | 71 | mkdir -p $rfc_dir 72 | touch $rfc_dir/_404s 73 | 74 | } 75 | 76 | search() { 77 | if [ -z "$1" ]; then 78 | echo 'Usage: rfc search ""' 79 | return $UNRECOGNIZED_CMD; 80 | fi 81 | grep -Is --exclude _404s $@ $rfc_dir/* | sed "s%$rfc_dir/%RFC %" 82 | return 0 83 | } 84 | 85 | update() { 86 | 87 | local new_commit= 88 | local actual='' 89 | local tmp='._rfc_tmp' 90 | 91 | fetch_url $GITHUB_HEAD_URL $tmp 92 | 93 | new_commit=$(grep '"sha"' $tmp | sed 's/.*"\([0-9a-z]\{8\}\).*,/\1/') 94 | 95 | if [ "$COMMIT" = "$new_commit" ]; then 96 | echo 'This version is up to date!' 97 | return 0 98 | fi 99 | 100 | if [ "$COMMIT" != "" ]; then 101 | actual="from $COMMIT " 102 | fi 103 | 104 | fetch_url $RFC_REMOTE_URL $tmp 105 | 106 | \cp "$0" "/tmp/$0.bak" 2>/dev/null # Backup 107 | chmod +x "$0" 108 | rm -f $tmp 109 | 110 | echo "'rfc' updated ${actual}to $new_commit." 111 | return 0 112 | } 113 | 114 | print_not_found_error() { 115 | if [[ $1 == draft* ]]; then 116 | echo "There's no such draft." 117 | else 118 | echo "There's no such RFC." 119 | fi 120 | } 121 | 122 | print_usage() { 123 | echo 'Usage: 124 | rfc --version # display the version number and exit 125 | rfc --help # display this text and exit 126 | 127 | rfc # display the RFC 128 | rfc update # Update the script 129 | rfc search [OPTS] X # Search for X with grep with OPTS passed through 130 | rfc clear # clear the cache' 131 | } 132 | 133 | print_version() { 134 | local commit= 135 | if [ "$COMMIT" != "" ]; then 136 | commit="[$COMMIT] " 137 | fi 138 | 139 | echo "rfc v$VERSION $commit- $REPO_HOME" 140 | } 141 | 142 | ### 143 | 144 | if [ $# -eq 0 ]; then 145 | print_usage 146 | return 0 147 | fi 148 | 149 | which curl > /dev/null 2>&1 150 | if [ $? -ne 0 ]; then 151 | which wget > /dev/null 2>&1 152 | 153 | if [ $? -ne 0 ]; then 154 | echo "Error: You need Wget or cURL!" 155 | return $NO_CURL_WGET; 156 | fi 157 | 158 | fetch_cmd='wget' 159 | 160 | fi 161 | 162 | init_rfc_dir 163 | 164 | case "$1" in 165 | 166 | -v|--version|version) 167 | print_version 168 | return 0;; 169 | 170 | -h|--help|-help|help) 171 | print_usage 172 | return 0;; 173 | 174 | -*) 175 | echo "Unrecognized option: $1" 176 | print_usage 177 | return $UNRECOGNIZED_CMD;; 178 | 179 | clear) 180 | rm -rf $rfc_dir 181 | return 0;; 182 | 183 | up|update) 184 | update 185 | return 0;; 186 | 187 | search) 188 | shift; 189 | search $* 190 | return $?;; 191 | 192 | _404s) 193 | print_usage 194 | return 1;; 195 | 196 | *) 197 | grep -q "^$1\$" $rfc_dir/_404s 2> /dev/null 198 | if [ $? -eq 0 ]; then 199 | 200 | print_not_found_error "$1" 201 | return $NOT_FOUND 202 | 203 | elif [ ! -f "$rfc_dir/$1" ]; then 204 | 205 | if [[ $1 == draft* ]]; then 206 | get_draft $1 207 | else 208 | get_rfc $1 209 | fi 210 | 211 | code=$? 212 | 213 | if [ $code -eq $NETWORK_ERROR ]; then 214 | echo "Unable to connect to the network." 215 | [ ! -s "$rfc_dir/$1" ] && rm -f "$rfc_dir/$1" 216 | return $NETWORK_ERROR 217 | fi 218 | 219 | if [ $code -eq $NOT_FOUND ]; then 220 | echo "$1" >> "$rfc_dir/_404s" 221 | print_not_found_error "$1" 222 | 223 | [ ! -s "$rfc_dir/$1" ] && rm -f "$rfc_dir/$1" 224 | 225 | return $NOT_FOUND 226 | fi 227 | 228 | fi 229 | 230 | print_rfc $* ;; 231 | esac 232 | 233 | } 234 | 235 | __rfc $* 236 | 237 | -------------------------------------------------------------------------------- /bin/spark: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # spark 4 | # https://github.com/holman/spark 5 | # 6 | # Generates sparklines for a set of data. 7 | # 8 | # Here's a a good web-based sparkline generator that was a bit of inspiration 9 | # for spark: 10 | # 11 | # https://datacollective.org/sparkblocks 12 | # 13 | # spark takes a comma-separated list of data and then prints a sparkline out of 14 | # it. 15 | # 16 | # Examples: 17 | # 18 | # spark 1,5,22,13,53 19 | # # => ▁▁▃▂▇ 20 | # 21 | # spark 0,30,55,80,33,150 22 | # # => ▁▂▃▅▂▇ 23 | # 24 | # spark -h 25 | # # => Prints the spark help text. 26 | set -e 27 | 28 | # Prints the help text for spark. 29 | # 30 | # Returns nothing. 31 | help() 32 | { 33 | echo "spark\n" 34 | echo "USAGE:" 35 | echo " spark [comma,separated,value,list]\n" 36 | echo "EXAMPLES:" 37 | echo " spark 1,5,22,13,53" 38 | echo " ▁▁▃▂▇" 39 | echo " spark 0,30,55,80,33,150" 40 | echo " ▁▂▃▅▂▇" 41 | } 42 | 43 | # The actual fun characters we are generating in the sparkline. 44 | ticks=(▁ ▂ ▃ ▅ ▆ ▇) 45 | 46 | # The numbers the user gave us. 47 | numbers=() 48 | 49 | # The sorted array of the numbers. 50 | sorted=() 51 | 52 | # This sets up our secondary array so we can actually generate the correct 53 | # tick. 54 | # 55 | # Returns nothing. 56 | setup_array() { 57 | # 3,6,2 => 2,3,6 58 | sorted=$(echo $1 | tr ',' '\n' | sort -k1,1n | paste -s -d',' -) 59 | 60 | # convert comma-separated string to array 61 | IFS=, 62 | sorted=($sorted) 63 | numbers=($1) 64 | } 65 | 66 | # The maximum value of the sorted array. In other words, the last value. 67 | sort_max() 68 | { 69 | last=${#sorted[@]} 70 | echo ${sorted[$last - 1]} 71 | } 72 | 73 | # The minimum value of the sorted array. In other words, the first value. 74 | sort_min() 75 | { 76 | echo ${sorted[0]} 77 | } 78 | 79 | # Find the distance between tiers so we know which tick to assign a character. 80 | tier() 81 | { 82 | number_of_ticks=${#ticks[@]} 83 | distance=$(echo "$(sort_max) / $number_of_ticks" | bc) 84 | echo $distance 85 | } 86 | 87 | # Determines what tick we should print for this number and prints it. 88 | # 89 | # Returns nothing. 90 | print_tick() 91 | { 92 | tier=$(tier) 93 | 94 | for (( i = 0 ; i < ${#numbers[@]} ; i++ )) 95 | do 96 | tick=${ticks[$i]} 97 | number=$1 98 | less_than=$(echo "$i * $tier + sort_min + $tier" | bc) 99 | greater_than=$(echo "($i - 1) * $tier + sort_min + $tier" | bc) 100 | result=$(echo "$number <= $less_than && $number >= $greater_than" | bc) 101 | 102 | if [ $result -eq 1 ] 103 | then 104 | echo "$tick" 105 | return 106 | fi 107 | done 108 | 109 | last=${#ticks[@]} 110 | echo ${ticks[$last-1]} 111 | } 112 | 113 | # Iterate over all of our ticks and print them out. 114 | # 115 | # Returns nothing. 116 | print_ticks() 117 | { 118 | for number in ${numbers[@]} 119 | do 120 | echo $"$(print_tick $number)\c" 121 | done 122 | echo "" 123 | } 124 | 125 | while getopts ":h" option; do 126 | case "$option" in 127 | h) help && exit ;; 128 | # [?]) echo "$OPTARG";; 129 | esac 130 | done 131 | 132 | # Accept input from $1 or from the pipeline. 133 | if test "$1" != "" 134 | then 135 | data="$1" 136 | else 137 | data='' 138 | 139 | # check to see if stdin's a tty 140 | if [ -t 0 ]; then 141 | help 142 | exit 143 | fi 144 | 145 | while read data; do 146 | data=$data 147 | break 148 | done 149 | fi 150 | 151 | setup_array $data 152 | print_ticks $data 153 | -------------------------------------------------------------------------------- /bin/tcolors: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # tputcolors 3 | 4 | echo 5 | echo -e "$(tput bold) reg bld und tput-command-colors$(tput sgr0)" 6 | 7 | for i in $(seq 1 7); do 8 | echo " $(tput setaf $i)Text$(tput sgr0) $(tput bold)$(tput setaf $i)Text$(tput sgr0) $(tput sgr 0 1)$(tput setaf $i)Text$(tput sgr0) \$(tput setaf $i)" 9 | done 10 | 11 | echo ' Bold $(tput bold)' 12 | echo ' Underline $(tput sgr 0 1)' 13 | echo ' Reset $(tput sgr0)' 14 | echo 15 | -------------------------------------------------------------------------------- /bin/termcolors: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This file echoes a bunch of color codes to the 4 | # terminal to demonstrate what's available. Each 5 | # line is the color code of one forground color, 6 | # out of 17 (default + 16 escapes), followed by a 7 | # test use of that color on all nine background 8 | # colors (default + 8 escapes). 9 | # 10 | 11 | T='gYw' # The test text 12 | 13 | echo -e "\n 40m 41m 42m 43m\ 14 | 44m 45m 46m 47m"; 15 | 16 | for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \ 17 | '1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \ 18 | ' 36m' '1;36m' ' 37m' '1;37m'; 19 | do FG=${FGs// /} 20 | echo -en " $FGs \033[$FG $T " 21 | for BG in 40m 41m 42m 43m 44m 45m 46m 47m; 22 | do echo -en "$EINS \033[$FG\033[$BG $T \033[0m"; 23 | done 24 | echo; 25 | done 26 | echo 27 | 28 | -------------------------------------------------------------------------------- /bin/tmux-github-status: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CURRENT_STATUS="$(tmux show-options | grep status-left-fg | grep -Eio '(red|green|yellow)')" 3 | STATUS_URL="https://status.github.com/api" 4 | GITHUB_STATUS=$(curl $STATUS_URL/status.json | jq -r '.status') 5 | 6 | echo $GITHUB_STATUS 7 | 8 | case $GITHUB_STATUS in 9 | ma*) 10 | INDICATOR=" ⬤" 11 | NEW_STATUS="red" 12 | ;; 13 | mi*) 14 | INDICATOR=" ⬤" 15 | NEW_STATUS="yellow" 16 | ;; 17 | *) 18 | INDICATOR=" " 19 | NEW_STATUS="green" 20 | ;; 21 | esac 22 | 23 | tmux set-option status-left "$INDICATOR" 24 | tmux set-option status-left-fg $NEW_STATUS 25 | 26 | if [ "$NEW_STATUS" != "$CURRENT_STATUS" ]; then 27 | MESSAGE="$(curl $STATUS_URL/last-message.json | jq -r '.body')" 28 | tmux set-option message-bg $NEW_STATUS 29 | tmux display-message " $MESSAGE" 30 | # make sure message exits first 31 | sleep 7 32 | tmux set-option -u message-bg 33 | tmux set-option -u message-fg 34 | fi 35 | -------------------------------------------------------------------------------- /bin/tmux-ssh-split: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # If running in tmux and the user has ssh-ed into another machine, create split 3 | # pane also logged into that machine. Otherwise behave like regular split. 4 | 5 | # Extract ssh arguments like hostname used to initial connect to another 6 | # machine. 7 | 8 | WINDOW_INDEX=$(tmux display-message -p '#I') 9 | SESSION_VARIABLE_NAME="window_${WINDOW_INDEX}_ssh_args" 10 | 11 | SSH_ARGS=$(tmux showenv | grep -F "$SESSION_VARIABLE_NAME" | sed 's/^.*=//') 12 | if [ -n "$SSH_ARGS" ] 13 | then 14 | tmux splitw $1 "exec ssh $SSH_ARGS" 15 | else 16 | tmux splitw $1 17 | fi 18 | 19 | -------------------------------------------------------------------------------- /bin/treed: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # usage: treed PATH 3 | # View folder structure using `tree` with some options 4 | # 5 | # Lifted from https://github.com/mathiasbynens/dotfiles/pull/249/files 6 | 7 | tree -aC -I ".git" --dirsfirst "$@" | less -FRNX 8 | -------------------------------------------------------------------------------- /bin/tusers: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | grep -oE "@\w+$" | sort | uniq 4 | -------------------------------------------------------------------------------- /bin/unwrap: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Usage: unwrap [] 3 | # Removes hard line breaks from text such that each paragraph occupies a 4 | # single line. Indented code blocks and text quoted with '>' are not 5 | # reformatted. Bulleted and numbered lists are formatted but individual 6 | # items are retained. 7 | 8 | # open the file or use stdin 9 | file = 10 | if ARGV.empty? || ARGV[0] == '-' 11 | $stdin 12 | else 13 | File.open(ARGV[0], 'rb') 14 | end 15 | 16 | # slurp the entire contents 17 | text = file.read 18 | 19 | # remove hard breaks and unify spacing in text 20 | def unwrap(text) 21 | text[/^ +/].to_s + 22 | text.tr("\n", ' ').gsub(/ +/, ' ').strip 23 | end 24 | 25 | # split into paragraphs and remove hard 26 | paras = 27 | text.split(/\n{2,}/).map do |para| 28 | if para =~ /^(>| *\[| {4,})/ 29 | # quoted material, references, indented code blocks 30 | para 31 | elsif para =~ /^( *)[0-9*-]/ 32 | # indented bulleted and numbered lists 33 | indent = $1.to_s 34 | para. 35 | split(/\n#{indent}(?! )/). 36 | map { |item| unwrap(item) }. 37 | join("\n#{indent}") 38 | else 39 | # normal paragraphs 40 | unwrap(para) 41 | end 42 | end 43 | 44 | # join all the paragraphs and write to stdout 45 | puts paras.join("\n\n") 46 | -------------------------------------------------------------------------------- /setup/asdf.sh: -------------------------------------------------------------------------------- 1 | #/bin/env bash 2 | 3 | set -e 4 | cd "$(dirname "$0")" 5 | 6 | 7 | if [ -s ~/.asdf ]; then 8 | echo "asdf installed, skipping..." 9 | else 10 | git clone https://github.com/asdf-vm/asdf .asdf 11 | fi 12 | 13 | echo "Adding plugins" 14 | 15 | ~/.asdf/bin/asdf plugin-add golang https://github.com/kennyp/asdf-golang 16 | ~/.asdf/bin/asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git 17 | ~/.asdf/bin/asdf plugin-add ruby https://github.com/asdf-vm/asdf-ruby.git 18 | 19 | echo "DONE!" 20 | -------------------------------------------------------------------------------- /setup/vim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ 4 | https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim 5 | 6 | #vim -c "PlugInstall +qa" 7 | 8 | -------------------------------------------------------------------------------- /zsh/aliases.zsh: -------------------------------------------------------------------------------- 1 | alias dark="base16_oceanicnext" 2 | alias light="base16_solarized-light" 3 | 4 | alias cls='clear' 5 | alias reload!='. ~/.zshrc' 6 | alias count='wc -l' 7 | 8 | alias shout="tr '[[:lower:]]' '[[:upper:]]'" 9 | 10 | # IP addresses 11 | alias ip="dig +short myip.opendns.com @resolver1.opendns.com" 12 | alias localip="ipconfig getifaddr en0" 13 | alias ips="ifconfig -a | grep -o 'inet6\? \(\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\|[a-fA-F0-9:]\+\)' | sed -e 's/inet6* //'" 14 | 15 | # Enhanced WHOIS lookups 16 | alias whois="whois -h whois-servers.net" 17 | 18 | # Flush Directory Service cache 19 | alias flush="dscacheutil -flushcache" 20 | 21 | # View HTTP traffic 22 | alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'" 23 | alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\"" 24 | 25 | # Recursively delete `.DS_Store` files 26 | alias ds_nomore="find . -type f -name '*.DS_Store' -ls -delete" 27 | 28 | # ROT13-encode text. Works for decoding, too! ;) 29 | alias rot13='tr a-zA-Z n-za-mN-ZA-M' 30 | 31 | # Show/hide hidden files in Finder 32 | alias show="defaults write com.apple.Finder AppleShowAllFiles -bool true && killall Finder" 33 | alias hide="defaults write com.apple.Finder AppleShowAllFiles -bool false && killall Finder" 34 | 35 | # Hide/show all desktop icons (useful when presenting) 36 | alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder" 37 | alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder" 38 | 39 | # from @nvie https://coderwall.com/p/4tkkpq 40 | # 41 | # ls **/*.zsh | map dirname 42 | alias map="xargs -n1" 43 | 44 | # iA writer 45 | alias ia="open $1 -a /Applications/iA\ Writer.app" 46 | -------------------------------------------------------------------------------- /zsh/common.zsh: -------------------------------------------------------------------------------- 1 | export GHI_PAGER=less 2 | export EDITOR="vim" 3 | 4 | function colours() { 5 | for i in {0..255} ; do 6 | printf "\x1b[38;5;${i}mcolour${i}\n" 7 | done 8 | } 9 | 10 | 11 | function trash() { mv $1 ~/.Trash } 12 | 13 | # find shorthand 14 | function f() { 15 | find . -name "$1" 16 | } 17 | 18 | # cd into whatever is the forefront Finder window. 19 | cdf() { # short for cdfinder 20 | cd "`osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)'`" 21 | } 22 | 23 | # minimal client for AnyBar status bar app 24 | function anybar { echo -n $1 | nc -4u -w0 localhost ${2:-1738}; } 25 | 26 | # Refresh env vars under tmux 27 | if [ -n "$TMUX" ]; then 28 | function refresh { 29 | export $(tmux show-environment | grep "^SSH_AUTH_SOCK") 30 | } 31 | else 32 | function refresh { } 33 | fi 34 | 35 | # Codi 36 | # Usage: codi [filetype] [filename] 37 | codi() { 38 | local syntax="${1:-python}" 39 | shift 40 | vim -c \ 41 | "let g:startify_disable_at_vimenter = 1 |\ 42 | set bt=nofile ls=0 noru nonu nornu |\ 43 | hi ColorColumn ctermbg=NONE |\ 44 | hi VertSplit ctermbg=NONE |\ 45 | hi NonText ctermfg=0 |\ 46 | Codi $syntax" "$@" 47 | } 48 | -------------------------------------------------------------------------------- /zsh/completion.sh: -------------------------------------------------------------------------------- 1 | # matches case insensitive for lowercase 2 | zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' 3 | 4 | # pasting with tabs doesn't perform completion 5 | zstyle ':completion:*' insert-tab pending 6 | 7 | compdef dc=docker-compose 8 | 9 | compdef g=git 10 | compdef h=git 11 | 12 | zstyle ':completion:*:*:g*:*' user-commands \ 13 | amend:"Use the last commit message and amend your stuffs" \ 14 | churn:"Show most actively changed parts of a repo" \ 15 | ci:"View CI status for a ref" \ 16 | conflicts:"Show list of files in a conflict state" \ 17 | contributors:"Show list of contributors sorted by line count" \ 18 | credit:"Quick way to credit an author on the latest commit" \ 19 | edit-conflicts:"Open files with conflicts in $EDITOR" \ 20 | exclude:"Exclude files in repo without modifying .gitignore" \ 21 | go:"CLI helper for GitHub.com, inspired by the CommandBar" \ 22 | grab:"Clone GitHub repo to $CODE/repo@owner" \ 23 | nwo:"Display GitHub owner and repository name" \ 24 | outgoing:"Show commits on current branch that do not exist on branch upstream" \ 25 | pr:"Start or open a pull request for the current branch" \ 26 | prune-merged-branches:"Delete all branches that are fully merged into specified branch" \ 27 | rank-contributors:"Rank contributors by total size of diffs" \ 28 | rel:"Show relative ahead/behind info between branch and a ref" \ 29 | sweep:"Remove fully merged branches" \ 30 | thanks:"Display commit count by author for a given Git ref" \ 31 | undo:"Undo your last commit, but don't throw away your changes" \ 32 | wtf:"Display the state of your repository in a readable, easy-to-scan format." \ 33 | 34 | -------------------------------------------------------------------------------- /zsh/config.zsh: -------------------------------------------------------------------------------- 1 | export LSCOLORS="exfxcxdxbxegedabagacad" 2 | export CLICOLOR=true 3 | 4 | fpath=($ZSH/completions/src $ZSH/functions $fpath) 5 | 6 | autoload -U $ZSH/functions/*(:t) 7 | 8 | HISTFILE=~/.zsh_history 9 | HISTSIZE=10000 10 | SAVEHIST=10000 11 | 12 | setopt NO_BG_NICE # don't nice background tasks 13 | setopt NO_HUP 14 | setopt NO_LIST_BEEP 15 | setopt LOCAL_OPTIONS # allow functions to have local options 16 | setopt LOCAL_TRAPS # allow functions to have local traps 17 | setopt HIST_VERIFY 18 | setopt SHARE_HISTORY # share history between sessions ??? 19 | setopt EXTENDED_HISTORY # add timestamps to history 20 | setopt PROMPT_SUBST 21 | setopt CORRECT 22 | setopt COMPLETE_IN_WORD 23 | setopt IGNORE_EOF 24 | 25 | setopt APPEND_HISTORY # adds history 26 | setopt INC_APPEND_HISTORY SHARE_HISTORY # adds history incrementally and share it across sessions 27 | setopt HIST_IGNORE_ALL_DUPS # don't record dupes in history 28 | setopt HIST_REDUCE_BLANKS 29 | 30 | # don't expand aliases _before_ completion has finished 31 | # like: git comm-[tab] 32 | setopt complete_aliases 33 | 34 | zle -N newtab 35 | 36 | bindkey '^[^[[D' backward-word 37 | bindkey '^[^[[C' forward-word 38 | bindkey '^[[5D' beginning-of-line 39 | bindkey '^[[5C' end-of-line 40 | bindkey '^[[3~' delete-char 41 | bindkey '^[^N' newtab 42 | bindkey '^?' backward-delete-char 43 | -------------------------------------------------------------------------------- /zsh/functions/_apex: -------------------------------------------------------------------------------- 1 | #compdef _apex apex 2 | 3 | _apex() { 4 | compadd $(apex autocomplete) 5 | } 6 | -------------------------------------------------------------------------------- /zsh/functions/_brew: -------------------------------------------------------------------------------- 1 | #compdef brew 2 | 3 | # Brew ZSH completion function 4 | # Drop this somewhere in your $fpath (like /usr/share/zsh/site-functions) 5 | # and rename it _brew 6 | # 7 | # altered from _fink 8 | 9 | _brew_all_formulae() { 10 | formulae=(`brew search`) 11 | } 12 | 13 | _brew_installed_formulae() { 14 | installed_formulae=(`brew list`) 15 | } 16 | 17 | _brew_installed_taps() { 18 | installed_taps=(`brew tap`) 19 | } 20 | 21 | _brew_outdated_formulae() { 22 | outdated_formulae=(`brew outdated`) 23 | } 24 | 25 | local -a _1st_arguments 26 | _1st_arguments=( 27 | 'audit:check formulae for Homebrew coding style' 28 | 'bundle:look for a Brewfile and run each line as a brew command' 29 | 'cat:display formula file for a formula' 30 | 'cleanup:uninstall unused and old versions of packages' 31 | 'commands:show a list of commands' 32 | 'create:create a new formula' 33 | 'deps:list dependencies and dependants of a formula' 34 | 'doctor:audits your installation for common issues' 35 | 'edit:edit a formula' 36 | 'home:visit the homepage of a formula or the brew project' 37 | 'info:information about a formula' 38 | 'install:install a formula' 39 | 'reinstall:install a formula anew; re-using its current options' 40 | 'link:link a formula' 41 | 'list:list files in a formula or not-installed formulae' 42 | 'log:git commit log for a formula' 43 | 'missing:check all installed formuale for missing dependencies.' 44 | 'outdated:list formulae for which a newer version is available' 45 | 'pin:pin specified formulae' 46 | 'prune:remove dead links' 47 | 'remove:remove a formula' 48 | 'search:search for a formula (/regex/ or string)' 49 | 'server:start a local web app that lets you browse formulae (requires Sinatra)' 50 | 'tap:tap a new formula repository from GitHub, or list existing taps' 51 | 'unlink:unlink a formula' 52 | 'unpin:unpin specified formulae' 53 | 'untap:remove a tapped repository' 54 | 'update:freshen up links' 55 | 'upgrade:upgrade outdated formulae' 56 | 'uses:show formulae which depend on a formula' 57 | ) 58 | 59 | local expl 60 | local -a formulae installed_formulae installed_taps outdated_formulae 61 | 62 | _arguments \ 63 | '(-v)-v[verbose]' \ 64 | '(--cellar)--cellar[brew cellar]' \ 65 | '(--config)--config[brew configuration]' \ 66 | '(--env)--env[brew environment]' \ 67 | '(--repository)--repository[brew repository]' \ 68 | '(--version)--version[version information]' \ 69 | '(--prefix)--prefix[where brew lives on this system]' \ 70 | '(--cache)--cache[brew cache]' \ 71 | '*:: :->subcmds' && return 0 72 | 73 | if (( CURRENT == 1 )); then 74 | _describe -t commands "brew subcommand" _1st_arguments 75 | return 76 | fi 77 | 78 | case "$words[1]" in 79 | search|-S) 80 | _arguments \ 81 | '(--macports)--macports[search the macports repository]' \ 82 | '(--fink)--fink[search the fink repository]' ;; 83 | list|ls) 84 | _arguments \ 85 | '(--unbrewed)--unbrewed[files in brew --prefix not controlled by brew]' \ 86 | '(--pinned)--pinned[list all versions of pinned formulae]' \ 87 | '(--versions)--versions[list all installed versions of a formula]' \ 88 | '1: :->forms' && return 0 89 | 90 | if [[ "$state" == forms ]]; then 91 | _brew_installed_formulae 92 | _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae 93 | fi ;; 94 | install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|edit|options) 95 | _brew_all_formulae 96 | _wanted formulae expl 'all formulae' compadd -a formulae ;; 97 | remove|rm|uninstall|unlink|cleanup|link|ln|pin|unpin) 98 | _brew_installed_formulae 99 | _wanted installed_formulae expl 'installed formulae' compadd -a installed_formulae ;; 100 | upgrade) 101 | _brew_outdated_formulae 102 | _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae ;; 103 | untap) 104 | _brew_installed_taps 105 | _wanted installed_taps expl 'installed taps' compadd -a installed_taps ;; 106 | esac 107 | -------------------------------------------------------------------------------- /zsh/functions/_c: -------------------------------------------------------------------------------- 1 | #compdef c 2 | _files -W $PROJECTS -/ -------------------------------------------------------------------------------- /zsh/functions/_docker-compose: -------------------------------------------------------------------------------- 1 | #compdef docker-compose 2 | 3 | # Description 4 | # ----------- 5 | # zsh completion for docker-compose 6 | # ------------------------------------------------------------------------- 7 | # Authors 8 | # ------- 9 | # * Steve Durrheimer 10 | # ------------------------------------------------------------------------- 11 | # Inspiration 12 | # ----------- 13 | # * @albers docker-compose bash completion script 14 | # * @felixr docker zsh completion script : https://github.com/felixr/docker-zsh-completion 15 | # ------------------------------------------------------------------------- 16 | 17 | __docker-compose_q() { 18 | docker-compose 2>/dev/null $compose_options "$@" 19 | } 20 | 21 | # All services defined in docker-compose.yml 22 | __docker-compose_all_services_in_compose_file() { 23 | local already_selected 24 | local -a services 25 | already_selected=$(echo $words | tr " " "|") 26 | __docker-compose_q config --services \ 27 | | grep -Ev "^(${already_selected})$" 28 | } 29 | 30 | # All services, even those without an existing container 31 | __docker-compose_services_all() { 32 | [[ $PREFIX = -* ]] && return 1 33 | integer ret=1 34 | services=$(__docker-compose_all_services_in_compose_file) 35 | _alternative "args:services:($services)" && ret=0 36 | 37 | return ret 38 | } 39 | 40 | # All services that have an entry with the given key in their docker-compose.yml section 41 | __docker-compose_services_with_key() { 42 | local already_selected 43 | local -a buildable 44 | already_selected=$(echo $words | tr " " "|") 45 | # flatten sections to one line, then filter lines containing the key and return section name. 46 | __docker-compose_q config \ 47 | | sed -n -e '/^services:/,/^[^ ]/p' \ 48 | | sed -n 's/^ //p' \ 49 | | awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \ 50 | | grep " \+$1:" \ 51 | | cut -d: -f1 \ 52 | | grep -Ev "^(${already_selected})$" 53 | } 54 | 55 | # All services that are defined by a Dockerfile reference 56 | __docker-compose_services_from_build() { 57 | [[ $PREFIX = -* ]] && return 1 58 | integer ret=1 59 | buildable=$(__docker-compose_services_with_key build) 60 | _alternative "args:buildable services:($buildable)" && ret=0 61 | 62 | return ret 63 | } 64 | 65 | # All services that are defined by an image 66 | __docker-compose_services_from_image() { 67 | [[ $PREFIX = -* ]] && return 1 68 | integer ret=1 69 | pullable=$(__docker-compose_services_with_key image) 70 | _alternative "args:pullable services:($pullable)" && ret=0 71 | 72 | return ret 73 | } 74 | 75 | __docker-compose_get_services() { 76 | [[ $PREFIX = -* ]] && return 1 77 | integer ret=1 78 | local kind 79 | declare -a running paused stopped lines args services 80 | 81 | docker_status=$(docker ps > /dev/null 2>&1) 82 | if [ $? -ne 0 ]; then 83 | _message "Error! Docker is not running." 84 | return 1 85 | fi 86 | 87 | kind=$1 88 | shift 89 | [[ $kind =~ (stopped|all) ]] && args=($args -a) 90 | 91 | lines=(${(f)"$(_call_program commands docker $docker_options ps $args)"}) 92 | services=(${(f)"$(_call_program commands docker-compose 2>/dev/null $compose_options ps -q)"}) 93 | 94 | # Parse header line to find columns 95 | local i=1 j=1 k header=${lines[1]} 96 | declare -A begin end 97 | while (( j < ${#header} - 1 )); do 98 | i=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 1 )) 99 | j=$(( i + ${${header[$i,-1]}[(i) ]} - 1 )) 100 | k=$(( j + ${${header[$j,-1]}[(i)[^ ]]} - 2 )) 101 | begin[${header[$i,$((j-1))]}]=$i 102 | end[${header[$i,$((j-1))]}]=$k 103 | done 104 | lines=(${lines[2,-1]}) 105 | 106 | # Container ID 107 | local line s name 108 | local -a names 109 | for line in $lines; do 110 | if [[ ${services[@]} == *"${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}"* ]]; then 111 | names=(${(ps:,:)${${line[${begin[NAMES]},-1]}%% *}}) 112 | for name in $names; do 113 | s="${${name%_*}#*_}:${(l:15:: :::)${${line[${begin[CREATED]},${end[CREATED]}]/ ago/}%% ##}}" 114 | s="$s, ${line[${begin[CONTAINER ID]},${end[CONTAINER ID]}]%% ##}" 115 | s="$s, ${${${line[${begin[IMAGE]},${end[IMAGE]}]}/:/\\:}%% ##}" 116 | if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = Exit* ]]; then 117 | stopped=($stopped $s) 118 | else 119 | if [[ ${line[${begin[STATUS]},${end[STATUS]}]} = *\(Paused\)* ]]; then 120 | paused=($paused $s) 121 | fi 122 | running=($running $s) 123 | fi 124 | done 125 | fi 126 | done 127 | 128 | [[ $kind =~ (running|all) ]] && _describe -t services-running "running services" running "$@" && ret=0 129 | [[ $kind =~ (paused|all) ]] && _describe -t services-paused "paused services" paused "$@" && ret=0 130 | [[ $kind =~ (stopped|all) ]] && _describe -t services-stopped "stopped services" stopped "$@" && ret=0 131 | 132 | return ret 133 | } 134 | 135 | __docker-compose_pausedservices() { 136 | [[ $PREFIX = -* ]] && return 1 137 | __docker-compose_get_services paused "$@" 138 | } 139 | 140 | __docker-compose_stoppedservices() { 141 | [[ $PREFIX = -* ]] && return 1 142 | __docker-compose_get_services stopped "$@" 143 | } 144 | 145 | __docker-compose_runningservices() { 146 | [[ $PREFIX = -* ]] && return 1 147 | __docker-compose_get_services running "$@" 148 | } 149 | 150 | __docker-compose_services() { 151 | [[ $PREFIX = -* ]] && return 1 152 | __docker-compose_get_services all "$@" 153 | } 154 | 155 | __docker-compose_caching_policy() { 156 | oldp=( "$1"(Nmh+1) ) # 1 hour 157 | (( $#oldp )) 158 | } 159 | 160 | __docker-compose_commands() { 161 | local cache_policy 162 | 163 | zstyle -s ":completion:${curcontext}:" cache-policy cache_policy 164 | if [[ -z "$cache_policy" ]]; then 165 | zstyle ":completion:${curcontext}:" cache-policy __docker-compose_caching_policy 166 | fi 167 | 168 | if ( [[ ${+_docker_compose_subcommands} -eq 0 ]] || _cache_invalid docker_compose_subcommands) \ 169 | && ! _retrieve_cache docker_compose_subcommands; 170 | then 171 | local -a lines 172 | lines=(${(f)"$(_call_program commands docker-compose 2>&1)"}) 173 | _docker_compose_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/ ##/:}) 174 | (( $#_docker_compose_subcommands > 0 )) && _store_cache docker_compose_subcommands _docker_compose_subcommands 175 | fi 176 | _describe -t docker-compose-commands "docker-compose command" _docker_compose_subcommands 177 | } 178 | 179 | __docker-compose_subcommand() { 180 | local opts_help opts_force_recreate opts_no_recreate opts_no_build opts_remove_orphans opts_timeout opts_no_color opts_no_deps 181 | 182 | opts_help='(: -)--help[Print usage]' 183 | opts_force_recreate="(--no-recreate)--force-recreate[Recreate containers even if their configuration and image haven't changed. Incompatible with --no-recreate.]" 184 | opts_no_recreate="(--force-recreate)--no-recreate[If containers already exist, don't recreate them. Incompatible with --force-recreate.]" 185 | opts_no_build="(--build)--no-build[Don't build an image, even if it's missing.]" 186 | opts_remove_orphans="--remove-orphans[Remove containers for services not defined in the Compose file]" 187 | opts_timeout=('(-t --timeout)'{-t,--timeout}"[Specify a shutdown timeout in seconds. (default: 10)]:seconds: ") 188 | opts_no_color='--no-color[Produce monochrome output.]' 189 | opts_no_deps="--no-deps[Don't start linked services.]" 190 | 191 | integer ret=1 192 | 193 | case "$words[1]" in 194 | (build) 195 | _arguments \ 196 | $opts_help \ 197 | "*--build-arg=[Set build-time variables for one service.]:=: " \ 198 | '--force-rm[Always remove intermediate containers.]' \ 199 | '--no-cache[Do not use cache when building the image.]' \ 200 | '--pull[Always attempt to pull a newer version of the image.]' \ 201 | '*:services:__docker-compose_services_from_build' && ret=0 202 | ;; 203 | (bundle) 204 | _arguments \ 205 | $opts_help \ 206 | '--push-images[Automatically push images for any services which have a `build` option specified.]' \ 207 | '(--output -o)'{--output,-o}'[Path to write the bundle file to. Defaults to ".dab".]:file:_files' && ret=0 208 | ;; 209 | (config) 210 | _arguments \ 211 | $opts_help \ 212 | '(--quiet -q)'{--quiet,-q}"[Only validate the configuration, don't print anything.]" \ 213 | '--resolve-image-digests[Pin image tags to digests.]' \ 214 | '--services[Print the service names, one per line.]' \ 215 | '--volumes[Print the volume names, one per line.]' && ret=0 216 | ;; 217 | (create) 218 | _arguments \ 219 | $opts_help \ 220 | $opts_force_recreate \ 221 | $opts_no_recreate \ 222 | $opts_no_build \ 223 | "(--no-build)--build[Build images before creating containers.]" \ 224 | '*:services:__docker-compose_services_all' && ret=0 225 | ;; 226 | (down) 227 | _arguments \ 228 | $opts_help \ 229 | "--rmi[Remove images. Type must be one of: 'all': Remove all images used by any service. 'local': Remove only images that don't have a custom tag set by the \`image\` field.]:type:(all local)" \ 230 | '(-v --volumes)'{-v,--volumes}"[Remove named volumes declared in the \`volumes\` section of the Compose file and anonymous volumes attached to containers.]" \ 231 | $opts_remove_orphans && ret=0 232 | ;; 233 | (events) 234 | _arguments \ 235 | $opts_help \ 236 | '--json[Output events as a stream of json objects]' \ 237 | '*:services:__docker-compose_services_all' && ret=0 238 | ;; 239 | (exec) 240 | _arguments \ 241 | $opts_help \ 242 | '-d[Detached mode: Run command in the background.]' \ 243 | '--privileged[Give extended privileges to the process.]' \ 244 | '(-u --user)'{-u,--user=}'[Run the command as this user.]:username:_users' \ 245 | '-T[Disable pseudo-tty allocation. By default `docker-compose exec` allocates a TTY.]' \ 246 | '--index=[Index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ 247 | '(-):running services:__docker-compose_runningservices' \ 248 | '(-):command: _command_names -e' \ 249 | '*::arguments: _normal' && ret=0 250 | ;; 251 | (help) 252 | _arguments ':subcommand:__docker-compose_commands' && ret=0 253 | ;; 254 | (images) 255 | _arguments \ 256 | $opts_help \ 257 | '-q[Only display IDs]' \ 258 | '*:services:__docker-compose_services_all' && ret=0 259 | ;; 260 | (kill) 261 | _arguments \ 262 | $opts_help \ 263 | '-s[SIGNAL to send to the container. Default signal is SIGKILL.]:signal:_signals' \ 264 | '*:running services:__docker-compose_runningservices' && ret=0 265 | ;; 266 | (logs) 267 | _arguments \ 268 | $opts_help \ 269 | '(-f --follow)'{-f,--follow}'[Follow log output]' \ 270 | $opts_no_color \ 271 | '--tail=[Number of lines to show from the end of the logs for each container.]:number of lines: ' \ 272 | '(-t --timestamps)'{-t,--timestamps}'[Show timestamps]' \ 273 | '*:services:__docker-compose_services_all' && ret=0 274 | ;; 275 | (pause) 276 | _arguments \ 277 | $opts_help \ 278 | '*:running services:__docker-compose_runningservices' && ret=0 279 | ;; 280 | (port) 281 | _arguments \ 282 | $opts_help \ 283 | '--protocol=[tcp or udp \[default: tcp\]]:protocol:(tcp udp)' \ 284 | '--index=[index of the container if there are multiple instances of a service \[default: 1\]]:index: ' \ 285 | '1:running services:__docker-compose_runningservices' \ 286 | '2:port:_ports' && ret=0 287 | ;; 288 | (ps) 289 | _arguments \ 290 | $opts_help \ 291 | '-q[Only display IDs]' \ 292 | '*:services:__docker-compose_services_all' && ret=0 293 | ;; 294 | (pull) 295 | _arguments \ 296 | $opts_help \ 297 | '--ignore-pull-failures[Pull what it can and ignores images with pull failures.]' \ 298 | '*:services:__docker-compose_services_from_image' && ret=0 299 | ;; 300 | (push) 301 | _arguments \ 302 | $opts_help \ 303 | '--ignore-push-failures[Push what it can and ignores images with push failures.]' \ 304 | '*:services:__docker-compose_services' && ret=0 305 | ;; 306 | (rm) 307 | _arguments \ 308 | $opts_help \ 309 | '(-f --force)'{-f,--force}"[Don't ask to confirm removal]" \ 310 | '-v[Remove any anonymous volumes attached to containers]' \ 311 | '*:stopped services:__docker-compose_stoppedservices' && ret=0 312 | ;; 313 | (run) 314 | _arguments \ 315 | $opts_help \ 316 | $opts_no_deps \ 317 | '-d[Detached mode: Run container in the background, print new container name.]' \ 318 | '*-e[KEY=VAL Set an environment variable (can be used multiple times)]:environment variable KEY=VAL: ' \ 319 | '--entrypoint[Overwrite the entrypoint of the image.]:entry point: ' \ 320 | '--name=[Assign a name to the container]:name: ' \ 321 | '(-p --publish)'{-p,--publish=}"[Publish a container's port(s) to the host]" \ 322 | '--rm[Remove container after run. Ignored in detached mode.]' \ 323 | "--service-ports[Run command with the service's ports enabled and mapped to the host.]" \ 324 | '-T[Disable pseudo-tty allocation. By default `docker-compose run` allocates a TTY.]' \ 325 | '(-u --user)'{-u,--user=}'[Run as specified username or uid]:username or uid:_users' \ 326 | '(-v --volume)*'{-v,--volume=}'[Bind mount a volume]:volume: ' \ 327 | '(-w --workdir)'{-w,--workdir=}'[Working directory inside the container]:workdir: ' \ 328 | '(-):services:__docker-compose_services' \ 329 | '(-):command: _command_names -e' \ 330 | '*::arguments: _normal' && ret=0 331 | ;; 332 | (scale) 333 | _arguments \ 334 | $opts_help \ 335 | $opts_timeout \ 336 | '*:running services:__docker-compose_runningservices' && ret=0 337 | ;; 338 | (start) 339 | _arguments \ 340 | $opts_help \ 341 | '*:stopped services:__docker-compose_stoppedservices' && ret=0 342 | ;; 343 | (stop|restart) 344 | _arguments \ 345 | $opts_help \ 346 | $opts_timeout \ 347 | '*:running services:__docker-compose_runningservices' && ret=0 348 | ;; 349 | (top) 350 | _arguments \ 351 | $opts_help \ 352 | '*:running services:__docker-compose_runningservices' && ret=0 353 | ;; 354 | (unpause) 355 | _arguments \ 356 | $opts_help \ 357 | '*:paused services:__docker-compose_pausedservices' && ret=0 358 | ;; 359 | (up) 360 | _arguments \ 361 | $opts_help \ 362 | '(--abort-on-container-exit)-d[Detached mode: Run containers in the background, print new container names. Incompatible with --abort-on-container-exit.]' \ 363 | $opts_no_color \ 364 | $opts_no_deps \ 365 | $opts_force_recreate \ 366 | $opts_no_recreate \ 367 | $opts_no_build \ 368 | "(--no-build)--build[Build images before starting containers.]" \ 369 | "(-d)--abort-on-container-exit[Stops all containers if any container was stopped. Incompatible with -d.]" \ 370 | '(-t --timeout)'{-t,--timeout}"[Use this timeout in seconds for container shutdown when attached or when containers are already running. (default: 10)]:seconds: " \ 371 | $opts_remove_orphans \ 372 | '*:services:__docker-compose_services_all' && ret=0 373 | ;; 374 | (version) 375 | _arguments \ 376 | $opts_help \ 377 | "--short[Shows only Compose's version number.]" && ret=0 378 | ;; 379 | (*) 380 | _message 'Unknown sub command' && ret=1 381 | ;; 382 | esac 383 | 384 | return ret 385 | } 386 | 387 | _docker-compose() { 388 | # Support for subservices, which allows for `compdef _docker docker-shell=_docker_containers`. 389 | # Based on /usr/share/zsh/functions/Completion/Unix/_git without support for `ret`. 390 | if [[ $service != docker-compose ]]; then 391 | _call_function - _$service 392 | return 393 | fi 394 | 395 | local curcontext="$curcontext" state line 396 | integer ret=1 397 | typeset -A opt_args 398 | 399 | local file_description 400 | 401 | if [[ -n ${words[(r)-f]} || -n ${words[(r)--file]} ]] ; then 402 | file_description="Specify an override docker-compose file (default: docker-compose.override.yml)" 403 | else 404 | file_description="Specify an alternate docker-compose file (default: docker-compose.yml)" 405 | fi 406 | 407 | _arguments -C \ 408 | '(- :)'{-h,--help}'[Get help]' \ 409 | '*'{-f,--file}"[${file_description}]:file:_files -g '*.yml'" \ 410 | '(-p --project-name)'{-p,--project-name}'[Specify an alternate project name (default: directory name)]:project name:' \ 411 | '--verbose[Show more output]' \ 412 | '(- :)'{-v,--version}'[Print version and exit]' \ 413 | '(-H --host)'{-H,--host}'[Daemon socket to connect to]:host:' \ 414 | '--tls[Use TLS; implied by --tlsverify]' \ 415 | '--tlscacert=[Trust certs signed only by this CA]:ca path:' \ 416 | '--tlscert=[Path to TLS certificate file]:client cert path:' \ 417 | '--tlskey=[Path to TLS key file]:tls key path:' \ 418 | '--tlsverify[Use TLS and verify the remote]' \ 419 | "--skip-hostname-check[Don't check the daemon's hostname against the name specified in the client certificate (for example if your docker host is an IP address)]" \ 420 | '(-): :->command' \ 421 | '(-)*:: :->option-or-argument' && ret=0 422 | 423 | local -a relevant_compose_flags relevant_docker_flags compose_options docker_options 424 | 425 | relevant_compose_flags=( 426 | "--file" "-f" 427 | "--host" "-H" 428 | "--project-name" "-p" 429 | "--tls" 430 | "--tlscacert" 431 | "--tlscert" 432 | "--tlskey" 433 | "--tlsverify" 434 | "--skip-hostname-check" 435 | ) 436 | 437 | relevant_docker_flags=( 438 | "--host" "-H" 439 | "--tls" 440 | "--tlscacert" 441 | "--tlscert" 442 | "--tlskey" 443 | "--tlsverify" 444 | ) 445 | 446 | for k in "${(@k)opt_args}"; do 447 | if [[ -n "${relevant_docker_flags[(r)$k]}" ]]; then 448 | docker_options+=$k 449 | if [[ -n "$opt_args[$k]" ]]; then 450 | docker_options+=$opt_args[$k] 451 | fi 452 | fi 453 | if [[ -n "${relevant_compose_flags[(r)$k]}" ]]; then 454 | compose_options+=$k 455 | if [[ -n "$opt_args[$k]" ]]; then 456 | compose_options+=$opt_args[$k] 457 | fi 458 | fi 459 | done 460 | 461 | case $state in 462 | (command) 463 | __docker-compose_commands && ret=0 464 | ;; 465 | (option-or-argument) 466 | curcontext=${curcontext%:*:*}:docker-compose-$words[1]: 467 | __docker-compose_subcommand && ret=0 468 | ;; 469 | esac 470 | 471 | return ret 472 | } 473 | 474 | _docker-compose "$@" 475 | -------------------------------------------------------------------------------- /zsh/functions/_gcd: -------------------------------------------------------------------------------- 1 | #compdef gcd 2 | local -a ignored 3 | ignored=('tmp' '**/tmp') 4 | _path_files -/ -W $GOSRC -F ignored 5 | 6 | -------------------------------------------------------------------------------- /zsh/functions/_git-rm: -------------------------------------------------------------------------------- 1 | #compdef git-rm 2 | _arguments -S -A '-*' \ 3 | '-f[override the up-to-date check]' \ 4 | "-n[don't actually remove the files, just show if they exist in the index]" \ 5 | '-r[allow recursive removal when a leading directory-name is given]' \ 6 | '--cached[only remove files from the index]' && ret=0 7 | _files 8 | -------------------------------------------------------------------------------- /zsh/functions/_rake: -------------------------------------------------------------------------------- 1 | #compdef _rake rake 2 | # Lifted from https://github.com/joshuaclayton/dotfiles/blob/master/zsh_profile.d/completion.zsh 3 | 4 | _rake_does_task_list_need_generating() { 5 | if [[ ! -f .rake_tasks ]]; then return 0; 6 | else 7 | accurate=$(stat -f%m .rake_tasks) 8 | changed=$(stat -f%m Rakefile) 9 | return $(expr $accurate '>=' $changed) 10 | fi 11 | } 12 | 13 | _rake() { 14 | if [[ -f Rakefile ]]; then 15 | if _rake_does_task_list_need_generating; then 16 | rake --silent --tasks | cut -d " " -f 2 | cut -d "[" -f 1 > .rake_tasks 17 | fi 18 | compadd $(cat .rake_tasks) 19 | fi 20 | } 21 | 22 | -------------------------------------------------------------------------------- /zsh/functions/_yarn: -------------------------------------------------------------------------------- 1 | #compdef yarn 2 | # ------------------------------------------------------------------------------ 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are met: 5 | # * Redistributions of source code must retain the above copyright 6 | # notice, this list of conditions and the following disclaimer. 7 | # * Redistributions in binary form must reproduce the above copyright 8 | # notice, this list of conditions and the following disclaimer in the 9 | # documentation and/or other materials provided with the distribution. 10 | # * Neither the name of the zsh-users nor the 11 | # names of its contributors may be used to endorse or promote products 12 | # derived from this software without specific prior written permission. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY 18 | # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | # ------------------------------------------------------------------------------ 25 | # Description 26 | # ----------- 27 | # 28 | # Completion script for yarn (https://yarnpkg.com/) 29 | # 30 | # ------------------------------------------------------------------------------ 31 | # Authors 32 | # ------- 33 | # 34 | # * Massimiliano Torromeo 35 | # 36 | # ------------------------------------------------------------------------------ 37 | 38 | _commands=( 39 | 'access' 40 | 'cache' 41 | "check:Verify package dependencies agains yarn's lock file" 42 | 'clean:Cleans and removes unnecessary files from package dependencies' 43 | 'config:Manages the yarn configuration files' 44 | 'generate-lock-entry:Generates a lock file entry' 45 | 'global:Install packages globally on your operating system' 46 | 'help:Show information about a command' 47 | 'import' 48 | 'info:Show information about a package' 49 | 'init:Interactively creates or updates a package.json file' 50 | 'install:Install all the dependencies listed within package.json' 51 | 'licenses:List licenses for installed packages' 52 | 'link:Symlink a package folder during development' 53 | 'list:List installed packages' 54 | 'login:Store registry username and email' 55 | 'logout:Clear registry username and email' 56 | 'outdated:Checks for outdated package dependencies' 57 | 'owner:Manage package owners' 58 | 'pack:Creates a compressed gzip archive of package dependencies' 59 | 'publish:Publishes a package to the npm registry' 60 | 'run:Runs a defined package script' 61 | 'tag:Add, remove, or list tags on a package' 62 | 'team:Maintain team memberships' 63 | 'unlink:Unlink a previously created symlink for a package' 64 | 'version:Updates the package version' 65 | 'versions' 66 | 'why:Show information about why a package is installed' 67 | ) 68 | 69 | _global_commands=( 70 | 'add:Installs a package and any packages that it depends on' 71 | 'bin:Displays the location of the yarn bin folder' 72 | 'remove:Remove installed package from dependencies updating package.json' 73 | 'upgrade:Upgrades packages to their latest version based on the specified range' 74 | 'upgrade-interactive' 75 | ) 76 | 77 | _yarn_commands_scripts() { 78 | local -a scripts 79 | scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n')) 80 | _describe 'command or script' _commands -- _global_commands -- scripts 81 | } 82 | 83 | _yarn_scripts() { 84 | local -a scripts 85 | scripts=($(yarn run --json 2>/dev/null | sed -E '/Commands available|possibleCommands/!d;s/.*Commands available from binary scripts: ([^"]+)".*/\1/;s/.*"items":\[([^]]+).*/\1/;s/[" ]//g' | tr , '\n')) 86 | _describe 'script' scripts 87 | } 88 | 89 | _yarn_global_commands() { 90 | local -a cmds 91 | cmds=('ls:List installed packages') 92 | _describe 'command' _global_commands 93 | } 94 | 95 | _yarn_commands() { 96 | _describe 'command' _commands -- _global_commands 97 | } 98 | 99 | _yarn() { 100 | local context state state_descr line 101 | typeset -A opt_args 102 | 103 | _arguments \ 104 | '(-h --help)'{-h,--help}'[output usage information]' \ 105 | '(-V --version)'{-V,--version}'[output the version number]' \ 106 | '--verbose[output verbose messages on internal operations]' \ 107 | '--offline[trigger an error if any required dependencies are not available in local cache]' \ 108 | '--prefer-offline[use network only if dependencies are not available in local cache]' \ 109 | '--strict-semver' \ 110 | '--json' \ 111 | "--ignore-scripts[don't run lifecycle scripts]" \ 112 | '--har[save HAR output of network traffic]' \ 113 | '--ignore-platform[ignore platform checks]' \ 114 | '--ignore-engines[ignore engines check]' \ 115 | '--ignore-optional[ignore optional dependencies]' \ 116 | '--force[install and build packages even if they were built before, overwrite lockfile]' \ 117 | '--skip-integrity-check[run install without checking if node_modules is installed]' \ 118 | '--check-files[install will verify file tree of packages for consistency]' \ 119 | "--no-bin-links[don't generate bin links when setting up packages]" \ 120 | '--flat[only allow one version of a package]' \ 121 | '(--prod --production)'{--prod,--production} \ 122 | "--no-lockfile[don't read or generate a lockfile]" \ 123 | "--pure-lockfile[don't generate a lockfile]" \ 124 | "--frozen-lockfile[don't generate a lockfile and fail if an update is needed]" \ 125 | '--link-duplicates[create hardlinks to the repeated modules in node_modules]' \ 126 | '--global-folder=[modules folder]:folder:_files -/' \ 127 | '--modules-folder=[rather than installing modules into the node_modules folder relative to the cwd, output them here]:folder:_files -/' \ 128 | '--cache-folder=[specify a custom folder to store the yarn cache]:folder:_files -/' \ 129 | '--mutex=[use a mutex to ensure only one yarn instance is executing]:type[\:specifier]' \ 130 | '--no-emoji[disable emoji in output]' \ 131 | '(-s --silent)'{-s,--silent}'[skip Yarn console logs, other types of logs (script output) will be printed]' \ 132 | '--proxy=:host:_hosts' \ 133 | '--https-proxy=:host:_hosts' \ 134 | '--no-progress[disable progress bar]' \ 135 | '--network-concurrency=[maximum number of concurrent network requests]:number' \ 136 | '--network-timeout=[TCP timeout for network requests]:milliseconds' \ 137 | '--non-interactive[do not show interactive prompts]' \ 138 | '1: :_yarn_commands_scripts' \ 139 | '*:: :->command_args' 140 | 141 | 142 | case $state in 143 | command_args) 144 | case $words[1] in 145 | help) 146 | _arguments \ 147 | '1: :_yarn_commands' \ 148 | ;; 149 | 150 | access) 151 | _arguments \ 152 | '1: :(public restricted grant revoke ls-packages ls-collaborators edit)' 153 | ;; 154 | 155 | add) 156 | _arguments \ 157 | '(-D --dev)'{-D,--dev}'[install packages in devDependencies]' \ 158 | '(-P --peer)'{-P,--peer}'[install packages in peerDependencies]' \ 159 | '(-O --optional)'{-O,--optional}'[install packages in optionalDependencies]' \ 160 | '(-E --exact)'{-E,--exact}'[install packages as exact versions]' \ 161 | '(-T --tilde)'{-T,--tilde}'[install the most recent release of the packages that have the same minor version]' \ 162 | '*:package-name:' 163 | ;; 164 | 165 | cache) 166 | _arguments \ 167 | '1: :(ls dir clean)' 168 | ;; 169 | 170 | check) 171 | _arguments \ 172 | '--integrity' \ 173 | '--verify-tree' 174 | ;; 175 | 176 | config) 177 | _arguments \ 178 | '1: :(set get delete list)' \ 179 | '*:: :->config_args' 180 | ;; 181 | 182 | global) 183 | _arguments \ 184 | '--prefix=[bin prefix to use to install binaries]' \ 185 | '1: :_yarn_global_commands' \ 186 | '*:: :->command_args' 187 | ;; 188 | 189 | info) 190 | _arguments \ 191 | '1:package:' \ 192 | '2:field' 193 | ;; 194 | 195 | init) 196 | _arguments \ 197 | '(-y --yes)'{-y,--yes}'[install packages in devDependencies]' 198 | ;; 199 | 200 | licenses) 201 | _arguments \ 202 | '1: :(ls generate-disclaimer)' \ 203 | ;; 204 | 205 | link|unlink|outdated) 206 | _arguments \ 207 | '1:package' \ 208 | ;; 209 | 210 | list) 211 | _arguments \ 212 | '--depth[Limit the depth of the shown dependencies]:depth' 213 | ;; 214 | 215 | owner) 216 | _arguments \ 217 | '1: :(ls add rm)' \ 218 | '*:: :->owner_args' 219 | ;; 220 | 221 | pack) 222 | _arguments \ 223 | '(-f --filename)'{-f,--filename}':filename:_files' 224 | ;; 225 | 226 | publish) 227 | _arguments \ 228 | '--new-version:version:' \ 229 | '--message:message:' \ 230 | '--no-git-tag-version' \ 231 | '--access:access:' \ 232 | '--tag:tag:' \ 233 | '1: :_files' 234 | ;; 235 | 236 | remove|upgrade) 237 | _arguments \ 238 | '*:package:' 239 | ;; 240 | 241 | run) 242 | _arguments \ 243 | '1: :_yarn_scripts' 244 | ;; 245 | 246 | tag) 247 | _arguments \ 248 | '1: :(ls add rm)' \ 249 | '*:: :->tag_args' 250 | ;; 251 | 252 | team) 253 | _arguments \ 254 | '1: :(create destroy add rm ls)' \ 255 | '*:: :->team_args' 256 | ;; 257 | 258 | version) 259 | _arguments \ 260 | '--new-version:version:' \ 261 | '--message:message:' \ 262 | '--no-git-tag-version' 263 | ;; 264 | 265 | why) 266 | _arguments \ 267 | '1:query:_files' 268 | ;; 269 | esac 270 | ;; 271 | esac 272 | 273 | case $state in 274 | config_args) 275 | case $words[1] in 276 | get|delete) 277 | _arguments \ 278 | '1:key:' 279 | ;; 280 | 281 | set) 282 | _arguments \ 283 | '(-g --global)'{-g,--global} \ 284 | '1:key:' \ 285 | '2:value:' 286 | ;; 287 | esac 288 | ;; 289 | 290 | owner_args) 291 | case $words[1] in 292 | ls) 293 | _arguments \ 294 | '1:package:' 295 | ;; 296 | 297 | add|rm) 298 | _arguments \ 299 | '1:user:' \ 300 | '2:package:' 301 | ;; 302 | esac 303 | ;; 304 | 305 | tag_args) 306 | case $words[1] in 307 | ls) 308 | _arguments \ 309 | '1:package' 310 | ;; 311 | 312 | add|rm) 313 | _arguments \ 314 | '1:package:' \ 315 | '2:tag:' 316 | ;; 317 | esac 318 | ;; 319 | 320 | team_args) 321 | case $words[1] in 322 | create|destroy|ls) 323 | _arguments \ 324 | '1:scope\:team:' 325 | ;; 326 | 327 | add|rm) 328 | _arguments \ 329 | '1:scope\:team:' \ 330 | '2:user:' 331 | ;; 332 | esac 333 | ;; 334 | esac 335 | } 336 | 337 | _yarn "$@" 338 | 339 | # Local Variables: 340 | # mode: Shell-Script 341 | # sh-indentation: 2 342 | # indent-tabs-mode: nil 343 | # sh-basic-offset: 2 344 | # End: 345 | # vim: ft=zsh sw=2 ts=2 et 346 | -------------------------------------------------------------------------------- /zsh/functions/c: -------------------------------------------------------------------------------- 1 | cd $PROJECTS/$1; -------------------------------------------------------------------------------- /zsh/functions/last_modified: -------------------------------------------------------------------------------- 1 | ls -t $* 2> /dev/null | head -n 1 2 | -------------------------------------------------------------------------------- /zsh/functions/verbose_completion: -------------------------------------------------------------------------------- 1 | zstyle ':completion:*' verbose yes 2 | zstyle ':completion:*:descriptions' format '%B%d%b' 3 | zstyle ':completion:*:messages' format '%d' 4 | zstyle ':completion:*:warnings' format 'No matches for: %d' 5 | zstyle ':completion:*' group-name '' 6 | -------------------------------------------------------------------------------- /zsh/functions/zsh_stats: -------------------------------------------------------------------------------- 1 | fc -l 1 | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20 2 | -------------------------------------------------------------------------------- /zsh/git.zsh: -------------------------------------------------------------------------------- 1 | export GHI_PAGER=less 2 | export GIT_SANDBOX=~/code/sandbox 3 | export GIT_MERGE_AUTOEDIT=no 4 | 5 | # Wrap git with hub 6 | alias git=hub 7 | 8 | function g { 9 | if [[ $# > 0 ]]; then 10 | git "$@" 11 | else 12 | echo "Last commit: $(time_since_last_commit) ago" 13 | git status --short --branch 14 | fi 15 | } 16 | 17 | # Special git alias for my dots (h for home), inspired by: 18 | # https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/ 19 | alias config='git --git-dir=$HOME/.cfg/ --work-tree=$HOME' 20 | function h { 21 | if [[ $# > 0 ]]; then 22 | config "$@" 23 | else 24 | echo "Last commit: $(time_since_last_commit) ago" 25 | config status --short --branch 26 | fi 27 | } 28 | 29 | 30 | function time_since_last_commit() { 31 | ref=$(git symbolic-ref HEAD 2> /dev/null) || return 32 | git log -1 --pretty=format:"%ar" | sed 's/\([0-9]*\) \(.\).*/\1\2/' 33 | } 34 | 35 | function sandbox() { 36 | cd $GIT_SANDBOX && git clone $1 && cd `last_modified` 37 | } 38 | -------------------------------------------------------------------------------- /zsh/go.zsh: -------------------------------------------------------------------------------- 1 | export GOPATH=$HOME/go 2 | export GOSRC=$GOPATH/src/github.com 3 | export PATH=$PATH:$GOPATH/bin 4 | 5 | 6 | function gcd { 7 | cd "$GOSRC/$1" 8 | } 9 | -------------------------------------------------------------------------------- /zsh/homebrew.zsh: -------------------------------------------------------------------------------- 1 | export HOMEBREW_CASK_OPTS="--appdir=/Applications" 2 | -------------------------------------------------------------------------------- /zsh/ruby.zsh: -------------------------------------------------------------------------------- 1 | # bundler 2 | alias b="bundle" 3 | alias be="bundle exec" 4 | 5 | # rspec 6 | alias specs="rspec --format=documentation" 7 | -------------------------------------------------------------------------------- /zsh/tmux.zsh: -------------------------------------------------------------------------------- 1 | # Wrap ssh commmand to allow smart pane behavior in tmux. 2 | # 3 | # Lifted from https://github.com/moonboots/tmux-ssh/blob/master/tmux-sshrc 4 | # 5 | # After opening a tmux window and ssh-ing into another server, new panes will 6 | # open already ssh-ed to the server. 7 | function ssh() { 8 | # set only if within running tmux 9 | if [ "$TERM" = "screen" ] && [ -n "$TMUX" ]; then 10 | window_index=$(tmux display-message -p '#I') 11 | 12 | # arbitrary environment variable name to remember ssh args like server 13 | # hostname so we can connect again. 14 | session_variable_name="window_${window_index}_ssh_args" 15 | 16 | # save in tmux session variable 17 | tmux setenv $session_variable_name "$*" 18 | 19 | # set window title 20 | tmux rename-window $* 21 | 22 | # run ssh 23 | /usr/bin/ssh $* 24 | 25 | # unset variable so new panes don't continue ssh-ing to this server 26 | tmux setenv -u $session_variable_name 27 | else 28 | /usr/bin/ssh $* 29 | fi 30 | 31 | # rename title back 32 | tmux rename-window zsh 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /zsh/window.zsh: -------------------------------------------------------------------------------- 1 | # From http://dotfiles.org/~_why/.zshrc 2 | # Sets the window title nicely no matter where you are 3 | function title() { 4 | # escape '%' chars in $1, make nonprintables visible 5 | a=${(V)1//\%/\%\%} 6 | 7 | # Truncate command, and join lines. 8 | a=$(print -Pn "%40>...>$a" | tr -d "\n") 9 | 10 | case $TERM in 11 | screen) 12 | print -Pn "\ek$a:$3\e\\" # screen title (in ^A") 13 | ;; 14 | xterm*|rxvt) 15 | print -Pn "\e]2;$2\a" # plain xterm title ($3 for pwd) 16 | ;; 17 | esac 18 | } 19 | 20 | --------------------------------------------------------------------------------