moved around bash functions, maybe fixed a bug in motd

moveTools
Adam Veldhousen 9 years ago
parent 7aaff1f1dc
commit 86fdf11341
Signed by: adam
GPG Key ID: 6DB29003C6DD1E4B

@ -1,8 +1,52 @@
#!/bin/bash
#vim: set ft=sh
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
function prunelocal(){
for b in `git branch --merged | grep -v \*`; do git branch -D $b; done
@ -19,18 +63,13 @@ function printmotd(){
if [[ -f $GOPATH/bin/fortune ]]; then
echo ""
$GOPATH/bin/fortune
elif [[ -f $(fortune) ]]; then
echo ""
elif [[ -f fortune ]]; then
echo ""
fortune
fi
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
# usage: clone user/repo <dir>
function clone()
@ -75,7 +114,6 @@ function vim(){
fi
}
# runs vim outside of the term by forking the command and gvim, great for my windows box
function vimd(){
if [[ $# -eq 0 ]]; then
@ -103,43 +141,7 @@ function calc() {
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
function fs() {
@ -284,50 +286,53 @@ function getcertnames() {
fi;
}
# `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;
# Linux
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
}
# `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;
# OSX
# prints battery percentage, only works on OSX
function batteryPercent(){
echo $(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%d", $10/$5 * 100)}')
}
# `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;
# 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)')";
}
# `o` with no arguments opens the current directory, otherwise opens the given
# location
function o() {
if [ $# -eq 0 ]; then
open .;
# 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
open "$@";
if hash pigz 2> /dev/null; then
cmd="pigz";
else
cmd="gzip";
fi;
fi;
}
# `tre` is a shorthand for `tree` with hidden files and color enabled, ignoring
# the `.git` directory, listing directories first. The output gets piped into
# `less` with options to preserve color and line numbers, unless the output is
# small enough for one screen.
function tre() {
tree -aC -I '.git|node_modules|bower_components' --dirsfirst "$@" | less -FRNX;
echo "Compressing .tar using \`${cmd}\`…";
"${cmd}" -v "${tmpFile}" || return 1;
[ -f "${tmpFile}" ] && rm "${tmpFile}";
echo "${tmpFile}.gz created successfully.";
}

Loading…
Cancel
Save