Skip to content

Commit 21894b2

Browse files
committed
Provide a fish shell toggle for swiftly one-liners
Make code blocks wrap on limited horizontal space
1 parent f34121d commit 21894b2

File tree

3 files changed

+83
-14
lines changed

3 files changed

+83
-14
lines changed

_includes/install/_linux_platforms_tabs.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,42 @@
55
<p class="description">
66
The Swiftly installer manages Swift and its dependencies. It supports switching between different versions and downloading updates.
77
</p>
8-
<h4>Run this in a terminal:</h4>
9-
<div class="language-plaintext highlighter-rouge"><div class="highlight"><button>Copy</button><pre class="highlight"><code>curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz &amp;&amp; \
10-
tar zxf swiftly-$(uname -m).tar.gz &amp;&amp; \
11-
./swiftly init --quiet-shell-followup &amp;&amp; \
12-
. ~/.local/share/swiftly/env.sh &amp;&amp; \
13-
hash -r
14-
</code></pre></div></div>
8+
<div class="shellcode-intro">Run this in a terminal:<button id="shell" class="toggle">fish</button></div>
9+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><button>Copy</button><pre class="highlight"><code id="shellcode" style="white-space: initial;"></code></pre></div></div>
1510
<h4>License: <a href="https://raw.githubusercontent.com/swiftlang/swiftly/refs/heads/main/LICENSE.txt">Apache-2.0</a> | PGP: <a href="https://download.swift.org/swiftly/linux/swiftly-0.4.0-dev-x86_64.tar.gz.sig">Signature</a></h4>
1611
<a href="/install/linux/swiftly" class="cta-secondary">Instructions</a>
1712
</li>
1813
</ul>
14+
15+
<script>
16+
var shell = "";
17+
var shellToggle = document.getElementById("shell");
18+
var code = document.getElementById("shellcode");
19+
20+
function setShell() {
21+
code.innerText = "curl -O https://download.swift.org/swiftly/linux/swiftly-$(uname -m).tar.gz && \\\n"
22+
code.innerText += "tar zxf swiftly-$(uname -m).tar.gz && \\\n"
23+
code.innerText += "./swiftly init --quiet-shell-followup && \\\n"
24+
25+
if (shell == "sh") {
26+
shell = "fish";
27+
code.innerText += ". ~/.swiftly/env.fish"
28+
shellToggle.innerText = "sh";
29+
} else {
30+
shell = "sh";
31+
code.innerText += ". ${SWIFTLY_HOME_DIR:-~/.swiftly}/env.sh && \\\n"
32+
code.innerText += "hash -r"
33+
shellToggle.innerText = "fish";
34+
}
35+
}
36+
37+
setShell();
38+
39+
shellToggle.addEventListener("mousedown", function() {
40+
setShell();
41+
});
42+
</script>
43+
1944
<ul class="grid-level-0 grid-layout-1-column">
2045
<li class="grid-level-1">
2146
<h3>Container</h3>

assets/stylesheets/elements/_grid.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,23 @@ div.highlight {
131131
margin: 0;
132132
display: none;
133133
}
134+
135+
button.toggle {
136+
width: fit-content;
137+
float: right;
138+
margin-right: 1.1rem;
139+
background-color: var(--color-fill-tertiary);
140+
border: 1px solid var(--color-fill-quaternary);
141+
border-radius: var(--border-radius);
142+
143+
&:hover {
144+
color: var(--color-link);
145+
background-color: var(--color-fill-quaternary);
146+
}
147+
}
148+
149+
.shellcode-intro {
150+
font-size: .8rem;
151+
color: var(--color-secondary-label);
152+
padding-top: 0.8rem;
153+
}

install/macos/index.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ title: Install Swift
1212
<p class="description">
1313
To download toolchains from Swift.org, use the Swiftly toolchain installer. Swift.org toolchains include experimental features like Embedded Swift and support for WebAssembly.
1414
</p>
15-
<h4>Run this in a terminal:</h4>
16-
<div class="language-plaintext highlighter-rouge"><div class="highlight"><button>Copy</button><pre class="highlight"><code>curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg &amp;&amp; \
17-
installer -pkg swiftly.pkg -target CurrentUserHomeDirectory &amp;&amp; \
18-
~/.swiftly/bin/swiftly init --quiet-shell-followup &amp;&amp; \
19-
. ~/.swiftly/env.sh &amp;&amp; \
20-
hash -r
21-
</code></pre></div></div>
15+
<div class="shellcode-intro">Run this in a terminal:<button id="shell" class="toggle"></button></div>
16+
<div class="language-plaintext highlighter-rouge"><div class="highlight"><button>Copy</button><pre style="white-space: initial;" class="highlight"><code id="shellcode"></code></pre></div></div>
2217
<h4>License: <a href="https://raw.githubusercontent.com/swiftlang/swiftly/refs/heads/main/LICENSE.txt">Apache-2.0</a></h4>
2318
<a href="/install/macos/swiftly" class="cta-secondary">Instructions</a>
2419
</li>
@@ -32,6 +27,35 @@ hash -r
3227
<a href="https://developer.apple.com/xcode/" class="cta-secondary external">Install Xcode</a>
3328
</li>
3429
</ul>
30+
<script>
31+
32+
var shell = "";
33+
var shellToggle = document.getElementById("shell");
34+
var code = document.getElementById("shellcode");
35+
36+
function setShell() {
37+
code.innerText = "curl -O https://download.swift.org/swiftly/darwin/swiftly.pkg && \\\n"
38+
code.innerText += "installer -pkg swiftly.pkg -target CurrentUserHomeDirectory && \\\n"
39+
code.innerText += "~/.swiftly/bin/swiftly init --quiet-shell-followup && \\\n"
40+
41+
if (shell == "sh") {
42+
shell = "fish";
43+
code.innerText += ". ~/.swiftly/env.fish"
44+
shellToggle.innerText = "sh";
45+
} else {
46+
shell = "sh";
47+
code.innerText += ". ${SWIFTLY_HOME_DIR:-~/.swiftly}/env.sh && \\\n"
48+
code.innerText += "hash -r"
49+
shellToggle.innerText = "fish";
50+
}
51+
}
52+
53+
setShell();
54+
55+
shellToggle.addEventListener("mousedown", function() {
56+
setShell();
57+
});
58+
</script>
3559

3660

3761
## Other Install Options

0 commit comments

Comments
 (0)