From 146a32324274421d3e0298d5a4b8e3f83c47d2c0 Mon Sep 17 00:00:00 2001 From: segudev <41948994+segudev@users.noreply.github.com> Date: Wed, 30 Jul 2025 11:09:08 +0200 Subject: [PATCH 1/4] Fix bash syntax error in process substitution Refactored the fzf command execution to use command substitution instead of process substitution with conditional logic. The original code had a `return` statement inside a process substitution which created a bash syntax error. Changes: - Capture fzf output in a variable first - Check exit status separately - Use here-string to process the output - Replace `return` with `exit 1` for proper subprocess handling This improves compatibility across different bash versions and makes the code more readable. Fixes the "bad substitution: no closing ')'" error. --- cmdk-core.sh | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/cmdk-core.sh b/cmdk-core.sh index 5dc6c4f..3c64db6 100644 --- a/cmdk-core.sh +++ b/cmdk-core.sh @@ -11,24 +11,25 @@ script_dirpath="$(cd "$(dirname "${0}")" && pwd)" output_paths=() +# EXPLANATION: +# -m allows multiple selections +# --ansi tells fzf to parse the ANSI color codes that we're generating with fd +# --scheme=path optimizes for path-based input +# --with-nth allows us to use the custom sorting mechanism +fzf_output=$(FZF_DEFAULT_COMMAND="sh ${script_dirpath}/list-files.sh ${1:-}" fzf \ + -m \ + --ansi \ + --bind='change:top' \ + --scheme=path \ + --preview="sh ${script_dirpath}/preview.sh {}") + +if [ "${?}" -ne 0 ]; then + exit 1 +fi + while IFS="" read -r line; do # IFS="" -> no splitting (we may have paths with spaces) output_paths+=("${line}") -done < <( - # EXPLANATION: - # -m allows multiple selections - # --ansi tells fzf to parse the ANSI color codes that we're generating with fd - # --scheme=path optimizes for path-based input - # --with-nth allows us to use the custom sorting mechanism - FZF_DEFAULT_COMMAND="sh ${script_dirpath}/list-files.sh ${1:-}" fzf \ - -m \ - --ansi \ - --bind='change:top' \ - --scheme=path \ - --preview="sh ${script_dirpath}/preview.sh {}" - if [ "${?}" -ne 0 ]; then - return - fi -) +done <<< "${fzf_output}" dirs=() text_files=() From f5acecae2c2926552d75eed99d9d5f5916a7fdd2 Mon Sep 17 00:00:00 2001 From: segudev <41948994+segudev@users.noreply.github.com> Date: Sun, 10 Aug 2025 15:45:02 +0200 Subject: [PATCH 2/4] Fix merge conflict --- cmdk-core.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmdk-core.sh b/cmdk-core.sh index 3c64db6..b9d8939 100644 --- a/cmdk-core.sh +++ b/cmdk-core.sh @@ -16,17 +16,15 @@ output_paths=() # --ansi tells fzf to parse the ANSI color codes that we're generating with fd # --scheme=path optimizes for path-based input # --with-nth allows us to use the custom sorting mechanism -fzf_output=$(FZF_DEFAULT_COMMAND="sh ${script_dirpath}/list-files.sh ${1:-}" fzf \ +fzf_output="$(FZF_DEFAULT_COMMAND="bash ${script_dirpath}/list-files.sh ${*}" fzf \ -m \ --ansi \ --bind='change:top' \ --scheme=path \ - --preview="sh ${script_dirpath}/preview.sh {}") - + --preview="bash ${script_dirpath}/preview.sh {}")" if [ "${?}" -ne 0 ]; then exit 1 fi - while IFS="" read -r line; do # IFS="" -> no splitting (we may have paths with spaces) output_paths+=("${line}") done <<< "${fzf_output}" From cca0bcc127dfac6db05e1eac32cfb948df810474 Mon Sep 17 00:00:00 2001 From: segudev <41948994+segudev@users.noreply.github.com> Date: Tue, 6 Jan 2026 10:27:44 +0100 Subject: [PATCH 3/4] Fix unbound variable errors with set -u - Remove braces from $* and $@ parameter expansions to handle empty arguments - Change list-files.sh shebang from sh to bash (script uses bash arrays) --- cmdk-core.sh | 2 +- list-files.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmdk-core.sh b/cmdk-core.sh index b9d8939..30d3333 100644 --- a/cmdk-core.sh +++ b/cmdk-core.sh @@ -16,7 +16,7 @@ output_paths=() # --ansi tells fzf to parse the ANSI color codes that we're generating with fd # --scheme=path optimizes for path-based input # --with-nth allows us to use the custom sorting mechanism -fzf_output="$(FZF_DEFAULT_COMMAND="bash ${script_dirpath}/list-files.sh ${*}" fzf \ +fzf_output="$(FZF_DEFAULT_COMMAND="bash ${script_dirpath}/list-files.sh $*" fzf \ -m \ --ansi \ --bind='change:top' \ diff --git a/list-files.sh b/list-files.sh index 5aaa568..e588513 100644 --- a/list-files.sh +++ b/list-files.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash set -euo pipefail script_dirpath="$(cd "$(dirname "${0}")" && pwd)" @@ -65,7 +65,7 @@ SUBDIRS_MODE="subdirs" # Show all files in the current directory, and recurse i mode="${SYSTEM_MODE}" -for arg in "${@}"; do +for arg in "$@"; do case "$arg" in -o) mode="${PWD_MODE}" From 2a7207c312836b89a62219021fd4883db255638a Mon Sep 17 00:00:00 2001 From: segudev <41948994+segudev@users.noreply.github.com> Date: Tue, 6 Jan 2026 11:01:35 +0100 Subject: [PATCH 4/4] Fix unbound variable error with empty open_targets array --- cmdk-core.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmdk-core.sh b/cmdk-core.sh index 30d3333..e8da643 100644 --- a/cmdk-core.sh +++ b/cmdk-core.sh @@ -66,9 +66,11 @@ for output in "${output_paths[@]}"; do done # We can open open_targets here (no need to pass them to the parent) -for open_target_filepath in "${open_targets[@]}"; do - open "${open_target_filepath}" -done +if [ "${#open_targets[@]}" -gt 0 ]; then + for open_target_filepath in "${open_targets[@]}"; do + open "${open_target_filepath}" + done +fi # However, text files & dirs need to be passed to the parent, so they # get run in the user's shell process (and not this subprocess)