chronicle-shell 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb256c224fc5da05d9a0cdcdb9d4efd15156f9194783088e110fd5213549dc55
4
- data.tar.gz: 1f1f7415835c37376b46ac436f431cb48081bf669440afb58617e41a5a5f27fa
3
+ metadata.gz: f707745dee11d1c8fa3d5f2f4216fbb5690d84686a1b71bf9fa260ba81ef5405
4
+ data.tar.gz: 843417530290463b87a23b6f6994118af7d80ceda5ba17dd5ce5fd98c1ae002a
5
5
  SHA512:
6
- metadata.gz: 94112b98f9536c38fdc9bd8de1900b119b92a400e82f93d38de594d12f8baed537081bb1dc07350afbf51fc6a187fa1097f8d82f39adc5ad64067487a994aca7
7
- data.tar.gz: c813a082d7d2e36f0c4091cd875d3b9be5d262b39ddf249e011f6ac68fcc3aea05e7d73d1855d0d71565cf5e1b7d20c53e6c03d213f01637a684b9a1d1254121
6
+ metadata.gz: d0ebd51e400c50f0d726d58078c078501a5ec3a6dddbf483437061565dd43a84ba1f9a3a759d7b46c91705d287aa2a3f68510f3870d4685d97573ff6c68891c0
7
+ data.tar.gz: defa5005faf851c6d674c45c89cb60e71a56ca2e7daa903fda172034dcae1dc93280bf471c4dbebbb622b06c22a298c9fb8c0bc81463a4ff1296588a931ae285
data/README.md CHANGED
@@ -1,39 +1,19 @@
1
1
  # Chronicle::Shell
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chronicle/shell`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Shell importer for [chronicle-etl](https://github.com/chronicle-app/chronicle-etl)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Available Connectors
6
+ ### Extractors
7
+ - `shell-history` - Extract shell history from bash or zsh
6
8
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'chronicle-shell'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install chronicle-shell
9
+ ### Transformers
10
+ - `shell-history` - Process a shell command
22
11
 
23
12
  ## Usage
24
13
 
25
- TODO: Write usage instructions here
14
+ ```bash
15
+ gem install chronicle-etl
16
+ chronicle-etl connectors:install shell
26
17
 
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/chronicle-shell. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/chronicle-shell/blob/main/CODE_OF_CONDUCT.md).
36
-
37
- ## Code of Conduct
38
-
39
- Everyone interacting in the Chronicle::Shell project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/chronicle-shell/blob/main/CODE_OF_CONDUCT.md).
18
+ chronicle-etl --extractor shell-history --since "2022-02-07" --transformer shell-history --loader table
19
+ ```
@@ -31,5 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_dependency "chronicle-etl", "~> 0.3.0"
34
+ spec.add_dependency "chronicle-etl", "~> 0.4.0"
35
35
  end
@@ -1,5 +1,4 @@
1
1
  require 'chronicle/etl'
2
- require 'tty-command'
3
2
 
4
3
  module Chronicle
5
4
  module Shell
@@ -10,13 +9,12 @@ module Chronicle
10
9
  r.identifier = 'shell-history'
11
10
  end
12
11
 
12
+ setting :filename, default: ENV['HISTFILE']
13
+ setting :shell, default: 'bash'
14
+
13
15
  BASH_TIMESTAMP_REGEX = /^\#(?<timestamp>[0-9]{10})/
14
16
 
15
17
  def prepare
16
- # TODO: determine if we're working with bash or zsh
17
- @shell_name = 'bash'
18
-
19
- @filename = history_filename
20
18
  @commands = load_commands
21
19
  end
22
20
 
@@ -29,7 +27,7 @@ module Chronicle
29
27
  meta = {
30
28
  username: username,
31
29
  hostname: hostname,
32
- shell_name: @shell_name
30
+ shell_name: @config.shell
33
31
  }
34
32
  yield Chronicle::ETL::Extraction.new(data: command, meta: meta)
35
33
  end
@@ -37,10 +35,19 @@ module Chronicle
37
35
 
38
36
  private
39
37
 
38
+ # TODO: modularize the shell-specific stuff
40
39
  def history_filename
40
+ @config.filename || __send__("history_filename_default_#{@config.shell}")
41
+ end
42
+
43
+ def history_filename_default_bash
41
44
  File.join(Dir.home, ".bash_history")
42
45
  end
43
46
 
47
+ def history_filename_default_zsh
48
+ File.join(Dir.home, ".zsh_history")
49
+ end
50
+
44
51
  def username
45
52
  @username ||= Etc.getlogin
46
53
  end
@@ -55,10 +62,10 @@ module Chronicle
55
62
  def load_commands
56
63
  commands = []
57
64
 
58
- loader = "load_commands_from_#{@shell_name}"
59
- send(loader) do |command|
60
- next if @options[:load_since] && command[:timestamp] < @options[:load_since]
61
- next if @options[:load_until] && command[:timestamp] > @options[:load_until]
65
+ loader = "load_commands_from_#{@config.shell}"
66
+ __send__(loader) do |command|
67
+ next if @config.since && command[:timestamp] < @config.since
68
+ next if @config.until && command[:timestamp] > @config.until
62
69
 
63
70
  if block_given?
64
71
  yield command
@@ -72,7 +79,7 @@ module Chronicle
72
79
 
73
80
  def load_commands_from_bash
74
81
  timestamp = nil
75
- File.foreach(@filename) do |line|
82
+ File.foreach(history_filename) do |line|
76
83
  if match = line.scrub.match(BASH_TIMESTAMP_REGEX)
77
84
  timestamp = Time.at(match[:timestamp].to_i)
78
85
  elsif timestamp
@@ -84,6 +91,7 @@ module Chronicle
84
91
 
85
92
  def load_commands_from_zsh
86
93
  # TODO: implement this
94
+ raise NotImplementedError
87
95
  end
88
96
  end
89
97
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Chronicle
4
4
  module Shell
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chronicle-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Louis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronicle-etl
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.0
19
+ version: 0.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.0
26
+ version: 0.4.0
27
27
  description: Extract shell command history from Bash or Zsh
28
28
  email:
29
29
  - andrew@hyfen.net
@@ -33,7 +33,6 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - CODE_OF_CONDUCT.md
35
35
  - Gemfile
36
- - Gemfile.lock
37
36
  - LICENSE.txt
38
37
  - README.md
39
38
  - Rakefile
@@ -65,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
64
  - !ruby/object:Gem::Version
66
65
  version: '0'
67
66
  requirements: []
68
- rubygems_version: 3.1.2
67
+ rubygems_version: 3.1.6
69
68
  signing_key:
70
69
  specification_version: 4
71
70
  summary: Shell connectors for Chronicle-ETL
data/Gemfile.lock DELETED
@@ -1,84 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- chronicle-shell (0.1.0)
5
- chronicle-etl (~> 0.3.0)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (7.0.2)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 1.6, < 2)
13
- minitest (>= 5.1)
14
- tzinfo (~> 2.0)
15
- chronic_duration (0.10.6)
16
- numerizer (~> 0.1.1)
17
- chronicle-etl (0.3.0)
18
- activesupport
19
- chronic_duration (~> 0.10.6)
20
- colorize (~> 0.8.1)
21
- marcel (~> 1.0.2)
22
- mini_exiftool (~> 2.10)
23
- nokogiri (~> 1.13)
24
- runcom (~> 6.2)
25
- sequel (~> 5.35)
26
- sqlite3 (~> 1.4)
27
- thor (~> 0.20)
28
- tty-progressbar (~> 0.17)
29
- tty-table (~> 0.11)
30
- colorize (0.8.1)
31
- concurrent-ruby (1.1.9)
32
- i18n (1.9.1)
33
- concurrent-ruby (~> 1.0)
34
- marcel (1.0.2)
35
- mini_exiftool (2.10.2)
36
- mini_portile2 (2.7.1)
37
- minitest (5.15.0)
38
- nokogiri (1.13.1)
39
- mini_portile2 (~> 2.7.0)
40
- racc (~> 1.4)
41
- numerizer (0.1.1)
42
- pastel (0.8.0)
43
- tty-color (~> 0.5)
44
- racc (1.6.0)
45
- rake (13.0.6)
46
- refinements (7.18.0)
47
- runcom (6.6.0)
48
- refinements (~> 7.16)
49
- xdg (~> 4.4)
50
- sequel (5.53.0)
51
- sqlite3 (1.4.2)
52
- strings (0.2.1)
53
- strings-ansi (~> 0.2)
54
- unicode-display_width (>= 1.5, < 3.0)
55
- unicode_utils (~> 1.4)
56
- strings-ansi (0.2.0)
57
- thor (0.20.3)
58
- tty-color (0.6.0)
59
- tty-cursor (0.7.1)
60
- tty-progressbar (0.18.2)
61
- strings-ansi (~> 0.2)
62
- tty-cursor (~> 0.7)
63
- tty-screen (~> 0.8)
64
- unicode-display_width (>= 1.6, < 3.0)
65
- tty-screen (0.8.1)
66
- tty-table (0.12.0)
67
- pastel (~> 0.8)
68
- strings (~> 0.2.0)
69
- tty-screen (~> 0.8)
70
- tzinfo (2.0.4)
71
- concurrent-ruby (~> 1.0)
72
- unicode-display_width (2.1.0)
73
- unicode_utils (1.4.0)
74
- xdg (4.5.0)
75
-
76
- PLATFORMS
77
- -darwin-20
78
-
79
- DEPENDENCIES
80
- chronicle-shell!
81
- rake (~> 13.0)
82
-
83
- BUNDLED WITH
84
- 2.3.6