mirror of
https://github.com/ohmybash/oh-my-bash.git
synced 2024-09-21 02:17:11 +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:
parent
1fdb9d035c
commit
8b8a3b31e0
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
|
fi
|
||||||
|
|
||||||
local LAST_EPOCH
|
local LAST_EPOCH
|
||||||
|
# shellcheck disable=SC1090
|
||||||
. ~/.osh-update
|
. ~/.osh-update
|
||||||
if [[ ! $LAST_EPOCH ]]; then
|
if [[ ! $LAST_EPOCH ]]; then
|
||||||
_omb_upgrade_update_timestamp
|
_omb_upgrade_update_timestamp
|
||||||
@ -34,7 +35,7 @@ function _omb_upgrade_check {
|
|||||||
# update ~/.osh-update
|
# update ~/.osh-update
|
||||||
_omb_upgrade_update_timestamp
|
_omb_upgrade_update_timestamp
|
||||||
if [[ $DISABLE_UPDATE_PROMPT == true ]] ||
|
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 ]]; }
|
[[ $line == Y* || $line == y* || ! $line ]]; }
|
||||||
then
|
then
|
||||||
source "$OSH"/tools/upgrade.sh
|
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: 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"
|
printf "Error: Install Bash and try running this installation script with Bash.\n"
|
||||||
if command -v bash >/dev/null 2>&1; then
|
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'
|
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
|
fi
|
||||||
|
# shellcheck disable=SC2317
|
||||||
return 1 >/dev/null 2>&1 || exit 1
|
return 1 >/dev/null 2>&1 || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! ${BASH_VERSINFO[0]-} ]] || ((BASH_VERSINFO[0] < 3 || BASH_VERSINFO[0] == 3 && BASH_VERSINFO[1] < 2)); then
|
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: Bash 3.2 required for Oh My Bash.\n" >&2
|
||||||
printf "Error: Upgrade Bash and try again.\n" >&2
|
printf "Error: Upgrade Bash and try again.\n" >&2
|
||||||
|
# shellcheck disable=SC2317
|
||||||
return 2 &>/dev/null || exit 2
|
return 2 &>/dev/null || exit 2
|
||||||
elif ((BASH_VERSINFO[0] < 4)); then
|
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
|
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 {
|
function _omb_install_print_usage {
|
||||||
|
# shellcheck disable=SC2016
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
'usage: ./install.sh [--unattended | --dry-run | --help | --usage | --version]' \
|
'usage: ./install.sh [--unattended | --dry-run | --help | --usage | --version]' \
|
||||||
'usage: bash -c "$(< install.sh)" [--unattended | --dry-run | --help | --usage |' \
|
'usage: bash -c "$(< install.sh)" [--unattended | --dry-run | --help | --usage |' \
|
||||||
@ -113,6 +117,7 @@ function _omb_install_run {
|
|||||||
function _omb_install_banner {
|
function _omb_install_banner {
|
||||||
# MOTD message :)
|
# MOTD message :)
|
||||||
printf '%s' "$GREEN"
|
printf '%s' "$GREEN"
|
||||||
|
# shellcheck disable=SC1003,SC2016
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
' __ __ __ ' \
|
' __ __ __ ' \
|
||||||
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
|
' ____ / /_ ____ ___ __ __ / /_ ____ ______/ /_ ' \
|
||||||
@ -127,14 +132,15 @@ function _omb_install_banner {
|
|||||||
## @var[in] install_opts
|
## @var[in] install_opts
|
||||||
## @var[in] OSH
|
## @var[in] OSH
|
||||||
function _omb_install_user_bashrc {
|
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
|
if [[ -f ~/.bashrc || -h ~/.bashrc ]]; then
|
||||||
|
# shellcheck disable=SC2155
|
||||||
local bashrc_backup=~/.bashrc.omb-backup-$(date +%Y%m%d%H%M%S)
|
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"
|
_omb_install_run mv ~/.bashrc "$bashrc_backup"
|
||||||
fi
|
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\\
|
sed "/^export OSH=/ c\\
|
||||||
export OSH='${OSH//\'/\'\\\'\'}'
|
export OSH='${OSH//\'/\'\\\'\'}'
|
||||||
" "$OSH"/templates/bashrc.osh-template >| ~/.bashrc.omb-temp &&
|
" "$OSH"/templates/bashrc.osh-template >| ~/.bashrc.omb-temp &&
|
||||||
@ -155,13 +161,14 @@ export OSH='${OSH//\'/\'\\\'\'}'
|
|||||||
set +e
|
set +e
|
||||||
_omb_install_banner
|
_omb_install_banner
|
||||||
printf '%s\n' "${GREEN}Please look over the ~/.bashrc file to select a theme, plugins, completions, aliases, and options${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}"
|
||||||
|
|
||||||
if [[ :$install_opts: == *:dry-run:* ]]; then
|
if [[ :$install_opts: == *:dry-run:* ]]; then
|
||||||
printf '%s\n' "$GREEN$BOLD[dryrun]$NORMAL Sample bashrc is created at '$BOLD$HOME/.bashrc-ombtemp$NORMAL'."
|
printf '%s\n' "$GREEN$BOLD[dryrun]$NORMAL Sample bashrc is created at '$BOLD$HOME/.bashrc-ombtemp$NORMAL'."
|
||||||
elif [[ :$install_opts: != *:unattended:* ]]; then
|
elif [[ :$install_opts: != *:unattended:* ]]; then
|
||||||
if [[ $- == *i* ]]; then
|
if [[ $- == *i* ]]; then
|
||||||
# In case install.sh is sourced from the interactive Bash
|
# In case install.sh is sourced from the interactive Bash
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
else
|
else
|
||||||
exec bash
|
exec bash
|
||||||
@ -170,7 +177,7 @@ export OSH='${OSH//\'/\'\\\'\'}'
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _omb_install_system_bashrc {
|
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 q=\' Q="'\''"
|
||||||
local osh="'${OSH//$q/$Q}'"
|
local osh="'${OSH//$q/$Q}'"
|
||||||
osh=${osh//$'\n'/$'\\\n'}
|
osh=${osh//$'\n'/$'\\\n'}
|
||||||
@ -181,30 +188,32 @@ function _omb_install_system_bashrc {
|
|||||||
_omb_install_banner
|
_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}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 '%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 {
|
function _omb_install_main {
|
||||||
# Use colors, but only if connected to a terminal, and that terminal
|
# Use colors, but only if connected to a terminal, and that terminal
|
||||||
# supports them.
|
# supports them.
|
||||||
|
local ncolors=
|
||||||
if type -P tput &>/dev/null; then
|
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
|
fi
|
||||||
|
|
||||||
|
local RED GREEN YELLOW BLUE BOLD NORMAL
|
||||||
if [[ -t 1 && -n $ncolors && $ncolors -ge 8 ]]; then
|
if [[ -t 1 && -n $ncolors && $ncolors -ge 8 ]]; then
|
||||||
local RED=$(tput setaf 1 2>/dev/null || tput AF 1 2>/dev/null)
|
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)
|
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)
|
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)
|
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)
|
BOLD=$(tput bold 2>/dev/null || tput md 2>/dev/null)
|
||||||
local NORMAL=$(tput sgr0 2>/dev/null || tput me 2>/dev/null)
|
NORMAL=$(tput sgr0 2>/dev/null || tput me 2>/dev/null)
|
||||||
else
|
else
|
||||||
local RED=""
|
RED=""
|
||||||
local GREEN=""
|
GREEN=""
|
||||||
local YELLOW=""
|
YELLOW=""
|
||||||
local BLUE=""
|
BLUE=""
|
||||||
local BOLD=""
|
BOLD=""
|
||||||
local NORMAL=""
|
NORMAL=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local install_opts install_prefix
|
local install_opts install_prefix
|
||||||
@ -263,7 +272,7 @@ function _omb_install_main {
|
|||||||
# precedence over umasks except for filesystems mounted with option "noacl".
|
# precedence over umasks except for filesystems mounted with option "noacl".
|
||||||
umask g-w,o-w
|
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 || {
|
type -P git &>/dev/null || {
|
||||||
echo "Error: git is not installed"
|
echo "Error: git is not installed"
|
||||||
return 1
|
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
|
if [ "$_omb_uninstall_confirmation" != y ] && [ "$_omb_uninstall_confirmation" != Y ]; then
|
||||||
printf '%s\n' "Uninstall cancelled"
|
printf '%s\n' "Uninstall cancelled"
|
||||||
unset _omb_uninstall_confirmation
|
unset _omb_uninstall_confirmation
|
||||||
|
# shellcheck disable=SC2317
|
||||||
return 0 2>/dev/null || exit 0
|
return 0 2>/dev/null || exit 0
|
||||||
fi
|
fi
|
||||||
unset _omb_uninstall_confirmation
|
unset _omb_uninstall_confirmation
|
||||||
@ -52,6 +53,7 @@ if ! _omb_uninstall_contains_omb ~/.bashrc; then
|
|||||||
fi
|
fi
|
||||||
printf '%s\n' "uninstall: Canceled." >&2
|
printf '%s\n' "uninstall: Canceled." >&2
|
||||||
unset _omb_uninstall_bashrc_original
|
unset _omb_uninstall_bashrc_original
|
||||||
|
# shellcheck disable=SC2317
|
||||||
return 1 2>/dev/null || exit 1
|
return 1 2>/dev/null || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -79,6 +81,7 @@ case $- in
|
|||||||
*i*)
|
*i*)
|
||||||
if [ -n "${BASH_VERSION-}" ]; then
|
if [ -n "${BASH_VERSION-}" ]; then
|
||||||
declare -f _omb_util_unload >/dev/null 2>&1 && _omb_util_unload
|
declare -f _omb_util_unload >/dev/null 2>&1 && _omb_util_unload
|
||||||
|
# shellcheck disable=SC1090
|
||||||
source ~/.bashrc
|
source ~/.bashrc
|
||||||
fi ;;
|
fi ;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user