Created
August 20, 2010 06:52
-
-
Save usergenic/539763 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 | |
# This script deals with the weirdness of how googlecl downloads txt format documents from | |
# google. Theres some weird header bytes on the file it gets and my emacs has no idea how | |
# to preserve the newline form, so we transform before sending to emacs. Your mileage may vary. | |
# | |
# You can invoke this script like this: | |
# | |
# $ google docs edit --editor google-edit --format txt --title yourtitlehere | |
# | |
# I use an alias called doc | |
# | |
# alias doc="google docs edit --editor google-edit --format txt --title" | |
# | |
# Pretty handy-- even creates the document if it doesn't exist. | |
# perhaps you would prefer vim? | |
EDITOR="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" | |
# preserve downloaded version | |
cp $* $*.orig_download | |
# chomp the first 3 characters off the file | |
ruby -e 'f=ARGV[0];c=File.read(f)[3..-1];File.open(f,"w"){|h|h.print(c)}' $* | |
# clean up newlines | |
dos2unix $* | |
# make a reference copy of the transformed file | |
cp $* $*.orig_transform | |
# open up the editor and edit the file | |
$EDITOR $* | |
# check for differences between reference copy and edit result | |
diff -i -b -B -q $*.orig_transform $* | |
if [ ! $? -eq 0 ]; then | |
echo "File changed." | |
else | |
# if no change, then move the downloaded copy back into position | |
cp $*.orig_download $* | |
fi | |
# clean up | |
rm $*.orig_download | |
rm $*.orig_transform |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment