chronicle-shell 0.2.1 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1f1e5fd44c4e21f27a1f0879096ebedc08dcb866ec62393b5935e348816c9a1
4
- data.tar.gz: d1fee6983b672b691f19bf1efb6fa10629cbc3b112205761da35e7f82e5e59ec
3
+ metadata.gz: 83dc9bab0e1b65930d8243a16ba6debe3d92cb4424b50e80d8511dc13dc6f3e4
4
+ data.tar.gz: 57d4a5d1f434dedacb3071c3f96ac211990f42b92b75db1416b852b3b5f93806
5
5
  SHA512:
6
- metadata.gz: 15d51d049d46e24bed446cb8ea03cf2faed69f362a974e828336c5e3449d0037e221c15941cbc417c9585ff0e01160f6fcac5765a494f62f0e3d2d0b7934c0c3
7
- data.tar.gz: ca9f88415679b7aa492a318e48885d1df401b98975c5f735bb36eb310494374d33b4e7cbdac06a06714c5161213ff5472796589bb225a96a40842d036f7dab9f
6
+ metadata.gz: de0dba35c9ea5e3612c52f2adcf543c4922485e69e44e650113a89cb03ad24737bf7a1a271cdb3febd409ab02a481ed1d436a9374fe50a181c634dc6d69c2b93
7
+ data.tar.gz: 5cbfef0e14a2d6e1ee7ffabdc99627ab5af6bad3d30368e082dad3057a701bc5dfef3da38e5ce7c8aadcf8689b35910060fe36486e060f1f7ffd358599a414c2
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
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.3"
34
+ spec.add_dependency "chronicle-etl", "~> 0.5"
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
@@ -80,13 +81,15 @@ module Chronicle
80
81
  end
81
82
 
82
83
  def load_commands_from_bash
83
- timestamp = nil
84
- File.foreach(history_filename) do |line|
85
- if match = line.scrub.match(BASH_TIMESTAMP_REGEX)
86
- timestamp = Time.at(match[:timestamp].to_i)
87
- elsif timestamp
88
- 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 }
89
90
  yield command
91
+ else
92
+ command = line.scrub.strip
90
93
  end
91
94
  end
92
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.1"
5
+ VERSION = "0.2.4"
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.1
4
+ version: 0.2.4
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-03-14 00:00:00.000000000 Z
11
+ date: 2022-03-25 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.3
19
+ version: '0.5'
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.3
26
+ version: '0.5'
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.3.9
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: []