From 8a3e194140926fe12ef55a434fe3066fb7b80c82 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 7 May 2022 12:16:52 +0300 Subject: [PATCH] Update readme, add sources and move some things to the folder --- README.md | 7 ++++++- bash_rc | 27 ++------------------------- bashrc.d/history_options | 18 ++++++++++++++++++ bashrc.d/nano_editor | 2 ++ bashrc.d/terraform_completion | 4 +++- install_my_bashrc.sh | 32 +++++++++++++++++++++++++++----- sources | 5 +++++ 7 files changed, 63 insertions(+), 32 deletions(-) create mode 100644 bashrc.d/history_options create mode 100644 bashrc.d/nano_editor create mode 100644 sources diff --git a/README.md b/README.md index 5b6afb7..f0baaea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # my_bashrc -My Bash RC file + +My Bash RC file. With the posibility to add more files from a ~/.bashrc.d folder and to install more, from git repositories (in the *sources* file). + +# Installation + +Run install_my_bashrc.sh as the user you want to install it, or give an existing folder as parameter to install it somewhere else (/etc/skel for example). diff --git a/bash_rc b/bash_rc index 247b642..ad9cba4 100755 --- a/bash_rc +++ b/bash_rc @@ -18,29 +18,6 @@ fi export PATH="${PATH}:${HOME}/bin:/usr/local/bin:/usr/local/sbin" -export EDITOR=nano - -# shellcheck disable=SC1091 -source "${HOME}/.bashrc_ps1" - -# Format history records -export HISTTIMEFORMAT="[%s] " - -# Append to history file -#PROMPT_COMMAND="history -a; $PROMPT_COMMAND" - -# Share between shells -#PROMPT_COMMAND="history -c; history -r; $PROMPT_COMMAND" - -# append to the history file, don't overwrite it -shopt -s histappend -# Unlimited history -export HISTFILESIZE= -export HISTSIZE= -# don't put duplicate lines or lines starting with space in the history. -# See bash(1) for more options -HISTCONTROL=ignoreboth - # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize @@ -110,9 +87,9 @@ fi mkdir -p "${HOME}/.screen" export SCREENDIR="${HOME}/.screen" -# Set other bashrc files +# Source other RC files mkdir -p "${HOME}/.bashrc.d" -for bashrc_file in $(find "${HOME}/.bashrc.d" -type f | sort | grep -v ~$) +for bashrc_file in $(find "${HOME}/.bashrc.d" -type f | grep -v '\.bak$' |grep -v '~$' | sort) do if [ -n "${bashrc_file}" ]; then # shellcheck disable=SC1090 diff --git a/bashrc.d/history_options b/bashrc.d/history_options new file mode 100644 index 0000000..261d963 --- /dev/null +++ b/bashrc.d/history_options @@ -0,0 +1,18 @@ +#!/bin/bash +# Format history records +export HISTTIMEFORMAT="[%s] " + +# Append to history file +#PROMPT_COMMAND="history -a; $PROMPT_COMMAND" + +# Share between shells +#PROMPT_COMMAND="history -c; history -r; $PROMPT_COMMAND" + +# append to the history file, don't overwrite it +shopt -s histappend +# Unlimited history +export HISTFILESIZE= +export HISTSIZE= +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth diff --git a/bashrc.d/nano_editor b/bashrc.d/nano_editor new file mode 100644 index 0000000..4737458 --- /dev/null +++ b/bashrc.d/nano_editor @@ -0,0 +1,2 @@ +#!/bin/bash +export EDITOR=nano diff --git a/bashrc.d/terraform_completion b/bashrc.d/terraform_completion index 401e645..cecb1e9 100644 --- a/bashrc.d/terraform_completion +++ b/bashrc.d/terraform_completion @@ -1,2 +1,4 @@ #!/bin/bash -complete -C /usr/bin/terraform terraform +if [ -x /usr/bin/terraform ]; then + complete -C /usr/bin/terraform terraform +fi diff --git a/install_my_bashrc.sh b/install_my_bashrc.sh index cc2d246..d9e85c4 100755 --- a/install_my_bashrc.sh +++ b/install_my_bashrc.sh @@ -2,10 +2,32 @@ my_dir=$(dirname "${0}") -if [ -e "${HOME}/.bashrc" ]; then - mv "${HOME}/.bashrc" "${HOME}/.bashrc.bak" +if [ -n "${1}" ]; then + install_directory="${1}" + if [ ! -d "${install_directory}" ]; then + echo "The given install directory '${install_directory}' does NOT exists." + exit 2 + fi + echo "Installing in '${install_directory}' folder instead of \$HOME" +else + install_directory="${HOME}" +fi + +if [ -e "${install_directory}/.bashrc" ]; then + mv "${install_directory}/.bashrc" "${install_directory}/.bashrc.bak" fi cd "${my_dir}" ||exit 1 -cp bash_rc "${HOME}/.bashrc" -rfp -mkdir -p "${HOME}/.bashrc.d/" -cp bashrc.d/* "${HOME}/.bashrc.d/" -rfp +cp bash_rc "${install_directory}/.bashrc" -rfp +mkdir -p "${install_directory}/.bashrc.d/" +cp bashrc.d/* "${install_directory}/.bashrc.d/" -rfp +if [ -e "${my_dir}/sources}" ]; then + mkdir -p "${install_directory}/src/" + while read -r source + do + source_name=$(basename "${source}" .git) + git clone "${source}" "${install_directory}/src/${source_name}" --depth 1 + if [ -e "${install_directory}/src/${source_name}/install.sh" ]; then + bash "${install_directory}/src/${source_name}/install.sh" + fi + done <<< "$(sed 's/#.*$//g' "${my_dir}/sources")" +fi diff --git a/sources b/sources new file mode 100644 index 0000000..2fbb63c --- /dev/null +++ b/sources @@ -0,0 +1,5 @@ +# Add (or remove) sources repositories +# The repository will be cloned to ~/src and +# if there is an install.sh script in the root +# of the repository, it will be run (so be careful) +https://github.com/ajdelgado/bash_prompt.git