Textastic + git: a match made in jailbreaker nerd heaven
The problem domain
I’m absolutely loving Textastic. It’s a text editor for the iPad with syntax highlighting and a lot of those other niceties you’d like to have in a text editor. It’s no TextMate (or Sublime Text), but if I’m editing code on the go, it’s a godsend. The developer is very active in adding new features and correcting any existing problems, too; it’s $10 well spent for me. There is one feature that may or may not be in the works for Textastic, though, that I’ve been jonesing to have. And that’s version control support. I’d love the ability to make clones of my github repos inside Textastic’s working directory, edit my code, and then commit it (and push it). I was feeling exceptionally bold and nerdy yesterday, so I took this roadblock and faced it head-on to roll my own solution. Here’s what I did, translated into what you can do.
The jailbreak
Textastic runs on the iPad. If you have a 1st-generation iPad running on iOS 4.3.1, that’s a prime candidate for jailbreaking! Skip over to the iPhone Dev Team’s blog and download the latest copy of redsn0w and a copy of the iPad 4.3.1 IPSW package (used by redsn0w), and follow redsn0w’s directions (they’re very easy to follow). Mere minutes later, you’ll be rockin' with Cydia on your iPad’s SpringBoard. Moving on…
The packages
In order to do some of the necessary stuff ahead, you’ll need to search for and download a few packages from Cydia. Queue up and install the following:
- Core Utilities (coreutils)
- less
- OpenSSH
- OpenSSL
- iFile (it’s a store package, $5 I believe; it’s indispensable for browsing the iPad’s file system, but if your iPad is connected to a computer you can also use other tools, like funbox)
- Safari Download Manager (again, a commercial package, but you can simply download the files on a computer and use something like funbox, if you prefer)
- git
There’s one more you have to download, but you can’t seem to do it from Cydia. Get the latest build of MobileTerminal, found here. If you’re doing it on your iPad, and you’ve got iFile/Safari Download Manager installed, you can simply tap the link to the latest version, download it into iFile on your iPad, and install it using iFile’s built-in DEB package installer. Otherwise, you’ll have to download the .deb file to your computer and use funbox to install it to your connected iPad.
The configuration
There are a few things we’ll need to do to make this easy on
ourselves, and the first step is to setup a .bashrc file in our /var/mobile/
directory, and define an alias into Textastic’s Documents directory
(it’s a lengthy path). If you’ve got iFile, fire it up and create a
file named .bashrc in the /var/mobile/ directory (make sure you
have iFile’s “Show hidden files” setting on, otherwise you won’t be
able to see it after you create it). You can then tap that file and
open it in iFile’s build in text viewer/editor. (If you’ve got
funbox, you can create this on your computer as a text file and then
transfer it over to the /var/mobile directory, all using funbox).
The file really just needs the line below; if you happen to already
have a .bashrc file, just add this somewhere. This will allow you to
fire up MobileTerminal and just type in textastic, hit enter, and be
placed right where you need to be to get to all of Textastic’s
documents.
alias textastic='cd /var/mobile/Applications/62EBB0B3-5DCC-437A-A6B4-E764EE458579/Documents'
Now that we’ve got our alias, it’s time to make sure MobileTerminal reads this .bashrc file when it launches. Create a .bash_profile file inside your /var/mobile directory, and stick in this line of text.
source ~/.bashrc
Now we’ll need to create a file at /etc/shells (after you login as root).
su root sudo touch /etc/shells
Now we’ll need to edit the contents of that file with the following. Again, edit it using the same method you modified the .bashrc file above.
/bin/sh /bin/bash
Now, ensure this new file is owned by root:wheel (do this as root, again).
chown root:wheel /etc/shells
Then, you’ll need to edit the /etc/master.passwd file (make sure you’re still logged in as root). You’ll see two lines, one beginning with mobile, one beginning with root. Each one ends with :/bin/sh. Change this to read :/bin/bash.
Now the next time you fire up MobileTerminal, you ought to have your .bashrc file loaded.
Explanation:
All the applications (App Store apps, that is) are stored in the
/var/mobile/Applications directory, but they’re not easily
identifiable because each application’s folder is named after the
app’s GUID. This is another place where iFile comes in great handy; it
has a setting that’ll translate all the GUID-looking folder names in
that Applications directory into the actual app names, making it
much easier to find Textastic. Textastic’s GUID is part of that path
shown above; I won’t bother with repeating it again!
The action
Now comes the fun part. Launch MobileTerminal to get started. In the
examples below, each line of code is a new prompt. You’ll have access to that alias we set up. Type it in, then hit enter.
textastic
Now you’ll be in the directory where Textastic stores its documents.
I’ve created a new git folder for all my repos, to keep them
separate from anything else I might create in Textastic.
mkdir git mkdir awesomesauce && cd awesomesauce git init
Voila! Now you have a git repo inside of Textastic. Fire up Textastic
and you’ll see your git folder in all its glory. Edit code in your
new project, then when you need to commit, switch back to
MobileTerminal, jump into the directory where your code is, and run
your git commands.
. ./.bashrc textastic cd git/awesomesauce git status
The only limitation I’ve found right now is that git add -i doesn’t
work; I’m likely missing some dependency it requires, and I have no
idea what that is.
The nice
Of course, you can have git with github too. Just follow github’s directions on setting up your credentials locally.
git config --global user.name "Firstname Lastname" git config --global user.email "email@domain.com" git config --global github.user username git config --global github.token 0123456789yourf0123456789token
Also, since you have ssh installed, you need to generate your
private/public key pair to use in your exchanges with github. Just
follow the prompts after typing…
ssh-keygen
You’ll need to grab the contents of the id_rsa.pub file in
/var/mobile/.ssh/ and paste them in your github account dashboard.
Again, you can do this using iFile, or if you’ve got your iPad
connected to your computer, use something like funbox.
The closing
Anyway, hope this helps you all! It seems like a rather lengthy setup, but apart from installing a few packages, creating a file, and running a couple of terminal commands, it’s actually not too bad, and you only have to set it up once. Let me know if you have any questions!
