Skip to content

Commit

Permalink
finalizing initial interface
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Dec 24, 2011
1 parent f1e6982 commit f88b510
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 88 deletions.
26 changes: 24 additions & 2 deletions README.md
@@ -1,7 +1,29 @@
# jot

> jots down your thoughts so _you_ don't have to
Simple local storage for all of those half baked ideas.

move along, I'll publish this soon
`jot`, `drop` and roll.

## Install

Add the following to your plugin definition

addSbtPlugin("me.lessis" % "jot" % "0.1.0")

And add following in your build definition

seq(jotSettings:_*)

## usage

Below is a list of available settings

jot # Appends an item to your jot file
clean(for jot) or (clean in (SomeConfig, jot)) # Removes an item from your jot file
jot-drop or (drop in SomeConfig)) # Drops a target item from your jot file
jot-cat or (cat in (SomeConfig)) # Lists your jottings
jot-file or (jotFile in (SomeConfig)) # File containing jottings
target(for jot) or (target in (SomeConfig, jot)) # Directory containing generated jot file
colors(for jot) or (colors in (SomeConfig, jot)) # Toggles ansii colored output

Doug Tangren (softprops) 2011
17 changes: 15 additions & 2 deletions build.sbt
Expand Up @@ -5,9 +5,22 @@ organization := "me.lessis"
name := "jot"

version <<= sbtVersion { v =>
if(v.startsWith("0.10")) "0.1.0-%s-SNAPSHOT".format(v)
else if(v.startsWith("0.11")) "0.1.0-SNAPSHOT"
if(v.startsWith("0.11")) "0.1.0"
else error("unsupported version of sbt %s" format v)
}

scalacOptions += "-deprecation"

seq(ScriptedPlugin.scriptedSettings: _*)

publishTo := Some("Scala Tools Nexus" at "http://nexus.scala-tools.org/content/repositories/releases/")

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

seq(lsSettings :_*)

homepage := Some(url("https://github.com/softprops/jot/"))

description := "Sbt interface for storing local project notes"

(LsKeys.tags in LsKeys.lsync) := Seq("sbt")
36 changes: 21 additions & 15 deletions notes/0.1.0.markdown
@@ -1,33 +1,39 @@
# initial release

Jot tracks local project notes in a simple format. I will not make you a sandwich.

- sbt plugins [best practices][bp]
`Jot` tracks project notes locally. It will not make you a sandwich.

- settings

below is a list of available settings
below is a list of available settings(*)

jot # Appends an item to your jot file
clean(for jot) or (clean in (SomeConfig, jot)) # Removes an item from your jot file
jot-drop or (drop in SomeConfig)) # Drops a target item from your jot file
jot-cat or (cat in SomeConfig) # Lists your jottings
jot-file or (jotFile in SomeConfig) # File containing jottings
target(for jot) or (target in (SomeConfig, jot)) # Directory containing jot-file
colors(for jot) or (colors in (SomeConfig, jot)) # Toggles ansii colored output

jot # Appends a thought to your jot file
rm(for jot) or (rm in (SomeConfig, jot)) # Removes a thought from your jot file
ls(for jot) or (ls in (SomeConfig, jot)) # Lists your jotted thoughts
clear(for jot) or (ls in (SomeConfig, jot)) # Clears all jotted thoughts
jot-file(for jot) or (jotFile in (SomeConfig, jot)) # File containing thoughts
jot-directory(for jot) or (jotDirectory in (SomeConfig, jot)) # Directory containing jot file
colors(for jot) or (colors in (SomeConfig, jot)) # Toggles ansii colored output
(*) subject to change in the future. Some key interface combinations of `jot-x(for jot)` were kind of annoying so some keys are not
scoped to jot. This may change in the future

for more information see the projects [readme][rm]
for more information see the project's [readme][rm].

- published for sbt [0.11][sbt11]
- published for sbt [0.11.2][sbt112]

Add the following to your plugin definition

addSbtPlugin("me.lessis" % "jot" % "0.1.0")

And add the settings in your build file with
And add following in your build definition

seq(jotSettings:_*)

And you're done.

If you want other support for other sbt versions [Let me know][issues]

[bp]: https://github.com/harrah/xsbt/wiki/Plugins-Best-Practices
[rm]: https://github.com/softprops/jot#readme
[sbt11]: http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.0/sbt-launch.jar
[sbt112]: http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar
[issues]: https://github.com/softprops/jot/issues
2 changes: 1 addition & 1 deletion notes/about.markdown
@@ -1,3 +1,3 @@
[jot][jot] simply keeps track of project notes. nothing more.
[jot][jot] keeps track of project notes. nothing more.

[jot]: github.com/softprops/jot#readme
8 changes: 8 additions & 0 deletions project/plugins.sbt
@@ -0,0 +1,8 @@
libraryDependencies <+= sbtVersion("org.scala-tools.sbt" %% "scripted-plugin" % _)


resolvers ++= Seq(
"less is" at "http://repo.lessis.me",
"coda" at "http://repo.codahale.com")

addSbtPlugin("me.lessis" % "ls-sbt" % "0.1.1")
19 changes: 19 additions & 0 deletions src/main/ls/0.1.0.json
@@ -0,0 +1,19 @@

{
"organization":"me.lessis",
"name":"jot",
"version":"0.1.0",
"description":"Sbt interface for storing local project notes",
"site":"https://github.com/softprops/jot/",
"tags":["sbt"],
"docs":"",
"licenses": [],
"resolvers": ["http://scala-tools.org/repo-releases"],
"dependencies": [{
"organization":"org.scala-tools.sbt",
"name": "scripted-sbt_2.9.1",
"version": "0.11.2"
}],
"scalas": ["2.9.1"],
"sbt": true
}
136 changes: 71 additions & 65 deletions src/main/scala/jot.scala
@@ -1,97 +1,103 @@
package jot

import sbt._
import Project.Initialize
import java.io.File

object Plugin extends sbt.Plugin {
import sbt._
import sbt.Project.Initialize
import sbt.Keys._
import JotKeys._
import JotKeys.{ jot => j, _ }
import java.io.File

object JotKeys {
val jot = InputKey[Unit]("jot", "Appends an item your jot file")
val rm = InputKey[Unit]("rm", "Removes an item from your jot file")
val ls = TaskKey[Unit]("ls", "Enumerates the contents of your jot file")
val clear = TaskKey[Unit]("clear", "Clears jot file")
val jotFile = SettingKey[File]("jot-file", "File containing jotted items")
val jotDirectory = SettingKey[File]("jot-directory", "Directory containing jot file")
val drop = InputKey[Unit](key("drop"), "Removes an item from your jot file")
val cat = TaskKey[Unit](key("cat"), "Enumerates the contents of your jot file")
val jotFile = SettingKey[File](key("file"), "File containing jotted items")
val colors = SettingKey[Boolean]("colors", "Toggles ansii colored output")
}

private def lines(f: File): Array[(String, Int)] = IO.read(f) match {
case "" => Array.empty[(String, Int)]
case str => str.split("\n\n").zipWithIndex
private def key(name: String) = "jot-%s" format name
}

private def clearTask: Initialize[Task[Unit]] =
(streams, jotFile in jot) map {
private def lines(f: File): Array[(String, Int)] =
IO.read(f) match {
case "" => Array.empty[(String, Int)]
case str => str.split("\n\n").zipWithIndex
}

private def cleanTask: Initialize[Task[Unit]] =
(streams, jotFile) map {
(out, jf) =>
IO.write(jf, "")
out.log.info("jots cleared")
out.log.info("Jots cleared")
}

private def lsTask: Initialize[Task[Unit]] =
(streams, jotFile in jot, colors in jot) map {
private def catTask: Initialize[Task[Unit]] =
(streams, jotFile, colors in j) map {
(out, jf, clrs) =>
out.log.info("jottings..")
out.log.info("Jottings..")
IO.touch(jf)
lines(jf) match {
case Array() => out.log.info("you have none. try `jot some ideas`")
case ts => ts.foreach { _ match {
case(l, n) => out.log.info(
(if(clrs) "\033[0;36m%s\033[0m) \033[0;37m%s\033[0m" else "%s) %s") format(n, l)
)
} }
case Array() => out.log.info("You have none. Try `jot some ideas`")
case ts => ts.foreach {
_ match {
case(l, n) => out.log.info(
(if(clrs) "\033[0;36m%s\033[0m) \033[0;37m%s\033[0m" else "%s) %s") format(n, l)
)
}
}
}
}

def jotSettings: Seq[Setting[_]] =
jotSettingsIn(Compile) ++ jotSettingsIn(Test)

def jotSettingsIn(c: Configuration) = inConfig(c)(jotSettings0)
def jotSettingsIn(c: Configuration) = inConfig(c)(jotSettings0) ++ Seq(
clean in j <<= (clean in (c, j))
)

def jotSettings0: Seq[Setting[_]] = Seq(
jotDirectory in jot <<= (baseDirectory).identity,
jotFile in jot <<= (jotDirectory in jot)(_ / ".jot"),
colors in jot := true,
jot <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, streams, jotFile in jot, colors in jot) map { (args, out, jf, clrs) =>
args.mkString(" ").trim match {
case "" => out.log.error("usage: `jot some ideas`")
case item =>
IO.touch(jf)
IO.append(jf, item + "\n\n")
out.log.info(
(if(clrs) "jotted, \033[0;37m%s\033[0m" else "jotted, %s") format item
)
}
target in j <<= baseDirectory,
jotFile <<= (target in j)(_ / ".jot"),
colors in j := true,
j <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, streams, jotFile, colors in j) map {
(args, out, jf, clrs) =>
args.mkString(" ").trim match {
case "" => out.log.error("usage: `jot some ideas`")
case item =>
IO.touch(jf)
IO.append(jf, item + "\n\n")
out.log.info(
(if(clrs) "jotted, \033[0;37m%s\033[0m" else "jotted, %s") format item
)
}
}
},
rm in jot <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, streams, jotFile in jot, colors in jot) map { (args, out, jf, clrs) =>
args match {
case Seq(num) =>
IO.touch(jf)
val lns = lines(jf)
lns match {
case Array() => out.log.info("nothing to remove")
case many => IO.write(jf, many.filter( _ match {
case (l, n) if(n == num.toInt) =>
out.log.info(
(if(clrs) "removed, \033[0;37m%s\033[0m" else "removed, %s") format l
)
false
case _ => true
}).map(_._1) match {
case Array() => ""
case lns => lns.mkString("","\n\n","\n\n")
})
}
case _ => out.log.error("usage: rm(for jot) <num>")
}
drop <<= inputTask { (argsTask: TaskKey[Seq[String]]) =>
(argsTask, streams, jotFile, colors in j) map {
(args, out, jf, clrs) =>
(args, out.log) match {
case (Seq(num), log) =>
IO.touch(jf)
val lns = lines(jf)
lns match {
case Array() => log.info("Nothing to drop")
case many => IO.write(jf, many.filter( _ match {
case (l, n) if(n == num.toInt) =>
log.info(
(if(clrs) "Dropped, \033[0;37m%s\033[0m" else "removed, %s") format l
)
false
case _ => true
}).map(_._1) match {
case Array() => ""
case lns => lns.mkString("","\n\n","\n\n")
})
}
case (_, log) => log.error("usage: jot-drop <num>")
}
}
},
ls in jot <<= lsTask,
clear in jot <<= clearTask
cat <<= catTask,
clean in j <<= cleanTask
)
}
2 changes: 1 addition & 1 deletion src/sbt-test/jot/customfile/build.sbt
@@ -1,3 +1,3 @@
seq(jotSettings:_*)

(JotKeys.jotFile in (Compile, JotKeys.jot)) <<= (baseDirectory)(_ / ".myjots")
(JotKeys.jotFile in Compile) <<= (baseDirectory)(_ / ".myjots")
4 changes: 2 additions & 2 deletions src/sbt-test/jot/simple/test
Expand Up @@ -4,7 +4,7 @@ $ delete .jot
$ exists .jot

# check that the file is empty
> clear(for jot)
> clean(for jot)
> empty .jot

# check content creation
Expand All @@ -13,5 +13,5 @@ $ exists .jot
> contents .jot fixtures/before-rm

# not rm the second item
> rm(for jot) 1
> jot-drop 1
> contents .jot fixtures/after-rm

0 comments on commit f88b510

Please sign in to comment.