omglog 0.0.3 → 0.0.4
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.
- data/lib/linux.rb +18 -0
- data/lib/omglog.rb +49 -0
- data/lib/osx.rb +12 -0
- metadata +8 -5
data/lib/linux.rb
ADDED
@@ -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
|
data/lib/omglog.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Omglog
|
4
|
+
VERSION = '0.0.3'
|
5
|
+
|
6
|
+
def run_on system
|
7
|
+
Omglog::Base.run
|
8
|
+
system.on_change { Omglog::Base.run }
|
9
|
+
end
|
10
|
+
module_function :run_on
|
11
|
+
|
12
|
+
class Base
|
13
|
+
CLEAR = "\n----\n"
|
14
|
+
YELLOW, BLUE, GREY, HIGHLIGHT = '0;33', '0;34', '0;90', '1;30;47'
|
15
|
+
SHORTEST_MESSAGE = 12
|
16
|
+
LOG_CMD = %{git log --all --date-order --graph --color --pretty="format: \2%h\3\2%d\3\2 %an, %ar\3\2 %s\3"}
|
17
|
+
LOG_REGEX = /(.*)\u0002(.*)\u0003\u0002(.*)\u0003\u0002(.*)\u0003\u0002(.*)\u0003/
|
18
|
+
|
19
|
+
def self.run
|
20
|
+
rows, cols = `tput lines; tput cols`.scan(/\d+/).map(&:to_i)
|
21
|
+
`#{LOG_CMD} -#{rows}`.tap {|log|
|
22
|
+
print CLEAR + log.split("\n")[0...(rows - 1)].map {|l|
|
23
|
+
commit = l.scan(LOG_REGEX).flatten.map(&:to_s)
|
24
|
+
commit.any? ? render_commit(commit, cols) : l
|
25
|
+
}.join("\n") + "\n" + "\e[#{GREY}mupdated #{Time.now.strftime("%a %H:%M:%S")}\e[m ".rjust(cols + 8)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.render_commit commit, cols
|
30
|
+
row_highlight = commit[2][/[^\/]HEAD\b/] ? HIGHLIGHT : YELLOW
|
31
|
+
[nil, row_highlight, BLUE, '', GREY].map {|c| "\e[#{c}m" if c }.zip(
|
32
|
+
arrange_commit(commit, cols)
|
33
|
+
).join + "\e[m"
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.arrange_commit commit, cols
|
37
|
+
commit[0].chomp!(' ')
|
38
|
+
commit[-2].sub!(/(\d+)\s(\w)[^\s]+ ago/, '\1\2 ago')
|
39
|
+
room = [cols - [commit[0].gsub(/\e\[[\d;]*m/, ''), commit[1..-2]].flatten.map(&:length).inject(&:+), SHORTEST_MESSAGE].max
|
40
|
+
commit.tap {|commit|
|
41
|
+
commit[-1, 0] = if commit[-1].length > room
|
42
|
+
commit.pop[0...(room - 1)] + '…'
|
43
|
+
else
|
44
|
+
commit.pop.ljust(room)
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/osx.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omglog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-03-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rb-fsevent
|
16
|
-
requirement: &
|
16
|
+
requirement: &70352988124480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.4.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70352988124480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rb-inotify
|
27
|
-
requirement: &
|
27
|
+
requirement: &70352988123920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70352988123920
|
36
36
|
description: Realtime git logging using fseventsd. omg!
|
37
37
|
email: ben@hoskings.net
|
38
38
|
executables:
|
@@ -41,6 +41,9 @@ extensions: []
|
|
41
41
|
extra_rdoc_files: []
|
42
42
|
files:
|
43
43
|
- bin/omglog
|
44
|
+
- lib/linux.rb
|
45
|
+
- lib/omglog.rb
|
46
|
+
- lib/osx.rb
|
44
47
|
homepage: http://github.com/benhoskings/omglog
|
45
48
|
licenses: []
|
46
49
|
post_install_message:
|