feat: support the command of auto-start script for shell (#1281)
This commit is contained in:
parent
7ba70b2959
commit
be0af7e69c
4 changed files with 87 additions and 0 deletions
11
zellij-utils/assets/shell/auto-start.bash
Normal file
11
zellij-utils/assets/shell/auto-start.bash
Normal file
|
|
@ -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
|
||||
11
zellij-utils/assets/shell/auto-start.fish
Normal file
11
zellij-utils/assets/shell/auto-start.fish
Normal file
|
|
@ -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
|
||||
11
zellij-utils/assets/shell/auto-start.zsh
Normal file
11
zellij-utils/assets/shell/auto-start.zsh
Normal file
|
|
@ -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
|
||||
|
|
@ -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)]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue