mirror of
https://github.com/samsonjs/csc360-a1-shell.git
synced 2026-04-27 14:57:43 +00:00
Fix tilde user expansion
This commit is contained in:
parent
826b4d5594
commit
52ef7cb7f5
1 changed files with 6 additions and 1 deletions
|
|
@ -68,7 +68,12 @@ module Shell
|
||||||
found_glob_char = word && word =~ /[*?\[]/ # must be unquoted
|
found_glob_char = word && word =~ /[*?\[]/ # must be unquoted
|
||||||
# Expand tildes at the beginning of unquoted words.
|
# Expand tildes at the beginning of unquoted words.
|
||||||
if word && at_word_start
|
if word && at_word_start
|
||||||
field.sub!(/^~/, Dir.home)
|
field.sub!(/^~([^\/]*)/) do
|
||||||
|
user = Regexp.last_match(1)
|
||||||
|
user.empty? ? Dir.home : Dir.home(user)
|
||||||
|
rescue ArgumentError
|
||||||
|
"~#{user}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
at_word_start = false
|
at_word_start = false
|
||||||
if sep
|
if sep
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue