Hilbish/docs/hooks/command.md

68 lines
1.4 KiB
Markdown
Raw Normal View History

---
title: Command
description:
layout: doc
menu:
docs:
2023-12-18 17:33:05 +00:00
parent: "Signals"
---
2023-12-24 22:23:10 +00:00
## command.preexec
Thrown right before a command is executed.
2023-12-24 22:23:10 +00:00
#### Variables
`string` **`input`**
The raw string that the user typed. This will include the text
without changes applied to it (argument substitution, alias expansion,
etc.)
2021-11-22 21:36:32 +00:00
2023-12-24 22:23:10 +00:00
`string` **`cmdStr`**
The command that will be directly executed by the current runner.
2021-11-22 21:36:32 +00:00
2023-12-24 22:23:10 +00:00
<hr>
## command.exit
Thrown after the user's ran command is finished.
#### Variables
`number` **`code`**
The exit code of what was executed.
`string` **`cmdStr`**
The command or code that was executed
<hr>
## command.not-found
Thrown if the command attempted to execute was not found.
This can be used to customize the text printed when a command is not found.
Example:
```lua
local bait = require 'bait'
-- Remove any present handlers on `command.not-found`
local notFoundHooks = bait.hooks 'command.not-found'
for _, hook in ipairs(notFoundHooks) do
bait.release('command.not-found', hook)
end
-- then assign custom
bait.catch('command.not-found', function(cmd)
print(string.format('The command "%s" was not found.', cmd))
end)
```
#### Variables
`string` **`cmdStr`**
The name of the command.
<hr>
## command.not-executable
Thrown when the user attempts to run a file that is not executable
(like a text file, or Unix binary without +x permission).
#### Variables
`string` **`cmdStr`**
The name of the command.