mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 09:31:11 +00:00
fix(setup): improve command escaping for Raycast scripts
This commit is contained in:
@@ -44,9 +44,10 @@ write_raycast_script() {
|
|||||||
local title="$2"
|
local title="$2"
|
||||||
local mo_bin="$3"
|
local mo_bin="$3"
|
||||||
local subcommand="$4"
|
local subcommand="$4"
|
||||||
local raw_cmd="\"${mo_bin}\" ${subcommand}"
|
|
||||||
local cmd_escaped="${raw_cmd//\\/\\\\}"
|
local cmd_for_applescript="${mo_bin//\\/\\\\}"
|
||||||
cmd_escaped="${cmd_escaped//\"/\\\"}"
|
cmd_for_applescript="${cmd_for_applescript//\"/\\\"}"
|
||||||
|
|
||||||
cat > "$target" << EOF
|
cat > "$target" << EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
@@ -68,9 +69,9 @@ set -euo pipefail
|
|||||||
echo "🐹 Running ${title}..."
|
echo "🐹 Running ${title}..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Command to execute
|
MO_BIN="${mo_bin}"
|
||||||
_MO_RAW_CMD='${raw_cmd}'
|
MO_SUBCOMMAND="${subcommand}"
|
||||||
_MO_CMD_ESCAPED="${cmd_escaped}"
|
MO_BIN_ESCAPED="${cmd_for_applescript}"
|
||||||
|
|
||||||
has_app() {
|
has_app() {
|
||||||
local name="\$1"
|
local name="\$1"
|
||||||
@@ -119,8 +120,8 @@ launch_with_app() {
|
|||||||
case "\$app" in
|
case "\$app" in
|
||||||
Terminal)
|
Terminal)
|
||||||
if command -v osascript >/dev/null 2>&1; then
|
if command -v osascript >/dev/null 2>&1; then
|
||||||
osascript <<'APPLESCRIPT'
|
osascript <<APPLESCRIPT
|
||||||
set targetCommand to "\${_MO_CMD_ESCAPED}"
|
set targetCommand to "\${MO_BIN_ESCAPED} \${MO_SUBCOMMAND}"
|
||||||
tell application "Terminal"
|
tell application "Terminal"
|
||||||
activate
|
activate
|
||||||
do script targetCommand
|
do script targetCommand
|
||||||
@@ -131,8 +132,8 @@ APPLESCRIPT
|
|||||||
;;
|
;;
|
||||||
iTerm|iTerm2)
|
iTerm|iTerm2)
|
||||||
if command -v osascript >/dev/null 2>&1; then
|
if command -v osascript >/dev/null 2>&1; then
|
||||||
osascript <<'APPLESCRIPT'
|
osascript <<APPLESCRIPT
|
||||||
set targetCommand to "\${_MO_CMD_ESCAPED}"
|
set targetCommand to "\${MO_BIN_ESCAPED} \${MO_SUBCOMMAND}"
|
||||||
tell application "iTerm2"
|
tell application "iTerm2"
|
||||||
activate
|
activate
|
||||||
try
|
try
|
||||||
@@ -156,52 +157,52 @@ APPLESCRIPT
|
|||||||
;;
|
;;
|
||||||
Alacritty)
|
Alacritty)
|
||||||
if launcher_available "Alacritty" && command -v open >/dev/null 2>&1; then
|
if launcher_available "Alacritty" && command -v open >/dev/null 2>&1; then
|
||||||
open -na "Alacritty" --args -e /bin/zsh -lc "\${_MO_RAW_CMD}"
|
open -na "Alacritty" --args -e /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Kitty)
|
Kitty)
|
||||||
if has_bin "kitty"; then
|
if has_bin "kitty"; then
|
||||||
kitty --hold /bin/zsh -lc "\${_MO_RAW_CMD}"
|
kitty --hold /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
elif [[ -x "/Applications/kitty.app/Contents/MacOS/kitty" ]]; then
|
elif [[ -x "/Applications/kitty.app/Contents/MacOS/kitty" ]]; then
|
||||||
"/Applications/kitty.app/Contents/MacOS/kitty" --hold /bin/zsh -lc "\${_MO_RAW_CMD}"
|
"/Applications/kitty.app/Contents/MacOS/kitty" --hold /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
WezTerm)
|
WezTerm)
|
||||||
if has_bin "wezterm"; then
|
if has_bin "wezterm"; then
|
||||||
wezterm start -- /bin/zsh -lc "\${_MO_RAW_CMD}"
|
wezterm start -- /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
elif [[ -x "/Applications/WezTerm.app/Contents/MacOS/wezterm" ]]; then
|
elif [[ -x "/Applications/WezTerm.app/Contents/MacOS/wezterm" ]]; then
|
||||||
"/Applications/WezTerm.app/Contents/MacOS/wezterm" start -- /bin/zsh -lc "\${_MO_RAW_CMD}"
|
"/Applications/WezTerm.app/Contents/MacOS/wezterm" start -- /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Ghostty)
|
Ghostty)
|
||||||
if has_bin "ghostty"; then
|
if has_bin "ghostty"; then
|
||||||
ghostty --command "/bin/zsh" -- -lc "\${_MO_RAW_CMD}"
|
ghostty --command "/bin/zsh" -- -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
elif [[ -x "/Applications/Ghostty.app/Contents/MacOS/ghostty" ]]; then
|
elif [[ -x "/Applications/Ghostty.app/Contents/MacOS/ghostty" ]]; then
|
||||||
"/Applications/Ghostty.app/Contents/MacOS/ghostty" --command "/bin/zsh" -- -lc "\${_MO_RAW_CMD}"
|
"/Applications/Ghostty.app/Contents/MacOS/ghostty" --command "/bin/zsh" -- -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Hyper)
|
Hyper)
|
||||||
if launcher_available "Hyper" && command -v open >/dev/null 2>&1; then
|
if launcher_available "Hyper" && command -v open >/dev/null 2>&1; then
|
||||||
open -na "Hyper" --args /bin/zsh -lc "\${_MO_RAW_CMD}"
|
open -na "Hyper" --args /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
WindTerm)
|
WindTerm)
|
||||||
if launcher_available "WindTerm" && command -v open >/dev/null 2>&1; then
|
if launcher_available "WindTerm" && command -v open >/dev/null 2>&1; then
|
||||||
open -na "WindTerm" --args /bin/zsh -lc "\${_MO_RAW_CMD}"
|
open -na "WindTerm" --args /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
Warp)
|
Warp)
|
||||||
if launcher_available "Warp" && command -v open >/dev/null 2>&1; then
|
if launcher_available "Warp" && command -v open >/dev/null 2>&1; then
|
||||||
open -na "Warp" --args /bin/zsh -lc "\${_MO_RAW_CMD}"
|
open -na "Warp" --args /bin/zsh -lc "\"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
return \$?
|
return \$?
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -210,7 +211,7 @@ APPLESCRIPT
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [[ -n "\${TERM:-}" && "\${TERM}" != "dumb" ]]; then
|
if [[ -n "\${TERM:-}" && "\${TERM}" != "dumb" ]]; then
|
||||||
"${mo_bin}" ${subcommand}
|
"\${MO_BIN}" \${MO_SUBCOMMAND}
|
||||||
exit \$?
|
exit \$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -229,7 +230,7 @@ fi
|
|||||||
|
|
||||||
echo "TERM environment variable not set and no launcher succeeded."
|
echo "TERM environment variable not set and no launcher succeeded."
|
||||||
echo "Run this manually:"
|
echo "Run this manually:"
|
||||||
echo " \${_MO_RAW_CMD}"
|
echo " \"\${MO_BIN}\" \${MO_SUBCOMMAND}"
|
||||||
exit 1
|
exit 1
|
||||||
EOF
|
EOF
|
||||||
chmod +x "$target"
|
chmod +x "$target"
|
||||||
|
|||||||
Reference in New Issue
Block a user