text in text editors gets scrambled after defining set_prompt












1















I've set set_prompt to print prompt always on a new line.



set_prompt() {
local curpos
stty -echo
while read -t 0; do :; done
echo -en "33[6n"
IFS=';' read -s -d R -a curpos
stty echo
(( curpos[1] > 1 )) && printf "n"
}


but now, if I edit a file in text editors like emacs or nano, the text gets scrambled like printing character at wrong place or cursor jumps ahead or back while navigating, making text overlap.





at this point



PS1=[]$(git rev-parse --git-dir > /dev/null 2>&1 && git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ${HOSTNAME})[]:[]W[] Necktwi[]$[]
PROMPT_COMMAND=set_prompt




Instead of setting the set_prompt, one can also do



PS1='$(printf "%$((COLUMNS-1))sr")'$PS1


but even this gives the glitch in emacs, not tested nano, but not as bad as the above. I was able to correct this much less scrambled text by deleting the generated spurious characters.










share|improve this question

























  • What is the value of your $PS1 and $PROMPT_COMMAND variables?

    – glenn jackman
    Jan 26 at 16:24











  • updated the question about them

    – neckTwi
    Jan 26 at 16:37











  • The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

    – glenn jackman
    Jan 26 at 16:56













  • I am curious about the purpose of that function. Why do you have it?

    – glenn jackman
    Jan 26 at 16:57











  • actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

    – neckTwi
    Jan 27 at 4:55
















1















I've set set_prompt to print prompt always on a new line.



set_prompt() {
local curpos
stty -echo
while read -t 0; do :; done
echo -en "33[6n"
IFS=';' read -s -d R -a curpos
stty echo
(( curpos[1] > 1 )) && printf "n"
}


but now, if I edit a file in text editors like emacs or nano, the text gets scrambled like printing character at wrong place or cursor jumps ahead or back while navigating, making text overlap.





at this point



PS1=[]$(git rev-parse --git-dir > /dev/null 2>&1 && git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ${HOSTNAME})[]:[]W[] Necktwi[]$[]
PROMPT_COMMAND=set_prompt




Instead of setting the set_prompt, one can also do



PS1='$(printf "%$((COLUMNS-1))sr")'$PS1


but even this gives the glitch in emacs, not tested nano, but not as bad as the above. I was able to correct this much less scrambled text by deleting the generated spurious characters.










share|improve this question

























  • What is the value of your $PS1 and $PROMPT_COMMAND variables?

    – glenn jackman
    Jan 26 at 16:24











  • updated the question about them

    – neckTwi
    Jan 26 at 16:37











  • The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

    – glenn jackman
    Jan 26 at 16:56













  • I am curious about the purpose of that function. Why do you have it?

    – glenn jackman
    Jan 26 at 16:57











  • actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

    – neckTwi
    Jan 27 at 4:55














1












1








1








I've set set_prompt to print prompt always on a new line.



set_prompt() {
local curpos
stty -echo
while read -t 0; do :; done
echo -en "33[6n"
IFS=';' read -s -d R -a curpos
stty echo
(( curpos[1] > 1 )) && printf "n"
}


but now, if I edit a file in text editors like emacs or nano, the text gets scrambled like printing character at wrong place or cursor jumps ahead or back while navigating, making text overlap.





at this point



PS1=[]$(git rev-parse --git-dir > /dev/null 2>&1 && git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ${HOSTNAME})[]:[]W[] Necktwi[]$[]
PROMPT_COMMAND=set_prompt




Instead of setting the set_prompt, one can also do



PS1='$(printf "%$((COLUMNS-1))sr")'$PS1


but even this gives the glitch in emacs, not tested nano, but not as bad as the above. I was able to correct this much less scrambled text by deleting the generated spurious characters.










share|improve this question
















I've set set_prompt to print prompt always on a new line.



set_prompt() {
local curpos
stty -echo
while read -t 0; do :; done
echo -en "33[6n"
IFS=';' read -s -d R -a curpos
stty echo
(( curpos[1] > 1 )) && printf "n"
}


but now, if I edit a file in text editors like emacs or nano, the text gets scrambled like printing character at wrong place or cursor jumps ahead or back while navigating, making text overlap.





at this point



PS1=[]$(git rev-parse --git-dir > /dev/null 2>&1 && git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ${HOSTNAME})[]:[]W[] Necktwi[]$[]
PROMPT_COMMAND=set_prompt




Instead of setting the set_prompt, one can also do



PS1='$(printf "%$((COLUMNS-1))sr")'$PS1


but even this gives the glitch in emacs, not tested nano, but not as bad as the above. I was able to correct this much less scrambled text by deleting the generated spurious characters.







bash prompt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 28 at 3:01







neckTwi

















asked Jan 26 at 10:44









neckTwineckTwi

3413615




3413615













  • What is the value of your $PS1 and $PROMPT_COMMAND variables?

    – glenn jackman
    Jan 26 at 16:24











  • updated the question about them

    – neckTwi
    Jan 26 at 16:37











  • The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

    – glenn jackman
    Jan 26 at 16:56













  • I am curious about the purpose of that function. Why do you have it?

    – glenn jackman
    Jan 26 at 16:57











  • actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

    – neckTwi
    Jan 27 at 4:55



















  • What is the value of your $PS1 and $PROMPT_COMMAND variables?

    – glenn jackman
    Jan 26 at 16:24











  • updated the question about them

    – neckTwi
    Jan 26 at 16:37











  • The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

    – glenn jackman
    Jan 26 at 16:56













  • I am curious about the purpose of that function. Why do you have it?

    – glenn jackman
    Jan 26 at 16:57











  • actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

    – neckTwi
    Jan 27 at 4:55

















What is the value of your $PS1 and $PROMPT_COMMAND variables?

– glenn jackman
Jan 26 at 16:24





What is the value of your $PS1 and $PROMPT_COMMAND variables?

– glenn jackman
Jan 26 at 16:24













updated the question about them

– neckTwi
Jan 26 at 16:37





updated the question about them

– neckTwi
Jan 26 at 16:37













The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

– glenn jackman
Jan 26 at 16:56







The purpose of the [ and ] are to contain non-printing characters. If there is nothing in between them, they are useless, so you can tidy up your PS1. You need to add them to the set_prompt funtion: echo -en "[33[6n]"

– glenn jackman
Jan 26 at 16:56















I am curious about the purpose of that function. Why do you have it?

– glenn jackman
Jan 26 at 16:57





I am curious about the purpose of that function. Why do you have it?

– glenn jackman
Jan 26 at 16:57













actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

– neckTwi
Jan 27 at 4:55





actually, there is a color code between []. echo -en "[33[6n]" is printing [] before the prompt.

– neckTwi
Jan 27 at 4:55










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%2f496849%2ftext-in-text-editors-gets-scrambled-after-defining-set-prompt%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%2f496849%2ftext-in-text-editors-gets-scrambled-after-defining-set-prompt%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

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?