Skip to content

Commit f9842b1

Browse files
committed
Stop defaulting to Zsh and allow unspecified shell
This change removes the default shell of Zsh and allows you to use Sheldon without specifying a particular shell.
1 parent a804ff2 commit f9842b1

File tree

25 files changed

+113
-84
lines changed

25 files changed

+113
-84
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
- Local plugins.
2121
- Inline plugins.
2222
- Highly configurable install methods using templates.
23-
- Shell agnostic, with sensible defaults for Zsh.
23+
- Shell agnostic, with sensible defaults for Bash or Zsh
2424
- Super-fast plugin loading and parallel installation. See [benchmarks].
2525
- Config file using [TOML](https://toml.io) syntax.
26-
- Clean `~/.zshrc` or `~/.bashrc` (just add 1 line).
26+
- Clean `~/.bashrc` or `~/.zshrc` (just add 1 line).
2727

2828
[benchmarks]: https://github.com/rossmacarthur/zsh-plugin-manager-benchmark
2929

docs/README_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
- Local plugins.
2121
- Inline plugins.
2222
- Highly configurable install methods using templates.
23-
- Shell agnostic, with sensible defaults for Zsh.
23+
- Shell agnostic, with sensible defaults for Bash or Zsh
2424
- Super-fast plugin loading and parallel installation. See [benchmarks].
2525
- Config file using [TOML](https://toml.io) syntax.
26-
- Clean `~/.zshrc` or `~/.bashrc` (just add 1 line).
26+
- Clean `~/.bashrc` or `~/.zshrc` (just add 1 line).
2727

2828
[benchmarks]: https://github.com/rossmacarthur/zsh-plugin-manager-benchmark
2929

src/config/file.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ impl_serialize_as_str! { GitHubRepository }
175175
// Deserialization implementations
176176
////////////////////////////////////////////////////////////////////////////////
177177

178-
impl Default for Shell {
179-
fn default() -> Self {
180-
Self::Zsh
181-
}
182-
}
183-
184178
/// Produced when we fail to parse the shell type.
185179
#[derive(Debug, Error)]
186180
#[error("expected one of `bash` or `zsh`, got `{}`", self.0)]

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use crate::config::profile::MatchesProfile;
2525
#[derive(Debug)]
2626
pub struct Config {
2727
/// What type of shell is being used.
28-
pub shell: Shell,
28+
pub shell: Option<Shell>,
2929
/// Which files to match and use in a plugin's directory.
3030
pub matches: Option<Vec<String>>,
3131
/// The default list of template names to apply to each matched file.

src/config/normalize.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ pub fn normalize(raw_config: RawConfig, warnings: &mut Vec<Error>) -> Result<Con
3939
.with_context(|| format!("failed to compile template `{name}`"))?;
4040
}
4141

42-
let shell = shell.unwrap_or_default();
43-
4442
validate_template_names(shell, &apply, &templates)?;
4543

4644
// Normalize the plugins.
@@ -69,7 +67,7 @@ pub fn normalize(raw_config: RawConfig, warnings: &mut Vec<Error>) -> Result<Con
6967
fn normalize_plugin(
7068
raw_plugin: RawPlugin,
7169
name: String,
72-
shell: Shell,
70+
shell: Option<Shell>,
7371
templates: &IndexMap<String, String>,
7472
warnings: &mut Vec<Error>,
7573
) -> Result<Plugin> {
@@ -250,14 +248,30 @@ where
250248

251249
/// Check whether the specifed templates actually exist.
252250
fn validate_template_names(
253-
shell: Shell,
251+
shell: Option<Shell>,
254252
apply: &Option<Vec<String>>,
255253
templates: &IndexMap<String, String>,
256254
) -> Result<()> {
257255
if let Some(apply) = apply {
258256
for name in apply {
259-
if !shell.default_templates().contains_key(name) && !templates.contains_key(name) {
260-
bail!("unknown template `{name}`");
257+
if !templates.contains_key(name)
258+
&& !shell
259+
.map(|s| s.default_templates().contains_key(name))
260+
.unwrap_or(false)
261+
{
262+
match shell {
263+
Some(shell) => {
264+
if !shell.default_templates().contains_key(name) {
265+
bail!("unknown template `{name}`");
266+
}
267+
}
268+
None => {
269+
bail!(
270+
"unknown template `{name}` (help: set `shell` to use default \
271+
templates)"
272+
);
273+
}
274+
}
261275
}
262276
}
263277
}
@@ -297,7 +311,7 @@ mod tests {
297311
let err = normalize_plugin(
298312
raw,
299313
"test".to_string(),
300-
Shell::default(),
314+
Some(Shell::Zsh),
301315
&IndexMap::new(),
302316
&mut Vec::new(),
303317
)
@@ -330,7 +344,7 @@ mod tests {
330344
let plugin = normalize_plugin(
331345
raw_plugin,
332346
name,
333-
Shell::default(),
347+
Some(Shell::Zsh),
334348
&IndexMap::new(),
335349
&mut Vec::new(),
336350
)
@@ -368,7 +382,7 @@ mod tests {
368382
let plugin = normalize_plugin(
369383
raw_plugin,
370384
name,
371-
Shell::default(),
385+
Some(Shell::Zsh),
372386
&IndexMap::new(),
373387
&mut Vec::new(),
374388
)
@@ -399,7 +413,7 @@ mod tests {
399413
let plugin = normalize_plugin(
400414
raw_plugin,
401415
name,
402-
Shell::default(),
416+
Some(Shell::Zsh),
403417
&IndexMap::new(),
404418
&mut Vec::new(),
405419
)
@@ -437,7 +451,7 @@ mod tests {
437451
let plugin = normalize_plugin(
438452
raw_plugin,
439453
name,
440-
Shell::default(),
454+
Some(Shell::Zsh),
441455
&IndexMap::new(),
442456
&mut Vec::new(),
443457
)
@@ -471,7 +485,7 @@ mod tests {
471485
let plugin = normalize_plugin(
472486
raw_plugin,
473487
name,
474-
Shell::default(),
488+
Some(Shell::Zsh),
475489
&IndexMap::new(),
476490
&mut Vec::new(),
477491
)
@@ -504,7 +518,7 @@ mod tests {
504518
let plugin = normalize_plugin(
505519
raw_plugin,
506520
name,
507-
Shell::default(),
521+
Some(Shell::Zsh),
508522
&IndexMap::new(),
509523
&mut Vec::new(),
510524
)
@@ -538,7 +552,7 @@ mod tests {
538552
let plugin = normalize_plugin(
539553
raw_plugin,
540554
name,
541-
Shell::default(),
555+
Some(Shell::Zsh),
542556
&IndexMap::new(),
543557
&mut Vec::new(),
544558
)
@@ -568,7 +582,7 @@ mod tests {
568582
let plugin = normalize_plugin(
569583
raw_plugin,
570584
name,
571-
Shell::default(),
585+
Some(Shell::Zsh),
572586
&IndexMap::new(),
573587
&mut Vec::new(),
574588
)
@@ -591,7 +605,7 @@ mod tests {
591605
let err = normalize_plugin(
592606
raw_plugin,
593607
"test".to_string(),
594-
Shell::default(),
608+
Some(Shell::Zsh),
595609
&IndexMap::new(),
596610
&mut Vec::new(),
597611
)
@@ -617,7 +631,7 @@ mod tests {
617631
let err = normalize_plugin(
618632
raw_plugin,
619633
"test".to_string(),
620-
Shell::default(),
634+
Some(Shell::Zsh),
621635
&IndexMap::new(),
622636
&mut Vec::new(),
623637
)
@@ -649,7 +663,7 @@ mod tests {
649663
let plugin = normalize_plugin(
650664
raw_plugin,
651665
name,
652-
Shell::default(),
666+
Some(Shell::Zsh),
653667
&IndexMap::new(),
654668
&mut Vec::new(),
655669
)
@@ -673,7 +687,7 @@ mod tests {
673687
let plugin = normalize_plugin(
674688
raw_plugin,
675689
name,
676-
Shell::default(),
690+
Some(Shell::Zsh),
677691
&IndexMap::new(),
678692
&mut Vec::new(),
679693
)
@@ -691,7 +705,7 @@ mod tests {
691705
let err = normalize_plugin(
692706
raw_plugin,
693707
"test".to_string(),
694-
Shell::default(),
708+
Some(Shell::Zsh),
695709
&IndexMap::new(),
696710
&mut Vec::new(),
697711
)
@@ -715,7 +729,7 @@ mod tests {
715729
let err = normalize_plugin(
716730
raw_plugin,
717731
"test".to_string(),
718-
Shell::default(),
732+
Some(Shell::Zsh),
719733
&IndexMap::new(),
720734
&mut Vec::new(),
721735
)

src/lock/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ pub fn config(ctx: &Context, config: Config) -> Result<LockedConfig> {
5757
} = config;
5858

5959
let templates = {
60-
let mut map = shell.default_templates().clone();
60+
let mut map = shell
61+
.map(|s| s.default_templates().clone())
62+
.unwrap_or_default();
6163
for (name, template) in templates {
6264
map.insert(name, template);
6365
}
@@ -88,8 +90,10 @@ pub fn config(ctx: &Context, config: Config) -> Result<LockedConfig> {
8890

8991
let matches = matches
9092
.as_deref()
91-
.unwrap_or_else(|| shell.default_matches());
92-
let apply = apply.as_ref().unwrap_or_else(|| Shell::default_apply());
93+
.or_else(|| shell.map(|s| s.default_matches()));
94+
let apply = apply
95+
.as_deref()
96+
.or_else(|| shell.map(|s| s.default_apply()));
9397
let count = map.len();
9498
let mut errors = Vec::new();
9599

@@ -171,7 +175,7 @@ pub fn config(ctx: &Context, config: Config) -> Result<LockedConfig> {
171175

172176
impl Shell {
173177
/// The default files to match on for this shell.
174-
fn default_matches(&self) -> &[String] {
178+
fn default_matches(&self) -> &'static [String] {
175179
static DEFAULT_MATCHES_BASH: Lazy<Vec<String>> = Lazy::new(|| {
176180
vec_into![
177181
"{{ name }}.plugin.bash",
@@ -225,7 +229,7 @@ impl Shell {
225229
}
226230

227231
/// The default template names to apply.
228-
fn default_apply() -> &'static Vec<String> {
232+
fn default_apply(&self) -> &'static [String] {
229233
static DEFAULT_APPLY: Lazy<Vec<String>> = Lazy::new(|| vec_into!["source"]);
230234
&DEFAULT_APPLY
231235
}
@@ -316,7 +320,7 @@ mod tests {
316320
let dir = temp.path();
317321
let ctx = Context::testing(dir);
318322
let cfg = Config {
319-
shell: Shell::Zsh,
323+
shell: Some(Shell::Zsh),
320324
matches: None,
321325
apply: None,
322326
templates: IndexMap::new(),
@@ -327,10 +331,7 @@ mod tests {
327331

328332
assert_eq!(locked.ctx, ctx);
329333
assert_eq!(locked.plugins, Vec::new());
330-
assert_eq!(
331-
locked.templates,
332-
Shell::default().default_templates().clone(),
333-
);
334+
assert_eq!(locked.templates, Shell::Zsh.default_templates().clone(),);
334335
assert_eq!(locked.errors.len(), 0);
335336
}
336337

@@ -339,7 +340,7 @@ mod tests {
339340
let temp = tempfile::tempdir().expect("create temporary directory");
340341
let ctx = Context::testing(temp.path());
341342
let cfg = Config {
342-
shell: Shell::Zsh,
343+
shell: Some(Shell::Zsh),
343344
matches: None,
344345
apply: None,
345346
templates: IndexMap::new(),

0 commit comments

Comments
 (0)