Files
repo-tools/repo
2024-05-17 20:10:55 +10:00

42 lines
1.5 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.
#
# GOTCHA: (also, setup instructions)
#
# Bash scripts can't change the working directory of their callers. This is
# right and proper, but we need to work around it in this case.
#
# To use this script, create a function in your .bashrc or .zshrc:
#
# repo() { cd $(/path/to/this/script $@) }
#
REPO_BASE=${HOME}/src
repos=$(find -s "${REPO_BASE}" -maxdepth 3 -mindepth 3 -type d -not -path "${REPO_BASE}/repo-tools/*" | sed "s|${REPO_BASE}/||")
# 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 "$REPO_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.
#