Skip to content

Commit e737022

Browse files
kemingyCopilot
andauthored
feat: support fish shell (#1952)
* feat: support fish shell Signed-off-by: Keming <kemingyang@tensorchord.ai> * Update pkg/lang/ir/v1/shell.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Keming <kemingy94@gmail.com> * fix lint Signed-off-by: Keming <kemingyang@tensorchord.ai> --------- Signed-off-by: Keming <kemingyang@tensorchord.ai> Signed-off-by: Keming <kemingy94@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1df6b9f commit e737022

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

pkg/lang/ir/v1/conda.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
const (
31-
builderImage = "curlimages/curl:7.86.0"
31+
builderImage = "curlimages/curl:8.11.1"
3232
condaVersionDefault = "py311_24.11.1-0"
3333
microMambaImage = "mambaorg/micromamba:1.0.0"
3434
condaRootPrefix = "/opt/conda"
@@ -39,10 +39,19 @@ const (
3939
channels:
4040
- defaults
4141
`
42-
mambaActivate = `
42+
mambaActivateBash = `
4343
#!/bin/sh
4444
eval "$(/opt/conda/bin/micromamba shell hook --shell=bash)" || return $?
4545
micromamba activate "$@"
46+
`
47+
mambaActivateFish = `
48+
#!/usr/bin/fish
49+
/opt/conda/bin/micromamba shell hook --shell=fish | source
50+
micromamba activate $argv
51+
`
52+
condaActivateFish = `
53+
#!/usr/bin/fish
54+
conda activate $argv
4655
`
4756
)
4857

@@ -174,6 +183,8 @@ func (g generalGraph) installMiniConda(root llb.State) llb.State {
174183
llb.WithCustomName("[internal] create conda directory")).
175184
Run(llb.Shlexf("bash -c '%s'", installCondaBash),
176185
llb.WithCustomName("[internal] install conda")).Root().
186+
File(llb.Mkfile(fmt.Sprintf("%s/activate.fish", condaBinDir), 0755, []byte(condaActivateFish)),
187+
llb.WithCustomName("[internal] create the conda activate.fish file")).
177188
File(llb.Rm(condaSourcePath), llb.WithCustomName("[internal] rm conda source file"))
178189
return conda
179190
}
@@ -194,8 +205,10 @@ func (g *generalGraph) installMicroMamba(root llb.State) llb.State {
194205
llb.WithCustomName("[internal] copy micromamba binary")).
195206
File(llb.Mkfile(fmt.Sprintf("%s/.mambarc", condaRootPrefix), 0644, []byte(mambaRc)),
196207
llb.WithCustomName("[internal] create the mamba rc file")).
197-
File(llb.Mkfile(fmt.Sprintf("%s/activate", condaBinDir), 0755, []byte(mambaActivate)),
208+
File(llb.Mkfile(fmt.Sprintf("%s/activate", condaBinDir), 0755, []byte(mambaActivateBash)),
198209
llb.WithCustomName("[internal] create the mamba activate file")).
210+
File(llb.Mkfile(fmt.Sprintf("%s/activate.fish", condaBinDir), 0755, []byte(mambaActivateFish)),
211+
llb.WithCustomName("[internal] create the mamba activate.fish file")).
199212
Run(llb.Shlexf("update-alternatives --install /usr/bin/conda conda %s/micromamba 1", condaBinDir),
200213
llb.WithCustomName("[internal] update alternative micromamba to conda")).
201214
Run(llb.Shlexf("bash -c \"%s/micromamba shell init --shell bash\"", condaBinDir),

pkg/lang/ir/v1/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func JuliaPackageServer(url string) error {
197197
func Shell(shell string) error {
198198
g := DefaultGraph.(*generalGraph)
199199

200-
g.Shell = shell
200+
g.Shell = strings.ToLower(shell)
201201
return nil
202202
}
203203

pkg/lang/ir/v1/shell.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ diverged = "<>"
5353
renamed = "r"
5454
deleted = "x"
5555
`
56+
57+
fishVersion = "4.0b1"
5658
)
5759

5860
func (g *generalGraph) compileShell(root llb.State) (_ llb.State, err error) {
@@ -63,6 +65,9 @@ func (g *generalGraph) compileShell(root llb.State) (_ llb.State, err error) {
6365
if err != nil {
6466
return llb.State{}, err
6567
}
68+
} else if g.Shell == shellFish {
69+
g.RuntimeEnviron["SHELL"] = "/usr/bin/fish"
70+
root = g.compileFish(root)
6671
}
6772
if g.CondaConfig != nil {
6873
root = g.compileCondaShell(root)
@@ -76,13 +81,17 @@ func (g *generalGraph) compileCondaShell(root llb.State) llb.State {
7681
findDir = fileutil.EnvdHomeDir
7782
}
7883
rcPath := findDir(".bashrc")
84+
activateFile := "activate"
7985
if g.Shell == shellZSH {
8086
rcPath = findDir(".zshrc")
87+
} else if g.Shell == shellFish {
88+
rcPath = findDir(".config/fish/config.fish")
89+
activateFile = "activate.fish"
8190
}
8291
run := root.
8392
Run(llb.Shlexf("bash -c \"%s\"", g.condaInitShell(g.Shell)),
8493
llb.WithCustomNamef("[internal] init conda %s env", g.Shell)).
85-
Run(llb.Shlexf(`bash -c 'echo "source %s/activate envd" >> %s'`, condaBinDir, rcPath),
94+
Run(llb.Shlexf(`bash -c 'echo "source %s/%s envd" >> %s'`, condaBinDir, activateFile, rcPath),
8695
llb.WithCustomNamef("[internal] add conda environment to %s", rcPath))
8796
return run.Root()
8897
}
@@ -102,6 +111,10 @@ func (g *generalGraph) compilePrompt(root llb.State) llb.State {
102111
run = run.Run(
103112
llb.Shlexf(`bash -c 'echo "eval \"\$(starship init zsh)\"" >> %s'`, fileutil.EnvdHomeDir(".zshrc")),
104113
llb.WithCustomName("[internal] setting prompt zsh config")).Root()
114+
} else if g.Shell == shellFish {
115+
run = run.Run(
116+
llb.Shlexf(`bash -c 'echo "starship init fish | source" >> %s'`, fileutil.EnvdHomeDir(".config/fish/config.fish")),
117+
llb.WithCustomName("[internal] setting prompt fish config")).Root()
105118
}
106119
return run
107120
}
@@ -126,3 +139,18 @@ func (g generalGraph) compileZSH(root llb.State) (llb.State, error) {
126139
File(llb.Mkfile(zshrcPath, 0666, []byte(m.ZSHRC())))
127140
return zshrc, nil
128141
}
142+
143+
func (g generalGraph) compileFish(root llb.State) llb.State {
144+
base := llb.Image(builderImage)
145+
builder := base.Run(
146+
llb.Shlexf(`sh -c "wget -qO- https://github.com/fish-shell/fish-shell/releases/download/%s/fish-static-linux-$(uname -m).tar.xz | tar -xJf - -C /tmp || exit 1"`, fishVersion),
147+
llb.WithCustomName("[internal] download fish shell"),
148+
).Root()
149+
root = root.File(
150+
llb.Copy(builder, "/tmp/fish", "/usr/bin/fish"),
151+
llb.WithCustomName("[internal] copy fish shell from the builder image")).
152+
Run(llb.Shlex("fish --install"),
153+
llb.WithCustomName("[internal] install fish shell")).Root()
154+
155+
return root
156+
}

pkg/lang/ir/v1/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ type generalGraph struct {
9797
const (
9898
shellBASH = "bash"
9999
shellZSH = "zsh"
100+
shellFish = "fish"
100101
)

0 commit comments

Comments
 (0)