├── .gitignore ├── .ruby-version ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin └── with_anybar ├── lib ├── with_anybar.rb └── with_anybar │ └── version.rb └── with_anybar.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.gem 11 | *.rbc 12 | /.config 13 | /InstalledFiles 14 | /test/tmp/ 15 | /test/version_tmp/ 16 | 17 | /vendor/bundle 18 | /lib/bundler/man/ 19 | 20 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.2.2 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in with_anybar.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Riaz Virani 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Gem Version](https://badge.fury.io/rb/with_anybar.svg)](http://badge.fury.io/rb/with_anybar) 2 | 3 | # with_anybar 4 | 5 | With_anybar is a simple gem that uses [AnyBar](https://github.com/tonsky/AnyBar) as a notification system for a long running command line command. For example, you may need to execute a long build process or script that sometimes may error. Rather than manually checking the status of that command, you can see whether it's complete via AnyBar! 6 | 7 | ## Installation 8 | 9 | Install AnyBar 10 | 11 | $ brew cask install anybar 12 | 13 | Install the with_anybar gem 14 | 15 | $ gem install with_anybar 16 | 17 | ## Usage 18 | 19 | Call any command on your terminal using with_anybar 20 | 21 | $ with_anybar say "Your AnyBar should turn orange before turning green right now" 22 | 23 | While the command is running, your AnyBar will turn **ORANGE** 24 | 25 | If the command succeeds, your AnyBar will turn **GREEN** 26 | 27 | If the command fails, your AnyBar will turn **RED** 28 | 29 | If you are running multiple instances of AnyBar or not running it on the standard port (1738), you can set the 30 | `ANYBAR_PORT` environment variable on run. 31 | 32 | $ ANYBAR_PORT=1739 with_anybar say "Your AnyBar should turn orange before turning green right now" 33 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | -------------------------------------------------------------------------------- /bin/with_anybar: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "with_anybar" 3 | 4 | # Get arguments afterward and concatenate to string 5 | @command = ARGV.join(" ") 6 | 7 | # Launch Anybar if not running 8 | current_user = `whoami`.strip 9 | 10 | if Dir.exist?("/Users/#{current_user}/Applications/AnyBar.app") 11 | unless system("open /Users/#{current_user}/Applications/AnyBar.app") 12 | fail "Could not launch Anybar app" 13 | end 14 | elsif Dir.exist?("/Applications/AnyBar.app") 15 | unless system("open /Applications/AnyBar.app") 16 | fail "Could not launch Anybar app" 17 | end 18 | else 19 | fail "Could not find AnyBar app" 20 | end 21 | 22 | # Clear Anybar status 23 | warn "Getting to Work" 24 | WithAnybar.change_color("orange") 25 | 26 | # Run as system call 27 | begin 28 | if system(@command) 29 | @blinker = WithAnybar.blink("green") 30 | warn "Boom! Done." 31 | else 32 | @blinker = WithAnybar.blink("red") 33 | warn "Your job died a miserable death!" 34 | end 35 | 36 | warn "Press Enter to end" 37 | $stdin.gets 38 | ensure 39 | Process.kill('QUIT', @blinker) if @blinker 40 | WithAnybar.clear_color 41 | end 42 | -------------------------------------------------------------------------------- /lib/with_anybar.rb: -------------------------------------------------------------------------------- 1 | require "with_anybar/version" 2 | 3 | module WithAnybar 4 | require 'socket' 5 | 6 | def self.change_color(color) 7 | any_bar = UDPSocket.new 8 | any_bar.connect "localhost", ENV["ANYBAR_PORT"] || 1738 9 | any_bar.send color, 0 10 | any_bar.close 11 | end 12 | 13 | def self.clear_color 14 | change_color("white") 15 | end 16 | 17 | def self.blink(color) 18 | fork do 19 | while true do 20 | change_color(color) 21 | sleep(0.6) 22 | clear_color 23 | sleep(0.6) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/with_anybar/version.rb: -------------------------------------------------------------------------------- 1 | module WithAnybar 2 | VERSION = "0.2.0" 3 | end 4 | -------------------------------------------------------------------------------- /with_anybar.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'with_anybar/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "with_anybar" 8 | spec.version = WithAnybar::VERSION 9 | spec.authors = ["Riaz Virani"] 10 | spec.email = ["riaz.n.virani@gmail.com"] 11 | 12 | spec.summary = %q{Track status of a bash command in anybar} 13 | spec.homepage = "https://github.com/rvirani1/with_anybar" 14 | 15 | spec.files = `git ls-files -z`.split("\x0") 16 | spec.bindir = "bin" 17 | spec.executables = ["with_anybar"] 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.9" 21 | spec.add_development_dependency "rake", "~> 10.0" 22 | end 23 | --------------------------------------------------------------------------------