diff --git a/CHANGELOG.md b/CHANGELOG.md index 6085d54..1c10b26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,16 +20,17 @@ All notable changes to this project will be documented in this file. ### Changed -* Monolith de-layering (Step 11a): four concerns moved verbatim out of +* Monolith de-layering (Step 11a): five concerns moved verbatim out of `terminal/launchers/mqlaunch.sh` into dedicated libraries sourced back into the launcher's scope — the network concern (status/diagnostics/connectivity, 17 functions → `mqlaunch/lib/network.sh`), the fzf interactive pickers (git log/branch, kill process/port, run snippet, recent files, 6 functions → `mqlaunch/lib/fzf-pickers.sh`), diagnostics (version reporting, self-check, debug bundle, release notes, plus the system check, 6 functions → - `mqlaunch/lib/diagnostics.sh`), and the git & release menu launchers - (2 functions → `mqlaunch/lib/git-menus.sh`). No behavior change; the launcher - drops ~600 lines and each concern now has a named owner. Guarded by + `mqlaunch/lib/diagnostics.sh`), the git & release menu launchers + (2 functions → `mqlaunch/lib/git-menus.sh`), and the GitHub repo picker + (1 function → `mqlaunch/lib/repo-picker.sh`). No behavior change; the launcher + drops ~720 lines and each concern now has a named owner. Guarded by `tests/monolith-delayer-smoke.sh`, a table-driven check that fails if any extracted function is redefined in the monolith or a lib source is dropped. * `semantic-memory-maintainer` renamed to `vector-store-maintainer` to avoid diff --git a/docs/AUTHORITY_MAP.md b/docs/AUTHORITY_MAP.md index 8ec9b94..413597a 100644 --- a/docs/AUTHORITY_MAP.md +++ b/docs/AUTHORITY_MAP.md @@ -74,6 +74,7 @@ Reached through other live paths: | `mqlaunch/lib/fzf-pickers.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — fzf interactive pickers de-layered out of the monolith (Step 11a) | | `mqlaunch/lib/diagnostics.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — version/self-check/debug-bundle/release-notes/system-check de-layered out of the monolith (Step 11a) | | `mqlaunch/lib/git-menus.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — git & release menu launchers de-layered out of the monolith (Step 11a) | +| `mqlaunch/lib/repo-picker.sh` | `terminal/launchers/mqlaunch.sh` (sourced) — GitHub repo picker de-layered out of the monolith (Step 11a) | ## Bridges diff --git a/mqlaunch/lib/repo-picker.sh b/mqlaunch/lib/repo-picker.sh new file mode 100755 index 0000000..06dc8be --- /dev/null +++ b/mqlaunch/lib/repo-picker.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env bash +# mqlaunch GitHub repo picker — fzf over `gh repo list`, then an action menu to +# open in the browser, cd into the repo, or clone to ~/repos (optionally opening +# in VS Code or Finder). +# +# Extracted from terminal/launchers/mqlaunch.sh as part of Step 11a (monolith +# de-layering, audit P4). Sourced into the launcher's scope, so it relies on the +# launcher's ambient UI helpers (print_header/row/row_bold/empty_row/ +# print_footer/pause_enter) and on $HOME/$SHELL. Requires gh and fzf at runtime +# (both checked, with an install hint when missing). No behavior change — the +# function body is a verbatim move (the launcher's mislabeled "# Opens repo +# browser." comment is corrected here). Pure bash, covered by shellcheck. + +# Picks a GitHub repo via fzf and runs an open/clone action on it. +run_github_repo_picker() { + local fzf_bin gh_bin selected action clone_dir + + fzf_bin="$(command -v fzf 2>/dev/null || true)" + gh_bin="$(command -v gh 2>/dev/null || true)" + + print_header + + if [[ -z "$gh_bin" ]]; then + row_bold "GITHUB REPO PICKER" + empty_row + row "gh (GitHub CLI) is not installed." + row "Install: brew install gh" + print_footer + pause_enter + return 1 + fi + + if [[ -z "$fzf_bin" ]]; then + row_bold "GITHUB REPO PICKER" + empty_row + row "fzf is not installed." + row "Install: brew install fzf" + print_footer + pause_enter + return 1 + fi + + row_bold "GITHUB REPO PICKER" + empty_row + row "Hämtar dina repos från GitHub..." + print_footer + + selected="$( + "$gh_bin" repo list --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' 2>/dev/null \ + | "$fzf_bin" \ + --reverse \ + --border \ + --header='Välj ett GitHub-repo (ESC = avbryt)' \ + --prompt='repo > ' \ + --height=70% + )" + + [[ -z "$selected" ]] && return 0 + + action="$(printf '%s\n' \ + "Öppna i webbläsaren" \ + "Gå till repo i terminalen" \ + "Klona och hoppa in i terminalen" \ + "Klona till ~/repos" \ + "Klona till ~/repos och öppna i VS Code" \ + "Klona till ~/repos och öppna i Finder" \ + | "$fzf_bin" \ + --reverse \ + --border \ + --header="$selected" \ + --prompt='åtgärd > ' \ + --height=40% + )" + + [[ -z "$action" ]] && return 0 + + clone_dir="$HOME/repos" + mkdir -p "$clone_dir" + local repo_name repo_dir home_repo_dir + repo_name="$(basename "$selected")" + repo_dir="$clone_dir/$repo_name" + home_repo_dir="$HOME/$repo_name" + + case "$action" in + "Öppna i webbläsaren") + "$gh_bin" repo view "$selected" --web + print_footer + pause_enter + ;; + "Gå till repo i terminalen") + if [[ -d "$home_repo_dir" ]]; then + repo_dir="$home_repo_dir" + elif [[ ! -d "$repo_dir" ]]; then + printf "Repo saknas lokalt: %s\nKlona först med 'Klona och hoppa in i terminalen'.\n" "$home_repo_dir" + pause_enter + return 0 + fi + cd "$repo_dir" || return 1 + clear + printf "📁 %s\n" "$repo_dir" + exec "$SHELL" -l + ;; + "Klona och hoppa in i terminalen") + if [[ ! -d "$repo_dir" ]]; then + "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 + fi + cd "$repo_dir" || return 1 + clear + printf "📁 %s\n" "$repo_dir" + exec "$SHELL" -l + ;; + "Klona till ~/repos") + "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 + row "Klonat till $repo_dir" + print_footer + pause_enter + ;; + "Klona till ~/repos och öppna i VS Code") + "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 + code "$repo_dir" 2>/dev/null || open -a "Visual Studio Code" "$repo_dir" 2>/dev/null + print_footer + pause_enter + ;; + "Klona till ~/repos och öppna i Finder") + "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 + open "$repo_dir" + print_footer + pause_enter + ;; + esac +} diff --git a/terminal/launchers/mqlaunch.sh b/terminal/launchers/mqlaunch.sh index c70630ea..7269399 100755 --- a/terminal/launchers/mqlaunch.sh +++ b/terminal/launchers/mqlaunch.sh @@ -379,124 +379,15 @@ show_date_time() { pause_enter } -# Opens repo browser. -run_github_repo_picker() { - local fzf_bin gh_bin selected action clone_dir - - fzf_bin="$(command -v fzf 2>/dev/null || true)" - gh_bin="$(command -v gh 2>/dev/null || true)" - - print_header - - if [[ -z "$gh_bin" ]]; then - row_bold "GITHUB REPO PICKER" - empty_row - row "gh (GitHub CLI) is not installed." - row "Install: brew install gh" - print_footer - pause_enter - return 1 - fi - - if [[ -z "$fzf_bin" ]]; then - row_bold "GITHUB REPO PICKER" - empty_row - row "fzf is not installed." - row "Install: brew install fzf" - print_footer - pause_enter - return 1 - fi - - row_bold "GITHUB REPO PICKER" - empty_row - row "Hämtar dina repos från GitHub..." - print_footer - - selected="$( - "$gh_bin" repo list --limit 1000 --json nameWithOwner --jq '.[].nameWithOwner' 2>/dev/null \ - | "$fzf_bin" \ - --reverse \ - --border \ - --header='Välj ett GitHub-repo (ESC = avbryt)' \ - --prompt='repo > ' \ - --height=70% - )" - - [[ -z "$selected" ]] && return 0 - - action="$(printf '%s\n' \ - "Öppna i webbläsaren" \ - "Gå till repo i terminalen" \ - "Klona och hoppa in i terminalen" \ - "Klona till ~/repos" \ - "Klona till ~/repos och öppna i VS Code" \ - "Klona till ~/repos och öppna i Finder" \ - | "$fzf_bin" \ - --reverse \ - --border \ - --header="$selected" \ - --prompt='åtgärd > ' \ - --height=40% - )" - - [[ -z "$action" ]] && return 0 - - clone_dir="$HOME/repos" - mkdir -p "$clone_dir" - local repo_name repo_dir home_repo_dir - repo_name="$(basename "$selected")" - repo_dir="$clone_dir/$repo_name" - home_repo_dir="$HOME/$repo_name" - - case "$action" in - "Öppna i webbläsaren") - "$gh_bin" repo view "$selected" --web - print_footer - pause_enter - ;; - "Gå till repo i terminalen") - if [[ -d "$home_repo_dir" ]]; then - repo_dir="$home_repo_dir" - elif [[ ! -d "$repo_dir" ]]; then - printf "Repo saknas lokalt: %s\nKlona först med 'Klona och hoppa in i terminalen'.\n" "$home_repo_dir" - pause_enter - return 0 - fi - cd "$repo_dir" || return 1 - clear - printf "📁 %s\n" "$repo_dir" - exec "$SHELL" -l - ;; - "Klona och hoppa in i terminalen") - if [[ ! -d "$repo_dir" ]]; then - "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 - fi - cd "$repo_dir" || return 1 - clear - printf "📁 %s\n" "$repo_dir" - exec "$SHELL" -l - ;; - "Klona till ~/repos") - "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 - row "Klonat till $repo_dir" - print_footer - pause_enter - ;; - "Klona till ~/repos och öppna i VS Code") - "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 - code "$repo_dir" 2>/dev/null || open -a "Visual Studio Code" "$repo_dir" 2>/dev/null - print_footer - pause_enter - ;; - "Klona till ~/repos och öppna i Finder") - "$gh_bin" repo clone "$selected" "$repo_dir" 2>&1 | tail -3 - open "$repo_dir" - print_footer - pause_enter - ;; - esac -} +# GitHub repo picker (fzf over `gh repo list` + open/clone actions) lives in a +# dedicated library (Step 11a monolith de-layering, audit P4). Sourced into this +# scope so it keeps using the ambient UI helpers and $HOME/$SHELL; no behavior +# change — a verbatim move. +if [[ -f "$BASE_DIR/mqlaunch/lib/repo-picker.sh" ]]; then + source "$BASE_DIR/mqlaunch/lib/repo-picker.sh" +else + mq_debug "mqlaunch: repo picker lib missing: mqlaunch/lib/repo-picker.sh" +fi # fzf: bläddra och kopiera sparade AI-prompts från mqobsidian/_prompts/ prompts_pick() { diff --git a/tests/monolith-delayer-smoke.sh b/tests/monolith-delayer-smoke.sh index de55615..962491a 100755 --- a/tests/monolith-delayer-smoke.sh +++ b/tests/monolith-delayer-smoke.sh @@ -18,6 +18,7 @@ CONCERNS=( "mqlaunch/lib/fzf-pickers.sh : fzf_git_log fzf_git_branch fzf_kill_process fzf_kill_port fzf_run_snippet fzf_recent_files" "mqlaunch/lib/diagnostics.sh : get_repo_version show_version_info run_self_check run_debug_bundle show_release_notes system_check" "mqlaunch/lib/git-menus.sh : open_git_menu open_release_menu" + "mqlaunch/lib/repo-picker.sh : run_github_repo_picker" ) total=0