hkbakke / bash-insulter

Insults the user when typing wrong command
MIT License
629 stars 74 forks source link

profile.d script #17

Open ItchyBugReporter opened 6 years ago

ItchyBugReporter commented 6 years ago

I would suggest including a profile.d script to have bash-insulter able to be enabled globally. You'll see an example of this in my fork (which GitHub stupidly decided to append to my pull request for the Makefile -- completely unintentional on my part!).

My version of the script has a variable called GLOBAL_BASH_INSULTER which will enable bash-insulter globally if set to anything other than 0 (zero). If GLOBAL_BASH_INSULTER is removed or commented for some reason, an error message will be echo'ed when the shell loads asking for it to be added to the file. It is set to 0 in my script: if for some reason it is installed in an enterprise or office machine, the admin probably won't want it enable for everyone in case some user of the machine it's on gets offended easily.

hkbakke commented 6 years ago

The reason for using bash.bashrc and not profile to load bash-insulter was that bash-insulter really only exploits bash-specific functionality, while profile is really for all Bourne compatible shells. Since bash-insulter supports zsh now, one can however argue that profile.d is a suitable place. It is also clean to have its own file for easier automated installs, so I really have no real issues with your idea.

I feel that if profile.d is to be used there should be a requirement to actually detect that either bash or zsh is the current shell to not mess with ksh, ash and other untested shells using the same configuration files.

ItchyBugReporter commented 6 years ago

On my system (which runs CentOS 6), /etc/profile.d contains files ending in .bash , .zsh , .csh , and .sh . This seems to indicate that it's acceptable to have shell-specific files in /etc/profile.d . The problem here is that we would need to have the same file twice: either as two separate files or as a file and a symlink.

The other option is to use the $SHELL environmental variable to determine which shell it's in. The problem here is that when I execute /bin/bash with my default shell set to /bin/zsh, the $SHELL variable does not change to /bin/bash but instead remains as /bin/zsh , even when I try to specify -i , -l , or both (I haven't tested this in reverse).

When I wrote the profile.d script, I had not thought of the possibility of having shells other than bash or zsh, but I have no problem changing it -- just let me know which solution you like better (we could even combine the two, but that would be a bit redundant).