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
!n
shell history substitution. https://opensource.com/article/18/6/history-command
!n
shell history substitution. https://opensource.com/article/18/6/history-command – puppydog May 08 '20 at 17:31~/.inputrc
to assign a shortcut. For example, try adding this to your~/.inputrc
file (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? – terdon May 08 '20 at 18:03print -z $(cat runfile)
. Thanks! Used it to build this: https://github.com/slin63/rich-history – puppydog May 08 '20 at 19:46