I am using this in my vscode-yo plugin and noticed something strange. I upgraded some dotfiles of today and since then, the plugin wasn't showing any generators anymore. After investigating this, ANSI color codes where added in front of the path.
console.log(process.env.PATH.split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
require('fix-path')();
console.log(process.env.PATH.split(path.delimiter));
//=> [ '\u001b(B\u001b[m/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
After some more investigation, it seems that these lines in my dot-files trigger this behaviour.
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color';
fi;
If I remove these lines, the ANSI code is not added.
Fix
A simple fix is strip-ansi
require('fix-path')();
console.log(stripAnsi(process.env.PATH).split(path.delimiter));
//=> [ '/Users/sam/.nvm/versions/node/v4.2.1/bin', '/usr/local/bin', ...]
But maybe, this should be fixed somewhere deeper in the chain. After digging into with fix-path
does, I came to this line 72 in shell-path/index.js
. This is the line that returns the path with the ANSI color codes.