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
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# Define scripts to work with
SCRIPTS=("wtadd.sh" "wtremove.sh" "wtclone.sh" "wtlist.sh")

Expand Down
38 changes: 30 additions & 8 deletions wtadd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ function cp_cow {
}


# Detect which find variant is available by testing capabilities
function detect_find_variant {
# Test for BSD find (supports -E flag)
if find -E /dev/null -maxdepth 0 2>/dev/null; then
echo "bsd"
# Test for GNU find (supports --regextype)
elif find /dev/null -maxdepth 0 -regextype posix-extended 2>/dev/null; then
echo "gnu"
else
echo "basic"
fi
}

# Create a worktree from a given branchname, and copy some untracked files
function _worktree {
if [ -z "$1" ]; then
Expand Down Expand Up @@ -140,19 +153,28 @@ function _worktree {
# other way around
#
# shellcheck disable=SC2207
platform=`uname`
find_variant=$(detect_find_variant)
if $is_worktree; then
copy_source="."
else
copy_source=./$(git rev-parse --abbrev-ref HEAD)
fi
if [ "$platform" = "Darwin" ]; then
files_to_copy=( $(find -E $copy_source -not -path '*node_modules*' -and \
-iregex '.*\/\.(envrc|env|env.local|tool-versions|mise.toml)' ) )
else
files_to_copy=( $(find $copy_source -not -path '*node_modules*' -and \
-regextype posix-extended -iregex '.*\/\.(envrc|env|env.local|tool-versions|mise.toml)' ) )
fi

case "$find_variant" in
"bsd")
files_to_copy=( $(find -E $copy_source -not -path '*node_modules*' -and \
-iregex '.*\/\.(envrc|env|env.local|tool-versions|mise.toml)' ) )
;;
"gnu")
files_to_copy=( $(find $copy_source -not -path '*node_modules*' -and \
-regextype posix-extended -iregex '.*\/\.(envrc|env|env.local|tool-versions|mise.toml)' ) )
;;
"basic")
# Fallback to basic find without extended regex - use simple name matching
files_to_copy=( $(find $copy_source -not -path '*node_modules*' \
\( -name '.envrc' -o -name '.env' -o -name '.env.local' -o -name '.tool-versions' -o -name 'mise.toml' \) ) )
;;
esac

for f in "${files_to_copy[@]}"; do
target_path="${f#$copy_source/}"
Expand Down