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

command history incorrect after typo in previous entry #157

Closed
stuft2 opened this issue Oct 7, 2016 · 7 comments
Closed

command history incorrect after typo in previous entry #157

stuft2 opened this issue Oct 7, 2016 · 7 comments
Labels

Comments

@stuft2
Copy link

stuft2 commented Oct 7, 2016

When I make a typo in the aws-shell, it stores the command history in the history file incorrectly. So when I press the up arrow and correct the typo, I also have to correct the error that was made when my history was logged in the .aws/shell/history file.
My history file looks like this:

#2016-10-07 10:06:22.174150
+aws lamda add-permission --function-name hw-server --statement-id sns-invoke --action lambda:invokeFunction --principal sns.amazonaws.com --region ... --source-arn arn:aws:sns:...

#2016-10-07 10:06:52.750689
+aws lambda add-permission --function-name hw-server --statement-id sns-invoke --action lambda:invokeFunction --principal sns.amazonaws.com --region ... --source-arn arn:aws:sns:...

#2016-10-07 10:07:50.764975
+lambda add-permission --function-name hw-server --statement-id sns-invoke --action lambda:invokeFunction --principal sns.amazonaws.com --region ... --source-arn arn:aws:sns:...

it's adding + aws on my command so when I rerun the command it says there was an error because aws is not a choice option. The error says:
aws: error: argument command: Invalid choice, valid choices are: ... and then gives a list of the valid choices.

The last command in the command history was the one that worked and the first two commands returned the error.

@stuft2
Copy link
Author

stuft2 commented Oct 11, 2016

I believe this is a problem throughout all the shell and not just after making a typo. For example: I've noticed that when I've made a SNS topic, the command shell displays the ARN for the topic but then doesn't revert back to the origial aws> and instead I have to press return again (which displays and error telling me that I entered in something invalid) and then the aws> is finally displayed so I can begin to do something outside of just sns. I know it's not something huge but I'd like to see it fixed in the next version of aws-shell.

@donnemartin
Copy link
Collaborator

Hi @stuft2, thanks for the report!

When I make a typo in the aws-shell, it stores the command history in the history file incorrectly.

Just to clarify, it sounds like you are suggesting that aws-shell should only log your history if you execute a proper command, ignoring invalid commands?

For example: I've noticed that when I've made a SNS topic, the command shell displays the ARN for the topic but then doesn't revert back to the origial aws> and instead I have to press return again

I think this might be a separate issue, please feel free to submit a bug report if you agree.

@stuft2
Copy link
Author

stuft2 commented Oct 16, 2016

@donnemartin I feel like the aws-shell should log incorrect commands as well. That way you can go back and fix what you did wrong. However, the issue I'm seeing is that when I do make a typo, aws-shell logs the history incorrectly and so the following command (no matter what it is) is always wrong.

The aws-shell log file snippet that I posted above shows that when I made an incorrect command, it logged +aws at the beginning of the command. The final command that was logged in the snippet (the one that worked) did not log +aws and only longed from +lambda on. Did that help make the issue clearer? Thanks.

To add further clarity to the log file I posted above, the first log didn't work because I made a typo in lambda and spelled it lamda instead of lambda (aws-shell also logged the command incorrectly. It added a +aws to the front of the command); the second didn't work because I pressed my up arrow key, fixed the typo, and then the extra +aws made the command invalid (I didn't enter aws into the shell. That's the error that the log file made). The third log worked because I removed the extra aws from the command.

@stuft2
Copy link
Author

stuft2 commented Oct 16, 2016

I would consider this a bug but, at first glance, some may see it as a feature-request.

@donnemartin
Copy link
Collaborator

donnemartin commented Oct 20, 2016

Thanks for clarifying!

Seems I'm seeing something different, there does seem to be a bug somewhere.

Commands executed:

aws> aws
aws> aws s3 ls
aws> s3 ls
aws> ss3 ls

Contents of ~/.aws/shell/history

# 2016-10-19 20:34:03.570867
+aws

# 2016-10-19 20:34:47.883330
+aws s3 ls

# 2016-10-19 20:34:54.580947
+s3 ls

# 2016-10-19 20:34:56.878143
+ss3 ls

# 2016-10-19 20:37:04.129488
+.edit

Results shown after running .edit

aws aws aws
aws aws aws s3 ls
aws aws s3 ls
aws aws ss3 ls

@stuft2
Copy link
Author

stuft2 commented Oct 20, 2016

Yep, that looks like the same bug I'm finding too.

@joguSD
Copy link
Contributor

joguSD commented Oct 21, 2016

The file history (~/.aws/shell/history) logs the commands exactly as they are typed at the prompt, as this is passed to the prompt as the history object. I cannot replicate commands being prepended with 'aws' and then being stored into file history. This is the history that is used when you push the up arrow key.

In addition, there is an InMemoryHistory object that is separate from the FileHistory which is not attached to the prompt_toolkit prompt. Entries in the memory history are manually pushed after the 'aws' is prepended, so InMemoryHistory contains the full_cmd. When the EditHandler is executed it creates a temporary file based on the commands stored in the memory history and prepends 'aws' a second time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants