Skip to content
Snippets Groups Projects

find

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Bartek Jaskulski
    find.sh 721 B
    #!/bin/bash
    
    # Read from standard input and output only the project root paths
    while IFS= read -r line; do
        project_path=$(echo "$line" | awk -F/ '{print $1"/"$2}')
    
        current_dir="$project_path"
        found=false
    
        # While we're within the project directory or or any of its parent directories
        while [ "$current_dir" != "." ]; do
            if [ -f "$current_dir/composer.json" ]; then
                echo "$current_dir"  # Output only the project root path
                found=true
                break
            else
                current_dir=$(dirname "$current_dir")
            fi
        done
    
        if [ "$found" = false ]; then
            echo "$project_path"  # Output the project path if 'composer.json' is not found
        fi
    done
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment