File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55- Run ` shellcheck ` on all modified shell scripts.
66- If tests exist, run them and ensure each test method covers one execution path.
77- Keep files you touch tidy by fixing typos or minor issues you encounter.
8+ - When sourcing multiple files, load them individually in a deterministic order.
Original file line number Diff line number Diff line change 7171#
7272# @internal
7373# ###
74- pms_libs= " $(
75- find " $PMS /lib " -maxdepth 1 -type f \( -name ' *.sh ' -o -name " *. $PMS_SHELL " \)
76- ) "
77- for library_file in $pms_libs ; do
74+ # Load core and auxiliary libraries in a stable order. The while loop avoids
75+ # shell-specific word-splitting issues and guarantees each file is sourced
76+ # individually.
77+ while IFS= read -r library_file ; do
7878 # shellcheck disable=SC1090
7979 . " $library_file "
8080 if [ 1 -eq " ${PMS_DEBUG:- 0} " ]; then
8181 echo " source $library_file "
8282 fi
83- done
84- unset pms_libs library_file
83+ done < <( find " $PMS /lib" -maxdepth 1 -type f \( -name ' *.sh' -o -name " *.$PMS_SHELL " \) | sort)
8584
8685if [ -d " $PMS_LOCAL /lib" ]; then
87- local_libs=" $(
88- find " $PMS_LOCAL /lib" -maxdepth 1 -type f \( -name ' *.sh' -o -name " *.$PMS_SHELL " \)
89- ) "
90- for local_library in $local_libs ; do
86+ while IFS= read -r local_library; do
9187 # shellcheck disable=SC1090
9288 . " $local_library "
9389 if [ 1 -eq " ${PMS_DEBUG:- 0} " ]; then
9490 echo " source $local_library "
9591 fi
96- done
97- unset local_libs local_library
92+ done < <( find " $PMS_LOCAL /lib" -maxdepth 1 -type f \( -name ' *.sh' -o -name " *.$PMS_SHELL " \) | sort)
9893fi
9994
10095_pms_source_file " $HOME /.pms.plugins"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+ # shellcheck shell=bash
3+
4+ setup () {
5+ pms_root=" $( cd " $BATS_TEST_DIRNAME /.." && pwd) "
6+ export PMS=" $pms_root "
7+ export PMS_LOCAL=" $BATS_TEST_TMPDIR /local"
8+ mkdir -p " $PMS_LOCAL /plugins"
9+ export PMS_DEBUG=0
10+ export PMS_THEME=default
11+ export HOME=" $BATS_TEST_TMPDIR /home"
12+ mkdir -p " $HOME "
13+ }
14+
15+ @test " pms.sh loads libraries when sourced in zsh" {
16+ run zsh -c " source \" $PMS /pms.sh\" zsh >/dev/null && type _pms_source_file >/dev/null"
17+ [ " $status " -eq 0 ]
18+ }
You can’t perform that action at this time.
0 commit comments