mirror of
https://github.com/zellij-org/zellij.git
synced 2024-11-23 08:57:14 +03:00
Add subcommand to generate completions
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
b3eb9f1302
commit
9aca589167
@ -1,90 +0,0 @@
|
||||
#compdef zellij
|
||||
|
||||
autoload -U is-at-least
|
||||
|
||||
_zellij() {
|
||||
typeset -A opt_args
|
||||
typeset -a _arguments_options
|
||||
local ret=1
|
||||
|
||||
if is-at-least 5.2; then
|
||||
_arguments_options=(-s -S -C)
|
||||
else
|
||||
_arguments_options=(-s -C)
|
||||
fi
|
||||
|
||||
local context curcontext="$curcontext" state line
|
||||
_arguments "${_arguments_options[@]}" \
|
||||
'-s+[Send "split (direction h == horizontal / v == vertical)" to active zellij session]' \
|
||||
'--split=[Send "split (direction h == horizontal / v == vertical)" to active zellij session]' \
|
||||
'-o+[Send "open file in new pane" to active zellij session]' \
|
||||
'--open-file=[Send "open file in new pane" to active zellij session]' \
|
||||
'--max-panes=[Maximum panes on screen, caution: opening more panes will close old ones]' \
|
||||
'--data-dir=[Change where zellij looks for layouts and plugins]' \
|
||||
'-l+[Path to a layout yaml file]' \
|
||||
'--layout=[Path to a layout yaml file]' \
|
||||
'-c+[Change where zellij looks for the configuration]' \
|
||||
'--config=[Change where zellij looks for the configuration]' \
|
||||
'-m[Send "move focused pane" to active zellij session]' \
|
||||
'--move-focus[Send "move focused pane" to active zellij session]' \
|
||||
'-d[]' \
|
||||
'--debug[]' \
|
||||
'-h[Prints help information]' \
|
||||
'--help[Prints help information]' \
|
||||
'-V[Prints version information]' \
|
||||
'--version[Prints version information]' \
|
||||
":: :_zellij_commands" \
|
||||
"*::: :->zellij" \
|
||||
&& ret=0
|
||||
case $state in
|
||||
(zellij)
|
||||
words=($line[1] "${words[@]}")
|
||||
(( CURRENT += 1 ))
|
||||
curcontext="${curcontext%:*:*}:zellij-command-$line[1]:"
|
||||
case $line[1] in
|
||||
(option)
|
||||
_arguments "${_arguments_options[@]}" \
|
||||
'--clean[Disables loading of configuration file at default location]' \
|
||||
'-h[Prints help information]' \
|
||||
'--help[Prints help information]' \
|
||||
'-V[Prints version information]' \
|
||||
'--version[Prints version information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments "${_arguments_options[@]}" \
|
||||
'-h[Prints help information]' \
|
||||
'--help[Prints help information]' \
|
||||
'-V[Prints version information]' \
|
||||
'--version[Prints version information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
(( $+functions[_zellij_commands] )) ||
|
||||
_zellij_commands() {
|
||||
local commands; commands=(
|
||||
"option:Change the behaviour of zellij" \
|
||||
"help:Prints this message or the help of the given subcommand(s)" \
|
||||
)
|
||||
_describe -t commands 'zellij commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_zellij__help_commands] )) ||
|
||||
_zellij__help_commands() {
|
||||
local commands; commands=(
|
||||
|
||||
)
|
||||
_describe -t commands 'zellij help commands' commands "$@"
|
||||
}
|
||||
(( $+functions[_zellij__option_commands] )) ||
|
||||
_zellij__option_commands() {
|
||||
local commands; commands=(
|
||||
|
||||
)
|
||||
_describe -t commands 'zellij option commands' commands "$@"
|
||||
}
|
||||
|
||||
_zellij "$@"
|
@ -1,117 +0,0 @@
|
||||
_zellij() {
|
||||
local i cur prev opts cmds
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
cmd=""
|
||||
opts=""
|
||||
|
||||
for i in ${COMP_WORDS[@]}
|
||||
do
|
||||
case "${i}" in
|
||||
zellij)
|
||||
cmd="zellij"
|
||||
;;
|
||||
|
||||
help)
|
||||
cmd+="__help"
|
||||
;;
|
||||
option)
|
||||
cmd+="__option"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case "${cmd}" in
|
||||
zellij)
|
||||
opts=" -m -d -h -V -s -o -l -c --move-focus --debug --help --version --split --open-file --max-panes --data-dir --layout --config option help"
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
|
||||
--split)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-s)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--open-file)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-o)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--max-panes)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--data-dir)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--layout)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-l)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
--config)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
-c)
|
||||
COMPREPLY=($(compgen -f "${cur}"))
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
|
||||
zellij__help)
|
||||
opts=" -h -V --help --version "
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
zellij__option)
|
||||
opts=" -h -V --clean --help --version "
|
||||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
fi
|
||||
case "${prev}" in
|
||||
|
||||
*)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
complete -F _zellij -o bashdefault -o default zellij
|
@ -1,17 +0,0 @@
|
||||
complete -c zellij -n "__fish_use_subcommand" -s s -l split -d 'Send "split (direction h == horizontal / v == vertical)" to active zellij session'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s o -l open-file -d 'Send "open file in new pane" to active zellij session'
|
||||
complete -c zellij -n "__fish_use_subcommand" -l max-panes -d 'Maximum panes on screen, caution: opening more panes will close old ones'
|
||||
complete -c zellij -n "__fish_use_subcommand" -l data-dir -d 'Change where zellij looks for layouts and plugins'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s l -l layout -d 'Path to a layout yaml file'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s c -l config -d 'Change where zellij looks for the configuration'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s m -l move-focus -d 'Send "move focused pane" to active zellij session'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s d -l debug
|
||||
complete -c zellij -n "__fish_use_subcommand" -s h -l help -d 'Prints help information'
|
||||
complete -c zellij -n "__fish_use_subcommand" -s V -l version -d 'Prints version information'
|
||||
complete -c zellij -n "__fish_use_subcommand" -f -a "option" -d 'Change the behaviour of zellij'
|
||||
complete -c zellij -n "__fish_use_subcommand" -f -a "help" -d 'Prints this message or the help of the given subcommand(s)'
|
||||
complete -c zellij -n "__fish_seen_subcommand_from option" -l clean -d 'Disables loading of configuration file at default location'
|
||||
complete -c zellij -n "__fish_seen_subcommand_from option" -s h -l help -d 'Prints help information'
|
||||
complete -c zellij -n "__fish_seen_subcommand_from option" -s V -l version -d 'Prints version information'
|
||||
complete -c zellij -n "__fish_seen_subcommand_from help" -s h -l help -d 'Prints help information'
|
||||
complete -c zellij -n "__fish_seen_subcommand_from help" -s V -l version -d 'Prints version information'
|
23
build.rs
23
build.rs
@ -1,23 +0,0 @@
|
||||
use std::fs;
|
||||
use structopt::clap::Shell;
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
const BIN_NAME: &str = "zellij";
|
||||
|
||||
fn main() {
|
||||
// Generate Shell Completions
|
||||
let mut clap_app = CliArgs::clap();
|
||||
println!("cargo:rerun-if-changed=src/cli.rs");
|
||||
let mut out_dir = std::env::var_os("CARGO_MANIFEST_DIR").unwrap();
|
||||
out_dir.push("/assets/completions");
|
||||
|
||||
println!(
|
||||
"Completion files will to added to this location: {:?}",
|
||||
out_dir
|
||||
);
|
||||
fs::create_dir_all(&out_dir).unwrap();
|
||||
clap_app.gen_completions(BIN_NAME, Shell::Bash, &out_dir);
|
||||
clap_app.gen_completions(BIN_NAME, Shell::Zsh, &out_dir);
|
||||
clap_app.gen_completions(BIN_NAME, Shell::Fish, &out_dir);
|
||||
}
|
@ -51,4 +51,10 @@ pub enum ConfigCli {
|
||||
/// Disables loading of configuration file at default location
|
||||
clean: bool,
|
||||
},
|
||||
|
||||
#[structopt(name = "generate-completion")]
|
||||
GenerateCompletion {
|
||||
shell: String,
|
||||
},
|
||||
}
|
||||
|
||||
|
14
src/main.rs
14
src/main.rs
@ -45,6 +45,20 @@ pub fn main() {
|
||||
let mut stream = UnixStream::connect(ZELLIJ_IPC_PIPE).unwrap();
|
||||
let api_command = bincode::serialize(&ApiCommand::OpenFile(file_to_open)).unwrap();
|
||||
stream.write_all(&api_command).unwrap();
|
||||
} else if let Some(crate::cli::ConfigCli::GenerateCompletion { shell }) = opts.option {
|
||||
let shell = match shell.as_ref() {
|
||||
"bash" => structopt::clap::Shell::Bash,
|
||||
"fish" => structopt::clap::Shell::Fish,
|
||||
"zsh" => structopt::clap::Shell::Zsh,
|
||||
"powerShell" => structopt::clap::Shell::PowerShell,
|
||||
"elvish" => structopt::clap::Shell::Elvish,
|
||||
other => {
|
||||
eprintln!("Unsupported shell: {}", other);
|
||||
std::process::exit(1);
|
||||
},
|
||||
};
|
||||
let mut out = std::io::stdout();
|
||||
CliArgs::clap().gen_completions_to("zellij", shell, &mut out);
|
||||
} else {
|
||||
let os_input = get_os_input();
|
||||
atomic_create_dir(ZELLIJ_TMP_DIR).unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user