Skip to content

Instantly share code, notes, and snippets.

@mracos
Created May 31, 2019 21:24
Show Gist options
  • Save mracos/76797f8b05278b58cf2f42a89e769900 to your computer and use it in GitHub Desktop.
Save mracos/76797f8b05278b58cf2f42a89e769900 to your computer and use it in GitHub Desktop.
git audio macos only
#!/usr/bin/env ruby
require 'base64'
require 'tempfile'
if ARGV.count == 0
puts <<~HELP
Usage: git audio [command]
Commands available:
- git audio commit path_to_audio.mp3
It will create a commit with a audio embed in it
- git audio show commit_hash
It will play an audio associated with a commit
HELP
end
AUDIO_START= '==AUDIO=='
command = ARGV.first
if command == 'commit'
path_to_audio = ARGV[1]
# no new lines in generated base64
encoded_audio = Base64.strict_encode64(File.read(path_to_audio))
`git commit -m '#{encoded_audio}'`
elsif command == 'show'
commit_hash = ARGV[1]
# get only commit description
encoded_audio = `git log --format=%B -n 1 #{commit_hash}`
file = Tempfile.new("git-audio")
file.write(Base64.decode64(encoded_audio))
`afplay #{file.path}`
file.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment