forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspace-fixer.sh
executable file
·57 lines (46 loc) · 1.31 KB
/
space-fixer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# Add spaces between Chinese and English, number or symbols.
#
# Dependency: This script requires the `https://www.npmjs.com/package/pangu` package.
# Install it via `pip install pangu` or `pnpm install -g pangu` or `npm install -g pangu`.
#
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Space Fixer
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 📝
# @raycast.packageName Conversions
# Documentation:
# @raycast.description Add spaces between Chinese and English, number or symbols.
# @raycast.author RealTong
# @raycast.authorURL https://raycast.com/RealTong
# pip, pnp paths
export PATH="$HOME/.pyenv/shims:$HOME/Library/pnpm:$PATH"
# nvm paths
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# npm paths
NPM_BIN_PATH=$(which npm)
if [[ -n "$NPM_BIN_PATH" ]]; then
NPM_DIR=$(dirname "$NPM_BIN_PATH")
export PATH="$NPM_DIR:$PATH"
fi
pangu_path=$(which pangu)
if [ -z "$pangu_path" ]; then
echo "Error: pangu not found in PATH"
exit 1
fi
input=$(pbpaste)
if [ -z "$input" ]; then
echo "Input is empty"
exit 1
fi
# Call pangu : pangu -t "text"
output=$($pangu_path -t "$input")
if [ -z "$output" ]; then
echo "Output is empty"
exit 1
fi
echo $output | pbcopy
echo "Fixed Chinese text has been copied to the clipboard"