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

Random sleep after each command #14

Open
zeroXten opened this issue Apr 1, 2014 · 4 comments
Open

Random sleep after each command #14

zeroXten opened this issue Apr 1, 2014 · 4 comments

Comments

@zeroXten
Copy link

zeroXten commented Apr 1, 2014

Add this to .bashrc etc

export PROMPT_COMMAND='sleep $(($RANDOM % ($(($RANDOM % 9))+1)))'

This will sleep for up to 10 seconds, weighted to lower values:

$ for i in {1..10000}; do echo $(($RANDOM % ($(($RANDOM % 9))+1))); done | sort | uniq -c
3088 0
1999 1
1577 2
1114 3
832 4
590 5
419 6
272 7
109 8

@bkhouri
Copy link

bkhouri commented Feb 15, 2019

This would need to support if the user already have a PROMPT_COMMENT function defined, so to not give any indication that something is awry.

@zeroXten
Copy link
Author

zeroXten commented Feb 16, 2019

Something like this then?
export PROMPT_COMMAND="sleep $(($RANDOM % ($(($RANDOM % 9))+1))); $PROMPT_COMMAND"

@benaryorg
Copy link
Collaborator

benaryorg commented Mar 2, 2019

If you want the "${RANDOM}" to be re-evaluated on every invocation you'll need an extra layer of quotation.

@benaryorg
Copy link
Collaborator

benaryorg commented Mar 2, 2019

Furthermore you might want to consider using "${PROMT_COMMAND[@]}" instead to preserve arguments with spaces properly.
Edit: that would require closing the quotes after semicolon and then inserting the fancy variant.
I mean.… this wouldn't make much difference for 99% of all people, but if some defined their PROMPT_COMMAND as an array, which may or may not be legal, no idea, then this will preserve behaviour. Somehow. Maybe.

Maybe I'm just overthinking this and you can leave it as is (except for the above thing, about re-evaluating properly, which would easily be solved by single quotes and then appending the command by closing the single quotes and starting new double quotes, oh how I hate shells.…)

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

No branches or pull requests

3 participants