bash functions to make life a little easier
# Use https://github.com/mathiasbynens/dotfiles as a starting point
# Read it all before you run it or you WILL jack some things up.
# Add your extra functions to the .functions file.
# Restart terminal, or just `source ~/.functions` to refresh
# Count the number of files of a specific type
function countfiles() {
local filetype="$1"
ls *."$filetype" -l | wc -l
}
# Extract audio from a video file with ffmpeg
function extractaudio() {
video=$1
ffmpeg -i "$video" -vn -ac 2 -ar 44100 -ab 320k -f mp3 "${video%.*}.mp3"
}
# Switch which version of PHP to use from CLI
# see https://coderwall.com/p/vn1iqg
function php-switch() {
local version="$1"
if [ "$version" = '-h' ]; then
echo "Usage: `basename ${FUNCNAME[0]}` [-h] [-v (53|54|55)]"
elif [ "$version" = "" ]; then
echo "`$(basename php) --version`"
else
if [ "$version" = "53" ]; then
brew unlink php54 && brew unlink php55 && brew unlink php53 && brew link php53
elif [ "$version" = "54" ]; then
brew unlink php53 && brew unlink php55 && brew unlink php54 && brew link php54
elif [ "$version" = "55" ]; then
brew unlink php53 && brew unlink php54 && brew unlink php55 && brew link php55
fi
php --version
fi
}
# Useful for generating the SHA256 hash from a single file.
function sha256sum() {
local FILE="$1"
shasum -a 256 "$FILE" | cut -d" " -f1
}
# Extract files from a tarball without having to remember the exact flag sequence
function untar() {
tar -xvzf "$@"
}
# Update all the git repositories under ~/Repositories
function updaterepos() {
for f in ~/Repositories/*
do
cd $f && git pull origin master && cd ..
done
}