Skip to content

Commit

Permalink
Merge pull request #131 from nevzatseferoglu/zsh-shell-completion
Browse files Browse the repository at this point in the history
Add zsh shell auto-completion function
  • Loading branch information
fatihbaltaci authored Feb 14, 2023
2 parents c70e3fd + 55e1121 commit c1b086c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

## Installation

`ddosify` is available via [Docker](https://hub.docker.com/r/ddosify/ddosify), [Docker Extension](https://hub.docker.com/extensions/ddosify/ddosify-docker-extension), [Homebrew Tap](#homebrew-tap-macos-and-linux), and downloadable pre-compiled binaries from the [releases page](https://github.com/ddosify/ddosify/releases/latest) for macOS, Linux and Windows.
`ddosify` is available via [Docker](https://hub.docker.com/r/ddosify/ddosify), [Docker Extension](https://hub.docker.com/extensions/ddosify/ddosify-docker-extension), [Homebrew Tap](#homebrew-tap-macos-and-linux), and downloadable pre-compiled binaries from the [releases page](https://github.com/ddosify/ddosify/releases/latest) for macOS, Linux and Windows. For auto-completion, see: [Ddosify Completions](https://github.com/ddosify/ddosify/blob/master/completions/README.md).

### Docker

Expand Down
42 changes: 42 additions & 0 deletions completions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Shell completions

## Zsh

`completions/_ddosify` provides a basic auto-completions. You can apply one of the steps to get an auto-completion successfully.

You can locate the file in any directory referenced by `$fpath`. You can use the following command to list directories in `$fpath`.

```bash
echo $fpath | tr ' ' '\n'
```

For example, if you are using [oh-my-zsh](https://ohmyz.sh/) you can add it as a plugin after locating file under plugin related directory appeared in `$fpath`. You can create a directory named `ddosify` under `~/.oh-my-zsh/plugins` and copy `_ddosify` file to it.

```bash
mkdir -p ~/.oh-my-zsh/plugins/ddosify
cp completions/_ddosify ~/.oh-my-zsh/plugins/ddosify
```

Then, you can add `ddosify` to your plugins list in `~/.zshrc` file.

```
# ~/.zshrc
plugins=(
...
ddosify
)
```

If you don't have an appropriate directory, you can create one and add it to `$fpath`.

```
mkdir -p ${ZDOTDIR:-~}/.zsh_functions
echo 'fpath+=${ZDOTDIR:-~}/.zsh_functions' >> ${ZDOTDIR:-~}/.zshrc
```

Then, you can copy `_ddosify` file to the directory you created.

```
cp completions/_ddosify ${ZDOTDIR:-~}/.zsh_functions/_ddosify
```
32 changes: 32 additions & 0 deletions completions/_ddosify
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#compdef ddosify _ddosify

typeset -A opt_args

_ddosify() {
local curcontext="$curcontext" state line
local -a opts

opts+=(
"-t[Target URL.]"
"-P[Proxy address as protocol\://username\:password@host\:port. Supported proxies \[http(s), socks\].]"
"-T[Request timeout in seconds (default 5).]"
"-a[Basic authentication, username\:password.]"
"-b[Payload of the network packet (body).]"
"-cert_key_path[A path to a certificate key file (usually called 'key.pem').]:filename:_files"
"-cert_path[A path to a certificate file (usually called 'cert.pem'.)]:filename:_files"
"-config[Json config file path. If a config file is provided, other flag values will be ignored.]:filename:_files"
"-d[Test duration in seconds (default 10).]"
"-debug[Iterates the scenario once and prints curl-like verbose result.]"
"-h[Request Headers. Ex\: -h 'Accept\: text/html' -h 'Content-Type\: application/xml'.]"
"-l[Type of the load test \['linear', 'incremental', 'waved'\] (default 'linear').]"
"-m[Request Method Type. For Http(s)\:\['GET', 'POST', 'PUT', 'DELETE', 'UPDATE', 'PATCH'\] (default 'GET').]"
"-n[Total iteration count (default 100).]"
"-o[Output destination (default 'stdout').]"
"-version[Prints version, git commit, built date (utc), go information and quit.]"
)

_arguments -s -w : $opts && return 0

return 1
}

0 comments on commit c1b086c

Please sign in to comment.