Implement ability to disable shell history

This commit is contained in:
Christopher Schnick 2023-01-04 20:33:54 +01:00
parent 5dcb994f9b
commit f0eccfb17b
2 changed files with 18 additions and 0 deletions

View file

@ -3,6 +3,7 @@ package io.xpipe.core.process;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import io.xpipe.core.charsetter.NewLine;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
@ -32,6 +33,8 @@ public interface ShellType {
.collect(Collectors.joining(" "));
}
void disableHistory(ShellProcessControl pc) throws Exception;
default String getExitCommand() {
return "exit";
}

View file

@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
import lombok.Value;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@ -105,6 +106,10 @@ public class ShellTypes {
return "@echo off\n" + content;
}
@Override
public void disableHistory(ShellProcessControl pc) throws IOException {
}
@Override
public String getExitCodeVariable() {
return "errorlevel";
@ -212,6 +217,11 @@ public class ShellTypes {
@Value
public static class PowerShell implements ShellType {
@Override
public void disableHistory(ShellProcessControl pc) throws Exception {
pc.executeCommand("Set-PSReadLineOption -HistorySaveStyle SaveNothing");
}
@Override
public String addInlineVariablesToCommand(Map<String, String> variables, String command) {
var content = "";
@ -449,6 +459,11 @@ public class ShellTypes {
return "echo " + prefix + "$" + name;
}
@Override
public void disableHistory(ShellProcessControl pc) throws Exception {
pc.executeCommand("unset HISTFILE");
}
@Override
public String getExitCommand() {
return "exit 0";