what are the chances you actually need literal '%template' in cmd?

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-07-27 20:43:04 +03:00
parent 5675a08012
commit ccad66749c
1 changed files with 7 additions and 10 deletions

17
sx-open
View File

@ -107,7 +107,7 @@ error() {
handle_target() {
declare -n result=$1
declare h cmd regex target_is_file target target_left cmd_is_template
target_is_file=0
cmd_append_target=1
target=$2
target_left=$target
@ -127,16 +127,13 @@ handle_target() {
fi
while (( $# )); do
cmd=( $1 ); regex=$2
cmd=$1 regex=$2
for c in "${!cmd[@]}"; do
if [[ "${cmd[c]}" == '%target%' ]]; then
cmd_is_template=1
cmd[c]="$target"
fi
done
(( cmd_is_template )) || cmd+=( "$target" )
if [[ $cmd == *'%target%'* ]]; then
cmd=( ${cmd//%target%/$target} )
else
cmd+=( "$target" )
fi
if [[ "$target_left" =~ $regex ]]; then
act "${cmd[@]}"; result=$?