Skip to content

Instantly share code, notes, and snippets.

@nongiach
Last active January 8, 2022 17:32
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nongiach/0a7231896108370c6ec0c42a3d3f1c82 to your computer and use it in GitHub Desktop.
Save nongiach/0a7231896108370c6ec0c42a3d3f1c82 to your computer and use it in GitHub Desktop.
# Author: @chaignc
# Two commands in this script:
# record2discord => send all typed bash command to your discord channel, see bellow for the blacklist
# last2discord => send the last typed command to your discord channel.
DISCORD_WEBHOOK_URL="Your_Discord_WebHook_URL" # UPDATE this with your web hook (take 2 minutes and read about this online)
_send2discord() {
# Blacklist some commands
[[ ! $BASH_COMMAND =~ .*autojump.* ]] && \
[[ ! $BASH_COMMAND =~ ^ls.* ]] && \
[[ ! $BASH_COMMAND =~ ^.?vim.* ]] && \
[[ ! $BASH_COMMAND =~ ^cat.* ]] && \
curl -H "Content-Type: application/json" -X POST \
-d "{\"username\": \"chaignc\", \"content\": \"\`\`\`$BASH_COMMAND\`\`\`\"}" \
$DISCORD_WEBHOOK_URL
}
# send bash typed command to discord in realtime
alias record2discord='trap _send2discord DEBUG'
# send last typed command to discord
function last2discord() { history -w /dev/stdout | sed 'x;$!d' | ( IFS= read -a BASH_COMMAND; _send2discord ) }
alias c=last2discord
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment