Skip to content

Instantly share code, notes, and snippets.

@dellow
Last active July 19, 2018 16:10
Show Gist options
  • Save dellow/70633b8db3cc885193981905d1540233 to your computer and use it in GitHub Desktop.
Save dellow/70633b8db3cc885193981905d1540233 to your computer and use it in GitHub Desktop.
Dot Files
# ---------------------------------------------------------------------------
# System aliases.
# ---------------------------------------------------------------------------
#
# Color support.
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# ---------------------------------------------------------------------------
# Sublime Text
# ---------------------------------------------------------------------------
#
alias st='/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'
# ---------------------------------------------------------------------------
# Composer
# ---------------------------------------------------------------------------
#
alias composer="php /usr/local/bin/composer.phar"
# ---------------------------------------------------------------------------
# OS & Shortcuts
# ---------------------------------------------------------------------------
# Enable aliases to be sudo’ed.
alias sudo='sudo '
# Print each PATH entry on a separate line
alias path='echo -e ${PATH//:/\\n}'
# Get macOS Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages.
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update; sudo gem cleanup'
# Recursively delete `.DS_Store` files
alias cleanup="find . -type f -name '*.DS_Store' -ls -delete"
# IP addresses
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en0"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
# Reveal hidden files.
alias la='ls -A'
# Reload the shell.
alias reload="exec ${SHELL} -l"
# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'
# Network.
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
alias getip='ipconfig getifaddr en1'
alias getnetwork='arp -a'
alias ifactive="ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'"
# Show/hide hidden files in Finder.
alias show="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hide="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"
# Hide/show all desktop icons (useful when presenting).
alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"
# Enable/Disable Spotlight
alias spotoff="sudo mdutil -a -i off"
alias spoton="sudo mdutil -a -i on"
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# Kill all the tabs in Chrome to free up memory
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"
# ---------------------------------------------------------------------------
# Gulp
# ---------------------------------------------------------------------------
#
alias g='gulp'
# ---------------------------------------------------------------------------
# Git
# ---------------------------------------------------------------------------
#
alias gitst='git status'
alias gitcm='git commit -am'
alias gitmg='git merge'
alias gitmgs='git merge --squash'
alias gitco='git checkout'
alias gitbr='git branch'
alias gitps='git push'
alias gitlog='git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
alias gitreset='git reset --hard HEAD'
alias gitprevious='git reset --hard HEAD~1'
alias gitpsall='git push origin --all && git push origin --tags'
alias gitgraph='git log --graph --decorate --pretty=oneline --abbrev-commit --all'
alias gita='git add --all'
alias gitls='git ls-files'
alias gitcobr='git checkout -b'
alias gitfetch='git fetch origin'
alias gitfetchall='git fetch --all'
alias gitrb='git rebase -i'
alias gitdt='git difftool'
alias gitamend='git commit --amend'
# ---------------------------------------------------------------------------
# Functions
# ---------------------------------------------------------------------------
#
# Usage: fs <dir/filename>
# Desc: Determine size of a file or total size of a directory
function fs() {
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh;
else
local arg=-sh;
fi
if [[ -n "$@" ]]; then
du $arg -- "$@";
else
du $arg .[^.]* ./*;
fi;
}
# Usage: gitclone <repo_url>
# Desc: Clones repo and get's ALL remote branches
function gitclone(){
git clone $1 .
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
git branch --track ${branch##*/} $branch
done
}
# Usage: gitdeletebranch <branch>
# Desc: Removes a branch from the Git local and remote.
function gitdeletebranch(){
git branch -D $1
git push origin :$1
}
# Usage: gitdeletedir <directory>
# Desc: Removes a directory from the Git remote.
function gitdeletedir(){
git rm -r --cached $1
git commit -am "Removed ignored $1 directory"
}
# Usage: gitdeletetag <tag>
# Desc: Removes a tag from the Git local and remote.
function gitdeletetag(){
git tag -d $1
git push origin :refs/tags/$1
}
# Usage: httpserver <dirname>
# Desc: Start an HTTP server from a directory, optionally specifying the port
function httpserver() {
local port="${1:-8000}";
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port";
}
# Usage: mkd <dirname>
# Desc: Create a new directory and enter it.
function mkd() {
mkdir -p "$@" && cd "$_";
}
# Usage: ngrok <local_domain>
# Desc: Fires up ngrok server
function ngrok(){
if [ -z ${1+x} ]; then
echo "You must set a local domain";
else
~/ngrok http -host-header=rewrite $1:80
fi
}
# Usage: phpserver <dirname>
# Desc: Start a PHP server from a directory, optionally specifying the port
function phpserver() {
local port="${1:-4000}";
local ip=$(ipconfig getifaddr en1);
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}";
}
# Usage: resize <width> <img_path> (or wildcard - *.jpg)
# Desc: Resizes an image or batch of images.
function resize(){
sips -Z $1 $2
}
# Usage: transfer <path_to_file>
# Desc: Uses transfer.sh to upload files.
function transfer() {
if [ $# -eq 0 ]; then echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi
tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile;
}
# Usage: tre
# Desc: `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring the `.git` directory, listing directories first. The output gets piped into `less` with options to preserve color and line numbers, unless the output is small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}
# ~/.bashrc: executed by bash(1) for non-login shells.
# ---------------------------------------------------------------------------
# PATH
# ---------------------------------------------------------------------------
export PATH="$HOME/usr/local/php5/bin:$HOME/.rvm/bin:$HOME/.composer/vendor/bin:$PATH"
# ---------------------------------------------------------------------------
# Terminal editor
# ---------------------------------------------------------------------------
export EDITOR=nano
# ---------------------------------------------------------------------------
# Git editor
# ---------------------------------------------------------------------------
export GIT_EDITOR=nano
# ---------------------------------------------------------------------------
# Don't check mail
# ---------------------------------------------------------------------------
unset MAILCHECK
# ---------------------------------------------------------------------------
# Don't put duplicate lines or lines starting with space in the history.
# ---------------------------------------------------------------------------
HISTCONTROL=ignoreboth
# ---------------------------------------------------------------------------
# For setting history length see HISTSIZE and HISTFILESIZE in bash(1)
# ---------------------------------------------------------------------------
HISTSIZE=1000
HISTFILESIZE=2000
# ---------------------------------------------------------------------------
# Load RVM into a shell session *as a function*
# ---------------------------------------------------------------------------
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# ---------------------------------------------------------------------------
# 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
# ---------------------------------------------------------------------------
# Alias definitions
# ---------------------------------------------------------------------------
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment