Skip to content

Commit 305465e

Browse files
unhappychoiceclaude
andcommitted
feat(shell): add Nushell init snippet + variant
Add Shell::Nushell alongside bash/zsh/fish/powershell, accepted as 'nushell' (with 'nu' alias) by clap. The new src/shells/nushell.nu defensively builds out $env.config.hooks.env_change.PWD so it preserves any pre-existing hooks, and guards against the first-prompt firing ($before == null) to avoid double-splashing alongside the explicit startup '^splashboard' call. source_line returns the snippet itself for Nushell rather than the eval-on-startup one-liner the POSIX shells use, because Nushell's 'source' command requires a parse-time constant path. The rc wiring layer therefore embeds the snippet verbatim between marker comments. Refs #246 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 0298646 commit 305465e

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎src/shell.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ const BASH: &str = include_str!("shells/bash.sh");
66
const ZSH: &str = include_str!("shells/zsh.sh");
77
const FISH: &str = include_str!("shells/fish.fish");
88
const POWERSHELL: &str = include_str!("shells/powershell.ps1");
9+
const NUSHELL: &str = include_str!("shells/nushell.nu");
910

1011
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
1112
pub enum Shell {
1213
Bash,
1314
Zsh,
1415
Fish,
1516
Powershell,
17+
#[value(alias = "nu")]
18+
Nushell,
1619
}
1720

1821
impl Shell {
@@ -22,6 +25,7 @@ impl Shell {
2225
Shell::Zsh => "zsh",
2326
Shell::Fish => "fish",
2427
Shell::Powershell => "powershell",
28+
Shell::Nushell => "nushell",
2529
}
2630
}
2731
}
@@ -32,6 +36,7 @@ pub fn init_snippet(shell: Shell) -> &'static str {
3236
Shell::Zsh => ZSH,
3337
Shell::Fish => FISH,
3438
Shell::Powershell => POWERSHELL,
39+
Shell::Nushell => NUSHELL,
3540
}
3641
}
3742

@@ -67,6 +72,7 @@ fn classify_shell_path(path: &str) -> Option<Shell> {
6772
"zsh" => Some(Shell::Zsh),
6873
"fish" => Some(Shell::Fish),
6974
"pwsh" | "powershell" => Some(Shell::Powershell),
75+
"nu" | "nushell" => Some(Shell::Nushell),
7076
_ => None,
7177
}
7278
}
@@ -87,17 +93,27 @@ pub fn default_rc_path(shell: Shell) -> Option<PathBuf> {
8793
.join("Documents")
8894
.join("PowerShell")
8995
.join("Microsoft.PowerShell_profile.ps1"),
96+
// Nushell's config can live elsewhere (`~/Library/Application Support/nushell/`
97+
// on macOS, `%APPDATA%\nushell\` on Windows), but `~/.config/nushell/config.nu`
98+
// is the documented default on Linux and works on macOS too. Users on other
99+
// layouts pass `--rc-path` to `splashboard install`.
100+
Shell::Nushell => home.join(".config").join("nushell").join("config.nu"),
90101
})
91102
}
92103

93104
/// Source line appended inside the marker block; delegates to `splashboard init <shell>`
94-
/// so any snippet update lands automatically on next shell start.
105+
/// so any snippet update lands automatically on next shell start. Nushell is the odd
106+
/// one out: its `source` command requires a parse-time constant path, so we can't use
107+
/// the same eval-on-startup indirection. Instead `source_line` returns the snippet
108+
/// itself for Nushell, which `format_block` embeds verbatim between markers — re-running
109+
/// `splashboard install` rewrites the block in place when the snippet changes.
95110
pub fn source_line(shell: Shell) -> &'static str {
96111
match shell {
97112
Shell::Bash => "eval \"$(splashboard init bash)\"",
98113
Shell::Zsh => "eval \"$(splashboard init zsh)\"",
99114
Shell::Fish => "splashboard init fish | source",
100115
Shell::Powershell => "Invoke-Expression (& splashboard init powershell | Out-String)",
116+
Shell::Nushell => NUSHELL,
101117
}
102118
}
103119

‎src/shells/nushell.nu‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# splashboard — render on new shell and on directory change
2+
$env.config = ($env.config? | default {})
3+
$env.config.hooks = ($env.config.hooks? | default {})
4+
$env.config.hooks.env_change = ($env.config.hooks.env_change? | default {})
5+
$env.config.hooks.env_change.PWD = (
6+
$env.config.hooks.env_change.PWD?
7+
| default []
8+
| append {|before, after| if $before != null and $before != $after { ^splashboard --on-cd } }
9+
)
10+
^splashboard

0 commit comments

Comments
 (0)