Workflow in mac+alfred implements quick formatting of nginx configuration

I've found very few features in many editing software for formatting nginx configurations. However, Nginx configuration files are often complex and manually formatting them can become tedious and time-consuming. In this article, we will introduce how to use Alfred Workflow to quickly format Nginx configuration files on macOS and improve the readability and maintainability of the configuration files.

Prerequisites:
1. First of all, you must have it alfred. I think this is an artifact (for mac).
2. You need to have the tool to format the nginx configuration file. Here we use the nginxfmt
download command under Python:pip3 install nginxfmt

Once the above is met, we can perform the operation

Implementation

image.png

Script content

#!/bin/bash

# 获取剪贴板中的nginx配置代码块
text="$(pbpaste)"

# 使用nginx-config-formatter来格式化配置
formatted_config=$(/Users/xiaobo/miniforge3/bin/nginxfmt --pipe <<< "$text")

# 将格式化后的配置复制到剪贴板
echo "$formatted_config" | pbcopy

The above is /Users/xiaobo/miniforge3/bin/nginxfmtyour nginxfmt path, which can be which nginxfmtobtained using

With the above, you can select the content you want to format. Execute option+command+L and the formatted nginx will appear on the clipboard.

Guess you like

Origin blog.csdn.net/Mrxiao_bo/article/details/132860048