mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-22 07:30:24 +00:00
More fixes for mac
This commit is contained in:
parent
ded82617e6
commit
fd05f9bb0f
4 changed files with 89 additions and 54 deletions
|
@ -40,7 +40,7 @@ public abstract class ExternalApplicationType implements PrefsChoiceValue {
|
|||
try (ShellProcessControl pc = ShellStore.local().create().start()) {
|
||||
try (var c = pc.command(String.format("osascript -e 'POSIX path of (path to application \"%s\")'", applicationName)).start()) {
|
||||
var path = c.readOnlyStdout();
|
||||
if (!c.waitFor()) {
|
||||
if (c.getExitCode() != 0) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(Path.of(path));
|
||||
|
|
21
dist/licenses/zshi.license
vendored
Normal file
21
dist/licenses/zshi.license
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2020 Roman Perepelitsa
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
4
dist/licenses/zshi.properties
vendored
Normal file
4
dist/licenses/zshi.properties
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
name=zshi
|
||||
version=1.0
|
||||
license=MIT License
|
||||
link=https://github.com/romkatv/zshi
|
|
@ -1,7 +1,6 @@
|
|||
package io.xpipe.extension.util;
|
||||
|
||||
import io.xpipe.core.impl.FileNames;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.process.ShellProcessControl;
|
||||
import io.xpipe.core.process.ShellType;
|
||||
import io.xpipe.core.process.ShellTypes;
|
||||
|
@ -16,7 +15,8 @@ import java.util.Random;
|
|||
public class ScriptHelper {
|
||||
|
||||
public static int getScriptId() {
|
||||
// A deterministic approach can cause permission problems when two different users execute the same command on a system
|
||||
// A deterministic approach can cause permission problems when two different users execute the same command on a
|
||||
// system
|
||||
// Therefore, use a random approach
|
||||
return new Random().nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
@ -51,7 +51,15 @@ public class ScriptHelper {
|
|||
local rc
|
||||
for rc in .zshenv .zprofile .zshrc .zlogin; do
|
||||
>$tmp/$rc <<<'{
|
||||
if (( ${+_zshi_global_rcs} )); then
|
||||
"builtin" "set" "-o" "global_rcs"
|
||||
"builtin" "unset" "_zshi_global_rcs"
|
||||
fi
|
||||
ZDOTDIR="$_zshi_zdotdir"
|
||||
# Not .zshenv because /etc/zshenv has already been read
|
||||
if [[ -o global_rcs && "'$rc'" != ".zshenv" && -f "/etc/'${rc:1}'" && -r "/etc/'${rc:1}'" ]]; then
|
||||
"builtin" "source" "--" "/etc/'${rc:1}'"
|
||||
fi
|
||||
if [[ -f "$ZDOTDIR/'$rc'" && -r "$ZDOTDIR/'$rc'" ]]; then
|
||||
"builtin" "source" "--" "$ZDOTDIR/'$rc'"
|
||||
fi
|
||||
|
@ -60,10 +68,17 @@ public class ScriptHelper {
|
|||
-o "login" && "'$rc'" == ".zlogin" ||
|
||||
-o "no_login" && "'$rc'" == ".zshrc" ||
|
||||
-o "no_login" && -o "no_interactive" && "'$rc'" == ".zshenv" ]]; then
|
||||
if (( ${+_zshi_global_rcs} )); then
|
||||
set -o global_rcs
|
||||
fi
|
||||
"builtin" "unset" "_zshi_rcs" "_zshi_zdotdir"
|
||||
"builtin" "command" "rm" "-rf" "--" '${(q)tmp}'
|
||||
"builtin" "eval" '${(q)init}'
|
||||
else
|
||||
if [[ -o global_rcs ]]; then
|
||||
_zshi_global_rcs=
|
||||
fi
|
||||
set -o no_global_rcs
|
||||
_zshi_zdotdir=${ZDOTDIR:-~}
|
||||
ZDOTDIR='${(q)tmp}'
|
||||
fi
|
||||
|
@ -76,18 +91,17 @@ public class ScriptHelper {
|
|||
} "$@"
|
||||
""";
|
||||
|
||||
public static String constructOpenWithInitScriptCommand(ShellProcessControl processControl, List<String> init, String toExecuteInShell) {
|
||||
public static String constructOpenWithInitScriptCommand(
|
||||
ShellProcessControl processControl, List<String> init, String toExecuteInShell) {
|
||||
ShellType t = processControl.getShellType();
|
||||
if (init.size() == 0 && toExecuteInShell == null) {
|
||||
return t.getNormalOpenCommand();
|
||||
}
|
||||
|
||||
String nl = t.getNewLine().getNewLineString();
|
||||
var content = String.join(nl, init)
|
||||
+ nl;
|
||||
var content = String.join(nl, init) + nl;
|
||||
|
||||
if (processControl.getOsType().equals(OsType.LINUX)
|
||||
|| processControl.getOsType().equals(OsType.MAC)) {
|
||||
if (t.equals(ShellTypes.BASH)) {
|
||||
content = "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n" + content;
|
||||
}
|
||||
|
||||
|
@ -101,7 +115,7 @@ public class ScriptHelper {
|
|||
|
||||
if (t.equals(ShellTypes.ZSH)) {
|
||||
var zshiFile = createExecScript(processControl, ZSHI);
|
||||
return t.getNormalOpenCommand() + " " + zshiFile + " " + initFile;
|
||||
return t.getNormalOpenCommand() + " \"" + zshiFile + "\" \"" + initFile + "\"";
|
||||
}
|
||||
|
||||
return t.getInitFileOpenCommand(initFile);
|
||||
|
@ -117,9 +131,7 @@ public class ScriptHelper {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static String createExecScript(
|
||||
ShellProcessControl processControl, String file, String content
|
||||
) {
|
||||
private static String createExecScript(ShellProcessControl processControl, String file, String content) {
|
||||
ShellType type = processControl.getShellType();
|
||||
content = type.prepareScriptContent(content);
|
||||
|
||||
|
@ -136,9 +148,7 @@ public class ScriptHelper {
|
|||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static String createAskPassScript(
|
||||
SecretValue pass, ShellProcessControl parent, ShellType type
|
||||
) {
|
||||
public static String createAskPassScript(SecretValue pass, ShellProcessControl parent, ShellType type) {
|
||||
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
||||
var temp = parent.getTemporaryDirectory();
|
||||
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
||||
|
|
Loading…
Reference in a new issue