This commit is contained in:
2025-11-04 23:28:37 +01:00
parent c5a060bf29
commit 990e0f93c2
5 changed files with 131 additions and 32 deletions

View File

@@ -1,23 +1,20 @@
#!/bin/bash
token="$1"
page=1
project_dir="$HOME/projects"
base_url="https://gitea.finnvanreenen.nl/api/v1"
function process_repo() {
json="$1"
local json="$1"
local remote_name="$2"
checkout="$project_dir"
local checkout="$project_dir"
if [[ "$(echo "$json" | jq -r '.name')" == 'dotfiles' ]]; then
return # do not clone dotfiles
fi
full_name="$(echo "$json" | jq -r '.full_name')"
clone_url="$(echo "$json" | jq -r '.clone_url')"
ssh_url="$(echo "$json" | jq -r '.ssh_url')"
local full_name="$(echo "$json" | jq -r '.full_name')"
local clone_url="$(echo "$json" | jq -r '.clone_url')"
local ssh_url="$(echo "$json" | jq -r '.ssh_url')"
echo "$full_name"
@@ -32,32 +29,50 @@ function process_repo() {
if [ -d "$checkout/$full_name" ]
then
echo " already exists"
if [[ "$(git -C "$checkout/$full_name" remote | grep "^$remote_name\$")" == "" ]]
then
git -C "$checkout/$full_name" remote add "$remote_name" "$ssh_url"
else
git -C "$checkout/$full_name" remote set-url "$remote_name" "$ssh_url"
fi
else
echo " clone to $checkout/$full_name"
url="$(echo "$clone_url" | sed "s|://|://$token@|")"
git clone "$clone_url" "$project_dir/$full_name"
git -C "$project_dir/$full_name" remote set-url origin "$ssh_url"
git clone "$url" "$checkout/$full_name"
git -C "$checkout/$full_name" remote set-url origin "$ssh_url"
git -C "$checkout/$full_name" remote add "$remote_name" "$ssh_url"
fi
}
while [[ $page -lt 50 ]]
do
# echo
echo "get repo list page $page"
repos="$(curl -X 'GET' "$base_url/user/repos?page=$page&token=$token" \
-H 'accept: application/json')"
function fetch_repos() {
local base_url="$1"
local remote_name="$2"
local token="$3"
if [[ "$repos" != "[]" ]]
then
for repo in $(echo "$repos" | jq -c '.[]' | sed -e 's/ /%20;/g')
do
repo="$( echo "$repo" | sed -e 's/%20;/ /g' )"
process_repo "$repo"
done
else
echo "No more repositories found."
page=999
fi
local page=1
page="$(( $page + 1 ))"
done
while [[ $page -lt 50 ]]
do
# echo
echo "get repo list page $page"
repos="$(curl -X 'GET' "$base_url/user/repos?page=$page&token=$token" \
-H 'accept: application/json')"
if [[ "$repos" != "[]" ]]
then
for repo in $(echo "$repos" | jq -c '.[]' | sed -e 's/ /%20;/g')
do
repo="$( echo "$repo" | sed -e 's/%20;/ /g' )"
process_repo "$repo"
done
else
echo "No more repositories found."
page=999
fi
page="$(( $page + 1 ))"
done
}
fetch_repos https://gitea.finnvanreenen.nl/api/v1 tea "$(pass show gitea.finnvanreenen.nl/autoclone)"
fetch_repos https://git.gay/api/v1 gay "$(pass show git.gay/autoclone)"

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
app="$(flatpak list --app --columns=name,application | sed -e 's/\t/ (/' -e 's/$/)/' | fzf)"
flatpak run "$(echo "$app" | sed -e 's/^.*(\(.*\))$/\1/')"

View File

@@ -0,0 +1,78 @@
#!/bin/bash
function update_remote() {
local repo="$1"
for remote in $(git -C "$repo" remote 2>/dev/null)
do
local new_url="$(git -C "$repo" remote get-url "$remote" | sed -e 's|^https://FReenen:[0-9a-f]*@gitea.finnvanreenen.nl/|git@gitea.finnvanreenen.nl:|')"
git -C "$repo" remote set-url "$remote" "$new_url"
done
return 1
}
for repo in $(find $HOME/projects/ -type d -name '.git' | sed -e 's/ /%20;/g')
do
repo="$( echo "$repo" | sed -e 's/%20;/ /g' -e 's|/\.git$||' )"
git -C "$repo" fetch --all 1>/dev/null \
|| update_remote "$repo" \
|| { echo "failt to fetch $repo" ; echo ; }
changes=""
staged=""
unsgated=""
git diff --cached --exit-code &>/dev/null || staged="staged"
git diff --exit-code &>/dev/null || unsgated="unsgated"
if [[ ! -z "$staged" && ! -z "$unstaged" ]]
then
changes="staged and unstaged changes"
elif [[ ! -z "$unstaged" ]]
then
changes="unstaged changes"
elif [[ ! -z "$staged" ]]
then
changes="staged changes"
fi
remote=""
b=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$b" != "" ]
then
behind=$(git rev-list HEAD...@{u} --ignore-submodules --count 2>/dev/null)
ahead=$(git rev-list @{u}...HEAD --ignore-submodules --count 2>/dev/null)
if [[ "$behind" > 0 && "$ahead" > 0 ]]
then
remote="merge with remote"
elif [[ "$behind" > 0 ]]
then
remote="push to remote"
elif [[ "$ahead" > 0 ]]
then
remote="pull from remote"
fi
fi
if [[ ! -z "$changes" || ! -z "$remote" ]]
then
echo "# $repo"
echo
if [[ ! -z "$changes" && ! -z "$remote" ]]
then
echo "has $changes and has to $remote"
elif [[ ! -z "$changes" ]]
then
echo "has $changes"
elif [[ ! -z "$remote" ]]
then
echo "has to $remote"
fi
echo
fi
done

View File

@@ -1,2 +1,3 @@
[Context]
filesystems=/home/freenen/.local/share/vdhcoapp:ro;~/projects:ro;~/.local/tiCloudAgent;~/.local/share/vdhcoapp;
sockets=gpg-agent
filesystems=~/.local/share/vdhcoapp:ro;~/projects:ro;~/.local/tiCloudAgent;~/.local/share/browserpass;~/.password-store/;~/.gnupg