Skip to content

Simplify script installation #7

@phisanti

Description

@phisanti

I quite like this package and approach. Thus, I would like to include a lesson I recently learnt while developing an R code aims to include some CLI tools. It is possible to include the following line in the R/configure file:

#!/bin/bash

# Determine the user's shell configuration file
SHELL_RC="$(basename $SHELL)rc"
USER_RC="$HOME/.$SHELL_RC"

# Define color codes
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'


# Add the exec directory of the package to the PATH
export PATH=$(Rscript -e "cat(system.file(\"exec\", package = \"yourpackagename\"))"):$PATH
EXPORT_CMD='export PATH=$(Rscript -e "cat(system.file(\"exec\", package = \"yourpackagename\"))"):$PATH'
if ! grep -Fxq "$EXPORT_CMD" "$USER_RC"; then
    echo "$EXPORT_CMD" >> "$USER_RC"
    echo -e "${GREEN}Added yourpackagename exec directory to PATH in $USER_RC${NC}"
else
    echo -e "${YELLOW}yourpackagename exec directory already in PATH in $USER_RC${NC}"
fi
echo -e "${YELLOW}Please run 'source $USER_RC' before using the command.${NC}"
# Source the user's shell configuration file to apply changes
source "$USER_RC"

This way it is not necessary to communicate with users to include the proper export in their .bashrc or ./zshrc as it will be automatically identified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions