Created
November 27, 2019 14:13
-
-
Save cuu/33697a88648ee8d831f558eade427d06 to your computer and use it in GitHub Desktop.
generate raw.github for github repo file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env newlisp | |
; simple encoder | |
(define (url-encode str) | |
(replace {([^a-zA-Z0-9])} str (format "%%%2X" (char $1)) 0)) | |
(define (encode_space str) | |
(replace " " str "%20" ) | |
) | |
(setq raw_head "https://raw.githubusercontent.com/") | |
(setq git_remote (exec "git config --get branch.master.remote")) | |
(if (<= (length git_remote) 0) | |
(begin | |
(println "git error exiting...") | |
(exit) | |
) | |
) | |
(setq origin_url (exec (string "git config --get remote." (nth 0 git_remote) ".url"))) | |
(setq url_parts (parse (nth 0 origin_url) "/")) ;("https:" "" "github.com" "cuu" "gamestore.git") | |
;(println (find "github.com" url_parts)) | |
(setq github_subname (nth (+ (find "github.com" url_parts) 1) url_parts)) | |
;(println github_subname) | |
(setq pro_basename (exec (string "basename " "\"" (nth 0 origin_url) "\"" " .git") )) | |
;(println pro_basename) | |
(setq this_branch (nth 0 (exec "git branch | grep \\* | cut -d ' ' -f2"))) | |
;(println this_branch) | |
(setq current_path (nth 0 (exec "pwd"))) | |
;(println (length (main-args))) | |
(setq current_path_lst (parse (slice current_path (find (nth 0 pro_basename) current_path )) "/")) | |
(if (= (length (main-args)) 3) | |
(begin | |
(if (> (length current_path_lst) 1) | |
(println (encode_space (string raw_head github_subname "/" (nth 0 pro_basename) "/" this_branch "/" (join (rest current_path_lst) "/") "/" (nth 2 (main-args)) ))) | |
(println (encode_space (string raw_head github_subname "/" (nth 0 pro_basename) "/" this_branch "/" (nth 2 (main-args)) ))) | |
) | |
) | |
(begin | |
(if (> (length current_path_lst) 1) | |
(println (string raw_head github_subname "/" (nth 0 pro_basename) "/" this_branch "/" (join (rest current_path_lst) "/"))) | |
(println (string raw_head github_subname "/" (nth 0 pro_basename) "/" this_branch)) | |
) | |
) | |
) | |
(exit) |
Author
cuu
commented
Nov 27, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment