git-profile 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 11ffd78d70d830f59710dd4db59f29b8a73d6ce1362d0412eeacde9be6e259fc
4
+ data.tar.gz: 6ecca9a01de1d7132a1d375b42a28fb34219d54fea67440ac83545d0ec0d00a0
5
+ SHA512:
6
+ metadata.gz: 29e50ddba13a7e2eabd1d076868bbe935af389e9c8839373be8998c104cc22df597c5711851604f2360d991904e188b2f6621e112128cfe88d1b84dd4dbb190f
7
+ data.tar.gz: 591126e0dd827687d5515883708c076c0cecdba92b372d82204e66bbebc8a18d7af1ee8a338d5062100abb2d9a61d52591b306becd25b3fef6323f74bd432f23
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in git-profile.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 jithindasad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # git-profile
2
+ **Warning 🚧** The tool was developed for authors personal use, No extensive testing has been done.
3
+ Make sure you make a backup of your `gitconfig` before doing anything.
4
+
5
+ `$ cp ~/.gitconfig ~/.gitconfig.example`
6
+
7
+ **git-profile** is a CLI tool which allows you to switch between multiple git profiles interactively.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'git-profile'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install git-profile
24
+
25
+ ## Usage
26
+
27
+ `$ git-profile <command>`
28
+
29
+ Commands:
30
+ ```
31
+ git-profile add # Adds a new git profile
32
+ git-profile delete [username] # Remove a specific git profile
33
+ git-profile help [COMMAND] # Describe available commands or one specific command
34
+ git-profile list # List all available git profiles.
35
+ git-profile reset # Deletes all data and reset.
36
+ git-profile use [username] # Set the global git profile.
37
+ git-profile whoami # Show the global git profile
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jithindasad/git-profile.
49
+
50
+
51
+ ## License
52
+
53
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git/profile"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/git-profile ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "git/profile"
@@ -0,0 +1,34 @@
1
+ require_relative 'lib/git/profile/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "git-profile"
5
+ spec.version = Git::Profile::VERSION
6
+ spec.authors = ["jithindasad"]
7
+ spec.email = ["jithindasad@gmail.com"]
8
+
9
+ spec.description = "git-profile is a CLI tool which allows you to switch between multiple git profiles interactively."
10
+ spec.summary = spec.description
11
+ spec.homepage = "https://github.com/jithindasad/git-profile"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+ spec.add_dependency "thor", "~> 1.1"
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ spec.metadata["changelog_uri"] = "https://github.com/jithindasad/git-profile/blob/main/CHANGELOG.md"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+ end
@@ -0,0 +1,154 @@
1
+ require "git/profile/version"
2
+ require 'thor'
3
+ require 'yaml'
4
+
5
+ module Utilities
6
+
7
+ def user_exists?(email)
8
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
9
+ users = YAML.load(File.read(profiles))
10
+
11
+ emails = users[:users].filter do |user|
12
+ user[:email] == email
13
+ end
14
+
15
+ emails.empty? ? false : true
16
+ end
17
+
18
+ def fetch_user_data
19
+ username = ask("enter your username:")
20
+ email = ask("enter your email:")
21
+
22
+ unless email =~ /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
23
+ say("Invalid email address, Try Again! \n")
24
+ self.fetch_user_data
25
+ end
26
+
27
+ return [username, email]
28
+ end
29
+
30
+ def save(username, email)
31
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
32
+ if File.zero?(profiles)
33
+ users = {users: [{username: "#{username}", email: "#{email}"}]}
34
+ File.open(profiles, "w") { |file| file.write(users.to_yaml) }
35
+ else
36
+ if user_exists?(email)
37
+ say("User already exists!")
38
+ exit
39
+ end
40
+ users = YAML.load(File.read(profiles))
41
+ user = {username: "#{username}", email: "#{email}"}
42
+ users[:users].push(user)
43
+ File.open(profiles, "w") { |file| file.write(users.to_yaml) }
44
+ end
45
+ say("User #{username} <#{email}> has been added!")
46
+ end
47
+
48
+ end
49
+
50
+ module Profile
51
+ class CLI < Thor
52
+ include Thor::Actions
53
+ include Utilities
54
+
55
+ def self.exit_on_failure?
56
+ true
57
+ end
58
+
59
+ desc "add", "Adds a new git profile"
60
+ def add
61
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
62
+ profile_directory = File.join(Dir.home, ".git-profile")
63
+ username, email = fetch_user_data
64
+
65
+ if File.exist?(profiles)
66
+ save(username, email)
67
+ else
68
+ Dir.mkdir(profile_directory) unless Dir.exist?(profile_directory)
69
+ create_file "#{File.join(Dir.home, ".git-profile/profiles.yml")}"
70
+ username, email = fetch_user_data
71
+ save(username, email)
72
+ end
73
+ end
74
+
75
+ desc "list", "List all available git profiles."
76
+ def list
77
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
78
+ if File.exist?(profiles) && !File.zero?(profiles)
79
+ users = YAML.load(File.read(profiles))
80
+ users[:users].each_with_index { |user, index| say("#{index + 1}. #{user[:username]} <#{user[:email]}>") }
81
+ else
82
+ say("No git profiles found. You can add a git profile with `$git-profile add` command .")
83
+ end
84
+ end
85
+
86
+ desc "use [username]", "Set the global git profile."
87
+ def use(username)
88
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
89
+ config_path = File.join(Dir.home, ".gitconfig")
90
+ if File.exist?(profiles) && !File.zero?(profiles)
91
+ users = YAML.load(File.read(profiles))
92
+ user = users[:users].filter { |user| user[:username] == username }
93
+ unless user.empty?
94
+ File.open(config_path, 'w') {|file| file.truncate(0) } if File.exist?(config_path)
95
+ run("git config --global user.name #{user.first[:username]}")
96
+ run("git config --global user.email #{user.first[:email]}")
97
+ say("git credentials has been updated.")
98
+ else
99
+ say("No git profiles with username #{username} was found. See all available profiles with `$git-profile list` command .")
100
+ end
101
+ else
102
+ say("No git profiles with username #{username} was found. See all available profiles with `$git-profile list` command .")
103
+ end
104
+ end
105
+
106
+ desc "delete [username]", "Remove a specific git profile"
107
+ def delete(username)
108
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
109
+
110
+ if File.exist?(profiles) && !File.zero?(profiles)
111
+ users = YAML.load(File.read(profiles))
112
+ user = users[:users].filter { |user| user[:username] == username }
113
+
114
+ unless user.empty?
115
+ users[:users].delete(user.first)
116
+ say("User #{user.first[:username]} <#{user.first[:email].to_s}> has been deleted!")
117
+ if users[:users].empty?
118
+ File.open(profiles, 'w') {|file| file.truncate(0) }
119
+ else
120
+ File.open(profiles, "w") { |file| file.write(users.to_yaml) }
121
+ end
122
+ else
123
+ say("No git profiles with username #{username} was found. You can see all available profiles with `$git-profile list` command .")
124
+ end
125
+ else
126
+ say("No git profiles found. You can add a git profile with `$git-profile add` command .")
127
+ end
128
+ end
129
+
130
+ desc "reset", "Deletes all data and reset."
131
+ def reset
132
+ profiles = File.join(Dir.home, "/.git-profile/profiles.yml")
133
+ config_path = File.join(Dir.home, ".gitconfig")
134
+ File.open(profiles, 'w') {|file| file.truncate(0) } if File.exist?(profiles) && !File.zero?(profiles)
135
+ File.open(config_path, 'w') {|file| file.truncate(0) } if File.exist?(config_path)
136
+ say("reset successfull!")
137
+ end
138
+
139
+ desc "whoami", "Show the global git profile"
140
+ def whoami
141
+ config_path = File.join(Dir.home, ".gitconfig")
142
+ if File.exist?(config_path) && !File.zero?(config_path)
143
+ print("username: ")
144
+ username = run("git config user.name", config = {:verbose => false})
145
+ print("email: ")
146
+ email = run("git config user.email", config = {:verbose => false})
147
+ else
148
+ say("No git profiles found. You can add a git profile with `$git-profile use` command .")
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ Profile::CLI.start(ARGV)
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Profile
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-profile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jithindasad
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ description: git-profile is a CLI tool which allows you to switch between multiple
28
+ git profiles interactively.
29
+ email:
30
+ - jithindasad@gmail.com
31
+ executables:
32
+ - git-profile
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - exe/git-profile
45
+ - git-profile.gemspec
46
+ - lib/git/profile.rb
47
+ - lib/git/profile/version.rb
48
+ homepage: https://github.com/jithindasad/git-profile
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ allowed_push_host: https://rubygems.org
53
+ homepage_uri: https://github.com/jithindasad/git-profile
54
+ source_code_uri: https://github.com/jithindasad/git-profile
55
+ changelog_uri: https://github.com/jithindasad/git-profile/blob/main/CHANGELOG.md
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.3.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.1.4
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: git-profile is a CLI tool which allows you to switch between multiple git
75
+ profiles interactively.
76
+ test_files: []