chronicle-shell 0.2.0 → 0.2.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd121be7bcf453873b98d815bd22b5ef2a685b2e5752d88982ab435ded4e9a1d
|
4
|
+
data.tar.gz: f175ee27114f9b02344387e06a19122f400c37291e67721ad7aecfb32dc77016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
8
|
+
- `shell:history` - Extract shell history from bash or zsh
|
8
9
|
|
9
10
|
### Transformers
|
10
|
-
- `shell
|
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
|
18
|
+
chronicle-etl plugins:install shell
|
17
19
|
|
18
|
-
|
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
|
```
|
data/chronicle-shell.gemspec
CHANGED
@@ -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 = '
|
9
|
+
r.identifier = 'history'
|
10
10
|
end
|
11
11
|
|
12
|
-
setting :
|
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
|
-
|
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
|
-
|
82
|
-
File.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
command = { timestamp: timestamp, command:
|
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
|
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.
|
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-
|
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.
|
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.
|
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.
|
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: []
|