No description
Find a file
2023-06-20 14:38:56 -07:00
.circleci Upgrade to Ruby 3.2.1 2023-02-13 23:34:28 -08:00
.github Merge pull request #15 from samsonjs/dependabot/github_actions/github/codeql-action-2 2022-06-22 10:16:00 -07:00
bin Initialize the template project 2022-01-16 15:51:10 -08:00
exe Implement the most basic API possible 2022-01-16 18:22:54 -08:00
ext/wordexp_ext Move extension to a subdirectory 2022-01-16 21:45:41 -08:00
lib Bump version to v0.1.2 2023-01-08 00:37:08 -08:00
test Update rubocop to 1.34.1 2022-08-09 10:58:17 -07:00
.gitignore Use rake-compiler 2022-01-16 21:52:08 -08:00
.overcommit.yml Initial commit 2022-01-16 15:35:53 -08:00
.prettierignore Initial commit 2022-01-16 15:35:53 -08:00
.rubocop.yml Upgrade to Ruby 3.2 and drop 2.6 2023-01-08 00:26:12 -08:00
.ruby-version Upgrade to Ruby 3.2.1 2023-02-13 23:34:28 -08:00
CHANGELOG.md Bump version to v0.1.2 2023-01-08 00:37:08 -08:00
CODE_OF_CONDUCT.md Initialize the template project 2022-01-16 15:51:10 -08:00
Gemfile Bump rubocop-minitest from 0.29.0 to 0.31.0 2023-06-01 13:57:45 +00:00
Gemfile.lock Bump rubocop-minitest from 0.29.0 to 0.31.0 2023-06-01 13:57:45 +00:00
LICENSE.txt Initialize the template project 2022-01-16 15:51:10 -08:00
Rakefile Take extension files into account in verify_gemspec_files task 2022-01-16 22:08:04 -08:00
README.md Update README.md 2022-06-22 10:20:04 -07:00
wordexp.gemspec Upgrade to Ruby 3.2 and drop 2.6 2023-01-08 00:26:12 -08:00

wordexp

Gem Version Circle Code Climate Maintainability

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).


Quick start

$ gem install wordexp
require 'wordexp'

cmd = Wordexp.expand("echo 'roof cats' $HOME ~/bin $(date +%F)")
# => ["echo", "roof cats", "/home/queso", "/home/queso/bin", "2022-01-16"]

fork { exec(*cmd) }
# roof cats /home/queso /home/queso/bin 2022-01-16

With that you're half way to a fairly usable shell in Ruby. Ok maybe not half but it's a start.

Command line

Just for fun there's a command line executable that you can use to play around or debug. Note that when you're calling it from another shell you have to quote everything liberally as to not have it interpret anything. It takes a single string as its argument so you'll want to use your shell's strictest quoting, e.g. in zsh:

bundle exec wordexp $'echo "hello there" \'blah blah\' "$(date)"'

You can also open up irb and interact with it there:

>> require 'wordexp'
=> true
>> Wordexp.expand('echo "hello there" \'blah blah\' "$(date)"')
=> ["echo", "hello there", "blah blah", "Sun 16 Jan 2022 22:43:08 PST"]
>> Wordexp.expand <<~EOT.strip
  echo "hello there" 'blah blah' "$(date)"
EOT
=> ["echo", "hello there", "blah blah", "Sun 16 Jan 2022 22:43:08 PST"]

Support

If you want to report a bug, or have ideas, feedback or questions about the gem, let me know via GitHub issues and I will do my best to provide a helpful answer. Happy hacking!

License

The gem is available as open source under the terms of the MIT License.

Code of conduct

Everyone interacting in this projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Contribution guide

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.