GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add tilde expansion to expand() by nfischer · Pull Request #293 · shelljs/shelljs

Conversation

@nfischer

@nfischer nfischer commented Jan 19, 2016

Copy link
Copy Markdown
Member

This adds tilde expansion to the expand() function. Arguments starting with '~/'
will have the tilde expanded to the user's home directory, as with Bash.

Also, if an argument is simply ~, then it will expand to the home directory as well.

> cd('~'); // Go to home directory
> ls('~/*.js'); // Look for all .js files
> cd('~/..'); // Go to /home, /Users, or C:\Users

This does not support all of Bash's tilde expansion (not sure if this would be difficult). For example:

$ ls ~otheruser # look into otheruser's home folder
$ # Nothing like this is supported in ShellJS

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nfischer nfischer added feature low priority labels Jan 19, 2016
@nfischer nfischer assigned ariporad Jan 19, 2016
@nfischer

nfischer commented Jan 19, 2016

Copy link
Copy Markdown
Member Author

This works right now with the old expand() function. If we rework this function to use the glob module (#275), this should still be compatible.

This still needs to be tested on Windows.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 19, 2016

Copy link
Copy Markdown
Member Author

For future reference, this prefers os.homedir when it's available, which I can see in node v3.0.0 (nodejs/node#1791). For earlier versions, this relies on environmental variables, which appears to work well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ariporad
ariporad reviewed Jan 24, 2016
View reviewed changes
Comment thread src/common.js

@ariporad ariporad Jan 24, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why not just use os-homedir instead? I don't really feel like we need to reinvent the wheel. (It's also not really that big a deal either way).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nfischer nfischer Jan 24, 2016

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

In terms of implementation, this should be very similar. I opted to just code it myself because it cuts out a dependency and it was only a few lines of code. I think it's easier to keep small snippets in the code base.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ariporad ariporad Jan 24, 2016

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ok

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ariporad ariporad assigned nfischer and unassigned ariporad Jan 24, 2016
@nfischer
feat: add tilde expansion to expand()
b3f2664
This adds tilde expansion to the expand() function. Arguments starting with '~/'
will have the tilde expanded to the user's home directory, as with Bash.
@ariporad

ariporad commented Jan 24, 2016

Copy link
Copy Markdown
Contributor

Did this ever get tested on Windows?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 24, 2016

Copy link
Copy Markdown
Member Author

@ariporad good catch! I did test it on my Windows 7 machine. It passes the test/cd.js unit tests. I also ran a simple shell script myself, and it behaves exactly as I would expect.

cd('~');
echo(pwd());
cd('~/Documents'); // still works, evven with a forward slash
echo(pwd());
cd('~');
echo(pwd());
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 24, 2016

Copy link
Copy Markdown
Member Author

That was testing on Windows 7 64 bit, Node v5, running through cmd.exe

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Jan 24, 2016

Copy link
Copy Markdown
Contributor

LGTM!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ariporad added a commit that referenced this pull request Jan 24, 2016
@ariporad
Merge pull request #293 from nfischer/feat-home-directory-tilde
c422069
feat: add tilde expansion to expand()
@ariporad
ariporad merged commit c422069 into shelljs:master Jan 24, 2016
@nfischer
nfischer deleted the feat-home-directory-tilde branch January 28, 2016 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@nfischer nfischer

Labels

feature low priority

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@nfischer @ariporad
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.