wordexp 0.1.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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/exe/wordexp +11 -0
- data/ext/wordexp_ext/extconf.rb +3 -0
- data/lib/wordexp/cli.rb +7 -0
- data/lib/wordexp/version.rb +3 -0
- data/lib/wordexp/wordexp_ext.bundle +0 -0
- data/lib/wordexp.rb +53 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb71655c4037612389f450fa4b30e11e74de3f3341bc21c1f9e383ef004032cc
|
4
|
+
data.tar.gz: 2d44f45f8059ef90230f0f1838925c2ed93346877797dd91eea8d06ed85522f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e75fa85c1e12d4941b25590e298b5f7ef07bb6a580e206865db691aeb2a96577a553afeeeb2d680acba9112b4d31c4973f3cc68380bc15f7bedd5cf4c57f44aa
|
7
|
+
data.tar.gz: b7f2852a1f45ad3323eaa1cc50351ad6cec485a941000f73823cc5bea048e502eb22d88c9669ec9f576c5b647a1fb9d7b16ae8c06c65c808a45b238efe1d35b3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Sami Samhuri
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# wordexp
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/wordexp)
|
4
|
+
[](https://app.circleci.com/pipelines/github/samsonjs/wordexp?branch=main)
|
5
|
+
[](https://codeclimate.com/github/samsonjs/wordexp/maintainability)
|
6
|
+
|
7
|
+
A Ruby gem for performing shell word expansion using [wordexp][]. It's like [Shellwords][] turned up to 11. Not only does it split taking quotes into account, but it also expands environment variables and tildes, and runs subcommands in \``backticks`\` or `$(dollar parentheses)`.
|
8
|
+
|
9
|
+
[wordexp]: https://man7.org/linux/man-pages/man3/wordexp.3.html
|
10
|
+
[Shellwords]: https://ruby-doc.org/stdlib-3.1.0/libdoc/shellwords/rdoc/Shellwords.html
|
11
|
+
|
12
|
+
---
|
13
|
+
|
14
|
+
- [Quick start](#quick-start)
|
15
|
+
- [Support](#support)
|
16
|
+
- [License](#license)
|
17
|
+
- [Code of conduct](#code-of-conduct)
|
18
|
+
- [Contribution guide](#contribution-guide)
|
19
|
+
|
20
|
+
## Quick start
|
21
|
+
|
22
|
+
```
|
23
|
+
$ gem install wordexp
|
24
|
+
```
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'wordexp'
|
28
|
+
|
29
|
+
cmd = Wordexp.expand("echo 'roof cats' $HOME ~/bin $(date +%F)")
|
30
|
+
# => ["echo", "roof cats", "/home/queso", "/home/queso/bin", "2022-01-16"]
|
31
|
+
|
32
|
+
fork { exec(*cmd) }
|
33
|
+
# roof cats /home/queso /home/queso/bin 2022-01-16
|
34
|
+
```
|
35
|
+
|
36
|
+
With that you're half way to a [fairly usable shell in Ruby](https://github.com/samsonjs/csc360-a1-shell).
|
37
|
+
|
38
|
+
## Support
|
39
|
+
|
40
|
+
If you want to report a bug, or have ideas, feedback or questions about the gem, [let me know via GitHub issues](https://github.com/samsonjs/wordexp/issues/new) and I will do my best to provide a helpful answer. Happy hacking!
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
45
|
+
|
46
|
+
## Code of conduct
|
47
|
+
|
48
|
+
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
49
|
+
|
50
|
+
## Contribution guide
|
51
|
+
|
52
|
+
Pull requests are welcome! Make sure that new code is reasonably well tested and all the checks pass. I'm happy to provide a bit of direction and guidance if you're unsure how to proceed with any of these things.
|
data/exe/wordexp
ADDED
data/lib/wordexp/cli.rb
ADDED
Binary file
|
data/lib/wordexp.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'wordexp/wordexp_ext'
|
2
|
+
|
3
|
+
module Wordexp
|
4
|
+
autoload :CLI, 'wordexp/cli'
|
5
|
+
autoload :VERSION, 'wordexp/version'
|
6
|
+
|
7
|
+
# Illegal occurrence of newline or one of |, &, ;, <, >, (, ), {, }.
|
8
|
+
class BadCharacterError < StandardError; end
|
9
|
+
|
10
|
+
# An undefined shell variable was referenced, and the WRDE_UNDEF flag told us to consider this an error.
|
11
|
+
class BadValueError < StandardError; end
|
12
|
+
|
13
|
+
# Command substitution requested, but the WRDE_NOCMD flag told us to consider this an error.
|
14
|
+
class CommandSubstitutionError < StandardError; end
|
15
|
+
|
16
|
+
# Out of memory.
|
17
|
+
class NoSpaceError < StandardError; end
|
18
|
+
|
19
|
+
# Shell syntax error, such as unbalanced parentheses or unmatched quotes.
|
20
|
+
class SyntaxError < StandardError; end
|
21
|
+
|
22
|
+
# An undocumented error occurred.
|
23
|
+
class UndocumentedError < StandardError; end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
def expand(string)
|
27
|
+
result = Ext.wordexp(string)
|
28
|
+
return result if result.is_a?(Array)
|
29
|
+
|
30
|
+
case result
|
31
|
+
when :wrde_badchar
|
32
|
+
# FIXME: useful message that includes the position of the character
|
33
|
+
raise BadCharacterError, 'Bad character'
|
34
|
+
|
35
|
+
when :wrde_badval
|
36
|
+
raise BadValueError, 'Bad value'
|
37
|
+
|
38
|
+
when :wrde_cmdsub
|
39
|
+
raise CommandSubstitutionError, 'Command substitution is disabled'
|
40
|
+
|
41
|
+
when :wrde_nospace
|
42
|
+
raise NoSpaceError, 'Out of memory'
|
43
|
+
|
44
|
+
when :wrde_syntax
|
45
|
+
raise SyntaxError, 'Bad value'
|
46
|
+
|
47
|
+
else
|
48
|
+
warn "wordexp returned an unexpected result: #{result.inspect}"
|
49
|
+
raise UndocumentedError, 'An unknown error occurred'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wordexp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sami Samhuri
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- sami@samhuri.net
|
16
|
+
executables:
|
17
|
+
- wordexp
|
18
|
+
extensions:
|
19
|
+
- ext/wordexp_ext/extconf.rb
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- exe/wordexp
|
25
|
+
- ext/wordexp_ext/extconf.rb
|
26
|
+
- lib/wordexp.rb
|
27
|
+
- lib/wordexp/cli.rb
|
28
|
+
- lib/wordexp/version.rb
|
29
|
+
- lib/wordexp/wordexp_ext.bundle
|
30
|
+
homepage: https://github.com/samsonjs/wordexp
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
bug_tracker_uri: https://github.com/samsonjs/wordexp/issues
|
35
|
+
changelog_uri: https://github.com/samsonjs/wordexp/releases
|
36
|
+
source_code_uri: https://github.com/samsonjs/wordexp
|
37
|
+
homepage_uri: https://github.com/samsonjs/wordexp
|
38
|
+
rubygems_mfa_required: 'true'
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- ext
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.6.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.3.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: A Ruby gem for performing shell word expansion using wordexp
|
59
|
+
test_files: []
|