bash-preexec | ⚡ preexec and precmd functions for Bash just like Zsh | Command Line Interface library
kandi X-RAY | bash-preexec Summary
kandi X-RAY | bash-preexec Summary
⚡ preexec and precmd functions for Bash just like Zsh.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of bash-preexec
bash-preexec Key Features
bash-preexec Examples and Code Snippets
Community Discussions
Trending Discussions on bash-preexec
QUESTION
There is a command line tool at my company that many people will use, but we need to set some restrictions on the tool's usage based on the environment that the user is in.
For example, if the user is logged into our production environment and they run dbt run
, I need to flash a warning and prompt them to continue or exit.
I use zsh
myself and found the preexec()
hook, but unfortunately, because of the way this is implemented, calling exit
kills the whole shell and closes the terminal. This seems to be a non-starter for this option.
I'm looking for a pure bash
alternative (many of my coworkers may not use zsh
) that will allow me to evaluate a command before it's executed, run the command through some logic, and allow me to either kill the command or run it.
Here is the zsh
function i wrote for reference:
ANSWER
Answered 2020-Nov-16 at 10:46What you need to do is create a wrapper around the original command, not mess with preexec
and other shell-specific hooks. Of course, you can write this wrapper itself as a zsh script. So you'll create, e.g., dbt_safe.zsh
which would internally call dbt
, and your colleagues would just use dbt_safe.zsh
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install bash-preexec
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page