Giter Site home page Giter Site logo

Comments (19)

silverwind avatar silverwind commented on August 22, 2024

Interesting. What does process.env.TERM end up being when you see the ANSI codes and which shell and OS is this on?

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024
  • TERM=xterm-256color
  • shell: bash

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Pushed sindresorhus/shell-path@1703975, can you give that one a try?

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Note: I don't understand what \u001b(B\u001b[m does, but I guess it won't hurt if we strip it. Maybe @Qix- has some insight?

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024

Note: I don't understand what \u001b(B\u001b[m does

Neither do I :).

Will try it tomorrow, just closed my laptop but guess it'll work as strip-ansi was the hotfix I used in my code.

from fix-path.

sindresorhus avatar sindresorhus commented on August 22, 2024

Couldn't we just disable colors by for example changing echo "$PATH" to something like TERM=dumb; echo "$PATH"?

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024

The less dependencies, the better. Will try it out tomorrow!

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024

Couldn't resist, had to know :).

Tried this:

function pathFromSudoSync() {
    try {
        return childProcess.execSync('TERM=dumb; sudo -Hiu ' + user + ' echo "$PATH"', opts).trim();
    } catch (err) {
        // may fail with 'sudo: must be setuid root'
        return '';
    }
}

But still returns a string with color codes. This is the .bash_prompt I use btw. Maybe this offers some more insights.

from fix-path.

Qix- avatar Qix- commented on August 22, 2024

Not sure what (B is but [m is analogous to [0m. I don't think it's standard.

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Pretty sure that \u001b(B\u001b[m has nothing to do with color at least.

$ node -e 'console.log("\u001b(B\u001b[mHi!")'
Hi!

from fix-path.

Qix- avatar Qix- commented on August 22, 2024

[0m (or [m) means reset render. \u001b(B seems strange. I'll have to research. I can take a look later; my attention is on the mass shooting right now, heh.

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024

I did some more investigation in the dot-file. It's actually this line that is the cause of all this.

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Googling the first three bytes 0x1B 0x28 0x42 tells me it's some kind of japanese escape sequence?

http://www.sxemacs.org/docs/internals/JIS7.html

     Escape sequence   ASCII equivalent   Meaning
     ---------------   ----------------   -------
     0x1B 0x28 0x4A    ESC ( J            invoke Japanese-JISX0201-Roman
     0x1B 0x28 0x49    ESC ( I            invoke Japanese-JISX0201-Kana
     0x1B 0x24 0x42    ESC $ B            invoke Japanese-JISX0208
     0x1B 0x28 0x42    ESC ( B            invoke Printing-ASCII

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Confirming it's the output of tput sgr0, which appears to be a color reset that also seems to reset japanese terminals to regular ASCII mode. I still think my fix is worth to keep, as TERM=dumb does probably not take care of \u001b(B.

> child_process.execSync('tput sgr0', {encoding: 'utf8'})
'\u001b(B\u001b[m'

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

TERM=dumb does remove both sequences for me on both OSX and Linux. Now if only I could get this execSync to work 😕

> child_process.execSync("tput sgr0", {encoding: 'utf8', env: process.env})
'\u001b(B\u001b[m'
> process.env.TERM = 'dumb'
'dumb'
> child_process.execSync("tput sgr0", {encoding: 'utf8', env: process.env})
Error: Command failed: tput sgr0

from fix-path.

SamVerschueren avatar SamVerschueren commented on August 22, 2024

When executing that I noticed the shell of child_process is sh. Tried changing that to bash but didn't seem to work either.

from fix-path.

Qix- avatar Qix- commented on August 22, 2024

That's not uncommon, unless you specifically invoke the shell of your choice, you're going to get /bin/sh.

from fix-path.

silverwind avatar silverwind commented on August 22, 2024

Won't matter in which shell that sudo executes. The -i option does "run the shell specified by the target user's password database entry as a login shell".

from fix-path.

sindresorhus avatar sindresorhus commented on August 22, 2024

Just realized I never published the strip-ansi workaround. Done now. Keeping this issue open as I'd still like to find a better fix. Open to additional suggestions.

from fix-path.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.