41 lines
1.3 KiB
Bash
Executable File
41 lines
1.3 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 | 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}")
|
|
|
|
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.
|
|
# |