Created
September 1, 2023 00:22
-
-
Save hoehermann/74057ea1a9adf4b7b3f6d84948c9155f to your computer and use it in GitHub Desktop.
.bashrc lines to stop operator from referring to /dev/sd? directly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# disallow accessing /dev/sd? directly | |
reject_devsdx () { | |
if [[ ${BASH_COMMAND} =~ "/dev/sd" ]] | |
then | |
echo "Stop being stupid. Use one of these:" | |
find /dev/disk -type l -printf '%p -> ' -exec readlink -f {} ';' | grep "$(echo ${BASH_COMMAND} | grep -Po '/dev/sd\S+')$" | |
return 1 | |
fi | |
} | |
shopt -s extdebug | |
trap reject_devsdx DEBUG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment