cani 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -3
- data/lib/cani.rb +23 -9
- data/lib/cani/completions.rb +49 -33
- data/lib/cani/config.rb +27 -9
- data/lib/cani/fzf.rb +5 -1
- data/lib/cani/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1779bf69b0e5700933653fecb00fc5d01afa4356fdb9b0f6e3c33dee79e83b40
|
4
|
+
data.tar.gz: 54b9a94174250fc18a2593c05a474f3fa15e1f106f9146dd2fcb91373733a10f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d4bb3348016465616eaea9463e5f34a1f67b2f53bbd4ceba9c0395641c28f5de9144051af7e319986b7f712f3a84782ef218460911bbcd0a494987bf1f326f
|
7
|
+
data.tar.gz: 4f75d70a8ad7ca34887baadbf2ee1273d452aa3b63c945c1c687c5c35ff000576347e026d8af9763c82e011f682244541684ca5d7ec0f1a633933719314b8f69
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Cani — a [caniuse.com](caniuse.com) tui interface ![Licence](https://img.shields.io/badge/license-MIT-E9573F.svg) [![Gem Version](https://img.shields.io/gem/v/cani.svg?colorB=E9573F&style=square)](rubygems.org/gems/cani) [![Issues](https://img.shields.io/github/issues/SidOfc/cani.svg)](https://github.com/SidOfc/cani/issues)
|
1
|
+
# Cani — a [caniuse.com](caniuse.com) tui interface ![Licence](https://img.shields.io/badge/license-MIT-E9573F.svg) [![Gem Version](https://img.shields.io/gem/v/cani.svg?colorB=E9573F&style=square)](https://rubygems.org/gems/cani) [![Issues](https://img.shields.io/github/issues/SidOfc/cani.svg)](https://github.com/SidOfc/cani/issues)
|
2
2
|
|
3
3
|
![cani cli](/assets/cani.png)
|
4
4
|
|
@@ -34,7 +34,7 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
**dependencies**
|
36
36
|
|
37
|
-
Cani depends on [fzf](https://github.com/junegunn/fzf) to display most menu's.
|
37
|
+
Cani depends on [fzf](https://github.com/junegunn/fzf) to display most menu's and Curses for displaying the feature support table.
|
38
38
|
<!-- Fzf is not a requirement when piping the output to another command -->
|
39
39
|
|
40
40
|
## Configuration
|
@@ -47,11 +47,16 @@ After installation, running the command (`cani`) for the first time will create
|
|
47
47
|
- `~/.config/cani/completions/_cani.zsh` - zsh completion
|
48
48
|
- `~/.config/fish/completions/cani.fish` - fish completions
|
49
49
|
|
50
|
-
|
50
|
+
**Existing shell configuration files will also be modified by default:**
|
51
51
|
|
52
52
|
- `~/.bashrc` - A source line to bash completions will be added, or updated if it exists
|
53
53
|
- `~/.zshrc` - A source line to zsh completions will be added, or updated if it exists
|
54
54
|
|
55
|
+
This behavior can be permanently disabled at any time by adding the `--no-modify`
|
56
|
+
[option](#options) at the end of the `cani` command. A built-in command is provided to print
|
57
|
+
the completion paths for each shell: [`cani completion_paths`](#completion_paths). This allows
|
58
|
+
you to add the path manually.
|
59
|
+
|
55
60
|
After running the command for the first time, please restart your shell or `source` your `~/.*rc` file to load completions.
|
56
61
|
There are some commented settings that can be adjusted in the `~/.config/cani/config.yml` file.
|
57
62
|
|
@@ -66,9 +71,17 @@ Cani supports the following actions:
|
|
66
71
|
- [`version`](#version) - print the version number
|
67
72
|
- [`update`](#update) - force update data and completions
|
68
73
|
- [`install_completions`](#install_completions) - install shell completions
|
74
|
+
- [`completion_paths`](#completion_paths) - prints paths to shell completion files (for sourcing)
|
69
75
|
- [`purge`](#purge) - purge files and directories created by `cani`
|
70
76
|
- [`edit`](#edit) - edit the default configuration file with `$EDITOR`
|
71
77
|
|
78
|
+
## Options
|
79
|
+
|
80
|
+
`cani` supports the following command line flags / options:
|
81
|
+
|
82
|
+
- `--no-modify` - permanently disable automatic addition / deletion of shell config files.
|
83
|
+
- `--modify` - permanently enable automatic addition / deletion of shell config files.
|
84
|
+
|
72
85
|
### use
|
73
86
|
|
74
87
|
```sh
|
@@ -157,6 +170,20 @@ Completions are supported for `zsh`, `bash` and `fish` shells (currently).
|
|
157
170
|
They are automatically installed upon first invocation of the `cani` command.
|
158
171
|
This command is only a fallback in case there were any issues with permissions etc..
|
159
172
|
|
173
|
+
### completion_paths
|
174
|
+
|
175
|
+
When `--no-modify` is applied the completion paths are no longer automatically inserted
|
176
|
+
in your shell configuration files. In order to figure out where the files you need to
|
177
|
+
source are located, you can run this command. It will output something like this:
|
178
|
+
|
179
|
+
```plain
|
180
|
+
fish: /home/sidofc/.config/fish/completions/cani.fish
|
181
|
+
bash: /home/sidofc/.config/cani/completions/_cani.bash
|
182
|
+
zsh: /home/sidofc/.config/cani/completions/_cani.zsh
|
183
|
+
```
|
184
|
+
|
185
|
+
The fish completions are autoloaded and do not need to be sourced manually.
|
186
|
+
|
160
187
|
### purge
|
161
188
|
|
162
189
|
```sh
|
data/lib/cani.rb
CHANGED
@@ -23,8 +23,10 @@ module Cani
|
|
23
23
|
@settings ||= Config.new
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.exec!(command, *args_and_options)
|
27
|
+
return config if command.start_with? '-'
|
26
28
|
|
27
|
-
|
29
|
+
args = args_and_options.reject { |arg| arg.start_with? '-' }
|
28
30
|
command = :help unless command && respond_to?(command)
|
29
31
|
command = command.to_s.downcase.to_sym
|
30
32
|
|
@@ -35,7 +37,8 @@ module Cani
|
|
35
37
|
use args[0]
|
36
38
|
when :show
|
37
39
|
show args[0], args[1]
|
38
|
-
when :update, :purge, :help, :version,
|
40
|
+
when :update, :purge, :help, :version,
|
41
|
+
:install_completions, :completion_paths
|
39
42
|
send command
|
40
43
|
else
|
41
44
|
help
|
@@ -52,20 +55,23 @@ module Cani
|
|
52
55
|
puts 'in the \'use\' overview or calling \'use some-feature\' will display a'.light_black
|
53
56
|
puts 'table as seen on caniuse.com using curses.'.light_black
|
54
57
|
puts ''
|
55
|
-
puts 'cani is dependent on fzf (https://github.com/junegunn/fzf)
|
56
|
-
puts '
|
58
|
+
puts 'cani is dependent on fzf (https://github.com/junegunn/fzf)'.light_black
|
59
|
+
puts 'for the interactive TUI to work. Without fzf,'.light_black
|
60
|
+
puts 'commands can still be piped to get the regular (colorless) output.'.light_black
|
57
61
|
puts ''
|
58
|
-
puts 'Cani requires at least 20 lines and 40 cols to work properly,
|
59
|
-
puts 'below this width
|
62
|
+
puts 'Cani requires at least 20 lines and 40 cols to work properly,'.light_black
|
63
|
+
puts 'this is not a hard limit but below this width long lines could wrap'.light_black
|
64
|
+
puts 'a lot and significantly reduce visible information.'.light_black
|
60
65
|
puts ''
|
61
66
|
puts 'Usage:'.red
|
62
|
-
puts ' cani'.yellow + ' [COMMAND [ARGUMENTS]]'
|
67
|
+
puts ' cani'.yellow + ' [COMMAND [ARGUMENTS] [OPTIONS]]'
|
63
68
|
puts ''
|
64
69
|
puts 'Commands:'.red
|
65
70
|
puts ' use '.blue + ' [FEATURE] ' + 'show browser support for FEATURE'.light_black
|
66
71
|
puts ' show'.blue + ' [BROWSER [VERSION]] ' + 'show information about specific BROWSER and VERSION'.light_black
|
67
72
|
puts ' '
|
68
73
|
puts ' install_completions '.blue + 'installs completions for bash, zsh and fish'.light_black
|
74
|
+
puts ' completion_paths '.blue + 'prints completion paths that must be sourced in your shell configuration files'.light_black
|
69
75
|
puts ' update '.blue + 'force update api data and completions'.light_black
|
70
76
|
puts ' edit '.blue + 'edit configuration in $EDITOR'.light_black
|
71
77
|
puts ' purge '.blue + 'remove all completion, configuration and data'.light_black
|
@@ -74,6 +80,10 @@ module Cani
|
|
74
80
|
puts ' help '.blue + 'show this help'.light_black
|
75
81
|
puts ' version '.blue + 'print the version number'.light_black
|
76
82
|
puts ''
|
83
|
+
puts 'Options:'.red
|
84
|
+
puts ' --[no-]modify '.white + 'permanently enable/disable automatic adding/removing'.light_black
|
85
|
+
puts ' '.white + 'of source lines in shell configuration files'.light_black
|
86
|
+
puts ''
|
77
87
|
puts 'Examples:'.red
|
78
88
|
puts ' cani'.yellow + ' use'.blue
|
79
89
|
puts ' cani'.yellow + ' use'.blue + ' \'box-shadow\''
|
@@ -95,8 +105,12 @@ module Cani
|
|
95
105
|
puts VERSION
|
96
106
|
end
|
97
107
|
|
108
|
+
def self.completion_paths
|
109
|
+
Completions.paths
|
110
|
+
end
|
111
|
+
|
98
112
|
def self.install_completions
|
99
|
-
Completions.install!
|
113
|
+
Completions.install! || exit(1)
|
100
114
|
end
|
101
115
|
|
102
116
|
def self.purge
|
@@ -106,7 +120,7 @@ module Cani
|
|
106
120
|
end
|
107
121
|
|
108
122
|
def self.update
|
109
|
-
api.update! &&
|
123
|
+
api.update! && install_completions unless api.updated?
|
110
124
|
end
|
111
125
|
|
112
126
|
def self.edit
|
data/lib/cani/completions.rb
CHANGED
@@ -7,14 +7,14 @@ module Cani
|
|
7
7
|
shw = Cani.api.browsers.reduce String.new do |acc, browser|
|
8
8
|
versions = browser.versions.reverse.join(' ')
|
9
9
|
acc +
|
10
|
-
|
11
|
-
|
10
|
+
"\ncomplete -f -c cani -n '__fish_cani_using_command show' -a '#{browser.abbr}' -d '#{browser.label}'" +
|
11
|
+
"\ncomplete -f -c cani -n '__fish_cani_showing_browser #{browser.abbr}' -a '#{versions}'"
|
12
12
|
end
|
13
13
|
|
14
14
|
use = Cani.api.features.reduce String.new do |acc, feature|
|
15
15
|
description = feature.title.size > 40 ? feature.title[0..28] + '..' : feature.title
|
16
16
|
acc +
|
17
|
-
|
17
|
+
"\ncomplete -f -c cani -n '__fish_cani_using_command use' -a '#{feature.name}' -d '#{description}'"
|
18
18
|
end
|
19
19
|
|
20
20
|
tpl + shw + "\n" + use
|
@@ -26,8 +26,8 @@ module Cani
|
|
26
26
|
indent = 10
|
27
27
|
versions = Cani.api.browsers.reduce String.new do |acc, browser|
|
28
28
|
acc + (' ' * (indent - 2)) + browser.abbr + ")\n" +
|
29
|
-
|
30
|
-
|
29
|
+
(' ' * indent) + "_arguments -C \"1: :(#{browser.versions.join(' ')})\"\n" +
|
30
|
+
(' ' * indent) + ";;\n"
|
31
31
|
end.strip
|
32
32
|
|
33
33
|
tpl.gsub('{{names}}', Cani.api.browsers.map(&:abbr).join(' '))
|
@@ -41,8 +41,8 @@ module Cani
|
|
41
41
|
indent = 10
|
42
42
|
versions = Cani.api.browsers.reduce String.new do |acc, browser|
|
43
43
|
acc + (' ' * (indent - 2)) + '"' + browser.abbr + "\")\n" +
|
44
|
-
|
45
|
-
|
44
|
+
(' ' * indent) + "COMPREPLY=($(compgen -W \"#{browser.versions.join(' ')}\" ${COMP_WORDS[COMP_CWORD]}))\n" +
|
45
|
+
(' ' * indent) + ";;\n"
|
46
46
|
end.strip
|
47
47
|
|
48
48
|
tpl.gsub('{{names}}', Cani.api.browsers.map(&:abbr).join(' '))
|
@@ -55,13 +55,8 @@ module Cani
|
|
55
55
|
FileUtils.mkdir_p Cani.config.fish_comp_dir
|
56
56
|
FileUtils.mkdir_p Cani.config.comp_dir
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
file << generate_fish
|
61
|
-
end
|
62
|
-
|
63
|
-
%w[bash zsh].each do |shell|
|
64
|
-
File.open File.join(Cani.config.comp_dir, "_cani.#{shell}"), 'w' do |file|
|
58
|
+
%w[bash zsh fish].each do |shell|
|
59
|
+
File.open completion_path(shell), 'w' do |file|
|
65
60
|
file << send("generate_#{shell}")
|
66
61
|
end
|
67
62
|
end
|
@@ -71,12 +66,8 @@ module Cani
|
|
71
66
|
end
|
72
67
|
|
73
68
|
def self.remove!
|
74
|
-
|
75
|
-
|
76
|
-
File.unlink fish_comp if File.exist? fish_comp
|
77
|
-
|
78
|
-
%w[bash zsh].each do |shell|
|
79
|
-
shell_comp = File.join Cani.config.comp_dir, "_cani.#{shell}"
|
69
|
+
%w[bash zsh fish].each do |shell|
|
70
|
+
shell_comp = completion_path shell
|
80
71
|
|
81
72
|
File.unlink shell_comp if File.exist? shell_comp
|
82
73
|
end
|
@@ -85,12 +76,36 @@ module Cani
|
|
85
76
|
delete_source_lines!
|
86
77
|
end
|
87
78
|
|
79
|
+
def self.paths
|
80
|
+
puts "fish: #{completion_path(:fish)}"
|
81
|
+
puts "bash: #{completion_path(:bash)}"
|
82
|
+
puts "zsh: #{completion_path(:zsh)}"
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.completion_path(shell)
|
86
|
+
return File.join Cani.config.fish_comp_dir, 'cani.fish' if shell == :fish
|
87
|
+
|
88
|
+
File.join Cani.config.comp_dir, "_cani.#{shell}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.compile_source_line(path)
|
92
|
+
return "test -e #{path}; and source #{path}" if path.end_with? '.fish'
|
93
|
+
|
94
|
+
"[ -f #{path} ] && source #{path}"
|
95
|
+
end
|
96
|
+
|
88
97
|
def self.delete_source_lines!
|
98
|
+
return unless Cani.config.modify_shell_configs
|
99
|
+
|
89
100
|
%w[bash zsh].each do |shell|
|
90
|
-
shellrc
|
101
|
+
shellrc = File.join Dir.home, ".#{shell}rc"
|
102
|
+
|
103
|
+
next unless File.exist? shellrc
|
104
|
+
|
91
105
|
lines = File.read(shellrc).split "\n"
|
92
|
-
comp_path =
|
93
|
-
|
106
|
+
comp_path = completion_path shell
|
107
|
+
comp_src = compile_source_line comp_path
|
108
|
+
rm_idx = lines.find_index { |l| l.match comp_src }
|
94
109
|
|
95
110
|
lines.delete_at rm_idx unless rm_idx.nil?
|
96
111
|
File.write shellrc, lines.join("\n")
|
@@ -98,18 +113,19 @@ module Cani
|
|
98
113
|
end
|
99
114
|
|
100
115
|
def self.insert_source_lines!
|
116
|
+
return unless Cani.config.modify_shell_configs
|
117
|
+
|
101
118
|
%w[bash zsh].each do |shell|
|
102
|
-
shellrc
|
119
|
+
shellrc = File.join Dir.home, ".#{shell}rc"
|
120
|
+
|
121
|
+
next unless File.exist? shellrc
|
122
|
+
|
103
123
|
lines = File.read(shellrc).split "\n"
|
104
|
-
comp_path =
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
lines
|
109
|
-
"#{lines[slidx][/^\s+/]}[ -f #{comp_path} ] && source #{comp_path}"
|
110
|
-
else
|
111
|
-
lines << "[ -f #{comp_path} ] && source #{comp_path}"
|
112
|
-
end
|
124
|
+
comp_path = completion_path shell
|
125
|
+
comp_src = compile_source_line comp_path
|
126
|
+
|
127
|
+
lines << comp_src \
|
128
|
+
unless lines.find_index { |l| l.match comp_src }
|
113
129
|
|
114
130
|
File.write shellrc, lines.join("\n")
|
115
131
|
end
|
data/lib/cani/config.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Cani
|
2
2
|
class Config
|
3
|
-
attr_reader :settings
|
4
|
-
|
5
|
-
FILE
|
6
|
-
DIRECTORY
|
7
|
-
COMP_DIR
|
8
|
-
FISH_DIR
|
9
|
-
FISH_COMP_DIR
|
10
|
-
|
3
|
+
attr_reader :settings, :modify_shell_configs
|
4
|
+
|
5
|
+
FILE = File.join(Dir.home, '.config', 'cani', 'config.yml').freeze
|
6
|
+
DIRECTORY = File.dirname(FILE).freeze
|
7
|
+
COMP_DIR = File.join(DIRECTORY, 'completions').freeze
|
8
|
+
FISH_DIR = File.join(Dir.home, '.config', 'fish').freeze
|
9
|
+
FISH_COMP_DIR = File.join(FISH_DIR, 'completions').freeze
|
10
|
+
NO_MODIFY_FILE = File.join(DIRECTORY, '.no-modify-shellrc').freeze
|
11
|
+
DEFAULTS = {
|
11
12
|
# data settings
|
12
13
|
'expire' => 86_400,
|
13
14
|
'source' => 'https://raw.githubusercontent.com/Fyrd/caniuse/master/data.json',
|
@@ -20,7 +21,16 @@ module Cani
|
|
20
21
|
}.freeze
|
21
22
|
|
22
23
|
def initialize(**opts)
|
23
|
-
|
24
|
+
no_modify_exists = File.exist? NO_MODIFY_FILE
|
25
|
+
@settings = DEFAULTS.merge opts
|
26
|
+
@modify_shell_configs =
|
27
|
+
if allow_shellrc_modification?
|
28
|
+
File.delete NO_MODIFY_FILE if no_modify_exists
|
29
|
+
true
|
30
|
+
elsif disallow_shellrc_modification?
|
31
|
+
FileUtils.touch NO_MODIFY_FILE unless no_modify_exists
|
32
|
+
false
|
33
|
+
end
|
24
34
|
|
25
35
|
if File.exist? file
|
26
36
|
if (yml = YAML.load_file(file))
|
@@ -31,6 +41,14 @@ module Cani
|
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
44
|
+
def disallow_shellrc_modification?
|
45
|
+
ARGV.include?('--no-modify') || File.exist?(NO_MODIFY_FILE)
|
46
|
+
end
|
47
|
+
|
48
|
+
def allow_shellrc_modification?
|
49
|
+
ARGV.include?('--modify') || !disallow_shellrc_modification?
|
50
|
+
end
|
51
|
+
|
34
52
|
def file
|
35
53
|
FILE
|
36
54
|
end
|
data/lib/cani/fzf.rb
CHANGED
@@ -13,7 +13,11 @@ module Cani
|
|
13
13
|
header = ohdr.is_a?(Array) ? [:cani, *ohdr].map { |v| v.to_s.downcase }.join(':')
|
14
14
|
: 'cani:' + ohdr.to_s
|
15
15
|
|
16
|
-
|
16
|
+
IO.popen("fzf --ansi --header=\"[#{header}]\" #{query}", 'r+') do |io|
|
17
|
+
io.write rows
|
18
|
+
io.close_write
|
19
|
+
io.read
|
20
|
+
end.split ' '
|
17
21
|
else
|
18
22
|
# when output of any initial command is being piped
|
19
23
|
# print results and exit this command.
|
data/lib/cani/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cani
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sidney Liebrand
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.7.6
|
164
|
+
rubygems_version: 3.0.3
|
166
165
|
signing_key:
|
167
166
|
specification_version: 4
|
168
167
|
summary: A simple caniuse CLI.
|