added docker-machine util function. removed old boot2docker helpers
parent
b6876b7700
commit
c3e52d9380
236
.bash_functions
236
.bash_functions
|
|
@ -1,52 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#vim: set ft=sh
|
#vim: set ft=sh
|
||||||
|
|
||||||
IFS=$'\n$\t'
|
IFS=$'\n$\t'
|
||||||
|
|
||||||
# `s` with no arguments opens the current directory in Sublime Text, otherwise
|
|
||||||
# opens the given location
|
|
||||||
function s() {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
subl .;
|
|
||||||
else
|
|
||||||
subl "$@";
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
# `a` with no arguments opens the current directory in Atom Editor, otherwise
|
|
||||||
# opens the given location
|
|
||||||
function a() {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
atom .;
|
|
||||||
else
|
|
||||||
atom "$@";
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
# `v` with no arguments opens the current directory in Vim, otherwise opens the
|
|
||||||
# given location
|
|
||||||
function v() {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
vim .;
|
|
||||||
else
|
|
||||||
vim "$@";
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
# `o` with no arguments opens the current directory, otherwise opens the given
|
|
||||||
# location
|
|
||||||
function o() {
|
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
open .;
|
|
||||||
else
|
|
||||||
open "$@";
|
|
||||||
fi;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create a new directory and enter it
|
|
||||||
function mkd() {
|
|
||||||
mkdir -p "$@" && cd "$_";
|
|
||||||
}
|
|
||||||
|
|
||||||
# delete merged local branches
|
# delete merged local branches
|
||||||
function prunelocal(){
|
function prunelocal(){
|
||||||
for b in `git branch --merged | grep -v \*`; do git branch -D $b; done
|
for b in `git branch --merged | grep -v \*`; do git branch -D $b; done
|
||||||
|
|
@ -62,14 +18,19 @@ function printmotd(){
|
||||||
|
|
||||||
if [[ -f $GOPATH/bin/fortune ]]; then
|
if [[ -f $GOPATH/bin/fortune ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
$GOPATH/bin/fortune
|
$GOPATH/bin/fortune -file="$GOPATH/bin/fortunes.txt"
|
||||||
elif [[ -f fortune ]]; then
|
elif [[ -f $(fortune) ]]; then
|
||||||
echo ""
|
echo ""
|
||||||
fortune
|
fortune
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# prints battery percentage, only works on OSX
|
||||||
|
function batteryPercent(){
|
||||||
|
ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%d", $10/$5 * 100)}'
|
||||||
|
}
|
||||||
|
|
||||||
# a shortcut for cloning from github
|
# a shortcut for cloning from github
|
||||||
# usage: clone user/repo <dir>
|
# usage: clone user/repo <dir>
|
||||||
function clone()
|
function clone()
|
||||||
|
|
@ -91,22 +52,61 @@ function clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
# sshs into boot2docker
|
# sshs into boot2docker
|
||||||
function b2d() {
|
function dm() {
|
||||||
b2dinit
|
local TARGET=$2
|
||||||
boot2docker ssh
|
if [ -z "$2" ]; then
|
||||||
}
|
TARGET="default"
|
||||||
|
|
||||||
function b2dinit() {
|
|
||||||
if [[ -n $(ps -ae | grep ".boot2docker") || -n $(tasklist.exe | grep "VBoxHeadless") ]]; then
|
|
||||||
echo "Initializing boot2docker"
|
|
||||||
boot2docker init &> /dev/null
|
|
||||||
boot2docker up &> /dev/null
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eval $(boot2docker shellinit)
|
case $1 in
|
||||||
|
"start" | "up" )
|
||||||
|
|
||||||
|
if [ -z $(docker-machine ls | grep $TARGET) ]; then
|
||||||
|
CREATE=false
|
||||||
|
echo "machine doesn't exist (yes to create)"
|
||||||
|
read CREATE
|
||||||
|
if [[ $CREATE == "yes" ]]; then
|
||||||
|
docker-machine create $TARGET
|
||||||
|
else
|
||||||
|
echo "exiting"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z $(docker-machine status $TARGET | grep Running) ]; then
|
||||||
|
docker-machine start $TARGET
|
||||||
|
fi
|
||||||
|
|
||||||
|
eval $(docker-machine env $TARGET) ;;
|
||||||
|
|
||||||
|
"stop" | "halt" )
|
||||||
|
|
||||||
|
echo "stopping docker machine..."
|
||||||
|
docker-machine stop $TARGET ;;
|
||||||
|
|
||||||
|
"delete" | "destroy" )
|
||||||
|
|
||||||
|
echo "destroying docker machine..."
|
||||||
|
docker-machine rm $TARGET ;;
|
||||||
|
|
||||||
|
"ip" )
|
||||||
|
|
||||||
|
echo $(docker-machine ip $TARGET) ;;
|
||||||
|
|
||||||
|
* )
|
||||||
|
|
||||||
|
echo "usage: dm COMMAND [arg]"
|
||||||
|
echo "[machine name] is 'default' if not defined"
|
||||||
|
echo "Commands:"
|
||||||
|
echo " start | up [machine name] Brings up a docker machine and adds variables to the environment"
|
||||||
|
echo " stop | halt [machine name] Stops the specified docker machine"
|
||||||
|
echo " delete | destroy [machine name] Destroys the specified docker machine"
|
||||||
|
echo " ip [machine name] Prints the ip address for this machine" ;;
|
||||||
|
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function vim(){
|
function vimt(){
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
vim
|
vim
|
||||||
else
|
else
|
||||||
|
|
@ -114,6 +114,7 @@ function vim(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# runs vim outside of the term by forking the command and gvim, great for my windows box
|
# runs vim outside of the term by forking the command and gvim, great for my windows box
|
||||||
function vimd(){
|
function vimd(){
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
|
|
@ -141,7 +142,43 @@ function calc() {
|
||||||
printf "\n";
|
printf "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Create a new directory and enter it
|
||||||
|
function mkd() {
|
||||||
|
mkdir -p "$@" && cd "$_";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Change working directory to the top-most Finder window location
|
||||||
|
function cdf() { # short for `cdfinder`
|
||||||
|
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
||||||
|
function targz() {
|
||||||
|
local tmpFile="${@%/}.tar";
|
||||||
|
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
|
||||||
|
|
||||||
|
size=$(
|
||||||
|
stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat`
|
||||||
|
stat -c"%s" "${tmpFile}" 2> /dev/null # GNU `stat`
|
||||||
|
);
|
||||||
|
|
||||||
|
local cmd="";
|
||||||
|
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
|
||||||
|
# the .tar file is smaller than 50 MB and Zopfli is available; use it
|
||||||
|
cmd="zopfli";
|
||||||
|
else
|
||||||
|
if hash pigz 2> /dev/null; then
|
||||||
|
cmd="pigz";
|
||||||
|
else
|
||||||
|
cmd="gzip";
|
||||||
|
fi;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
echo "Compressing .tar using \`${cmd}\`…";
|
||||||
|
"${cmd}" -v "${tmpFile}" || return 1;
|
||||||
|
[ -f "${tmpFile}" ] && rm "${tmpFile}";
|
||||||
|
echo "${tmpFile}.gz created successfully.";
|
||||||
|
}
|
||||||
|
|
||||||
# Determine size of a file or total size of a directory
|
# Determine size of a file or total size of a directory
|
||||||
function fs() {
|
function fs() {
|
||||||
|
|
@ -286,7 +323,45 @@ function getcertnames() {
|
||||||
fi;
|
fi;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Linux
|
# `s` with no arguments opens the current directory in Sublime Text, otherwise
|
||||||
|
# opens the given location
|
||||||
|
function s() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
subl .;
|
||||||
|
else
|
||||||
|
subl "$@";
|
||||||
|
fi;
|
||||||
|
}
|
||||||
|
|
||||||
|
# `a` with no arguments opens the current directory in Atom Editor, otherwise
|
||||||
|
# opens the given location
|
||||||
|
function a() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
atom .;
|
||||||
|
else
|
||||||
|
atom "$@";
|
||||||
|
fi;
|
||||||
|
}
|
||||||
|
|
||||||
|
# `v` with no arguments opens the current directory in Vim, otherwise opens the
|
||||||
|
# given location
|
||||||
|
function v() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
vim .;
|
||||||
|
else
|
||||||
|
vim "$@";
|
||||||
|
fi;
|
||||||
|
}
|
||||||
|
|
||||||
|
# `o` with no arguments opens the current directory, otherwise opens the given
|
||||||
|
# location
|
||||||
|
function o() {
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
open .;
|
||||||
|
else
|
||||||
|
open "$@";
|
||||||
|
fi;
|
||||||
|
}
|
||||||
|
|
||||||
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
|
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
|
||||||
# the `.git` directory, listing directories first. The output gets piped into
|
# the `.git` directory, listing directories first. The output gets piped into
|
||||||
|
|
@ -295,44 +370,3 @@ function getcertnames() {
|
||||||
function tre() {
|
function tre() {
|
||||||
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
|
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# OSX
|
|
||||||
|
|
||||||
# prints battery percentage, only works on OSX
|
|
||||||
function batteryPercent(){
|
|
||||||
echo $(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%d", $10/$5 * 100)}')
|
|
||||||
}
|
|
||||||
|
|
||||||
# Change working directory to the top-most Finder window location
|
|
||||||
function cdf() { # short for `cdfinder`
|
|
||||||
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
|
|
||||||
}
|
|
||||||
|
|
||||||
# Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
|
|
||||||
function targz() {
|
|
||||||
local tmpFile="${@%/}.tar";
|
|
||||||
tar -cvf "${tmpFile}" --exclude=".DS_Store" "${@}" || return 1;
|
|
||||||
|
|
||||||
size=$(
|
|
||||||
stat -f"%z" "${tmpFile}" 2> /dev/null; # OS X `stat`
|
|
||||||
stat -c"%s" "${tmpFile}" 2> /dev/null # GNU `stat`
|
|
||||||
);
|
|
||||||
|
|
||||||
local cmd="";
|
|
||||||
if (( size < 52428800 )) && hash zopfli 2> /dev/null; then
|
|
||||||
# the .tar file is smaller than 50 MB and Zopfli is available; use it
|
|
||||||
cmd="zopfli";
|
|
||||||
else
|
|
||||||
if hash pigz 2> /dev/null; then
|
|
||||||
cmd="pigz";
|
|
||||||
else
|
|
||||||
cmd="gzip";
|
|
||||||
fi;
|
|
||||||
fi;
|
|
||||||
|
|
||||||
echo "Compressing .tar using \`${cmd}\`…";
|
|
||||||
"${cmd}" -v "${tmpFile}" || return 1;
|
|
||||||
[ -f "${tmpFile}" ] && rm "${tmpFile}";
|
|
||||||
echo "${tmpFile}.gz created successfully.";
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue