This commit is contained in:
mnv 2024-10-28 13:43:37 +08:00 committed by GitHub
commit 4cdd02636f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,16 +1,58 @@
#!/bin/zsh #!/bin/zsh
# compile a string of coffeescript and print to output # Check if coffee is installed
if ! command -v coffee >/dev/null 2>&1; then
echo "Error: CoffeeScript compiler not found. Please install it with 'npm install -g coffee-script'" >&2
return 1
fi
# Compile a string of CoffeeScript and print to output
cf() { cf() {
coffee -peb "$1" if [[ -z "$1" ]]; then
echo "Error: No input provided" >&2
echo "Usage: cf 'CoffeeScript code'" >&2
return 1
fi
coffee -peb -- "$1" 2>/dev/null || {
echo "Error: Failed to compile CoffeeScript" >&2
return 1
} }
# compile & copy to clipboard }
# Compile & copy to clipboard
cfc() { cfc() {
cf "$1" | clipcopy if [[ -z "$1" ]]; then
echo "Error: No input provided" >&2
echo "Usage: cfc 'CoffeeScript code'" >&2
return 1
fi
local result
result=$(cf "$1") || return 1
echo "$result" | clipcopy && echo "Compiled code copied to clipboard"
} }
# compile from clipboard & print # Compile from clipboard & print
alias cfp='cf "$(clippaste)"' cfp() {
local input
input=$(clippaste)
if [[ -z "$input" ]]; then
echo "Error: Clipboard is empty" >&2
return 1
fi
cf "$input"
}
# compile from clipboard and copy to clipboard # Compile from clipboard and copy back to clipboard
alias cfpc='cfp | clipcopy' cfpc() {
local input result
input=$(clippaste)
if [[ -z "$input" ]]; then
echo "Error: Clipboard is empty" >&2
return 1
fi
result=$(cf "$input") || return 1
echo "$result" | clipcopy && echo "Compiled code copied to clipboard"
}
# Export the functions
export -f cf cfc cfp cfpc