romglog 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Support UTF-8 in author names & commit messages, even when
4
+ # the system locale isn't set to UTF-8.
5
+ Encoding.default_external = Encoding::UTF_8 if RUBY_VERSION > '1.8.7'
6
+
7
+ $:.unshift File.expand_path('../../lib', __FILE__)
8
+
9
+ require 'omglog'
10
+
11
+ abort("Run omglog at the root of the git repo you'd like to watch.") if (ARGV & %w[-h --help help]).any?
12
+ abort("The current directory doesn't look like the root of a git repo.") unless File.directory?('.git')
13
+
14
+ if RUBY_PLATFORM[/darwin/i]
15
+ require 'osx'
16
+ Omglog.run_on Omglog::OSX
17
+ elsif RUBY_PLATFORM[/linux/i]
18
+ require 'linux'
19
+ Omglog.run_on Omglog::Linux
20
+ else
21
+ abort("Sorry, your system isn't supported yet. It just needs notification support -- i.e. fsevents on OS X, or inotify on Linux.")
22
+ end
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Support UTF-8 in author names & commit messages, even when
4
+ # the system locale isn't set to UTF-8.
5
+ Encoding.default_external = Encoding::UTF_8 if RUBY_VERSION > '1.8.7'
6
+
7
+ $:.unshift File.expand_path('../../lib', __FILE__)
8
+
9
+ require 'romglog'
10
+
11
+ abort("Run omglog at the root of the git repo you'd like to watch.") if (ARGV & %w[-h --help help]).any?
12
+ abort("The current directory doesn't look like the root of a git repo.") unless File.directory?('.git')
13
+
14
+ if RUBY_PLATFORM[/darwin/i]
15
+ require 'osx'
16
+ Romglog.run_on Omglog::OSX
17
+ elsif RUBY_PLATFORM[/linux/i]
18
+ require 'linux'
19
+ Romglog.run_on Omglog::Linux
20
+ else
21
+ abort("Sorry, your system isn't supported yet. It just needs notification support -- i.e. fsevents on OS X, or inotify on Linux.")
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'rb-inotify'
2
+
3
+ module Omglog
4
+ class Linux
5
+ def self.on_change &block
6
+ INotify::Notifier.new.tap do |notifier|
7
+ notifier.watch('.git', :modify, :recursive, &block)
8
+ ['TERM', 'INT', 'QUIT'].each do |signal|
9
+ trap(signal) do
10
+ notifier.stop
11
+ exit(0)
12
+ end
13
+ end
14
+ notifier.run
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,72 @@
1
+ # coding: utf-8
2
+
3
+ module Omglog
4
+ VERSION = '0.0.8'
5
+
6
+ def run_on system
7
+ Omglog::Base.run
8
+ on_terminal_resize { Omglog::Base.run }
9
+ system.on_change { Omglog::Base.run }
10
+ end
11
+ module_function :run_on
12
+
13
+ def on_terminal_resize &block
14
+ rendering = true
15
+ trap("WINCH") {
16
+ # A dragging resize fires lots of WINCH events; this throttles the redraw
17
+ # and should cause it to (usually) line up with the final dimensions.
18
+ if rendering
19
+ rendering = false
20
+ sleep 0.5
21
+ rendering = true
22
+ yield
23
+ end
24
+ }
25
+ end
26
+ module_function :on_terminal_resize
27
+
28
+ class Base
29
+ CLEAR = "\n----\n"
30
+ GREEN, YELLOW, BLUE, GREY, HIGHLIGHT = '0;32', '0;33', '0;34', '0;90', '1;30;47'
31
+ SHORTEST_MESSAGE = 12
32
+ LOG_CMD = %{git log --all --date-order --graph --color --pretty="format: \2%h\3\2%d\3\2 %an, %ar\3\2 %s\3"}
33
+ LOG_REGEX = /(.*)\u0002(.*)\u0003\u0002(.*)\u0003\u0002(.*)\u0003\u0002(.*)\u0003/
34
+
35
+ def self.log_cmd
36
+ @log_cmd ||= [LOG_CMD].concat(ARGV).join(' ')
37
+ end
38
+
39
+ def self.run
40
+ rows, cols = `tput lines; tput cols`.scan(/\d+/).map(&:to_i)
41
+ `#{log_cmd} -#{rows}`.tap {|log|
42
+ log_lines = Array.new(rows, '')
43
+ log_lines.unshift *log.split("\n")
44
+
45
+ print CLEAR + log_lines[0...(rows - 1)].map {|l|
46
+ commit = l.scan(LOG_REGEX).flatten.map(&:to_s)
47
+ commit.any? ? render_commit(commit, cols) : l
48
+ }.join("\n") + "\n" + "\e[#{GREY}mupdated #{Time.now.strftime("%a %H:%M:%S")}\e[m ".rjust(cols + 8)
49
+ }
50
+ end
51
+
52
+ def self.render_commit commit, cols
53
+ row_highlight = commit[2][/[^\/]HEAD\b/] ? HIGHLIGHT : YELLOW
54
+ [nil, row_highlight, GREEN, '', GREY].map {|c| "\e[#{c}m" if c }.zip(
55
+ arrange_commit(commit, cols)
56
+ ).join + "\e[m"
57
+ end
58
+
59
+ def self.arrange_commit commit, cols
60
+ commit[0].chomp!(' ')
61
+ commit[-2].sub!(/(\d+)\s(\w)[^\s]+ ago/, '\1\2 ago')
62
+ room = [cols - [commit[0].gsub(/\e\[[\d;]*m/, ''), commit[1..-2]].flatten.map(&:length).inject(&:+), SHORTEST_MESSAGE].max
63
+ commit.tap {|commit|
64
+ commit[-1, 0] = if commit[-1].length > room
65
+ commit.pop[0...(room - 1)] + '…'
66
+ else
67
+ commit.pop.ljust(room)
68
+ end
69
+ }
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,12 @@
1
+ require 'rb-fsevent'
2
+
3
+ module Omglog
4
+ class OSX
5
+ def self.on_change &block
6
+ FSEvent.new.tap {|fsevent|
7
+ fsevent.watch('.git', &block)
8
+ fsevent.run
9
+ }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+
3
+ module Romglog
4
+ VERSION = '0.0.8'
5
+
6
+ def run_on system
7
+ Romglog::Base.run
8
+ on_terminal_resize { Romglog::Base.run }
9
+ system.on_change { Romglog::Base.run }
10
+ end
11
+ module_function :run_on
12
+
13
+ def on_terminal_resize &block
14
+ rendering = true
15
+ trap("WINCH") {
16
+ # A dragging resize fires lots of WINCH events; this throttles the redraw
17
+ # and should cause it to (usually) line up with the final dimensions.
18
+ if rendering
19
+ rendering = false
20
+ sleep 0.5
21
+ rendering = true
22
+ yield
23
+ end
24
+ }
25
+ end
26
+ module_function :on_terminal_resize
27
+
28
+ class Base
29
+ CLEAR = "\n----\n"
30
+ YELLOW, BLUE, GREY, HIGHLIGHT = '0;33', '0;34', '0;90', '1;30;47'
31
+ CMD = %{git reflog}
32
+
33
+ def self.log_cmd
34
+ @log_cmd ||= [CMD].concat(ARGV).join(' ')
35
+ end
36
+
37
+ def self.run
38
+ rows, cols = `tput lines; tput cols`.scan(/\d+/).map(&:to_i)
39
+ `#{log_cmd}`.tap {|log|
40
+ log_lines = Array.new(rows, '')
41
+ log_lines.unshift(*log.split("\n"))
42
+
43
+ print CLEAR + log_lines[0...(rows - 1)].map {|l|
44
+ render_line(l)
45
+ }.join("\n") + "\n" + "\e[#{GREY}mupdated #{Time.now.strftime("%a %H:%M:%S")}\e[m ".rjust(cols + 8)
46
+ }
47
+ end
48
+
49
+ def self.render_line line
50
+ cols = line.split(' ')
51
+ (["\e[#{YELLOW}m#{cols.shift}\e[m"] + cols).join(' ')
52
+ end
53
+
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: romglog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Huiming Teo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rb-fsevent
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rb-inotify
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.8.8
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.8.8
46
+ description: Realtime git log + reflog using fseventsd based on benhoskings's omglog.
47
+ omg! :)
48
+ email: teohuiming@gmail.com
49
+ executables:
50
+ - omglog
51
+ - romglog
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - bin/omglog
56
+ - bin/romglog
57
+ - lib/linux.rb
58
+ - lib/omglog.rb
59
+ - lib/osx.rb
60
+ - lib/romglog.rb
61
+ homepage: http://github.com/teohm/romglog
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.24
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Realtime git log + reflog using fseventsd based on benhoskings's omglog.
85
+ test_files: []
86
+ has_rdoc: