Skip to content

Instantly share code, notes, and snippets.

@zackshapiro
Last active August 29, 2015 14:15
Show Gist options
  • Save zackshapiro/b65824847e542d1903d8 to your computer and use it in GitHub Desktop.
Save zackshapiro/b65824847e542d1903d8 to your computer and use it in GitHub Desktop.
How to create a git watcher
# this assumes you have brew installed – http://brew.sh/
# and oh-my-zsh – https://github.com/robbyrussell/oh-my-zsh
# First, create a new zshell script
cd ~/.oh-my-zsh/plugins
mkdir your-plugin
cd your-plugin
# create the empty script doc
touch your-plugin.plugin.zsh
# open the file in your text editor of choice. Mine is Atom (atom.io)
atom your-plugin.plugin.zsh
# Create your script
# this navigates to where I keep my changelogs.md file, creates a var with the date info ex. 10-25-2014
# adds, commits, and pushes any new changes to that file (that file's the only thing in that
# then cds out of the directory
cd ~/dev/changelogs/
d=$(date +'%m-%d-%Y')
git add .
git commit -m "$d"
git push
cd
# Install fswatch – fswatch will watch for any save event
# docs – https://github.com/emcrisostomo/fswatch
brew update
brew install fswatch
# Watch the file (change the first file path to the file or directory you want to watch)
fswatch -o ~/dev/changelogs/changelog.md | xargs -n1 bash ~/.oh-my-zsh/plugins/your-plugin/your-plugin.plugin.zsh
# Create an alias
cd
cd .zshrc
alias watch='fswatch -o ~/dev/changelogs/changelog.md | xargs -n1 bash ~/.oh-my-zsh/plugins/your-plugin/your-plugin.plugin.zsh'
# Open a new tab in your terminal and type watch to constantly monitor for that file to be saved
# I haven't looked for a good way yet to have this running without a dedicated tab but I'm sure there's a way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment