Skip to content

Commit 7f79c49

Browse files
committed
Add --shell option to limactl shell
This allows to use a predictable shell for scripting, and also provides a way to recover an instance when the user shell has been misconfigured. Signed-off-by: Jan Dubois <[email protected]>
1 parent 68229f2 commit 7f79c49

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cmd/limactl/shell.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func newShellCommand() *cobra.Command {
3636

3737
shellCmd.Flags().SetInterspersed(false)
3838

39+
shellCmd.Flags().String("shell", "", "shell interpreter, e.g. /bin/bash")
3940
shellCmd.Flags().String("workdir", "", "working directory")
4041
return shellCmd
4142
}
@@ -108,7 +109,16 @@ func shellAction(cmd *cobra.Command, args []string) error {
108109
}
109110
logrus.Debugf("changeDirCmd=%q", changeDirCmd)
110111

111-
script := fmt.Sprintf("%s ; exec $SHELL --login", changeDirCmd)
112+
shell, err := cmd.Flags().GetString("shell")
113+
if err != nil {
114+
return err
115+
}
116+
if shell == "" {
117+
shell = `"$SHELL"`
118+
} else {
119+
shell = shellescape.Quote(shell)
120+
}
121+
script := fmt.Sprintf("%s ; exec %s --login", changeDirCmd, shell)
112122
if len(args) > 1 {
113123
script += fmt.Sprintf(
114124
" -c %s",

0 commit comments

Comments
 (0)