yarsh 0.3.0 → 0.3.1

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: 149709074192906833f0d530ba07da00c9a6591ea79864fd5d5f2e9c39019ad8
4
- data.tar.gz: 4c7336c81d2531dd94052c05344d186e97878b94c92e1ad5852955d10df07da3
3
+ metadata.gz: a2abe40eb2be33ef53eba4b99743447c9db93831dd1e8c00221b1934cd5bc264
4
+ data.tar.gz: 3f53d3e1a4a560b7c04982a7874899d8be8aaba714a3cc42dc4ecff6adae99b2
5
5
  SHA512:
6
- metadata.gz: 030f6d98caa7410911fd8cff2e55e9062dda276c6f45f27d2e29073b53717aa273a0b58ad3b761833c1a955fa0b8ade8501c7c0fcab0af8095eff09a906451ce
7
- data.tar.gz: 85d5081c0f07e9ddea3e0ea5202abea2d2adbea4b6cedf22f8d9a81c4a34fad0b1a9c037de8da601579b2e5bbbea4f649e9a2661b31c3496bf5f8f91d65f727f
6
+ metadata.gz: d89b9258f28f13778ad03734cd98db71e09f0b55132631fb2e054ec37286cde8ba688db5dede69835f1ca2ce51fd2cce4a9759707ef5df27cfe8218e6305f6c3
7
+ data.tar.gz: 7ca6c547b1eb3aac0c4c8c1582e42b71007fe2181877aa2d74379c24a175ff48d6307dc978c13a752d4ca054e69a40fc94ee0f4c661e0ca4ed571e82653926de
data/CHANGES.md CHANGED
@@ -200,4 +200,13 @@ See commits: `bcc25b4`, `ea92742`, `51c9db8`, `2218f29`, `0fceeb8`. Tests in
200
200
  transformation, heredoc handling, binding threading, integration with
201
201
  `Yarsh::Shell`).
202
202
 
203
+ ## 0.3.0
203
204
 
205
+ A completion engine for writing shell commands complete in ruby. It comes with a Shell completion engine using bash autocomplete when available.
206
+
207
+ It alos comes with completion for the gem command.
208
+
209
+ ## 0.3.1
210
+
211
+ * Small bug fix for the REPL.
212
+ * Added the export reserved word to define global variables in the shell.
data/lib/yarsh/shell.rb CHANGED
@@ -14,6 +14,8 @@ module Yarsh
14
14
  local logout mapfile popd printf pushd pwd read readonly
15
15
  return set shift shopt source suspend test times trap true
16
16
  type typeset ulimit umask unalias unset wait].freeze
17
+ EXPORT = 'export'
18
+ DO_NOT_PRINT_RETURN_VALUE = :do_not_print_return_value80y0327y47123
17
19
 
18
20
  def initialize(bind)
19
21
  @bind = bind
@@ -65,7 +67,7 @@ module Yarsh
65
67
  private
66
68
 
67
69
  def format_output(object)
68
- pp object
70
+ pp object unless object == DO_NOT_PRINT_RETURN_VALUE
69
71
  end
70
72
  alias fp format_output
71
73
 
@@ -89,6 +91,7 @@ module Yarsh
89
91
 
90
92
  def unclosed_quote?(line)
91
93
  return false if line.nil?
94
+
92
95
  double_quotes = line.scan(/(?<!\\)"/).size
93
96
  single_quotes = line.scan(/(?<!\\)'/).size
94
97
  double_quotes.odd? || single_quotes.odd?
@@ -96,6 +99,7 @@ module Yarsh
96
99
 
97
100
  def inside_quote?(pre)
98
101
  return false if pre.nil? || pre.empty?
102
+
99
103
  double_quotes = pre.scan(/(?<!\\)"/).size
100
104
  single_quotes = pre.scan(/(?<!\\)'/).size
101
105
  double_quotes.odd? || single_quotes.odd?
@@ -116,7 +120,17 @@ module Yarsh
116
120
 
117
121
  if input == 'cd' || input.start_with?('cd ')
118
122
  cd(input.split(' ', 2)[1])
119
- return nil
123
+ return DO_NOT_PRINT_RETURN_VALUE
124
+ end
125
+
126
+ if input.start_with?("#{EXPORT} ")
127
+ assignment = input[EXPORT.length + 1..].strip.split('=', 2)
128
+ if assignment.size == 2
129
+ ENV[assignment[0]] = assignment[1].gsub(/\A['"]|['"]\z/, '') # Remove surrounding quotes if present
130
+ return DO_NOT_PRINT_RETURN_VALUE
131
+ end
132
+ puts @cf.fg_red("Error: Invalid export syntax. Use 'export VAR=value'")
133
+ return DO_NOT_PRINT_RETURN_VALUE
120
134
  end
121
135
 
122
136
  begin
@@ -131,11 +145,13 @@ module Yarsh
131
145
  begin
132
146
  input = Yarsh.expand_aliases(input, Config.instance.aliases)
133
147
  execute(input)
148
+ DO_NOT_PRINT_RETURN_VALUE
134
149
  rescue Exception => e
135
150
  $sher = e
136
151
  info("#{e.class}: #{e.message}")
137
152
  puts "#{@cf.bold.underline.fg_blue('Shell:')} '#{input}': #{e.message}"
138
153
  puts "#{@cf.bold.underline.fg_red('Ruby:')} '#{input}': #{rb_error.message}"
154
+ DO_NOT_PRINT_RETURN_VALUE
139
155
  end
140
156
  end
141
157
  end
@@ -161,10 +177,6 @@ module Yarsh
161
177
  end
162
178
 
163
179
  def execute(cmd)
164
- return system(cmd, exception: true) if cmd.match?(/[|;&`$(){}\[\]<>]/)
165
- args = Shellwords.shellsplit(cmd)
166
- system(*args, exception: true)
167
- rescue ArgumentError
168
180
  system(cmd, exception: true)
169
181
  end
170
182
 
@@ -191,17 +203,17 @@ module Yarsh
191
203
 
192
204
  if word.empty?
193
205
  return ENV['PATH'].split(File::PATH_SEPARATOR)
194
- .flat_map { |dir| Dir["#{dir}/*"] }
195
- .map { |f| File.basename(f) }
196
- .uniq
197
- .sort
206
+ .flat_map { |dir| Dir["#{dir}/*"] }
207
+ .map { |f| File.basename(f) }
208
+ .uniq
209
+ .sort
198
210
  end
199
211
 
200
212
  cmd = word.strip.split(/\s+/).first
201
213
  return [] if cmd.nil? || cmd.empty?
202
214
 
203
215
  # Strip privileged prefix (sudo, doas, etc.) — complete the real command
204
- if Yarsh::Completion::Engine::PRIVILEGED_COMMANDS.include?(cmd)
216
+ if Yarsh::Completion::Engine::PRIVILEGED_COMMANDS.include?(cmd) && cmd != word
205
217
  remaining = word.sub(/\A#{Regexp.escape(cmd)}\s+/, '')
206
218
  return complete_command(remaining)
207
219
  end
@@ -228,7 +240,7 @@ module Yarsh
228
240
 
229
241
  def complete_ruby(word)
230
242
  IRB::InputCompletor.retrieve_completion_data(word, bind: @bind)
231
- rescue
243
+ rescue StandardError
232
244
  []
233
245
  end
234
246
 
@@ -322,8 +334,9 @@ module Yarsh
322
334
  Reline.autocompletion = Config.instance.autocompletion
323
335
  Reline.completion_append_character = ' '
324
336
  Reline.core.config.keyseq_timeout = 0.5
325
- Reline.completion_proc = proc { |target, pre, post|
326
- next [] if inside_quote?(pre)
337
+ Reline.completion_proc = proc { |target, pre, _post|
338
+ next [] if inside_quote?(pre) || pre =~ /'|"\z/
339
+
327
340
  full = pre.empty? ? target : pre.rstrip + ' ' + target
328
341
  first_word = full.strip.split(/\s+/).first.to_s
329
342
  ruby_completions = if !Config.instance.ruby_completion ||
data/lib/yarsh/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Yarsh
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarsh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yarsh4all