Last active
June 17, 2020 06:31
-
-
Save mdtareque/6a12420c36a285500af924b53ce74d41 to your computer and use it in GitHub Desktop.
Bashrc - color, alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PATH="$PATH":~/bin | |
bold=$(tput bold) | |
#normal=$(tput sgr0) | |
normal=$'\e[0m' # (works better sometimes) | |
bold=$(tput bold) # make colors bold/bright | |
red="$bold$(tput setaf 1)" # bright red text | |
green=$(tput setaf 2) # dim green text | |
fawn=$(tput setaf 3); beige="$fawn" # dark yellow text | |
yellow="$bold$fawn" # bright yellow text | |
darkblue=$(tput setaf 4) # dim blue text | |
blue="$bold$darkblue" # bright blue text | |
purple=$(tput setaf 5); magenta="$purple" # magenta text | |
pink="$bold$purple" # bright magenta text | |
darkcyan=$(tput setaf 6) # dim cyan text | |
cyan="$bold$darkcyan" # bright cyan text | |
gray=$(tput setaf 7) # dim white text | |
darkgray="$bold"$(tput setaf 0) # bold black = dark gray text | |
white="$bold$gray" # bright white text | |
echo "${red}hello ${yellow}this is ${green}coloured${normal}" | |
alias folder-size='du -d 1 -h .' | |
alias tree='tree -C' | |
alias findg="find . -not -iwholename '*.git*'" | |
alias jmxProcess='ps auxf | grep -v -E "(jmxremote.host=localhost|jmxremote.host=127.|grep)" | grep -E "(jmxremote.authenticate=false|jmxremote.ssl=false)"' | |
# colorize | |
alias ls="ls -G " | |
alias grep="grep --color" | |
alias g++="g++ -Wall -DLOCAL=1 " | |
# open files in splits | |
function vim3() { | |
if [ -z ${fname+x} ]; then | |
echo "set ${fname} is not set" | |
fi | |
touch ${fname}.cpp.out ${fname}.cpp ${fname}.cpp.in | |
vim ${fname}.cpp.out -c "vsp ${fname}.cpp" -c "wincmd l" -c "sp ${fname}.cpp.in" | |
} | |
#https://stackoverflow.com/questions/6841143/how-to-set-font-color-for-stdout-and-stderr | |
# to get stderr in red color, invoke as '$ color command' | |
color()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1 | |
alias run='color ./a.out' | |
alias r='color ./a.out' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias gplog='git log --all --graph --decorate --oneline' | |
alias s='git status' | |
alias b='git branch' | |
alias gd='git diff' | |
alias gdc='git diff --cached' | |
alias delete-git-local-branches="git for-each-ref --format '%(refname:short)' refs/heads | grep -v mainline | xargs git branch -d" | |
function gs() { | |
echo "${bold}${yellow}git branch${normal}";git branch; | |
echo -e "\n${bold}${yellow}git status --show-stash${normal}"; git status --show-stash; | |
echo -e "\n${bold}${yellow}git dag -3${normal}"; git dag -3 | |
# echo -e "\n${bold}${yellow}git stash list${normal}"; git stash list | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
email = <email> | |
name = <name> | |
[color] | |
ui = auto | |
[core] | |
pager = less -FMRiX | |
[push] | |
default = simple | |
[alias] | |
dag = log --graph --format='format:%C(yellow)%h%C(reset) %C(blue)\"%an\" <%ae>%C(reset) %C(magenta)%cr%C(reset)%C(auto)%d%C(reset)%n%s' --date-order | |
[push] | |
default = simple | |
[log] | |
decorate = auto | |
abbrevCommit = false | |
[alias] | |
dag = log --graph --format='format:%C(yellow)%h%C(reset) %C(blue)\"%an\" <%ae>%C(reset) %C(magenta)%cr%C(reset)%C(auto)%d%C(reset)%n%s' --date-order | |
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit | |
winning = shortlog --summary --numbered --email | |
pr = pull --rebase | |
changesIn = show --pretty="" name-only | |
changes = log --stat --oneline | |
uncommit = reset HEAD^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" vim notes | |
" General VIM Language Syntax | |
" Verb + Noun e.g.delete word | |
" nouns : TextObjects or Motions or parameterized text objects(find/search) | |
" TextObjects: iw inner word, it inner tag, i" inner quotes, ip inner paragraph, as a sentence | |
" Prefer text objects to motions when possible for repeatability | |
"" command mode line navigation https://vi.stackexchange.com/a/2344/8092 | |
" C-W delete a word | |
" C-U delete line | |
" C-b move to start of line | |
" C-e move to end of line | |
" Mapping | |
" F3 is mapped to toggle line number | |
" ,c is mapped to toggle comments | |
" ,, is mapped to compile cpp files | |
" ,r is mapped to run a.out | |
" ,o is mapped to copy all lines to clipboard | |
" ,l is mapped to reload all files in current window | |
" power key navigation | |
" gi :: start in insert mode where you left off | |
" completion | |
" <C-n><C-p> keyword completion | |
" <C-x><C-f> filename completion | |
" <C-x><C-l> whole line completion | |
" insert filename | |
" <c-r> % | |
" execute command without need to press enter : add 'silent' | |
" trick to visibily see whitespace https://stackoverflow.com/a/19012475/1135954 | |
"set syntax=whitespace | |
" tab editing ,not used | |
" https://stackoverflow.com/questions/7961581/is-there-a-vim-command-to-relocate-a-tab | |
" https://vim.fandom.com/wiki/Using_tab_pages | |
" https://superuser.com/questions/410982/in-vim-how-can-i-quickly-switch-between-tabs | |
" reload vimrc | |
nnoremap <localleader>v :source ~/.vimrc<cr> | |
" Local dirs (centralize everything) https://gist.github.com/millermedeiros/1262085/d6376a5cd6b13ba4573abe0f45a458bf6ae596b7 | |
set backupdir=~/.vim/backups | |
set directory=~/.vim/swaps | |
"https://youtu.be/XA2WjJbmmoM?t=445 | |
set nocompatible | |
" auto reload file https://unix.stackexchange.com/a/383044/17265 | |
set autoread | |
set updatetime=1000 | |
au CursorHold,CursorHoldI * checktime | |
au FocusGained,BufEnter * :checktime | |
au BufRead *.cpp set cursorline | |
syntax enable | |
" set filetypes https://stackoverflow.com/a/19709989/1135954 | |
" au BufRead,BufNewFile *.py set filetype=python | |
filetype plugin on | |
au BufRead .vimrc set filetype=vim | |
set path+=** | |
set wildmenu | |
set hlsearch | |
set foldmethod=manual | |
set tabstop=4 | |
set shiftwidth=4 | |
"set expandtab | |
set autoindent smartindent | |
set number relativenumber | |
" toggle line numbering https://stackoverflow.com/q/762515/1135954 | |
nnoremap <F3> :set invnumber invrelativenumber<CR> | |
set listchars=tab:→\ ,nbsp:␣,precedes:«,extends:» | |
" change new split direction https://stackoverflow.com/a/22614431/1135954 | |
set splitright splitbelow | |
" leader for current buffer https://learnvimscriptthehardway.stevelosh.com/chapters/12.html | |
let maplocalleader = "," | |
" compile g++ | |
" best solution, vim runs command new bash shell, aliases are not set, so below works. | |
" we need to press enter so that we can see the errors | |
nnoremap <localleader>, :w\|:!g++ -Wall -DLOCAL=1 %<CR> | |
" execute a.out | |
nnoremap <localleader>r :w\|:silent !./a.out<cr><C-l> | |
" copy all lines to system clipboard | |
nnoremap <localleader>o :silent %w !pbcopy<cr> | |
" reload all files in current window | |
nnoremap <localleader>l :windo e<cr> | |
" Faster scrolling | |
nnoremap <C-e> 4<C-e> | |
nnoremap <C-y> 4<C-y> | |
au BufNewFile,BufRead *.cpp set nolist | |
fun! OpenInOutFiles() | |
let fname = expand('%:t') | |
let inName = fname . '.in' | |
let outName = fname . '.out' | |
exe "vsplit " . inName | |
exe "split " . outName | |
normal <c-w><c-w> | |
endfun | |
nnoremap <localleader>k :call OpenInOutFiles()<cr> | |
" show tab chars | |
au BufNewFile,BufRead *.py set list | |
" https://alvinalexander.com/linux/vi-vim-editor-color-scheme-colorscheme/ | |
au BufRead .vimrc colorscheme morning | |
au BufRead cpp colorscheme desert | |
au BufRead py colorscheme pablo | |
"insert current datetime on writing dts in insert mode https://vim.fandom.com/wiki/Insert_current_date_or_time | |
:iab <expr> dts strftime("%a, %d %b %Y %H:%M:%S %z") | |
" save and reload folds of current file | |
augroup AutoSaveFolds | |
autocmd! | |
autocmd BufWinLeave * mkview | |
autocmd BufWinEnter * silent loadview | |
augroup END | |
"https://shapeshed.com/vim-statuslines/ | |
set laststatus=2 | |
function! GitBranch() | |
return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") | |
endfunction | |
function! StatuslineGit() | |
let l:extension = expand('%:e') | |
if (l:extension == 'in' || l:extension == 'out') | |
return '' | |
endif | |
let l:branchname = GitBranch() | |
return strlen(l:branchname) > 0?'['.l:branchname.']':'' | |
endfunction | |
set statusline= | |
set statusline+=%{StatuslineGit()} | |
set statusline+=\ %F | |
" change direction | |
set statusline+=%= | |
set statusline+=\ %y | |
set statusline+=\ [%{&fileencoding?&fileencoding:&encoding}] | |
set statusline+=\ %p%% | |
set statusline+=\ \ %l:%c | |
" language specific comment character | |
:autocmd FileType cpp,java,javascript nnoremap <buffer> <localleader>c I//<esc> | |
:autocmd FileType python,bash nnoremap <buffer> <localleader>c I#<esc> | |
:autocmd FileType vim nnoremap <buffer> <localleader>c I"<esc> | |
" java skeleton code https://vi.stackexchange.com/q/20429/8092 | |
augroup javatemplates | |
autocmd! | |
autocmd BufNewFile *.java $r ~/.vim/templates/skeleton.java|call s:SetupJavaClass() | |
fun! s:SetupJavaClass() | |
exe "%s/__TIME__/" . strftime("%a, %d %b %Y %H:%M:%S %z") | |
exe "%s/__CLASS_NAME__/" . expand('%:t:r') | |
" TODO add fileReader system property for local testing | |
endfun | |
augroup END | |
" cpp skeleton code | |
augroup cpptemplates | |
autocmd! | |
autocmd BufNewFile *.cpp $r ~/.vim/templates/skeleton.cpp|call s:SetupCpp() | |
fun! s:SetupCpp() | |
exe "%s/__TIME__/" . strftime("%a, %d %b %Y %H:%M:%S %z") | |
exe "set foldmethod=syntax" | |
exe "set foldmethod=manual" | |
" https://devhints.io/vimscript#variables | |
let l:fname = expand('%:t') | |
exe "%s/input.txt/" . l:fname | |
exe "%s/output.txt/" . l:fname | |
let l:inName = l:fname . '.in' | |
"https://vi.stackexchange.com/a/1947/8092 | |
silent exe '!touch ' . l:inName | |
exe "vsplit " . l:inName | |
let l:outName = l:fname . '.out' | |
silent exe '!touch ' . l:outName | |
exe "split " . l:outName | |
"normal "/void solve\n" | |
"exe "79jo" | |
endfun | |
augroup END | |
" py skeleton code | |
augroup pytemplates | |
autocmd! | |
autocmd BufNewFile *.py $r ~/.vim/templates/skeleton.py3.py|call s:SetupPython() | |
fun! s:SetupPython() | |
exe "%s/__TIME__/" . strftime("%a, %d %b %Y %H:%M:%S %z") | |
" TODO: add input.txt and output.txt replace and similar splits as cpp | |
" https://unix.stackexchange.com/a/336537/17265 exe "set foldmethod=indent" | |
endfun | |
augroup END | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment