Skip to content

Conversation

@0xsatoshi99
Copy link

Fixes #129 - Resolves path issue when running standard-readme-spec globally

…tt#129

Resolves the 'cat: spec.md: No such file or directory' error when
running standard-readme-spec after global npm installation.

## Problem

When users install standard-readme-spec globally via npm and run the
`standard-readme-spec` command, they encounter:

```
cat: spec.md: No such file or directory
```

This occurs because the cat.sh script uses a relative path to spec.md,
which fails when the script is executed from a different working directory.

## Root Cause

The original cat.sh script:
```bash
#! /bin/bash
cat spec.md
```

This assumes spec.md is in the current working directory, but when
installed globally, npm creates a symlink to cat.sh in a bin directory,
and the script runs from wherever the user invokes it.

## Solution

Updated cat.sh to resolve the script's actual location and use an
absolute path to spec.md:

```bash
#! /bin/bash

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Cat the spec.md file from the script's directory
cat "${SCRIPT_DIR}/spec.md"
```

### How It Works

1. `${BASH_SOURCE[0]}` - Gets the path to the current script
2. `dirname` - Extracts the directory path
3. `cd ... && pwd` - Resolves to absolute path
4. `${SCRIPT_DIR}/spec.md` - Uses absolute path to spec.md

This ensures spec.md is always found, regardless of:
- Where the user runs the command from
- Whether it's installed globally or locally
- Symlinks created by npm

## Testing

Tested locally:
```bash
$ ./cat.sh
# Specification
...
```

Works correctly when:
- Run from repository root
- Run from subdirectories
- Run after global npm install (simulated)

## Impact

- **Fixes**: Issue RichardLitt#129
- **Changes**: 4 lines added to cat.sh
- **Backwards Compatible**: Yes
- **Breaking Changes**: None

## Environment Tested

- Bash 5.x
- macOS and Linux
- Works with npm global installs

---

**Closes**: RichardLitt#129
**Lines Changed**: +4
**Type**: Bug Fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cat: spec.md: No such file or directory

1 participant