Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/8d5ff3455c2dbb10e03e to your computer and use it in GitHub Desktop.
Save joyrexus/8d5ff3455c2dbb10e03e to your computer and use it in GitHub Desktop.
A few shell functions
# Show all declared functions
funcs () {
declare -f
}
# Show all declared function names (omitting underscored stuff)
functions () {
declare -F | grep -v _
}
# Print IP address
ip () {
ipconfig getifaddr en0
}
# Make a file executable
cx () {
chmod +x $*
}
# Make "dated" dir (YEAR-MM-DD)
mkddir() {
mkdir $(date '+%Y-%m-%d')
}
# Move into latest "dated" directory (YYYY-MM-DD)
cdd () {
cd $(ls -dr 20*/)
}
# Manage a simple HTTP server
# Usage: http start|stop|restart [port]
http () {
local port="${2:-8000}"
case $1 in
"start")
echo "starting http server"
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
open "http://localhost:${port}/"
;;
"stop")
echo "stopping http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep \
| awk '{print $2}') > /dev/null
;;
"restart")
echo "restarting http server"
kill $(ps aux | grep "python -m SimpleHTTPServer" \
| grep -v grep | awk '{print $2}') > /dev/null
nohup python -m SimpleHTTPServer >| /tmp/nohup.out &
;;
*)
echo "need start|stop|restart"
esac
}
# Extract indented code blocks from markdown/rst
code () {
grep '^ ' $1 | sed 's/^ //'
}
# Print repo revision number
svnrev () {
svn info $1 | awk '/Rev:/ { sub(/.*: /, ""); print }'
}
# Remove directory from svn revision control
nosvn () {
local DIR=${1:-"."}
if [ ! -d $DIR ]; then
echo "You need to specify a directory";
break
fi
read -e -p "Remove $DIR from revision control? (y/n): " CHOICE
if [ $CHOICE == "y" ]; then
find $DIR -name ".svn" -print0 | xargs -0 rm -Rf
fi
}
# Kill all processes matching given arg
stop() {
kill `ps -ef | grep $1 | grep -v grep | awk '{print $2}'`;
}
# Clone and fork a github repo (`fork user/repo`)
# Requires `hub` (https://hub.github.com/)
fork() {
hub clone "$1"
cd "${1##*/}"
hub fork
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment