├── .gitignore ├── Makefile ├── package.json ├── README.md ├── LICENSE └── bin └── c /.gitignore: -------------------------------------------------------------------------------- 1 | **/*.pyc 2 | **/*.pyo 3 | todo.md 4 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | 3 | install: bin/c 4 | mkdir -p $(PREFIX)/$(dir $<) 5 | cp $< $(PREFIX)/$< 6 | 7 | uninstall: 8 | rm -f $(PREFIX)/bin/c 9 | 10 | .PHONY: install uninstall 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "c-clone", 3 | "version": "1.0.0", 4 | "description": "clone a github folder", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/neo1218/c.git" 12 | }, 13 | "keywords": [ 14 | "github", 15 | "clone", 16 | "folder" 17 | ], 18 | "bin": { 19 | "c": "./bin/c" 20 | }, 21 | "preferGlobal": true, 22 | "engines": { 23 | "node": "*" 24 | }, 25 | "author": "neo1218 (http://neo1218.github.io)", 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/neo1218/c/issues" 29 | }, 30 | "homepage": "https://github.com/neo1218/c#readme" 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # c 2 | [![npm](https://img.shields.io/npm/v/c-clone.svg?maxAge=2592000)](https://www.npmjs.com/package/c-clone) 3 |
4 | clone a github repo folder but change it to svn . 5 | 6 | ## Install 7 | 8 | ```$ npm install -g c-clone``` 9 | 10 | ## Info 11 | [Info]
12 | c: clone a github repo folder
13 | version: 1.0.0
14 | 15 | ## Usage 16 | [Usage]
17 | c install [github_folder_url]
18 | c install [github_folder_url] [rename]
19 | 20 | for example: if you want to get flask examples, but don't like clone the whole flask repo, 21 | you can run:
22 | ```c install https://github.com/pallets/flask/tree/master/examples```
23 | or clearer
24 | ```c install https://github.com/pallets/flask/tree/master/examples flask_examples```
25 | 26 | ## Note 27 | if you first use c install, you may meet this: 28 | 29 | R)eject, accept (t)emporarily or accept (p)ermanently? 30 | 31 | just type P :) 32 | 33 | ## License 34 | MIT@neo1218
35 | check [LICENSE](https://github.com/neo1218/c/blob/master/LICENSE) for more detail 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright © 2016 neo1218 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 6 | associated documentation files (the “Software”), to deal in the Software without restriction, 7 | including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 15 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 16 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 17 | -------------------------------------------------------------------------------- /bin/c: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # c: c install repo_url 3 | 4 | # 5 | # setup 6 | # 7 | version='1.0.0' 8 | repoinfo=() 9 | svnurl="" 10 | 11 | # 12 | # show_version: show version info 13 | # 14 | function show_version() 15 | { 16 | cat <<-EOF 17 | [Info] 18 | c: clone a github repo folder 19 | version: $version 20 | EOF 21 | } 22 | 23 | 24 | # 25 | # error_exit 26 | # file descriptor 1 is the stdout 27 | # file descriptor 2 is the stderr 28 | # 2>&1: stderr redirect to stdout 29 | # 30 | function error_exit() 31 | { 32 | echo $1 2>&1 33 | exit 1 34 | } 35 | 36 | # 37 | # log 38 | # 39 | function log() 40 | { 41 | printf " \033[36m%10s\033[0m : \033[90m%s\033[0m\n" $1 $2 42 | } 43 | 44 | # 45 | # magic 46 | # 47 | function magic() 48 | { 49 | giturl=$1 50 | local IFS="/" 51 | 52 | repoinfo=($giturl) 53 | repoinfo[5]="trunk" 54 | unset repoinfo[6] 55 | 56 | git2svn=${repoinfo[@]} 57 | svnurl=${git2svn// //} 58 | } 59 | 60 | # 61 | # check 62 | # 63 | function check_github() 64 | { 65 | hostname=${repoinfo[2]} 66 | shouldbe="github.com" 67 | if [ "$hostname" != "$shouldbe" ] 68 | then 69 | error_exit "the url is not a github repo url" 70 | exit 1 71 | fi 72 | } 73 | 74 | # 75 | # check_path_exist 76 | # 77 | function check_path_exist() 78 | { 79 | if test -d "./$1" 80 | then 81 | error_exit "$1 already exists, please change the name!" 82 | exit 1 83 | fi 84 | } 85 | 86 | # 87 | # bar 88 | # 89 | 90 | # 91 | # display help msg 92 | # 93 | function display_help() 94 | { 95 | cat <<-EOF 96 | [Usage] 97 | c install [github_folder_url] 98 | c install [github_folder_url] [rename] 99 | EOF 100 | } 101 | 102 | # 103 | # svn_clone 104 | # use svn clone the folder 105 | # 106 | function svn_clone() 107 | { 108 | if test -z $2 109 | then 110 | svn checkout $1 111 | else 112 | svn checkout $1 $2 113 | fi 114 | } 115 | 116 | # 117 | # main 118 | # handle arguments 119 | # 120 | if test $# -eq 0; then 121 | show_version 122 | else 123 | while test $# -ne 0; do 124 | case $1 in 125 | install) 126 | repourl=$2 127 | if test -z $3 128 | then : 129 | else rename=$3 130 | fi 131 | 132 | magic $repourl 133 | check_github 134 | if test -z $3 135 | then 136 | check_path_exist ${repoinfo[${#repoinfo[@]}]} 137 | svn_clone $svnurl 138 | else 139 | check_path_exist $3 140 | svn_clone $svnurl $3 141 | fi 142 | ;; 143 | -h|--help) 144 | display_help ;; 145 | -v|--version) 146 | show_version ;; 147 | esac 148 | shift 149 | done 150 | fi 151 | --------------------------------------------------------------------------------