Coder Social home page Coder Social logo

preexec_confirm's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.