Shell native Google drive

A year ago I’ve built a setup where I can edit my Google drive documents with Vim but it didn’t catch because I was using drive which requires manual pulling and pushing, just like Git. So while I’m using Git on daily basis, Google drive is only needed when I want to collaborate or easily share a document which apparently is not so often. After short dry time and maybe some small issues, I forgot about it. However it’s still a sour point for me because I’m browsing with Qutebrowser and editing Google docs in it is not so fluent.

Yesterday, my friend Shaked shared with me a nice gem, GCSF:

GCSF is a virtual filesystem that allows users to mount their Google Drive account locally and interact with it as a regular disk partition.

GCSF is libfuse based, and there were other similar projects before but they seemed outdated when I wanted to try them. This is a very good news because now I don’t need to think about pulling or pushing. I just need to go to my local folder and edit the file.

How to edit a Google doc file locally with Vim:

  1. Install GCSF and mount your Google drive.
  2. Install Pandoc.
  3. Browse to Google drive settings, check the box ‘Convert Uploads’.
  4. Add to your Vim configuration (.vimrc):

    1
    2
    autocmd BufReadPost *.odt :%!pandoc -f odt -t markdown
    autocmd BufWritePost *.odt :!pandoc -f markdown -t odt % -o "%:r".odt

  5. Create user service at ~/.config/systemd/user/:
  6. Enable and start the service

    1
    2
    systemctl --user enable gcsf
    systemctl --user start gcsf

Notes:

  • When you create a Google doc, it should have ‘odt’ extension in your local mount.
  • If you want to create a Google doc locally, make sure it has ‘.odt’ suffix.
  • You can add more file types in the same matter, such as ‘docx’ but it has little use in Google drive.
  • Cooperative editing won’t work, and I won’t bet it will happen anytime soon or in this matter.
  • Don’t edit it while others might be editing it.
  • Pandoc conversion will destroy some WYSIWYG, for example pictures positions and fonts. Work with simple documents.

What is it good for?

  • GCSF in general makes it easier to share with others, makes it more like Dropbox.
  • Google drive allows hosting static webpages1, maybe it can work with Hexo and the like
  • Easy backup for documents and the like (not sure how good it will work)
  • Initial drafting - Google docs has ‘suggestion’ and allows commenting which is more important in document development and you loose that in conversion. But the first step is the hardest step.

  1. I can’t find the original documentation but Google it ;)