Add pre-push hook. #35

Closed
alexcouper opened this Issue May 16, 2014 · 21 comments

Comments

Projects
None yet
5 participants
@alexcouper
Owner

alexcouper commented May 16, 2014

I want to play "push it" by salt n pepa on every push.

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper May 17, 2014

Owner

I'm having difficulty forking the process into the background so that the push doesn't wait for the end of the song before exiting.

#!/bin/bash

#mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- &
mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- & disown
#nohup mplayer -really-quiet -cache 8192 -vo null - /Users/alex/pushit_small.mp3 > /dev/null 2>&1 &
#mplayer -really-quiet /Users/alex/pushit_small.mp3 <&- >&- 2>&- & disown
#mplayer -really-quiet /Users/alex/pushit_small.mp3 & disown
#mplayer -really-quiet /Users/alex/pushit_small.mp3 >/dev/null 2>&1 &
echo "done"
exit 0

None of the above exit before the mp3 (a 10 second sample) has finished.
Although they do echo "done"

Owner

alexcouper commented May 17, 2014

I'm having difficulty forking the process into the background so that the push doesn't wait for the end of the song before exiting.

#!/bin/bash

#mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- &
mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- & disown
#nohup mplayer -really-quiet -cache 8192 -vo null - /Users/alex/pushit_small.mp3 > /dev/null 2>&1 &
#mplayer -really-quiet /Users/alex/pushit_small.mp3 <&- >&- 2>&- & disown
#mplayer -really-quiet /Users/alex/pushit_small.mp3 & disown
#mplayer -really-quiet /Users/alex/pushit_small.mp3 >/dev/null 2>&1 &
echo "done"
exit 0

None of the above exit before the mp3 (a 10 second sample) has finished.
Although they do echo "done"

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper May 17, 2014

Owner

Largely courtesy of @OddBloke:

Generating the awesome push it clip:

curl -s "$(youtube-dl -g http://www.youtube.com/watch\?v\=vCadcBR95oU -k)" > pushit
ffmpeg -i pushit pushit.wav
sox pushit.wav pushit_small.mp3 trim 1:56 10 fade 0:1 0 0:4
Owner

alexcouper commented May 17, 2014

Largely courtesy of @OddBloke:

Generating the awesome push it clip:

curl -s "$(youtube-dl -g http://www.youtube.com/watch\?v\=vCadcBR95oU -k)" > pushit
ffmpeg -i pushit pushit.wav
sox pushit.wav pushit_small.mp3 trim 1:56 10 fade 0:1 0 0:4
@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson May 18, 2014

Contributor

I changed the curl/ffmpeg commands into this: youtube-dl http://www.youtube.com/watch\?v\=vCadcBR95oU -qckx --audio-format wav -o pushit.wav

Contributor

koddsson commented May 18, 2014

I changed the curl/ffmpeg commands into this: youtube-dl http://www.youtube.com/watch\?v\=vCadcBR95oU -qckx --audio-format wav -o pushit.wav

@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson May 18, 2014

Contributor

Sorry that actually doesn't extract the audio from the video

Contributor

koddsson commented May 18, 2014

Sorry that actually doesn't extract the audio from the video

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper May 18, 2014

Owner

Another one I want, probably on nosetests not returning an error:

curl -s "$(youtube-dl -g https://www.youtube.com/watch\?v\=fm660vIn8Tg -k)" > vid
ffmpeg -i vid vid.wav
sox vid.wav vid.mp3 trim 0:11 19 fade 0:1 0 0:2
Owner

alexcouper commented May 18, 2014

Another one I want, probably on nosetests not returning an error:

curl -s "$(youtube-dl -g https://www.youtube.com/watch\?v\=fm660vIn8Tg -k)" > vid
ffmpeg -i vid vid.wav
sox vid.wav vid.mp3 trim 0:11 19 fade 0:1 0 0:2
@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson May 18, 2014

Contributor

I messed around with a bunch of methods to achieve background music playing in the terminal and nothing seemed to work on my machine. My only thought now is doing all these operations in python (import youtube-dl as a library, slicing up the audio using some other library and then playing it) and forking that python script to the background.

Contributor

koddsson commented May 18, 2014

I messed around with a bunch of methods to achieve background music playing in the terminal and nothing seemed to work on my machine. My only thought now is doing all these operations in python (import youtube-dl as a library, slicing up the audio using some other library and then playing it) and forking that python script to the background.

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper May 18, 2014

Owner

I have this script:

$ cat .git/hooks/pre-push
#!/bin/bash

mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- & disown
echo "done"
exit 0

If I run .git/hooks/pre-push directly from the command line it works. As in, the music starts and I am given the console before the music finishes.

It's just that from the hook it fails. As in when run with git push

Owner

alexcouper commented May 18, 2014

I have this script:

$ cat .git/hooks/pre-push
#!/bin/bash

mplayer -really-quiet /Users/alex/pushit_small.mp3 >&- 2>&- & disown
echo "done"
exit 0

If I run .git/hooks/pre-push directly from the command line it works. As in, the music starts and I am given the console before the music finishes.

It's just that from the hook it fails. As in when run with git push

@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson May 18, 2014

Contributor

Does it fail in the sense that it hangs or in the sense that it doesn't play the clip?

Contributor

koddsson commented May 18, 2014

Does it fail in the sense that it hangs or in the sense that it doesn't play the clip?

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper May 18, 2014

Owner

Yes, sorry - it fails in the sense that it hangs whilst playing the clip - and only returns to the console after that.

Owner

alexcouper commented May 18, 2014

Yes, sorry - it fails in the sense that it hangs whilst playing the clip - and only returns to the console after that.

@ikornaselur

This comment has been minimized.

Show comment
Hide comment
@ikornaselur

ikornaselur May 19, 2014

Have you tried running a python script that spawns a subprocess?

For example

from subprocess import Popen

Popen(["mplayer", "-really-quiet", "vid.mp3"])

I have no idea if this works as a git hook, but this runs in a few milliseconds for me and returns to my shell with the audio playing in the background. I can even kill the shell that ran the python process.

Have you tried running a python script that spawns a subprocess?

For example

from subprocess import Popen

Popen(["mplayer", "-really-quiet", "vid.mp3"])

I have no idea if this works as a git hook, but this runs in a few milliseconds for me and returns to my shell with the audio playing in the background. I can even kill the shell that ran the python process.

@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson May 19, 2014

Contributor

I can confirm that @ikornaselur's solution works

Contributor

koddsson commented May 19, 2014

I can confirm that @ikornaselur's solution works

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper Jun 3, 2014

Owner

@koddsson I beg to differ.

$ cat .git/hooks/pre-push
#!/usr/bin/env python

import sys
from subprocess import Popen

Popen(["mplayer", "-really-quiet", "/Users/alex/pushit_small.mp3"])
sys.exit(0)

When I run:
git push

I have to wait for the tune to play before getting terminal access again.

Owner

alexcouper commented Jun 3, 2014

@koddsson I beg to differ.

$ cat .git/hooks/pre-push
#!/usr/bin/env python

import sys
from subprocess import Popen

Popen(["mplayer", "-really-quiet", "/Users/alex/pushit_small.mp3"])
sys.exit(0)

When I run:
git push

I have to wait for the tune to play before getting terminal access again.

@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson Jun 3, 2014

Contributor

Huh, that's weird. Works on my ubuntu 14.04. Maybe you need to upgrade to a better OS.

Contributor

koddsson commented Jun 3, 2014

Huh, that's weird. Works on my ubuntu 14.04. Maybe you need to upgrade to a better OS.

@koddsson

This comment has been minimized.

Show comment
Hide comment
@koddsson

koddsson Jun 3, 2014

Contributor

All jokes aside maybe we can compare how it works on our different machines tomorrow at work.

Contributor

koddsson commented Jun 3, 2014

All jokes aside maybe we can compare how it works on our different machines tomorrow at work.

@OddBloke

This comment has been minimized.

Show comment
Hide comment
@OddBloke

OddBloke Jun 4, 2014

Collaborator

Yeah, I haven't had any problems with backgrounding the hook on my Debian machine.

Collaborator

OddBloke commented Jun 4, 2014

Yeah, I haven't had any problems with backgrounding the hook on my Debian machine.

@OddBloke

This comment has been minimized.

Show comment
Hide comment
@OddBloke

OddBloke Jun 4, 2014

Collaborator

One potential solution to try: daemonising the process that calls mplayer.

Collaborator

OddBloke commented Jun 4, 2014

One potential solution to try: daemonising the process that calls mplayer.

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper Jun 5, 2014

Owner

Closing on account of impossibility on mac.

For reasons that are beyond me.

Owner

alexcouper commented Jun 5, 2014

Closing on account of impossibility on mac.

For reasons that are beyond me.

@alexcouper alexcouper closed this Jun 5, 2014

@jeremykenedy

This comment has been minimized.

Show comment
Hide comment
@jeremykenedy

jeremykenedy Jun 24, 2015

Hi,

You can use quicktime to snip your mp3 and the native mac command line player to play it from command line.

Please see below.

#!/bin/bash

## ADD VARIABLES HERE ##
_yourSoundFileAndPath="/Users/jeremykenedy/Desktop/pushit-jk-master/pushit8s.m4a"

## ADD ALIAS'S HERE ##
alias pushitmaster="git push origin master;afplay "$_yourSoundFileAndPath

I also created a repo @ https://github.com/jeremykenedy/pushit

Yay !

Jeremy :)

Hi,

You can use quicktime to snip your mp3 and the native mac command line player to play it from command line.

Please see below.

#!/bin/bash

## ADD VARIABLES HERE ##
_yourSoundFileAndPath="/Users/jeremykenedy/Desktop/pushit-jk-master/pushit8s.m4a"

## ADD ALIAS'S HERE ##
alias pushitmaster="git push origin master;afplay "$_yourSoundFileAndPath

I also created a repo @ https://github.com/jeremykenedy/pushit

Yay !

Jeremy :)

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper Jun 24, 2015

Owner

Nice @jeremykenedy - I'll see if afplay suffers from the same behaviour as mplayer when combined with a git hook.

Owner

alexcouper commented Jun 24, 2015

Nice @jeremykenedy - I'll see if afplay suffers from the same behaviour as mplayer when combined with a git hook.

@alexcouper

This comment has been minimized.

Show comment
Hide comment
@alexcouper

alexcouper Jun 24, 2015

Owner

yeah unfortunately it looks like alias-ing is the only way to get this to work on mac.

Somehow (I have no idea how) the git push waits for the script to play despite the process being forked.

git-funnies

Owner

alexcouper commented Jun 24, 2015

yeah unfortunately it looks like alias-ing is the only way to get this to work on mac.

Somehow (I have no idea how) the git push waits for the script to play despite the process being forked.

git-funnies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment