I have the following as a member of
(("/home/robin/.local/bin/.*[^/]\\'" . "Shell-Script mode magic number") lambda nil (if (eq major-mode (default-value 'major-mode)) (progn (sh-mode) (insert "#! /bin/bash -peux # "))))
The mode is set correctly, but the text is not inserted. And it doesn't seem to have been inserted into the wrong buffer, either, because
C-x s says "(No files need saving)".