Skip to content

Commit

Permalink
feat: add support for elvish shell (starship#1725)
Browse files Browse the repository at this point in the history
* feat: add support for elvish shell

* improve doc

* elvish 0.15 is out

* fix example init

* update systax for 0.15 stable

* udpate second init example too

* remove warning from swift module

* add warning to status module docs

* prefix elvish version with v
  • Loading branch information
davidkna authored Feb 2, 2021
1 parent 10d5a70 commit 22dc8b8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ shown below. Can't see yours? Have a look at the [extra platform instructions](h
eval $(starship init ion)
```

#### Elvish

**Warning** Only elvish v0.15 or higher is supported.
Add the following to the end of `~/.elvish/rc.elv`:

```sh
# ~/.elvish/rc.elv

eval (starship init elvish)
```

## 🤝 Contributing

We are always looking for contributors of **all skill levels**! If you're looking to ease your way into the project, try out a [good first issue](https://github.com/starship/starship/labels/🌱%20good%20first%20issue).
Expand Down
14 changes: 14 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ description: Starship is the minimal, blazing fast, and extremely customizable p

eval $(starship init ion)
```
#### Elvish

::: warning
Only elvish v0.15 or higher is supported.
:::

Add the following to the end of `~/.elvish/rc.elv`:

```sh
# ~/.elvish/rc.elv

eval (starship init elvish)
```

8 changes: 8 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ can do this in two ways:

By default it only changes color. If you also want to change it's shape take a
look at [this example](#with-custom-error-shape).

::: warning
`error_symbol` is not supported on elvish shell.
:::

### Options

Expand Down Expand Up @@ -2263,6 +2267,10 @@ To enable it, set `disabled` to `false` in your configuration file.

:::

::: warning
This module is not supported on elvish shell.
:::

### Options

| Option | Default | Description |
Expand Down
1 change: 1 addition & 0 deletions src/bug_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ fn get_config_path(shell: &str) -> Option<PathBuf> {
}
}
"zsh" => Some(".zshrc"),
"elvish" => Some(".elvish/rc.elv"),
_ => None,
}
.map(|path| home_dir.join(path))
Expand Down
2 changes: 2 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl<'a> Context<'a> {
"ion" => Shell::Ion,
"powershell" => Shell::PowerShell,
"zsh" => Shell::Zsh,
"elvish" => Shell::Elvish,
_ => Shell::Unknown,
}
}
Expand Down Expand Up @@ -426,6 +427,7 @@ pub enum Shell {
Ion,
PowerShell,
Zsh,
Elvish,
Unknown,
}

Expand Down
10 changes: 10 additions & 0 deletions src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ fi"#,
let script = format!("eval $({} init ion --print-full-init)", starship.sprint()?);
Some(script)
}
Some("elvish") => {
let script = format!(
"eval ({} init elvish --print-full-init | slurp)",
starship.sprint_posix()?
);
Some(script)
}
None => {
println!(
"Invalid shell name provided: {}\\n\
Expand Down Expand Up @@ -204,6 +211,7 @@ pub fn init_main(shell_name: &str) -> io::Result<()> {
"fish" => print_script(FISH_INIT, &starship_path.sprint_posix()?),
"powershell" => print_script(PWSH_INIT, &starship_path.sprint()?),
"ion" => print_script(ION_INIT, &starship_path.sprint()?),
"elvish" => print_script(ELVISH_INIT, &starship_path.sprint_posix()?),
_ => {
println!(
"printf \"Shell name detection failed on phase two init.\\n\
Expand Down Expand Up @@ -245,3 +253,5 @@ const FISH_INIT: &str = include_str!("starship.fish");
const PWSH_INIT: &str = include_str!("starship.ps1");

const ION_INIT: &str = include_str!("starship.ion");

const ELVISH_INIT: &str = include_str!("starship.elv");
33 changes: 33 additions & 0 deletions src/init/starship.elv
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set-env STARSHIP_SHELL "elvish"
set-env STARSHIP_SESSION_KEY (::STARSHIP:: session)

# Define Hooks
local:cmd-start-time = 0
local:cmd-end-time = 0

fn starship-after-readline-hook [line]{
cmd-start-time = (::STARSHIP:: time)
}

fn starship-before-readline-hook {
cmd-end-time = (::STARSHIP:: time)
}

# Install Hooks
edit:after-readline = [ $@edit:after-readline $starship-after-readline-hook~ ]
edit:before-readline = [ $@edit:before-readline $starship-before-readline-hook~ ]

# Install starship
edit:prompt = {
# Note:
# Elvish does not appear to support exit status codes (--status)

if (== $cmd-start-time 0) {
::STARSHIP:: prompt --jobs=$num-bg-jobs
} else {
::STARSHIP:: prompt --jobs=$num-bg-jobs --cmd-duration=(- $cmd-end-time $cmd-start-time)
}
}

# Get rid of default rprompt
edit:rprompt = { }
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {
let shell_arg = Arg::with_name("shell")
.value_name("SHELL")
.help(
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion",
"The name of the currently running shell\nCurrently supported options: bash, zsh, fish, powershell, ion, elvish",
)
.required(true);

Expand Down

0 comments on commit 22dc8b8

Please sign in to comment.