howzit 2.0.12 → 2.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +4 -1
- data/CHANGELOG.md +33 -0
- data/Rakefile +41 -0
- data/bin/howzit +4 -3
- data/docker/Dockerfile +11 -0
- data/docker/Dockerfile-2.6 +11 -0
- data/docker/Dockerfile-2.7 +11 -0
- data/docker/Dockerfile-3.0 +11 -0
- data/docker/bash_profile +13 -0
- data/docker/inputrc +57 -0
- data/howzit.gemspec +1 -0
- data/lib/howzit/buildnote.rb +19 -7
- data/lib/howzit/colors.rb +9 -0
- data/lib/howzit/config.rb +1 -0
- data/lib/howzit/prompt.rb +9 -3
- data/lib/howzit/task.rb +146 -0
- data/lib/howzit/topic.rb +4 -95
- data/lib/howzit/util.rb +3 -3
- data/lib/howzit/version.rb +1 -1
- data/lib/howzit.rb +12 -0
- data/scripts/runtests.sh +4 -0
- data/spec/task_spec.rb +6 -0
- metadata +22 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb673909d87ac094a2111c1f6fa364fb54183059267e009886562c89a81310d7
|
4
|
+
data.tar.gz: ec766bf5d2f3b3454a289f429e28c12f19545a79dfe6f10d29f0afb04abdc9b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5f2e3624bad256848b1c2d8a4bc95dcbbee5d8cf0e2c63efa79b139ca3a330ce773edb2e68375ea72158de0ce69ffaedd7673f36cbee5cd937c255ccaa3e5fe
|
7
|
+
data.tar.gz: f024cd0ffb6b41ab6184cf36ef65e644e90f5ab7e5c57b8a2c9cc1be404802f992f708464a3a2ab984122fddb4880ec704cda85dd371aeee735b417e15d942c2
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -4,10 +4,13 @@ sudo: required
|
|
4
4
|
dist: trusty
|
5
5
|
cache: bundler
|
6
6
|
rvm:
|
7
|
+
- ruby-2.6.4
|
7
8
|
- ruby-2.7.0
|
8
9
|
- ruby-3.0.1
|
9
10
|
install:
|
10
|
-
- gem uninstall bundler
|
11
11
|
- gem install bundler --version '2.2.29'
|
12
12
|
- bundle install
|
13
13
|
script: "bundle exec rspec spec --exclude-pattern 'cli*'"
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- main
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
### 2.0.15
|
2
|
+
|
3
|
+
2022-08-05 17:16
|
4
|
+
|
5
|
+
#### IMPROVED
|
6
|
+
|
7
|
+
- -R can take an argument to filter results
|
8
|
+
- Show a topic preview when using fzf to select from available topics
|
9
|
+
- Paginate help output
|
10
|
+
- Refactor Topic.run
|
11
|
+
|
12
|
+
#### FIXED
|
13
|
+
|
14
|
+
- Invalid options for more pager
|
15
|
+
- Error running grep command
|
16
|
+
- Show method not accepting paginate option
|
17
|
+
|
18
|
+
### 2.0.14
|
19
|
+
|
20
|
+
2022-08-05 13:24
|
21
|
+
|
22
|
+
#### FIXED
|
23
|
+
|
24
|
+
- Travis CI fixes
|
25
|
+
|
26
|
+
### 2.0.13
|
27
|
+
|
28
|
+
2022-08-05 13:19
|
29
|
+
|
30
|
+
#### IMPROVED
|
31
|
+
|
32
|
+
- Add tests for more ruby versions via Docker
|
33
|
+
|
1
34
|
### 2.0.12
|
2
35
|
|
3
36
|
2022-08-05 11:27
|
data/Rakefile
CHANGED
@@ -5,6 +5,7 @@ require 'bundler/gem_tasks'
|
|
5
5
|
require 'rspec/core/rake_task'
|
6
6
|
require 'rubocop/rake_task'
|
7
7
|
require 'yard'
|
8
|
+
require 'tty-spinner'
|
8
9
|
|
9
10
|
task default: %i[test yard]
|
10
11
|
|
@@ -34,3 +35,43 @@ desc 'Changelog version check'
|
|
34
35
|
task :cver do
|
35
36
|
puts IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).match(/^#+ (\d+\.\d+\.\d+(\w+)?)/)[1]
|
36
37
|
end
|
38
|
+
|
39
|
+
desc 'Run tests in Docker'
|
40
|
+
task :dockertest, :version, :login do |_, args|
|
41
|
+
args.with_defaults(version: 'all', login: false)
|
42
|
+
case args[:version]
|
43
|
+
when /^a/
|
44
|
+
%w[6 7 3].each do |v|
|
45
|
+
Rake::Task['dockertest'].reenable
|
46
|
+
Rake::Task['dockertest'].invoke(v, false)
|
47
|
+
end
|
48
|
+
Process.exit 0
|
49
|
+
when /^3/
|
50
|
+
img = 'howzittest3'
|
51
|
+
file = 'docker/Dockerfile-3.0'
|
52
|
+
when /6$/
|
53
|
+
img = 'howzittest26'
|
54
|
+
file = 'docker/Dockerfile-2.6'
|
55
|
+
when /(^2|7$)/
|
56
|
+
img = 'howzittest27'
|
57
|
+
file = 'docker/Dockerfile-2.7'
|
58
|
+
else
|
59
|
+
img = 'howzittest'
|
60
|
+
file = 'docker/Dockerfile'
|
61
|
+
end
|
62
|
+
|
63
|
+
puts `docker build . --file #{file} -t #{img}`
|
64
|
+
|
65
|
+
exec "docker run -v #{File.dirname(__FILE__)}:/howzit -it #{img} /bin/bash -l" if args[:login]
|
66
|
+
|
67
|
+
spinner = TTY::Spinner.new('[:spinner] Running tests ...', hide_cursor: true)
|
68
|
+
|
69
|
+
spinner.auto_spin
|
70
|
+
res = `docker run --rm -v #{File.dirname(__FILE__)}:/howzit -it #{img}`
|
71
|
+
# commit = puts `bash -c "docker commit $(docker ps -a|grep #{img}|awk '{print $1}'|head -n 1) #{img}"`.strip
|
72
|
+
spinner.success
|
73
|
+
spinner.stop
|
74
|
+
|
75
|
+
puts res
|
76
|
+
# puts commit&.empty? ? "Error commiting Docker tag #{img}" : "Committed Docker tag #{img}"
|
77
|
+
end
|
data/bin/howzit
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
$LOAD_PATH.unshift File.join(__dir__, '..', 'lib')
|
@@ -49,7 +49,8 @@ OptionParser.new do |opts|
|
|
49
49
|
Howzit.options[:list_topics] = true
|
50
50
|
end
|
51
51
|
|
52
|
-
opts.on('-R', '--list-runnable', 'List topics containing @ directives (verbose)') do
|
52
|
+
opts.on('-R', '--list-runnable [PATTERN]', 'List topics containing @ directives (verbose)') do |pat|
|
53
|
+
Howzit.options[:for_topic] = pat
|
53
54
|
Howzit.options[:list_runnable] = true
|
54
55
|
end
|
55
56
|
|
@@ -201,7 +202,7 @@ OptionParser.new do |opts|
|
|
201
202
|
opts.separator("\n Misc:\n\n") #=================================================================== MISC
|
202
203
|
|
203
204
|
opts.on('-h', '--help', 'Display this screen') do
|
204
|
-
|
205
|
+
Howzit::Util.page opts.to_s
|
205
206
|
Process.exit 0
|
206
207
|
end
|
207
208
|
|
data/docker/Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:3.0.1
|
2
|
+
# RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
3
|
+
RUN mkdir /howzit
|
4
|
+
WORKDIR /howzit
|
5
|
+
# COPY ./ /howzit/
|
6
|
+
RUN gem install bundler:2.2.17
|
7
|
+
RUN apt-get update -y
|
8
|
+
RUN apt-get install -y less vim
|
9
|
+
COPY ./docker/inputrc /root/.inputrc
|
10
|
+
COPY ./docker/bash_profile /root/.bash_profile
|
11
|
+
CMD ["scripts/runtests.sh"]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:2.6
|
2
|
+
# RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
3
|
+
RUN mkdir /howzit
|
4
|
+
WORKDIR /howzit
|
5
|
+
# COPY ./ /howzit/
|
6
|
+
RUN gem install bundler:2.2.17
|
7
|
+
RUN apt-get update -y
|
8
|
+
RUN apt-get install -y less vim
|
9
|
+
COPY ./docker/inputrc /root/.inputrc
|
10
|
+
COPY ./docker/bash_profile /root/.bash_profile
|
11
|
+
CMD ["scripts/runtests.sh"]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:2.7
|
2
|
+
# RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
3
|
+
RUN mkdir /howzit
|
4
|
+
WORKDIR /howzit
|
5
|
+
# COPY ./ /howzit/
|
6
|
+
RUN gem install bundler:2.2.17
|
7
|
+
RUN apt-get update -y
|
8
|
+
RUN apt-get install -y less vim
|
9
|
+
COPY ./docker/inputrc /root/.inputrc
|
10
|
+
COPY ./docker/bash_profile /root/.bash_profile
|
11
|
+
CMD ["scripts/runtests.sh"]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
FROM ruby:3.0.0
|
2
|
+
# RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
|
3
|
+
RUN mkdir /howzit
|
4
|
+
WORKDIR /howzit
|
5
|
+
# COPY ./ /howzit/
|
6
|
+
RUN gem install bundler:2.2.17
|
7
|
+
RUN apt-get update -y
|
8
|
+
RUN apt-get install -y less vim
|
9
|
+
COPY ./docker/inputrc /root/.inputrc
|
10
|
+
COPY ./docker/bash_profile /root/.bash_profile
|
11
|
+
CMD ["scripts/runtests.sh"]
|
data/docker/bash_profile
ADDED
data/docker/inputrc
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
"\e[3~": delete-char
|
2
|
+
"\ex": 'cd !$ \015ls\015'
|
3
|
+
"\ez": 'cd -\015'
|
4
|
+
"\e\C-m": '\C-a "$(\C-e|fzf)"\C-a'
|
5
|
+
"\e/": '"$(!!|fzf)"\C-a \C-m\C-m'
|
6
|
+
# these allow you to use alt+left/right arrow keys
|
7
|
+
# to jump the cursor over words
|
8
|
+
"\e[1;5C": forward-word
|
9
|
+
"\e[1;5D": backward-word
|
10
|
+
# "\e[D": backward-word
|
11
|
+
# "\e[C": forward-word
|
12
|
+
"\ea": menu-complete
|
13
|
+
# TAB: menu-complete
|
14
|
+
# "\e[Z": "\e-1\C-i"
|
15
|
+
|
16
|
+
"\e\C-l": history-and-alias-expand-line
|
17
|
+
|
18
|
+
# these allow you to start typing a command and
|
19
|
+
# use the up/down arrow to auto complete from
|
20
|
+
# commands in your history
|
21
|
+
"\e[B": history-search-forward
|
22
|
+
"\e[A": history-search-backward
|
23
|
+
"\ew": history-search-backward
|
24
|
+
"\es": history-search-forward
|
25
|
+
# this lets you hit tab to auto-complete a file or
|
26
|
+
# directory name ignoring case
|
27
|
+
set completion-ignore-case On
|
28
|
+
set mark-symlinked-directories On
|
29
|
+
set completion-prefix-display-length 2
|
30
|
+
set bell-style none
|
31
|
+
# set bell-style visible
|
32
|
+
set meta-flag on
|
33
|
+
set convert-meta off
|
34
|
+
set input-meta on
|
35
|
+
set output-meta on
|
36
|
+
set show-all-if-ambiguous on
|
37
|
+
set show-all-if-unmodified on
|
38
|
+
set completion-map-case on
|
39
|
+
set visible-stats on
|
40
|
+
|
41
|
+
# Do history expansion when space entered?
|
42
|
+
$if bash
|
43
|
+
Space: magic-space
|
44
|
+
$endif
|
45
|
+
|
46
|
+
# Show extra file information when completing, like `ls -F` does
|
47
|
+
set visible-stats on
|
48
|
+
|
49
|
+
# Be more intelligent when autocompleting by also looking at the text after
|
50
|
+
# the cursor. For example, when the current line is "cd ~/src/mozil", and
|
51
|
+
# the cursor is on the "z", pressing Tab will not autocomplete it to "cd
|
52
|
+
# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the
|
53
|
+
# Readline used by Bash 4.)
|
54
|
+
set skip-completed-text on
|
55
|
+
|
56
|
+
# Use Alt/Meta + Delete to delete the preceding word
|
57
|
+
"\e[3;3~": kill-word
|
data/howzit.gemspec
CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency 'yard', '~> 0.9.5'
|
39
39
|
spec.add_development_dependency 'redcarpet', '~> 3.2'
|
40
40
|
spec.add_development_dependency 'github-markup', '~> 1.3'
|
41
|
+
spec.add_development_dependency 'tty-spinner', '~> 0.9'
|
41
42
|
|
42
43
|
spec.add_runtime_dependency 'mdless', '~> 1.0', '>= 1.0.28'
|
43
44
|
spec.add_runtime_dependency 'tty-screen', '~> 0.8'
|
data/lib/howzit/buildnote.rb
CHANGED
@@ -32,6 +32,11 @@ module Howzit
|
|
32
32
|
read_help(file)
|
33
33
|
end
|
34
34
|
|
35
|
+
##
|
36
|
+
## Inspect
|
37
|
+
##
|
38
|
+
## @return description
|
39
|
+
##
|
35
40
|
def inspect
|
36
41
|
puts "#<Howzit::BuildNote @topics=[#{@topics.count}]>"
|
37
42
|
end
|
@@ -55,7 +60,8 @@ module Howzit
|
|
55
60
|
##
|
56
61
|
## @param term [String] The search term
|
57
62
|
##
|
58
|
-
def find_topic(term)
|
63
|
+
def find_topic(term = nil)
|
64
|
+
return @topics if term.nil?
|
59
65
|
@topics.filter do |topic|
|
60
66
|
rx = term.to_rx
|
61
67
|
topic.title.downcase =~ rx
|
@@ -127,7 +133,8 @@ module Howzit
|
|
127
133
|
def list_runnable
|
128
134
|
output = []
|
129
135
|
output.push(%({bg}"Runnable" Topics:{x}\n).c)
|
130
|
-
|
136
|
+
|
137
|
+
find_topic(Howzit.options[:for_topic]).each do |topic|
|
131
138
|
s_out = []
|
132
139
|
|
133
140
|
topic.tasks.each do |task|
|
@@ -243,6 +250,11 @@ module Howzit
|
|
243
250
|
Process.exit 0
|
244
251
|
end
|
245
252
|
|
253
|
+
##
|
254
|
+
## Accessor method for note_file (path to located build note)
|
255
|
+
##
|
256
|
+
## @return [String] path
|
257
|
+
##
|
246
258
|
def note_file
|
247
259
|
@note_file ||= find_note_file
|
248
260
|
end
|
@@ -581,7 +593,7 @@ module Howzit
|
|
581
593
|
ARGV.length.times do
|
582
594
|
ARGV.shift
|
583
595
|
end
|
584
|
-
res = yn("No build notes file found, create one?",
|
596
|
+
res = yn("No build notes file found, create one?", false)
|
585
597
|
create_note if res
|
586
598
|
Process.exit 1
|
587
599
|
end
|
@@ -620,15 +632,15 @@ module Howzit
|
|
620
632
|
|
621
633
|
topic_matches = []
|
622
634
|
if Howzit.options[:grep]
|
623
|
-
matches =
|
635
|
+
matches = grep(Howzit.options[:grep])
|
624
636
|
case Howzit.options[:multiple_matches]
|
625
637
|
when :all
|
626
|
-
topic_matches.concat(matches.
|
638
|
+
topic_matches.concat(matches.sort_by(&:title))
|
627
639
|
else
|
628
|
-
topic_matches.concat(Prompt.choose(matches))
|
640
|
+
topic_matches.concat(Prompt.choose(matches.map(&:title), height: :max))
|
629
641
|
end
|
630
642
|
elsif Howzit.options[:choose]
|
631
|
-
titles = Prompt.choose(list_topics)
|
643
|
+
titles = Prompt.choose(list_topics, height: :max)
|
632
644
|
titles.each { |title| topic_matches.push(find_topic(title)[0]) }
|
633
645
|
# If there are arguments use those to search for a matching topic
|
634
646
|
elsif !Howzit.cli_args.empty?
|
data/lib/howzit/colors.rb
CHANGED
@@ -243,6 +243,7 @@ module Howzit
|
|
243
243
|
|
244
244
|
ATTRIBUTES.each do |c, v|
|
245
245
|
new_method = <<-EOSCRIPT
|
246
|
+
# Color string as #{c}
|
246
247
|
def #{c}(string = nil)
|
247
248
|
result = ''
|
248
249
|
result << "\e[#{v}m" if Howzit::Color.coloring?
|
@@ -266,6 +267,7 @@ module Howzit
|
|
266
267
|
|
267
268
|
# Accept brightwhite in addition to boldwhite
|
268
269
|
new_method = <<-EOSCRIPT
|
270
|
+
# color string as #{c}
|
269
271
|
def #{c.to_s.sub(/bold/, 'bright')}(string = nil)
|
270
272
|
result = ''
|
271
273
|
result << "\e[#{v}m" if Howzit::Color.coloring?
|
@@ -286,6 +288,13 @@ module Howzit
|
|
286
288
|
module_eval(new_method)
|
287
289
|
end
|
288
290
|
|
291
|
+
##
|
292
|
+
## Generate escape codes for hex colors
|
293
|
+
##
|
294
|
+
## @param hex [String] The hexadecimal color code
|
295
|
+
##
|
296
|
+
## @return [String] ANSI escape string
|
297
|
+
##
|
289
298
|
def rgb(hex)
|
290
299
|
is_bg = hex.match(/^bg?#/) ? true : false
|
291
300
|
hex_string = hex.sub(/^([fb]g?)?#/, '')
|
data/lib/howzit/config.rb
CHANGED
data/lib/howzit/prompt.rb
CHANGED
@@ -78,15 +78,21 @@ module Howzit
|
|
78
78
|
##
|
79
79
|
## @return [Array] the selected results
|
80
80
|
##
|
81
|
-
def choose(matches)
|
81
|
+
def choose(matches, height: :auto)
|
82
|
+
height = if height == :auto
|
83
|
+
matches.count + 3
|
84
|
+
else
|
85
|
+
TTY::Screen.rows
|
86
|
+
end
|
82
87
|
if Util.command_exist?('fzf')
|
83
88
|
settings = [
|
84
89
|
'-0',
|
85
90
|
'-1',
|
86
91
|
'-m',
|
87
|
-
"--height=#{
|
92
|
+
"--height=#{height}",
|
88
93
|
'--header="Use tab to mark multiple selections, enter to display/run"',
|
89
|
-
'--prompt="Select a section > "'
|
94
|
+
'--prompt="Select a section > "',
|
95
|
+
'--preview="howzit {}"'
|
90
96
|
]
|
91
97
|
res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
|
92
98
|
if res.nil? || res.empty?
|
data/lib/howzit/task.rb
CHANGED
@@ -17,14 +17,160 @@ module Howzit
|
|
17
17
|
@default = default
|
18
18
|
end
|
19
19
|
|
20
|
+
##
|
21
|
+
## Inspect
|
22
|
+
##
|
23
|
+
## @return [String] description
|
24
|
+
##
|
20
25
|
def inspect
|
21
26
|
%(<#Howzit::Task @type=:#{@type} @title="#{@title}" @block?=#{@action.split(/\n/).count > 1}>)
|
22
27
|
end
|
23
28
|
|
29
|
+
##
|
30
|
+
## Output string representation
|
31
|
+
##
|
32
|
+
## @return [String] string representation of the object.
|
33
|
+
##
|
24
34
|
def to_s
|
25
35
|
@title
|
26
36
|
end
|
27
37
|
|
38
|
+
##
|
39
|
+
## Execute a block type
|
40
|
+
##
|
41
|
+
def run_block
|
42
|
+
Howzit.console.info "{bg}Running block {bw}#{@title}{x}".c if Howzit.options[:log_level] < 2
|
43
|
+
block = @action
|
44
|
+
script = Tempfile.new('howzit_script')
|
45
|
+
begin
|
46
|
+
script.write(block)
|
47
|
+
script.close
|
48
|
+
File.chmod(0o777, script.path)
|
49
|
+
system(%(/bin/sh -c "#{script.path}"))
|
50
|
+
ensure
|
51
|
+
script.close
|
52
|
+
script.unlink
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
## Execute an include task
|
58
|
+
##
|
59
|
+
## @return [Integer] number of tasks executed
|
60
|
+
##
|
61
|
+
def run_include
|
62
|
+
output = []
|
63
|
+
matches = Howzit.buildnote.find_topic(@action)
|
64
|
+
raise "Topic not found: #{@action}" if matches.empty?
|
65
|
+
|
66
|
+
$stderr.puts "{by}Running tasks from {bw}#{matches[0].title}{x}".c if Howzit.options[:log_level] < 2
|
67
|
+
output.concat(matches[0].run(nested: true))
|
68
|
+
$stderr.puts "{by}End include: #{matches[0].tasks.count} tasks{x}".c if Howzit.options[:log_level] < 2
|
69
|
+
[output, matches[0].tasks.count]
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
## Execute a run task
|
74
|
+
##
|
75
|
+
def run_run
|
76
|
+
title = Howzit.options[:show_all_code] ? @action : @title
|
77
|
+
$stderr.puts "{bg}Running {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
|
78
|
+
system(@action)
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
## Execute a copy task
|
83
|
+
##
|
84
|
+
def run_copy
|
85
|
+
title = Howzit.options[:show_all_code] ? @action : @title
|
86
|
+
$stderr.puts "{bg}Copied {bw}#{title}{bg} to clipboard{x}".c if Howzit.options[:log_level] < 2
|
87
|
+
os_copy(@action)
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
## Platform-agnostic copy-to-clipboard
|
92
|
+
##
|
93
|
+
## @param string [String] The string to copy
|
94
|
+
##
|
95
|
+
def os_copy(string)
|
96
|
+
os = RbConfig::CONFIG['target_os']
|
97
|
+
out = "{bg}Copying {bw}#{string}".c
|
98
|
+
case os
|
99
|
+
when /darwin.*/i
|
100
|
+
$stderr.puts "#{out} (macOS){x}".c if Howzit.options[:log_level].zero?
|
101
|
+
`echo #{Shellwords.escape(string)}'\\c'|pbcopy`
|
102
|
+
when /mingw|mswin/i
|
103
|
+
$stderr.puts "#{out} (Windows){x}".c if Howzit.options[:log_level].zero?
|
104
|
+
`echo #{Shellwords.escape(string)} | clip`
|
105
|
+
else
|
106
|
+
if 'xsel'.available?
|
107
|
+
$stderr.puts "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level].zero?
|
108
|
+
`echo #{Shellwords.escape(string)}'\\c'|xsel -i`
|
109
|
+
elsif 'xclip'.available?
|
110
|
+
$stderr.puts "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level].zero?
|
111
|
+
`echo #{Shellwords.escape(string)}'\\c'|xclip -i`
|
112
|
+
else
|
113
|
+
$stderr.puts out if Howzit.options[:log_level].zero?
|
114
|
+
$stderr.puts 'Unable to determine executable for clipboard.'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
## Platform-agnostic open command
|
121
|
+
##
|
122
|
+
## @param command [String] The command
|
123
|
+
##
|
124
|
+
def os_open(command)
|
125
|
+
os = RbConfig::CONFIG['target_os']
|
126
|
+
out = "{bg}Opening {bw}#{command}".c
|
127
|
+
case os
|
128
|
+
when /darwin.*/i
|
129
|
+
Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
|
130
|
+
`open #{Shellwords.escape(command)}`
|
131
|
+
when /mingw|mswin/i
|
132
|
+
Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
|
133
|
+
`start #{Shellwords.escape(command)}`
|
134
|
+
else
|
135
|
+
if 'xdg-open'.available?
|
136
|
+
Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
|
137
|
+
`xdg-open #{Shellwords.escape(command)}`
|
138
|
+
else
|
139
|
+
Howzit.console.debug out if Howzit.options[:log_level] < 2
|
140
|
+
Howzit.console.debug 'Unable to determine executable for `open`.'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
##
|
146
|
+
## Execute the task
|
147
|
+
##
|
148
|
+
def run
|
149
|
+
output = []
|
150
|
+
tasks = 1
|
151
|
+
if @type == :block
|
152
|
+
run_block
|
153
|
+
else
|
154
|
+
case @type
|
155
|
+
when :include
|
156
|
+
output, tasks = run_include
|
157
|
+
when :run
|
158
|
+
run_run
|
159
|
+
when :copy
|
160
|
+
run_copy
|
161
|
+
when :open
|
162
|
+
os_open(@action)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
[output, tasks]
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
## Output terminal-formatted list item
|
171
|
+
##
|
172
|
+
## @return [String] List representation of the object.
|
173
|
+
##
|
28
174
|
def to_list
|
29
175
|
" * #{@type}: #{@title.preserve_escapes}"
|
30
176
|
end
|
data/lib/howzit/topic.rb
CHANGED
@@ -56,52 +56,16 @@ module Howzit
|
|
56
56
|
task_count = Howzit.buildnote.find_topic(task.action)[0].tasks.count
|
57
57
|
" (#{task_count} tasks)"
|
58
58
|
else
|
59
|
-
|
59
|
+
''
|
60
60
|
end
|
61
61
|
q = %({bg}#{task.type.to_s.capitalize} {xw}"{bw}#{task.title}{xw}"#{note}{x}).c
|
62
62
|
res = Prompt.yn(q, default: task.default)
|
63
63
|
next unless res
|
64
64
|
|
65
65
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
block = task.action
|
70
|
-
script = Tempfile.new('howzit_script')
|
71
|
-
begin
|
72
|
-
script.write(block)
|
73
|
-
script.close
|
74
|
-
File.chmod(0777, script.path)
|
75
|
-
system(%(/bin/sh -c "#{script.path}"))
|
76
|
-
tasks += 1
|
77
|
-
ensure
|
78
|
-
script.close
|
79
|
-
script.unlink
|
80
|
-
end
|
81
|
-
else
|
82
|
-
title = Howzit.options[:show_all_code] ? task.action : task.title
|
83
|
-
case task.type
|
84
|
-
when :include
|
85
|
-
matches = Howzit.buildnote.find_topic(task.action)
|
86
|
-
raise "Topic not found: #{task.action}" if matches.empty?
|
87
|
-
|
88
|
-
$stderr.puts "{by}Running tasks from {bw}#{matches[0].title}{x}".c if Howzit.options[:log_level] < 2
|
89
|
-
output.push(matches[0].run(nested: true))
|
90
|
-
$stderr.puts "{by}End include: #{matches[0].tasks.count} tasks{x}".c if Howzit.options[:log_level] < 2
|
91
|
-
tasks += matches[0].tasks.count
|
92
|
-
when :run
|
93
|
-
$stderr.puts "{bg}Running {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
|
94
|
-
system(task.action)
|
95
|
-
tasks += 1
|
96
|
-
when :copy
|
97
|
-
$stderr.puts "{bg}Copied {bw}#{title}{bg} to clipboard{x}".c if Howzit.options[:log_level] < 2
|
98
|
-
os_copy(task.action)
|
99
|
-
tasks += 1
|
100
|
-
when :open
|
101
|
-
os_open(task.action)
|
102
|
-
tasks += 1
|
103
|
-
end
|
104
|
-
end
|
66
|
+
run_output, total = task.run
|
67
|
+
output.concat(run_output)
|
68
|
+
tasks += total
|
105
69
|
end
|
106
70
|
else
|
107
71
|
Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
|
@@ -113,61 +77,6 @@ module Howzit
|
|
113
77
|
output
|
114
78
|
end
|
115
79
|
|
116
|
-
##
|
117
|
-
## Platform-agnostic copy-to-clipboard
|
118
|
-
##
|
119
|
-
## @param string [String] The string to copy
|
120
|
-
##
|
121
|
-
def os_copy(string)
|
122
|
-
os = RbConfig::CONFIG['target_os']
|
123
|
-
out = "{bg}Copying {bw}#{string}".c
|
124
|
-
case os
|
125
|
-
when /darwin.*/i
|
126
|
-
$stderr.puts "#{out} (macOS){x}".c if Howzit.options[:log_level].zero?
|
127
|
-
`echo #{Shellwords.escape(string)}'\\c'|pbcopy`
|
128
|
-
when /mingw|mswin/i
|
129
|
-
$stderr.puts "#{out} (Windows){x}".c if Howzit.options[:log_level].zero?
|
130
|
-
`echo #{Shellwords.escape(string)} | clip`
|
131
|
-
else
|
132
|
-
if 'xsel'.available?
|
133
|
-
$stderr.puts "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level].zero?
|
134
|
-
`echo #{Shellwords.escape(string)}'\\c'|xsel -i`
|
135
|
-
elsif 'xclip'.available?
|
136
|
-
$stderr.puts "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level].zero?
|
137
|
-
`echo #{Shellwords.escape(string)}'\\c'|xclip -i`
|
138
|
-
else
|
139
|
-
$stderr.puts out if Howzit.options[:log_level].zero?
|
140
|
-
$stderr.puts 'Unable to determine executable for clipboard.'
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
##
|
146
|
-
## Platform-agnostic open command
|
147
|
-
##
|
148
|
-
## @param command [String] The command
|
149
|
-
##
|
150
|
-
def os_open(command)
|
151
|
-
os = RbConfig::CONFIG['target_os']
|
152
|
-
out = "{bg}Opening {bw}#{command}".c
|
153
|
-
case os
|
154
|
-
when /darwin.*/i
|
155
|
-
Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
|
156
|
-
`open #{Shellwords.escape(command)}`
|
157
|
-
when /mingw|mswin/i
|
158
|
-
Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
|
159
|
-
`start #{Shellwords.escape(command)}`
|
160
|
-
else
|
161
|
-
if 'xdg-open'.available?
|
162
|
-
Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
|
163
|
-
`xdg-open #{Shellwords.escape(command)}`
|
164
|
-
else
|
165
|
-
Howzit.console.debug out if Howzit.options[:log_level] < 2
|
166
|
-
Howzit.console.debug 'Unable to determine executable for `open`.'
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
80
|
# Output a topic with fancy title and bright white text.
|
172
81
|
#
|
173
82
|
# @param options [Hash] The options
|
data/lib/howzit/util.rb
CHANGED
@@ -4,7 +4,6 @@ module Howzit
|
|
4
4
|
# Util class
|
5
5
|
module Util
|
6
6
|
class << self
|
7
|
-
|
8
7
|
##
|
9
8
|
## Read a file with UTF-8 encoding and
|
10
9
|
## leading/trailing whitespace removed
|
@@ -90,7 +89,7 @@ module Howzit
|
|
90
89
|
args = case pg
|
91
90
|
when 'delta'
|
92
91
|
'--pager="less -FXr"'
|
93
|
-
when
|
92
|
+
when 'less'
|
94
93
|
'-FXr'
|
95
94
|
when 'bat'
|
96
95
|
if Howzit.options[:highlight]
|
@@ -153,6 +152,7 @@ module Howzit
|
|
153
152
|
options = {
|
154
153
|
color: true,
|
155
154
|
highlight: false,
|
155
|
+
paginate: true,
|
156
156
|
wrap: 0
|
157
157
|
}
|
158
158
|
|
@@ -168,7 +168,7 @@ module Howzit
|
|
168
168
|
|
169
169
|
output = `echo #{Shellwords.escape(string.strip)}#{pipes}`.strip
|
170
170
|
|
171
|
-
if Howzit.options[:paginate]
|
171
|
+
if options[:paginate] && Howzit.options[:paginate]
|
172
172
|
page(output)
|
173
173
|
else
|
174
174
|
puts output
|
data/lib/howzit/version.rb
CHANGED
data/lib/howzit.rb
CHANGED
@@ -55,18 +55,30 @@ module Howzit
|
|
55
55
|
@config ||= Config.new
|
56
56
|
end
|
57
57
|
|
58
|
+
##
|
59
|
+
## Array for tracking inclusions and avoiding duplicates in output
|
60
|
+
##
|
58
61
|
def inclusions
|
59
62
|
@inclusions ||= []
|
60
63
|
end
|
61
64
|
|
65
|
+
##
|
66
|
+
## Module storage for Howzit::Config.options
|
67
|
+
##
|
62
68
|
def options
|
63
69
|
config.options
|
64
70
|
end
|
65
71
|
|
72
|
+
##
|
73
|
+
## Module storage for buildnote
|
74
|
+
##
|
66
75
|
def buildnote
|
67
76
|
@buildnote ||= BuildNote.new
|
68
77
|
end
|
69
78
|
|
79
|
+
##
|
80
|
+
## Convenience method for logging with Howzit.console.warn, etc.
|
81
|
+
##
|
70
82
|
def console
|
71
83
|
@console ||= Howzit::ConsoleLogger.new(options[:log_level])
|
72
84
|
end
|
data/scripts/runtests.sh
ADDED
data/spec/task_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: howzit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '1.3'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: tty-spinner
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0.9'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0.9'
|
223
237
|
- !ruby/object:Gem::Dependency
|
224
238
|
name: mdless
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,6 +303,12 @@ files:
|
|
289
303
|
- README.md
|
290
304
|
- Rakefile
|
291
305
|
- bin/howzit
|
306
|
+
- docker/Dockerfile
|
307
|
+
- docker/Dockerfile-2.6
|
308
|
+
- docker/Dockerfile-2.7
|
309
|
+
- docker/Dockerfile-3.0
|
310
|
+
- docker/bash_profile
|
311
|
+
- docker/inputrc
|
292
312
|
- fish/completions/bld.fish
|
293
313
|
- fish/completions/fisher.fish
|
294
314
|
- fish/completions/howzit.fish
|
@@ -307,6 +327,7 @@ files:
|
|
307
327
|
- lib/howzit/topic.rb
|
308
328
|
- lib/howzit/util.rb
|
309
329
|
- lib/howzit/version.rb
|
330
|
+
- scripts/runtests.sh
|
310
331
|
- spec/.rubocop.yml
|
311
332
|
- spec/buildnote_spec.rb
|
312
333
|
- spec/cli_spec.rb
|