commit outputs can now be colored with a new script color-commit

This commit is contained in:
2024-11-17 13:03:49 -05:00
parent 76be210ec3
commit beedfd1be2
8 changed files with 66 additions and 14 deletions

View File

@@ -28,5 +28,6 @@
moveonscreen = super.callPackage ./scripts/wm-controls/moveonscreen.nix {};
s_check = super.callPackage ./scripts/wm-controls/s_check.nix {};
switchmon = super.callPackage ./scripts/wm-controls/switchmon.nix {};
color-commit = super.callPackage ./scripts/misc/color-commit.nix {};
};
}

View File

@@ -4,6 +4,7 @@ pkgs.writeShellApplication {
runtimeInputs = with pkgs; [
git
gawk
myScripts.color-commit
];
text = ''
set -e
@@ -64,7 +65,7 @@ pkgs.writeShellApplication {
if [ -z "$line" ]; then
if [ -n "$msg" ] && [ ''${#lines[@]} -gt 0 ]; then
git add "''${lines[@]}"
git commit -m "$msg"
git commit -m "$msg" | color-commit
fi
collecting=false
msg=""
@@ -80,7 +81,7 @@ pkgs.writeShellApplication {
# Final cleanup
if [ -n "$msg" ] && [ ''${#lines[@]} -gt 0 ]; then
git add "''${lines[@]}"
git commit -m "$msg"
git commit -m "$msg" | color-commit
fi
)
'';

View File

@@ -0,0 +1,37 @@
{ pkgs }:
pkgs.writeShellApplication {
name = "color-commit";
text = ''
stdin=$(cat)
[ -z "$stdin" ] && echo "Requires input via stdin" && exit 1
teal="\\\033[38;2;180;249;248m"
pink="\\\033[38;2;187;154;247m"
reset="\\\033[0m"
green_bg="\\\033[48;2;16;55;39m"
red_bg="\\\033[48;2;62;21;31m"
blue_bg="\\\033[48;2;33;73;129m"
branch=$(git branch | grep "\*" | cut -d' ' -f2)
output=$(echo "$stdin" | grep -A 1 -E "\[''${branch} ")
[ -z "$output" ] && echo "This doesn't look like commit output: " && echo "$stdin" && exit 1
echo "$output" | while IFS= read -r line; do
[ "$line" = "--" ] && continue
if [[ "$line" =~ ^\[$branch ]]; then
line=$(echo "$line" | sed -E "s/\[([a-zA-Z0-9_-]+) ([a-zA-Z0-9]{7})\] (.*)/$(printf '%s' "$teal")\[\\1 \\2\]$(printf '%s' "$pink") \"\3\"$(printf '%s' "$reset")/")
echo -e "$line"
else
line=$(echo "$line" | sed -E \
-e "s/([0-9]+ file(s)? changed,?)/''${blue_bg}\1''${reset}/g" \
-e "s/([0-9]+ insertion(s)?\(\+\),?)/''${green_bg}\1''${reset}/g" \
-e "s/([0-9]+ deletion(s)?\(-\),?)/''${red_bg}\1''${reset}/g")
echo -e "$line"
echo
fi
done
'';
}