aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-25 14:33:53 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-25 14:33:53 +0200
commit9aca589167fec7b5b309c60208bd4cd203bc9c6e (patch)
tree8fc6394398b9064194b860580952097bd5bfb8ba
parentMerge pull request #356 from zellij-org/add-auto-release (diff)
downloadsl0ppij-9aca589167fec7b5b309c60208bd4cd203bc9c6e.tar.gz
sl0ppij-9aca589167fec7b5b309c60208bd4cd203bc9c6e.tar.xz
sl0ppij-9aca589167fec7b5b309c60208bd4cd203bc9c6e.zip
Add subcommand to generate completions
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--assets/completions/_zellij90
-rw-r--r--assets/completions/zellij.bash117
-rw-r--r--assets/completions/zellij.fish17
-rw-r--r--build.rs23
-rw-r--r--src/cli.rs6
-rw-r--r--src/main.rs14
6 files changed, 20 insertions, 247 deletions
diff --git a/assets/completions/_zellij b/assets/completions/_zellij
deleted file mode 100644
index 774a28fa..00000000
--- a/assets/completions/_zellij
+++ /dev/null
@@ -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 "$@" \ No newline at end of file
diff --git a/assets/completions/zellij.bash b/assets/completions/zellij.bash
deleted file mode 100644
index 9cd8f890..00000000
--- a/assets/completions/zellij.bash
+++ /dev/null
@@ -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
diff --git a/assets/completions/zellij.fish b/assets/completions/zellij.fish
deleted file mode 100644
index 4c1e536f..00000000
--- a/assets/completions/zellij.fish
+++ /dev/null
@@ -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'
diff --git a/build.rs b/build.rs
deleted file mode 100644
index 3240db67..00000000
--- a/build.rs
+++ /dev/null
@@ -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);
-}
diff --git a/src/cli.rs b/src/cli.rs
index 008fb28c..b6b0ec3c 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -51,4 +51,10 @@ pub enum ConfigCli {
/// Disables loading of configuration file at default location
clean: bool,
},
+
+ #[structopt(name = "generate-completion")]
+ GenerateCompletion {
+ shell: String,
+ },
}
+
diff --git a/src/main.rs b/src/main.rs
index ec249e8a..377ef4f6 100644
--- a/src/main.rs
+++ b/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();