Created
February 17, 2024 14:37
-
-
Save xorvo/7878669c086c65b4decc03469510a476 to your computer and use it in GitHub Desktop.
Clone git repositories to dedicated path
This file contains hidden or 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 ruby | |
# For pulling git repo into a destination directory based on global path of the repo | |
# example: [email protected]:rabbitmq/rabbitmq-server.git => ~/projects/github.com/rabbitmq/rabbitmq-server | |
require 'fileutils' | |
PROJECTS_DIR="#{Dir.home}/projects" | |
url = ARGV[0] | |
regex = /git@(?<host>[\w-]+\.\w+):(?<user>[\w-]+)\/(?<repo>[\w\.-]+)\.git/ | |
matchdata = regex.match(url) | |
raise "Invalid input #{url}" unless matchdata | |
parent_dir = File.join(PROJECTS_DIR, matchdata['host'], matchdata['user']) | |
dir = File.join(parent_dir, matchdata['repo']) | |
FileUtils.mkdir_p(parent_dir) | |
system("git clone #{url} #{dir} && cd #{dir}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment