aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJae-Heon Ji <32578710+jaeheonji@users.noreply.github.com>2022-04-21 00:28:09 +0900
committerGitHub <noreply@github.com>2022-04-21 00:28:09 +0900
commitbe0af7e69c141ed709c09765988820c6f8f31945 (patch)
treec71e35de65bd577c016c37cc7c46539b31e6472c
parentflake.lock: Update (#1331) (diff)
downloadsl0ppij-be0af7e69c141ed709c09765988820c6f8f31945.tar.gz
sl0ppij-be0af7e69c141ed709c09765988820c6f8f31945.tar.xz
sl0ppij-be0af7e69c141ed709c09765988820c6f8f31945.zip
feat: support the command of auto-start script for shell (#1281)
-rw-r--r--zellij-utils/assets/shell/auto-start.bash11
-rw-r--r--zellij-utils/assets/shell/auto-start.fish11
-rw-r--r--zellij-utils/assets/shell/auto-start.zsh11
-rw-r--r--zellij-utils/src/setup.rs54
4 files changed, 87 insertions, 0 deletions
diff --git a/zellij-utils/assets/shell/auto-start.bash b/zellij-utils/assets/shell/auto-start.bash
new file mode 100644
index 00000000..2a050f00
--- /dev/null
+++ b/zellij-utils/assets/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/assets/shell/auto-start.fish b/zellij-utils/assets/shell/auto-start.fish
new file mode 100644
index 00000000..c4b9e967
--- /dev/null
+++ b/zellij-utils/assets/shell/auto-start.fish
@@ -0,0 +1,11 @@
+if not set -q ZELLIJ
+ if test "$ZELLIJ_AUTO_ATTACH" = "true"
+ zellij attach -c
+ else
+ zellij
+ end
+
+ if test "$ZELLIJ_AUTO_EXIT" = "true"
+ kill $fish_pid
+ end
+end
diff --git a/zellij-utils/assets/shell/auto-start.zsh b/zellij-utils/assets/shell/auto-start.zsh
new file mode 100644
index 00000000..2a050f00
--- /dev/null
+++ b/zellij-utils/assets/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
diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs
index 96bbba41..79392c2e 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)
}
@@ -136,10 +154,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 +168,14 @@ pub struct Setup {
/// Dump the specified layout file to stdout
#[clap(long)]
pub dump_layout: Option<String>,
+
/// Generates completion for the specified shell
#[clap(long, value_name = "SHELL")]
pub generate_completion: Option<String>,
+
+ /// Generates auto-start script for the specified shell
+ #[clap(long, value_name = "SHELL")]
+ pub generate_auto_start: Option<String>,
}
impl Setup {
@@ -242,6 +267,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 +435,30 @@ 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);
+ }
+ };
+
+ let mut out = std::io::stdout();
+ match shell {
+ Shell::Bash => {
+ let _ = out.write_all(BASH_AUTO_START_SCRIPT);
+ }
+ Shell::Fish => {
+ let _ = out.write_all(FISH_AUTO_START_SCRIPT);
+ }
+ Shell::Zsh => {
+ let _ = out.write_all(ZSH_AUTO_START_SCRIPT);
+ }
+ _ => {}
+ }
+ }
}
#[cfg(test)]