Add scripts to save/reload/update current state
This commit is contained in:
54
bundle/bundles.sh
Executable file
54
bundle/bundles.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/bash
|
||||
usage() {
|
||||
cat << EOT
|
||||
Usage:
|
||||
./${0##*/} list|update|clone|save
|
||||
|
||||
Commands:
|
||||
ls -> List all the bundle repos
|
||||
update -> Update all the bundle repos
|
||||
clone -> Use 'bundles.txt' to repopulate
|
||||
save -> Save repos to 'bundles.txt'
|
||||
EOT
|
||||
exit
|
||||
}
|
||||
|
||||
colors() {
|
||||
sed -E -e 's/\[red\]/[31m/g' \
|
||||
-e 's/\[green\]/[32m/g' \
|
||||
-e 's/\[reset\]/[0m/g' \
|
||||
-e 's/\[b\]/[1m/g' \
|
||||
-e 's/\[ul\]/[4m/g'
|
||||
}
|
||||
|
||||
repos() {
|
||||
# Eval "$1" for all directories
|
||||
local dn
|
||||
for dn in * ; do
|
||||
[[ -d "$dn" ]] || continue
|
||||
eval "${1//@@/$dn}" | colors
|
||||
done
|
||||
}
|
||||
|
||||
clone_bundles() {
|
||||
# Clone the bundles in 'bundles.txt'
|
||||
locals dn repo
|
||||
while read -r dn repo ; do
|
||||
if [[ -d "$dn" ]]; then
|
||||
echo "*** Dir [red][$dn][reset] already exists!" | colors
|
||||
else
|
||||
git clone "$repo" "$dn" 2>&1 | sed "s|^|[green][$dn][reset] |g" | colors
|
||||
fi
|
||||
done < bundles.txt
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
ls) repos 'echo -e "[red]@@[reset] [green]$(git -C @@ remote get-url origin)[reset]"' ;;
|
||||
update) repos 'git -C @@ pull 2>&1 | sed "s|^|[@@] |g"' ;;
|
||||
save) repos 'echo -e "@@ $(git -C @@ remote get-url origin)"' | tee bundles.txt ;;
|
||||
clone) clone_bundles ;;
|
||||
?*) echo "Unknown command: $1" ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
|
||||
# Fin.
|
||||
Reference in New Issue
Block a user