chronicle-shell 0.2.0 → 0.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f707745dee11d1c8fa3d5f2f4216fbb5690d84686a1b71bf9fa260ba81ef5405
4
- data.tar.gz: 843417530290463b87a23b6f6994118af7d80ceda5ba17dd5ce5fd98c1ae002a
3
+ metadata.gz: bd121be7bcf453873b98d815bd22b5ef2a685b2e5752d88982ab435ded4e9a1d
4
+ data.tar.gz: f175ee27114f9b02344387e06a19122f400c37291e67721ad7aecfb32dc77016
5
5
  SHA512:
6
- metadata.gz: d0ebd51e400c50f0d726d58078c078501a5ec3a6dddbf483437061565dd43a84ba1f9a3a759d7b46c91705d287aa2a3f68510f3870d4685d97573ff6c68891c0
7
- data.tar.gz: defa5005faf851c6d674c45c89cb60e71a56ca2e7daa903fda172034dcae1dc93280bf471c4dbebbb622b06c22a298c9fb8c0bc81463a4ff1296588a931ae285
6
+ metadata.gz: 4e652cbf303a7f5407d3d1bf67c688932836551760e5966a194ee75a2944957a958f3500e371cd116ad8050d798f8667fe24ad1eb01ad1425adf1d6716b909ab
7
+ data.tar.gz: 434efb8f969f5c28a6e49a89ab88a8193d9dd195365bd7be1d08d83b3cee1c3f8752c71b5e32604dd3bf5a15f49a0f485090d77b0832561f2d19219d0fa34d04
data/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  # Chronicle::Shell
2
+ [![Gem Version](https://badge.fury.io/rb/chronicle-shell.svg)](https://badge.fury.io/rb/chronicle-shell)
2
3
 
3
4
  Shell importer for [chronicle-etl](https://github.com/chronicle-app/chronicle-etl)
4
5
 
5
6
  ## Available Connectors
6
7
  ### Extractors
7
- - `shell-history` - Extract shell history from bash or zsh
8
+ - `shell:history` - Extract shell history from bash or zsh
8
9
 
9
10
  ### Transformers
10
- - `shell-history` - Process a shell command
11
+ - `shell:history` - Turn a shell command into Chronicle Schema
11
12
 
12
- ## Usage
13
+ ## Usage and examples
13
14
 
14
15
  ```bash
16
+ # install chronicle-etl and then this plugin
15
17
  gem install chronicle-etl
16
- chronicle-etl connectors:install shell
18
+ chronicle-etl plugins:install shell
17
19
 
18
- chronicle-etl --extractor shell-history --since "2022-02-07" --transformer shell-history --loader table
20
+ # output commands since Feb 7 as json
21
+ chronicle-etl --extractor shell:history --transformer shell:history --since "2022-02-07" --loader json
22
+
23
+ # Show recent commands sorted by frequency of use
24
+ chronicle-etl --extractor shell:history --limit 500 --fields command --silent | sort | uniq -c | sort -nr
19
25
  ```
@@ -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.4.0"
34
+ spec.add_dependency "chronicle-etl", "~> 0.4.3"
35
35
  end
@@ -6,10 +6,10 @@ module Chronicle
6
6
  register_connector do |r|
7
7
  r.provider = 'shell'
8
8
  r.description = 'shell command history'
9
- r.identifier = 'shell-history'
9
+ r.identifier = 'history'
10
10
  end
11
11
 
12
- setting :filename, default: ENV['HISTFILE']
12
+ setting :input
13
13
  setting :shell, default: 'bash'
14
14
 
15
15
  BASH_TIMESTAMP_REGEX = /^\#(?<timestamp>[0-9]{10})/
@@ -37,7 +37,8 @@ module Chronicle
37
37
 
38
38
  # TODO: modularize the shell-specific stuff
39
39
  def history_filename
40
- @config.filename || __send__("history_filename_default_#{@config.shell}")
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}")
41
42
  end
42
43
 
43
44
  def history_filename_default_bash
@@ -74,17 +75,21 @@ module Chronicle
74
75
  end
75
76
  end
76
77
 
78
+ commands = commands.first(@config.limit) if @config.limit
79
+
77
80
  commands
78
81
  end
79
82
 
80
83
  def load_commands_from_bash
81
- timestamp = nil
82
- File.foreach(history_filename) do |line|
83
- if match = line.scrub.match(BASH_TIMESTAMP_REGEX)
84
- timestamp = Time.at(match[:timestamp].to_i)
85
- elsif timestamp
86
- 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 }
87
90
  yield command
91
+ else
92
+ command = line.scrub.strip
88
93
  end
89
94
  end
90
95
  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.2.0"
5
+ VERSION = "0.2.3"
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.2.0
4
+ version: 0.2.3
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-26 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.4.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.4.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
@@ -49,7 +49,7 @@ metadata:
49
49
  homepage_uri: https://github.com/chronicle-app/chronicle-shell
50
50
  source_code_uri: https://github.com/chronicle-app/chronicle-shell
51
51
  changelog_uri: https://github.com/chronicle-app/chronicle-shell/releases
52
- post_install_message:
52
+ post_install_message:
53
53
  rdoc_options: []
54
54
  require_paths:
55
55
  - lib
@@ -64,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.1.6
68
- signing_key:
67
+ rubygems_version: 3.3.3
68
+ signing_key:
69
69
  specification_version: 4
70
70
  summary: Shell connectors for Chronicle-ETL
71
71
  test_files: []