I defined a simple function prepend
(below) that should automatically place a repeated term of a bash command in the following input prompts. For example, by typing prepend git
in the terminal, all following inputs should have git
already entered. For the most part, prepend
does this; however, seemingly at random, prepend
will cut off the first letter of the word (e.g. $prepend sensors
yields $ensors
on the following input prompt).
I was wondering why this is happening and how to possibly fix it. However, if there's an alternative/canonical way to have text entered into input prompts, I wouldn't mind implementing this differently.
#!/bin/bash
#stty to stop text from being displayed before $PS1
function prepend {
if ! [ -z "$1" ]
then
PROMPT_COMMAND="stty -echo && xdotool type $1 && stty echo"
set PROMPT_COMMAND
else
unset PROMPT_COMMAND
fi
}
TIOCSTI
to stuff data into the input. See here. – meuh Jan 10 '19 at 18:15