Skip to content

Instantly share code, notes, and snippets.

@hassansin
Last active August 18, 2019 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassansin/2a2bd32c9c2e514c17da4b2ec8b3851c to your computer and use it in GitHub Desktop.
Save hassansin/2a2bd32c9c2e514c17da4b2ec8b3851c to your computer and use it in GitHub Desktop.
dotfiles
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# added by travis gem
[ -f /home/hassansin/.travis/travis.sh ] && source /home/hassansin/.travis/travis.sh
command -v vg >/dev/null 2>&1 && eval "$(vg eval --shell bash)"
## Postgres, psql, pgadmin
alias postgres="docker run --rm --name postgres \
-v /var/lib/postgresql/data:/var/lib/postgresql/data \
-v \${HOME}/.psqlrc:/root/.psqlrc \
-e POSTGRES_PASSWORD=admin \
-p 5432:5432 -d postgres"
alias psql="docker exec -it -e PGPASSWORD=admin postgres psql -U postgres"
alias pgadmin="docker run -d --rm -p 7000:80 \
--name=pgadmin \
-v /var/lib/pgadmin:/var/lib/pgadmin \
-e 'PGADMIN_DEFAULT_EMAIL=admin' \
-e 'PGADMIN_DEFAULT_PASSWORD=admin' \
--link postgres:postgres \
dpage/pgadmin4"
## phpmyadmin
cat > /tmp/config.user.inc.php <<- EOF
<?php
\$cfg['DBG']['sql']=true;
\$cfg['LoginCookieValidity'] = 10000000;
\$cfg['MaxNavigationItems'] = 1000;
EOF
alias phpmyadmin="docker run -d --rm --name phpmyadmin -v sessions:/sessions -v /tmp/config.user.inc.php:/etc/phpmyadmin/config.user.inc.php -e PMA_ARBITRARY=1 -e PMA_HOST=\$(myip) -p 7000:80 phpmyadmin/phpmyadmin"
## Others
alias psysh="docker run -it --rm -v \$(pwd):/app alxsad/psysh echo"
alias groovysh="docker run --rm -itv \$PWD:/src mausch/docker-groovysh"
[user]
[core]
editor = vim
[push]
default = simple
[http]
postBuffer = 1048576000
[github]
user = hassansin
token = 6930be7d8218137fc61590c0625801e585642685
\set PROMPT1 '%[%033[1m%]%M %n@%/%R%[%033[0m%]%#%x '
\set PROMPT2 '[more] %R > '
\pset null '[null]'
\set COMP_KEYWORD_CASE upper
\timing
\set HISTSIZE 2000
\x auto
\set HISTFILE /var/lib/postgresql/data/.psql_history- :DBNAME
# set Zsh as your default Tmux shell
set-option -g default-shell /bin/zsh
# Tmux should be pretty, we need 256 color for that
set -g default-terminal "screen-256color"
# Tmux uses a 'control key', let's set it to 'Ctrl-a'
# Reason: 'Ctrl-a' is easier to reach than 'Ctrl-b'
set -g prefix C-a
unbind C-b
# command delay? We don't want that, make it short
set -sg escape-time 0
# Set the numbering of windows to go from 1 instead
# of 0 - silly programmers :|
set-option -g base-index 1
setw -g pane-base-index 1
# Allow us to reload our Tmux configuration while
# using Tmux
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# move around panes like in vim
# bind j select-pane -D
# bind k select-pane -U
# bind l select-pane -R
# bind h select-pane -L
# quick pane cycling with Ctrl-a
#unbind ^A
#bind ^A select-pane -t :.+
# Sane scrolling
# set -g mode-mouse on
# enable vim mode
set-window-option -g mode-keys vi
#bind-key -t vi-copy 'v' begin-selection
#bind-key -t vi-copy 'y' copy-selection
### DESIGN CHANGES ###
# panes
set -g pane-border-bg brightblue
set -g pane-border-fg colour236
set -g pane-active-border-fg brightblue
set -g pane-active-border-bg colour236
## Status bar design
# status line
set -g status-justify left
set -g status-bg default
set -g status-fg colour12
set -g status-interval 30
#window mode
setw -g mode-bg colour6
setw -g mode-fg colour0
# The modes {
setw -g clock-mode-colour colour135
setw -g mode-attr bold
setw -g mode-fg colour196
setw -g mode-bg colour238
# }
# The statusbar {
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-attr dim
set -g status-right '#h #[fg=colour233,bg=colour241,bold]'
set -g status-right-length 50
set -g status-left-length 20
setw -g window-status-current-fg colour81
setw -g window-status-current-bg colour238
setw -g window-status-current-attr bold
setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F '
setw -g window-status-fg colour138
setw -g window-status-bg colour235
setw -g window-status-attr none
setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F '
# }
run-shell ~/tmux-resurrect/resurrect.tmux
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-capture-pane-contents 'on'
set nocompatible " be iMproved, required
" --- General settings ---
set backspace=indent,eol,start
set ruler
set number
set showcmd
set incsearch
set hlsearch
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab smarttab
set autoread
set autowrite
set so=7 " cursor offset : 7 lines
set noswapfile "no swap file
set hidden
set list
set list listchars=tab:▸\ ,trail:.,extends:>
set undofile
set undodir=~/.vim/undodir
syntax on
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'airblade/vim-gitgutter'
Plugin 'pangloss/vim-javascript'
Plugin 'shougo/vimshell.vim'
Plugin 'shougo/vimproc.vim'
Plugin 'fatih/vim-go'
Plugin 'mxw/vim-jsx'
Plugin 'nanotech/jellybeans.vim'
Plugin 'mileszs/ack.vim'
Plugin 'henrik/vim-indexed-search'
Plugin 'xolox/vim-misc'
Plugin 'xolox/vim-notes'
Plugin 'plasticboy/vim-markdown'
Plugin 'w0rp/ale'
Plugin 'sebdah/vim-delve'
Plugin 'sjl/gundo.vim'
Plugin 'LargeFile'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
set guifont=Menlo\ for\ Powerline
" --- Colors ----
set t_Co=256
set background=dark
colorscheme jellybeans
highlight SpecialKey ctermbg=None ctermfg=235
highlight Normal ctermbg=NONE
" ---- status line ----
set laststatus=2 " always show status line
let g:airline_powerline_fonts = 1
let g:airline_detect_paste=1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_idx_mode = 1
let g:airline#extensions#tabline#fnamemod = ':t'
nmap <silent> <leader>t :Lex<CR>
" ----- jistr/vim-nerdtree-tabs -----
" Open/close NERDTree Tabs with \t
nmap <silent> <leader>t :NERDTreeTabsToggle<CR>
" To have NERDTree always open on startup
" let g:nerdtree_tabs_open_on_console_startup = 1
" ----- netrw -------
" let g:netrw_list_hide= '\(^\|\s\s\)\zs\.\S\+'
" let g:netrw_preview=1
" let g:netrw_liststyle=3
" let g:netrw_browse_split=4
" let g:netrw_winsize=-30
" let g:netrw_banner=0
" let g:netrw_sort_sequence = '[\/]$,*'
" autocmd FileType netrw setl bufhidden=wipe
" ----- numbers -----
" let g:numbers_exclude = ['unite', 'tagbar', 'startify', 'gundo', 'vimshell', 'w3m', 'nerdtree', 'Mundo', 'MundoDiff', 'netrw']
" ----- ale --------
let g:ale_sign_error = '✘'
let g:ale_sign_warning = '▲'
"show errors or warnings in statusline
let g:airline#extensions#ale#enabled = 1
let g:ale_fixers = {
\ 'javascript': ['prettier'],
\}
let g:ale_fix_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
let g:ale_javascript_prettier_options = '--single-quote'
" ---- javascript -----
autocmd Filetype javascript setlocal ts=2 sts=2 sw=2 expandtab smarttab
" ----- airblade/vim-gitgutter settings -----
" Required after having changed the colorscheme
hi clear SignColumn
" In vim-airline, only display "hunks" if the diff is non-zero
let g:airline#extensions#hunks#non_zero_only = 1
" ---- henrik/vim-indexed-search ----
let g:indexed_search_shortmess = 1
let g:indexed_search_numbered_only = 1
" --- xolox/vim-notes -----
:let g:notes_directories = ['~/Documents/Notes']
:let g:notes_suffix = '.md'
" :let g:notes_suffix = '.md'
" ------ Go Settings -----
let g:go_fmt_command = "goimports"
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
"let g:go_auto_sameids = 1
"let g:go_auto_type_info = 1
"let updatetime=200
" ------ fzf ---------
" installed using git
set rtp+=~/.fzf
nmap <silent> <C-p> <Esc>:FZF<CR>
" ----- Ag ---------
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
cnoreabbrev Ack Ack!
" ----- vim-markdown -----
let g:vim_markdown_folding_disabled = 1
set conceallevel=2
let g:vim_markdown_frontmatter = 1
let g:LargeFile = 10
" autocmd FileType yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab
" ----- Custom mappings ----
" delete Current Buffer: \q
nnoremap <Leader>q :bp\|bd #<CR>
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
nmap <leader>- <Plug>AirlineSelectPrevTab
nmap <leader>= <Plug>AirlineSelectNextTab
" clipboard copy paste
vnoremap <C-c> :w !xclip -i -sel c<CR><CR>:echo line("'>") - line("'<") + 1 . " lines copied to clipboard"<CR>
" quickfix window mappings
map <C-n> :cnext<CR>
map <C-m> :cprevious<CR>
nnoremap <leader>a :cclose<CR>
"to save file that was opened without sudo
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
:command! -nargs=* NRun :write | !node % "<q-args>"
:command! -nargs=* NDebug :write | :!node --inspect-brk % "<q-args>"
# vi: ft=sh
export ZSH=~/.oh-my-zsh
DISABLE_AUTO_UPDATE="true"
DISABLE_UNTRACKED_FILES_DIRTY="true"
NVM_LAZY_LOAD="true"
plugins+=(git zsh-autosuggestions docker docker-compose zsh-syntax-highlighting zsh-nvm aws)
##### User configuration
export PATH="/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
source $ZSH/oh-my-zsh.sh
fpath=(~/.zsh/completions $fpath)
autoload -U compinit && compinit
# pure-prompt
autoload -U promptinit; promptinit
prompt pure
PROMPT="%F{yellow}%B%(1j.*.)%b%f$PROMPT"
export LANG=en_US.UTF-8
# 256 color schemes
export TERM="xterm-256color"
setopt RM_STAR_WAIT
setopt interactivecomments
setopt CORRECT
#GO
export GOPATH=~/Workspace/go
export PATH=$PATH:/usr/local/go/bin:/usr/local/kafka/bin:$GOPATH/bin
export GOROOT=/usr/local/go
#k8s
export KUBECONFIG=~/.kube/config
#### Aliases
alias myip="ip route get 8.8.8.8 | awk 'NR==1 {print \$NF}'"
alias copy="xclip -sel clip"
alias paste="xclip -sel clip -o"
alias psaux="ps aux | grep"
alias ohmyzsh="vim ~/.oh-my-zsh"
alias zshrc="vim ~/.zshrc"
alias vimrc="vim ~/.vimrc"
alias tmuxrc="vim ~/.tmux.conf"
# git aliases
alias gs="git status"
alias gl="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# Docker based tools
#heroku(){
# docker run -it --rm -u "$(id -u)":"$(id -g)" -w "$HOME" \
# -v /etc/passwd:/etc/passwd:ro \
# -v /etc/group:/etc/group:ro \
# -v /etc/localtime:/etc/localtime:ro \
# -v /home:/home \
# -v /tmp:/tmp \
# -v /run/user/"$(id -u)":/run/user/"$(id -u)" \
# --name heroku \
# johnnagro/heroku-toolbelt "$@"
#}
# Gist
# When 2FA enabled, use Personal access tokens with "gist" permission
# You can use ~/.netrc to avoid typing password everytime
export DOTFILES_GISTID=2a2bd32c9c2e514c17da4b2ec8b3851c
gist(){
filename=$(basename "$2")
if [ -z "$1" -o -z "$2" ]; then
echo 'usage: gist put|get|delete|diff filepath';
elif [ ! -f "$2" ]; then
echo "file doesn't exist";
elif [ "$1" = "put" ]; then
jq -R -s 'split("\n") | join("\n") | {files: {"'"$filename"'": {content: .}}}' "$2"| \
curl -sn -XPATCH https://api.github.com/gists/$DOTFILES_GISTID -d @- | \
jq -r -e 'if .description then "updated: " + .description else . end'
elif [ "$1" = "get" ]; then
curl -s "https://api.github.com/gists/$DOTFILES_GISTID" | jq -r -e '.files."'"$filename"'".content'
elif [ "$1" = "delete" ]; then
jq -n '{files: {"'"$filename"'": {content: ""}}}' | \
curl -s -n -XPATCH https://api.github.com/gists/$DOTFILES_GISTID -d @- |\
jq -r -e 'if .description then "updated: " + .description else . end'
elif [ "$1" = "diff" ]; then
gist get "$2" > /tmp/REMOTE
vimdiff "$2" /tmp/REMOTE # use :cq to quit with non-zero exit status and skip following
[ $? -eq 0 ] && mv /tmp/REMOTE "/tmp/$filename" && gist put "/tmp/$filename" && rm "/tmp/$filename"
fi
}
# FZF
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_OPTS="--reverse --inline-info --multi --no-mouse --height=21 --color fg:188,bg:233,hl:103,fg+:222,bg+:234,hl+:104,info:183,prompt:110,spinner:107,pointer:167,marker:215"
which rg > /dev/null 2>&1 && export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"'
bindkey -s '^p' "vim \$(fzf)^M"
# Toggle Monitor
#MONITOR1="eDP-1"
#MONITOR2="VGA-1"
#alias toggle_monitor='xrandr --listactivemonitors | grep "$MONITOR1" > /dev/null && xrandr --output "$MONITOR2" --auto --output "$MONITOR1" --off || xrandr --output "$MONITOR1" --auto --output "$MONITOR2" --off'
alias vim=/usr/local/bin/nvim
alias nvim=/usr/local/bin/nvim
alias vi=/usr/local/bin/vim
alias dc=docker-compose
alias rg="rg --pretty"
source ~/.custom.sh
# added by travis gem
[ -f /home/hassansin/.travis/travis.sh ] && source /home/hassansin/.travis/travis.sh
#export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
# tabtab source for serverless package
# uninstall by removing these lines or running `tabtab uninstall serverless`
[[ -f /home/hassansin/.nvm/versions/node/v8.7.0/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.zsh ]] && . /home/hassansin/.nvm/versions/node/v8.7.0/lib/node_modules/serverless/node_modules/tabtab/.completions/serverless.zsh
# tabtab source for sls package
# uninstall by removing these lines or running `tabtab uninstall sls`
[[ -f /home/hassansin/.nvm/versions/node/v8.7.0/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.zsh ]] && . /home/hassansin/.nvm/versions/node/v8.7.0/lib/node_modules/serverless/node_modules/tabtab/.completions/sls.zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment