Embedded Scripts in WordPress with GitHub Gist and Update Script
I asked at Stack Overflow recently if I could embed a text file into a webpage. My reason was basic: I wanted to be able to use my newly created GitHub script repository to be my source for scripts I posted on this blog. If I was able to do this, I reasoned, than my script on the blog will be up-to-date when I updated my GitHub repository. Unfortunately, there appears to be no direct way to do this that I could find so I look for an alternative and found GitHub Gist. GitHub Gist’s description:
Gist is a simple way to share snippets and pastes with others. All gists are git repositories, so they are automatically versioned, forkable and usable as a git repository.
I was hoping that there would be a way to link a script but there isn’t. Basically the standard process it to visit the GitHub Gist WebUI paste the script, config, … and then post the link on its own line into WordPress.
Because this creates git repository it means it can be updated. So I wrote a script does two functions: 1) Creates a repository for a file; 2) updates all files listed in the script with a Gist repository.
Works pretty good, there are a couple caveats though. First, Gist does not recognize the interpreter on the first line of a script and instead uses the extension. I tend not to use the
.sh extension but I wanted syntax highlighting so the script on the blog now are labeled as
name.sh which I guess isn’t a huge deal. Second, each script must have it’s own repository or all the scripts, configs… would be placed when put into a post. Not sure if this a breach of etiquette but I think I’m ok.
The script requires defunkts excellent
gist command line upload tool.
The syntax is such:
ghsync-gist - Add or update gist repo(s) a - Add gist repo for file(s) u - Update all gist repos for all files