mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-22 15:40:23 +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 (ShellProcessControl pc = ShellStore.local().create().start()) {
|
||||||
try (var c = pc.command(String.format("osascript -e 'POSIX path of (path to application \"%s\")'", applicationName)).start()) {
|
try (var c = pc.command(String.format("osascript -e 'POSIX path of (path to application \"%s\")'", applicationName)).start()) {
|
||||||
var path = c.readOnlyStdout();
|
var path = c.readOnlyStdout();
|
||||||
if (!c.waitFor()) {
|
if (c.getExitCode() != 0) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
return Optional.of(Path.of(path));
|
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;
|
package io.xpipe.extension.util;
|
||||||
|
|
||||||
import io.xpipe.core.impl.FileNames;
|
import io.xpipe.core.impl.FileNames;
|
||||||
import io.xpipe.core.process.OsType;
|
|
||||||
import io.xpipe.core.process.ShellProcessControl;
|
import io.xpipe.core.process.ShellProcessControl;
|
||||||
import io.xpipe.core.process.ShellType;
|
import io.xpipe.core.process.ShellType;
|
||||||
import io.xpipe.core.process.ShellTypes;
|
import io.xpipe.core.process.ShellTypes;
|
||||||
|
@ -16,7 +15,8 @@ import java.util.Random;
|
||||||
public class ScriptHelper {
|
public class ScriptHelper {
|
||||||
|
|
||||||
public static int getScriptId() {
|
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
|
// Therefore, use a random approach
|
||||||
return new Random().nextInt(Integer.MAX_VALUE);
|
return new Random().nextInt(Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
@ -30,64 +30,78 @@ public class ScriptHelper {
|
||||||
|
|
||||||
private static final String ZSHI =
|
private static final String ZSHI =
|
||||||
"""
|
"""
|
||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
emulate -L zsh -o no_unset
|
emulate -L zsh -o no_unset
|
||||||
|
|
||||||
if (( ARGC == 0 )); then
|
if (( ARGC == 0 )); then
|
||||||
print -ru2 -- 'Usage: zshi <init-command> [zsh-flag]...
|
print -ru2 -- 'Usage: zshi <init-command> [zsh-flag]...
|
||||||
The same as plain `zsh [zsh-flag]...` except that an additional
|
The same as plain `zsh [zsh-flag]...` except that an additional
|
||||||
<init-command> gets executed after all standard Zsh startup files
|
<init-command> gets executed after all standard Zsh startup files
|
||||||
have been sourced.'
|
have been sourced.'
|
||||||
return 1
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
() {
|
||||||
|
local init=$1
|
||||||
|
shift
|
||||||
|
local tmp
|
||||||
|
{
|
||||||
|
tmp=$(mktemp -d ${TMPDIR:-/tmp}/zsh.XXXXXXXXXX) || return
|
||||||
|
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
|
fi
|
||||||
|
ZDOTDIR="$_zshi_zdotdir"
|
||||||
() {
|
# Not .zshenv because /etc/zshenv has already been read
|
||||||
local init=$1
|
if [[ -o global_rcs && "'$rc'" != ".zshenv" && -f "/etc/'${rc:1}'" && -r "/etc/'${rc:1}'" ]]; then
|
||||||
shift
|
"builtin" "source" "--" "/etc/'${rc:1}'"
|
||||||
local tmp
|
fi
|
||||||
{
|
if [[ -f "$ZDOTDIR/'$rc'" && -r "$ZDOTDIR/'$rc'" ]]; then
|
||||||
tmp=$(mktemp -d ${TMPDIR:-/tmp}/zsh.XXXXXXXXXX) || return
|
"builtin" "source" "--" "$ZDOTDIR/'$rc'"
|
||||||
local rc
|
fi
|
||||||
for rc in .zshenv .zprofile .zshrc .zlogin; do
|
} always {
|
||||||
>$tmp/$rc <<<'{
|
if [[ -o "no_rcs" ||
|
||||||
ZDOTDIR="$_zshi_zdotdir"
|
-o "login" && "'$rc'" == ".zlogin" ||
|
||||||
if [[ -f "$ZDOTDIR/'$rc'" && -r "$ZDOTDIR/'$rc'" ]]; then
|
-o "no_login" && "'$rc'" == ".zshrc" ||
|
||||||
"builtin" "source" "--" "$ZDOTDIR/'$rc'"
|
-o "no_login" && -o "no_interactive" && "'$rc'" == ".zshenv" ]]; then
|
||||||
|
if (( ${+_zshi_global_rcs} )); then
|
||||||
|
set -o global_rcs
|
||||||
fi
|
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
|
||||||
|
}' || return
|
||||||
|
done
|
||||||
|
_zshi_zdotdir=${ZDOTDIR:-~} ZDOTDIR=$tmp zsh "$@"
|
||||||
} always {
|
} always {
|
||||||
if [[ -o "no_rcs" ||
|
[[ -e $tmp ]] && rm -rf -- $tmp
|
||||||
-o "login" && "'$rc'" == ".zlogin" ||
|
}
|
||||||
-o "no_login" && "'$rc'" == ".zshrc" ||
|
} "$@"
|
||||||
-o "no_login" && -o "no_interactive" && "'$rc'" == ".zshenv" ]]; then
|
|
||||||
"builtin" "unset" "_zshi_rcs" "_zshi_zdotdir"
|
|
||||||
"builtin" "command" "rm" "-rf" "--" '${(q)tmp}'
|
|
||||||
"builtin" "eval" '${(q)init}'
|
|
||||||
else
|
|
||||||
_zshi_zdotdir=${ZDOTDIR:-~}
|
|
||||||
ZDOTDIR='${(q)tmp}'
|
|
||||||
fi
|
|
||||||
}' || return
|
|
||||||
done
|
|
||||||
_zshi_zdotdir=${ZDOTDIR:-~} ZDOTDIR=$tmp zsh "$@"
|
|
||||||
} always {
|
|
||||||
[[ -e $tmp ]] && rm -rf -- $tmp
|
|
||||||
}
|
|
||||||
} "$@"
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
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();
|
ShellType t = processControl.getShellType();
|
||||||
if (init.size() == 0 && toExecuteInShell == null) {
|
if (init.size() == 0 && toExecuteInShell == null) {
|
||||||
return t.getNormalOpenCommand();
|
return t.getNormalOpenCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
String nl = t.getNewLine().getNewLineString();
|
String nl = t.getNewLine().getNewLineString();
|
||||||
var content = String.join(nl, init)
|
var content = String.join(nl, init) + nl;
|
||||||
+ nl;
|
|
||||||
|
|
||||||
if (processControl.getOsType().equals(OsType.LINUX)
|
if (t.equals(ShellTypes.BASH)) {
|
||||||
|| processControl.getOsType().equals(OsType.MAC)) {
|
|
||||||
content = "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n" + content;
|
content = "if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n" + content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +115,7 @@ public class ScriptHelper {
|
||||||
|
|
||||||
if (t.equals(ShellTypes.ZSH)) {
|
if (t.equals(ShellTypes.ZSH)) {
|
||||||
var zshiFile = createExecScript(processControl, ZSHI);
|
var zshiFile = createExecScript(processControl, ZSHI);
|
||||||
return t.getNormalOpenCommand() + " " + zshiFile + " " + initFile;
|
return t.getNormalOpenCommand() + " \"" + zshiFile + "\" \"" + initFile + "\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.getInitFileOpenCommand(initFile);
|
return t.getInitFileOpenCommand(initFile);
|
||||||
|
@ -117,9 +131,7 @@ public class ScriptHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private static String createExecScript(
|
private static String createExecScript(ShellProcessControl processControl, String file, String content) {
|
||||||
ShellProcessControl processControl, String file, String content
|
|
||||||
) {
|
|
||||||
ShellType type = processControl.getShellType();
|
ShellType type = processControl.getShellType();
|
||||||
content = type.prepareScriptContent(content);
|
content = type.prepareScriptContent(content);
|
||||||
|
|
||||||
|
@ -136,9 +148,7 @@ public class ScriptHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static String createAskPassScript(
|
public static String createAskPassScript(SecretValue pass, ShellProcessControl parent, ShellType type) {
|
||||||
SecretValue pass, ShellProcessControl parent, ShellType type
|
|
||||||
) {
|
|
||||||
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
var content = type.getScriptEchoCommand(pass.getSecretValue());
|
||||||
var temp = parent.getTemporaryDirectory();
|
var temp = parent.getTemporaryDirectory();
|
||||||
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
var file = FileNames.join(temp, "askpass-" + getScriptId() + "." + type.getScriptFileEnding());
|
||||||
|
|
Loading…
Reference in a new issue