Skip to content

Instantly share code, notes, and snippets.

@fanatid
Last active July 6, 2019 08:16
Show Gist options
  • Save fanatid/d773e6ab32eedd0c245e to your computer and use it in GitHub Desktop.
Save fanatid/d773e6ab32eedd0c245e to your computer and use it in GitHub Desktop.
dotfiles
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export HISTSIZE=10000
export HISTFILESIZE=10000
export PAGER=less
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
# export BLUEBIRD_DEBUG=1
# export Q_DEBUG=1
# nvm & node.js
export NPM_CONFIG_PREFIX=$HOME/.local
export NODE_PATH=$HOME/.local/lib/node_modules:$NODE_PATH
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
which node 1>/dev/null 2>&1 && source <(node --completion-bash)
# Go
export GOPATH=$HOME/.local/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
mkdir -p $GOPATH/{bin,pkg,src}
# Rust
[ -s "$HOME/.cargo/env" ] && . $HOME/.cargo/env
which rustup 1>/dev/null 2>&1 && source <(rustup completions bash)
# Kubernetes
export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config
which kubectl 1>/dev/null 2>&1 && source <(kubectl completion bash)
which kubeadm 1>/dev/null 2>&1 && source <(kubeadm completion bash)
# Terraform
which terraform 1>/dev/null 2>&1 && complete -C $HOME/.local/bin/terraform terraform
# Fetch 24-hour AWS STS session token and set appropriate environment variables.
# See http://docs.aws.amazon.com/cli/latest/reference/sts/get-session-token.html .
# You must have jq installed and in your PATH https://stedolan.github.io/jq/ .
# Add this function to your .bashrc or save it to a file and source that file from .bashrc .
# Usage: aws-creds MFA_TOKEN [OTHER_AWS_STS_GET-SESSION-TOKEN_OPTIONS]
function aws-creds () {
if [[ ! $1 ]]; then
echo "aws-creds: missing required argument: MFA_TOKEN_CODE" 1>&2
return 99
fi
export -n AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
# replace USER and 12_DIGIT_ACCOUNT_NUMBER with appropriate values
local iam_user=fanatid
local aws_account=316676488525
local rv creds_json
creds_json=$(set -o pipefail; aws --output json sts get-session-token --duration-seconds 86400 --serial-number "arn:aws:iam::$aws_account:mfa/$iam_user" --token-code "$@")
rv="$?"
if [[ $rv -ne 0 || ! $creds_json ]]; then
echo "aws-creds: failed to get credentials: $creds_json" 1>&2
return "$rv"
fi
local jq="jq --exit-status --raw-output"
AWS_ACCESS_KEY_ID=$(echo "$creds_json" | $jq .Credentials.AccessKeyId)
rv="$?"
if [[ $rv -ne 0 || ! $AWS_ACCESS_KEY_ID ]]; then
echo "aws-creds: failed to parse output for AWS_ACCESS_KEY_ID: $creds_json" 1>&2
return "$rv"
fi
AWS_SECRET_ACCESS_KEY=$(echo "$creds_json" | $jq .Credentials.SecretAccessKey)
rv="$?"
if [[ $rv -ne 0 || ! $AWS_SECRET_ACCESS_KEY ]]; then
echo "aws-creds: failed to parse output for AWS_SECRET_ACCESS_KEY: $creds_json" 1>&2
return "$rv"
fi
AWS_SESSION_TOKEN=$(echo "$creds_json" | $jq .Credentials.SessionToken)
rv="$?"
if [[ $rv -ne 0 || ! $AWS_SESSION_TOKEN ]]; then
echo "aws-creds: failed to parse output for AWS_SESSION_TOKEN: $creds_json" 1>&2
return "$rv"
fi
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
local tokens="AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID\nAWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY\nAWS_SESSION_TOKEN=$AWS_SESSION_TOKEN"
echo -e $tokens >~/.aws/aws-creds
echo -e "AWS credentials received:\n$tokens"
}
function aws-creds-load () {
AWS_ACCESS_KEY_ID=$(awk -F "AWS_ACCESS_KEY_ID=" 'NF > 1 {print $2}' ~/.aws/aws-creds)
AWS_SECRET_ACCESS_KEY=$(awk -F "AWS_SECRET_ACCESS_KEY=" 'NF > 1 {print $2}' ~/.aws/aws-creds)
AWS_SESSION_TOKEN=$(awk -F "AWS_SESSION_TOKEN=" 'NF > 1 {print $2}' ~/.aws/aws-creds)
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
}
aws-creds-load
[alias]
a = add
bl = branch -avv
br = branch
chb = checkout -b
ch = checkout
coa = commit --amend
com = commit -m
d = diff
h = log --oneline --graph --decorate
rv = remote -v
st = status -sb
[color]
branch = always
diff = always
interactive = always
status = always
[core]
editor = vim
[user]
name = Kirill Fomichev
email = fanatid@ya.ru
" auto-reload vimrc
augroup vimrc_reload
au!
autocmd bufwritepost .vimrc source ~/.vimrc
augroup END
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Sections:
" -> Plugins (Vundle)
" -> General
" -> VIM user interface
" -> Colors and Fonts
" -> Files and backups
" -> Text, tab and indent related
" -> Moving around, tabs and buffers
" -> Status line
" -> Plugins (Settings)
" -> Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins (Vundle)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let need_to_install_plugins=0
if empty(system("test -e ~/.vim/bundle/vundle/autoload/vundle.vim && echo 1"))
echo "Installing Vundle..."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !rm -rf ~/.vim/bundle/vundle
silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
let need_to_install_plugins=1
endif
set runtimepath+=~/.vim/bundle/vundle/
call vundle#begin()
Plugin 'gmarik/vundle'
" Colorschemes
Plugin 'molokai'
" General Editing
Plugin 'scrooloose/syntastic'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'ntpeters/vim-better-whitespace'
" Plugin 'vim-scripts/YankRing.vim'
" Plugin 'terryma/vim-multiple-cursors'
Plugin 'vim-scripts/mru.vim'
Plugin 'editorconfig/editorconfig-vim'
" Navigation
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'majutsushi/tagbar'
Plugin 'jeetsukumaran/vim-buffergator'
" Languages
Plugin 'Valloric/YouCompleteMe'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
Plugin 'pangloss/vim-javascript'
Plugin 'marijnh/tern_for_vim'
Plugin 'fatih/vim-go'
" Development Tools
Plugin 'tpope/vim-fugitive'
" Desire
" smart indent
" auto twin bracket
call vundle#end()
if need_to_install_plugins == 1
echo "Installing plugins via Vundle. Please ignore warnings afterwards."
echo "This is a one-time operation that will take about a minute..."
silent! PluginInstall
echo "Done installing Vundle plugins!"
echo "Install jsonlint"
silent !npm install jsonlint -g
echo "Done installing jsonlint"
echo "Install YouCompleteMe"
silent !~/.vim/bundle/YouCompleteMe/install.sh
echo "Done installing YouCompleteMe"
echo "Install JSCTags"
silent !npm install -g git://github.com/ramitos/jsctags.git
silent !cd ~/.vim/bundle/tern_for_vim && npm install
echo "Done installing JSCTags"
q
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set filetypes
au BufRead,BufNewFile *.json set filetype=json
au BufRead,BufNewFile *.md set filetype=markdown
au BufRead,BufNewFile *.go set filetype=go tabstop=8
" Sets how many lines of history VIM has to remember
set history=500
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" With a map leader it's possible to do extra key combinations
" like <leader>w saves the current file
let mapleader=","
" Fast saving
nmap <leader>w :w!<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => VIM user interface
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc,.git\*,.hg\*,.svn\*
"Always show current position
set ruler
" Height of the command bar
set cmdheight=2
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" Show matching brackets when text indicator is over them
set showmatch
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Colors and Fonts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable syntax highlighting
syntax enable
" Set current colorscheme
colorscheme molokai
" Set utf8 as standard encoding and en_US as the standard language
set encoding=utf8
" Use Unix as the standard file type
set ffs=unix,dos,mac
" Set ruler color
highlight ColorColumn ctermbg=Gray
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Files, backups and undo
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Text, tab and indent related
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show number for each line
set number
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
" Linebreak on 500 characters
set linebreak
set textwidth=80
set colorcolumn=+1
set ai "Auto indent
set si "Smart indent
set wrap "Wrap lines
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Moving around, tabs, windows and buffers
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Close all the buffers
map <leader>ba :1,1000 bd!<cr>
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Smart way to move tabs
" Use C-A-PgUp / C-A-PgDown for moving between tabs
map <S-h> :tabmove -1<cr>
map <S-l> :tabmove +1<cr>
" Useful mappings for managing tabs
nnoremap <C-t> :tabnew<CR>
inoremap <C-t> <Esc>:tabnew<CR>i
" Opens a new tab with the current buffer's path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Specify the behavior when switching between buffers
try
set switchbuf=useopen,usetab,newtab
set stal=2
catch
endtry
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
""""""""""""""""""""""""""""""
" => Status line
""""""""""""""""""""""""""""""
" Always show the status line
set laststatus=2
" Format the status line
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins (Settings)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Syntastic
let g:syntastic_check_on_open=1
set statusline+=%{SyntasticStatuslineFlag()}
let g:syntastic_json_checkers=['jsonlint']
"let g:syntastic_javascript_checkers=['jshint', 'jscs']
let g:syntastic_javascript_checkers=['standard']
"let g:syntastic_javascript_checkers=['eslint']
" vim-airline
let g:airline_theme="luna"
let g:airline#extensions#tabline#enabled=1
" MRU
let MRU_Max_Entries=100
map <leader>f :MRU<CR>
" NERDTree
"autocmd StdinReadPre * let s:std_in=1
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
map <leader>n :NERDTreeTabsToggle<cr>
" Tagbar
map <leader>t :TagbarToggle<cr>
" vim-buffergator
let g:buffergator_suppress_keymaps=1
map <leader>b :BuffergatorOpen<CR>
map <leader>B :BuffergatorClose<CR>
map <leader>to :BuffergatorTabsOpen<CR>
map <leader>tc :BuffergatorTabsClose<CR>
" YouCompleteMe
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_autoclose_preview_window_after_insertion=1
let g:ycm_max_diagnostics_to_display=15
" vim-go
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Returns true if paste mode is enabled
function! HasPaste()
if &paste
return 'PASTE MODE '
en
return ''
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment