Skip to content

Commit cdc2b8d

Browse files
authored
Merge pull request #418 from owasp-noir/add-fish-completion
Refactor completion scripts and instructions for shell auto-completion
2 parents 32a5b82 + 47db2b9 commit cdc2b8d

File tree

4 files changed

+86
-4
lines changed

4 files changed

+86
-4
lines changed

docs/_advanced/tips/shell-completion.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,46 @@ To enable auto-completion for Zsh, run the following command to generate the com
1212

1313
```bash
1414
noir --generate-completion zsh
15+
# #compdef noir
16+
# _arguments \
17+
# ....
1518
```
1619

1720
Then, move the generated script to your Zsh completions directory, typically `~/.zsh/completion/`. If this directory does not exist, you may need to create it. Ensure the script is named `_noir` to follow Zsh's naming convention for completion scripts.
1821

22+
```bash
23+
noir --generate-completion zsh > ~/.zsh/completion/_noir
24+
```
25+
1926
## Bash completion
2027

2128
For Bash, generate the completion script by running:
2229

2330
```bash
2431
noir --generate-completion bash
32+
# _noir_completions() {
33+
# local cur prev opts
34+
# ....
35+
```
36+
37+
After generating the script, move it to the appropriate directory for Bash completions. This location can vary depending on your operating system and Bash configuration, but a common path is `/etc/bash_completion.d/` for system-wide availability, or `~/.local/share/bash-completion/completions/` for a single user. Ensure the script is executable and sourced in your Bash profile.
38+
39+
```bash
40+
noir --generate-completion bash > ~/.local/share/bash-completion/completions/noir
2541
```
2642

27-
After generating the script, move it to the appropriate directory for Bash completions. This location can vary depending on your operating system and Bash configuration, but a common path is `/etc/bash_completion.d/` for system-wide availability, or `~/.local/share/bash-completion/completions/` for a single user. Ensure the script is executable and sourced in your Bash profile.
43+
## Fish completion
44+
45+
For Fish, generate the completion script by running:
46+
47+
```bash
48+
noir --generate-completion fish
49+
# function __fish_noir_needs_command
50+
# ....
51+
```
52+
53+
After generating the script, move it to the Fish completions directory, typically `~/.config/fish/completions/.` If this directory does not exist, you may need to create it. Ensure the script is named noir.fish to follow Fish's naming convention for completion scripts.
54+
55+
```bash
56+
noir --generate-completion fish > ~/.config/fish/completions/noir.fish
57+
```

docs/_includes/usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ FLAGS:
1919
--set-pvalue-json VALUE Specifies the value of the identified parameter for JSON data
2020
--set-pvalue-path VALUE Specifies the value of the identified parameter for path parameters
2121
--status-codes Display HTTP status codes for discovered endpoints
22-
--exclude-codes Exclude specific HTTP status code
22+
--exclude-codes 404,500 Exclude specific HTTP response codes (comma-separated)
2323
--include-path Include file path in the plain result
2424
--no-color Disable color output
2525
--no-log Displaying only the results
@@ -48,7 +48,7 @@ FLAGS:
4848
CONFIG:
4949
--config-file ./config.yaml Specify the path to a configuration file in YAML format
5050
--concurrency 100 Set concurrency
51-
--generate-completion zsh Generate Zsh/Bash completion script
51+
--generate-completion zsh Generate Zsh/Bash/Fish completion script
5252

5353
DEBUG:
5454
-d, --debug Show debug messages

src/completions.cr

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,52 @@ _noir_completions() {
105105
106106
complete -F _noir_completions noir
107107
SCRIPT
108+
end
109+
110+
def generate_fish_completion_script
111+
<<-SCRIPT
112+
function __fish_noir_needs_command
113+
set -l cmd (commandline -opc)
114+
if test (count $cmd) -eq 1
115+
return 0
116+
end
117+
return 1
118+
end
119+
120+
complete -c noir -n '__fish_noir_needs_command' -a '-b' -d 'Set base path'
121+
complete -c noir -n '__fish_noir_needs_command' -a '-u' -d 'Set base URL for endpoints'
122+
complete -c noir -n '__fish_noir_needs_command' -a '-f' -d 'Set output format'
123+
complete -c noir -n '__fish_noir_needs_command' -a '-o' -d 'Write result to file'
124+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue' -d 'Specifies the value of the identified parameter'
125+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-header' -d 'Specifies the value of the identified parameter for headers'
126+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-cookie' -d 'Specifies the value of the identified parameter for cookies'
127+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-query' -d 'Specifies the value of the identified parameter for query parameters'
128+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-form' -d 'Specifies the value of the identified parameter for form data'
129+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-json' -d 'Specifies the value of the identified parameter for JSON data'
130+
complete -c noir -n '__fish_noir_needs_command' -a '--set-pvalue-path' -d 'Specifies the value of the identified parameter for path parameters'
131+
complete -c noir -n '__fish_noir_needs_command' -a '--status-codes' -d 'Display HTTP status codes for discovered endpoints'
132+
complete -c noir -n '__fish_noir_needs_command' -a '--exclude-codes' -d 'Exclude specific HTTP response codes (comma-separated)'
133+
complete -c noir -n '__fish_noir_needs_command' -a '--include-path' -d 'Include file path in the plain result'
134+
complete -c noir -n '__fish_noir_needs_command' -a '--no-color' -d 'Disable color output'
135+
complete -c noir -n '__fish_noir_needs_command' -a '--no-log' -d 'Displaying only the results'
136+
complete -c noir -n '__fish_noir_needs_command' -a '-T' -d 'Activates all taggers for full analysis coverage'
137+
complete -c noir -n '__fish_noir_needs_command' -a '--use-taggers' -d 'Activates specific taggers'
138+
complete -c noir -n '__fish_noir_needs_command' -a '--list-taggers' -d 'Lists all available taggers'
139+
complete -c noir -n '__fish_noir_needs_command' -a '--send-req' -d 'Send results to a web request'
140+
complete -c noir -n '__fish_noir_needs_command' -a '--send-proxy' -d 'Send results to a web request via an HTTP proxy'
141+
complete -c noir -n '__fish_noir_needs_command' -a '--send-es' -d 'Send results to Elasticsearch'
142+
complete -c noir -n '__fish_noir_needs_command' -a '--with-headers' -d 'Add custom headers to be included in the delivery'
143+
complete -c noir -n '__fish_noir_needs_command' -a '--use-matchers' -d 'Send URLs that match specific conditions to the Deliver'
144+
complete -c noir -n '__fish_noir_needs_command' -a '--use-filters' -d 'Exclude URLs that match specified conditions and send the rest to Deliver'
145+
complete -c noir -n '__fish_noir_needs_command' -a '--diff-path' -d 'Specify the path to the old version of the source code for comparison'
146+
complete -c noir -n '__fish_noir_needs_command' -a '-t' -d 'Specify the technologies to use'
147+
complete -c noir -n '__fish_noir_needs_command' -a '--exclude-techs' -d 'Specify the technologies to be excluded'
148+
complete -c noir -n '__fish_noir_needs_command' -a '--list-techs' -d 'Show all technologies'
149+
complete -c noir -n '__fish_noir_needs_command' -a '--config-file' -d 'Specify the path to a configuration file in YAML format'
150+
complete -c noir -n '__fish_noir_needs_command' -a '--concurrency' -d 'Set concurrency'
151+
complete -c noir -n '__fish_noir_needs_command' -a '-d' -d 'Show debug messages'
152+
complete -c noir -n '__fish_noir_needs_command' -a '-v' -d 'Show version'
153+
complete -c noir -n '__fish_noir_needs_command' -a '--build-info' -d 'Show version and Build info'
154+
complete -c noir -n '__fish_noir_needs_command' -a '-h' -d 'Show help'
155+
SCRIPT
108156
end

src/options.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,22 @@ def run_options_parser
122122
parser.separator "\n CONFIG:".colorize(:blue)
123123
parser.on "--config-file ./config.yaml", "Specify the path to a configuration file in YAML format" { |var| noir_options["config_file"] = YAML::Any.new(var) }
124124
parser.on "--concurrency 100", "Set concurrency" { |var| noir_options["concurrency"] = YAML::Any.new(var) }
125-
parser.on "--generate-completion zsh", "Generate Zsh/Bash completion script" do |var|
125+
parser.on "--generate-completion zsh", "Generate Zsh/Bash/Fish completion script" do |var|
126126
case var
127127
when "zsh"
128128
puts generate_zsh_completion_script
129129
STDERR.puts "\n> Instructions: Copy the content above and save it in the zsh-completion directory as _noir".colorize(:yellow)
130130
when "bash"
131131
puts generate_bash_completion_script
132132
STDERR.puts "\n> Instructions: Copy the content above and save it in the .bashrc file as noir.".colorize(:yellow)
133+
when "fish"
134+
puts generate_fish_completion_script
135+
STDERR.puts "\n> Instructions: Copy the content above and save it in the fish-completion directory as noir.fish".colorize(:yellow)
133136
else
134137
puts "ERROR: Invalid completion type.".colorize(:yellow)
135138
puts "e.g., noir --generate-completion zsh"
136139
puts "e.g., noir --generate-completion bash"
140+
puts "e.g., noir --generate-completion fish"
137141
end
138142

139143
exit

0 commit comments

Comments
 (0)