Created
August 2, 2013 15:04
-
-
Save morganestes/6140587 to your computer and use it in GitHub Desktop.
bash functions to make life a little easier
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
| # 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 |
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
| # Count the number of files of a specific type | |
| function countfiles() { | |
| local filetype="$1" | |
| ls *."$filetype" -l | wc -l | |
| } |
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
| # 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" | |
| } |
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
| # 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 | |
| } |
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
| # Useful for generating the SHA256 hash from a single file. | |
| function sha256sum() { | |
| local FILE="$1" | |
| shasum -a 256 "$FILE" | cut -d" " -f1 | |
| } |
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
| # Extract files from a tarball without having to remember the exact flag sequence | |
| function untar() { | |
| tar -xvzf "$@" | |
| } |
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
| # Update all the git repositories under ~/Repositories | |
| function updaterepos() { | |
| for f in ~/Repositories/* | |
| do | |
| cd $f && git pull origin master && cd .. | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment