Skip to content

Instantly share code, notes, and snippets.

@billhathaway
Last active August 29, 2015 14:24
Show Gist options
  • Save billhathaway/a2efe9e179e654f77ed5 to your computer and use it in GitHub Desktop.
Save billhathaway/a2efe9e179e654f77ed5 to your computer and use it in GitHub Desktop.
bash function to create and open a new file for programming challenges
GOEDITOR="/Applications/Atom.app"
# practice does the following
# creates a new directory named after the project
# creates a file under that directory named $project.go with a small template
# NOTE: specifically not using main.go so I can distinguish the files in my editor tabs
# opens the file in my editor
# changes to the new project directory
practice() {
if [ $# -ne 1 ]; then
echo "need project name"
return
fi
project=${1}
basedir="${GOPATH}/src/bitbucket.org/billhathaway/practice/${project}"
mkdir -p "${basedir}"
cat > "${basedir}/${project}.go"<<EOF
package main
import (
"fmt"
)
func main() {
}
EOF
open -a "${GOEDITOR}" "${basedir}/${project}.go"
cd "${basedir}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment