Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions cmdk-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ script_dirpath="$(cd "$(dirname "${0}")" && pwd)"

output_paths=()

# EXPLANATION:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace all these lines with the following to fix the merge conflict:

Suggested change
# EXPLANATION:
# 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="bash ${script_dirpath}/list-files.sh ${*}" fzf \
-m \
--ansi \
--bind='change:top' \
--scheme=path \
--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}"

# -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="bash ${script_dirpath}/list-files.sh $*" fzf \
-m \
--ansi \
--bind='change:top' \
--scheme=path \
--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 < <(
# 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="bash ${script_dirpath}/list-files.sh ${*}" fzf \
-m \
--ansi \
--bind='change:top' \
--scheme=path \
--preview="bash ${script_dirpath}/preview.sh {}"
if [ "${?}" -ne 0 ]; then
return
fi
)
done <<< "${fzf_output}"

dirs=()
text_files=()
Expand Down Expand Up @@ -67,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)
Expand Down
4 changes: 2 additions & 2 deletions list-files.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

set -euo pipefail
script_dirpath="$(cd "$(dirname "${0}")" && pwd)"
Expand Down Expand Up @@ -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}"
Expand Down