Last active
January 5, 2017 03:12
-
-
Save azam/5898a0ae791e3686dbab3da4d35e59b9 to your computer and use it in GitHub Desktop.
Common bash profile for macOS
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
### prep a dir for git with github sane defaults | |
### usage: gitprep ulidj azam/ulidj | |
gitprep() { | |
if [ -z "$2" ] | |
then | |
echo "gitprep: illegal arguments" | |
echo "usage: gitprep [dirname] [reponame]" | |
return -1 | |
else | |
mkdir $1 | |
cd $1 | |
git init | |
git config user.name "azam" | |
git config user.email "[email protected]" | |
git config push.default simple | |
git config core.precomposeunicode true | |
git remote add origin [email protected]:$2 | |
git remote update | |
return 0 | |
fi | |
} | |
### Generate 16 random alphanumeric chars | |
### Usage: randpass | |
randpass() { | |
cat /dev/urandom | env LC_CTYPE=C tr -dc "a-zA-Z0-9" | head -c 16 | |
echo | |
return 0 | |
} | |
### Runs command for n times asynchronously | |
### Usage: runasync N my command here | |
runasync() { | |
local n=$1 | |
shift | |
for i in `seq $n`; do | |
nohup $@ &> nohup.out.$i & | |
done | |
} | |
### Runs command for n times synchronously | |
### Usage: run N my command here | |
run() { | |
local n=$1 | |
shift | |
for i in `seq $n`; do | |
$@ | |
done | |
} | |
### Zip all files and directories in current directory in separate zip files | |
### Usage: zipall | |
zipall() { | |
for i in */; do zip -r "${i%/}.zip" "$i"; done | |
} | |
### Zip all files and directories in current directory in one file | |
### Usage: zd . | |
zd() { | |
zip -r "$1.zip" "$1" | |
} | |
### Watch a directory for changes and echo the changed file | |
### Usage: watch . 3 | |
watch() { | |
local interval=$2 | |
while [[ true ]] | |
do | |
local files=`find $1 -type f -mtime -${interval}s` | |
if [$files != ""] ; then | |
echo $files | |
fi | |
sleep $interval | |
done | |
} | |
### Useful settings | |
export PS1="\D{%T} \W$ " | |
alias ll="ls -alG" | |
alias mroe=more | |
alias flushdns="sudo killall -HUP mDNSResponder" | |
alias servehere="python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"0.0.0.0\", 8888), shs.SimpleHTTPRequestHandler).serve_forever()'" | |
alias genkey="ssh-keygen -t rsa -N '' -f" | |
alias lslisten="lsof -P -iTCP -sTCP:LISTEN" | |
alias lsports="sudo lsof -iTCP -sTCP:LISTEN -n -P" | |
alias grepjava="grep -R --include=*.java" | |
alias grepjs="grep -R --include=*.js" | |
alias grepxml="grep -R --include=*.xml" | |
### Java | |
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) | |
### NPM | |
export PATH=$PATH:./node_modules/.bin | |
### Rust | |
export PATH="$HOME/.cargo/bin:$PATH" | |
export RUST_SRC_PATH="$HOME/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/src" | |
### Helper for macOS apps | |
__APPPATHS=("ce:CotEditor" "st:Sublime\ Text" "vsc:Visual\ Studio\ Code") | |
for __apppath in "${__APPPATHS[@]}" ; do | |
__alias=${__apppath%%:*} | |
__path=${__apppath#*:} | |
alias $__alias="open -a /Applications/$__path.app" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment