Skip to content

Commit

Permalink
Automatically detect available shell when using the 'exec' hook (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jun 25, 2017
1 parent 1801394 commit a858826
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,7 @@ Host *

### master (unreleased)

* Automatically detect available shell when using the 'exec' hook ([#254](https://github.com/moul/advanced-ssh-config/issues/254))
* Automatically detect if `-q` is passed to the parent ssh process to disable logging ([#253](https://github.com/moul/advanced-ssh-config/pull/253)) by [@cao](https://github.com/cao)
* Add a new `%g` (gateway) parameter to `ResolveCommand` and `ProxyCommand` ([#247](https://github.com/moul/advanced-ssh-config/pull/247)
* Fix panic on particular `assh.yml` files
Expand Down
22 changes: 21 additions & 1 deletion pkg/hooks/driver_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package hooks

import (
"bytes"
"fmt"
"os"
"os/exec"
"strings"

"github.com/moul/advanced-ssh-config/pkg/templates"
)
Expand Down Expand Up @@ -32,7 +34,25 @@ func (d ExecDriver) Run(args RunArgs) error {
return err
}

cmd := exec.Command("/bin/sh", "-c", buff.String())
var (
availableShells = []string{"/bin/sh", "/bin/bash", "/bin/zsh"}
selectedShell = ""
)
for _, shell := range availableShells {
info, err := os.Stat(shell)
if err != nil {
continue
}
if info.Mode()&0111 != 0 {
selectedShell = shell
break
}
}
if selectedShell == "" {
return fmt.Errorf("No available shell found. (tried %s)", strings.Join(availableShells, ", "))
}

cmd := exec.Command(selectedShell, "-c", buff.String())
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
Expand Down

0 comments on commit a858826

Please sign in to comment.