A simple utility to manage Nginx configurations.

Fix colors and column padding and add ● indicators for enabled sites

+25 -24
+6 -6
README.md
··· 11 11 $ sudo nx list 12 12 SITE STATUS 13 13 ---------------------------------------- ---------- 14 - example.com Enabled 15 - └── knot.example.com Enabled 16 - └── pds.example.com Enabled 17 - └── statusphere.example.com Enabled 18 14 default Disabled 19 - example.net Enabled 20 - └── staging.example.net Enabled 15 + ● example.com Enabled 16 + └── ● knot.example.com Enabled 17 + └── ● pds.example.com Enabled 18 + └── statusphere.example.com Disabled 19 + ● example.net Enabled 20 + └── ● staging.example.net Enabled 21 21 └── wiki.example.net Disabled 22 22 └── ws.example.net Disabled 23 23 ```
+19 -18
nx.sh
··· 7 7 SITE=$2 8 8 9 9 # Colors 10 - GREEN='\033[0;32m' 11 - RED='\033[0;31m' 12 - BOLD='\033[1m' 13 - NC='\033[0m' 10 + BOLD=$(tput bold) 11 + GREEN=$(tput setaf 2) 12 + RED=$(tput setaf 1) 13 + NC=$(tput sgr0) 14 14 15 15 # Check for root 16 16 if [[ $EUID -ne 0 ]]; then ··· 21 21 case $ACTION in 22 22 list|l) 23 23 # We store the output in a variable to pipe it into 'column' at the end 24 - table_output="${BOLD}SITE${NC};${BOLD}STATUS${NC}\n" 25 - table_output+="----------------------------------------;----------\n" 24 + table_output="${BOLD}SITE${NC}${NC};${BOLD}STATUS${NC}\n" 25 + table_output+="${NC}${NC}----------------------------------------;----------\n" 26 26 27 27 # 1. Get unique names. 2. Reverse dots for sorting (com.google). 3. Sort. 4. Restore original. 28 28 all_sites=$( (cd "$AVAILABLE" 2>/dev/null && ls -1; cd "$ENABLED" 2>/dev/null && ls -1) | \ ··· 40 40 if [[ "$s" == *.* ]] && echo "$all_sites" | grep -qxw "$parent_domain"; then 41 41 is_sub=1 42 42 fi 43 + 44 + # Check for existence with and without .conf 45 + status="Disabled" 46 + [[ -L "$ENABLED/$s" || -L "$ENABLED/$s.conf" ]] && status="Enabled" 47 + 48 + # Filtering logic 49 + if [[ "$SITE" == "--enabled" && "$status" == "Disabled" ]]; then continue; fi 50 + if [[ "$SITE" == "--disabled" && "$status" == "Enabled" ]]; then continue; fi 43 51 44 52 display_name="$s" 45 53 if [[ $is_sub -eq 1 ]]; then 46 - display_name="└── $s" 54 + [[ "$status" == "Enabled" ]] && display_name="└── ${BOLD}${GREEN}●${NC} ${s}${NC}" || display_name="└── ${s}${NC}${NC}" 47 55 else 48 - display_name="${BOLD}${display_name}${NC}" 56 + [[ "$status" == "Enabled" ]] && display_name="${BOLD}${GREEN}●${NC} ${BOLD}${s}${NC}" || display_name="${BOLD}${s}${NC}${NC}" 49 57 fi 50 - 51 - # Check for existence with and without .conf 52 - status="Disabled" 53 - [[ -L "$ENABLED/$s" || -L "$ENABLED/$s.conf" ]] && status="${GREEN}Enabled${NC}" 54 - 55 - # Filtering logic 56 - if [[ "$SITE" == "--enabled" && "$status" == "Disabled" ]]; then continue; fi 57 - if [[ "$SITE" == "--disabled" && "$status" == "${GREEN}Enabled${NC}" ]]; then continue; fi 58 58 59 - table_output+="${display_name};${status}\n" 59 + [[ "$status" == "Enabled" ]] && display_status="${BOLD}${GREEN}Enabled${NC}" || display_status="Disabled" 60 + table_output+="${display_name};${display_status}\n" 60 61 done 61 62 62 63 # Render the table using column 63 - echo -e "$table_output" | column -t -s ';' 64 + echo -e "$table_output" | column -ts ';' 64 65 ;; 65 66 66 67 enable)