Reputation: 53803
I have a function that returns a command as a string. How do I pass this command to the next prompt as a string without executing it.
For example:
Function commandGenerator
returns cd ~/some_dir/
as a string. Now I execute commandGenerator
in my terminal:
> commandGenerator
> cd ~/some_dir/
^
Cursor position after execution of commandGenerator.
I can now edit the command or hit enter to execute it.
Upvotes: 3
Views: 164
Reputation: 531155
The -z
option to the built-in print
command writes text to the command buffer.
% print -z "cd ~/some_dir/"
% cd ~/some_dir
You can call this from within your commandGenerator
function. When the function exits, the next command line will be populated with the text printed by print -z
.
Upvotes: 4