Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/dev/jbang/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public static Path getConfigDir(boolean init) {
if (jd != null) {
dir = Paths.get(jd);
} else {
dir = Paths.get(System.getProperty("user.home")).resolve(".jbang");
// On Windows, USERPROFILE is more reliable than user.home for non-ASCII
// usernames
String home = Util.isWindows()
? System.getenv().getOrDefault("USERPROFILE", System.getProperty("user.home"))
: System.getProperty("user.home");
dir = Paths.get(home).resolve(".jbang");
}

if (init)
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/dev/jbang/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static dev.jbang.util.JavaUtil.defaultJdkManager;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -480,7 +481,18 @@ public static int setup(boolean withJava, boolean force, boolean chatty) {
}
}
if (!cmd.isEmpty()) {
System.out.println(cmd);
if (Util.isWindows() && Util.getShell() == Util.Shell.powershell) {
try {
Path tmpFile = Files.createTempFile("jbang-setup-", ".ps1");
tmpFile.toFile().deleteOnExit();
Files.write(tmpFile, cmd.getBytes(StandardCharsets.UTF_8));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does seem right - shouldn't need to write to a tempfile to get UTF_8 string.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you mean "does not seem right"? (I agree)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Not right.

System.out.println(tmpFile.toAbsolutePath().toString());
} catch (IOException e) {
System.out.println(cmd);
}
} else {
System.out.println(cmd);
}
return EXIT_EXECUTE;
} else {
return EXIT_OK;
Expand Down
Loading