Last active
April 6, 2019 00:05
-
-
Save mikowl/91f9785a257af0e19b724a358faf2559 to your computer and use it in GitHub Desktop.
My bash_profile
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
# My Aliases | |
alias atom='open -a "Atom"' | |
alias brofile='open ~/.bash_profile' | |
alias chrm='open -a /Applications/Google\ Chrome.app' | |
alias tree='tree -I ".sass-cache|node_modules"' | |
alias ghd='open -a "/Applications/GitHub Desktop.app"' | |
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder" | |
alias getpath='pwd | tr -d "\r\n" | pbcopy' | |
alias getwp='curl -O https://wordpress.org/latest.zip && unzip latest.zip && rm latest.zip' | |
alias hosts='sudo nano /private/etc/hosts' | |
alias myip='curl ipecho.net/plain ; echo' | |
alias listdir='du -sh */ | sort -n -r' | |
alias static='wget -k -K -E -r -l 10 -p -N -F --restrict-file-names=windows -nH' | |
# Launch quick local server | |
alias srv='php -S localhost:8000' | |
alias srv8='php -S localhost:8000 | chrm http://localhost:8000' | |
# Docker stuff | |
alias flushredis='docker exec nordicnaturals_redis /bin/bash -c "redis-cli flushall"' | |
alias nnbash='docker exec -it nordicnaturals_web bash' | |
alias flushmagento='php bin/magento cache:flush' | |
alias dcup='docker-compose up -d' | |
alias dc='docker-compose' | |
alias deploystatic='php bin/magento setup:static-content:deploy --area=frontend -f' | |
# Autocorrect typos in path names when using `cd` | |
shopt -s cdspell; | |
# Enable some Bash 4 features when possible: | |
# * `autocd`, e.g. `**/qux` will enter `./foo/bar/baz/qux` | |
# * Recursive globbing, e.g. `echo **/*.txt` | |
for option in autocd globstar; do | |
shopt -s "$option" 2> /dev/null; | |
done; | |
# Add tab completion for many Bash commands | |
if which brew &> /dev/null && [ -f "$(brew --prefix)/share/bash-completion/bash_completion" ]; then | |
source "$(brew --prefix)/share/bash-completion/bash_completion"; | |
elif [ -f /etc/bash_completion ]; then | |
source /etc/bash_completion; | |
fi; | |
# Add `killall` tab completion for common apps | |
complete -o "nospace" -W "Contacts Calendar Dock Finder Mail Safari iTunes SystemUIServer Terminal Twitter" killall; | |
# Start server at given port and open Chrome with appropriate address | |
# Example srv 8000 starts a server at localhost:8000 | |
function serve { | |
php -S localhost:$@ | | |
open /Applications/Google\ Chrome.app http://localhost:$@ | |
} | |
# Color LS | |
colorflag="-G" | |
alias ls="command ls ${colorflag}" | |
alias l="ls -lF ${colorflag}" # all files, in long format | |
alias la="ls -laF ${colorflag}" # all files inc dotfiles, in long format | |
alias lsd='ls -lF ${colorflag} | grep "^d"' # only directories | |
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" | |
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less' | |
alias lsz="du -sh" | |
# Always enable colored `grep` output | |
# Note: `GREP_OPTIONS="--color=auto"` is deprecated, hence the alias usage. | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
# Easier navigation: .., ..., ...., ....., ~ and - | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias ~="cd ~" # `cd` is probably faster to type though | |
alias -- -="cd -" | |
# Shortcuts | |
alias sites="cd ~/Sites" | |
alias desk="cd ~/Desktop" | |
# Enable aliases to be sudo’ed | |
alias sudo='sudo ' | |
# 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 }'" | |
# Print each PATH entry on a separate line | |
alias path='echo -e ${PATH//:/\\n}' | |
# Colored up cat | |
# Install Pygments first - "sudo easy_install Pygments" | |
# and pigments material theme: https://github.com/horosgrisa/pygments-style-material | |
alias c='pygmentize -O style=material -f console256 -g' | |
# Git | |
alias gs='git status' | |
alias gst='git status -sb' | |
alias ga='git add .' | |
alias gc='git commit -m' | |
alias gp='git push' | |
alias gl='git log --graph --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" --abbrev-commit' | |
alias gb='git branch' | |
alias gco='git checkout' | |
### Prompt Colors | |
# Modified version of @gf3's Sexy Bash Prompt | |
# (https://github.com/gf3/dotfiles) | |
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then | |
export TERM='gnome-256color'; | |
elif infocmp xterm-256color >/dev/null 2>&1; then | |
export TERM='xterm-256color'; | |
fi; | |
prompt_git() { | |
local s=''; | |
local branchName=''; | |
# Check if the current directory is in a Git repository. | |
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then | |
# check if the current directory is in .git before running git checks | |
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then | |
# Ensure the index is up to date. | |
git update-index --really-refresh -q &>/dev/null; | |
# Check for uncommitted changes in the index. | |
if ! $(git diff --quiet --ignore-submodules --cached); then | |
s+='+'; | |
fi; | |
# Check for unstaged changes. | |
if ! $(git diff-files --quiet --ignore-submodules --); then | |
s+='!'; | |
fi; | |
# Check for untracked files. | |
if [ -n "$(git ls-files --others --exclude-standard)" ]; then | |
s+='?'; | |
fi; | |
# Check for stashed files. | |
if $(git rev-parse --verify refs/stash &>/dev/null); then | |
s+='$'; | |
fi; | |
fi; | |
# Get the short symbolic ref. | |
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit | |
# Otherwise, just give up. | |
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \ | |
git rev-parse --short HEAD 2> /dev/null || \ | |
echo '(unknown)')"; | |
[ -n "${s}" ] && s=" [${s}]"; | |
echo -e "${1}${branchName}${2}${s}"; | |
else | |
return; | |
fi; | |
} | |
if tput setaf 1 &> /dev/null; then | |
tput sgr0; # reset colors | |
bold=$(tput bold); | |
reset=$(tput sgr0); | |
# Solarized colors, taken from http://git.io/solarized-colors. | |
black=$(tput setaf 0); | |
blue=$(tput setaf 33); | |
cyan=$(tput setaf 37); | |
green=$(tput setaf 113); | |
greenalt=$(tput setaf 077); | |
orange=$(tput setaf 166); | |
purple=$(tput setaf 125); | |
red=$(tput setaf 124); | |
violet=$(tput setaf 61); | |
white=$(tput setaf 15); | |
yellow=$(tput setaf 136); | |
else | |
bold=''; | |
reset="\e[0m"; | |
black="\e[1;30m"; | |
blue="\e[1;34m"; | |
cyan="\e[1;36m"; | |
green="\e[1;32m"; | |
orange="\e[1;33m"; | |
purple="\e[1;35m"; | |
red="\e[1;31m"; | |
violet="\e[1;35m"; | |
white="\e[1;37m"; | |
yellow="\e[1;33m"; | |
fi; | |
# Highlight the user name when logged in as root. | |
if [[ "${USER}" == "root" ]]; then | |
userStyle="${red}"; | |
else | |
userStyle="${orange}"; | |
fi; | |
# Highlight the hostname when connected via SSH. | |
if [[ "${SSH_TTY}" ]]; then | |
hostStyle="${bold}${red}"; | |
else | |
hostStyle="${yellow}"; | |
fi; | |
# Set the terminal title and prompt. | |
PS1="\[\033]0;\W\007\]"; # working directory base name | |
PS1+="\[${bold}\]\n"; # newline | |
PS1+="\[${userStyle}\]\u"; # username | |
#PS1+="\[${white}\] at "; | |
#PS1+="\[${hostStyle}\]\h"; # host | |
PS1+="\[${white}\] in "; | |
PS1+="\[${cyan}\]\w"; # working directory full path | |
PS1+="\$(prompt_git \"\[${white}\] on \[${green}\]\" \"\[${blue}\]\")"; # Git repository details | |
PS1+="\n"; | |
PS1+="\[${white}\]⚡ \[${reset}\]"; # `$` (and reset color) | |
export PS1; | |
PS2="\[${yellow}\]→ \[${reset}\]"; | |
export PS2; | |
# Git branch details | |
function parse_git_dirty() { | |
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*" | |
} | |
function parse_git_branch() { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" | |
} | |
# Change this symbol to something sweet. | |
# (http://en.wikipedia.org/wiki/Unicode_symbols) | |
symbol="⚡ " | |
### Misc | |
# Only show the current directory's name in the tab | |
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"' | |
# 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" | |
# Kill all the tabs in Chrome to free up memory | |
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description | |
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill" | |
# Reload the shell (i.e. invoke as a login shell) | |
alias reload="exec ${SHELL} -l" | |
# init z! (https://github.com/rupa/z) | |
. ~/z.sh | |
#Define editor | |
export EDITOR='subl -w' | |
# Load RVM function | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" | |
# Git completion | |
if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then | |
. `brew --prefix`/etc/bash_completion.d/git-completion.bash | |
fi | |
# Trigger ~/.bashrc commands | |
#. ~/.bashrc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment