I'm trying to replicate the behavior of the history builtin: specifically when you do !<line # of command> and it's just replaced with the command at line #.
Let's say that I have a file with the following contents:
cd ~/some/path
I would like to be able to take the contents of that file and have that pushed into the current terminal input line as such:
$ ./put_to_input file
$ cd ~/some/path # pulled from the file, not manually typed
Not sure if this is possible. Help would be appreciated!
Clarification:
I want to put the lines of the file into the terminal input, as if the person had typed it themselves. Similar to if you use the
!nshell history substitution. https://opensource.com/article/18/6/history-command
!nshell history substitution. opensource.com/article/18/6/history-command~/.inputrcto assign a shortcut. For example, try adding this to your~/.inputrcfile (create it if it doesn't exist):Control-P: cd ~/some/path. Then, open a new terminal and press Ctrl+P, and the text will appear on your prompt. Is that a decent workaround?print -z $(cat runfile). Thanks! Used it to build this: github.com/slin63/rich-history