Aaron Shen
Aaron Shen

Reputation: 8374

zsh programmatically populate command content

I'm writing myself a script to optimize workflow. I want to populate the command programmatically, e.g. if I run myscript, I want it to prepopulate a string "this is great" in the next prompt:

% myscript
% this is great

Is this possible? I'm using zsh, but it'll be better if this can be achieved using common bash commands.

Upvotes: 1

Views: 342

Answers (1)

chepner
chepner

Reputation: 530813

The print command takes a -z option that does what you want:

% print -z hi
% hi

Note, though, this only works within a single shell instance. If you include this in a script, you'll have to source the script:

% . myscript
% hi

not execute it in a separate process

% zsh myscript
%

I'm unaware of any equivalent functionality in bash.

Upvotes: 2

Related Questions