Skip to content

Commit e37c743

Browse files
Merge pull request #60 from dnicolson/improve-path-support
Improve path support
2 parents 8aa43f1 + a91a4ec commit e37c743

File tree

1 file changed

+2
-26
lines changed

1 file changed

+2
-26
lines changed

main.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sublime, sublime_plugin
2-
import os, platform, shutil, tempfile, json, re, sys
2+
import os, platform, shutil, tempfile, json, re, sys, shellenv
33
from subprocess import Popen, PIPE
44
from .src.libs.global_vars import *
55
from .src.libs import util
@@ -111,32 +111,8 @@ def start():
111111
fixPathSettings = None
112112
fixPathOriginalEnv = {}
113113

114-
def getSysPath():
115-
command = ""
116-
if platform.system() == "Darwin":
117-
command = "env TERM=ansi CLICOLOR=\"\" SUBLIME=1 /usr/bin/login -fqpl $USER $SHELL -l -c 'TERM=ansi CLICOLOR=\"\" SUBLIME=1 printf \"%s\" \"$PATH\"'"
118-
elif platform.system() == "Linux":
119-
command = "env TERM=ansi CLICOLOR=\"\" SUBLIME=1 $SHELL --login -c 'TERM=ansi CLICOLOR=\"\" printf \"%s\" $PATH'"
120-
else:
121-
return ""
122-
123-
# Execute command with original environ. Otherwise, our changes to the PATH propogate down to
124-
# the shell we spawn, which re-adds the system path & returns it, leading to duplicate values.
125-
sysPath = Popen(command, stdout=PIPE, shell=True, env=fixPathOriginalEnv).stdout.read()
126-
127-
# this line fixes problems of users having an "echo" command in the .bash_profile file or in other similar files.
128-
sysPath = sysPath.splitlines()[-1]
129-
130-
sysPathString = sysPath.decode("utf-8")
131-
# Remove ANSI control characters (see: http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed )
132-
sysPathString = re.sub(r'\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]', '', sysPathString)
133-
sysPathString = sysPathString.strip().rstrip(':')
134-
135-
# Decode the byte array into a string, remove trailing whitespace, remove trailing ':'
136-
return sysPathString
137-
138114
def fixPath():
139-
currSysPath = getSysPath()
115+
currSysPath = ':'.join(shellenv.get_path()[1])
140116
# Basic sanity check to make sure our new path is not empty
141117
if len(currSysPath) < 1:
142118
return False

0 commit comments

Comments
 (0)