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: support tilde expansion #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

HasanAlrimawi
Copy link

This PR suggests possible solution for #26676

Changes

  • Expand tilde to home directory whenever applicable (being mentioned as home directory).

@CLAassistant
Copy link

CLAassistant commented Nov 27, 2024

CLA assistant check
All committers have signed the CLA.

|| (text.find('~').unwrap_or(0) == text.len() - 1)
{
let temp = text.clone().replace(
'~',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this as a test case? I think it will fail: echo ~/test/~/test (should only expand ~/)

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Let's shift this to happen when executing and not when parsing.

text.push_str(temp.as_str());
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should do this while parsing, but instead during execution. The home directory in the shell might change while running. For example, the following test case should pass:

$ export HOME=test ; echo ~/test/~/test
test/test/~/test

@HasanAlrimawi
Copy link
Author

HasanAlrimawi commented Dec 2, 2024

@dsherret
I was able to solve the testcase you mentioned. However, in src/shell/execute.rs fn execute_sequential_list
When I try to destructure the item.sequence before execution, in order to check tildes occurrences for expansion, some values get partially moved, which leaves me forced to re-generate the sequence again and that may be overhead.
Any suggestions/better approaches in order to update the WordParts with tildes expanded? (e.g. another place of the code that may help with that, etc.)

@HasanAlrimawi
Copy link
Author

@dsherret I was able to solve the testcase you mentioned. However, in src/shell/execute.rs fn execute_sequential_list When I try to destructure the item.sequence before execution, in order to check tildes occurrences for expansion, some values get partially moved, which leaves me forced to re-generate the sequence again and that may be overhead. Any suggestions/better approaches in order to update the WordParts with tildes expanded? (e.g. another place of the code that may help with that, etc.)

@dsherret
Any possible insights?

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.

3 participants