Search code examples
bashzsh

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.


Solution

  • 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.