chronicle-shell 0.1.0 → 0.2.2

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: 2b88a844a7e429898c8cd9851e9326be1cb1a61cb7fb0598d44456519941d3b9
4
+ data.tar.gz: 51db09766b5dacf94e4cd92ea5531cdb6475e5afa4759d48acb7e3e8f224cc36
5
5
  SHA512:
6
- metadata.gz: 94112b98f9536c38fdc9bd8de1900b119b92a400e82f93d38de594d12f8baed537081bb1dc07350afbf51fc6a187fa1097f8d82f39adc5ad64067487a994aca7
7
- data.tar.gz: c813a082d7d2e36f0c4091cd875d3b9be5d262b39ddf249e011f6ac68fcc3aea05e7d73d1855d0d71565cf5e1b7d20c53e6c03d213f01637a684b9a1d1254121
6
+ metadata.gz: 0a4f39726fe053ad6b5341cc5bece31eafb52bfde210fc7cb601cf388b4f7d131d0828d656946f436c455632d9c4f688e3c933f2069fcd55aef7c3204804d9f1
7
+ data.tar.gz: e4941551b42d16d90ac55345395d7b7bfbd73873a05dde157d129f4add9b0f839a4e55bf90705cd048e3a1c91e261f34aaf346933ebcc948630caf07df179c37
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 plugins: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.3"
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
@@ -7,16 +6,15 @@ module Chronicle
7
6
  register_connector do |r|
8
7
  r.provider = 'shell'
9
8
  r.description = 'shell command history'
10
- r.identifier = 'shell-history'
9
+ r.identifier = 'history'
11
10
  end
12
11
 
12
+ setting :input
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,20 @@ module Chronicle
37
35
 
38
36
  private
39
37
 
38
+ # TODO: modularize the shell-specific stuff
40
39
  def history_filename
40
+ # Ideally we coudl just use ENV['HISTFILE] but it's not available outside of Bash
41
+ @config.input&.first || __send__("history_filename_default_#{@config.shell}")
42
+ end
43
+
44
+ def history_filename_default_bash
41
45
  File.join(Dir.home, ".bash_history")
42
46
  end
43
47
 
48
+ def history_filename_default_zsh
49
+ File.join(Dir.home, ".zsh_history")
50
+ end
51
+
44
52
  def username
45
53
  @username ||= Etc.getlogin
46
54
  end
@@ -55,10 +63,10 @@ module Chronicle
55
63
  def load_commands
56
64
  commands = []
57
65
 
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]
66
+ loader = "load_commands_from_#{@config.shell}"
67
+ __send__(loader) do |command|
68
+ next if @config.since && command[:timestamp] < @config.since
69
+ next if @config.until && command[:timestamp] > @config.until
62
70
 
63
71
  if block_given?
64
72
  yield command
@@ -67,23 +75,28 @@ module Chronicle
67
75
  end
68
76
  end
69
77
 
78
+ commands = commands.first(@config.limit) if @config.limit
79
+
70
80
  commands
71
81
  end
72
82
 
73
83
  def load_commands_from_bash
74
- timestamp = nil
75
- File.foreach(@filename) do |line|
76
- if match = line.scrub.match(BASH_TIMESTAMP_REGEX)
77
- timestamp = Time.at(match[:timestamp].to_i)
78
- elsif timestamp
79
- command = { timestamp: timestamp, command: line.scrub.strip }
84
+ command = nil
85
+ File.readlines(history_filename).reverse_each do |line|
86
+ timestamp_line = line.scrub.match(BASH_TIMESTAMP_REGEX)
87
+ if timestamp_line && command
88
+ timestamp = Time.at(timestamp_line[:timestamp].to_i)
89
+ command = { timestamp: timestamp, command: command }
80
90
  yield command
91
+ else
92
+ command = line.scrub.strip
81
93
  end
82
94
  end
83
95
  end
84
96
 
85
97
  def load_commands_from_zsh
86
98
  # TODO: implement this
99
+ raise NotImplementedError
87
100
  end
88
101
  end
89
102
  end
@@ -6,7 +6,7 @@ module Chronicle
6
6
  register_connector do |r|
7
7
  r.provider = 'shell'
8
8
  r.description = 'a shell command'
9
- r.identifier = 'shell-history'
9
+ r.identifier = 'history'
10
10
  end
11
11
 
12
12
  def transform
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Chronicle
4
4
  module Shell
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.2"
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.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Louis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-10 00:00:00.000000000 Z
11
+ date: 2022-03-16 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.3
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.3
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
@@ -50,7 +49,7 @@ metadata:
50
49
  homepage_uri: https://github.com/chronicle-app/chronicle-shell
51
50
  source_code_uri: https://github.com/chronicle-app/chronicle-shell
52
51
  changelog_uri: https://github.com/chronicle-app/chronicle-shell/releases
53
- post_install_message:
52
+ post_install_message:
54
53
  rdoc_options: []
55
54
  require_paths:
56
55
  - lib
@@ -65,8 +64,8 @@ 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
69
- signing_key:
67
+ rubygems_version: 3.3.3
68
+ signing_key:
70
69
  specification_version: 4
71
70
  summary: Shell connectors for Chronicle-ETL
72
71
  test_files: []
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