Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Once installed, use the centml CLI tool with the following command:
centml
```

If you want tab completion, run
```bash
source scripts/completions/completion.<shell language>
```
Shell language can be: bash, zsh, fish
(Hint: add `source /path/to/completions/completion.<shell language>` to your `~/.bashrc`, `~/.zshrc` or `~/.config/fish/completions/centml.fish`)

### 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. \
Expand Down
29 changes: 29 additions & 0 deletions scripts/completions/completion.bash
Original file line number Diff line number Diff line change
@@ -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;

18 changes: 18 additions & 0 deletions scripts/completions/completion.fish
Original file line number Diff line number Diff line change
@@ -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)";

41 changes: 41 additions & 0 deletions scripts/completions/completion.zsh
Original file line number Diff line number Diff line change
@@ -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