Sometimes, after I run some commands (for example git
commands), I discover that I forgot some configurations or forgot to put some requirements... . So I thought about displaying a message, to remind me or warn me, (like the one displayed when we run sudo apt upgrade
:
The following packages will be upgraded ... Do you want to continue [Y/n]?)
I want to get a similar message when I run a specific command ("Did you check the conf files, did you update the requirements file?) When I type Y, the command run and when I type n, the command stops.
How to do this in Ubuntu?
Typically, when there are things that have to be done before an actual command runs - such as providing and setting up environment variables, adding extra positional parameters, etc - the command is placed into a wrapper script. How it should be implemented - that depends on the specific command you want and things you want to check before actual command runs. In the very simple case such as
git
, you could do something along the following lines:Of course the next question is the naming of the command. This script could be named
git-commit
or something similar. I would advice against naming wrapper scripts same as the original application.See also: