mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 01:56:39 +00:00
Change how plugins/actions work a bit
This includes both how they detect what the current mode (install/uninstall/cleanup/etc) is, and also forces them to register themselves with Dotify. The registration will be used for running pre/post hooks.
This commit is contained in:
32
src/actions/git.sh
Normal file
32
src/actions/git.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
# Register git action
|
||||
dotify-register-action "git"
|
||||
|
||||
# Git action.
|
||||
dotify-action-git() {
|
||||
local mode="$1"
|
||||
! local valid_mode="$(command -v "dotify-action-git-do-${mode}")"
|
||||
|
||||
if [ -n "$valid_mode" ]; then
|
||||
shift 1
|
||||
dotify-action-git-do-${mode} $@
|
||||
fi
|
||||
}
|
||||
|
||||
dotify-action-git-do-install() {
|
||||
echo "git install: $@"
|
||||
}
|
||||
|
||||
dotify-action-git-do-uninstall() {
|
||||
echo "git uninstall: $@"
|
||||
}
|
||||
|
||||
dotify-action-git-do-cleanup() {
|
||||
echo "git cleanup: $@"
|
||||
}
|
||||
|
||||
dotify-action-git-post-run() {
|
||||
if [ "$1" == "cleanup" ]; then
|
||||
shift 1
|
||||
dotify-action-link-do-cleanup $@
|
||||
fi
|
||||
}
|
||||
32
src/actions/link.sh
Normal file
32
src/actions/link.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
# Register link action.
|
||||
dotify-register-action "link"
|
||||
|
||||
# Link action.
|
||||
dotify-action-link() {
|
||||
local mode="$1"
|
||||
! local valid_mode="$(command -v "dotify-action-link-do-${mode}")"
|
||||
|
||||
if [ -n "$valid_mode" ]; then
|
||||
shift 1
|
||||
dotify-action-link-do-${mode} $@
|
||||
fi
|
||||
}
|
||||
|
||||
dotify-action-link-do-install() {
|
||||
echo "link install: $@"
|
||||
}
|
||||
|
||||
dotify-action-link-do-uninstall() {
|
||||
echo "link uninstall: $@"
|
||||
}
|
||||
|
||||
dotify-action-link-do-cleanup() {
|
||||
echo "link cleanup: $@"
|
||||
}
|
||||
|
||||
dotify-action-link-post-run() {
|
||||
if [ "$1" == "cleanup" ]; then
|
||||
shift 1
|
||||
dotify-action-link-do-cleanup $@
|
||||
fi
|
||||
}
|
||||
@@ -45,7 +45,7 @@ source "../lib/internals/locate-dotfile.sh"
|
||||
source "../lib/internals/locate-target.sh"
|
||||
|
||||
#
|
||||
# Command functions
|
||||
# Main functions
|
||||
#
|
||||
|
||||
source "../lib/dotify-action.sh"
|
||||
@@ -54,15 +54,16 @@ source "../lib/dotify-compile.sh"
|
||||
source "../lib/dotify-help.sh"
|
||||
source "../lib/dotify-info.sh"
|
||||
source "../lib/dotify-install.sh"
|
||||
source "../lib/dotify-register-action.sh"
|
||||
source "../lib/dotify-uninstall.sh"
|
||||
source "../lib/dotify-version.sh"
|
||||
|
||||
#
|
||||
# Built-in Plugins
|
||||
# Built-in action plugins
|
||||
#
|
||||
|
||||
source "../plugins/link.sh"
|
||||
source "../plugins/git.sh"
|
||||
source "../actions/link.sh"
|
||||
source "../actions/git.sh"
|
||||
|
||||
#
|
||||
# Dotfile commands
|
||||
|
||||
4
src/lib/dotify-register-action.sh
Normal file
4
src/lib/dotify-register-action.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
dotify-register-action() {
|
||||
if [ -z "$DOTIFY_ACTIONS" ]; then DOTIFY_ACTIONS=(); fi
|
||||
DOTIFY_ACTIONS+=("$1")
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
dotify-action-git() {
|
||||
if [ "$DOTIFY_RUN_MODE" == "install" ]; then
|
||||
dotify-action-git-install $@
|
||||
elif [ "$DOTIFY_RUN_MODE" == "uninstall" ]; then
|
||||
dotify-action-git-uninstall $@
|
||||
fi
|
||||
}
|
||||
|
||||
dotify-action-git-install() {
|
||||
echo "git install: $@"
|
||||
}
|
||||
|
||||
dotify-action-git-uninstall() {
|
||||
echo "git uninstall: $@"
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
dotify-action-link() {
|
||||
if [ "$DOTIFY_RUN_MODE" == "install" ]; then
|
||||
dotify-action-link-install $@
|
||||
elif [ "$DOTIFY_RUN_MODE" == "uninstall" ]; then
|
||||
dotify-action-link-uninstall $@
|
||||
fi
|
||||
}
|
||||
|
||||
dotify-action-link-install() {
|
||||
echo "link install: $@"
|
||||
}
|
||||
|
||||
dotify-action-link-uninstall() {
|
||||
echo "link uninstall: $@"
|
||||
}
|
||||
Reference in New Issue
Block a user