From 0bffe673f89e12e91e4188a4784b89261b331bb3 Mon Sep 17 00:00:00 2001 From: gbaconni Date: Fri, 29 Oct 2021 09:05:15 +0200 Subject: [PATCH] Fix set_header.sh --- README.md | 10 +++------- set_header.sh | 34 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 61d0b30..2c4d43f 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,7 @@ vim Makefile Below replace "marvin" with your 42 Network login. ``` -export USER="marvin" - -./set_header.sh +USER="marvin" ./set_header.sh ``` In all your git repositories: @@ -60,7 +58,6 @@ git config user.email "marvin@student.42lausanne.ch" UNIX/BSD Distro (MacOS X, FreeBSD, OpenBSD, etc.) edit `~/.zshrc`: ``` vim ~/.zshrc -export USER="marvin" export MAIL="marvin@student.42lausanne.ch" :wq source ~/.zshrc @@ -69,7 +66,6 @@ source ~/.zshrc Linux/GNU Distro (Debian/Ubuntu, RedHat/SuSE, Arch, Gentoo, etc.) edit `~/.bashrc`: ``` vim ~/.bashrc -export USER="marvin" export MAIL="marvin@student.42lausanne.ch" :wq source ~/.bashrc @@ -85,10 +81,10 @@ source ~/.bashrc Troubleshooting: ``` git config user.name -git config user.email echo $USER +git config user.email echo $MAIL -grep -e 'USER=' -e 'MAIL=' ~/.zshrc +grep -e ' USER=' -e ' MAIL=' ~/.zshrc ``` The location of this alternative version of stdheader.vim: diff --git a/set_header.sh b/set_header.sh index 7312ccb..50a8878 100755 --- a/set_header.sh +++ b/set_header.sh @@ -1,34 +1,38 @@ #!/bin/bash # ./set_header.sh -# Set variables +set -e -if [ -f "~/.zshrc" ] +DOMAIN=$DOMAIN-student.42lausanne.ch} +MAIL=${MAIL-${USER}@${DOMAIN}} + +# Add stdheader to vim plugins +test -d ~/.vim/plugin || mkdir -p ~/.vim/plugin +cp vim/stdheader.vim ~/.vim/plugin/ + +# Set variables +if test -f ~/.zshrc then - if ! grep -q ' USER=' "~/.zshrc" ] && [ -z "$USER" ] + if ! grep -q ' USER=' ~/.zshrc && [ -z "$USER" ] then echo 'export USER=`whoami`' >> ~/.zshrc fi - if ! grep -q ' MAIL=' "~/.zshrc" ] + if ! grep -q ' MAIL=' ~/.zshrc then - echo 'export MAIL="${USER}@student.42lausanne.ch"' >> ~/.zshrc + echo "export MAIL=\"${MAIL}\"" >> ~/.zshrc fi + source ~/.zshrc fi -if [ -f "~/.bashrc" ] +if test -f ~/.bashrc then - if ! grep -q ' USER=' "~/.bashrc" ] && [ -z "$USER" ] + if ! grep -q ' USER=' ~/.bashrc && [ -z "$USER" ] then echo 'export USER=`whoami`' >> ~/.bashrc fi - if ! grep -q ' MAIL=' "~/.bashrc" ] + if ! grep -q ' MAIL=' ~/.bashrc then - echo 'export MAIL="${USER}@student.42lausanne.ch"' >> ~/.bashrc + echo "export MAIL=\"${MAIL}\"" >> ~/.bashrc fi + source ~/.bashrc fi -test -d ~/.vim/plugin || mkdir -p ~/.vim/plugin - -# Add stdheader to vim plugins -cp vim/stdheader.vim ~/.vim/plugin/ - -source ~/.zshrc