#!/bin/bash
# PODNAME: cube
# ABSTRACT: quick script to send things to hypnocube rather than piping yourself

# easy way to write to cube rather than echoing to the pipe

CUBE=/tmp/hypnocube

if [ ! -e $CUBE ] ; then
  ps ax|grep cubepipe |grep -vq grep
  if [ "$?" == "1" ] ; then
    echo STDERR "starting cube as it is not running"
    cubepipe --daemon
    sleep 3
  else
    echo STDERR "cubepipe is running, but there is no pipe ($CUBE) - restarting"
    cubepipe --restart --daemon
    sleep 3
  fi
fi

status=1
if [ ! -p $CUBE ] ; then
  echo STDERR "$CUBE is not a pipe"
else
  if [ "$1" != "" ] ; then
    echo "$@" >> $CUBE
    status=0
  fi
fi
# perl pod may get added so lets exit before thats an issue
exit $status 

__END__

=pod

=encoding UTF-8

=head1 NAME

cube - quick script to send things to hypnocube rather than piping yourself

=head1 VERSION

version 1.9.1

=head1 AUTHOR

Kevin Mulholland <moodfarm@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Kevin Mulholland.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
