notify_osd 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/perl
  2. #
  3. # notify_osd: perform some string manipulation on notify-osd messages
  4. # and then send to the screen message window
  5. # Copyright (C) 2010 Canonical Ltd.
  6. #
  7. # Authors: Dustin Kirkland <kirkland@byobu.org>
  8. # with help from Mathias Gug <mathias.gug@canonical.com>
  9. #
  10. # This program is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, version 3 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. $/ = "\n\n";
  22. $PKG = "byobu";
  23. $sleep = 5;
  24. while (<STDIN>) {
  25. # Ensure that the notify_osd indicator is enabled
  26. my $skip = 0;
  27. open(F, "<$ENV{BYOBU_CONFIG_DIR}/status");
  28. foreach my $i (<F>) {
  29. if ($i =~ /notify_osd=0/) {
  30. $skip = 1;
  31. }
  32. }
  33. close(F);
  34. if ($skip == 1) {
  35. next;
  36. }
  37. $msg = $_;
  38. $msg =~ s/\[[^,]*, //; # strip the leading "[timestamp, "
  39. $msg =~ s/\] /: /; # replace the " ] " following the indicator name, with ":"
  40. $msg =~ s/\s+/ /g; # collapse multi-whitespace into one
  41. $msg =~ s/\s+$//g; # strip trailing whitespace
  42. $msg =~ s/^\s+//g; # strip leading whitespace
  43. system("/usr/bin/screen", "-X", "-S", "$ARGV[0]", "at", "*", "msgwait", "$sleep");
  44. system("/usr/bin/screen", "-X", "-S", "$ARGV[0]", "at", "*", "echo", "[$msg]");
  45. sleep($sleep);
  46. system("/usr/bin/screen", "-X", "-S", "$ARGV[0]", "at", "*", "msgwait", "0");
  47. }