Skip to content

Commit

Permalink
chore(integrations): zpipe alias (#3210)
Browse files Browse the repository at this point in the history
* chore(completions): zpipe alias

* chore(integrations): zpipe alias
  • Loading branch information
imsnif authored Mar 20, 2024
1 parent 58b13ba commit ec6d627
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,3 +667,23 @@ fn generate_unique_session_name() -> String {
process::exit(1);
}
}

pub(crate) fn list_aliases(opts: CliArgs) {
let (config, _layout, _config_options, _config_without_layout, _config_options_without_layout) =
match Setup::from_cli_args(&opts) {
Ok(results) => results,
Err(e) => {
if let ConfigError::KdlError(error) = e {
let report: Report = error.into();
eprintln!("{:?}", report);
} else {
eprintln!("{}", e);
}
process::exit(1);
},
};
for alias in config.plugins.list() {
println!("{}", alias);
}
process::exit(0);
}
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ fn main() {
})) = opts.command
{
commands::list_sessions(no_formatting, short);
} else if let Some(Command::Sessions(Sessions::ListAliases)) = opts.command {
commands::list_aliases(opts);
} else if let Some(Command::Sessions(Sessions::KillAllSessions { yes })) = opts.command {
commands::kill_all_sessions(yes);
} else if let Some(Command::Sessions(Sessions::KillSession { ref target_session })) =
Expand Down
7 changes: 7 additions & 0 deletions zellij-utils/assets/completions/comp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ function zr () { zellij run --name "$*" -- bash -ic "$*";}
function zrf () { zellij run --name "$*" --floating -- bash -ic "$*";}
function ze () { zellij edit "$*";}
function zef () { zellij edit --floating "$*";}
function zpipe () {
if [ -z "$1" ]; then
zellij pipe;
else
zellij pipe -p $1;
fi
}
13 changes: 13 additions & 0 deletions zellij-utils/assets/completions/comp.fish
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ end
function zef
command zellij edit --floating $argv
end

# the zpipe alias and its completions
function __fish_complete_aliases
zellij list-aliases 2>/dev/null
end
function zpipe
if count $argv > /dev/null
command zellij pipe -p $argv
else
command zellij pipe
end
end
complete -c zpipe -f -a "(__fish_complete_aliases)" -d "Zpipes"
7 changes: 7 additions & 0 deletions zellij-utils/assets/completions/comp.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ function zr () { zellij run --name "$*" -- zsh -ic "$*";}
function zrf () { zellij run --name "$*" --floating -- zsh -ic "$*";}
function ze () { zellij edit "$*";}
function zef () { zellij edit --floating "$*";}
function zpipe () {
if [ -z "$1" ]; then
/home/aram/code/zellij/target/dev-opt/zellij pipe;
else
/home/aram/code/zellij/target/dev-opt/zellij pipe -p $1;
fi
}
6 changes: 4 additions & 2 deletions zellij-utils/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ pub enum Sessions {
#[clap(short, long, value_parser, takes_value(false), default_value("false"))]
short: bool,
},

/// List existing plugin aliases
#[clap(visible_alias = "la")]
ListAliases,
/// Attach to a session
#[clap(visible_alias = "a")]
Attach {
Expand Down Expand Up @@ -231,7 +233,7 @@ pub enum Sessions {
height: Option<String>,
},
/// Load a plugin
#[clap(visible_alias = "r")]
#[clap(visible_alias = "p")]
Plugin {
/// Plugin URL, can either start with http(s), file: or zellij:
#[clap(last(true), required(true))]
Expand Down
3 changes: 3 additions & 0 deletions zellij-utils/src/input/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ impl PluginAliases {
pub fn from_data(aliases: BTreeMap<String, RunPlugin>) -> Self {
PluginAliases { aliases }
}
pub fn list(&self) -> Vec<String> {
self.aliases.keys().cloned().collect()
}
}

/// Plugin metadata
Expand Down

0 comments on commit ec6d627

Please sign in to comment.