From a332fb8c9057e81d5664ea04cd67fcd800da093f Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Wed, 18 Sep 2019 23:27:36 +0100 Subject: [PATCH] added setup_bash.sh --- setup/setup_bash.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 setup/setup_bash.sh diff --git a/setup/setup_bash.sh b/setup/setup_bash.sh new file mode 100755 index 00000000..7c400246 --- /dev/null +++ b/setup/setup_bash.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# vim:ts=4:sts=4:sw=4:et +# +# Author: Hari Sekhon +# Date: 2019-09-18 23:21:50 +0100 (Wed, 18 Sep 2019) +# +# https://github.com/harisekhon/bash-tools +# +# License: see accompanying Hari Sekhon LICENSE file +# +# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish +# +# https://www.linkedin.com/in/harisekhon +# + +# Checks if .bashrc and .bash_profile are sourced, otherwise injects source lines in to the $HOME directory equivalents + +set -euo pipefail +[ -n "${DEBUG:-}" ] && set -x +srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" + +setup_file(){ + local filename="$1" + if grep -Eq "(source|\.).+$srcdir/$filename" ~/"$filename" 2>/dev/null; then + echo "$filename already sourced in ~/$filename" + else + echo "injecting into ~/$filename: source $srcdir/$filename" + echo "source $srcdir/$filename" >> ~/"$filename" + fi +} + +setup_file .bashrc +setup_file .bash_profile