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

add ppath command #72

Merged
merged 7 commits into from
Mar 28, 2015
Merged

add ppath command #72

merged 7 commits into from
Mar 28, 2015

Conversation

dopcn
Copy link

@dopcn dopcn commented Jan 14, 2015

Print application's 'Documents' directory path.

Print application's 'Documents' directory path.
@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!


class FBPrintApplicationDocumentsPath(fb.FBCommand):
def name(self):
return 'ppath'
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like pdocspath might be a better command here, even if it is a bit verbose. Luckily the prefix matching will then allow pdocs to work as well. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

have thought about this before. It seems to me the word docs path is a little ambiguous, maybe docs dir path is better but too long. Here use ppath is just easy to type in. will change to the name suggested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thought: have ppath capable of printing other paths other than docs, and have it take an argument to specify which specific path. Otherwise, perhaps ppath can just print the app root, and then it's easy for users to append Documents or any other subpath.

return "Print application's 'Documents' directory path."

def run(self, arguments, options):
lldb.debugger.HandleCommand('po [NSSearchPathForDirectoriesInDomains(9, 1, YES) lastObject]') # NSDocumentDirectory == 9 NSUserDomainMask == 1
Copy link
Contributor

Choose a reason for hiding this comment

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

In other parts of Chisel, in addition to printing a value, we've copied it to the pasteboard. Would you mind adding that here?

@kastiglione
Copy link
Contributor

@dopcn What do you think about having option flags to allow the desired directory to be opened in Terminal, or maybe Finder as well? For example ppath -t to open in Terminal. These don't need to be added to this pull request, but they'd be nice to add sooner or later.

not fully tested yet

def run(self, arguments, options):
if options.open:
path = fb.evaluateExpressionValue('(NSString *)[NSSearchPathForDirectoriesInDomains(9, 1, YES) lastObject]')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make constants for these numbers?

Copy link
Contributor

Choose a reason for hiding this comment

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

This could use evaluateObjectExpression() instead of evaluateExpressionValue(), which would make the NSString cast unnecessary.

Copy link
Author

Choose a reason for hiding this comment

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

@kastiglione hi I tried evaluateObjectExpression() and evaluateExpression() but only get pointer value instead of string value so I keep using evaluateExpressionValue() and split the string output in the new implementation. Am I missing something?

@kastiglione
Copy link
Contributor

@dopcn What do you think of the comments I made?

@dopcn
Copy link
Author

dopcn commented Mar 17, 2015

@kastiglione sorry, back and working on it now...

@dopcn
Copy link
Author

dopcn commented Mar 27, 2015

Update copy to the pasteboard before print

NSUserDomainMask = '1'
path = fb.evaluateExpressionValue('(NSString*)[NSSearchPathForDirectoriesInDomains(' + NSDocumentDirectory + ', ' + NSUserDomainMask + ', YES) lastObject]')
pathString = '{}'.format(path).split('"')[1]
cmd = 'echo {} | tr -d "\n" | pbcopy'.format(pathString)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be echo -n to avoid the tr piece.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know why echo -n just doesn't work as os.system()'s parameter. The -n will be taken as part of pathString and copied into pasteboard

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems /bin/sh doesn't handle -n like bash and zsh do. Oh well. Thanks for trying.

@kastiglione
Copy link
Contributor

Thanks @dopcn, I'm happy to accept this. Before that, can you merge from master because there are now conflicts.

@kastiglione
Copy link
Contributor

Thanks @dopcn!

kastiglione added a commit that referenced this pull request Mar 28, 2015
@kastiglione kastiglione merged commit dc87f01 into facebook:master Mar 28, 2015
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.

4 participants