- Do a better job at finding repos - Use common config - Refer to init.bash in comments
44 lines
1.6 KiB
Bash
Executable File
44 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
## repo: cd to a code repo, with some fancy fuzzy findingness
|
|
#
|
|
# I don't want to have to type `github.com` and an org name every time I need to
|
|
# cd to a new repo. Unfortunately, my new repo structure will make this
|
|
# necessary a lot of the time, unless I solve for it.
|
|
#
|
|
# So yeah. Here's this thing.
|
|
#
|
|
# NOT WORKING?
|
|
#
|
|
# Since shell scripts can't change the working directories of their callers (as
|
|
# is right and proper), this script can only do its job if it's called by a
|
|
# function, e.g.:
|
|
#
|
|
# repo() { cd $(/path/to/this/script $@) }
|
|
#
|
|
# If you add 'source /path/to/this/repo/init.bash' to your shell rc file (e.g.
|
|
# ~/.zshrc), this (and perhaps some other goodies) will be set up for you.
|
|
#
|
|
|
|
source $(dirname ${BASH_SOURCE[0]})/config.bash
|
|
|
|
repos=$(find "${REPOSITORY_BASE}" -name '.git' | sed "s|${REPO_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 "github.com/buildkite/${1}" --prompt="Repo: ")"
|
|
|
|
echo "$REPOSITORY_BASE/$selected"
|
|
|
|
# TODO: It could be super nice to bias in favour of more frequently selected options.
|
|
# For the last 500 uses (or so):
|
|
# SELECT result, count(1)
|
|
# FROM (SELECT * FROM invocations ORDER BY time DESC LIMIT 500) inv
|
|
# WHERE term LIKE '${TERM}%'
|
|
# GROUP BY result
|
|
# ORDER BY count(1) desc
|
|
#
|
|
# BUT:
|
|
# If there are exact matches on repo name, they should always be at the top.
|
|
# |