Skip to content

Instantly share code, notes, and snippets.

@sadbox
Forked from apage43/newns.sh
Last active December 19, 2015 09:48
Show Gist options
  • Select an option

  • Save sadbox/5935188 to your computer and use it in GitHub Desktop.

Select an option

Save sadbox/5935188 to your computer and use it in GitHub Desktop.
function newns {
if [ $# -ne 1 ]; then
echo "Incorrect number of arguments: $# Expected: 1"
return 1
elif [ ! -e project.clj ]; then
echo "Not in a project directory."
return 1
fi
local filename=src/$(echo $1 | tr .- /_).clj
local testname=test/$(echo $1 | tr .- /_)_test.clj
local dir=$(dirname $filename)
local testdir=$(dirname $testname)
if [ -e $filename ]; then
echo "File $filename already exists."
return 1
elif [ -e $testname ]; then
echo "Test $testname already exists."
return 1
else
mkdir -p $dir $testdir
echo "(ns $1)" > $filename
echo -e "(ns $1-test\n (:require [clojure.test :refer :all]
[$1 :refer :all]))" > $testname
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment