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

Filename arguments invalidated after implicit cd #136

Closed
CGamesPlay opened this issue Jun 7, 2023 · 0 comments · Fixed by #138
Closed

Filename arguments invalidated after implicit cd #136

CGamesPlay opened this issue Jun 7, 2023 · 0 comments · Fixed by #138

Comments

@CGamesPlay
Copy link
Contributor

Hey, loving the activity on this project. Thanks for resolving #118 so quickly. I've now ported most of my projects to using argc, and I'm seeing how far I can push it.

It's great that argc automatically cds into the directory of the Argcfile.sh it finds in the parent hierarchy; this is generally the thing that a script author wants. However, if the command accepts a filename argument, the filename is invalid when the script gets run. See this Argcfile for an example:

#!/usr/bin/env bash
# @arg file <FILE>
set -e
eval "$(argc --argc-eval "$0" "$@")"
ls $argc_file

Run this script:

mkdir directory
cd directory
touch test.txt
argc test.txt

The script fails, because the file does not exist, because the directory was changed.

I can think of a few options here:

  • Export ARGC_ORIGINAL_PATH or some other variable, which contains the path of the original pwd.
  • For <FILE/DIR/PATH> arguments, they are automatically prefixed with the appropriate path.

The first option seems like the best overall to me. The second requires that the argument values are tagged properly, and there could also be use cases where we don't need a specific argument, but we still want to know the original directory of the command.

Thanks for your consideration!

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 a pull request may close this issue.

1 participant