From 29e01282c796d352994a37e7dbbd938e8eeb62e5 Mon Sep 17 00:00:00 2001 From: Jae-Heon Ji Date: Tue, 29 Mar 2022 17:53:52 +0900 Subject: [PATCH 1/4] feat: add auto-start command --- zellij-utils/src/setup.rs | 30 ++++++++++++++++++++++++++ zellij-utils/src/shell/auto-start.fish | 6 ++++++ 2 files changed, 36 insertions(+) create mode 100644 zellij-utils/src/shell/auto-start.fish diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 96bbba41a1..6780956b44 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -136,10 +136,12 @@ pub struct Setup { /// Dump the default configuration file to stdout #[clap(long)] pub dump_config: bool, + /// Disables loading of configuration file at default location, /// loads the defaults that zellij ships with #[clap(long)] pub clean: bool, + /// Checks the configuration of zellij and displays /// currently used directories #[clap(long)] @@ -148,9 +150,14 @@ pub struct Setup { /// Dump the specified layout file to stdout #[clap(long)] pub dump_layout: Option, + /// Generates completion for the specified shell #[clap(long, value_name = "SHELL")] pub generate_completion: Option, + + /// Generates auto-start script for the specified shell + #[clap(long, value_name = "SHELL")] + pub generate_auto_start: Option, } impl Setup { @@ -242,6 +249,11 @@ impl Setup { std::process::exit(0); } + if let Some(shell) = &self.generate_auto_start { + Self::generate_auto_start(shell); + std::process::exit(0); + } + if let Some(layout) = &self.dump_layout { dump_specified_layout(layout)?; std::process::exit(0); @@ -405,6 +417,24 @@ impl Setup { _ => {} }; } + + fn generate_auto_start(shell: &str) { + let shell: Shell = match shell.to_lowercase().parse() { + Ok(shell) => shell, + _ => { + eprintln!("Unsupported shell: {}", shell); + std::process::exit(1); + } + }; + + match shell { + Shell::Fish => { + let script = include_str!("./shell/auto-start.fish"); + println!("{}", script); + } + _ => {} + } + } } #[cfg(test)] diff --git a/zellij-utils/src/shell/auto-start.fish b/zellij-utils/src/shell/auto-start.fish new file mode 100644 index 0000000000..091ca11d22 --- /dev/null +++ b/zellij-utils/src/shell/auto-start.fish @@ -0,0 +1,6 @@ +if not set -q ZELLIJ + zellij + + # auto quit the shell + kill $fish_pid +end From 2ebeb8d1b85f35a34b8fba29f6c3937d8f09683d Mon Sep 17 00:00:00 2001 From: Jae-Heon Ji Date: Mon, 18 Apr 2022 22:12:41 +0900 Subject: [PATCH 2/4] feat: add auto-start scripts --- zellij-utils/src/shell/auto-start.bash | 11 +++++++++++ zellij-utils/src/shell/auto-start.fish | 11 ++++++++--- zellij-utils/src/shell/auto-start.zsh | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 zellij-utils/src/shell/auto-start.bash create mode 100644 zellij-utils/src/shell/auto-start.zsh diff --git a/zellij-utils/src/shell/auto-start.bash b/zellij-utils/src/shell/auto-start.bash new file mode 100644 index 0000000000..2a050f0049 --- /dev/null +++ b/zellij-utils/src/shell/auto-start.bash @@ -0,0 +1,11 @@ +if [[ -z "$ZELLIJ" ]]; then + if [[ "$ZELLIJ_AUTO_ATTACH" == "true" ]]; then + zellij attach -c + else + zellij + fi + + if [[ "$ZELLIJ_AUTO_EXIT" == "true" ]]; then + exit + fi +fi diff --git a/zellij-utils/src/shell/auto-start.fish b/zellij-utils/src/shell/auto-start.fish index 091ca11d22..e3186085e6 100644 --- a/zellij-utils/src/shell/auto-start.fish +++ b/zellij-utils/src/shell/auto-start.fish @@ -1,6 +1,11 @@ if not set -q ZELLIJ - zellij + if test "$ZELLIJ_AUTO_ATTACH" = "true" + zellij attach -c + else + zellij + end - # auto quit the shell - kill $fish_pid + if test "$ZELLIJ_AUTO_EXIT" = "true" + suspend --force + end end diff --git a/zellij-utils/src/shell/auto-start.zsh b/zellij-utils/src/shell/auto-start.zsh new file mode 100644 index 0000000000..2a050f0049 --- /dev/null +++ b/zellij-utils/src/shell/auto-start.zsh @@ -0,0 +1,11 @@ +if [[ -z "$ZELLIJ" ]]; then + if [[ "$ZELLIJ_AUTO_ATTACH" == "true" ]]; then + zellij attach -c + else + zellij + fi + + if [[ "$ZELLIJ_AUTO_EXIT" == "true" ]]; then + exit + fi +fi From b85742417192d0f7ecdeb0f55712d7dac253cda9 Mon Sep 17 00:00:00 2001 From: Jae-Heon Ji Date: Mon, 18 Apr 2022 22:29:09 +0900 Subject: [PATCH 3/4] refactor: update script file location --- .../{src => assets}/shell/auto-start.bash | 0 .../{src => assets}/shell/auto-start.fish | 0 .../{src => assets}/shell/auto-start.zsh | 0 zellij-utils/src/setup.rs | 28 +++++++++++++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) rename zellij-utils/{src => assets}/shell/auto-start.bash (100%) rename zellij-utils/{src => assets}/shell/auto-start.fish (100%) rename zellij-utils/{src => assets}/shell/auto-start.zsh (100%) diff --git a/zellij-utils/src/shell/auto-start.bash b/zellij-utils/assets/shell/auto-start.bash similarity index 100% rename from zellij-utils/src/shell/auto-start.bash rename to zellij-utils/assets/shell/auto-start.bash diff --git a/zellij-utils/src/shell/auto-start.fish b/zellij-utils/assets/shell/auto-start.fish similarity index 100% rename from zellij-utils/src/shell/auto-start.fish rename to zellij-utils/assets/shell/auto-start.fish diff --git a/zellij-utils/src/shell/auto-start.zsh b/zellij-utils/assets/shell/auto-start.zsh similarity index 100% rename from zellij-utils/src/shell/auto-start.zsh rename to zellij-utils/assets/shell/auto-start.zsh diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 6780956b44..79392c2ee1 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -115,6 +115,24 @@ pub const FISH_EXTRA_COMPLETION: &[u8] = include_bytes!(concat!( "assets/completions/comp.fish" )); +pub const BASH_AUTO_START_SCRIPT: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/", + "assets/shell/auto-start.bash" +)); + +pub const FISH_AUTO_START_SCRIPT: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/", + "assets/shell/auto-start.fish" +)); + +pub const ZSH_AUTO_START_SCRIPT: &[u8] = include_bytes!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/", + "assets/shell/auto-start.zsh" +)); + pub fn dump_default_config() -> std::io::Result<()> { dump_asset(DEFAULT_CONFIG) } @@ -427,10 +445,16 @@ impl Setup { } }; + let mut out = std::io::stdout(); match shell { + Shell::Bash => { + let _ = out.write_all(BASH_AUTO_START_SCRIPT); + } Shell::Fish => { - let script = include_str!("./shell/auto-start.fish"); - println!("{}", script); + let _ = out.write_all(FISH_AUTO_START_SCRIPT); + } + Shell::Zsh => { + let _ = out.write_all(ZSH_AUTO_START_SCRIPT); } _ => {} } From b09577ccc04b3c62fda224d92cc8ca156c8286d1 Mon Sep 17 00:00:00 2001 From: Jae-Heon Ji Date: Wed, 20 Apr 2022 23:36:27 +0900 Subject: [PATCH 4/4] chore: change kill signal --- zellij-utils/assets/shell/auto-start.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zellij-utils/assets/shell/auto-start.fish b/zellij-utils/assets/shell/auto-start.fish index e3186085e6..c4b9e96755 100644 --- a/zellij-utils/assets/shell/auto-start.fish +++ b/zellij-utils/assets/shell/auto-start.fish @@ -6,6 +6,6 @@ if not set -q ZELLIJ end if test "$ZELLIJ_AUTO_EXIT" = "true" - suspend --force + kill $fish_pid end end