gitmagical 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/gitmagic +171 -0
  3. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70c70528c492c0f61a5b4c1b8c7e6b69f48563e95545080697a7ea92bd6d4e95
4
+ data.tar.gz: 1c0b896beae4857bfc9769dd8ca2cb1dac26df07abec8c9643d7d889861ece56
5
+ SHA512:
6
+ metadata.gz: f526251bbe030a94c0e2a1e8bf2f24ddfcf2ad639acb57ba566a89056779ef346d03358d0ecfe57b3b19f33c1ddde8b0a4cf3ffec37dec1166ea16cf3edc5176
7
+ data.tar.gz: 4a40fe81f418776789ed444729becb808e31e5797daebf61d57e98dc50b1d476620e4074b31d7887894edded22869730a352a74c4eb625c421ca7e1c71919078
data/bin/gitmagic ADDED
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # Change these settings to fit your setup:
5
+ $user = "isene"
6
+ $repodir = "/home/geir/G/GIT-isene"
7
+ $pres_templ = "/home/geir/G/GIT/gh-presentation"
8
+ $issues = "true"
9
+ $downloads = "true"
10
+ $wiki = "false"
11
+ $priv = "false"
12
+
13
+ # Initializing variable
14
+ $dir = Dir.pwd
15
+ $message = ""
16
+ $desc = ""
17
+ $repo = ""
18
+
19
+ require 'getoptlong'
20
+ require 'fileutils'
21
+ require 'date'
22
+
23
+ prgmversion = 0.1
24
+
25
+ def help
26
+ puts <<HELPTEXT
27
+ NAME
28
+ "gitmagic" is a swiss army knife of git tools
29
+
30
+ SYNOPSIS
31
+ gitmagic [-idDpusvh] [long-options]
32
+
33
+ DESCRIPTION
34
+ gitmagic makes initiating a project easy, also from
35
+ a local template project. It also simplifies updating
36
+ git projects. It will do more in due time.
37
+
38
+ OPTIONS
39
+ -c, --clone
40
+ Simply clones a repo, just like 'git clone'.
41
+ -i, --init
42
+ Initialize a new github project.
43
+ Requires a name for the repo as argument
44
+ You may supply --desc (-d) for a description of the repo, or else a
45
+ description will be added in the form "Project_2018-09-13"
46
+ You may supply a dir path "--dir" (-D), or else the current dir is used
47
+ EXAMPLE: gimagic -i "My new repo!" -d "Really cool stuff" -D ~/projects/124
48
+ -d, --desc
49
+ Add description to a new repo
50
+ Used in combination with --init or --slides
51
+ -D, --dir
52
+ Specify the directory for a new initiated repo
53
+ Used in combination with --init or --update
54
+ If no directory is specified, the program will use the current directory
55
+ -p, --priv
56
+ Make the Github repo private
57
+ -u, --update
58
+ Update a github project
59
+ Takes the commit message as argument
60
+ You may supply a dir path "--dir" (-D), or else the current dir is used
61
+ EXAMPLE: gimagic -u "Bug fix" -D ~/projects/159
62
+ -s, --slides
63
+ Create a presentation project with slides written in simple Markdown text.
64
+ See Fredrik Eilertsen's neat work that makes it possible to create
65
+ presentations using Jekyll (https://github.com/fredeil/gh-presentation)
66
+ This option will use '$pres_templ' to find the cloned "gh-presentation"
67
+ It will create the presentation under your '$repodir'
68
+ You must supply a name for your repo/presentation as the argument
69
+ EXAMPLE: gimagic -s "Presentation23"
70
+ -v, --version
71
+ Show the version of this program
72
+ -h, --help
73
+ Show this help text
74
+
75
+ COPYRIGHT:
76
+ Copyright 2018, Geir Isene (https://isene.org)
77
+ This program is released under the WTFPL license
78
+ (Full license text here: http://www.wtfpl.net/about/)
79
+ HELPTEXT
80
+ end
81
+
82
+ opts = GetoptLong.new(
83
+ [ "--clone", "-c", GetoptLong::REQUIRED_ARGUMENT ],
84
+ [ "--init", "-i", GetoptLong::REQUIRED_ARGUMENT ],
85
+ [ "--desc", "-d", GetoptLong::REQUIRED_ARGUMENT ],
86
+ [ "--dir", "-D", GetoptLong::REQUIRED_ARGUMENT ],
87
+ [ "--priv", "-p", GetoptLong::NO_ARGUMENT ],
88
+ [ "--update", "-u", GetoptLong::REQUIRED_ARGUMENT ],
89
+ [ "--slides", "-s", GetoptLong::REQUIRED_ARGUMENT ],
90
+ [ "--version", "-v", GetoptLong::NO_ARGUMENT ],
91
+ [ "--help", "-h", GetoptLong::NO_ARGUMENT ]
92
+ )
93
+
94
+ def gitinit
95
+ `git init #{$dir}`
96
+ # Fix the git confi file
97
+ gitconftxt = "[remote \"origin\"]\n"
98
+ gitconftxt += "\turl = git@github.com:#{$user}/#{$repo}.git\n"
99
+ gitconftxt += "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
100
+ gitconftxt += "[branch \"master\"]\n"
101
+ gitconftxt += "\tremote = origin\n"
102
+ gitconftxt += "\tmerge = refs/heads/master"
103
+ File.write("#{$dir}/.git/config", gitconftxt, mode: 'a')
104
+ # Upload the repo to Github
105
+ jsontxt = "{\"name\": \"#{$repo}\", \"description\": \"#{$desc}\", \"private\": #{$priv}, \"has_issues\": #{$issues}, \"has_downloads\": #{$downloads}, \"has_wiki\": #{$wiki}}"
106
+ cmd = %Q[curl -u #{$user} https://api.github.com/user/repos -d '#{jsontxt}']
107
+ out = %x[ #{cmd} ]
108
+ end
109
+
110
+ def gitupdate
111
+ %x[ cd #{$dir} && git add . && git commit -m '#{$message}' && git push ]
112
+ end
113
+
114
+ def gitpres
115
+ $dir = $repodir + "/" + $repo
116
+ Dir.mkdir($dir)
117
+ presdir = $pres_templ + "/."
118
+ FileUtils.cp_r(presdir, $dir)
119
+ gitdir = $dir + "/.git"
120
+ FileUtils.remove_dir(gitdir)
121
+ end
122
+
123
+ # Catch error for required argument for option(s)
124
+ begin
125
+ opts.each do |opt, arg|
126
+ case opt
127
+ when "--help"
128
+ help
129
+ exit
130
+ when "--version"
131
+ puts "gitmagic version: #{prgmversion.to_s}"
132
+ exit
133
+ when "--clone"
134
+ $repo = arg
135
+ %x[ clone #{$repo} ]
136
+ exit
137
+ when "--desc"
138
+ $desc = arg
139
+ when "--dir"
140
+ $dir = File.expand_path(arg)
141
+ when "--priv"
142
+ $priv = "true"
143
+ when "--init"
144
+ $repo = arg
145
+ $desc = "Project_#{Date.today.to_s}" if $desc == ""
146
+ gitinit
147
+ $message = "Initialized"
148
+ gitupdate
149
+ puts "Git repo initiated: #{$repo}"
150
+ exit
151
+ when "--update"
152
+ $message = arg
153
+ gitupdate
154
+ puts "Git repo updated"
155
+ exit
156
+ when "--slides"
157
+ $repo = arg
158
+ $desc = "Presentation" if $desc == ""
159
+ gitpres
160
+ File.delete("#{$dir}/README.md") if File.exist?("#{$dir}/README.md")
161
+ gitinit
162
+ $message = "Initialized"
163
+ gitupdate
164
+ puts "Presentation created: #{$repo}"
165
+ exit
166
+ end
167
+ end
168
+ rescue
169
+ puts "ERROR"
170
+ end
171
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitmagical
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geir Isene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'Initiate projects from your local folders. Update projects easily. Create
14
+ new online presentations using Jekyll w/Gitpages. And more. See the Github page
15
+ for full info: https://github.com/isene/gitmagic'
16
+ email: g@isene.com
17
+ executables:
18
+ - gitmagic
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/gitmagic
23
+ homepage: https://isene.com/
24
+ licenses:
25
+ - Unlicense
26
+ metadata:
27
+ source_code_uri: https://github.com/isene/gitmagic
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.1.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A swiss army knife of git tools
47
+ test_files: []