diff --git a/README.md b/README.md index a6d9cc6..9e83934 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,21 @@ Install a systemd service as user, can be useful for timers for example : service_install "services/myservice.service" 1 ``` +### define_env + +Define an evirnment variable into the file `~/.config/environment`, you have to +source this file on your `.bashrc` or your `.zprofile`. + + - **input*** : + - `$1` : name of the variable + - `$2` : value, `""` if empty + - **output** : no value, but exit the function if the variale is already + defined (install) or not in file (uninstall) + +``` +define_env "NOTMUCH_CONFIG" "~/.config/notmuch" +``` + ### Avaible variables - `$repository` : the root folder of the repository diff --git a/examples/mail_bootstap b/examples/mail_bootstap index cde4f3d..1aa9b82 100644 --- a/examples/mail_bootstap +++ b/examples/mail_bootstap @@ -37,3 +37,6 @@ install_service "services/mail.timer" 1 # Symblink an executable to $HOME\.local\bin\ install_bin "bin/check_mails.sh" + +# Define the environment variable for Notmuch +define_env "NOTMUCH_CONFIG" "~/.config/notmuch" diff --git a/src/dotinstall.sh b/src/dotinstall.sh index 91f8c36..5126c4e 100755 --- a/src/dotinstall.sh +++ b/src/dotinstall.sh @@ -6,7 +6,7 @@ BIN_DIRECTORY="${HOME}/.local/bin/" LIB_DIRECTORY="${HOME}/.local/lib/" SYD_DIRECTORY="${HOME}/.config/systemd/user" DOTREPO="${HOME}/.config/dotrepo/" - +ENV_FILE="${HOME}/.config/environment" # DEFAULT VALUES OVERWRITE_DIRECTORY=0 @@ -281,6 +281,32 @@ install_bin () fi } +define_env () +{ + # Put a couple name value into $ENV_FILE file or remove it + # on uninstall mode + # $1 variable name + # $2 value + + [ -z $1 ] && { error "You must define a name"; return; } + [ ! -f $ENV_FILE ] && touch $ENV_FILE + if [ $install -eq 1 ] + then + printf "\nCreate an environment variable %s : " "$1" + [ $(grep -c -m 1 $1 $ENV_FILE) -eq 1 ] && { error "already exist"; return; } + local line + line="export ${1}=\"${2}\"" + echo "$line" >> $ENV_FILE + printf "\e[32mdone\e[0m\n" + else + printf "\nRemove an environment variable %s : " "$1" + [ $(grep -c -m 1 $1 $ENV_FILE) -eq 0 ] && { error "not exist"; return; } + sed -i "/^export $1=*/d" $ENV_FILE + printf "\e[32mdone\e[0m\n" + + fi +} + ## create bin directory [ ! -d $BIN_DIRECTORY ] && mkdir -p $BIN_DIRECTORY || printf "bin exist\n"