[{"data":1,"prerenderedAt":244},["ShallowReactive",2],{"post:escape-ansi-sequences":3},{"id":4,"title":5,"body":6,"date":232,"description":233,"draft":234,"extension":235,"meta":236,"navigation":237,"path":238,"seo":239,"stem":240,"tags":241,"__hash__":243},"posts\u002Fposts\u002Fescape-ansi-sequences.md","TIL: Escape ANSI Sequences in Bash",{"type":7,"value":8,"toc":226},"minimark",[9,26,40,45,54,58,61,88,92,95,116,120,123,213,222],[10,11,12,13,20,21,25],"p",{},"So after writing ",[14,15,19],"a",{"href":16,"rel":17},"https:\u002F\u002Fgithub.com\u002Fmborn319\u002Ftoday-i-learned\u002Fblob\u002Fmaster\u002Fbash\u002Fmake-a-custom-shell-prompt.md",[18],"nofollow","all about my fancy new shell prompt",", I had to adjust it a little. I knew I'd gotten it wrong when I started seeing my shell commands wrap ",[22,23,24],"strong",{},"before they reached the end of the window",".",[10,27,28,29,34,35,25],{},"A few Google searches found me, as always, in a Stack Overflow article: ",[14,30,33],{"href":31,"rel":32},"https:\u002F\u002Funix.stackexchange.com\u002Fquestions\u002F105958\u002Fterminal-prompt-not-wrapping-correctly",[18],"\"Terminal Prompt Not Wrapping Correctly\"",", which had the ",[14,36,39],{"href":37,"rel":38},"https:\u002F\u002Funix.stackexchange.com\u002Fa\u002F105974",[18],"solution enclosed",[41,42,44],"h2",{"id":43},"escape-your-ansi-escape-codes","Escape your ANSI Escape Codes!",[10,46,47,48,53],{},"Apparantely, despite being called ",[14,49,52],{"href":50,"rel":51},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FANSI_escape_code",[18],"ANSI \"Escape\" Codes",", you still need to escape these babies or weird things will happen.",[41,55,57],{"id":56},"my-original-shell-prompt","My Original Shell Prompt",[10,59,60],{},"Here's what I originally had for my shell prompt.",[62,63,68],"pre",{"className":64,"code":65,"language":66,"meta":67,"style":67},"language-bash shiki shiki-themes github-light github-dark","PS1=\"\\033[0;31m$ \\e[0m\"\n","bash","",[69,70,71],"code",{"__ignoreMap":67},[72,73,76,80,84],"span",{"class":74,"line":75},"line",1,[72,77,79],{"class":78},"sVt8B","PS1",[72,81,83],{"class":82},"szBVR","=",[72,85,87],{"class":86},"sZZnC","\"\\033[0;31m$ \\e[0m\"\n",[41,89,91],{"id":90},"correctly-escaping-the-color-codes","Correctly Escaping the Color Codes",[10,93,94],{},"Here's the \"proper\", correctly escaped prompt. Notice I also escaped the dollar sign!",[62,96,98],{"className":64,"code":97,"language":66,"meta":67,"style":67},"PS1=\"\\[\\033[0;31m\\]\\$ \\[\\e[0m\\]\"\n",[69,99,100],{"__ignoreMap":67},[72,101,102,104,106,109,113],{"class":74,"line":75},[72,103,79],{"class":78},[72,105,83],{"class":82},[72,107,108],{"class":86},"\"\\[\\033[0;31m\\]",[72,110,112],{"class":111},"sj4cs","\\$",[72,114,115],{"class":86}," \\[\\e[0m\\]\"\n",[41,117,119],{"id":118},"fancier-colors","Fancier Colors",[10,121,122],{},"I decided to add the CWD, or Current Working Directory, back in to my prompt. Context is key! While I was at it, I moved the color codes into variables so the prompt can be more easily read. Here's the result.",[62,124,126],{"className":64,"code":125,"language":66,"meta":67,"style":67},"PURPLE=\"\\033[0;31m\"\nRED=\"\\033[0;35m\"\nDIR=\"\\W\"\nCOLOR_RESET=\"\\[\\e[m\"\nPS1=\"\\[$PURPLE\\]$DIR\\[$COLOR_RESET\\]\\[$RED\\]\\$\\[$COLOR_RESET\\] \"\n",[69,127,128,138,149,160,171],{"__ignoreMap":67},[72,129,130,133,135],{"class":74,"line":75},[72,131,132],{"class":78},"PURPLE",[72,134,83],{"class":82},[72,136,137],{"class":86},"\"\\033[0;31m\"\n",[72,139,141,144,146],{"class":74,"line":140},2,[72,142,143],{"class":78},"RED",[72,145,83],{"class":82},[72,147,148],{"class":86},"\"\\033[0;35m\"\n",[72,150,152,155,157],{"class":74,"line":151},3,[72,153,154],{"class":78},"DIR",[72,156,83],{"class":82},[72,158,159],{"class":86},"\"\\W\"\n",[72,161,163,166,168],{"class":74,"line":162},4,[72,164,165],{"class":78},"COLOR_RESET",[72,167,83],{"class":82},[72,169,170],{"class":86},"\"\\[\\e[m\"\n",[72,172,174,176,178,181,184,187,190,193,196,199,202,204,206,208,210],{"class":74,"line":173},5,[72,175,79],{"class":78},[72,177,83],{"class":82},[72,179,180],{"class":86},"\"\\[",[72,182,183],{"class":78},"$PURPLE",[72,185,186],{"class":86},"\\]",[72,188,189],{"class":78},"$DIR",[72,191,192],{"class":86},"\\[",[72,194,195],{"class":78},"$COLOR_RESET",[72,197,198],{"class":86},"\\]\\[",[72,200,201],{"class":78},"$RED",[72,203,186],{"class":86},[72,205,112],{"class":111},[72,207,192],{"class":86},[72,209,195],{"class":78},[72,211,212],{"class":86},"\\] \"\n",[10,214,215,216,218,219,221],{},"Notice the begin and ending escape characters ",[69,217,192],{}," and ",[69,220,186],{}," around each color variable.",[223,224,225],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":67,"searchDepth":140,"depth":140,"links":227},[228,229,230,231],{"id":43,"depth":140,"text":44},{"id":56,"depth":140,"text":57},{"id":90,"depth":140,"text":91},{"id":118,"depth":140,"text":119},"2018-04-30T09:10:57-04:00","So after writing all about my fancy new shell prompt, I had to adjust it a little. I knew I'd gotten it wrong when I started seeing my shell commands wrap before they reached the end of the window.",false,"md",{},true,"\u002Fposts\u002Fescape-ansi-sequences",{"title":5,"description":233},"posts\u002Fescape-ansi-sequences",[66,242],"til","95aMDqXbB6cr3G5cIZxUMvO1ZcgUywFzVyZxC8rnInw",1790471528230]