Skip to content

Instantly share code, notes, and snippets.

@DanSnow
Created November 18, 2015 01:45
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 DanSnow/940b8737285a50643492 to your computer and use it in GitHub Desktop.
Save DanSnow/940b8737285a50643492 to your computer and use it in GitHub Desktop.
Trollor your friend, make a command "command not found"
#!/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