Last active
October 30, 2024 04:00
-
-
Save gabrielbidula/4b8f84a02dafd242b0e1cf1d682fcaac to your computer and use it in GitHub Desktop.
fake laravel pint formatter mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check if an argument was provided | |
if [ $# -eq 0 ]; then | |
echo "No file path provided." | |
exit 1 | |
fi | |
# Use the provided argument (file path) | |
file="$1" | |
# Ensure the file exists | |
if [ ! -f "$file" ]; then | |
echo "File does not exist: $file" | |
exit 1 | |
fi | |
# Run pint on the provided file without outputting any progress or errors | |
/path/to/pint --quiet "$file" | |
# Output the content of the file | |
cat "$file" |
This worked a bit better for me - since I think there was a race condition between Zed and pint writing to the file?
{
"language_overrides": {
"PHP": {
"format_on_save": {
"external": {
"command": "bash",
"arguments": [
"-c",
"temp=$(mktemp) && cp {buffer_path} $temp && vendor/bin/pint --quiet $temp && cat $temp"
]
}
}
}
}
}
Update for the latest version of Zed:
"language_overrides": {
"PHP": {
"formatter": {
"external": {
"command": "bash",
"arguments": [
"-c",
"temp=$(mktemp) && cat > $temp && ./vendor/bin/pint --quiet $temp && cat $temp"
]
}
}
}
}
@brandon-beacher would it be nice if we could delete the temp file right after we cat
it? or is that something unnecessary?
should be enough
temp=$(mktemp) && cat > $temp && ./vendor/bin/pint --quiet $temp && cat $temp && rm $temp
You guys are absolute legends
I noticed the above setup does not allow the pint option for "psr_autoloading": true
to work. This is what I am using, and it works without a temp file (and circumvents the race condition):
cat > {buffer_path} && ./vendor/bin/pint --quiet {buffer_path} && cat {buffer_path}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also add this to your
.zed/settings.json
: