shithub: shithub

Download patch

ref: b2f9582d4c988b7e8de59338402b63158470acd4
parent: 222e7d2a3fc43fbf9181e2c58c2a52c900da74bf
author: phil9 <telephil9@gmail.com>
date: Sun Jan 31 05:30:02 EST 2021

files: raw file view

	add link to file viewer to display raw file instead of an html
	rendering

--- a/gitrules
+++ b/gitrules
@@ -3,3 +3,4 @@
 /([^'/]+)/([^'/]+)/([^'/]+)/files.html		/bin/shithub /usr/git files '\1' '\2' '\3'
 /([^'/]+)/([^'/]+)/([^'/]+)/snap.tar.gz		/bin/shithub /usr/git tar '\1' '\2' '\3'
 /([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?f.html	/bin/shithub /usr/git view '\1' '\2' '\3' '\5'
+/([^'/]+)/([^'/]+)/([^'/]+)/(([^']+)/)?raw	/bin/shithub /usr/git viewraw '\1' '\2' '\3' '\5'
--- a/shithub
+++ b/shithub
@@ -256,13 +256,15 @@
 
 	user_prelude $gituser $repo $hash
 
-	echo '	<p>'$repo' @ <a href="'/git/$gituser/$repo/$hash/f.html'">'$hash'</a>
-		<pre id="code">'
+	echo '	<p>'$repo' @ <a href="'/git/$gituser/$repo/$hash/f.html'">'$hash'</a><br/></p>'
 	if(test -f $file){
+		echo '	<a href="'/git/$gituser/$repo/$hash/$file'/raw">View raw version</a>'
+		echo '	<pre id="code">'
 		htcat $file
 	}
 	if not if(test -d $file){
 		cd $file
+		echo '	<pre id="code">'
 		for(f in `$nl{ls}){
 			url=`$nl{echo -n $f/f.html | urlencode}
 			fname=`$nl{echo -n $f | htcat}
@@ -272,4 +274,19 @@
 	echo '	</pre>
 		</body>
 		</html>'
+
+case 'viewraw'
+	gituser=$2
+	repo=$3
+	refname=$4
+	file=$5
+
+	repons $gituser $repo
+	if(! ref=`{resolveref $refname}){
+		echo 'invalid ref '$refname''
+		exit
+	}
+	cd /mnt/git/$ref/tree
+	cat $file
+
 }