From 0258dd59b1bbe2814f0fc057528679bb5808c918 Mon Sep 17 00:00:00 2001 From: demenik Date: Tue, 2 Dec 2025 17:49:43 +0100 Subject: [PATCH] feat: Add git-changes script --- home/editors/nvim/plugins/lsp/servers.nix | 8 ++ home/shells/zsh/default.nix | 2 +- home/shells/zsh/scripts.nix | 33 -------- home/shells/zsh/scripts/default.nix | 47 +++++++++++ home/shells/zsh/scripts/git-changes.sh | 97 +++++++++++++++++++++++ 5 files changed, 153 insertions(+), 34 deletions(-) delete mode 100644 home/shells/zsh/scripts.nix create mode 100644 home/shells/zsh/scripts/default.nix create mode 100644 home/shells/zsh/scripts/git-changes.sh diff --git a/home/editors/nvim/plugins/lsp/servers.nix b/home/editors/nvim/plugins/lsp/servers.nix index 0d40b8e..26f752d 100644 --- a/home/editors/nvim/plugins/lsp/servers.nix +++ b/home/editors/nvim/plugins/lsp/servers.nix @@ -111,6 +111,14 @@ rust_analyzer = { enable = true; packageFallback = true; + config.rust-analyzer = { + procMacro.enable = true; + check = { + command = "clippy"; + allTargets = false; + }; + cargo.allFeatures = true; + }; }; clangd.enable = true; cmake.enable = true; diff --git a/home/shells/zsh/default.nix b/home/shells/zsh/default.nix index e702d2a..3b9c35c 100644 --- a/home/shells/zsh/default.nix +++ b/home/shells/zsh/default.nix @@ -6,7 +6,7 @@ imports = [ ./prompt.nix ./aliases.nix - ./scripts.nix + ./scripts ]; home.sessionVariables."SHELL" = "${lib.getExe pkgs.zsh}"; diff --git a/home/shells/zsh/scripts.nix b/home/shells/zsh/scripts.nix deleted file mode 100644 index 7998889..0000000 --- a/home/shells/zsh/scripts.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ - pkgs, - dotsDir, - ... -}: { - home.packages = with pkgs; [ - (writeScriptBin "rebuild" '' - cd ${dotsDir} - git add -A 2>/dev/null - sudo nixos-rebuild $@ switch --flake . - cd - >/dev/null - '') - - (writeScriptBin "update" '' - cd ${dotsDir} - git add -A 2>/dev/null - sudo nix flake $@ update - cd - >/dev/null - '') - - (writeScriptBin "nix" '' - NIX=${pkgs.lib.getExe pkgs.nix} - - if [[ $1 == "develop" || $1 == "shell" ]]; then - cmd=$1 - shift - exec "$NIX" "$cmd" -c "$SHELL" "$@" - else - exec "$NIX" "$@" - fi - '') - ]; -} diff --git a/home/shells/zsh/scripts/default.nix b/home/shells/zsh/scripts/default.nix new file mode 100644 index 0000000..898344e --- /dev/null +++ b/home/shells/zsh/scripts/default.nix @@ -0,0 +1,47 @@ +{ + pkgs, + dotsDir, + ... +}: { + home.packages = with pkgs; [ + ( + writeScriptBin "rebuild" + # sh + '' + cd ${dotsDir} + git add -A 2>/dev/null + sudo nixos-rebuild $@ switch --flake . + cd - >/dev/null + '' + ) + + ( + writeScriptBin "update" + # sh + '' + cd ${dotsDir} + git add -A 2>/dev/null + sudo nix flake $@ update + cd - >/dev/null + '' + ) + + ( + writeScriptBin "nix" + # sh + '' + NIX=${pkgs.lib.getExe pkgs.nix} + + if [[ $1 == "develop" || $1 == "shell" ]]; then + cmd=$1 + shift + exec "$NIX" "$cmd" -c "$SHELL" "$@" + else + exec "$NIX" "$@" + fi + '' + ) + + (writeScriptBin "git-changes" (builtins.readFile ./git-changes.sh)) + ]; +} diff --git a/home/shells/zsh/scripts/git-changes.sh b/home/shells/zsh/scripts/git-changes.sh new file mode 100644 index 0000000..0e120f5 --- /dev/null +++ b/home/shells/zsh/scripts/git-changes.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +if [ -n "$1" ]; then + BASE_BRANCH="$1" +else + if git show-ref --verify --quiet refs/heads/dev; then + BASE_BRANCH="dev" + elif git show-ref --verify --quiet refs/heads/main; then + BASE_BRANCH="main" + elif git show-ref --verify --quiet refs/heads/master; then + BASE_BRANCH="master" + else + echo "Warning: Neither 'dev', 'main' nor 'master' found. Defaulting to 'main'." >&2 + BASE_BRANCH="main" + fi +fi + +TARGET_BRANCH=${2:-$(git rev-parse --abbrev-ref HEAD)} + +if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + echo "Error: Not a git repository." >&2 + exit 1 +fi + +if ! git show-ref --verify --quiet refs/heads/"$BASE_BRANCH"; then + echo "Error: Base branch '$BASE_BRANCH' does not exist." >&2 +fi + +REMOTE_URL=$(git config --get remote.origin.url) +REPO_URL="" + +if [[ "$REMOTE_URL" == *"github.com"* || $REMOTE_URL == *"gitlab.com"* || $REMOTE_URL == *"gitlab.uni-ulm.de"* ]]; then + REPO_URL=$(echo "$REMOTE_URL" | sed -E 's/git@([^:]+):/https:\/\/\1\//') + REPO_URL=${REPO_URL%.git} +fi + +get_commit_link() { + local hash=$1 + if [ -n "$REPO_URL" ]; then + echo "($REPO_URL/commit/$hash)" + else + echo "($hash)" + fi +} + +feats="" +fixes="" +docs="" +refactors="" +tests="" +others="" + +echo "Generating changelog for '$TARGET_BRANCH' (comparing against '$BASE_BRANCH')..." +echo "-------------------------------------------------------------------------------" + +while IFS="|" read -r hash subject; do + link=$(get_commit_link "$hash") + + if [[ "$subject" =~ ^([a-z]+)(\([a-z0-9\ -]+\))?!?:[[:space:]]*(.*)$ ]]; then + type="${BASH_REMATCH[1]}" + clean_msg="${BASH_REMATCH[3]}" + + line=" - [\`${hash:0:7}\`]${link}: ${clean_msg}" + + case "$type" in + feat) feats="${feats}\n${line}" ;; + fix) fixes="${fixes}\n${line}" ;; + docs) docs="${docs}\n${line}" ;; + refactor) refactors="${refactors}\n${line}" ;; + test) tests="${tests}\n${line}" ;; + *) others="${others}\n${line} (Type: $type)" ;; + esac + else + line=" - [\`${hash:0:7}\`]${link}: ${subject}" + others="${others}\n${line}" + fi + +done < <(git log --no-merges --pretty=format:"%H|%s" "$BASE_BRANCH..$TARGET_BRANCH") + +if [ -n "$feats" ]; then + echo -e "\n- **New Features:**$feats" +fi +if [ -n "$fixes" ]; then + echo -e "\n- **Bug Fixes:**$fixes" +fi +if [ -n "$docs" ]; then + echo -e "\n- **Documentation:**$docs" +fi +if [ -n "$refactors" ]; then + echo -e "\n- **Refactoring:**$refactors" +fi +if [ -n "$tests" ]; then + echo -e "\n- **Tests:**$tests" +fi +if [ -n "$others" ]; then + echo -e "\n- **Other Changes:**$others" +fi +echo -e "\n> Automatically generated by [git-changes](https://github.com/demenik/dots/tree/main/home/shells/zsh/scripts/git-changes.sh)"