From f71bff54182f37a5c31d0ea11735dcc7ce79590d Mon Sep 17 00:00:00 2001 From: Eric Nielsen <4120606+ericbn@users.noreply.github.com> Date: Thu, 16 Feb 2023 07:47:42 -0500 Subject: [PATCH] Quote path names in init.zsh to properly handle path names with spaces. Fixes #497 --- CHANGELOG.md | 4 +++- src/stage2/29_zimfw_build_init.zsh.erb | 6 +++--- src/stage2/30_zmodule.zsh.erb | 8 ++++---- src/tools/degit.zsh.erb | 2 +- zimfw.zsh | 18 +++++++++--------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33eee9c..8d627a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes._ +### Fixed + +- Quote path names in init.zsh to properly handle path names with spaces. ## [1.11.1] - 2023-02-04 diff --git a/src/stage2/29_zimfw_build_init.zsh.erb b/src/stage2/29_zimfw_build_init.zsh.erb index 8a36e00..c0a0c69 100644 --- a/src/stage2/29_zimfw_build_init.zsh.erb +++ b/src/stage2/29_zimfw_build_init.zsh.erb @@ -5,8 +5,8 @@ _zimfw_build_init() { command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( - print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" - print -R "zmodule() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) @@ -22,7 +22,7 @@ _zimfw_build_init() { fi done zpre=$'*\0' - if (( ${#_zfpaths} )) print 'fpath=('${${_zfpaths#${~zpre}}:A}' ${fpath})' + if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:A}' ${fpath})' if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}} for zroot_dir in ${_zroot_dirs}; do zpre=${zroot_dir}$'\0' diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index c36ab11..5d6e18e 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -179,11 +179,11 @@ Per-call initialization options: shift zarg=${1} if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg} - zcmds+=("source ${zarg:A}") + zcmds+=("source ${(q-)zarg:A}") ;; -c|--cmd) shift - zcmds+=(${1//{}/${zroot_dir:A}}) + zcmds+=(${1//{}/${(q-)zroot_dir:A}}) ;; -d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;; *) @@ -211,11 +211,11 @@ Per-call initialization options: local -ra prezto_scripts=(${zroot_dir}/init.zsh(N)) if (( ${#zfpaths} && ${#prezto_scripts} )); then # this follows the prezto module format, no need to check for other scripts - zcmds=('source '${^prezto_scripts:A}) + zcmds=('source '${(q-)^prezto_scripts:A}) else # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - zcmds=('source '${^zscripts:A}) + zcmds=('source '${(q-)^zscripts:A}) fi fi if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then diff --git a/src/tools/degit.zsh.erb b/src/tools/degit.zsh.erb index fa639f0..121e011 100644 --- a/src/tools/degit.zsh.erb +++ b/src/tools/degit.zsh.erb @@ -1,7 +1,7 @@ # This runs in a new shell builtin emulate -L zsh -o EXTENDED_GLOB readonly -i PRINTLEVEL=${1} SUBMODULES=${8} -readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} ONPULL=${9} TEMP=.zdegit_${RANDOM} +readonly ACTION=${2} MODULE=${3} DIR=${4} URL=${5} REV=${7} ONPULL=${9} TEMP=.zdegit_${sysparams[pid]} readonly TARBALL_TARGET=${DIR}/${TEMP}_tarball.tar.gz INFO_TARGET=${DIR}/.zdegit print_error() { diff --git a/zimfw.zsh b/zimfw.zsh index 9f0c11c..5a00c5a 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -57,8 +57,8 @@ _zimfw_build_init() { command mv -f ${ztarget}{,.old} || return 1 fi _zimfw_mv =( - print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" - print -R "zmodule() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zimfw() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" + print -R "zmodule() { source ${(q-)ZIM_HOME}/zimfw.zsh \"\${@}\" }" local zroot_dir zpre local -a zif_functions zif_cmds zroot_functions zroot_cmds local -a zfunctions=(${_zfunctions}) zcmds=(${_zcmds}) @@ -74,7 +74,7 @@ _zimfw_build_init() { fi done zpre=$'*\0' - if (( ${#_zfpaths} )) print 'fpath=('${${_zfpaths#${~zpre}}:A}' ${fpath})' + if (( ${#_zfpaths} )) print 'fpath=('${(q-)${_zfpaths#${~zpre}}:A}' ${fpath})' if (( ${#zfunctions} )) print -R 'autoload -Uz -- '${zfunctions#${~zpre}} for zroot_dir in ${_zroot_dirs}; do zpre=${zroot_dir}$'\0' @@ -292,11 +292,11 @@ Per-call initialization options: shift zarg=${1} if [[ ${zarg} != /* ]] zarg=${zroot_dir}/${zarg} - zcmds+=("source ${zarg:A}") + zcmds+=("source ${(q-)zarg:A}") ;; -c|--cmd) shift - zcmds+=(${1//{}/${zroot_dir:A}}) + zcmds+=(${1//{}/${(q-)zroot_dir:A}}) ;; -d|--disabled) _zdisabled_root_dirs+=(${zroot_dir}) ;; *) @@ -324,11 +324,11 @@ Per-call initialization options: local -ra prezto_scripts=(${zroot_dir}/init.zsh(N)) if (( ${#zfpaths} && ${#prezto_scripts} )); then # this follows the prezto module format, no need to check for other scripts - zcmds=('source '${^prezto_scripts:A}) + zcmds=('source '${(q-)^prezto_scripts:A}) else # get script with largest size (descending `O`rder by `L`ength, and return only `[1]` first) local -ra zscripts=(${zroot_dir}/(init.zsh|(${zname:t}|${zroot_dir:t}).(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - zcmds=('source '${^zscripts:A}) + zcmds=('source '${(q-)^zscripts:A}) fi fi if (( ! ${#zfpaths} && ! ${#zfunctions} && ! ${#zcmds} )); then @@ -454,7 +454,7 @@ _zimfw_compile() { } _zimfw_info() { - print -R 'zimfw version: '${_zversion}' (built at 2023-02-04 14:46:47 UTC, previous commit is 7778e97)' + print -R 'zimfw version: '${_zversion}' (built at 2023-02-16 12:44:26 UTC, previous commit is fae0a7e)' print -R 'OSTYPE: '${OSTYPE} print -R 'TERM: '${TERM} print -R 'TERM_PROGRAM: '${TERM_PROGRAM} @@ -584,7 +584,7 @@ _zimfw_run_tool() { degit) zcmd="# This runs in a new shell builtin emulate -L zsh -o EXTENDED_GLOB readonly -i PRINTLEVEL=\${1} SUBMODULES=\${8} -readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} ONPULL=\${9} TEMP=.zdegit_\${RANDOM} +readonly ACTION=\${2} MODULE=\${3} DIR=\${4} URL=\${5} REV=\${7} ONPULL=\${9} TEMP=.zdegit_\${sysparams[pid]} readonly TARBALL_TARGET=\${DIR}/\${TEMP}_tarball.tar.gz INFO_TARGET=\${DIR}/.zdegit print_error() {