Skip to content

Instantly share code, notes, and snippets.

@hoehermann
Created September 1, 2023 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoehermann/74057ea1a9adf4b7b3f6d84948c9155f to your computer and use it in GitHub Desktop.
Save hoehermann/74057ea1a9adf4b7b3f6d84948c9155f to your computer and use it in GitHub Desktop.
.bashrc lines to stop operator from referring to /dev/sd? directly
# 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