‹ go back

Git and iOS.

Published 22 November 2020 at Yours, Kewbish. 1,281 words. Subscribe via RSS.


Introduction

I’ve always tried to take notes as much as possible on paper, just because it was easier (and theoretically also better for me). However, with COVID and spending more time with digital resources, I’ve tried to take more notes online. These notes have been, from the beginning, backed up somewhere. First, it was to Google Drive; later, to OneDrive, when I used OneNote. I relatively recently transitioned to Markdown files, but kept them in OneDrive. On Windows, I simply left them in the OneDrive folder, and edited with Vim.

On Linux, however, it’s not quite as easy. I originally started off using another OneDrive CLI tool, which served its purpose well. I ran the sync command every so often, and I had access from my phone. However, I found myself not syncing often, and having out of date copies of work on my phone, which wasn’t ideal. There was a bit too much friction for syncing - and to be honest, I just forgot. I could, of course, make a script and shove it in the autostart folder, but that didn’t occur to me til much later.

In an attempt to reap more of the benefits of version control, I then shunted all my files onto a Git repo. It served the same purpose, but with the same problem. I kept forgetting to sync to GitHub.

As well, with just a mostly out of date version on GitHub, I couldn’t access the latest version of my files on my phone. I’m trying to make it as easy as possible to have a sync from both ends, so I searched around for a solution.

This whole process would probably be a lot simpler on Android, but I use an iPhone. (Feel free to rant about non-free software here.) I can’t mess with folders and edit things as easily, so here is my attempt at describing my system now.

Overcomplicated ASCII Art

The system looks something like this:

+---------------------+        +-------------+        +----+
|                     |        |             |        |----|
|    git + sync.sh    | +----> |   |\---/|   | <----+ ||  ||
|                     |        |   |     |   |        ||  ||
+---------------------+        |    \___/    |        +----+
         |---|                 |             |        | || |
       +-------+               +-------------+        +----+

Figure 1. An excuse to experiment with ASCII art.

On the Git repo, I run a sync.sh script on log-in, which pulls the changes and commits and pushes any local ones. Everything then goes to a private GitHub repo.

But the Git integration from my phone would be tricky. Sure, I could view from my phone with the GitHub app, but I don’t think I can write. That’d end up not solving the problem, so I looked for something else.

iOS Magic

Enter Working Copy and Pretext.

I’m not entirely sure if there are other Git clients on iOS, but the one I stumbled upon first was Working Copy. It let me set up another Git identity and get into my GitHub easily. I managed to get everything done in a couple minutes - this part was very simple. (Add new repo, choose GitHub source, log in if it’s a private repo, clone, profit (?))

Great, I now had my notes on the local filesystem. But where?

Turns out that I had to go back and redownload the Files app (I’d uninstalled it in one of my cyclic purges), and enable access from there. Click the three little dots on the top, and switch the slider over for Working Copy.

Figure 2. A tricky hidden slider.

Figure 2. A tricky hidden slider.

This is where you should get Pretext, a simple Markdown editor1. It’s plaintext, with HTML preview, and enough tweaking features. It doesn’t have ads, though there are some other features that are unlockable with payment.

Inside Pretext, enter the Working Copy folder in Pretext, and select your repo of choice. From there, everything is a simple list view away. While Pretext can’t edit anything other than Markdown, that’s all my notes are in, so it works wonderfully. If I ever need to present, and don’t want Markdown syntax, there’s a nice HTML preview available in the Share > Preview as HTML menu.

Syncing

Right, so syncing. Syncing was probably the bigger headache of the two here. For some reason, the first time round I tried getting an XFCE Autostart desktop to work, it would refuse to do anything. I assume this is due to an issue that I’ll touch on in a few lines.

Under Session and Startup > Application Autostart, I +Added a new desktop file. I’m pretty sure it’s important that this doesn’t have a space in its title - that was the only thing different between my two attempts. The command I had it run was simply the bash script I wrote, which, for my later convenience, is below:

#!/bin/bash

cd ~/EVB/
if [[ `git status --porcelain` ]]; then
    for i in {1..50}; do ping -c1 www.google.com &> /dev/null && break; done
    NOW=$( date '+%F-%H%M' )
    git add .
    git commit --author="Emilie Ma <notarealemail@kewbi.sh>" -m "Sync: $NOW"
    git pull
    git push
    echo "Successful!"
else
    echo "No changes!"
fi

Probably change the directory to the one you’re using for your Git. Also, probably change the author, unless you’ve decided to impersonate me or are also named Emilie Ma.

And there we go - on login (since I do this at the beginning of the day, and I often only edit anything on my phone the afternoon before or at night), all changes will be pulled (and theoretically won’t conflict - I’m the only one using this, and I don’t tend to edit the same note at different times). The changes locally get pushed, and everything is fine and dandy!

Conclusion

Is this incredibly overengineered? Actually, not really. This is the simplest way I’ve found to do it, other than to just fire up my laptop every time I want to reference something, which I’d rather not do. I’m still not entirely sure how Working Copy even works, especially with the sandboxing things that are supposed to happen behind the scenes, but I won’t question it too much. It’s a nice system, and it works well enough.

This post is mostly for self reference later, but if I’ve somehow managed to help, that’s cool too.

Currently

It’s been a while since I appended one of these, so apologies if the conclusion was a bit abrupt. I’ve been working a decent bit more on my Racket x Chip-8 emulator attempt, and it hasn’t been very successful. I chalk this up to the fact I don’t know how to use the GUI / something’s wrong with the display code - the rest of it worked fine (theoretically) without it.

I have, however, managed to at least get some sort of display working with charterm, but I need to fix a pesky issue. The width for the display should be 64 pixels, and I can print much more to the terminal, but I need to find a way to linebreak. The display refuses to take newline characters, so that’s a bit of a challenge. I’m sure I’ll manage to work out some janky solution, anyhow.

I’ve also found some other amazing Racket games and Chip-8 implementations, so hopefully I can leech a bit off of their approaches. If all goes well, I’ll write about my progress next week. If not, I have some other ideas. Well, back to writing lab2.


  1. Having attempted to work with Notes before, I didn’t want to bother with trying to select and bold text with the WYSIWYG panes again. ↩︎

  2. And on another, slightly more quantitative note, I managed to hit 50k words on this blog! Five weeks ahead of schedule, so that’s something. ↩︎


‹ go back