Skip to content

Instantly share code, notes, and snippets.

@KellyLSB
Last active August 29, 2015 13:55
Show Gist options
  • Save KellyLSB/8721844 to your computer and use it in GitHub Desktop.
Save KellyLSB/8721844 to your computer and use it in GitHub Desktop.
Sublime Text 2 Rspec Runner (Dir Traversal Version) with FIFO tools. `fifo_reader` and `fifo_writer` use namespaces to keep jobs seperate. The rspec plugin for Sumblime writes the the 'rspec' fifo and can be read using the `fifo_reader rspec` command. Killing this process clears the remaining items in the queue. `fifo_reader <space>` can also be…
#!/usr/bin/env zsh
PIPE="/tmp/$1.fifo"
# Create the FIFO
if [ ! -p $PIPE ]; then mkfifo -m 0777 $PIPE; fi
# Trap kill traps
trap "rm -f $PIPE" SIGINT
trap "rm -f $PIPE" SIGTERM
# While the FIFO exists run the commands
while [ -p $PIPE ]; do
if read COMMAND < $PIPE; then
clear
/usr/bin/env zsh -c "$COMMAND"
wait
fi
done
# Kill any writers writing to this fifo
ps aux | grep 'fifo_writer $1' | tail -n +2 | awk '{print $2}' | xargs kill
exit
#!/usr/bin/env zsh
PIPE="/tmp/$1.fifo"
# Error if Pipe does not exit
if [ ! -p $PIPE ]
then
echo "Pipe: $PIPE is not available"
exit 1
fi
# Append to Pipe
echo $2 >> $PIPE
wait
exit
import sublime_plugin, re, subprocess
from os import path
class RspecRunner(sublime_plugin.EventListener):
def on_post_save(self, view):
filename = view.file_name()
# Are we in a rspec file
if re.search('[sS]{1}pec\.rb$', filename):
# Set the project tree for traversal
project_tree = filename
# File the highest project root
while project_tree != '/':
project_tree = path.dirname(project_tree)
if path.exists("%(project_tree)s/Gemfile" % locals()):
project_root = project_tree
# Get the row number
row = view.rowcol(view.sel()[0].begin())[0] + 1
# Prepare and run the spec
filename = re.sub("^%(project_root)s" % locals(), '.', filename)
command = "cd %(project_root)s; bundle exec rspec %(filename)s:%(row)s" % locals()
print "Appending Command: %(command)s to fifo." % locals()
subprocess.Popen(["fifo_writer", "rspec", command, "&"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment