howzit 2.0.25 → 2.0.28

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: 29f72dd5e915f1fbec378cc4210902fb6e3b9ce376de4f4e962c08b40dc5bbca
4
- data.tar.gz: bdc554ae8533b3a86360c82a41d4ea55677a5a271fab218db5b1057814aac490
3
+ metadata.gz: c2a724cc90c349de14afa896512a32d69bcf2fa44575f69e74b0a6f96d615ebb
4
+ data.tar.gz: 73c54a8893fa66784575235d329ad698da6e7a34a2741e09d2d93149b118f68a
5
5
  SHA512:
6
- metadata.gz: b49e67762ea36e7e792decb239a8d35f100f28be2992f70a2fb9b2d6ed13ba809db11aa4ea075244be6b263c1c464430b0e57db73ecf444a61f79fcdad812a91
7
- data.tar.gz: 7d2d9b973f4798dc4ce0082ccdaad308748a4a39fe505f384f928cdf1fe73a23f751928907e2418a602e26f0de46bafb874d9f0917017d39a0c6feedcfb99990
6
+ metadata.gz: 4d4c9e0c7e5c78f10479cea93dffa09fdf768d335210897feb127f849040bced7a05924a60f6621173ececb1fde116fe5a3ecc79270767c12718b1a1f9742281
7
+ data.tar.gz: ff2c18f91883cf4f3b6035b8b304a23575381fd1b9a74333781db8ac000b13d03eb43969bb80d964e3dafeec3556a2152392b2eb074a34561981753233e1fc9e
data/.travis.yml CHANGED
@@ -14,3 +14,4 @@ script: "bundle exec rspec spec --exclude-pattern 'cli*'"
14
14
  branches:
15
15
  only:
16
16
  - main
17
+ - develop
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ### 2.0.28
2
+
3
+ 2022-08-29 18:42
4
+
5
+ #### IMPROVED
6
+
7
+ - If a topic runs multiple directives, stop processing them if one returns a non-zero exit status
8
+
9
+ ### 2.0.27
10
+
11
+ 2022-08-23 12:25
12
+
13
+ #### IMPROVED
14
+
15
+ - Code cleanup
16
+
17
+ ### 2.0.26
18
+
19
+ 2022-08-23 11:36
20
+
21
+ #### IMPROVED
22
+
23
+ - Add ctrl-a/d bindings to fzf menu for select/deselect all
24
+
1
25
  ### 2.0.25
2
26
 
3
27
  2022-08-09 12:46
data/lib/howzit/prompt.rb CHANGED
@@ -87,59 +87,86 @@ module Howzit
87
87
  return [] if !$stdout.isatty || matches.count.zero?
88
88
 
89
89
  if Util.command_exist?('fzf')
90
- height = if height == :auto
91
- matches.count + 3
92
- else
93
- TTY::Screen.rows
94
- end
95
-
96
- settings = [
97
- '-0',
98
- '-1',
99
- '-m',
100
- "--height=#{height}",
101
- '--header="Use tab to mark multiple selections, enter to display/run"',
102
- '--prompt="Select a section > "',
103
- %(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
104
- ]
90
+ height = height == :auto ? matches.count + 3 : TTY::Screen.rows
91
+
92
+ settings = fzf_options(height)
105
93
  res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
106
- if res.nil? || res.empty?
107
- Howzit.console.info 'Cancelled'
108
- Process.exit 0
109
- end
110
- return res.split(/\n/)
94
+ return fzf_result(res)
95
+ end
96
+
97
+ tty_menu(matches)
98
+ end
99
+
100
+ def fzf_result(res)
101
+ if res.nil? || res.empty?
102
+ Howzit.console.info 'Cancelled'
103
+ Process.exit 0
111
104
  end
105
+ return res.split(/\n/)
106
+ end
107
+
108
+ def fzf_options(height)
109
+ [
110
+ '-0',
111
+ '-1',
112
+ '-m',
113
+ "--height=#{height}",
114
+ '--header="Tab: add selection, ctrl-a/d: (de)select all, return: display/run"',
115
+ '--bind ctrl-a:select-all,ctrl-d:deselect-all,ctrl-t:toggle-all',
116
+ '--prompt="Select a topic > "',
117
+ %(--preview="howzit --no-pager --header-format block --no-color --default --multiple first {}")
118
+ ]
119
+ end
112
120
 
121
+ ##
122
+ ## Display a numeric menu on the TTY
123
+ ##
124
+ ## @param matches The matches from which to select
125
+ ##
126
+ def tty_menu(matches)
113
127
  return matches if matches.count == 1
114
128
 
115
- res = matches[0..9]
116
- stty_save = `stty -g`.chomp
129
+ @stty_save = `stty -g`.chomp
117
130
 
118
131
  trap('INT') do
119
- system('stty', stty_save)
132
+ system('stty')
120
133
  exit
121
134
  end
122
135
 
123
136
  options_list(matches)
137
+ read_selection(matches)
138
+ end
124
139
 
125
- begin
126
- printf("Type 'q' to cancel, enter for first item", res.length)
127
- while (line = Readline.readline(': ', true))
128
- if line =~ /^[a-z]/i
129
- system('stty', stty_save) # Restore
130
- exit
131
- end
132
- line = line == '' ? 1 : line.to_i
140
+ ##
141
+ ## Read a single number response from the command line
142
+ ##
143
+ ## @param matches The matches
144
+ ##
145
+ def read_selection(matches)
146
+ printf "Type 'q' to cancel, enter for first item"
147
+ while (line = Readline.readline(': ', true))
148
+ line = read_num(line)
133
149
 
134
- return [matches[line - 1]] if line.positive? && line <= matches.length
150
+ return [matches[line - 1]] if line.positive? && line <= matches.length
135
151
 
136
- puts 'Out of range'
137
- options_list(matches)
138
- end
139
- ensure
140
- system('stty', stty_save)
152
+ puts 'Out of range'
153
+ read_selection(matches)
154
+ end
155
+ ensure
156
+ system('stty', @stty_save)
157
+ end
158
+
159
+ ##
160
+ ## Convert a response to an Integer
161
+ ##
162
+ ## @param line The response to convert
163
+ ##
164
+ def read_num(line)
165
+ if line =~ /^[a-z]/i
166
+ system('stty', @stty_save) # Restore
141
167
  exit
142
168
  end
169
+ line == '' ? 1 : line.to_i
143
170
  end
144
171
  end
145
172
  end
data/lib/howzit/task.rb CHANGED
@@ -56,11 +56,13 @@ module Howzit
56
56
  script.write(block)
57
57
  script.close
58
58
  File.chmod(0o777, script.path)
59
- system(%(/bin/sh -c "#{script.path}"))
59
+ res = system(%(/bin/sh -c "#{script.path}"))
60
60
  ensure
61
61
  script.close
62
62
  script.unlink
63
63
  end
64
+
65
+ res
64
66
  end
65
67
 
66
68
  ##
@@ -85,7 +87,7 @@ module Howzit
85
87
  def run_run
86
88
  title = Howzit.options[:show_all_code] ? @action : @title
87
89
  Howzit.console.info("{bg}Running {bw}#{title}{x}".c)
88
- system(@action)
90
+ return system(@action)
89
91
  end
90
92
 
91
93
  ##
@@ -95,6 +97,7 @@ module Howzit
95
97
  title = Howzit.options[:show_all_code] ? @action : @title
96
98
  Howzit.console.info("{bg}Copied {bw}#{title}{bg} to clipboard{x}".c)
97
99
  Util.os_copy(@action)
100
+ return true
98
101
  end
99
102
 
100
103
  ##
@@ -103,22 +106,22 @@ module Howzit
103
106
  def run
104
107
  output = []
105
108
  tasks = 1
106
- if @type == :block
107
- run_block
108
- else
109
- case @type
110
- when :include
111
- output, tasks = run_include
112
- when :run
113
- run_run
114
- when :copy
115
- run_copy
116
- when :open
117
- Util.os_open(@action)
118
- end
119
- end
109
+ res = if @type == :block
110
+ run_block
111
+ else
112
+ case @type
113
+ when :include
114
+ output, tasks = run_include
115
+ when :run
116
+ run_run
117
+ when :copy
118
+ run_copy
119
+ when :open
120
+ Util.os_open(@action)
121
+ end
122
+ end
120
123
 
121
- [output, tasks]
124
+ [output, tasks, res]
122
125
  end
123
126
 
124
127
  ##
data/lib/howzit/topic.rb CHANGED
@@ -63,9 +63,15 @@ module Howzit
63
63
  next unless res
64
64
 
65
65
  end
66
- run_output, total = task.run
66
+ run_output, total, success = task.run
67
+
67
68
  output.concat(run_output)
68
69
  tasks += total
70
+
71
+ unless success
72
+ Howzit.console.warn '{br}Error running task{bw} - non-zero exit, ending processing{x}'.c
73
+ break
74
+ end
69
75
  end
70
76
  else
71
77
  Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.25'
6
+ VERSION = '2.0.28'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.25
4
+ version: 2.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler