mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-05-11 05:55:37 +00:00
tools: Apply ShellCheck to files in the tools
directory (#402)
* Add `.shellcheckrc` * Apply ShellCheck to `tools/check_for_upgrade.sh` * Apply ShellCheck to `tools/uninstall.sh` * Apply ShellCheck to `tools/install.sh` Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
This commit is contained in:
1
.shellcheckrc
Normal file
1
.shellcheckrc
Normal file
@ -0,0 +1 @@
|
||||
disable=SC1087 # Use braces when expanding arrays -- needed for Zsh, not Bash
|
@ -18,6 +18,7 @@ function _omb_upgrade_check {
|
||||
fi
|
||||
|
||||
local LAST_EPOCH
|
||||
# shellcheck disable=SC1090
|
||||
. ~/.osh-update
|
||||
if [[ ! $LAST_EPOCH ]]; then
|
||||
_omb_upgrade_update_timestamp
|
||||
@ -34,7 +35,7 @@ function _omb_upgrade_check {
|
||||
# update ~/.osh-update
|
||||
_omb_upgrade_update_timestamp
|
||||
if [[ $DISABLE_UPDATE_PROMPT == true ]] ||
|
||||
{ read -p '[Oh My Bash] Would you like to check for updates? [Y/n]: ' line &&
|
||||
{ read -rp '[Oh My Bash] Would you like to check for updates? [Y/n]: ' line &&
|
||||
[[ $line == Y* || $line == y* || ! $line ]]; }
|
||||
then
|
||||
source "$OSH"/tools/upgrade.sh
|
||||
|
@ -6,14 +6,17 @@ if [ -z "${BASH_VERSION-}" ]; then
|
||||
printf "Error: Bash 3.2 or higher is required for Oh My Bash.\n"
|
||||
printf "Error: Install Bash and try running this installation script with Bash.\n"
|
||||
if command -v bash >/dev/null 2>&1; then
|
||||
# shellcheck disable=SC2016
|
||||
printf 'Example: \033[31;1mbash\033[0;34m -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"\n'
|
||||
fi
|
||||
# shellcheck disable=SC2317
|
||||
return 1 >/dev/null 2>&1 || exit 1
|
||||
fi
|
||||
|
||||
if [[ ! ${BASH_VERSINFO[0]-} ]] || ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 2)); then
|
||||
printf "Error: Bash 3.2 required for Oh My Bash.\n" >&2
|
||||
printf "Error: Upgrade Bash and try again.\n" >&2
|
||||
# shellcheck disable=SC2317
|
||||
return 2 &>/dev/null || exit 2
|
||||
elif ((BASH_VERSINFO[0] < 4)); then
|
||||
printf "Warning: Bash >=4 is no longer required for Oh My Bash but is cool to have ;)\n" >&2
|
||||
@ -28,6 +31,7 @@ function _omb_install_print_version {
|
||||
}
|
||||
|
||||
function _omb_install_print_usage {
|
||||
# shellcheck disable=SC2016
|
||||
printf '%s\n' \
|
||||
'usage: ./install.sh [--unattended | --dry-run | --help | --usage | --version]' \
|
||||
'usage: bash -c "$(< install.sh)" [--unattended | --dry-run | --help | --usage |' \
|
||||
@ -113,6 +117,7 @@ function _omb_install_run {
|
||||
function _omb_install_banner {
|
||||
# MOTD message :)
|
||||
printf '%s' "$GREEN"
|
||||
# shellcheck disable=SC1003,SC2016
|
||||
printf '%s\n' \
|
||||
' __ __ __ ' \
|
||||
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
|
||||
@ -127,14 +132,15 @@ function _omb_install_banner {
|
||||
## @var[in] install_opts
|
||||
## @var[in] OSH
|
||||
function _omb_install_user_bashrc {
|
||||
printf "${BLUE}Looking for an existing bash config...${NORMAL}\n"
|
||||
printf '%s\n' "${BLUE}Looking for an existing bash config...${NORMAL}"
|
||||
if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then
|
||||
# shellcheck disable=SC2155
|
||||
local bashrc_backup=~/.bashrc.omb-backup-$(date +%Y%m%d%H%M%S)
|
||||
printf "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to $bashrc_backup${NORMAL}\n"
|
||||
printf '%s\n' "${YELLOW}Found ~/.bashrc.${NORMAL} ${GREEN}Backing up to $bashrc_backup${NORMAL}"
|
||||
_omb_install_run mv ~/.bashrc "$bashrc_backup"
|
||||
fi
|
||||
|
||||
printf "${BLUE}Copying the Oh-My-Bash template file to ~/.bashrc${NORMAL}\n"
|
||||
printf '%s\n' "${BLUE}Copying the Oh-My-Bash template file to ~/.bashrc${NORMAL}"
|
||||
sed "/^export OSH=/ c\\
|
||||
export OSH='${OSH//\'/\'\\\'\'}'
|
||||
" "$OSH"/templates/bashrc.osh-template >| ~/.bashrc.omb-temp &&
|
||||
@ -155,13 +161,14 @@ export OSH='${OSH//\'/\'\\\'\'}'
|
||||
set +e
|
||||
_omb_install_banner
|
||||
printf '%s\n' "${GREEN}Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options${NORMAL}"
|
||||
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash"
|
||||
printf '%s\n' "${BLUE}${BOLD}To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash${NORMAL}"
|
||||
|
||||
if [[ :$install_opts: == *:dry-run:* ]]; then
|
||||
printf '%s\n' "$GREEN$BOLD[dryrun]$NORMAL Sample bashrc is created at '$BOLD$HOME/.bashrc-ombtemp$NORMAL'."
|
||||
elif [[ :$install_opts: != *:unattended:* ]]; then
|
||||
if [[ $- == *i* ]]; then
|
||||
# In case install.sh is sourced from the interactive Bash
|
||||
# shellcheck disable=SC1090
|
||||
source ~/.bashrc
|
||||
else
|
||||
exec bash
|
||||
@ -170,7 +177,7 @@ export OSH='${OSH//\'/\'\\\'\'}'
|
||||
}
|
||||
|
||||
function _omb_install_system_bashrc {
|
||||
printf "${BLUE}Creating a bashrc template at '$OSH/bashrc'...${NORMAL}\n"
|
||||
printf '%s\n' "${BLUE}Creating a bashrc template at '$OSH/bashrc'...${NORMAL}"
|
||||
local q=\' Q="'\''"
|
||||
local osh="'${OSH//$q/$Q}'"
|
||||
osh=${osh//$'\n'/$'\\\n'}
|
||||
@ -181,30 +188,32 @@ function _omb_install_system_bashrc {
|
||||
_omb_install_banner
|
||||
printf '%s\n' "${GREEN}To enable Oh My Bash, please copy '${BOLD}$OSH/bashrc${NORMAL}${GREEN}' to '${BOLD}~/.bashrc${NORMAL}${GREEN}'.${NORMAL}"
|
||||
printf '%s\n' "${GREEN}Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options${NORMAL}"
|
||||
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash"
|
||||
printf '%s\n' "${BLUE}${BOLD}To keep up on the latest news and updates, follow us on GitHub: https://github.com/ohmybash/oh-my-bash${NORMAL}"
|
||||
}
|
||||
|
||||
function _omb_install_main {
|
||||
# Use colors, but only if connected to a terminal, and that terminal
|
||||
# supports them.
|
||||
local ncolors=
|
||||
if type -P tput &>/dev/null; then
|
||||
local ncolors=$(tput colors 2>/dev/null || tput Co 2>/dev/null || echo -1)
|
||||
ncolors=$(tput colors 2>/dev/null || tput Co 2>/dev/null || echo -1)
|
||||
fi
|
||||
|
||||
local RED GREEN YELLOW BLUE BOLD NORMAL
|
||||
if [[ -t 1 && -n $ncolors && $ncolors -ge 8 ]]; then
|
||||
local RED=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null)
|
||||
local GREEN=$(tput setaf 2 2>/dev/null || tput AF 2 2>/dev/null)
|
||||
local YELLOW=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null)
|
||||
local BLUE=$(tput setaf 4 2>/dev/null || tput AF 4 2>/dev/null)
|
||||
local BOLD=$(tput bold 2>/dev/null || tput md 2>/dev/null)
|
||||
local NORMAL=$(tput sgr0 2>/dev/null || tput me 2>/dev/null)
|
||||
RED=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null)
|
||||
GREEN=$(tput setaf 2 2>/dev/null || tput AF 2 2>/dev/null)
|
||||
YELLOW=$(tput setaf 3 2>/dev/null || tput AF 3 2>/dev/null)
|
||||
BLUE=$(tput setaf 4 2>/dev/null || tput AF 4 2>/dev/null)
|
||||
BOLD=$(tput bold 2>/dev/null || tput md 2>/dev/null)
|
||||
NORMAL=$(tput sgr0 2>/dev/null || tput me 2>/dev/null)
|
||||
else
|
||||
local RED=""
|
||||
local GREEN=""
|
||||
local YELLOW=""
|
||||
local BLUE=""
|
||||
local BOLD=""
|
||||
local NORMAL=""
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
BOLD=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
local install_opts install_prefix
|
||||
@ -263,7 +272,7 @@ function _omb_install_main {
|
||||
# precedence over umasks except for filesystems mounted with option "noacl".
|
||||
umask g-w,o-w
|
||||
|
||||
printf "${BLUE}Cloning Oh My Bash...${NORMAL}\n"
|
||||
printf '%s\n' "${BLUE}Cloning Oh My Bash...${NORMAL}"
|
||||
type -P git &>/dev/null || {
|
||||
echo "Error: git is not installed"
|
||||
return 1
|
||||
|
@ -33,6 +33,7 @@ read -r -p "Are you sure you want to remove Oh My Bash? [y/N] " _omb_uninstall_c
|
||||
if [ "$_omb_uninstall_confirmation" != y ] && [ "$_omb_uninstall_confirmation" != Y ]; then
|
||||
printf '%s\n' "Uninstall cancelled"
|
||||
unset _omb_uninstall_confirmation
|
||||
# shellcheck disable=SC2317
|
||||
return 0 2>/dev/null || exit 0
|
||||
fi
|
||||
unset _omb_uninstall_confirmation
|
||||
@ -52,6 +53,7 @@ if ! _omb_uninstall_contains_omb ~/.bashrc; then
|
||||
fi
|
||||
printf '%s\n' "uninstall: Canceled." >&2
|
||||
unset _omb_uninstall_bashrc_original
|
||||
# shellcheck disable=SC2317
|
||||
return 1 2>/dev/null || exit 1
|
||||
fi
|
||||
|
||||
@ -79,6 +81,7 @@ case $- in
|
||||
*i*)
|
||||
if [ -n "${BASH_VERSION-}" ]; then
|
||||
declare -f _omb_util_unload >/dev/null 2>&1 && _omb_util_unload
|
||||
# shellcheck disable=SC1090
|
||||
source ~/.bashrc
|
||||
fi ;;
|
||||
esac
|
||||
|
Reference in New Issue
Block a user