xdotool type and stty occasionally cut off first letter of input












0















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
}









share|improve this question


















  • 1





    I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

    – egmont
    Jan 9 at 22:07











  • @egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

    – SWV
    Jan 10 at 0:42













  • Use the ioctl TIOCSTI to stuff data into the input. See here.

    – meuh
    Jan 10 at 18:15
















0















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
}









share|improve this question


















  • 1





    I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

    – egmont
    Jan 9 at 22:07











  • @egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

    – SWV
    Jan 10 at 0:42













  • Use the ioctl TIOCSTI to stuff data into the input. See here.

    – meuh
    Jan 10 at 18:15














0












0








0








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
}









share|improve this question














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
}






terminal xdotool






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 9 at 21:16









SWVSWV

11




11








  • 1





    I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

    – egmont
    Jan 9 at 22:07











  • @egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

    – SWV
    Jan 10 at 0:42













  • Use the ioctl TIOCSTI to stuff data into the input. See here.

    – meuh
    Jan 10 at 18:15














  • 1





    I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

    – egmont
    Jan 9 at 22:07











  • @egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

    – SWV
    Jan 10 at 0:42













  • Use the ioctl TIOCSTI to stuff data into the input. See here.

    – meuh
    Jan 10 at 18:15








1




1





I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

– egmont
Jan 9 at 22:07





I'm not aware of a proper solution, however, your hack is quite fragile. E.g. if you have another window (let's say a browser) focused when a terminal command completes, you'll end up "typing" into that window. On a side note: the "set" command doesn't do what you think it does. For your actual problem: you might inject a few "sleep 0.1"s into PROMPT_COMMAND and see if that helps, I have no clue why the first letter could be swallowed.

– egmont
Jan 9 at 22:07













@egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

– SWV
Jan 10 at 0:42







@egmont Thank you. Beyond the window focus, are there other major use-cases I should consider to make the function more robust?

– SWV
Jan 10 at 0:42















Use the ioctl TIOCSTI to stuff data into the input. See here.

– meuh
Jan 10 at 18:15





Use the ioctl TIOCSTI to stuff data into the input. See here.

– meuh
Jan 10 at 18:15










0






active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493555%2fxdotool-type-and-stty-occasionally-cut-off-first-letter-of-input%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493555%2fxdotool-type-and-stty-occasionally-cut-off-first-letter-of-input%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre