feat(scripts): add git-clone-list
This commit is contained in:
parent
9eac8c8195
commit
b4f50ad63a
2 changed files with 48 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
{ pkgs, nixosConfig, ... }: {
|
{ pkgs, nixosConfig, ... }: {
|
||||||
home.packages = [
|
home.packages = [
|
||||||
|
(import ./git-clone-list.nix { inherit pkgs; })
|
||||||
(import ./nix-update.nix { inherit pkgs nixosConfig; })
|
(import ./nix-update.nix { inherit pkgs nixosConfig; })
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
47
users/gandalf/modules/scripts/git-clone-list.nix
Normal file
47
users/gandalf/modules/scripts/git-clone-list.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
{ pkgs }:
|
||||||
|
|
||||||
|
pkgs.writeShellScriptBin "git-clone-list" ''
|
||||||
|
reset="\e[0m"
|
||||||
|
bold="\e[1m"
|
||||||
|
underline="\e[4m"
|
||||||
|
red="\e[31m"
|
||||||
|
green="\e[32m"
|
||||||
|
|
||||||
|
function help_screen {
|
||||||
|
echo
|
||||||
|
echo -e "''${bold}''${underline}Usage:''${reset} ''${bold}$0''${reset} <USER> <LIST>"
|
||||||
|
echo
|
||||||
|
echo -e "''${bold}''${underline}Arguments''${reset}:"
|
||||||
|
echo -e " ''${bold}USER''${reset} Github username of target user"
|
||||||
|
echo -e " ''${bold}LIST''${reset} List name of target list"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
function error {
|
||||||
|
echo
|
||||||
|
echo -e "''${red}>>> ''${bold}Error''${reset}''${red}: $1''${reset}"
|
||||||
|
if [ "$2" == "help" ]; then
|
||||||
|
help_screen
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -ne 2 ]; then
|
||||||
|
error "Expected 2 arguments, got $#" help
|
||||||
|
fi
|
||||||
|
|
||||||
|
USER=$1
|
||||||
|
LIST=$2
|
||||||
|
|
||||||
|
echo -e "''${green}>>> Fetching list https://github.com/stars/$USER/lists/$LIST ...''${reset}"
|
||||||
|
REPOS=$(${pkgs.xidel}/bin/xidel https://github.com/stars/$USER/lists/$LIST --xpath '//*[@id="user-list-repositories"]//a[not(@class)]/@href')
|
||||||
|
|
||||||
|
NUM_REPOS=$(echo $REPOS | wc -w)
|
||||||
|
IT=1
|
||||||
|
|
||||||
|
for repo in $REPOS; do
|
||||||
|
echo -e "''${green}>>> [$IT/$NUM_REPOS] Cloning: https://github.com$repo.git ...''${reset}"
|
||||||
|
${pkgs.git}/bin/git clone "https://github.com$repo.git" "''${repo:1}"
|
||||||
|
IT=$((IT + 1))
|
||||||
|
done
|
||||||
|
''
|
||||||
Loading…
Add table
Add a link
Reference in a new issue