Created
November 18, 2015 01:45
-
-
Save DanSnow/940b8737285a50643492 to your computer and use it in GitHub Desktop.
Trollor your friend, make a command "command not found"
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
#!/bin/bash | |
# Usage: bash command-not-found.sh <command> | |
# Eample: bash command-not-found.sh ls | |
# Then if you type ls it will act like ls is not install. | |
if [[ -z $1 ]]; then | |
return | |
fi | |
current_shell="$(rev <<< "$SHELL" | cut -d '/' -f 1 | rev)" | |
if [[ -x '/usr/lib/command-not-found' ]]; then | |
troll_command="/usr/lib/command-not-found --ignore-installed $1; argument_blackhole" | |
else | |
troll_command="echo '-${current_shell}: ${1}: command not found'; argument_blackhole" | |
fi | |
# To cleanup argument | |
argument_blackhole="argument_blackhole() { | |
return 127 | |
}" | |
case "$current_shell" in | |
'zsh') | |
shell_config="$HOME/.zshrc" | |
;; | |
'bash') | |
shell_config="$HOME/.bashrc" | |
;; | |
esac | |
if ! grep argument_blackhole "$shell_config"; then | |
echo "$argument_blackhole" >> "$shell_config" | |
fi | |
echo "alias ${1}='${troll_command}'" >> "$shell_config" | |
# Force shell to reload config file | |
exec "$current_shell" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment