Skip to content

Commit

Permalink
[env-manager] ensure run works on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Feb 7, 2024
1 parent a383939 commit 538d6e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions env-manager/src/main/java/io/yupiik/dev/command/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public Env(final Conf conf, final Os os, final RcService rc, final MessageHelper

@Override
public void run() {
final var windows = os.isWindows() && System.getenv("TERM") == null /* if not null behave as bash */;
final var hasTerm = os.isUnixLikeTerm();
final var windows = os.isWindows() && hasTerm /* if not null behave as bash */;
final var export = windows ? "set " : "export ";
final var comment = windows ? "%% " : "# ";
final var pathName = windows ? "Path" : "PATH";
Expand Down Expand Up @@ -113,12 +114,13 @@ public void close() throws SecurityException {
final var pathBase = ofNullable(System.getenv("YEM_ORIGINAL_PATH"))
.or(() -> ofNullable(System.getenv(pathName)))
.orElse("");
final var pathsSeparator = hasTerm ? ":" : pathSeparator;
final var pathVars = resolved.stream().map(RcService.MatchedPath::properties).anyMatch(RcService.ToolProperties::addToPath) ?
export + "YEM_ORIGINAL_PATH=" + quote + pathBase + quote + ";\n" +
export + pathName + "=" + quote + resolved.stream()
.filter(r -> r.properties().addToPath())
.map(r -> quoted(rc.toBin(r.path())))
.collect(joining(pathSeparator, "", pathSeparator)) + pathVar + quote + ";\n" :
.collect(joining(pathsSeparator, "", pathsSeparator)) + pathVar + quote + ";\n" :
"";
final var home = System.getProperty("user.home", "");
final var echos = Boolean.parseBoolean(tools.getProperty("echo", "true")) ?
Expand Down
2 changes: 1 addition & 1 deletion env-manager/src/main/java/io/yupiik/dev/command/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void run() {
Stream.of(""),
Stream.ofNullable(ofNullable(System.getenv("PathExt"))
.orElseGet(() -> System.getenv("PATHEXT")))
.map(i -> Stream.of(i.split(";"))
.flatMap(i -> Stream.of(i.split(";"))
.map(String::strip)
.filter(Predicate.not(String::isBlank))))
.toList() :
Expand Down
4 changes: 4 additions & 0 deletions env-manager/src/main/java/io/yupiik/dev/shared/Os.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ public boolean isAarch64() {
public boolean isWindows() {
return "windows".equals(findOs());
}

public boolean isUnixLikeTerm() {
return System.getenv("TERM") != null;
}
}

0 comments on commit 538d6e8

Please sign in to comment.