Skip to content

Commit

Permalink
feat(package): add instruction to add a yzsh theme
Browse files Browse the repository at this point in the history
  • Loading branch information
yunielrc committed Sep 22, 2023
1 parent fc58248 commit a5ae0bf
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/usr/lib/ydf/components/package/ydf-package-service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fi
# 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='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh homeln/ homelnr/ homecp/ rootcp/ homecat/ rootcat/ homecps/ rootcps/ homecats/ rootcats/ dconf_ini:dconf.ini postinstall'
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON='install @flatpak @snap docker_compose:docker-compose.yml plugin_zsh:${pkg_name}.plugin.zsh theme_zsh:${pkg_name}.theme.zsh homeln/ homelnr/ homecp/ rootcp/ homecat/ rootcat/ homecps/ rootcps/ homecats/ rootcats/ dconf_ini:dconf.ini postinstall'
# ANY OS
readonly __YDF_PACKAGE_SERVICE_INSTRUCTIONS_ANY="preinstall ${__YDF_PACKAGE_SERVICE_INSTRUCTIONS_COMMON}"
# MANJARO
Expand Down Expand Up @@ -256,6 +256,28 @@ ydf::package_service::__instruction_plugin_zsh() {
fi
}

#
# Execute theme_zsh instruction
#
# Arguments:
# pkg_name string package name
#
# Returns:
# 0 on success, non-zero on error.
#
ydf::package_service::__instruction_theme_zsh() {
local -r package_name="$1"

local -r theme_name="${package_name}.theme.zsh"
local -r theme_file="${PWD}/${theme_name}"
local -r theme_dest_file="${__YDF_YZSH_DATA_DIR}/themes/local/${theme_name}"

ln -vsf "$theme_file" "$theme_dest_file" || {
err "Creating theme symlink: ${theme_dest_file}"
return "$ERR_FILE_CREATION"
}
}

#
# Execute homeln instruction
#
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/packages/24ydftheme/24ydftheme.theme.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo 'great colors theme'
18 changes: 18 additions & 0 deletions tests/usr/lib/ydf/components/package/ydf-package-command.f.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ setup() {
fi
mkdir /home/vedv/.yzsh/plugins/local

if [[ -d /home/vedv/.yzsh/themes/local ]]; then
rm -rf /home/vedv/.yzsh/themes/local
fi
mkdir /home/vedv/.yzsh/themes/local

if [[ -d /.my ]]; then
sudo rm -r /.my
fi
Expand Down Expand Up @@ -826,3 +831,16 @@ preinstall: preinstall succeed"
postinstall
preinstall: preinstall succeed"
}

# Tests for ydf package install ./24ydftheme
@test "ydf package install ./24ydftheme Should succeed" {
local -r _package_name="24ydftheme"

run ydf package install "$_package_name"

assert_success
assert_output "'/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' -> '/home/vedv/ydf/tests/fixtures/packages/24ydftheme/24ydftheme.theme.zsh'"

assert [ -L '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
assert [ -f '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
}
32 changes: 32 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 @@ -25,6 +25,11 @@ setup() {
fi
mkdir /home/vedv/.yzsh/plugins/local

if [[ -d /home/vedv/.yzsh/themes/local ]]; then
rm -rf /home/vedv/.yzsh/themes/local
fi
mkdir /home/vedv/.yzsh/themes/local

if [[ -d /.my ]]; then
sudo rm -r /.my
fi
Expand Down Expand Up @@ -1174,3 +1179,30 @@ install: HOME: /home/vedv"
assert_success
assert_output "postinstall: MY_CONFIG2: my config2"
}

# Tests for ydf::package_service::__instruction_theme_zsh()
@test "ydf::package_service::__instruction_theme_zsh() Should fail if ln fails" {
cd "${TEST_FIXTURES_DIR}/packages/24ydftheme"

ln() {
assert_equal "$*" "-vsf /home/vedv/ydf/tests/fixtures/packages/24ydftheme/24ydftheme.theme.zsh /home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh"
return 1
}

run ydf::package_service::__instruction_theme_zsh '24ydftheme'

assert_failure
assert_output "ERROR> Creating theme symlink: /home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh"
}

@test "ydf::package_service::__instruction_theme_zsh() Should add theme" {
cd "${TEST_FIXTURES_DIR}/packages/24ydftheme"

run ydf::package_service::__instruction_theme_zsh '24ydftheme'

assert_success
assert_output "'/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' -> '/home/vedv/ydf/tests/fixtures/packages/24ydftheme/24ydftheme.theme.zsh'"

assert [ -L '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
assert [ -f '/home/vedv/.yzsh/themes/local/24ydftheme.theme.zsh' ]
}

0 comments on commit a5ae0bf

Please sign in to comment.