From a6fdc707a88f4946ce539c67018e6e49ea40fc47 Mon Sep 17 00:00:00 2001 From: destefy Date: Tue, 2 Jul 2024 16:59:19 -0400 Subject: [PATCH 1/3] start of tab completion support --- README.md | 7 +++++++ centml-complete.bash | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 centml-complete.bash diff --git a/README.md b/README.md index d582cf3..14ec917 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ Once installed, use the centml CLI tool with the following command: centml ``` +If you want tab completion, run +```bash +source centml-complete.bash +``` +DO THIS ANOTHER WAY TO SUPPORT OTHER SHELL LANGUAGES +ALSO IT"S TOO SLOW. + ### Compilation centml-python-client's compiler feature allows you to compile your ML model remotely using the [hidet](https://hidet.org/docs/stable/index.html) backend. \ diff --git a/centml-complete.bash b/centml-complete.bash new file mode 100644 index 0000000..762c11c --- /dev/null +++ b/centml-complete.bash @@ -0,0 +1,29 @@ +_centml_completion() { + local IFS=$'\n' + local response + + response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _CENTML_COMPLETE=bash_complete $1) + + for completion in $response; do + IFS=',' read type value <<< "$completion" + + if [[ $type == 'dir' ]]; then + COMPREPLY=() + compopt -o dirnames + elif [[ $type == 'file' ]]; then + COMPREPLY=() + compopt -o default + elif [[ $type == 'plain' ]]; then + COMPREPLY+=($value) + fi + done + + return 0 +} + +_centml_completion_setup() { + complete -o nosort -F _centml_completion centml +} + +_centml_completion_setup; + From 4430a6e26c6617e0bb62cbd4e58d2e866d2abf29 Mon Sep 17 00:00:00 2001 From: destefy Date: Thu, 11 Jul 2024 13:21:00 -0400 Subject: [PATCH 2/3] Add support for zsh and fish --- README.md | 6 +-- .../completion.bash | 0 completions/completion.fish | 18 ++++++++ completions/completion.zsh | 41 +++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) rename centml-complete.bash => completions/completion.bash (100%) create mode 100644 completions/completion.fish create mode 100644 completions/completion.zsh diff --git a/README.md b/README.md index 14ec917..011f8ca 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ centml If you want tab completion, run ```bash -source centml-complete.bash +source completions/completion. ``` -DO THIS ANOTHER WAY TO SUPPORT OTHER SHELL LANGUAGES -ALSO IT"S TOO SLOW. +Shell language can be: bash, zsh, fish +(Hint: add `source /path/to/completions/completion.` to your `~/.bashrc`, `~/.zshrc` or `~/.config/fish/completions/centml.fish`) ### Compilation diff --git a/centml-complete.bash b/completions/completion.bash similarity index 100% rename from centml-complete.bash rename to completions/completion.bash diff --git a/completions/completion.fish b/completions/completion.fish new file mode 100644 index 0000000..483cad9 --- /dev/null +++ b/completions/completion.fish @@ -0,0 +1,18 @@ +function _centml_completion; + set -l response (env _CENTML_COMPLETE=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) centml); + + for completion in $response; + set -l metadata (string split "," $completion); + + if test $metadata[1] = "dir"; + __fish_complete_directories $metadata[2]; + else if test $metadata[1] = "file"; + __fish_complete_path $metadata[2]; + else if test $metadata[1] = "plain"; + echo $metadata[2]; + end; + end; +end; + +complete --no-files --command centml --arguments "(_centml_completion)"; + diff --git a/completions/completion.zsh b/completions/completion.zsh new file mode 100644 index 0000000..4e811f6 --- /dev/null +++ b/completions/completion.zsh @@ -0,0 +1,41 @@ +#compdef centml + +_centml_completion() { + local -a completions + local -a completions_with_descriptions + local -a response + (( ! $+commands[centml] )) && return 1 + + response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _CENTML_COMPLETE=zsh_complete centml)}") + + for type key descr in ${response}; do + if [[ "$type" == "plain" ]]; then + if [[ "$descr" == "_" ]]; then + completions+=("$key") + else + completions_with_descriptions+=("$key":"$descr") + fi + elif [[ "$type" == "dir" ]]; then + _path_files -/ + elif [[ "$type" == "file" ]]; then + _path_files -f + fi + done + + if [ -n "$completions_with_descriptions" ]; then + _describe -V unsorted completions_with_descriptions -U + fi + + if [ -n "$completions" ]; then + compadd -U -V unsorted -a completions + fi +} + +if [[ $zsh_eval_context[-1] == loadautofunc ]]; then + # autoload from fpath, call function directly + _centml_completion "$@" +else + # eval/source/. command, register function for later + compdef _centml_completion centml +fi + From 5e4ae328778edbbf6304d0a62885f14abb400ad3 Mon Sep 17 00:00:00 2001 From: destefy Date: Thu, 18 Jul 2024 16:08:35 -0400 Subject: [PATCH 3/3] move completions to scripts/ --- README.md | 2 +- {completions => scripts/completions}/completion.bash | 0 {completions => scripts/completions}/completion.fish | 0 {completions => scripts/completions}/completion.zsh | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename {completions => scripts/completions}/completion.bash (100%) rename {completions => scripts/completions}/completion.fish (100%) rename {completions => scripts/completions}/completion.zsh (100%) diff --git a/README.md b/README.md index 011f8ca..9612118 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ centml If you want tab completion, run ```bash -source completions/completion. +source scripts/completions/completion. ``` Shell language can be: bash, zsh, fish (Hint: add `source /path/to/completions/completion.` to your `~/.bashrc`, `~/.zshrc` or `~/.config/fish/completions/centml.fish`) diff --git a/completions/completion.bash b/scripts/completions/completion.bash similarity index 100% rename from completions/completion.bash rename to scripts/completions/completion.bash diff --git a/completions/completion.fish b/scripts/completions/completion.fish similarity index 100% rename from completions/completion.fish rename to scripts/completions/completion.fish diff --git a/completions/completion.zsh b/scripts/completions/completion.zsh similarity index 100% rename from completions/completion.zsh rename to scripts/completions/completion.zsh