From e4eaab9519b6cc9c653b0d289c40626123093e0e Mon Sep 17 00:00:00 2001 From: Janik von Rotz Date: Thu, 5 Feb 2026 17:31:59 +0100 Subject: [PATCH] feat: wrap scripts in functions for better modularity and reusability --- bin/copy-to-clipboard | 12 +++++++----- bin/pull-all-repos | 40 +++++++++++++++++++++------------------- bin/status-all-repos | 16 +++++++++------- bin/unshallow-git-folder | 12 +++++++----- 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/bin/copy-to-clipboard b/bin/copy-to-clipboard index 974bb0d..eb78c04 100755 --- a/bin/copy-to-clipboard +++ b/bin/copy-to-clipboard @@ -1,7 +1,9 @@ #!/usr/bin/env bash -if [[ "$XDG_SESSION_TYPE" = "wayland" ]]; then - wl-copy -else - xclip -selection clipboard -fi +copy-to-clipboard() { + if [[ "$XDG_SESSION_TYPE" = "wayland" ]]; then + wl-copy + else + xclip -selection clipboard + fi +} diff --git a/bin/pull-all-repos b/bin/pull-all-repos index fc865ea..19a1b4e 100755 --- a/bin/pull-all-repos +++ b/bin/pull-all-repos @@ -1,23 +1,25 @@ #!/usr/bin/env bash -echo "Pull all git repos in $HOME." -repos=() -for repo in $(find "$HOME" -maxdepth 3 -type d -name '.git'); do - repos+=("$(basename "$(dirname "$repo")")") -done -echo "Repos to pull: ${repos[*]}" +pull-all-repos(){ + echo "Pull all git repos in $HOME." + repos=() + for repo in $(find "$HOME" -maxdepth 3 -type d -name '.git'); do + repos+=("$(basename "$(dirname "$repo")")") + done + echo "Repos to pull: ${repos[*]}" -for repo in $(find "$HOME" -maxdepth 2 -type d -name '.git'); do - dir=$(dirname "$repo") - - echo "Pull $(git -C "$dir" branch --show-current) in $dir" - git -C "$dir" pull - - echo "Pull submodules in $dir" - git -C "$dir" submodule update --recursive --remote -done + for repo in $(find "$HOME" -maxdepth 2 -type d -name '.git'); do + dir=$(dirname "$repo") + + echo "Pull $(git -C "$dir" branch --show-current) in $dir" + git -C "$dir" pull + + echo "Pull submodules in $dir" + git -C "$dir" submodule update --recursive --remote + done -echo "Pull selected repos." -~/knowledge/task pull-repos -git -C ~/Ansible-Build/inventories pull -git -C ~/Ansible-Build/inventories/sozialinfo pull \ No newline at end of file + echo "Pull selected repos." + ~/knowledge/task pull-repos + git -C ~/Ansible-Build/inventories pull + git -C ~/Ansible-Build/inventories/sozialinfo pull +} \ No newline at end of file diff --git a/bin/status-all-repos b/bin/status-all-repos index 5d66173..b77428b 100755 --- a/bin/status-all-repos +++ b/bin/status-all-repos @@ -1,9 +1,11 @@ #!/usr/bin/env bash -for repo in $(find "$HOME" -maxdepth 3 -type d -name '.git'); do - dir=$(dirname "$repo") - output=$(git -C "$dir" status) - if grep -qE "(Changes|Untracked|Conflicts)" <<< "$output"; then - echo "Git repo $dir is not up-to-date." - fi -done +status-all-repos(){ + for repo in $(find "$HOME" -maxdepth 3 -type d -name '.git'); do + dir=$(dirname "$repo") + output=$(git -C "$dir" status) + if grep -qE "(Changes|Untracked|Conflicts)" <<< "$output"; then + echo "Git repo $dir is not up-to-date." + fi + done +} \ No newline at end of file diff --git a/bin/unshallow-git-folder b/bin/unshallow-git-folder index eafabc3..eb3c080 100755 --- a/bin/unshallow-git-folder +++ b/bin/unshallow-git-folder @@ -1,9 +1,11 @@ #!/usr/bin/env bash -echo "Fetch with unshallow..." -git fetch --unshallow +unshallow-git-folder(){ + echo "Fetch with unshallow..." + git fetch --unshallow -echo "Fix origin fetch config." -git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" + echo "Fix origin fetch config." + git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" -echo "Now pull and checkout remote branches." \ No newline at end of file + echo "Now pull and checkout remote branches." +} \ No newline at end of file