From 0b3468ed4915b6dc5fc1a0bb5d0c64583b647b05 Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 27 Jul 2018 17:48:58 +0300 Subject: [PATCH] macro support Signed-off-by: fbt --- sx-open | 13 +++++++++++-- sx-open.cfg | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sx-open b/sx-open index 7f2ec5a..b9384f6 100755 --- a/sx-open +++ b/sx-open @@ -23,7 +23,7 @@ act() { # 3: no handler handle_target() { declare -n result=$1 - declare h cmd regex target_is_file target target_left + declare h cmd regex target_is_file target target_left cmd_is_template target_is_file=0 target=$2 target_left=$target @@ -46,8 +46,17 @@ handle_target() { while (( $# )); do 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 [[ "$target_left" =~ $regex ]]; then - act "${cmd[@]}" "$target"; result=$? + act "${cmd[@]}"; result=$? (( result )) && return 1 return 0 diff --git a/sx-open.cfg b/sx-open.cfg index e8cafb4..fddeecd 100644 --- a/sx-open.cfg +++ b/sx-open.cfg @@ -2,6 +2,12 @@ # Configuration file for sx-open # Note that as sx-open checks the regexes in order, they should be placed in order from specific to less so. +# macros: +# %target% — The first argument to this script. +# If not found, target is appended to the end of +# example: +#uri 'browser %target% --profile=work' '^https://.+\.?workdomain.tld.*' + # scheme [ ...] #scheme browser http https #scheme steam steam