2

I know you can simply put what you'd like to run:

func()
{
    cd scripts
    ./excellent/script
}

but, what I'd like to do instead is have ./excellent/script be put in my commandline without being entered. This way when I run func it puts what I need there and waits until I'm ready; think presentations:

$ func
$ ./excellent/script
mcp
  • 717

2 Answers2

2

This will basically accomplish it. What's really happening is that the command line prompt is just a fake one, but whatever you enter it executes right away, so it might as well be a real command prompt.

func() {
    cd scripts
    read -e -p '$ ' -i './excellent/script' command
    eval $command
}

If your prompt is more complicated than $ , to make it look right, you might need to remove -p '$ ' and add a line echo -ne "[whatever] " or similar before the read line.

frabjous
  • 8,691
0

If you're using readline (say, with bash), you could tie a keystroke to a simple function that assigns the value of the text:

bind -x '"\C-T": READLINE_LINE=./excellent/script'

This simply clobbers the current commandline (input) with the given text as soon as you hit Controlt. The downside of this idea is running out of keyboard shortcuts if you have multiple examples you want to prepare.

Inspired by mosvy's answer here.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255