diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d23841b --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + 22 rue de Plaisance, 75014 Paris, France + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..18be059 --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +# ne - nginx edit +# See LICENSE file for copyright and license details. + +# paths +PREFIX = ~/.local +MANPREFIX = $(PREFIX)/share/man +SHELL = bash + +include config.mk + +SRC = drw.c dmenu.c stest.c util.c +OBJ = $(SRC:.c=.o) + +all: install + +install: + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp ne $(PREFIX)/bin + mkdir -p $(DESTDIR)$(MANPREFIX)/man1 + cp ne.1 $(DESTDIR)$(MANPREFIX)/man1 + +#problema del check: in PATH si trova estesa, qua e' con ~ +#echo "${PATH}" | grep -q "$(DESTDIR)$(PREFIX)/bin" || echo "$(DESTDIR)$(PREFIX)/bin is not in the PATH variable, ne won't run" + + +uninstall: + rm -f $(DESTDIR)$(PREFIX)/bin/ne + rm -f $(DESTDIR)$(MANPREFIX)/ne.1 + +.PHONY: install uninstall diff --git a/README.md b/README.md index 0d1a2e6..c43f459 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ # ne -Edit the configuration for nginx or a conf for a specific file in sites-enabled \ No newline at end of file +Edit the configuration for nginx or a conf for a specific file in sites-enabled + +## install + +* git clone https://git.octosrv.me/mraber/ne +* cd ne && make diff --git a/ne b/ne index f286548..a938219 100755 --- a/ne +++ b/ne @@ -6,6 +6,7 @@ usage() { echo "ne - nginx edit" echo "Usage: ne file_to_edit [-y] [-c]" echo "Options:" + echo "-h -> Show this help" echo "-y -> skip confirm on reload" echo "-c -> manually choose the text editor (default = vim)" echo "Default behaviour: without arguments edits nginx.conf with confirmation" @@ -13,12 +14,11 @@ usage() { } text_editor=$EDITOR skip_confirm=0 -sites-enabled=/etc/nginx/sites-enabled +#sites-enabled="/etc/nginx/sites-enabled" -pushd $sites-enabled +pushd /etc/nginx/sites-enabled [[ $1 = "-h" ]] && usage -#[[ $# -le 0 ]] && file=../nginx.conf && printf "${RED}Editing nginx.conf${NC}\n" && sleep 0.50 || file=$1 && shift #programma senza argomenti edita configurazione globale di nginx #sbagliato l'if, se ho minore o uguale ad 1 argomento allora o è file o è flag, se file non esiste è un flag if [[ $# -le 0 ]] @@ -37,7 +37,19 @@ $(which cp) $file /tmp/copia_check_nginx_${USER} #$(which cat) $file > /tmp/copi #se cat > o cp danno errore vuol dire che il file non esiste ed esco male: [[ $? -eq 1 ]] && printf "${RED}File${NC} $file ${RED}not found, aborting${NC}\n" && exit 1 -[[ $1 = "-c" ]] && read -p "Editor? " text_editor || text_editor=vim #se flag è -c +if [[ $1 = "-c" ]] #se flag è -c e ho ancora una parola dopo allora quello è l'editor +then + shift + if [[ $1 = "" ]] + then + read -p "Editor? " text_editor + else + text_editor=$1 + shift + fi +fi + +[[ -e $(which $text_editor) ]] || exit 3 sudo $text_editor $file diff --color=always $file /tmp/copia_check_nginx_${USER} diff --git a/ne.1 b/ne.1 new file mode 100644 index 0000000..85ec964 --- /dev/null +++ b/ne.1 @@ -0,0 +1,26 @@ +.\" Manpage for ne. +.\" Contact marco@raber.me to correct errors or typos. +.TH man 8 "31 March 2022" "1.0" "ne man page" +.SH NAME +ne \- edit nginx conf +.SH SYNOPSIS +ne [FILENAME] +.SH DESCRIPTION +ne is a script that launches your preferred text editor to edit the nginx configuration. Once you close the editor it will perform a check on the conf and, if asked to, makes nginx reload the configuration. +.SH OPTIONS +ne options: +.TP +.B \-h +Display usage +.TP +.B \-y +ne does not ask for confirmation to reload the nginx conf +.TP +.B \-c [text editor] +ne asks what text editor to use +.SH SEE ALSO +nginx +.SH BUGS +No known bugs. +.SH AUTHOR +Marco Raber (marco@raber.me)