Skip to content

Instantly share code, notes, and snippets.

@jcdarwin
Last active May 14, 2016 06:05
Show Gist options
  • Save jcdarwin/61850200f6ed50becf275876974a1d33 to your computer and use it in GitHub Desktop.
Save jcdarwin/61850200f6ed50becf275876974a1d33 to your computer and use it in GitHub Desktop.
Our .extra file, used with mathiasbynens dotfiles: https://github.com/mathiasbynens/dotfiles
#####################################################
# Paths
#####################################################
# Add paths for epub_tools
export PATH=$PATH:/scripts/epub_tools:/scripts/epub_tools/epub_tools:/scripts/epub_tools/epubcheck:/scripts/epub_tools/epubify:/scripts/epub_tools/epubify_toc:/scripts/epub_tools/epubinfo:/scripts/epub_tools/generate_ncx:/scripts/epub_tools/kindlegen.mac:/scripts/epub_tools/kindlestrip:/scripts/epub_tools/manifester:/scripts/epub_tools/mobi_unpack:/scripts/epub_tools/mobify:/scripts/epub_tools/mobify_toc:/scripts/epub_tools/sequence_ncx
# Add paths for PHP ind PEAR in AMPPs
export PATH=/Applications/AMPPS/php/lib/pear:$PATH
export PATH=/Applications/AMPPS/php/bin:$PATH
# Add path for MongoDB
export PATH=/Applications/AMPPS/mongodb/bin:$PATH
# Sublime Text
export PATH=$PATH:/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/
export EDITOR='subl'
export PATH=/usr/local/bin:$PATH
# Ansible
export PATH=$PATH:/Users/jasondarwin/workspace/ansible/bin
PYTHONPATH=/Users/jasondarwin/workspace/ansible/lib:
ANSIBLE_LIBRARY=/Users/jasondarwin/workspace/ansible/library
MANPATH=/Users/jasondarwin/workspace/ansible/docs/man:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
alias veewee="bundle exec veewee"
# Add mysql to our path
export PATH=$PATH:/Applications/AMPPS/mysql/bin
#####################################################
# Aliases
#####################################################
# Alias to list our aliases
alias aliases="cat ~/.aliases ~/.extra | grep -A1 '^# Alias '"
# Alias to List all, with human readable filesizes
alias lah="ls -lah"
# Alias to clear our console
alias c="clear"
# Alias to Go home
alias h="cd ~/" # Go home
# Alias to create our composer autoloads
alias cdo="composer dump-autoload -o"
# Alias to edit the hosts file
alias hosts="sudo vim /private/etc/hosts"
# Alias to copy our public key to the clipboard
alias pubkey="/bin/cat ~/.ssh/id_rsa.pub | pbcopy"
# Alias to visualise git log (like gitk, in the terminal)
alias lg='git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
### Aliases for servers and REPLS
# Alias for a node http server
# http://mattfield.me/simplehttpclient-with-python/
alias server.node='open http://localhost:8000 && http-server -p 8000'
# Alias for a python http server
alias server.python='open http://localhost:8001 && python -m SimpleHTTPServer 8001'
# Alias for a python CORS http server
alias server.python.cors='open http://localhost:8001 && python -m /usr/local/bin/cors_server.py 8001'
#alias server.python.cgi='open http://localhost:8888 && python -m CGIHTTPServer 8888'
# Alias for a PHP http server
alias server.php='open http://localhost:8002 && php -S localhost:8002'
# Alias for comand-line PHP REPL
alias phpa=phpa-norl
# An alias to make a new dir and cd to it immediately
#alias mkcd='mkdir -p $1 && cd $1'
function mkcd {
if [ ! -n "$1" ]; then
echo "Enter a directory name"
elif [ -d $1 ]; then
echo "\`$1' already exists"
else
mkdir -p $1
cd $1
fi
}
# Open argument in Dash
# http://zanshin.net/2014/12/26/integrating-dash-into-vim-and-the-command-line/
function Dash() {
case $1 in
-h|--help|"")
echo "Usage: Dash [DOCSET:]TERM"
echo " Dash [ -h ]"
echo " e.g. Dash javascript:settimeout"
echo " Dash settimeout"
echo ""
echo "Dash is an API Documentation Browser and Code Snippet Manager for Mac OSX and iOS"
echo "https://kapeli.com/dash_guide";;
*)
open "dash://$*";;
esac
}
# fzf: https://github.com/junegunn/fzf/wiki/examples
# fe [FUZZY PATTERN] - Open the selected file with the default editor
# - Bypass fuzzy finder if there's only one match (--select-1)
# - Exit if there's no match (--exit-0)
fe() {
IFS='
'
local declare files=($(fzf -m --query="$1" --select-1 --exit-0))
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
unset IFS
}
# Modified version where you can press
# - CTRL-O to open with `open` command,
# - CTRL-E or Enter key to open with the $EDITOR
fo() {
local out file key
out=$(fzf -m --query="$1" --exit-0 --expect=ctrl-o,ctrl-e)
key=$(head -1 <<< "$out")
file=$(head -2 <<< "$out" | tail -1)
if [ -n "$file" ]; then
[ "$key" = ctrl-o ] && open "$file" || ${EDITOR:-vim} "$file"
fi
}
fv() {
ORIG_EDITOR=$EDITOR
EDITOR='vim'
fe
EDITOR=$ORIG_EDITOR
}
# https://github.com/junegunn/fzf/wiki/examples#changing-directory
# fda - including hidden directories
fda() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
}
# https://github.com/junegunn/fzf/wiki/examples#changing-directory
# cdf - cd into the directory of the selected file
cdf() {
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
# https://github.com/junegunn/fzf/wiki/examples
# c - browse chrome history
ch() {
local cols sep
cols=$(( COLUMNS / 3 ))
sep='{{::}}'
# Copy History DB to circumvent the lock
# - See http://stackoverflow.com/questions/8936878 for the file path
cp -f ~/Library/Application\ Support/Google/Chrome/Default/History /tmp/h
sqlite3 -separator $sep /tmp/h \
"select substr(title, 1, $cols), url
from urls order by last_visit_time desc" |
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\n", $1, $2}' |
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs open
}
# fzf alias to open the selected file with the default editor
alias fe='fe'
# fzf alias to open the selected file with the default editor - CTRL-O to open with `open` command
alias fo='fo'
# fzf alias to open a directory (including hidden directories)
alias fda='fda'
# fzf alias to cd into the directory of the selected file
alias cdf='cdf'
# fzf alias to browse chrome history
alias ch='ch'
alias fzf_aliases='cat ~/.extra | grep -i -A1 "fzf alias"'
# Alias for elastic search
alias es='cd /usr/local/bin/ && ./elasticsearch -p elasticsearch.pid --config=/usr/local/opt/elasticsearch/config/elasticsearch.yml'
#####################################################
# Extra apps
#####################################################
# init z https://github.com/rupa/z
. ~/z.sh
# init node version manager
. ~/.nvm/nvm.sh
# jenv
#if which jenv > /dev/null; then eval "$(jenv init -)"; fi
#export JAVA_HOME=/Users/jasondarwin/.jenv/versions/1.7
#export MAVEN_OPTS=-XX:MaxPermSize=512M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment