Compare commits
8 Commits
69ab075c80
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 758d01ff1e | |||
| 8c8f123f5f | |||
| 74693a6b3a | |||
| 854c282983 | |||
| f79230e1f9 | |||
| 18c9545eca | |||
| 94215b6cb7 | |||
| f939bf25b9 |
@ -2,9 +2,9 @@
|
||||
#
|
||||
# For shell config (e.g., to be sourced into .zshrc) see init.bash
|
||||
|
||||
REPOSITORY_BASE=~/src
|
||||
export REPOSITORY_BASE=~/src
|
||||
|
||||
# If a variable is only to be used by a single script, by custom it will be
|
||||
# prefixed with the name of the script.
|
||||
|
||||
REPO_DEFAULT_SEARCH_PREFIX="github.com/buildkite/"
|
||||
export REPO_DEFAULT_SEARCH_PREFIX="github.com/buildkite/"
|
||||
|
||||
18
fcl
18
fcl
@ -15,8 +15,11 @@
|
||||
# [ ] Make a way to turn off the pretty, in case it's getting in the way
|
||||
#
|
||||
|
||||
DEFAULT_ORG = "buildkite"
|
||||
REPO_BASE = "#{ENV['HOME']}/src"
|
||||
|
||||
ConfigPath = File.join(File.expand_path(File.dirname(__FILE__)), 'config.bash')
|
||||
ConfigValues = `env -i bash --noprofile --norc -c 'source #{ConfigPath}; env'`.lines.map(&:chomp)
|
||||
ConfigPairs = ConfigValues.map {|v| v.split('=',2) }.to_h
|
||||
Config = ConfigPairs.reject {|k,v| ['_','SHLVL','PWD'].include?(k) }
|
||||
|
||||
def clone(repo_url, destination)
|
||||
spinner_command = %Q[gum spin --show-output --spinner dot]
|
||||
@ -39,6 +42,9 @@ def repo_url(repo_str)
|
||||
# GitHub HTTPS. We like these, use it as-is.
|
||||
when /^(git|https)\:\/\/github\.com\//
|
||||
repo_str
|
||||
# Some other HTTPS. This is probably fine too, as long as it ends with '.git'
|
||||
when /^(git|https)\:\/\/.+\.git$/
|
||||
repo_str
|
||||
# GitHub SSH. Let's convert this to HTTPS.
|
||||
when /^git@github\.com\:.+\.git$/
|
||||
repo_str.sub(/^git@github\.com:/, 'https://github.com/')
|
||||
@ -48,9 +54,9 @@ def repo_url(repo_str)
|
||||
# Just a user/org name and repo name. Assume it's on GitHub and make an HTTPS URL.
|
||||
when /^[\w\-_]+\/[\w\-_\.]+$/
|
||||
"https://github.com/#{repo_str}.git"
|
||||
# Just a repo name. Assume it's a DEFAULT_ORG repo on GitHub and make an HTTPS URL.
|
||||
# Just a repo name. Assume it's a FCL_DEFAULT_ORG repo on GitHub and make an HTTPS URL.
|
||||
when /^[\w\-_\.]+$/
|
||||
"https://github.com/#{DEFAULT_ORG}/#{repo_str}.git"
|
||||
"https://github.com/#{Config['FCL_DEFAULT_ORG']}/#{repo_str}.git"
|
||||
else
|
||||
raise "I can't make a repo URL out of '#{repo_str}'."
|
||||
end
|
||||
@ -60,7 +66,7 @@ def destination_path(repo_str)
|
||||
repo_elms = repo_str.split('/')
|
||||
|
||||
repo = repo_elms.pop.sub(/\.git$/, '')
|
||||
org = repo_elms.pop || DEFAULT_ORG
|
||||
org = repo_elms.pop || Config.fetch('FCL_DEFAULT_ORG')
|
||||
forge = repo_elms.pop || 'github.com'
|
||||
|
||||
File.join(forge, org, repo)
|
||||
@ -69,7 +75,7 @@ end
|
||||
repo_str = ARGV.empty? ? `gum input --header="Enter a repo name" --placeholder=""`.chomp : ARGV[0]
|
||||
|
||||
destination = ARGV[1] || destination_path(repo_str)
|
||||
full_dest = File.join(REPO_BASE, destination)
|
||||
full_dest = File.join(Config['REPOSITORY_BASE'], destination)
|
||||
|
||||
clone_url = repo_url(repo_str)
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#
|
||||
cat <<-EOS
|
||||
repo () {
|
||||
cd \$($(dirname $(realpath ${BASH_SOURCE[0]}))/repo \$@)
|
||||
r=\$($(dirname $(realpath ${BASH_SOURCE[0]}))/repo \$@)
|
||||
[[ "\$r" != "." ]] && [[ "\$r" != "\$(pwd)/" ]] && cd \$r
|
||||
}
|
||||
EOS
|
||||
|
||||
9
repo
9
repo
@ -22,14 +22,19 @@
|
||||
|
||||
source $(dirname ${BASH_SOURCE[0]})/config.bash
|
||||
|
||||
repos=$(find "${REPOSITORY_BASE}" -name '.git' | sed "s|${REPO_BASE}/||" | sed 's|.git$||' | sort)
|
||||
repos=$(find "${REPOSITORY_BASE}" -maxdepth 5 -name '.git' | sed "s|${REPOSITORY_BASE}/||" | sed 's|.git$||' | sort)
|
||||
|
||||
# Default to searching within github.com, because that's by far the most common
|
||||
# place for repos to be.
|
||||
# selected=$(echo "${repos}" | gum filter --header="Pick a repo" --prompt="Repo: " --height=20 --value "github.com/${1}")
|
||||
selected="$(echo "${repos}" | fzf -1 -0 -q "${REPO_DEFAULT_SEARCH_PREFIX}${1}" --prompt="Repo: ")"
|
||||
selected="$(echo "${repos}" | fzf -1 -0 -q "${1:-${REPO_DEFAULT_SEARCH_PREFIX}}" --prompt="Repo: ")"
|
||||
|
||||
# Do nothing if no repo was selected
|
||||
if [ -n "${selected}" ]; then
|
||||
echo "${REPOSITORY_BASE}/${selected}"
|
||||
else
|
||||
echo '.'
|
||||
fi
|
||||
|
||||
# TODO: It could be super nice to bias in favour of more frequently selected options.
|
||||
# For the last 500 uses (or so):
|
||||
|
||||
Reference in New Issue
Block a user