Skip to content

Instantly share code, notes, and snippets.

@RensOliemans
Forked from hightemp/bash aliases
Created January 19, 2022 14:25
Show Gist options
  • Save RensOliemans/61b4495f8dab69d8838a7ce5947e963f to your computer and use it in GitHub Desktop.
Save RensOliemans/61b4495f8dab69d8838a7ce5947e963f to your computer and use it in GitHub Desktop.
OS=`echo \`uname\` | tr '[:upper:]' '[:lower:]'`
AURL="https://gist.githubusercontent.com/hightemp/5071909/raw/"
ANAME=".bash_aliases"
TMPAPATH="/tmp/$ANAME"
HOMEAPATH="~/$ANAME"
[ "$OS" = "windowsnt" ] && OS_WIN="yes"
[ "$OS" = "darwin" ] && OS_MAC="yes"
[ "$OS" = "linux" ] && OS_LIN="yes"
# Self-update
alias alias_update="rm -f $TMPAPATH;wget $AURL -O $TMPAPATH;mv $TMPAPATH $HOMEAPATH;source $HOMEAPATH"
# ls variants
alias la='ls -A'
alias l='ls -alFtr'
alias lsd='ls -d .*'
alias ll='ls -alF'
[ -n "$OS_LIN" ] && alias ls='ls --color=auto'
[ -n "$OS_MAC" ] && alias ls='ls -G'
# Various
alias h='history | tail'
alias hg='history | grep'
alias mvi='mv -i'
alias rmi='rm -i'
alias {ack,ak}='ack-grep'
# Directories
alias {up,..}='cd ..'
# Archives
function extract {
if [ -z "$1" ]; then
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvJf $1 ;;
*.lzma) unlzma $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x -ad $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*.xz) unxz $1 ;;
*.exe) cabextract $1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
alias extr='extract '
function extract_and_remove {
extract $1
rm -f $1
}
alias extrr='extract_and_remove '
function abspath() {
if [ -d "$1" ]; then
echo "$(cd $1; pwd)"
elif [ -f "$1" ]; then
if [[ $1 == */* ]]; then
echo "$(cd ${1%/*}; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
fi
}
alias abspath="abspath "
# Rails
alias src='script/rails console'
alias srs='script/rails server'
alias rgm='rails g model'
alias rgc='rails g controller'
alias rdc='rake db:drop db:create db:migrate db:seed'
alias rrg='rake routes | grep '
alias rspecd='rspec --drb '
# Git
alias gcl='git clone '
alias gst='git status'
alias {gbra,gb}='git branch'
alias {gco,go}='git checkout'
alias {gcob,gob}='git checkout -b '
alias {gadd,ga}='git add '
alias {gcom,gc}='git commit'
alias {gpul,gl}='git pull '
alias {gpus,gh}='git push '
alias glom='git pull origin master'
alias ghom='git push origin master'
alias gg='git grep '
# Output
alias lcase="tr '[:upper:]' '[:lower:]'"
alias ucase="tr '[:lower:]' '[:upper:]'"
# System
alias df="df -h"
alias du="du -h"
[ -n "$OS_MAC" ] && alias nproc="sysctl hw.ncpu | awk '{print \$2}'"
CORES=`nproc`
JOBS=$(expr $CORES + 1)
alias make="make -j$JOBS"
function install_from_git {
URL=$1
DIRNAME="/tmp/${URL##*/}"
gcl $URL $DIRNAME
pushd $DIRNAME
make
sudo make install
popd
rm -rf $DIRNAME
}
alias ifg="install_from_git "
if [ -n "$OS_MAC" ]; then
function free() {
FREE_BLOCKS=$(vm_stat | grep free | awk '{ print $3 }' | sed 's/\.//')
INACTIVE_BLOCKS=$(vm_stat | grep inactive | awk '{ print $3 }' | sed 's/\.//')
SPECULATIVE_BLOCKS=$(vm_stat | grep speculative | awk '{ print $3 }' | sed 's/\.//')
FREE=$((($FREE_BLOCKS+SPECULATIVE_BLOCKS)*4096/1048576))
INACTIVE=$(($INACTIVE_BLOCKS*4096/1048576))
TOTAL=$((($FREE+$INACTIVE)))
echo "Free: $FREE MB"
echo "Inactive: $INACTIVE MB"
echo "Total free: $TOTAL MB"
}
alias free="free"
fi
# Files
alias lcf="rename 'y/A-Z/a-z/' "
alias ucf="rename 'y/a-z/A-Z/' "
# Vim
alias v='vim'
# Tmux
alias {ton,tn}='tmux set -g mode-mouse on'
alias {tof,tf}='tmux set -g mode-mouse off'
# Linux ubuntu apt/aptitude
if [ -n "$OS_LIN" ]; then
alias aptcs='apt-cache search'
alias apti='sudo aptitude install'
alias aptr='sudo aptitude remove'
alias aptre='sudo aptitude reinstall'
alias apts='aptitude search'
alias aptu='sudo aptitude update'
alias aptuu='sudo aptitude update;sudo aptitude upgrade;'
fi
# Mac ports
if [ -n "$OS_MAC" ]; then
alias brewi='brew install'
alias brews='brew search'
alias porti='sudo port install'
alias ports='port search'
fi
# Grep
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
# Ruby gems
alias gemi='gem install'
alias gemre='gem reinstall'
alias gems='gem search'
# DNS
alias {hostname2ip,h2ip}='dig +short'
# Mac DHCP service
if [ -n "$OS_MAC" ]; then
alias {dhcpup,dhcp-start}='sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist'
alias {dhcpdn,dhcp-stop}='sudo /bin/launchctl unload -w /System/Library/LaunchDaemons/bootps.plist'
fi
# Clipboard
[ -n "$OS_MAC" ] && alias getcb='pbpaste'
[ -n "$OS_WIN" ] && alias getcb='cat /dev/clipboard'
[ -n "$OS_LIN" ] && alias getcb='xclip -o'
# Wget
alias wgetncc='wget --no-check-certificate'
alias wgetc='wget `getcb`'
function wget_archive_and_extract {
URL=$1
FILENAME=${URL##*/}
wget $URL -O $FILENAME
extract $FILENAME
rmi $FILENAME
}
alias wgetae='wget_archive_and_extract '
alias wgetaec='wgetae getcb'
# Utils
alias sitecopy='wget -k -K -E -r -l 10 -p -N -F -nH '
alias ytmp3='youtube-dl --extract-audio --audio-format mp3 '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment