preexec_confirm

Crates.iopreexec_confirm
lib.rspreexec_confirm
version0.1.2
sourcesrc
created_at2022-04-10 10:26:42.497984
updated_at2022-04-10 10:47:34.421119
descriptionA zsh `middleware` forcing users to confirm before executing commands with preconfigured texts/regex patterns
homepagehttps://github.com/anhtumai/preexec_confirm
repositoryhttps://github.com/anhtumai/preexec_confirm
max_upload_size
id565024
size240,920
Anh Tu Mai (anhtumai)

documentation

README

Preexec Confirm

A zsh `middleware` forcing user to confirm before executing commands
with preconfigured texts/regex patterns.

Demo

Users can define a YAML config file, specifying keywords or regex patterns of dangerous commands that they don't want to execute by accident. For example, serverless deploy --stage prod-environment

When the middleware detects a dangerous command, it will force the user to confirm by re-typing a random string, to avoid muscle memory.

Demo

Export env var SKIP_CONFIRM=true if you want to temporarily ignore the middleware.

Skip-confirm-demo

Installation and Usage

Requirements:

  • This project is only applied for Zsh.
  • Cargo is needed

1. Build from source

cargo install preexec_confirm

# ensure the system recognizes preexec_confirm path
which preexec_confirm
## ~/.cargo/bin/preexec_confirm

2. Create a YAML config file with the following format

- contain: string
  description (optional): string
  regex (optional): bool
  • contain: text/regex pattern to search in the command, depending on regex option
  • description: explains why the rule is needed
  • regex: if set to true, contain will be treated as a regex pattern

3. Ensure these lines exist in your .zshrc with correct order

function preexec_confirm_hook() {
    CONFIG_PATH="/home/anhtumai/.config/confirm/config.yml" #change this
    preexec_confirm $CONFIG_PATH $1
}

autoload -Uz add-zsh-hook

add-zsh-hook preexec preexec_confirm_hook

Uninstallation

  • Run cargo uninstall preexec_confirm
  • Remove these configured lines above in .zshrc
Commit count: 14

cargo fmt