Get the tarballs!
Even though Github doesn't expose this in the site (apparently they did ages ago), they provide tar.gz
files of the repositories.
wget -qO - https://github.com/<user>/repo>/archive/master.tar.gz | tar zx --strip-components=1 <repo>-master/<filename>
<user>
, <repo>
, <filename>
are what you'd expect them to be. --strip-components
is use to prevent tar
from creating a directory named after the repo.
Therefore:
$ wget -O - https://github.com/au-answers/dupe-check/archive/master.tar.gz | tar zx --strip-components=1 dupe-check-master/dupe-check
--2016-04-25 08:28:50-- https://github.com/au-answers/dupe-check/archive/master.tar.gz
Resolving github.com (github.com)... 192.30.252.128
Connecting to github.com (github.com)|192.30.252.128|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/au-answers/dupe-check/tar.gz/master [following]
--2016-04-25 08:28:51-- https://codeload.github.com/au-answers/dupe-check/tar.gz/master
Resolving codeload.github.com (codeload.github.com)... 192.30.252.160
Connecting to codeload.github.com (codeload.github.com)|192.30.252.160|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2470 (2.4K) [application/x-gzip]
Saving to: ‘STDOUT’
- 100%[========================================================================================================================================>] 2.41K --.-KB/s in 0s
2016-04-25 08:28:52 (21.5 MB/s) - written to stdout [2470/2470]
$ ll dupe-check
-rwxr-xr-x 1 muru muru 7.5K Mar 5 21:46 dupe-check
I'm not convinced this is a particularly friendly way. An additional chmod +x
is IMO infinitely preferable.
Failed attempts
Get the zips!
You can process substitution on zsh to extract the zips linked on the Github repo page. Github, thankfully, adds extra metadata to zips so that permissions are preserved. unzip
on Ubuntu is able to use that to restore permissions. So:
unzip -j =(wget -O - https://github.com/au-answers/dupe-check/archive/master.zip) dupe-check-master/dupe-check
Unfortunately, =()
is a zsh thing. It creates a proper file instead of a FIFO. Bash doesn't have an equivalent. <()
is always FIFO.
Git single files
You can get a single file from repo using git
. However, Github doesn't support this.
chmod
/ change their umask I'd say would be impossible. GitHub AFAIK doesn't support anything other than HTTPS, so I'd say using a protocol which allows to keep permissions would be impossible either. Executing the file automatically on the other hand would be easy, something likewget -O - https://raw.githubusercontent.com/AskUbuntu-Answers/dupe-check/master/dupe-check | env python3
.python3 <(wget -O - https://raw.githubusercontent.com/AskUbuntu-Answers/dupe-check/master/dupe-check)
would be better, if only to prevent any accidental use of stdin from chewing up the script.