Skip to content

Commit a15bde3

Browse files
translate-shell: Change setting for trans and gawk binaries
The current approach wasn't very clear how the PATH variable was used later in the script. Now the actual required binaries can be changed and are being used. This also fixes an issue with the implementation which relied on GNU tail and head which are by default not available on MacOS. By hard coding the complete path ensure that BSD tail and head are being used.
1 parent d9b655e commit a15bde3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

commands/apps/translate-shell/translate-shell-language-pair.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
# Install with Homebrew: `brew install translate-shell`
66
# or install with MacPorts: `sudo port install translate-shell`
77

8-
# translate-shell requires gawk to be accessible from PATH.
9-
# This is not the case if the Homebrew prefix was customized or when using macports.
10-
# Add your PATH here, if required.
11-
# PATH="$PATH"
8+
# Set required paths to binaries required for translate-shell.
9+
GAWK='/usr/local/bin/gawk'
10+
TRANS='/usr/local/bin/trans'
1211

1312
# Required parameters:
1413
# @raycast.schemaVersion 1
@@ -68,8 +67,9 @@ def white(message):
6867

6968
def translate(lang, query):
7069
cmd = f"""
71-
PATH="{PATH}"
72-
trans '{lang}' -dump '{query}' | tail -n +2 | head -n -2
70+
# Ensure gawk is available in PATH, as translate-shell requires it.
71+
PATH="$(dirname {GAWK}):$PATH"
72+
{TRANS} '{lang}' -dump '{query}' | /usr/bin/tail -n +2 | /usr/bin/head -n 1
7373
"""
7474

7575
stream = os.popen(cmd)

0 commit comments

Comments
 (0)