Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions translate/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,33 @@ func (t *Translator) assign(prefix string, a *syntax.Assign) {
}
}

func (t *Translator) parseSetExpr(args []*syntax.Word) bool {
if len(args) < 2 {
return false
}

next, _ := lit(args[1])

if next == "--" {
if len(args) > 2 {
t.str("set argv")
for _, arg := range args[2:] {
t.str(" ")
t.word(arg, false)
}
}
return true
}

for _, arg := range args[1:] {
flag, _ := lit(arg)
if !strings.HasPrefix(flag, "-") {
return false
}
}
return true
}

func (t *Translator) callExpr(c *syntax.CallExpr) {
if len(c.Args) == 0 {
// assignment
Expand All @@ -447,7 +474,12 @@ func (t *Translator) callExpr(c *syntax.CallExpr) {

first := c.Args[0]
l, _ := lit(first)

switch l {
case "set":
if t.parseSetExpr(c.Args) {
return
}
case "shift":
t.str("set -e argv[1]")
case "unset":
Expand Down
4 changes: 4 additions & 0 deletions translate/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ echo ${cool+a}
echo ${cool:+a}
echo ${cool-a}
echo ${cool:-a}
set -Cefu
Comment thread
Neved4 marked this conversation as resolved.
set -- x y z
unset ASPELL_CONF
for i in a b c ; do
if [ -d "$i/lib/aspell" ]; then
Expand Down Expand Up @@ -392,6 +394,8 @@ echo (set -q cool && echo 'a' || echo)
echo (test -n "$cool" && echo 'a' || echo)
echo (set -q cool && echo "$cool" || echo 'a')
echo (test -n "$cool" && echo "$cool" || echo 'a')

set argv x y z
set -e ASPELL_CONF
for i in a b c
if [ -d "$i"'/lib/aspell' ]
Expand Down