Skip to content

Instantly share code, notes, and snippets.

@blakek
Last active January 31, 2020 18:09
Show Gist options
  • Save blakek/41fa84d130d6c1c3ffb8c117a0e869f5 to your computer and use it in GitHub Desktop.
Save blakek/41fa84d130d6c1c3ffb8c117a0e869f5 to your computer and use it in GitHub Desktop.
My dotfile backup
##
# Standarize system commands
##
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -lhF'
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias poweroff='sudo shutdown -h now'
alias reboot='sudo reboot'
##
# Fix common typos
##
alias aotm='atom'
alias celar='echo "😜"; sleep .25; clear'
alias sl='echo "🚂 choo-choo"; ls'
##
# Defaults and alternatives for programs
##
isInstalled ccat && alias cat=ccat
alias howdoi='how2 -l javascript'
alias shrug='shrug | clipboard'
alias webcoach='webcoach --details --description'
##
# Shorthand shortcuts
##
# brew leaves outdated
alias blo='comm -12 <(brew outdated | sort) <(brew leaves | sort)'
# Browsersync
alias bs='browser-sync start --logLevel silent --server --files .'
# git
alias g='git'
alias gaa='git add .'
alias gb='git branch'
alias gc='git checkout'
alias gcm='git checkout master'
alias gcb='git checkout -b'
alias gd='git diff'
alias gf='git fetch --prune'
alias gl='git log'
alias glg='git log --graph --decorate --oneline --color | less -R'
alias gp='git pull --prune'
alias gs='git status'
function gdf() {
git diff --color "$@" | diff-so-fancy | less -R
}
alias gh='github'
alias st='subl'
##
# Shortcuts to OS X executables
##
alias chrome-browser='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'
alias firefox='/Applications/FirefoxDeveloperEdition.app/Contents/MacOS/firefox'
alias imageoptim='/Applications/ImageOptim.app/Contents/MacOS/ImageOptim'
##
# Functions
##
function github() {
github="$(type -fp github)"
[[ github == '' ]] && echo '`github` is not installed' && return
[[ $# -eq 0 ]] && "${github}" . || "${github}" "$@"
}
isInstalled ipt && function iseek() {
cd "$(ls -a -d */ .. | ipt)"
iseek
}
# Create the "import" command and import my helper functions
export BKLIB="$HOME/bin/lib"
# If a file exists and is not empty, source it. Otherwise, return an falsy value
import() {
[ -s "$1" ] && source "$1"
}
# Add my personal programs to PATH
import "${BKLIB}/mylog.sh"
export PATH="$HOME/bin:$PATH"
# Please don't use emacs
export EDITOR='atom -w'
# Don't remember commands if space was entered before them.
# Also, don't remember duplicate commands
export HISTCONTROL='ignoreboth'
export HISTIGNORE='exit'
# git prompt settings
import "$HOME/.git-prompt.sh" && {
export GIT_PS1_SHOWDIRTYSTATE='yes'
export GIT_PS1_SHOWUNTRACKEDFILES='yes'
export GIT_PS1_SHOWSTASHSTATE=''
export GIT_PS1_SHOWUPSTREAM='auto'
}
# My prompt
source "$HOME/bin/prompts/triangle.sh"
setPromptCommand
# PROMPT_COMMAND=prompt
primaryColor=$e_light_white
errorColor=$e_light_red
secondaryColor=$e_light_cyan
repoColor=$e_brown
# My aliases
import "$HOME/.bash_aliases"
# bash completion
import "$(brew --prefix)/etc/bash_completion"
# git bash completion
import "$HOME/.git-completion.bash"
# Add RVM to PATH
import "$HOME/.rvm/scripts/rvm" && import "$HOME/.profile"
# Add directory-specific node_modules to PATH
export PATH="node_modules/.bin:$PATH"
# Enable colors in Mac terminal
export CLICOLOR=1
# Expand ! combinations
bind Space:magic-space
# Add a little color to man
export LESS_TERMCAP_mb=$(printf '\e[32m')
export LESS_TERMCAP_md=$(printf '\e[32m')
export LESS_TERMCAP_me=$(printf "\e[0m")
export LESS_TERMCAP_se=$(printf "\e[0m")
export LESS_TERMCAP_so=$(printf "\e[1;44;37m")
export LESS_TERMCAP_ue=$(printf "\e[0m")
export LESS_TERMCAP_us=$(printf "\e[34m")
# Correct stuff
eval "$(thefuck --alias)"
# Set other environment variables and secrets
set -o allexport
import .env
set +o allexport
# Always start on a good note
true
prompt() {
local lastReturn="$?";
local prompt="${primaryColor}[\W${repoColor}\$(__git_ps1 \" %s\")${primaryColor}]";
if [ $lastReturn == "0" ]; then
dolla=$primaryColor"\$";
else
dolla=$errorColor"\$";
fi
PS1="${prompt}${dolla} ${e_reset}"
update_terminal_cwd 2>/dev/null
}
# Reset
reset='\e[0m'
# Colors
white='\e[1;37m'
black='\e[0;30m'
blue='\e[0;34m'
light_blue='\e[1;34m'
green='\e[0;32m'
light_green='\e[1;32m'
cyan='\e[0;36m'
light_cyan='\e[1;36m'
red='\e[0;31m'
light_red='\e[1;31m'
purple='\e[0;35m'
light_purple='\e[1;35m'
brown='\e[0;33m'
yellow='\e[1;33m'
gray='\e[0;30m'
light_gray='\e[0;37m'
# Formats
bold='\e[1m'
italic='\e[3m'
underline='\e[4m'
strikethrough='\e[9m'
e_bold='\[\e[0;1m\]'
e_italic='\[\e[0;3m\]'
e_underline='\[\e[0;4m\]'
e_strikethrough='\[\e[0;9m\]'
##
# For use in variables (e.g. $PS1)
##
# Reset
e_reset='\[\e[0m\]'
# Foreground colors
e_black='\[\e[0;30m\]'
e_gray='\[\e[1;30m\]'
e_red='\[\e[0;31m\]'
e_light_red='\[\e[1;31m\]'
e_green='\[\e[0;32m\]'
e_light_green='\[\e[1;32m\]'
e_brown='\[\e[0;33m\]'
e_yellow='\[\e[1;33m\]'
e_blue='\[\e[0;34m\]'
e_light_blue='\[\e[1;34m\]'
e_purple='\[\e[0;35m\]'
e_light_purple='\[\e[1;35m\]'
e_cyan='\[\e[0;36m\]'
e_light_cyan='\[\e[1;36m\]'
e_light_gray='\[\e[1;37m\]'
e_white='\[\e[0;37m\]'
e_default='\[\e[39m\]'
# Background colors
e_default='\[\e[1;39m\]'
e_bg_black='\[\e[40m\]'
e_bg_red='\[\e[41m\]'
e_bg_green='\[\e[42m\]'
e_bg_yellow='\[\e[43m\]'
e_bg_blue='\[\e[44m\]'
e_bg_magenta='\[\e[45m\]'
e_bg_cyan='\[\e[46m\]'
e_bg_light_gray='\[\e[47m\]'
e_bg_dark_gray='\[\e[100m\]'
e_bg_light_red='\[\e[101m\]'
e_bg_light_green='\[\e[102m\]'
e_bg_light_yellow='\[\e[103m\]'
e_bg_light_blue='\[\e[104m\]'
e_bg_light_magenta='\[\e[105m\]'
e_bg_light_cyan='\[\e[106m\]'
e_bg_white='\[\e[107m\]'
e_bg_default='\[\e[49m\]'
# Formats
e_bold='\[\e[1m\]'
e_italic='\[\e[3m\]'
e_underline='\[\e[4m\]'
e_strikethrough='\[\e[9m\]'
source "$BKLIB/colors.sh"
pheader() {
printf "\n$underline$@$reset\n"
}
pokay() {
printf "$green$@$reset\n"
}
pinfo() {
printf "$blue$@$reset\n"
}
pwarn() {
printf "$yellow$@$reset\n"
}
perror() {
printf "$red$@$reset\n"
}
piheader() {
printf "$underline$@$reset"
}
piokay() {
printf "$green$@$reset"
}
piinfo() {
printf "$blue$@$reset"
}
piwarn() {
printf "$yellow$@$reset"
}
pierror() {
printf "$red$@$reset"
}
ptrue() {
pokay "✔ $@"
}
pitrue() {
piokay "✔ $@"
}
pfalse() {
perror "✘ $@"
}
pifalse() {
pierror "✘ $@"
}
ptodo() {
pinfo "[ ] $@"
}
pitodo() {
piinfo "[ ] $@"
}
ptodoDone() {
pokay "[x] $@"
}
pitodoDone() {
piokay "[x] $@"
}
getSymbol() {
declare lastReturn="$1"
if [ $lastReturn == "0" ]; then
echo "${primaryColor}${e_bold}▲${e_reset}"
else
echo $errorColor"▵"
fi
}
setPS1() {
local lastReturn="$?"
local symbol=$(getSymbol $lastReturn)
PS1="${symbol} ${secondaryColor}\W${repoColor}\$(__git_ps1 \" %s\")${e_reset} "
update_terminal_cwd 2>/dev/null
}
promptCommand() {
local lastReturn="$?"
local symbol=$(getSymbol $lastReturn)
__git_ps1 "${symbol} ${secondaryColor}\W${repoColor}" "${e_reset} " " %s"
update_terminal_cwd 2>/dev/null
}
setPromptCommand() {
PROMPT_COMMAND='promptCommand'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment