Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
個人で使ってるツールの一括アップデート
#!/usr/bin/env zsh
function update_it() {
local tool_path="$1"
local target="$2"
pushd "$tool_path" &> /dev/null
[ ! -e .git ] && echo " x [Warning] $target is not git repository" && popd &> /dev/null && return 0;
if result="$(git pull origin master --rebase)"; then
echo "$result"
if [[ "$result" == "Already up-to-date." ]]; then
echo " + $target had already been updated"
else
echo " + $target was successfully updated"
fi
else
echo " x [Error] $target was unsuccessfully updated"
fi
popd &> /dev/null
}
function update_tool() {
local tool="$1"
update_it "$HOME/.$tool" "$tool"
}
function update_plugins_of_it() {
if [ "$2" = "false" ]; then
return 1
fi
local tool="$1"
for plugin in "$HOME"/."$tool"/plugins/*; do
update_it "$plugin" "$(basename "$plugin")"
done
}
function update_all() {
local -A TOOLS
TOOLS=(
rbenv true
pyenv false
nodenv true
zplug false
)
for tool in ${(k)TOOLS}; do
update_tool "$tool"
update_plugins_of_it $tool "$TOOLS[$tool]"
done
}
function main() {
update_all
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment