Skip to content

Instantly share code, notes, and snippets.

@vidul-nikolaev-petrov
Last active April 24, 2017 07:14
Show Gist options
  • Save vidul-nikolaev-petrov/b24a3a318c0826563fc3a4fb8d6aea8c to your computer and use it in GitHub Desktop.
Save vidul-nikolaev-petrov/b24a3a318c0826563fc3a4fb8d6aea8c to your computer and use it in GitHub Desktop.
Bash aliases
# apps
alias e='exit'
alias v='vim'
alias g='git'
alias gr='grep'
alias c='cut'
alias h='head'
alias t='tail'
alias tf='tail -f'
alias le='less'
alias mo='more'
alias n='node'
alias nm='nmap -sP'
alias p='_ping'
alias pa='_ping_average'
alias r='sudo su'
alias rh='sudo su -'
alias to='top -d1'
alias w='watch -n5'
alias w10='watch -n10'
alias w100='watch -n100'
# grep
alias gre='grep'
alias gerp='grep'
alias gri='grep -i'
alias grr='grep -r'
alias grv='grep -v'
alias grir='grep -ir'
# chmods
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
# navi
alias ,='cd'
alias .,='cd -'
alias ..='cd ..'
alias ...='..;..'
alias ....='..;..;..'
alias .....='..;..;..;..'
alias ......='..;..;..;..;..'
# list
alias la="ls --color -lAGbh --time-style='+%b %d %Y %H:%M'"
alias ll='ls --color --time-style="+%b %d %Y %H:%M"'
alias lls='ls -lc --color'
alias ls='ls -c --color'
alias l='lls'
alias lh='l -h'
# network
alias _ip='dig +short myip.opendns.com @resolver1.opendns.com'
alias _ping='ping 8.8.8.8'
alias _hosts='nmap -sP 192.168.1.0/24'
alias _http='python -m SimpleHTTPServer 4444'
# storage
alias df='df -h'
alias ducks='du -hcs * | sort -rn | head'
alias dusm='du -sm'
alias du32='du -ahx . | sort -rh | head -32'
alias du64='du -ahx . | sort -rh | head -64'
alias du128='du -ahx . | sort -rh | head -128'
alias f1='find . -xdev -type f -size +1M'
alias f10='find . -xdev -type f -size +10M'
alias f100='find . -xdev -type f -size +100M'
alias f1000='find . -xdev -type f -size +1000M'
# misc
alias rand_chars="head -c 500 /dev/urandom | base64 | sed 's/[^a-zA-Z0-9]//g'"
# git
alias git='git --no-pager'
alias gs='git status'
alias gb='git branch -a --color'
alias gd='git diff --color'
alias gc='git commit'
alias ga='git add'
alias gl='git log --pretty=oneline'
alias gps='git push'
alias gpl='git pull'
alias gco='git checkout'
alias grm='git rm'
alias gmv='git mv'
# functions
function _ping_average() {
ping 8.8.8.8 | perl -ne '/time=(\S+)/&&($s+=$1,$c+=1,print($t=localtime,"\t",int($s/$c)," ms$/"))' -
}
function cdmk_temp() {
local tmp_dir="/tmp/$(date +%s)_$(rand_chars | head -c8)"
mkdir $tmp_dir && cd $tmp_dir
}
function ff() {
find . -iname "*$1*"
}
function ffs() {
find . -iname "$1*"
}
function ffe() {
find . -iname "*$1"
}
function ge_dt() {
echo `date +%d_%m_%y.%H_%M_%S`
}
function inital_commit() {
echo "Initial commit: $1"
}
function ge() { # create new repository && add this file in it
local repo=$(ge_dt)
local file_fullname="$1"
local file_basename=$(basename $file_fullname)
local message=$(inital_commit $file_basename)
if [ $file_fullname == $file_basename ]; then
file_fullname="$(pwd)/$file_fullname"
fi
cdmk_temp && git init $repo && cd $repo && cp $file_fullname . &&
git add $file_basename && git commit -m "$message" $file_basename
}
function ger() { # `ge` && edit this file
local file_basename=$(basename $1)
ge $1 1> /dev/null
vim $file_basename
}
function geb() { # `ge` && edit this file in new branch
local file_basename=$(basename $1)
local repo_fullname=$(git rev-parse --show-toplevel)
local repo_basename=$(basename $repo_fillname)
ge $1 1> /dev/null
git checkout -b $repo_basename && vim $file_basename
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment