Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Last active October 9, 2015 02:57
Show Gist options
  • Save sycobuny/3427408 to your computer and use it in GitHub Desktop.
Save sycobuny/3427408 to your computer and use it in GitHub Desktop.
My current rc files (and friends)
# do regular system bashrc stuff, if there's one set up
if [ -f /etc/bashrc ] ; then
. /etc/bashrc
fi
# use 256 colors if available, otherwise default to
if [ -f /usr/share/terminfo/x/xterm-256color ] ; then
export TERM=xterm-256color
else
export TERM=xterm
fi
[user]
name = Stephen Belcher
email = sbelcher@......
[core]
excludesfile = ~/.gitignore_global
autocrlf = input
editor = /usr/bin/vim
[color]
ui = auto
[alias]
lg = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)-- %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
root = rev-parse --show-toplevel
#!/bin/bash
#
# Modified TMUX start script from:
# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# Store it to `~/bin/tmx` and issue `chmod +x`.
#
# Works because bash automatically trims by assigning to variables and by
# passing arguments
trim() { echo $1; }
if [[ -z "$1" ]]; then
echo "Specify session name as the first argument"
exit
fi
# Only because I often issue `ls` to this script by accident
if [[ "$1" == "ls" ]]; then
tmux ls
exit
fi
base_session="$1"
# This actually works without the trim() on all systems except OSX
tmux_nb=$(trim `tmux ls | grep "^$base_session" | wc -l`)
if [[ "$tmux_nb" == "0" ]]; then
echo "Launching tmux base session $base_session ..."
tmux new-session -s $base_session
else
# Make sure we are not already in a tmux session
if [[ -z "$TMUX" ]]; then
# Kill defunct sessions first
old_sessions=$(tmux ls 2>/dev/null | egrep "^[0-9]{14}.*[0-9]+\)$" | \
cut -f 1 -d:)
for old_session_id in $old_sessions; do
tmux kill-session -t $old_session_id
done
attached=$(tmux ls | grep "^$base_session: " | grep -v attached)
if [[ "$?" == "0" ]]; then
echo "Attaching to unattached base session $base_session ..."
tmux attach -t $base_session
else
session_num=$(tmux ls | grep "^$base_session-" | cut -d- -f2 | \
cut -d: -f1 | sort -rn | head -n1)
if [[ -z "$session_num" ]]; then
session_num=0
fi
session_num=$(($session_num + 1))
echo "Launching copy of base session $base_session ..."
# Session is is date and time to prevent conflict
session_id=$base_session-$session_num
# Create a new session (without attaching it) and link to base
# session to share windows
tmux new-session -d -t $base_session -s $session_id
# Create a new window in that session
#tmux new-window
# Attach to the new session
tmux attach-session -t $session_id
# When we detach from it, kill the session
tmux kill-session -t $session_id
fi
fi
fi
# statusbar
set-option -g status-bg black
set-option -g status-fg red
set-option -g status-justify right
set-option -g status-left-length 80
set-option -g status-right ""
set-option -g status-left "#[fg=cyan][#[fg=red]#S#[fg=cyan]] >>> #[fg=red]#(whoami)#[fg=cyan]@#[fg=red]#h #[fg=cyan](#[fg=red]#(pwd)#[fg=cyan]) (#[fg=red]#I #W#[fg=cyan])"
# utf-8 and coloring
set-window-option -g utf on
set -g default-terminal "screen-256color"
# copy mode - vi-style
set-window-option -g mode-keys vi
# aggressive resize - only make max-win-size-to-smallest-client apply in the
# current window, rather than across the entire session
set-window-option -g aggressive-resize on
" allow for project-local vim configurations
let s:gitroot = system('git root')
if s:gitroot !=# ''
let s:gitvimconfig = s:gitroot[0:-2] . "/.git/vimrc"
if filereadable(s:gitvimconfig)
exec "source " . s:gitvimconfig
endif
endif
" filesystem management
set nowb " do not create filename~ backups
set noswapfile " do not use .filename.swp/swo swap files
" code style preferences
set number " include line numbers, cause why not.
set smartindent " have VIM auto-indent when possible
set tabstop=4 " tabs are 4 characters wide by default for most code
set shiftwidth=4 " indent level is also 4 characters wide by default
set expandtab " expand tabs to spaces when I push the tab key
set nopaste " do not assume paste mode by default
set backspace=indent,eol,start " allow backspacing over indents/etc.
" remap ]], [[, [], and ][ to find block encoding without C-style
" Yoinked from vim help, see :help object-motions
map [[ ?{<CR>w99[{
map ][ /}<CR>b00]}
map ]] j0[[%/{<CR>
map [] k$][%?}<CR>
" syntax highlighting
" first off, turn it on
set t_Co=256 " 256-color terminal
syntax enable " enable highlighting
" add overflow column warning coloring
if exists('+colorcolumn')
set colorcolumn=79
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>79v.\+', -1)
endif
" set text width manually, cause colorcolumn auto-sets it
set textwidth=78
" add specific filenames not detected (yet) by any of my plugins
au BufNewFile,BufRead Vagrantfile,Gemfile set ft=ruby
" fix special case textwidth for git commit messages (fugitive auto-sets
" this, but me setting the colorcolumn and textwidth manually breaks that)
au FileType gitcommit set textwidth=72
" grab the contents of the visual selection
" thanks to http://stackoverflow.com/a/6271254
function! VS()
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - 2]
let lines[0] = lines[0][col1 - 1:]
return join(lines, "\n")
endfunction
" send commands using posgres using shift-r
" idea from Depesz, http://postgr.es/p/1DH
" slightly modified to dump into register r instead of the buffer
vmap R :\|let @r = system('psql -t', VS())<enter>
" break lines around a visual selection
vnoremap <Leader>i <Esc>a<CR><Esc>gvo<Esc>i<CR><Esc>
" learn vim the hard way - disable arrow movement
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" turn on spell-checking in markdown, plaintext files, and git commits; turn
" it off specifically for help files (which is a subset of plaintext files)
au FileType markdown set spell
au FileType gitcommit set spell
au BufRead *.txt set spell
au FileType help set nospell
" add a DiffWithSaved() command to see what changes we haven't saved yet
function! s:DiffWithSaved()
let filetype=&ft
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . filetype
endfunction
com! DiffSaved call s:DiffWithSaved()
" PLUGIN - vundle
" NOTES
" This requires pre-cloning of the git repository, eg:
" $ git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
" required settings for vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle
call vundle#rc()
" have vundle manage vundle
Bundle "gmarik/vundle"
" PLUGIN - powerline
" NOTES
" For this to look decent on Mac OS X, you need to download a Powerline
" patched font and enable it, or build your own. I use "Menlo" patched
" from https://gist.github.com/1595572.
" install powerline
Bundle "Lokaltog/vim-powerline"
set laststatus=2 " turn on statusbar
let g:Powerline_symbols = 'fancy' " use fancy utf-8 symbols
" PLUGIN - vim-surround
Bundle "tpope/vim-surround"
" PLUGIN - vim-git
Bundle "tpope/vim-git"
" PLUGIN - vim-fugitive
Bundle "tpope/vim-fugitive"
" PLUGIN - vim-markdown
Bundle "tpope/vim-markdown"
let g:markdown_fenced_languages = [
\ 'apacheconf=apache', 'aconf=apache', 'html', 'css',
\ 'javascript', 'perl', 'ruby', 'php', 'diff'
\ ]
" PLUGIN - NERDTree
Bundle "scrooloose/nerdtree"
" PLUGIN - undo-tree
Bundle "mbbill/undotree"
" PLUGIN - puppet-syntax-vim
Bundle "puppetlabs/puppet-syntax-vim"
" PLUGIN - vim-indent-guides
Bundle "nathanaelkane/vim-indent-guides"
" prevent errors from cropping up
hi Normal ctermbg=black
let g:indent_guides_start_level = 2 " no clue
let g:indent_guides_guide_size = 1 " no fat guides
let g:indent_guides_auto_colors = 0 " skip auto-color decisions
" make some pretty colors
au VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=235
au VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=236
" turn it on by default
au VimEnter * :IndentGuidesEnable
" PLUGIN - SyntaxRange
Bundle "SyntaxRange"
au FileType sql call SyntaxRange#Include(
\ ' AS \$PERL\$', ' \$PERL\$;', 'perl'
\ )
" PLUGIN - vim-slime
Bundle "jpalardy/vim-slime"
let g:slime_target = "tmux"
" PLUGIN - spacehi
Bundle "jpalardy/spacehi.vim"
" PLUGIN - csv
Bundle "csv.vim"
" PLUGIN - delimitMate
Bundle "Raimondi/delimitMate"
" PLUGIN - snipMate
Bundle "msanders/snipmate.vim"
au FileType snippet set noexpandtab
" SYNTAX - perl-mauke
Bundle "vim-scripts/perl-mauke.vim"
let perl_include_pod = 1
let perl_fold = 1
" COLORSCHEME - BadWolf
Bundle "sjl/badwolf"
colorscheme badwolf
" post-vundle-install required setting
filetype plugin indent on
# PERLBREW
# install perlbrew first:
# $ curl -kL http://install.perlbrew.pl | bash
# $ perlbrew init
export PERL5LIB=$HOME/.perl5/lib
export PERLBREW_ROOT=$HOME/.perl5/perlbrew
source $PERLBREW_ROOT/etc/bashrc
# RVM
# install RVM first:
# $ curl -L https://get.rvm.io | bash -s stable --ruby
export RVM_ROOT=$HOME/.rvm
if [[ -s $"$RVM_ROOT/scripts/rvm" ]] ; then
source $RVM_ROOT/etc/bashrc
fi
export PATH=$PATH:$RVM_ROOT/bin
# OH-MY-ZSH
# clone oh-my-zsh first:
# $ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
ZSH=$HOME/.oh-my-zsh
ZSH_THEME="cloud"
plugins=()
source $ZSH/oh-my-zsh.sh
# MACPORTS
export PATH=/opt/local/bin:$PATH
# MYSQL5.1 FROM MACPORTS
export PATH=/opt/local/lib/mysql51/bin:$PATH
# POSTGRES9.2 FROM MACPORTS
export PATH=/opt/local/lib/postgresql92/bin:$PATH
# ALIASES
alias gcpm="curl -L http://cpanmin.us | Perl - App::cpanminus"
alias ls="ls -liaFGh"
alias tmx="$HOME/.tmux-attach.bash"
alias vi=vim
alias ':e'=vim
# SITE ALIASES
if [ -e $HOME/.site_aliases ]; then
source $HOME/.site_aliases
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment