Skip to content

Commit

Permalink
Shell escape SRC and TARGET for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Oct 25, 2022
1 parent 93e9b2b commit 7c73055
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1689,14 +1689,16 @@ xplr.config.modes.builtin.rename = {
{
BashExecSilently0 = [===[
SRC="${XPLR_FOCUS_PATH:?}"
SRC_ESC=$(printf %q "$SRC")
TARGET="${XPLR_INPUT_BUFFER:?}"
TARGET_ESC=$(printf %q "$TARGET")
if [ -e "${TARGET:?}" ]; then
"$XPLR" -m 'LogError: %q' "$TARGET already exists"
"$XPLR" -m 'LogError: %q' "$TARGET_ESC already exists"
else
mv -- "${SRC:?}" "${TARGET:?}" \
&& "$XPLR" -m ExplorePwd \
&& "$XPLR" -m 'FocusPath: %q' "$TARGET" \
&& "$XPLR" -m 'LogSuccess: %q' "$SRC renamed to $TARGET"
&& "$XPLR" -m 'LogSuccess: %q' "$SRC_ESC renamed to $TARGET_ESC"
fi
]===],
},
Expand Down Expand Up @@ -1731,14 +1733,16 @@ xplr.config.modes.builtin.duplicate_as = {
{
BashExecSilently0 = [===[
SRC="${XPLR_FOCUS_PATH:?}"
SRC_ESC=$(printf %q "$SRC")
TARGET="${XPLR_INPUT_BUFFER:?}"
TARGET_ESC=$(printf %q "$TARGET")
if [ -e "${TARGET:?}" ]; then
"$XPLR" -m 'LogError: %q' "$TARGET already exists"
"$XPLR" -m 'LogError: %q' "$TARGET_ESC already exists"
else
cp -r -- "${SRC:?}" "${TARGET:?}" \
&& "$XPLR" -m ExplorePwd \
&& "$XPLR" -m 'FocusPath: %q' "$TARGET" \
&& "$XPLR" -m 'LogSuccess: %q' "$SRC duplicated as $TARGET"
&& "$XPLR" -m 'FocusPath: %q' "$TARGET_ESC" \
&& "$XPLR" -m 'LogSuccess: %q' "$SRC_ESC duplicated as $TARGET_ESC"
fi
]===],
},
Expand Down

0 comments on commit 7c73055

Please sign in to comment.