27 lines
1.3 KiB
Bash
Executable File
27 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
cd ~/nixos/dotfiles || exit
|
|
|
|
# Obtenir le hash actuel
|
|
current_hash=$(nix flake metadata --json 2>/dev/null | jq -r '.locks.nodes.nixpkgs.locked.rev')
|
|
|
|
# Obtenir le hash le plus récent
|
|
latest_hash=$(nix flake metadata github:NixOS/nixpkgs/nixos-unstable --json | jq -r '.locked.rev')
|
|
|
|
# Date du commit local
|
|
local_commit_date=$(nix flake metadata --json 2>/dev/null | jq -r '.locks.nodes.nixpkgs.locked.lastModified')
|
|
local_commit_date=$(date -d "@${local_commit_date}" "+%d/%m/%Y à %H:%M")
|
|
|
|
if [ "$current_hash" != "$latest_hash" ]; then
|
|
# Nombre de commits de retard
|
|
maj_count=$(curl -s "https://api.github.com/repos/NixOS/nixpkgs/compare/${current_hash}...${latest_hash}" | jq -r '.ahead_by // 0' 2>/dev/null || echo "?")
|
|
|
|
# Date du commit distant
|
|
remote_commit_date=$(curl -s https://api.github.com/repos/NixOS/nixpkgs/commits/c87b95e25065c028d31a94f06a62927d18763fdf | jq -r '.commit.author.date')
|
|
remote_commit_date=$(date -d "${remote_commit_date}" "+%d/%m/%Y à %H:%M")
|
|
printf '{"text": "%s ", "tooltip": "Commit distant : %s\\nCommit local : %s"}' "${maj_count}" "${remote_commit_date}" "${local_commit_date}"
|
|
# Compter les commits entre les deux
|
|
else
|
|
printf '{"text": "0 ", "tooltip": "Date du dernier commit :\\n%s"}' "${local_commit_date}"
|
|
fi
|