Skip to content

Instantly share code, notes, and snippets.

@staeff
Last active September 26, 2019 05:45
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 staeff/ba8efdbc4351968bd7ea to your computer and use it in GitHub Desktop.
Save staeff/ba8efdbc4351968bd7ea to your computer and use it in GitHub Desktop.
Snippets related to codio.com
# cd
alias ..='cd ..'
alias ...='cd ../..'
alias cd..='cd ..'
alias cdv='cdvirtualenv'
alias vhost='cd /etc/apache2/vhosts.d/'
function cdl { cd $1; ls;} # Change and list directory
function cdls { cd $1; clear; ls;} # Change and list directory on clear screen
alias nocomment='sed -i.bak "/^\#/d;/^ *$/d"'
# copy move rename
alias cp='cp -vi'
alias mv='mv -i'
alias rm='rm -i'
alias rd='rmdir'
# list
alias dir='ls -l'
alias l='ls -alF'
alias la='ls -la'
alias ll='ls -l'
alias ls='ls $LS_OPTIONS'
alias ls-l='ls -l'
alias l.='ls -d .* --color=auto'
alias l1='ls -1'
alias llh='ls -h'
# misc
alias hgrep='history|grep'
alias o='less'
alias sfind='find *|grep'
alias :q=’exit’
# git
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias iso2utf='iconv -f iso-8859-1 -t utf-8'
alias utf2iso='iconv -f utf-8 -t iso-8859-1'
alias createNewKey="dd bs=1 count=16 if=/dev/random | openssl base64"
alias pipupdate="pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U"
alias m='less -x4RFsX'
alias ssh-showkeys="tail +1 ~/.ssh/*.pub"
alias nzgrep='grep -v "^\s*$\|^\s*#.*"'
alias ducks='du -cks *|sort -rn|head -11'
alias ports='netstat -tulanp'
alias mount='mount |column -t'
alias dfree="df -h -x tmpfs"
alias hist='history | grep --color=auto'
alias ccat='pygmentize -O bg=dark'
alias servethis="python -c 'import SimpleHTTPServer; SimpleHTTPServer.test()'"
alias tm='ps -ef | grep'
alias freq='cut -f1 -d" " ~/.bash_history | sort | uniq -c | sort -nr | head -n 30'
function undozip(){
unzip -l "$1" | awk 'BEGIN { OFS="" ; ORS="" } ; { for ( i=4; i<NF; i++ ) print $i " "; print $NF "\n" }' | xargs -I{} rm -r {}
}
s(){
if [[ $# == 0 ]]; then
sudo $(history -p '!!')
else
sudo "$@"
fi
}
lt () {
ls -ltrh --color $1 | tail -n 15;
}
# go back x directories
b() {
str=""
count=0
while [ "$count" -lt "$1" ];
do
str=$str"../"
let count=count+1
done
cd $str
}
va () {
ack -li -- "$@" 2>/dev/null | xargs -o vim -c "/$@"
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
function mcd() {
mkdir -p "$1" && cd "$1";
}
[color]
branch = auto
diff = auto
status = auto
[alias]
# cool
ap = add -p
b = branch -av # all/verbose
br = branch
ci = commit
cia = commit -v -a
cl = clone
co = checkout
cp = cherry-pick
dc = diff --cached
df = diff
dfs = diff --staged
lg = log -p # show patches
st = status
# remove deleted files, i.e. add the to commit
rmdel = git rm $(git ls-files --deleted)
reha = reset --hard
sh = show
sh10 = show-branch --more=10
shbr = show-branch
mod = diff --name-status # list modified files
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
# sehr ähnlich
timeline = log --oneline --graph --decorate
# maybe
lsd = ls-files --deleted
ls = ls-files # list all file under version control
undo = reset --soft HEAD^
unstage = reset HEAD
# A log of commits indicating where various branches are currently pointing.
lga = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative --branches --remotes
# "git weburl" prints the URL of the github project page for repositories hosted on github.
weburl = !git config --get remote.origin.url | sed -e 's/git:\\/\\/github.com/https:\\/\\/github.com/' -e 's/git@github.com:/https:\\/\\/github.com\\//' -e 's/\\.git$//'
# "git browse" opens the github project page of this repository in the browser.
browse = !open `git weburl`
# notso
type = cat-file -t
dump = cat-file -p
whois = "!sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
who = shortlog -s --
whatis = show -s --pretty='tformat:%h (%s, %ad)' --date=short
# New aliases - to be checked
git = !exec git
f = !git fetch || echo "Gretchen, stop trying to make fetch happen\\!"
st = status --short --branch
n = number
# number, short
nu = number --column -s
# number, full status
ns = number --column
# number command, e.g. git number -c vim 1 # opens file 1 in vim!
nc = number -c
nvi = number -c vim
na = number add
si = status --ignored
ci = commit
co = checkout
br = branch
df = diff
dc = diff --cached
dn = diff --name-only
dw = diff --color-words
sq = merge --squash
cob = checkout -b
# quick add all and commit with message
cm = commit -a -m
ammend = commit --ammend
# safer than just doing git reset HEAD --hard. we can restore using git reflog
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard
llog = log --oneline @{upstream}..HEAD
llp = log -p @{upstream}..HEAD
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
# log tree
lt = log --graph --simplify-by-decoration --pretty=format:'%d' --all
# log list
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
# longer log list
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
# log list no color
lnc = log --pretty=format:"%h\\ %s\\ [%cn]"
# log oneline with dates
lds = log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
# short git log
le = log --oneline --decorate
# quick good log
l = log --graph --oneline --decorate --date=relative --all
# filelog
filelog = log -u
fl = log -u
# diff last commit
dlc = diff --cached HEAD~1
pr = pull --rebase
pro = pull --rebase origin
prom = pull --rebase origin mainline
dag = log --graph --format='format:%C(yellow)%h%C(reset) %C(blue)\"%an\" <%ae>%C(reset) %C(magenta)%ar%C(reset)%C(auto)%d%C(reset)%n%s' --date-order
dfn = diff --name-only
diffn = diff --name-only
permission-reset = !git diff -p -R | grep -E \"^(diff|(old|new) mode)\" | git apply
# searches through all commits
supergrep = !git rev-list --all | xargs git grep
fo = fetch origin
# show recent branches
recent = for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:short)"
scan = "!git clean -nx && git clean -ndx"
nuke = "!git clean -fx && git clean -fdx"
[core]
excludesfile = $HOME/.gitignore
pager=less -XRMSI
# configure git to always add '--rebase' to git pull, to maintain nicer history
# read more about it at http://gitready.com/advanced/2009/02/11/pull-with-rebase.html
# you can override this with the '--no-rebase' switch
[branch]
autosetuprebase = always
# 'set' is a shorthand for 'set-option'
# 'setw' is a shorthand for 'set-window-option'
# 'bind' is a shorthand for 'bind-key'
# I want to use the mouse
setw -g mode-mouse on
set -g mouse-select-window on
set -g mouse-select-pane on
set -g mouse-resize-pane on
# Status bar
set -g status-bg blue
set -g status-fg white
setw -g window-status-current-bg magenta
# Bind prefix to a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Reload conf
bind-key C-r source-file ~/.tmux.conf\; display "Config reloaded!"
# Double tapping the prefix jumps to the last window
bind-key C-a last-window
# remove escape delay in vim
set -s escape-time 0
# Set base-index to 1 instead 0
set -g base-index 1
setw -g pane-base-index 1
# New window with default path set to last path
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
" The Basics
set nocompatible
set background=light
set expandtab " spaces over tabs
set tabstop=4
set softtabstop=4
set shiftwidth=4
" ignorecase and smartcase together make search intelligently.
" all-lowercase string: case-insensitive
" one or more characters uppercase: case-sensitive
set ignorecase
set smartcase
" incsearch, showmatch and hlsearch work together to highlight search results (as you type).
set incsearch
set showmatch
set hlsearch
" pathogen
execute pathogen#infect()
" what is the difference between on and enable?
syntax enable
syntax on " syntax highlighing
filetype on " try to detect filetypes
filetype plugin indent on " enable loading indent file for filetype
colorscheme morning
" Bind for easy pasting
set pastetoggle=<F12>
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Window display
set showcmd ruler laststatus=2
" , is easier to type than \. I use leader commands constantly so it’s worth changing.
let mapleader = ","
let g:mapleader = ","
" Map "follow link"-command to simpler key
map <F11> <C-]>
" I like to bind Ctrl+<movement> keys to move around the windows,
" instead of using Ctrl+w + <movement>:
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Give a shortcut key to NERD Tree
" I rarely use NERD Tree anymore. Command-T is usually all you'll need.
" It is useful when you are getting to know a new codebase for the first time though
map <leader>n :NERDTreeToggle<CR>
map <C-n> :NERDTreeToggle<CR>
" http://vimcasts.org/episodes/the-edit-command/
" trigger edit|split|tab with path of current file
" %% - in the commandline expands to directory path of current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>ew :e %%
map <leader>es :sp %%
map <leader>ev :vsp %%
map <leader>et :tabe %%
" This turns off Vim’s crazy default regex characters and makes searches use Perl/Python compatible regex formatting
nnoremap / /\v
vnoremap / /\v
" Easy saving with CTLR+u
nnoremap <C-u> :w<CR>
inoremap <C-u> <ESC>:w<CR>
vnoremap <C-u> <ESC>:w<CR>
" use jj to exit back to normal mode
inoremap jj <ESC>
" make . do the same thing as : — it’s one less key to hit every time I want to save a file
" (on the german keyboard it is . for
nnoremap . :
" Quit like in bash
nnoremap <C-d> :q<CR>
" Shortcut to rapidly toggle `set list`, show invisible chars
nmap <leader>l :set list!<CR>
" clear out a search by typing ,<space>. This gets rid of the distracting highlighting once I’ve found what I’m looking for.
nnoremap <leader><space> :noh<cr>
" make the tab key match bracket pairs. I use this to move around all the time and <tab> is a hell of a lot easier to type than %.
nnoremap <tab> %
vnoremap <tab> %
" ,a - Ack
nnoremap <leader>a :Ack
" Vimux
" Prompt for a command to run map
map <leader>vp :VimuxPromptCommand<CR>
" Run last command executed by VimuxRunCommand
map <leader>vl :VimuxRunLastCommand<CR>
" Inspect runner pane
map <leader>vi :VimuxInspectRunner<CR>
" Close vim tmux runner opened by VimuxRunCommand
map <leader>vq :VimuxCloseRunner<CR>
" Interrupt any command running in the runner pane
map <Leader>vx :VimuxInterruptRunner<CR>
" use vimux to send code to a REPL.
function! VimuxSlime()
call VimuxSendText(@v)
call VimuxSendKeys("Enter")
endfunction
" If text is selected, save it in the v buffer and send that buffer it to tmux
vmap <leader>sl "vy :call VimuxSlime()<CR>
" Select current paragraph and send it to tmux
nmap <leader>sl vip<leader>sl<CR>
" Zen coding
" let g:user_zen_expandabbr_key = '<c-e>'
let g:use_zen_complete_tag = 1
let g:user_zen_settings = {
\ 'indentation': " ",
\ 'lang': "de",
\ 'scss': {
\ 'extends': 'css',
\ 'filters': 'fc',
\ },
\ 'html': {
\ 'extends': 'html',
\ 'snippets': {
\ 'lorem': "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
\ }
\ },
\}
" some interesting stuff from https://dl.dropbox.com/u/7627133/vimrc.html (Max)
autocmd FileType sql let b:surround_45 = "/* \r */"
" vim as a python ide http://sontek.net/turning-vim-into-a-modern-python-ide
" folding
set foldmethod=indent
set foldlevel=99
" configure SuperTab to be context sensitive and to enable omni code completion
au FileType python set omnifunc=pythoncomplete#Complete
let g:SuperTabDefaultCompletionType = "context"
" enable the menu and pydoc preview to get the most useful information out of the code completion
set completeopt=menuone,longest,preview
" http://stevelosh.com/blog/2010/09/coming-home-to-vim/
" This will disable the arrow keys while you’re in normal mode to help you learn to use hjkl.
" Trust me, you want to learn to use hjkl. Playing a lot of Nethack also helps.
"nnoremap <up> <nop>
"nnoremap <down> <nop>
"nnoremap <left> <nop>
"nnoremap <right> <nop>
" disables the arrow keys in insert mode to force you to get back into
" normal mode the instant you’re done inserting text, which is the “right way” to do things.
"inoremap <up> <nop>
"inoremap <down> <nop>
"inoremap <left> <nop>
"inoremap <right> <nop>
" ,ft - mapped to a "fold tag" for HTML - not working
" nnoremap <leader>ft Vatzf
" ,S - sort CSS Properties - not working
" nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>
" camelCase => camel_case functioniert irgendwie nicht so richtig
" vnoremap <leader>case :s/\v\C(([a-z]+)([A-Z]))/\2_\l\3/g<CR>
"highlight DiffAdd term=reverse cterm=bold ctermbg=green ctermfg=white
"highlight DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black
"highlight DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black
"highlight DiffDelete term=reverse cterm=bold ctermbg=red ctermfg=black

Snippets related to codio.com

qickly set up oh-my-zsh and make it run, when bash is called. Not sure if I want this behaviour, but chsh is not executable on codio. (Maybe this snippet should also go into the setup script)

echo "zsh && exit 0" >> ~/.bash_profile &&  
curl -L http://install.ohmyz.sh | sh 
# add to ~/.bash_profile or ~/.zshrc to autostart tmux session
case $- in *i*)
if [ -z "$TMUX" ]; then
exec tmux;
fi
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment