Skip to content

Commit

Permalink
feat(package): add an instruction homeln to create files symlinks on …
Browse files Browse the repository at this point in the history
…home
  • Loading branch information
yunielrc committed Sep 16, 2023
1 parent e2baaa0 commit ed4a268
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 11 deletions.
23 changes: 19 additions & 4 deletions src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Manage packages
#

shopt -s dotglob

#
# FOR CODE COMPLETION
#
Expand All @@ -19,17 +21,17 @@ fi
#

# declare -rA __YDF_PACKAGE_SERVICE_INSTRUCTIONS=(
# [common]="pre_install install post_install home homeln homecp homecps homecat root rootcp rootcps rootln rootcat flatpack dconf.ini plugin_zsh docker_compose"
# [common]="preinstall install postinstall flatpack dconf.ini plugin_zsh docker_compose homeln homelnr homecp homecps homecat rootln rootlnr rootcp rootcps rootcat"
# [manjaro]="pacman yay"
# [ubuntu]="apt"
# )

# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='home homeln homecp homecps homecat root rootcp rootcps rootln rootcat flatpack dconf.ini plugin_zsh docker_compose'
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='preinstall install postinstall flatpack dconf.ini plugin_zsh docker_compose homeln homelnr homecp homecps homecat rootln rootlnr rootcp rootcps rootcat'
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall pacman yay install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall apt install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# shellcheck disable=SC2016
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='plugin_zsh:${pkg_name}.plugin.zsh'
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall install @pacman @yay @flatpak @snap docker_compose:docker-compose.yml postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh homeln postinstall'
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_MANJARO="preinstall @pacman @yay ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_UBUNTU="preinstall install postinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"

#
Expand Down Expand Up @@ -221,6 +223,19 @@ ydf::package_service::__instruction_plugin_zsh() {
fi
}

#
# Execute homeln instruction
#
# Arguments:
# pkg_name string package name
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_homeln() {
ln -vsf --backup "${PWD}/homeln/"* ~/
}

#
# Install a ydotfile package from a directory
#
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/packages/11homeln/homeln/.my-config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my-config
1 change: 1 addition & 0 deletions tests/fixtures/packages/11homeln/homeln/.my/dir1/file11
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file11
1 change: 1 addition & 0 deletions tests/fixtures/packages/11homeln/homeln/.my/file1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file1
1 change: 1 addition & 0 deletions tests/fixtures/packages/11homeln/homeln/.my/file2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file2
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ ydf package COMMAND'

assert_success
assert_output --regexp "5dust@pacman: preinstall succeed
5dust@pacman: install succeed
.*
5dust@pacman: install succeed
5dust@pacman: postinstall succeed"

run command -v dust
Expand All @@ -140,8 +140,8 @@ ydf package COMMAND'

assert_success
assert_output --regexp "bat: preinstall succeed
bat: install succeed
.*
bat: install succeed
bat: postinstall succeed"

run command -v bat
Expand All @@ -158,8 +158,8 @@ bat: postinstall succeed"

assert_success
assert_output --regexp "6nnn@yay: preinstall succeed
6nnn@yay: install succeed
.*
6nnn@yay: install succeed
6nnn@yay: postinstall succeed"

run command -v nnn
Expand All @@ -175,8 +175,8 @@ bat: postinstall succeed"

assert_success
assert_output --regexp "rustscan: preinstall succeed
rustscan: install succeed
.*
rustscan: install succeed
rustscan: postinstall succeed"

run command -v rustscan
Expand Down
15 changes: 15 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-service.i.bats
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,18 @@ docker_compose"
assert_output "'/home/vedv/.yzsh/plugins/local/10ydfplugin.plugin.zsh' -> '/home/vedv/ydf/tests/fixtures/packages/10ydfplugin/10ydfplugin.plugin.zsh'
Plugin '10ydfplugin' already added to /home/vedv/.yzsh-gen.env"
}

@test "ydf::package_service::__instruction_homeln() Should add plugin" {
cd "${TEST_FIXTURES_DIR}/packages/11homeln"

run ydf::package_service::__instruction_homeln '11homeln'

assert_success
assert_output "'/home/vedv/.my' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my'
'/home/vedv/.my-config.env' -> '/home/vedv/ydf/tests/fixtures/packages/11homeln/homeln/.my-config.env'"

assert [ -L '/home/vedv/.my' ]
assert [ -d '/home/vedv/.my' ]
assert [ -L '/home/vedv/.my-config.env' ]
assert [ -f '/home/vedv/.my-config.env' ]
}
5 changes: 2 additions & 3 deletions tools/ct-clean-exec
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ vedv container exec "$VEDV_CONTAINER_NAME" "$@" ||
EXIT_STATUS=$?
# shellcheck disable=SC2155
readonly end_time=$(date +%s%N)
echo ">>>time: $(((end_time - start_time) / 1000000)) ms."
echo ">>Command executed"
echo ">>Command executed, time: $(((end_time - start_time) / 1000000)) ms."

echo
echo ">>Removing dirty container"
Expand All @@ -67,7 +66,7 @@ vedv container create --name "$VEDV_CONTAINER_NAME" "$VEDV_IMAGE_NAME"
echo ">>Container created"

echo
echo ">>Starting container for the next run in background. It can take up to 30 seconds for container to be ready"
echo ">>Starting container in background for the next run. It can take up to 30 seconds for container to be ready"
echo

vedv container start "$VEDV_CONTAINER_NAME" &>/dev/null
Expand Down

0 comments on commit ed4a268

Please sign in to comment.