Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unbound variable error in dir2prompt script #1

Open
thibaultyou opened this issue Sep 18, 2024 · 0 comments
Open

Fix unbound variable error in dir2prompt script #1

thibaultyou opened this issue Sep 18, 2024 · 0 comments

Comments

@thibaultyou
Copy link

Unbound variable error in dir2prompt.sh script after build

Description

After building the dir2prompt util using the provided justfile, running the resulting executable in the build directory produces an "unbound variable" error. This error prevents the script from executing correctly and limits its usability.

Steps to Reproduce

  1. Clone the repository
  2. Run the build process using the command: just build
  3. Change to the build directory
  4. Attempt to run the built script with various argument combinations, such as:
./dir2prompt .

Error Message

When running the built script, the following error is encountered:

./dir2prompt.sh: line 202: args[2]: unbound variable

Expected Behavior

The built script should run without errors for all valid argument combinations, including when fewer than three arguments are provided.

Actual Behavior

The built script throws an "unbound variable" error when attempting to access args[2], particularly when fewer than three arguments are provided.

Possible Cause

The error seems to originate from line 202 in the built script, where it's trying to access args[2] without first checking if it exists. This suggests that the argument parsing or handling in the script is not properly accounting for cases with fewer arguments.

Proposed Fix

I have prepared a fix for this issue that includes the following changes:

  1. Modified the argument parsing in the main execution part to handle cases with fewer arguments.
  2. Updated the parse_arguments function to output arguments in a more robust manner.
  3. Added default values for required variables to ensure they always have a value.
  4. Updated the README to include rg (ripgrep) as a dependency.
  5. Updated the version number to reflect this bug fix.

These changes allow the script to run without errors for all valid argument combinations and ensure users are aware of all required dependencies.

System Information

  • OS: macOS, version 14.6, build 23G80
  • Shell version: fish, version 3.7.1

Additional Notes

I have tested the fix by rebuilding the script and verifying that it resolves the unbound variable error when run from the build directory. I'm prepared to submit a pull request with these changes.

Let me know if you need any further information.

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

No branches or pull requests

1 participant