Gentoo Handbook提供了这方面的介绍。 看起来我们要用的是Hooking into the emerge process这一节的内容,也就是/etc/portage/bashrc,其实不然,这个 界面提供了更详细的说明,第一句话就指出了 The /etc/portage/bashrc file is a global bashrc file referenced by Portage. bashrc中定义的hook是全局生效的,显然不适用于我们的情况,实际上我们应该使用的是第二节提到的env。
To have a file called when emerging a specific package, it should be named following the pattern “/etc/portage/env/<category>/<package_name>” (versions can be included, see portage man page), the contents being as in /etc/portage/bashrc; the contents will be parsed as a bash script. These files can hook into specific phases of the emerge process.
post_src_install() { local insert_block="export export GTK_IM_MODULE=fcitx\nexport QT_IM_MODULE=fcitx5\nexport XMODIFIERS=@im=fcitx"
einfo ">>> [Fcitx Hook] adding environment variables to wps-office scripts in /usr/bin ..."
local bin_dir="${D}/usr/bin"
if [[ -d "${bin_dir}" ]]; then for script in"${bin_dir}"/*; do if [[ -f "${script}" ]]; then # safe check ifhead -n 1 "${script}" | grep -q "^#!"; then einfo "Patching: ${script##*/}" sed -i "4i ${insert_block}""${script}" else ewarn "Skipping: ${script##*/}" fi fi done else ewarn "Warning: ${bin_dir} DONT exist! skip hook" fi }