summaryrefslogtreecommitdiffstats
path: root/src/init
diff options
context:
space:
mode:
authorDavid Knaack <davidkna@users.noreply.github.com>2021-02-02 12:59:55 +0100
committerGitHub <noreply@github.com>2021-02-02 12:59:55 +0100
commit22dc8b842e721c440aa98035dd2dff30c7fe6497 (patch)
treeb4b15a181a96c75c6448e5f1a3d2ee9f1ae64973 /src/init
parent10d5a7034b006e8eacb1748cd27c020b614ded9f (diff)
feat: add support for elvish shell (#1725)
* 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
Diffstat (limited to 'src/init')
-rw-r--r--src/init/mod.rs10
-rw-r--r--src/init/starship.elv33
2 files changed, 43 insertions, 0 deletions
diff --git a/src/init/mod.rs b/src/init/mod.rs
index f80e8aedc..e8ff73ce2 100644
--- a/src/init/mod.rs
+++ b/src/init/mod.rs
@@ -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\
@@ -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\
@@ -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");
diff --git a/src/init/starship.elv b/src/init/starship.elv
new file mode 100644
index 000000000..1b84632a8
--- /dev/null
+++ b/src/init/starship.elv
@@ -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 = { }