-
-
Save davidad/8981964 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ORIGDIR=`pwd | sed 's/\ /\\ /g'` | |
cd ~/octopress | |
URL="http://davidad.github.io/" | |
function wrs() { | |
if [[ $2 = "y" ]]; then | |
L1="set theWindow's active tab index to theTabIndex" | |
L2="tell window 1 to make new tab with properties {URL:\"$1\"}" | |
else | |
L1="" | |
L2="" | |
fi | |
cat >.reload.scpt <<EOF | |
delay 0.8 | |
tell application "Google Chrome" | |
if (count every window) = 0 then | |
make new window | |
end if | |
set found to false | |
set theTabIndex to -1 | |
repeat with theWindow in every window | |
set theTabIndex to 0 | |
repeat with theTab in every tab of theWindow | |
set theTabIndex to theTabIndex + 1 | |
if theTab's URL contains "$1" then | |
set found to true | |
exit | |
end if | |
end repeat | |
if found then | |
exit repeat | |
end if | |
end repeat | |
if found then | |
tell theTab to reload | |
$L1 | |
else | |
$L2 | |
end if | |
end tell | |
EOF | |
} | |
wrs 'http://localhost:4000/' y | |
if [[ $1 = delete ]]; then | |
[[ -f $2 ]] && rm -i $2 && bundle exec rake generate && exec $0 deploy | |
exit 0 | |
elif [[ $1 = deploy ]]; then | |
bundle exec rake deploy \ | |
&& wrs $URL y && sleep 3 && osascript ./.reload.scpt \ | |
&& rm -f ./.reload.scpt .timeref rake_preview.log \ | |
&& git add . \ | |
&& git commit -m "Site updated at `date -u +"%Y-%m-%d %H:%M:%S UTC"`" \ | |
&& git push | |
exit 0 | |
fi | |
[[ -f $1 ]] && rm -f new_post.md && ln -s $1 new_post.md | |
[[ -f $1 ]] || bundle exec rake "new_post[$1]" | |
touch -m .timeref | |
ps x | egrep 'rake|rackup|jekyll|sass|compass' | grep -v grep | awk '{ print $1 }' | xargs kill | |
ps x | egrep 'rackup' | grep -v grep | awk '{ print $1 }' | xargs kill -9 | |
bundle exec rake preview > rake_preview.log 2>&1 & | |
sleep 0.3 | |
osascript ./.reload.scpt | |
vim -c 'set tw=80' -c 'map <C-G> :w<CR>:!osascript ./.reload.scpt<CR><CR>' \ | |
-c "cd $ORIGDIR" + new_post.md | |
VIM_STATUS=$? | |
[[ `readlink new_post.md` -nt .timeref ]] || VIM_STATUS=1 | |
[ $VIM_STATUS -eq 0 ] && osascript ./.reload.scpt && exec $0 deploy && exit 0 | |
[ $VIM_STATUS -ne 0 ] && wrs 'http://localhost:4000/' n \ | |
&& [ -f new_post.md ] && rm -i `readlink new_post.md` \ | |
&& git rm --ignore-unmatch new_post.md \ | |
&& sleep 0.4 && osascript ./.reload.scpt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment