mirror of
https://github.com/samsonjs/csc360-a1-shell.git
synced 2026-03-25 08:45:52 +00:00
Use wordexp to support super fancy expansions
- Expands environment variables, e.g. $HOME -> /home/tina
- Expands tildes, e.g. ~/bin -> /home/queso/bin
- Performs command substitution, e.g. `date +%F` -> 2022-01-16
or $(date +%F) -> 2022-01-16
This commit is contained in:
parent
9faa33fbf2
commit
0d0bb73114
3 changed files with 7 additions and 3 deletions
|
|
@ -1,2 +1,4 @@
|
|||
source 'https://rubygems.org'
|
||||
ruby '3.1.0'
|
||||
|
||||
gem 'wordexp', '~> 0.1'
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
wordexp (0.1.1)
|
||||
|
||||
PLATFORMS
|
||||
arm64-darwin-21
|
||||
|
||||
DEPENDENCIES
|
||||
wordexp (~> 0.1)
|
||||
|
||||
RUBY VERSION
|
||||
ruby 3.1.0p0
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
require 'English'
|
||||
require 'open3'
|
||||
require 'readline'
|
||||
require 'shellwords'
|
||||
require 'wordexp'
|
||||
|
||||
require './builtins'
|
||||
require './colours'
|
||||
|
|
@ -92,9 +92,9 @@ class Shell
|
|||
exit 0 if line.nil? # EOF, ctrl-d
|
||||
return if line.empty? # no input, no-op
|
||||
|
||||
args = Shellwords.split(line)
|
||||
args = Wordexp.expand(line)
|
||||
cmd = args.shift
|
||||
logger.verbose "Words: #{cmd} #{args.inspect}"
|
||||
logger.verbose "Parsed command: #{cmd} #{args.inspect}"
|
||||
if @builtins.builtin?(cmd)
|
||||
logger.verbose "Executing builtin #{cmd}"
|
||||
@builtins.exec(cmd, args)
|
||||
|
|
|
|||
Loading…
Reference in a new issue