mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-19 21:41:07 +01:00
coffee.plugin.zsh: improve CoffeeScript compilation utilities
Features: - Add check for CoffeeScript compiler installation - Add input validation for all functions - Add proper error messages with usage information - Add clipboard operation feedback Improvements: - Replace aliases with proper functions for better control - Use local variables to prevent namespace pollution - Add proper quoting and option handling - Add error output redirection - Export functions for subshell availability The previous implementation lacked error checking and could fail silently in various scenarios. This update makes the functions more robust and user-friendly while maintaining the original functionality.
This commit is contained in:
parent
eeb01c18c1
commit
23027ec890
1 changed files with 53 additions and 11 deletions
|
@ -1,16 +1,58 @@
|
|||
#!/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() {
|
||||
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() {
|
||||
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
|
||||
alias cfp='cf "$(clippaste)"'
|
||||
# Compile from clipboard & print
|
||||
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
|
||||
alias cfpc='cfp | clipcopy'
|
||||
# Compile from clipboard and copy back to clipboard
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue