Created
May 2, 2015 18:33
-
-
Save BerndGoldschmidt/0234edc76a764d0c805e to your computer and use it in GitHub Desktop.
My current ~/.bash_profile file
This file contains hidden or 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
# vim must go | |
export EDITOR="nano" | |
# some color please | |
export CLICOLOR=1 | |
# rbenv initializing | |
export RBENV_ROOT=/usr/local/var/rbenv | |
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi | |
# | |
export PATH="~/.rbenv/shims:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:/usr/local/Cellar/php55/5.5.7/bin:$PATH" | |
# git prompt | |
source ~/scripts/git-prompt.sh | |
# gt: Go to git top | |
alias gt='cd $(git rev-parse --show-toplevel 2>/dev/null || (echo "."; echo "No git repository" >&2))' | |
force_color_prompt=yes | |
export PS1='\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[31m\]$(__git_ps1 " (%s)")\[\033[00m\] $ ' | |
export CLICOLOR=1 | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
alias ls='ls -GFh' | |
# Allow forward search with crtl+s | |
stty -ixon | |
# brew tab completion | |
source `brew --repository`/Library/Contributions/brew_bash_completion.sh | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2013/03/14/more-command-line-handiness/ | |
# ########################################### | |
# ls archives (inspired by `extract`) | |
lsz() { | |
if [ $# -ne 1 ] | |
then | |
echo "lsz filename.[tar,tgz,gz,zip,etc]" | |
return 1 | |
fi | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2|*.tar.gz|*.tar|*.tbz2|*.tgz) tar tvf $1;; | |
*.zip) unzip -l $1;; | |
*) echo "'$1' unrecognized." ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# psgrep | |
alias psgrep="ps Ao pid,comm|ruby -e 'puts STDIN.read.gsub(/^ *(\d+) .*?([^\/]+?$)/,\"\\\1: \\\2\")'|grep -iE" | |
# chgext | |
# batch change extension | |
chgext() { | |
for file in *.$1 ; do mv $file `echo $file | sed "s/\(.*\.\)$1/\1$2/"` ; done | |
} | |
# quicklook for terminal! | |
alias ql="qlmanage -p &>/dev/null" | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2013/03/31/a-few-more-of-my-favorite-shell-aliases/ | |
# ########################################### | |
# Google Chrome | |
alias chrome="open -a \"Google Chrome\"" | |
alias cpu='top -o cpu' | |
alias mem='top -o rsize' | |
# copy the working directory path | |
alias cpwd='pwd|tr -d "\n"|pbcopy' | |
# DNS (with update thanks to @blanco) | |
alias flush="sudo killall -HUP mDNSResponder" | |
# share history between terminal sessions | |
alias he="history -a" # export history | |
alias hi="history -n" # import history | |
# Get your current public IP | |
alias ip="curl icanhazip.com" | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2013/07/24/bash-image-tools-for-web-designers/ | |
# ########################################### | |
# Quickly get image dimensions from the command line | |
function imgsize() { | |
local width height | |
if [[ -f $1 ]]; then | |
height=$(sips -g pixelHeight "$1"|tail -n 1|awk '{print $2}') | |
width=$(sips -g pixelWidth "$1"|tail -n 1|awk '{print $2}') | |
echo "${width} x ${height}" | |
else | |
echo "File not found" | |
fi | |
} | |
# encode a given image file as base64 and output css background property to clipboard | |
function 64enc() { | |
openssl base64 -in $1 | awk -v ext="${1#*.}" '{ str1=str1 $0 }END{ print "background:url(data:image/"ext";base64,"str1");" }'|pbcopy | |
echo "$1 encoded to clipboard" | |
} | |
# ########################################### | |
# voices | |
# ########################################### | |
alias robot="say -v Zarvox" | |
alias anna="say -v Anna" | |
alias steffi="say -v Steffi" | |
# ########################################### | |
# aliases | |
# ########################################### | |
alias cgs="clear && git status" | |
alias iossim="open /Applications/Xcode.app/Contents/Applications/iOS\ Simulator.app" | |
alias car="cat" | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2014/05/10/bash-and-dash/ | |
# ########################################### | |
# Open argument in Dash | |
function dash() { | |
open "dash://$*" | |
} | |
# open man page in dash | |
function dman() { | |
open "dash://man:$*" | |
} | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2014/05/14/up-fuzzy-navigation-up-a-directory-tree/ | |
# ########################################### | |
# inspired by `bd`: https://github.com/vigneshwaranr/bd | |
function _up() { | |
local rx updir | |
rx=$(ruby -e "print '$1'.gsub(/\s+/,'').split('').join('.*?')") | |
updir=`echo $PWD | ruby -e "print STDIN.read.sub(/(.*\/$rx[^\/]*\/).*/i,'\1')"` | |
echo -n "$updir" | |
} | |
function up() { | |
if [ $# -eq 0 ]; then | |
echo "up: traverses up the current working directory to first match and cds to it" | |
echo "You need an argument" | |
else | |
cd $(_up "$@") | |
fi | |
} | |
alias f="open -a Finder ." | |
# Sencha | |
export PATH=/Users/bernd/bin/Sencha/Cmd/5.0.3.324:$PATH | |
export SENCHA_CMD_3_0_0="/Users/bernd/bin/Sencha/Cmd/5.0.3.324" | |
# ########################################### | |
# handy stuff from http://brettterpstra.com/2015/01/05/sizeup-tidy-filesize-information-in-terminal/ | |
# ########################################### | |
__sizeup_build_query () { | |
local bool="and" | |
local query="" | |
for t in $@; do | |
query="$query -$bool -iname \"*.$t\"" | |
bool="or" | |
done | |
echo -n "$query" | |
} | |
__sizeup_humanize () { | |
local size=$1 | |
if [ $size -ge 1073741824 ]; then | |
printf '%6.2f%s' $(echo "scale=2;$size/1073741824"| bc) G | |
elif [ $size -ge 1048576 ]; then | |
printf '%6.2f%s' $(echo "scale=2;$size/1048576"| bc) M | |
elif [ $size -ge 1024 ]; then | |
printf '%6.2f%s' $(echo "scale=2;$size/1024"| bc) K | |
else | |
printf '%6.2f%s' ${size} b | |
fi | |
} | |
sizeup () { | |
local helpstring="Show file sizes for all files with totals\n-r\treverse sort\n-[0-3]\tlimit depth (default 4 levels, 0=unlimited)\nAdditional arguments limit by file extension\n\nUsage: sizeup [-r[0123]] ext [,ext]" | |
local totalb=0 | |
local size output reverse OPT | |
local depth="-maxdepth 4" | |
OPTIND=1 | |
while getopts "hr0123" opt; do | |
case $opt in | |
r) reverse="-r " ;; | |
0) depth="" ;; | |
1) depth="-maxdepth 1" ;; | |
2) depth="-maxdepth 2" ;; | |
3) depth="-maxdepth 3" ;; | |
h) echo -e $helpstring; return;; | |
\?) echo "Invalid option: -$OPTARG" >&2; return 1;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
local cmd="find . -type f ${depth}$(__sizeup_build_query $@)" | |
local counter=0 | |
while read -r file; do | |
counter=$(( $counter+1 )) | |
size=$(stat -f '%z' "$file") | |
totalb=$(( $totalb+$size )) | |
>&2 echo -ne $'\E[K\e[1;32m'"${counter}:"$'\e[1;31m'" $file "$'\e[0m'"("$'\e[1;31m'$size$'\e[0m'")"$'\r' | |
# >&2 echo -n "$(__sizeup_humanize $totalb): $file ($size)" | |
# >&2 echo -n $'\r' | |
output="${output}${file#*/}*$size*$(__sizeup_humanize $size)\n" | |
done < <(eval $cmd) | |
>&2 echo -ne $'\r\E[K\e[0m' | |
echo -e "$output"| sort -t '*' ${reverse}-nk 2 | cut -d '*' -f 1,3 | column -s '*' -t | |
echo $'\e[1;33;40m'"Total: "$'\e[1;32;40m'"$(__sizeup_humanize $totalb)"$'\e[1;33;40m'" in $counter files"$'\e[0m' | |
} | |
// the fuck! | |
alias fuck='$(thefuck $(fc -ln -1))' | |
// http://brettterpstra.com/2015/04/27/a-universal-clipboard-command-for-bash/ | |
copy() { | |
if [[ $1 =~ ^-?[hH] ]]; then | |
echo "Intelligently copies command results, text file, or raw text to" | |
echo "OS X clipboard" | |
echo | |
echo "Usage: copy [command or text]" | |
echo " or pipe a command: [command] | copy" | |
return | |
fi | |
local output | |
local res=false | |
local tmpfile="${TMPDIR}/copy.$RANDOM.txt" | |
local msg="" | |
if [[ $# == 0 ]]; then | |
output=$(cat) | |
msg="Input copied to clipboard" | |
res=true | |
else | |
local cmd="" | |
for arg in $@; do | |
cmd+="\"$(echo -en $arg|sed -E 's/"/\\"/g')\" " | |
done | |
output=$(eval "$cmd" 2> /dev/null) | |
if [[ $? == 0 ]]; then | |
msg="Results of command are in the clipboard" | |
res=true | |
else | |
if [[ -f $1 ]]; then | |
output="" | |
for arg in $@; do | |
if [[ -f $arg ]]; then | |
type=`file "$arg"|grep -c text` | |
if [ $type -gt 0 ]; then | |
output+=$(cat $arg) | |
msg+="Contents of $arg are in the clipboard.\n" | |
res=true | |
else | |
msg+="File \"$arg\" is not plain text.\n" | |
fi | |
fi | |
done | |
else | |
output=$@ | |
msg="Text copied to clipboard" | |
res=true | |
fi | |
fi | |
fi | |
$res && echo -ne "$output" | pbcopy -Prefer txt | |
echo -e "$msg" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment