Created
January 25, 2009 21:17
-
-
Save danchoi/52536 to your computer and use it in GitHub Desktop.
autoasciidoc
This file contains 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
#!/usr/bin/env ruby | |
# autoasciidoc | |
# Author: Daniel Choi [email protected] | |
# License: GPLv3 | |
# | |
# This program is a wrapper for asciidoc which watches the source text file for | |
# any changes, which automatically triggers a regeneration of the asciidoc | |
# output. | |
# | |
# Usage: | |
# Put this file on your PATH, chmod a+x it, and then run it just as you would | |
# run asciidoc, e.g. | |
# | |
# autoasciidoc test.txt | |
# | |
# You can pass any asciidoc options through the program. | |
# | |
file = ARGV.pop | |
last_mtime = File.stat(file).mtime | |
new_mtime = Time.now + 1 | |
loop do | |
if new_mtime > last_mtime | |
puts "Regenerating asciidoc output." | |
`asciidoc #{ARGV.join(' ')} #{file}` | |
last_mtime = File.stat(file).mtime | |
end | |
sleep 1 # check in one second intervals | |
new_mtime = File.stat(file).mtime | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment