0

i am actually programming a script where i can store commands in a cheatsheet (e.g. "git add .", "git merge", "docker compose-up" ....) - all commands that i need in my daily work.

see here: https://github.com/m1well/cheatsheet

now i have a question: is it possible to copy a command into the command line without any additional installations?

my actual idea is to implement it like the shell history -> add a number before each command and then i want to call it like this
$ my-script.sh -c 5
Where -c stands for command parameter (if have several parameters already implemented) and the 5 stands for the command in line 5.

TL;DR: is it possible to copy a line from a file to the command line and then execute it by clicking enter?

1 Answer 1

0

That depends on the OS. For Unix/Linux here are some suggestions how to stuff some string into the input buffer. Windows is of course different.

A completly different approach based on bash only is using something like this: Type these command into the bash prompt:

foo() {
    READLINE_LINE="execute me"
    READLINE_POINT=${#READLINE_LINE}
}
bind -x '"\ex": foo'

Now you can type Alt+x (the \ex part int the code) and current input line is replaced with execute me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .