diff --git a/.editorconfig b/.editorconfig index e35a1b04e5..8a181ef5e3 100755 --- a/.editorconfig +++ b/.editorconfig @@ -13,17 +13,18 @@ insert_final_newline = true trim_trailing_whitespace = false [.git*] +indent_size = tab indent_style = tab [{**.*sh,test/run}] +indent_size = tab indent_style = tab -indent_size = 4 shell_variant = bash binary_next_line = true # like -bn switch_case_indent = true # like -ci space_redirects = true # like -sr -keep_padding = false # like -kp +keep_padding = false # like -kp end_of_line = lf charset = utf-8 trim_trailing_whitespace = true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcef30aaa2..f42c096b6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15] + os: [ubuntu-20.04, ubuntu-18.04, macos-10.15, macos-11.0] runs-on: ${{ matrix.os }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6b682bae6a..d976893c05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,11 +15,12 @@ repos: - id: mixed-line-ending - id: check-added-large-files - repo: https://github.com/jumanjihouse/pre-commit-hooks - rev: 2.1.4 + rev: 2.1.5 hooks: - id: git-check # Configure in .gitattributes - id: shellcheck exclude: ".bats$" + args: [-e, SC1091, -e, SC2034] - id: shfmt exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks diff --git a/.shellcheckrc b/.shellcheckrc deleted file mode 100644 index 6418bd8f38..0000000000 --- a/.shellcheckrc +++ /dev/null @@ -1,6 +0,0 @@ -# We use colors and not assigned -disable=SC2154 -# Hard to fix -disable=SC2155 -# shellcheck is wrong on some -disable=SC2034 diff --git a/aliases/available/apt.aliases.bash b/aliases/available/apt.aliases.bash index 2f44493123..b7ef274c81 100644 --- a/aliases/available/apt.aliases.bash +++ b/aliases/available/apt.aliases.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # # -binaryanomaly @@ -8,7 +8,8 @@ about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which apt) ]; then + if _command_exists apt + then alias apts='apt-cache search' alias aptshow='apt-cache show' alias aptinst='sudo apt-get install -V' diff --git a/aliases/available/curl.aliases.bash b/aliases/available/curl.aliases.bash index 3ced1bb54f..a6b2b344ed 100644 --- a/aliases/available/curl.aliases.bash +++ b/aliases/available/curl.aliases.bash @@ -6,7 +6,8 @@ about-alias 'Curl aliases for convenience.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which curl) ]; then + if _command_exists curl + then # follow redirects alias cl='curl -L' # follow redirects, download as original name diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 0c7bcd9dfd..61ebe538ad 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -30,7 +30,7 @@ then alias grep='grep --color=auto' fi -if which gshuf &> /dev/null +if _command_exists gshuf then alias shuf=gshuf fi @@ -65,7 +65,7 @@ alias -- -='cd -' # Go back alias h='history' # Tree -if [ ! -x "$(which tree 2>/dev/null)" ] +if ! _command_exists tree then alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" fi diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 478861ba2d..8cafa82b01 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -37,8 +37,8 @@ alias gcb='git checkout -b' alias gco='git checkout' alias gcob='git checkout -b' alias gcobu='git checkout -b ${USER}/' -alias gcom='git checkout master' -alias gcpd='git checkout master; git pull; git branch -D' +alias gcom='git checkout $(get_default_branch)' +alias gcpd='git checkout $(get_default_branch); git pull; git branch -D' alias gct='git checkout --track' # clone @@ -64,13 +64,14 @@ alias gf='git fetch --all --prune' alias gft='git fetch --all --prune --tags' alias gftv='git fetch --all --prune --tags --verbose' alias gfv='git fetch --all --prune --verbose' -alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' +alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/$(get_default_branch)' alias gup='git fetch && git rebase' # log alias gg='git log --graph --pretty=format:'\''%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset'\'' --abbrev-commit --date=relative' alias ggf='git log --graph --date=short --pretty=format:'\''%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'\''' alias ggs='gg --stat' +alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # FROM https://stackoverflow.com/questions/39220870/in-git-list-names-of-branches-with-unpushed-commits alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' @@ -104,7 +105,7 @@ alias gp='git push' alias gpd='git push --delete' alias gpf='git push --force' alias gpo='git push origin HEAD' -alias gpom='git push origin master' +alias gpom='git push origin $(get_default_branch)' alias gpu='git push --set-upstream' alias gpunch='git push --force-with-lease' alias gpuo='git push --set-upstream origin' @@ -112,7 +113,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' # pull alias gl='git pull' -alias glum='git pull upstream master' +alias glum='git pull upstream $(get_default_branch)' alias gpl='git pull' alias gpp='git pull && git push' alias gpr='git pull --rebase' @@ -128,9 +129,9 @@ alias grm='git rm' # rebase alias grb='git rebase' alias grbc='git rebase --continue' -alias grm='git rebase master' -alias grmi='git rebase master -i' -alias gprom='git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master' # Rebase with latest remote master +alias grm='git rebase $(get_default_branch)' +alias grmi='git rebase $(get_default_branch) -i' +alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset alias gus='git reset HEAD' @@ -174,7 +175,7 @@ alias gsu='git submodule update --init --recursive' # these aliases requires git v2.23+ alias gsw='git switch' alias gswc='git switch --create' -alias gswm='git switch master' +alias gswm='git switch $(get_default_branch)' alias gswt='git switch --track' # tag @@ -196,3 +197,11 @@ esac function gdv() { git diff --ignore-all-space "$@" | vim -R - } + +function get_default_branch() { + if git branch | grep -q main; then + echo main + else + echo master + fi +} diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index d19057d0b3..b426d27004 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -2,24 +2,14 @@ cite 'about-alias' about-alias 'vim abbreviations' -VIM=$(command -v vim) -GVIM=$(command -v gvim) -MVIM=$(command -v mvim) +_command_exists vim || return -if [[ -n $VIM ]]; then - alias v='$VIM' - # open the vim help in fullscreen incorporated from - # https://stackoverflow.com/a/4687513 - alias vimh='${VIM} -c ":h | only"' -fi +alias v='vim' +# open the vim help in fullscreen incorporated from +# https://stackoverflow.com/a/4687513 +alias vimh='vim -c ":h | only"' # open vim in new tab is taken from # http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek -case $OSTYPE in - darwin*) - [[ -n $MVIM ]] && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } - ;; - *) - [[ -n $GVIM ]] && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } - ;; -esac +_command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } +_command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } diff --git a/bash_it.sh b/bash_it.sh index cb50420291..215c33c7db 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -3,7 +3,7 @@ BASH_IT_LOG_PREFIX="core: main: " # Only set $BASH_IT if it's not already set -if [ -z "$BASH_IT" ]; then +if [ -z "${BASH_IT:-}" ]; then # Setting $BASH to maintain backwards compatibility export BASH_IT=$BASH BASH="$(bash -c 'echo $BASH')" @@ -20,12 +20,12 @@ source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh source "${BASH_IT}/lib/log.bash" # We can only log it now -[ -z "$BASH_IT_OLD_BASH_SETUP" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!" +[ -z "${BASH_IT_OLD_BASH_SETUP:-}" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!" # For backwards compatibility, look in old BASH_THEME location -if [ -z "$BASH_IT_THEME" ]; then +if [ -z "${BASH_IT_THEME:-}" ]; then _log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!" - export BASH_IT_THEME="$BASH_THEME" + export BASH_IT_THEME="${BASH_THEME:-}" unset BASH_THEME fi @@ -114,6 +114,7 @@ for _bash_it_config_file in $CUSTOM; do if [ -e "${_bash_it_config_file}" ]; then filename=$(basename "${_bash_it_config_file}") filename=${filename%*.bash} + # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="custom: $filename: " _log_debug "Loading custom file..." # shellcheck disable=SC1090 @@ -122,7 +123,7 @@ for _bash_it_config_file in $CUSTOM; do done unset _bash_it_config_file -if [[ $PROMPT ]]; then +if [[ -n "${PROMPT:-}" ]]; then export PS1="\[""$PROMPT""\]" fi @@ -144,7 +145,7 @@ if [ -e "$HOME/.jekyllconfig" ]; then fi # BASH_IT_RELOAD_LEGACY is set. -if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then +if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then case $OSTYPE in darwin*) alias reload='source ~/.bash_profile' diff --git a/clean_files.txt b/clean_files.txt index edbe1df405..75aca06e5c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -42,12 +42,14 @@ completion/available/cargo.completion.bash completion/available/composer.completion.bash completion/available/conda.completion.bash completion/available/consul.completion.bash +completion/available/dart.completion.bash completion/available/django.completion.bash completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash +completion/available/git.completion.bash completion/available/github-cli.completion.bash completion/available/go.completion.bash completion/available/helm.completion.bash @@ -57,6 +59,7 @@ completion/available/jungle.completion.bash completion/available/knife.completion.bash completion/available/kontena.completion.bash completion/available/kubectl.completion.bash +completion/available/laravel.completion.bash completion/available/lerna.completion.bash completion/available/minikube.completion.bash completion/available/ngrok.completion.bash @@ -71,12 +74,20 @@ completion/available/rustup.completion.bash completion/available/sdkman.completion.bash completion/available/vault.completion.bash completion/available/vuejs.completion.bash +completion/available/wpscan.completion.bash + +# libraries +lib/utilities.bash # plugins # plugins/available/alias-completion.plugin.bash +plugins/available/autojump.plugin.bash +plugins/available/base.plugin.bash plugins/available/basher.plugin.bash +plugins/available/blesh.plugin.bash plugins/available/cmd-returned-notify.plugin.bash +plugins/available/direnv.plugin.bash plugins/available/docker-machine.plugin.bash plugins/available/git.plugin.bash plugins/available/go.plugin.bash @@ -84,6 +95,17 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/hub.plugin.bash +plugins/available/jump.plugin.bash +plugins/available/less-pretty-cat.plugin.bash +plugins/available/node.plugin.bash +plugins/available/nodenv.plugin.bash +plugins/available/percol.plugin.bash +plugins/available/plenv.plugin.bash +plugins/available/pyenv.plugin.bash +plugins/available/rbenv.plugin.bash +plugins/available/ruby.plugin.bash +plugins/available/textmate.plugin.bash plugins/available/thefuck.plugin.bash plugins/available/xterm.plugin.bash @@ -115,6 +137,7 @@ themes/powerline themes/powerline-multiline themes/powerline-naked themes/powerline-plain +themes/pure themes/purity # vendor init files diff --git a/completion/available/awscli.completion.bash b/completion/available/awscli.completion.bash index 530bdd2739..a30418373a 100644 --- a/completion/available/awscli.completion.bash +++ b/completion/available/awscli.completion.bash @@ -1 +1,6 @@ -[[ -x "$(which aws_completer)" ]] && complete -C "$(which aws_completer)" aws +# shellcheck shell=bash + +if _command_exists aws_completer +then + complete -C "$(command -v aws_completer)" aws +fi diff --git a/completion/available/brew.completion.bash b/completion/available/brew.completion.bash index 91c288def4..61998f8a71 100644 --- a/completion/available/brew.completion.bash +++ b/completion/available/brew.completion.bash @@ -5,28 +5,26 @@ about-completion "brew completion" # Load late to make sure `system` completion loads first # BASH_IT_LOAD_PRIORITY: 375 -if [[ "$(uname -s)" != 'Darwin' ]]; then +if [[ "$OSTYPE" != 'darwin'* ]]; then _log_warning "unsupported operating system - only 'Darwin' is supported" return 0 fi # Make sure brew is installed -_command_exists brew || return 0 +_bash_it_homebrew_check || return 0 -BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} - -if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]]; then +if [[ -r "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" ]]; then # shellcheck disable=1090 - source "$BREW_PREFIX"/etc/bash_completion.d/brew + source "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" -elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]]; then +elif [[ -r "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" ]]; then # shellcheck disable=1090 - source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh + source "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" -elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]]; then +elif [[ -f "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" ]]; then # For the git-clone based installation, see here for more info: # https://github.com/Bash-it/bash-it/issues/1458 # https://docs.brew.sh/Shell-Completion # shellcheck disable=1090 - source "$BREW_PREFIX"/completions/bash/brew + source "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" fi diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index eefe50fa34..176f08328d 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -3,14 +3,14 @@ cite "about-completion" about-completion "composer completion" function __composer_completion() { - local cur coms opts com + local cur coms opts com words COMPREPLY=() _get_comp_words_by_ref -n : cur words # lookup for command for word in "${words[@]:1}"; do - if [[ $word != -* ]]; then - com=$word + if [[ "${word}" != -* ]]; then + com="${word}" break fi done @@ -19,7 +19,7 @@ function __composer_completion() { if [[ ${cur} == --* ]]; then opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" - case "$com" in + case "${com}" in about) opts="${opts} " ;; @@ -109,18 +109,18 @@ function __composer_completion() { # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi # completing for a command - if [[ "$cur" == "$com" ]]; then + if [[ "${cur}" == "${com}" ]]; then coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate" # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) - __ltrim_colon_completions "$cur" + __ltrim_colon_completions "${cur}" return 0 fi diff --git a/completion/available/consul.completion.bash b/completion/available/consul.completion.bash index 3697ffc5bf..511cf37209 100644 --- a/completion/available/consul.completion.bash +++ b/completion/available/consul.completion.bash @@ -3,5 +3,5 @@ cite "about-completion" about-completion "Hashicorp consul completion" if _command_exists consul; then - complete -C "$(which consul)" consul + complete -C "$(command -v consul)" consul fi diff --git a/completion/available/dart.completion.bash b/completion/available/dart.completion.bash new file mode 100644 index 0000000000..b7563443cf --- /dev/null +++ b/completion/available/dart.completion.bash @@ -0,0 +1,48 @@ +# shellcheck shell=bash + +__dart_completion() { + # shellcheck disable=SC2155 + local prev=$(_get_pword) + # shellcheck disable=SC2155 + local curr=$(_get_cword) + + local HELP="--help -h" + local VERBOSE="-v --verbose" + + case $prev in + analyze) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --fatal-infos --no-fatal-warnings --fatal-warnings" -- "$curr")) + ;; + compile) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP aot-snapshot exe js jit-snapshot kernel" -- "$curr")) + ;; + create) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --template -t --no-pub --pub --force" -- "$curr")) + ;; + -t | --template) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "console-simple console-full package-simple web-simple" -- "$curr")) + ;; + format) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE -o --output --fix -l --line-length" -- "$curr")) + ;; + pub) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --no-trace --trace --verbosity cache deps downgrade get global logout outdated publish run upgrade uploader version" -- "$curr")) + ;; + run) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP --observe --enable-vm-service --no-pause-isolates-on-exit --no-pause-isolates-on-unhandled-exceptions --no-warn-on-pause-with-no-debugger --pause-isolates-on-exit --pause-isolates-on-unhandled-exceptions --warn-on-pause-with-no-debugger" -- "$curr")) + ;; + dart) + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --enable-analytics --disable-analytics help analyze compile create format pub run test" -- "$curr")) + ;; + esac +} + +complete -F __dart_completion dart diff --git a/completion/available/defaults.completion.bash b/completion/available/defaults.completion.bash index 5a8d0340d3..c43c0aae49 100644 --- a/completion/available/defaults.completion.bash +++ b/completion/available/defaults.completion.bash @@ -13,7 +13,7 @@ _defaults_domains() COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} - local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" ) + local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep "^$cur" ) local IFS=$'\n' COMPREPLY=( $domains ) if [[ $( echo '-app' | grep "^$cur" ) ]]; then @@ -41,8 +41,8 @@ _defaults() COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) return 0 elif [[ "$prev" == "-host" ]]; then - return 0 _known_hosts -a + return 0 else _defaults_domains return 0 diff --git a/completion/available/dmidecode.completion.bash b/completion/available/dmidecode.completion.bash index fc50c1f078..4a8845244e 100644 --- a/completion/available/dmidecode.completion.bash +++ b/completion/available/dmidecode.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __dmidecode_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/completion/available/docker-compose.completion.bash b/completion/available/docker-compose.completion.bash old mode 100644 new mode 100755 index bf2c13fb41..1102f5d97e --- a/completion/available/docker-compose.completion.bash +++ b/completion/available/docker-compose.completion.bash @@ -676,7 +676,7 @@ _docker_compose() { done local completions_func=_docker_compose_${command//-/_} - declare -F $completions_func >/dev/null && $completions_func + _is_function $completions_func && $completions_func eval "$previous_extglob_setting" return 0 diff --git a/completion/available/fabric.completion.bash b/completion/available/fabric.completion.bash index 7809b38014..6f746454dc 100644 --- a/completion/available/fabric.completion.bash +++ b/completion/available/fabric.completion.bash @@ -41,8 +41,8 @@ export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~" # Set command to get time of last file modification as seconds since Epoch -case `uname` in - Darwin|FreeBSD) +case "$OSTYPE" in + 'darwin'*|'freebsd'*) __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" ;; *) diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index 0020ad1b9f..31b77fa3de 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -1,39 +1,42 @@ -#!/usr/bin/env bash - -# Only operate on MacOS since there are no linux paths -if [[ "$(uname -s)" != 'Darwin' ]] ; then - _log_warning "unsupported operating system - only 'Darwin' is supported" - return 0 -fi +# shellcheck shell=bash +# +# Locate and load completions for `git`. # Make sure git is installed -_command_exists git || return 0 +_command_exists git || return # Don't handle completion if it's already managed -if complete -p git &>/dev/null ; then - _log_warning "completion already loaded - this usually means it is safe to stop using this completion" - return 0 +if complete -p git &> /dev/null; then + _log_warning "completion already loaded - this usually means it is safe to stop using this completion" + return 0 fi -_git_bash_completion_found=false +_git_bash_completion_xcrun_git= +if _command_exists xcrun; then + _git_bash_completion_xcrun_git="$(xcrun --find git)" +fi _git_bash_completion_paths=( - # MacOS non-system locations - '/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash' - '/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash' + # Standard locations + "${GIT_EXE%/*}/../share/git-core/git-completion.bash" + "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" + "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" + # MacOS non-system locations + "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" ) # Load the first completion file found -for _comp_path in "${_git_bash_completion_paths[@]}" ; do - if [ -r "$_comp_path" ] ; then - _git_bash_completion_found=true - source "$_comp_path" - break - fi +_git_bash_completion_found=false +for _comp_path in "${_git_bash_completion_paths[@]}"; do + if [[ -r "$_comp_path" ]]; then + _git_bash_completion_found=true + # shellcheck disable=SC1090 # don't follow + source "$_comp_path" + break + fi done # Cleanup if [[ "${_git_bash_completion_found}" == false ]]; then - _log_warning "no completion files found - please try enabling the 'system' completion instead." + _log_warning "no completion files found - please try enabling the 'system' completion instead." fi -unset _git_bash_completion_paths -unset _git_bash_completion_found +unset "${!_git_bash_completion@}" diff --git a/completion/available/git_flow.completion.bash b/completion/available/git_flow.completion.bash index 04f20ccd54..7bfc9ef42c 100644 --- a/completion/available/git_flow.completion.bash +++ b/completion/available/git_flow.completion.bash @@ -172,6 +172,7 @@ __git_flow_list_hotfixes () } # temporarily wrap __git_find_on_cmdline() for backwards compatibility -if [ -z "`type -t __git_find_subcommand`" ]; then +if ! _command_exists __git_find_subcommand +then alias __git_find_subcommand=__git_find_on_cmdline fi diff --git a/completion/available/git_flow_avh.completion.bash b/completion/available/git_flow_avh.completion.bash index 0b73a0bedd..abb51bf806 100644 --- a/completion/available/git_flow_avh.completion.bash +++ b/completion/available/git_flow_avh.completion.bash @@ -505,6 +505,7 @@ __git_flow_list_branches () } # alias __git_find_on_cmdline for backwards compatibility -if [ -z "`type -t __git_find_on_cmdline`" ]; then +if ! _command_exists __git_find_on_cmdline +then alias __git_find_on_cmdline=__git_find_subcommand fi diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 2b33383ff4..35971d5075 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -22,17 +22,9 @@ # Avoid inaccurate completions for subproject tasks COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') -__gradle-set-project-root-dir() { - local dir=`pwd` - project_root_dir=`pwd` - while [[ $dir != '/' ]]; do - if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then - project_root_dir=$dir - return 0 - fi - dir="$(dirname "$dir")" - done - return 1 +function __gradle-set-project-root-dir() { + project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")" + return "$?" } __gradle-init-cache-dir() { @@ -58,9 +50,9 @@ __gradle-set-cache-name() { __gradle-set-files-checksum() { # Cache MD5 sum of all Gradle scripts and modified timestamps - if builtin command -v md5 > /dev/null; then + if _command_exists md5; then gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)") - elif builtin command -v md5sum > /dev/null; then + elif _command_exists md5sum; then gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}') else echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 79d76bf0e1..67a5e29b1a 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -23,12 +23,12 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # If there is no git tab completion, but we have the _completion loader try to load it -if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then +if ! _is_function _git && _is_function _completion_loader; then _completion_loader git fi # Check that git tab completion is available and we haven't already set up completion -if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then +if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then # Duplicate and rename the 'list_all_commands' function eval "$(declare -f __git_list_all_commands | \ sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" @@ -227,7 +227,7 @@ EOF ((c++)) done if [ -z "$name" ]; then - repo=$(basename "$(pwd)") + repo="$(basename "${PWD}")" fi case "$prev" in -d|-h) diff --git a/completion/available/knife.completion.bash b/completion/available/knife.completion.bash index 83b332f9fd..4b9950edef 100644 --- a/completion/available/knife.completion.bash +++ b/completion/available/knife.completion.bash @@ -42,6 +42,7 @@ _KAC_is_file_newer_than() { _KAC_regen_cache() { local CACHE_NAME=$1 local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME" + # shellcheck disable=SC2155 local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX") shift 1 # discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated @@ -66,6 +67,7 @@ _KAC_get_command_from_cache_name() { # otherwise it waits for the cache to be generated # in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable # for obvious reason, do NOT call that in a sub-shell (in particular, no piping) +# shellcheck disable=SC2155 _KAC_get_and_regen_cache() { # the cache name can't have space in it local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@") @@ -100,7 +102,7 @@ _KAC_clean_cache() { # perform a cache cleaning when loading this file # On big systems this could baloon up to a 30 second run or more, so not enabling by default. -[[ "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache +[[ -n "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache ##################################### ### End of cache helper functions ### @@ -118,7 +120,7 @@ _KAC_get_current_base_command() { local PREVIOUS="knife" local I=1 local CURRENT - while [ $I -le "$COMP_CWORD" ]; do + while [[ "${I}" -le "${COMP_CWORD}" ]]; do # command words are all lower-case echo "${COMP_WORDS[$I]}" | grep -E "^[a-z]+$" > /dev/null || break CURRENT="$PREVIOUS ${COMP_WORDS[$I]}" @@ -127,12 +129,13 @@ _KAC_get_current_base_command() { I=$((I + 1)) done _KAC_CURRENT_COMMAND=$PREVIOUS - [ $I -le "$COMP_CWORD" ] && _KAC_CURRENT_COMMAND_NB_WORDS=$I + [[ "${I}" -le "${COMP_CWORD}" ]] && _KAC_CURRENT_COMMAND_NB_WORDS="${I}" } # searches the position of the currently completed argument in the current base command # (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...) # assumes the current base command is complete +# shellcheck disable=SC2155 _KAC_get_current_arg_position() { local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1)) local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH") @@ -150,10 +153,11 @@ _KAC_get_current_arg_position() { _knife() { _KAC_get_and_regen_cache _KAC_knife_commands local RAW_LIST ITEM REGEN_CMD ARG_POSITION + # shellcheck disable=SC2034 COMREPLY=() # get correct command & arg pos _KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$((COMP_CWORD + 1)) - RAW_LIST=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH" | cut -d ' ' -f $ARG_POSITION | uniq) + RAW_LIST=$(grep -E "^${_KAC_CURRENT_COMMAND}" "${_KAC_CACHE_PATH}" | cut -d ' ' -f "${ARG_POSITION}" | uniq) # we need to process that raw list a bit, most notably for placeholders # NOTE: I chose to explicitely fetch & cache _certain_ informations for the server (cookbooks & node names, etc) diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 7bd6f22323..8f03256896 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -1,15 +1,16 @@ -#!/usr/bin/bash +# shellcheck shell=bash -if command -v laravel > /dev/null; then - __laravel_completion() { - local OPTS=("-h --help -q --quiet --ansi --no-ansi -n --no-interaction -v -vv -vvv --verbose help list new") - COMPREPLY=() - for _opt_ in ${OPTS[@]}; do - if [[ "$_opt_" == "$2"* ]]; then - COMPREPLY+=("$_opt_") - fi - done - } +_command_exists laravel || return - complete -F __laravel_completion laravel -fi +function __laravel_completion() { + local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new') + local _opt_ + COMPREPLY=() + for _opt_ in "${OPTS[@]}"; do + if [[ "$_opt_" == "$2"* ]]; then + COMPREPLY+=("$_opt_") + fi + done +} + +complete -F __laravel_completion laravel diff --git a/completion/available/ngrok.completion.bash b/completion/available/ngrok.completion.bash index ffbdd3c870..ca50a16f42 100644 --- a/completion/available/ngrok.completion.bash +++ b/completion/available/ngrok.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __ngrok_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) local BASE_NO_CONF="--log --log-format --log-level --help" diff --git a/completion/available/notify-send.completion.bash b/completion/available/notify-send.completion.bash index b2c171e90f..676485f83a 100644 --- a/completion/available/notify-send.completion.bash +++ b/completion/available/notify-send.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash function __notify-send_completions() { + # shellcheck disable=SC2155 local curr=$(_get_cword) + # shellcheck disable=SC2155 local prev=$(_get_pword) case $prev in diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 73d62e395a..04e67ecbf5 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1 +1,6 @@ -[[ -x "$(which pew)" ]] && source "$(pew shell_config)" +# shellcheck shell=bash + +if _command_exists pew +then + source "$(pew shell_config)" +fi diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index 7ed8c17ee3..f094d6edec 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -6,6 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip is in the system's path. -if _command_exists pip; then - eval "$(pip completion --bash)" -fi +_command_exists pip || return + +function __bash_it_complete_pip() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip + _pip_completion "$@" + else + eval "$(pip completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip pip diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash index c2b585648e..34abc053fe 100644 --- a/completion/available/pip3.completion.bash +++ b/completion/available/pip3.completion.bash @@ -6,6 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip3 is in the system's path. -if _command_exists pip3; then - eval "$(pip3 completion --bash)" -fi +_command_exists pip3 || return + +function __bash_it_complete_pip3() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip3 + _pip_completion "$@" + else + eval "$(pip3 completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip3 pip3 diff --git a/completion/available/sdkman.completion.bash b/completion/available/sdkman.completion.bash index 7f0157f335..2dc090887a 100644 --- a/completion/available/sdkman.completion.bash +++ b/completion/available/sdkman.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash -_sdkman_complete() { + +function _sdkman_complete() { local CANDIDATES local CANDIDATE_VERSIONS + local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}" COMPREPLY=() @@ -10,7 +12,7 @@ _sdkman_complete() { elif [ "$COMP_CWORD" -eq 2 ]; then case "${COMP_WORDS[COMP_CWORD - 1]}" in "install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug") - CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') + CANDIDATES="${SDKMAN_CANDIDATES_CSV//,/${IFS:0:1}}" mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}") ;; "env") @@ -46,17 +48,17 @@ _sdkman_complete() { return 0 } -_sdkman_candidate_local_versions() { +function _sdkman_candidate_local_versions() { CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1") } -_sdkman_candidate_all_versions() { +function _sdkman_candidate_all_versions() { candidate="$1" CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate") - if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then + if [[ "${SDKMAN_OFFLINE_MODE:-false}" == "true" ]]; then CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS else # sdkman has a specific output format for Java candidate since @@ -70,12 +72,12 @@ _sdkman_candidate_all_versions() { # "+" - local version # "*" - installed # ">" - currently in use - CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort | uniq -u) " + CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort -u) " fi } -__sdkman_cleanup_local_versions() { +function __sdkman_cleanup_local_versions() { __sdkman_build_version_csv "$1" | tr ',' ' ' diff --git a/completion/available/sqlmap.completion.bash b/completion/available/sqlmap.completion.bash index 16addf8545..213dd81736 100644 --- a/completion/available/sqlmap.completion.bash +++ b/completion/available/sqlmap.completion.bash @@ -1,21 +1,22 @@ -#!/bin/bash +# shellcheck shell=bash # ---------------------------------------------------------------------------+ # | -# Thanks to Alexander Korznikov | +# Thanks to Alexander Korznikov | # http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html | # | # ---------------------------------------------------------------------------+ -if command -v sqlmap > /dev/null; then +if _command_exists sqlmap +then - _sqlmap() + function _sqlmap() { local cur prev COMPREPLY=() - cur=$(_get_cword) - prev=$(_get_pword) + cur="$(_get_cword)" + prev="$(_get_pword)" case $prev in @@ -143,7 +144,7 @@ if command -v sqlmap > /dev/null; then --mobile --page-rank --purge-output --smart \ --sqlmap-shell --wizard ' COMPREPLY=( $( \ - (while read -d ' ' i; do + (while read -d ' ' i; do [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && continue # flatten array with spaces on either side, @@ -152,7 +153,7 @@ if command -v sqlmap > /dev/null; then COMPREPLY=" ${COMPREPLY[@]} " # remove word from list of completions COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) - done + done printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}" ) ) diff --git a/completion/available/system.completion.bash b/completion/available/system.completion.bash index 8c4f71dcea..113a93f5be 100644 --- a/completion/available/system.completion.bash +++ b/completion/available/system.completion.bash @@ -1,9 +1,21 @@ #!/usr/bin/env bash - +# # Loads the system's Bash completion modules. # If Homebrew is installed (OS X), it's Bash completion modules are loaded. -if [[ -r /etc/bash_completion ]] ; then +if shopt -qo nounset +then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase. + __bash_it_restore_nounset=true + shopt -uo nounset +else + __bash_it_restore_nounset=false +fi + +if [[ -r "${BASH_COMPLETION:-}" ]] ; then + # shellcheck disable=SC1091 + source "${BASH_COMPLETION}" + +elif [[ -r /etc/bash_completion ]] ; then # shellcheck disable=SC1091 source /etc/bash_completion @@ -12,14 +24,36 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then # shellcheck disable=SC1091 source /etc/profile.d/bash_completion.sh -fi +elif _bash_it_homebrew_check +then + : ${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d} -if [[ "$(uname -s)" == 'Darwin' ]] && _command_exists brew ; then - BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} + case "${BASH_VERSION}" in + 1*|2*|3.0*|3.1*) + _log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?" + ;; + 3.2*|4.0*|4.1*) + # Import version 1.x of bash-completion, if installed. + BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion" + if [[ -r "$BASH_COMPLETION" ]] ; then + # shellcheck disable=SC1090 + source "$BASH_COMPLETION" + else + unset BASH_COMPLETION + fi + ;; + 4.2*|5*|*) + # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path + if [[ -r "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then + # shellcheck disable=SC1090 + source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh + fi + ;; + esac +fi - # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [[ -r "$BREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then - # shellcheck disable=SC1090 - source "$BREW_PREFIX"/etc/profile.d/bash_completion.sh - fi +if $__bash_it_restore_nounset +then + shopt -so nounset fi +unset __bash_it_restore_nounset diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index 28d599aaca..49d8f2cc92 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -1,5 +1,10 @@ -if [[ -x "$(which travis)" ]]; then - __TRAVIS_COMPLETION_SCRIPT="${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh" - [[ -f "${__TRAVIS_COMPLETION_SCRIPT}" ]] && source "${__TRAVIS_COMPLETION_SCRIPT}" +# shellcheck shell=bash + +if _command_exists travis +then + if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]] + then + source "${__TRAVIS_COMPLETION_SCRIPT}" + fi unset __TRAVIS_COMPLETION_SCRIPT fi diff --git a/completion/available/vuejs.completion.bash b/completion/available/vuejs.completion.bash index bbd79b9c9b..751658f0c9 100644 --- a/completion/available/vuejs.completion.bash +++ b/completion/available/vuejs.completion.bash @@ -1,7 +1,9 @@ # shellcheck shell=bash __vuejs_completion() { + # shellcheck disable=SC2155 local prev=$(_get_pword) + # shellcheck disable=SC2155 local curr=$(_get_cword) case $prev in diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index f9ea5790df..105468a356 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -1,15 +1,16 @@ -#!/usr/bin/bash +# shellcheck shell=bash -if command -v wpscan > /dev/null; then - __wpscan_completion() { - local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy") - COMPREPLY=() - for _opt_ in ${OPTS[@]}; do - if [[ "$_opt_" == "$2"* ]]; then - COMPREPLY+=("$_opt_") - fi - done - } +_command_exists wpscan || return - complete -F __wpscan_completion wpscan -fi +function __wpscan_completion() { + local _opt_ + local OPTS=('--help' '--hh' '--version' '--url' '--ignore-main-redirect' '--verbose' '--output' '--format' '--detection-mode' '--scope' '--headers' '--user-agent' '--vhost' '--random-user-agent' '--user-agents-list' '--http-auth' '--max-threads' '--throttle' '--request-timeout' '--connect-timeout' '--disable-tlc-checks' '--proxy' '--proxy-auth' '--cookie-string' '--cookie-jar' '--cache-ttl' '--clear-cache' '--server' '--cache-dir' '--update' '--no-update' '--wp-content-dir' '--wp-plugins-dir' '--wp-version-detection' '--main-theme-detection' '--enumerate' '--exclude-content-based' '--plugins-list' '--plugins-detection' '--plugins-version-all' '--plugins-version-detection' '--themes-list' '--themes-detection' '--themes-version-all' '--themes-version-detection' '--timthumbs-list' '--timthumbs-detection' '--config-backups-list' '--config-backups-detection' '--db-exports-list' '--db-exports-detection' '--medias-detection' '--users-list' '--users-detection' '--passwords' '--usernames' '--multicall-max-passwords' '--password-attack' '--stealthy') + COMPREPLY=() + for _opt_ in "${OPTS[@]}"; do + if [[ "$_opt_" == "$2"* ]]; then + COMPREPLY+=("$_opt_") + fi + done +} + +complete -F __wpscan_completion wpscan diff --git a/docs/README.md b/docs/README.md index fe18c80e17..33c1b03f07 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ ![Docs Status](https://readthedocs.org/projects/bash-it/badge/) ![License](https://img.shields.io/github/license/Bash-it/bash-it) ![shell](https://img.shields.io/badge/Shell-Bash-blue) -[![Join the chat at https://webchat.freenode.net/?channel=#bash-it](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://webchat.freenode.net/?channel=#bash-it) +[![Join the chat at https://web.libera.chat/?channel=#bash-it](https://img.shields.io/badge/chat-on%20Libera.Chat-brightgreen.svg)](https://web.libera.chat/?channel=#bash-it) **Bash-it** is a collection of community Bash commands and scripts for Bash 3.2+. (And a shameless ripoff of [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) :smiley:) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index 85ba2388d1..faa1af3401 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -70,11 +70,13 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``battery`` - Battery information (you'll need to enable the ``battery`` plugin) * ``clock`` - Current time in ``HH:MM:SS`` format * ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ ) +* ``duration`` - Duration of the last command. See :ref:`Command duration ` for details. * ``gcloud`` - Current gcloud active account * ``hostname`` - Host name of machine * ``in_toolbox`` - Show identifier if running inside a `toolbox `_ * ``in_vim`` - Show identifier if running in ``:terminal`` from vim * ``k8s_context`` - Show current kubernetes context +* ``k8s_namespace`` - Show current kubernetes namespace * ``last_status`` - Exit status of last run command * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` and ``conda`` supported) diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 7a9dc8bcaf..253cb595e4 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/hooks/dot-sh.sh b/hooks/dot-sh.sh index 3fa63216db..e1086bb62f 100755 --- a/hooks/dot-sh.sh +++ b/hooks/dot-sh.sh @@ -18,4 +18,4 @@ for file in "$@"; do fi done -exit $exit_code +exit "${exit_code:-0}" diff --git a/install.sh b/install.sh index 4940360f87..5d2f883e90 100755 --- a/install.sh +++ b/install.sh @@ -83,8 +83,8 @@ function _bash-it_check_for_backup() { fi echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 - if ! [[ $overwrite_backup ]]; then - while ! [[ $silent ]]; do + if [[ -z "${overwrite_backup}" ]]; then + while [[ -z "${silent}" ]]; do read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP case $RESP in [yY]) @@ -100,9 +100,9 @@ function _bash-it_check_for_backup() { esac done fi - if ! [[ $overwrite_backup ]]; then + if [[ -z "${overwrite_backup}" ]]; then echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" - if [[ $silent ]]; then + if [[ -n "${silent}" ]]; then echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m" fi exit 1 @@ -114,8 +114,8 @@ function _bash-it_check_for_backup() { function _bash-it_modify_config_files() { _bash-it_check_for_backup - if ! [[ $silent ]]; then - while ! [[ $append_to_config ]]; do + if [[ -z "${silent}" ]]; then + while [[ -z "${append_to_config}" ]]; do read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice case $choice in [yY]) @@ -131,7 +131,7 @@ function _bash-it_modify_config_files() { esac done fi - if [[ $append_to_config ]]; then + if [[ -n "${append_to_config}" ]]; then # backup/append _bash-it_backup_append else @@ -174,17 +174,17 @@ done shift $((OPTIND - 1)) -if [[ $silent ]] && [[ $interactive ]]; then +if [[ -n "${silent}" && -n "${interactive}" ]]; then echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi -if [[ $no_modify_config ]] && [[ $append_to_config ]]; then +if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m" exit 1 fi -BASH_IT="$(cd "$(dirname "$0")" && pwd)" +BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)" case $OSTYPE in darwin*) @@ -197,7 +197,7 @@ esac BACKUP_FILE=$CONFIG_FILE.bak echo "Installing bash-it" -if ! [[ $no_modify_config ]]; then +if [[ -z "${no_modify_config}" ]]; then _bash-it_modify_config_files fi @@ -212,10 +212,10 @@ cite _about _param _example _group _author _version # shellcheck source=./lib/helpers.bash source "$BASH_IT/lib/helpers.bash" -if [[ $interactive ]] && ! [[ $silent ]]; then +if [[ -n $interactive && -z "${silent}" ]]; then for type in "aliases" "plugins" "completion"; do - echo -e "\033[0;32mEnabling $type\033[0m" - _bash-it_load_some $type + echo -e "\033[0;32mEnabling ${type}\033[0m" + _bash-it_load_some "$type" done else echo "" @@ -230,7 +230,7 @@ fi echo "" echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" # shellcheck disable=SC2086 -echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m" +echo -e "\033[0;32mTo start using it, open a new tab or 'source "~/$CONFIG_FILE"'.\033[0m" echo "" echo "To show the available aliases/completions/plugins, type one of the following:" echo " bash-it show aliases" diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index bf63c362d4..94df885d42 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -11,8 +11,8 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---" # To use this in Bash-it for inline replacements with `sed`, use the following syntax: # sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file BASH_IT_SED_I_PARAMETERS=(-i) -case "$(uname)" in - Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "") +case "$OSTYPE" in + 'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") esac function _command_exists () @@ -23,7 +23,13 @@ function _command_exists () _example '$ _command_exists ls && echo exists' _group 'lib' local msg="${2:-Command '$1' does not exist!}" - type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -t "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _binary_exists () @@ -34,7 +40,13 @@ function _binary_exists () _example '$ _binary_exists ls && echo exists' _group 'lib' local msg="${2:-Binary '$1' does not exist!}" - type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -P "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _completion_exists () @@ -48,6 +60,22 @@ function _completion_exists () complete -p "$1" &> /dev/null && _log_warning "$msg" ; } +function _bash_it_homebrew_check() +{ + if _binary_exists 'brew' + then # Homebrew is installed + if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]] + then # variable isn't set + BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)" + else + true # Variable is set already, don't invoke `brew`. + fi + else # Homebrew is not installed. + BASH_IT_HOMEBREW_PREFIX= # clear variable, if set to anything. + false # return failure if brew not installed. + fi +} + function _make_reload_alias() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" } @@ -140,7 +168,7 @@ bash-it () $func $arg done - if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then + if [ -n "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:-}" ]; then _bash-it-reload fi else @@ -194,7 +222,10 @@ _bash-it-update-stable() { _bash-it-update- stable "$@" } -_bash-it_pull_and_update_inner() { +_bash-it_update_migrate_and_restart() { + _about 'Checks out the wanted version, pops directory and restart. Does not return (because of the restart!)' + _param '1: Which branch to checkout to' + _param '2: Which type of version we are using' git checkout "$1" &> /dev/null if [[ $? -eq 0 ]]; then echo "Bash-it successfully updated." @@ -203,7 +234,9 @@ _bash-it_pull_and_update_inner() { _bash-it-migrate echo "" echo "All done, enjoy!" - bash-it reload + # Don't forget to restore the original pwd! + popd &> /dev/null + _bash-it-restart else echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." fi @@ -220,9 +253,11 @@ _bash-it-update-() { silent=true fi done - local old_pwd="${PWD}" - cd "${BASH_IT}" || return + pushd "${BASH_IT}" &> /dev/null || return + + DIFF=$(git diff --name-status) + [ -n "$DIFF" ] && echo -e "Local changes detected in bash-it directory. Clean '$BASH_IT' directory to proceed.\n$DIFF" && return 1 if [ -z "$BASH_IT_REMOTE" ]; then BASH_IT_REMOTE="origin" @@ -240,6 +275,7 @@ _bash-it-update-() { if [[ -z "$TARGET" ]]; then echo "Can not find tags, so can not update to latest stable version..." + popd &> /dev/null return fi else @@ -280,12 +316,12 @@ _bash-it-update-() { if [[ $silent ]]; then echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." - _bash-it_pull_and_update_inner $TARGET $version + _bash-it_update_migrate_and_restart $TARGET $version else read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP case $RESP in [yY]|"") - _bash-it_pull_and_update_inner $TARGET $version + _bash-it_update_migrate_and_restart $TARGET $version ;; [nN]) echo "Not updating…" @@ -302,7 +338,7 @@ _bash-it-update-() { echo "Bash-it is up to date, nothing to do!" fi fi - cd "${old_pwd}" &> /dev/null || return + popd &> /dev/null } _bash-it-migrate() { @@ -316,7 +352,7 @@ _bash-it-migrate() { do for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` do - typeset ff=$(basename $f) + typeset ff="${f##*/}" # Get the type of component from the extension typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') @@ -330,8 +366,8 @@ _bash-it-migrate() { disable_func="_disable-$single_type" enable_func="_enable-$single_type" - $disable_func $component_name - $enable_func $component_name + $disable_func "$component_name" + $enable_func "$component_name" done done @@ -351,7 +387,7 @@ _bash-it-version() { cd "${BASH_IT}" || return - if [ -z $BASH_IT_REMOTE ]; then + if [ -z "${BASH_IT_REMOTE:-}" ]; then BASH_IT_REMOTE="origin" fi @@ -425,7 +461,7 @@ _bash-it-restart() { _about 'restarts the shell in order to fully reload it' _group 'lib' - saved_pwd=$(pwd) + saved_pwd="${PWD}" case $OSTYPE in darwin*) @@ -477,7 +513,7 @@ _bash-it-describe () do # Check for both the old format without the load priority, and the extended format with the priority declare enabled_files enabled_file - enabled_file=$(basename $f) + enabled_file="${f##*/}" enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l) if [ $enabled_files -gt 0 ]; then @@ -579,9 +615,9 @@ _disable-thing () printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return fi - rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" + rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}" else - rm "${BASH_IT}/enabled/$(basename $plugin_global)" + rm "${BASH_IT}/enabled/${plugin_global##*/}" fi fi @@ -657,7 +693,7 @@ _enable-thing () return fi - to_enable=$(basename $to_enable) + to_enable="${to_enable##*/}" # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) if [ ! -z "$enabled_plugin" ] ; then @@ -813,3 +849,30 @@ then fi } fi + +# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in +# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]` +# without any external dependencies. Let the shell do what it's good at. +function _bash-it-find-in-ancestor() ( + about 'searches parents of the current directory for any of the specified file names' + group 'helpers' + param '*: names of files or folders to search for' + returns '0: prints path of closest matching ancestor directory to stdout' + returns '1: no match found' + returns '2: improper usage of shell builtin' # uncommon + example '_bash-it-find-in-ancestor .git .hg' + example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile' + + local kin + # To keep things simple, we do not search the root dir. + while [[ "${PWD}" != '/' ]]; do + for kin in "$@"; do + if [[ -r "${PWD}/${kin}" ]]; then + printf '%s' "${PWD}" + return "$?" + fi + done + command cd .. || return "$?" + done + return 1 +) diff --git a/lib/log.bash b/lib/log.bash index 105c9064a1..6bc53a1239 100644 --- a/lib/log.bash +++ b/lib/log.bash @@ -22,8 +22,8 @@ function _log_general() param '3: message to log' group 'log' - message=$2${BASH_IT_LOG_PREFIX}$3 - _has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}" + message=$2${BASH_IT_LOG_PREFIX:-default: }$3 + _has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}" } function _log_debug() @@ -33,8 +33,8 @@ function _log_debug() example '$ _log_debug "Loading plugin git..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 - _log_general "${echo_green}" "DEBUG: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 + _log_general "${echo_green:-}" "DEBUG: " "$1" } function _log_warning() @@ -44,8 +44,8 @@ function _log_warning() example '$ _log_warning "git binary not found, disabling git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 - _log_general "${echo_yellow}" " WARN: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 + _log_general "${echo_yellow:-}" " WARN: " "$1" } function _log_error() @@ -55,6 +55,6 @@ function _log_error() example '$ _log_error "Failed to load git plugin..."' group 'log' - [[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 - _log_general "${echo_red}" "ERROR: " "$1" + [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 + _log_general "${echo_red:-}" "ERROR: " "$1" } diff --git a/lib/preview.bash b/lib/preview.bash index d0fb0623ba..418839cd2d 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -1,4 +1,4 @@ -if [[ $BASH_PREVIEW ]]; +if [[ "${BASH_PREVIEW:-}" ]]; then unset BASH_PREVIEW #Prevent infinite looping echo " diff --git a/lib/search.bash b/lib/search.bash old mode 100755 new mode 100644 diff --git a/lib/utilities.bash b/lib/utilities.bash index db63956d74..84fa4d96b2 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # # A collection of reusable functions. @@ -6,22 +6,25 @@ # Generic utilies ########################################################################### -_bash-it-get-component-name-from-path() { - # filename without path - filename=${1##*/} - # filename without path or priority - filename=${filename##*---} - # filename without path, priority or extension - echo ${filename%.*.bash} +function _bash-it-get-component-name-from-path() { + local filename + # filename without path + filename="${1##*/}" + # filename without path or priority + filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}" + # filename without path, priority or extension + echo "${filename%.*.bash}" } -_bash-it-get-component-type-from-path() { - # filename without path - filename=${1##*/} - # filename without path or priority - filename=${filename##*---} - # extension - echo ${filename} | cut -d '.' -f 2 +function _bash-it-get-component-type-from-path() { + local filename + # filename without path + filename="${1##*/}" + # filename without extension + filename="${filename%.bash}" + # extension without priority or name + filename="${filename##*.}" + echo "${filename}" } # This function searches an array for an exact match against the term passed @@ -43,96 +46,97 @@ _bash-it-get-component-type-from-path() { # contains pear! # # -_bash-it-array-contains-element() { - local e - for e in "${@:2}"; do - [[ "$e" == "$1" ]] && return 0 - done - return 1 +function _bash-it-array-contains-element() { + local e + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && return 0 + done + return 1 } # Dedupe a simple array of words without spaces. -_bash-it-array-dedup() { - echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' ' +function _bash-it-array-dedup() { + local IFS=$'\n' + echo "$@" | tr ' ' '\n' | sort -u } # Outputs a full path of the grep found on the filesystem -_bash-it-grep() { - if [[ -z "${BASH_IT_GREP}" ]] ; then - export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')" - fi - printf "%s " "${BASH_IT_GREP}" +function _bash-it-grep() { + : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" + printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" } - ########################################################################### # Component-specific functions (component is either an alias, a plugin, or a # completion). ########################################################################### -_bash-it-component-help() { - local component=$(_bash-it-pluralize-component "${1}") - local file=$(_bash-it-component-cache-file ${component}) - if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then - rm -f "${file}" 2>/dev/null - local func="_bash-it-${component}" - ${func} | $(_bash-it-grep) -E ' \[' | cat > ${file} - fi - cat "${file}" +function _bash-it-component-help() { + local component file func + component="$(_bash-it-pluralize-component "${1}")" + file="$(_bash-it-component-cache-file "${component}")" + if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then + rm -f "${file}" 2> /dev/null + func="_bash-it-${component}" + "${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}" + fi + cat "${file}" } -_bash-it-component-cache-file() { - local component=$(_bash-it-pluralize-component "${1}") - local file="${BASH_IT}/tmp/cache/${component}" - [[ -f ${file} ]] || mkdir -p $(dirname ${file}) - printf "${file}" +function _bash-it-component-cache-file() { + local component file + component="$(_bash-it-pluralize-component "${1}")" + file="${BASH_IT?}/tmp/cache/${component}" + [[ -f "${file}" ]] || mkdir -p "${file%/*}" + printf '%s' "${file}" } -_bash-it-pluralize-component() { - local component="${1}" - local len=$(( ${#component} - 1 )) - # pluralize component name for consistency - [[ ${component:${len}:1} != 's' ]] && component="${component}s" - [[ ${component} == "alias" ]] && component="aliases" - printf ${component} +function _bash-it-pluralize-component() { + local component="${1}" + local -i len=$((${#component} - 1)) + # pluralize component name for consistency + [[ "${component:${len}:1}" != 's' ]] && component="${component}s" + [[ "${component}" == "alias" ]] && component="aliases" + printf '%s' "${component}" } -_bash-it-clean-component-cache() { - local component="$1" - local cache - local -a BASH_IT_COMPONENTS=(aliases plugins completions) - if [[ -z ${component} ]] ; then - for component in "${BASH_IT_COMPONENTS[@]}" ; do - _bash-it-clean-component-cache "${component}" - done - else - cache="$(_bash-it-component-cache-file ${component})" - if [[ -f "${cache}" ]] ; then - rm -f "${cache}" - fi - fi +function _bash-it-clean-component-cache() { + local component="$1" + local cache + local -a BASH_IT_COMPONENTS=(aliases plugins completions) + if [[ -z "${component}" ]]; then + for component in "${BASH_IT_COMPONENTS[@]}"; do + _bash-it-clean-component-cache "${component}" + done + else + cache="$(_bash-it-component-cache-file "${component}")" + if [[ -f "${cache}" ]]; then + rm -f "${cache}" + fi + fi } # Returns an array of items within each compoenent. -_bash-it-component-list() { - local component="$1" - _bash-it-component-help "${component}" | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | awk '{print $1}' | sort -u } -_bash-it-component-list-matching() { - local component="$1"; shift - local term="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -- "${term}" | awk '{print $1}' | sort | uniq +function _bash-it-component-list-matching() { + local component="$1" + shift + local term="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -- "${term}" | awk '{print $1}' | sort -u } -_bash-it-component-list-enabled() { - local component="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list-enabled() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | awk '{print $1}' | sort -u } -_bash-it-component-list-disabled() { - local component="$1" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' +function _bash-it-component-list-disabled() { + local IFS=$'\n' component="$1" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | awk '{print $1}' | sort -u } # Checks if a given item is enabled for a particular component/file-type. @@ -143,10 +147,10 @@ _bash-it-component-list-disabled() { # # Examples: # _bash-it-component-item-is-enabled alias git && echo "git alias is enabled" -_bash-it-component-item-is-enabled() { - local component="$1" - local item="$2" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" +function _bash-it-component-item-is-enabled() { + local component="$1" + local item="$2" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s" } # Checks if a given item is disabled for a particular component/file-type. @@ -157,8 +161,8 @@ _bash-it-component-item-is-enabled() { # # Examples: # _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled" -_bash-it-component-item-is-disabled() { - local component="$1" - local item="$2" - _bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" +function _bash-it-component-item-is-disabled() { + local component="$1" + local item="$2" + _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s" } diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index 390b10e3cb..eb368d933c 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -19,6 +19,8 @@ about-plugin 'Automatic completion of aliases' # Automatically add completion for all aliases to commands having completion functions function alias_completion { local namespace="alias_completion" + local tmp_file completion_loader alias_name alias_tokens line completions + local alias_arg_words new_completion compl_func compl_wrapper # parse function based completion definitions, where capture group 2 => function and 3 => trigger local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' @@ -26,28 +28,25 @@ function alias_completion { local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" # create array of function completion triggers, keeping multi-word triggers together - eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" + eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" ((${#completions[@]} == 0)) && return 0 # create temporary file for wrapper functions and completions - local tmp_file tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 - local completion_loader completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')" # read in " '' ''" lines from defined aliases - local line - - # shellcheck disable=SC2162 # some aliases do have backslashes that needs to be interpreted + # shellcheck disable=SC2162 while read line; do - eval "local alias_tokens; alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error - local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" + eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error + # shellcheck disable=SC2154 # see `eval` above + alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" # skip aliases to pipes, boolean control structures and other command lists # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters) - eval "local alias_arg_words; alias_arg_words=($alias_args)" 2> /dev/null || continue + eval "alias_arg_words=($alias_args)" 2> /dev/null || continue # avoid expanding wildcards read -a alias_arg_words <<< "$alias_args" @@ -63,15 +62,15 @@ function alias_completion { continue fi fi - local new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" + new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" # create a wrapper inserting the alias arguments if any if [[ -n $alias_args ]]; then - local compl_func="${new_completion/#* -F /}" + compl_func="${new_completion/#* -F /}" compl_func="${compl_func%% *}" # avoid recursive call loops by ignoring our own functions - if [[ "${compl_func#_$namespace::}" == "$compl_func" ]]; then - local compl_wrapper="_${namespace}::${alias_name}" + if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then + compl_wrapper="_${namespace}::${alias_name}" echo "function $compl_wrapper { local compl_word=\$2 local prec_word=\$3 diff --git a/plugins/available/autojump.plugin.bash b/plugins/available/autojump.plugin.bash index 345ecadb5b..dc8fbbb49f 100644 --- a/plugins/available/autojump.plugin.bash +++ b/plugins/available/autojump.plugin.bash @@ -1,12 +1,15 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details' # Only supports the Homebrew variant, Debian and Arch at the moment. # Feel free to provide a PR to support other install locations -if command -v brew &>/dev/null && [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]]; then - . $(brew --prefix)/etc/profile.d/autojump.sh -elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then - . "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" -elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then - . "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" +if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then + source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" +elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" +elif _command_exists pacman && pacman -Q autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" fi diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash old mode 100755 new mode 100644 index 6da1384edf..6490ab880b --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -1,215 +1,180 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'miscellaneous tools' -function ips () -{ - about 'display all ip addresses for this host' - group 'base' - if command -v ifconfig &>/dev/null - then - ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' - elif command -v ip &>/dev/null - then - ip addr | grep -oP 'inet \K[\d.]+' - else - echo "You don't have ifconfig or ip command installed!" - fi +function ips() { + about 'display all ip addresses for this host' + group 'base' + if _command_exists ifconfig; then + ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' + elif _command_exists ip; then + ip addr | grep -oP 'inet \K[\d.]+' + else + echo "You don't have ifconfig or ip command installed!" + fi } -function down4me () -{ - about 'checks whether a website is down for you, or everybody' - param '1: website url' - example '$ down4me http://www.google.com' - group 'base' - curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' +function down4me() { + about 'checks whether a website is down for you, or everybody' + param '1: website url' + example '$ down4me http://www.google.com' + group 'base' + curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g' } -function myip () -{ - about 'displays your ip address, as seen by the Internet' - group 'base' - list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") - for url in ${list[*]} - do - res=$(curl -fs "${url}") - if [ $? -eq 0 ];then - break; - fi - done - res=$(echo "$res" | grep -Eo '[0-9\.]+') - echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" +function myip() { + about 'displays your ip address, as seen by the Internet' + group 'base' + list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") + for url in "${list[@]}"; do + if res="$(curl -fs "${url}")"; then + break + fi + done + res="$(echo "$res" | grep -Eo '[0-9\.]+')" + echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}" } -function pickfrom () -{ - about 'picks random line from file' - param '1: filename' - example '$ pickfrom /usr/share/dict/words' - group 'base' - local file=$1 - [ -z "$file" ] && reference $FUNCNAME && return - length=$(cat $file | wc -l) - n=$(expr $RANDOM \* $length \/ 32768 + 1) - head -n $n $file | tail -1 +function pickfrom() { + about 'picks random line from file' + param '1: filename' + example '$ pickfrom /usr/share/dict/words' + group 'base' + local file=${1:-} + local -i n=0 length + if [[ ! -r "$file" ]]; then + reference "${FUNCNAME[0]}" && return + fi + length="$(wc -l < "$file")" + n=$((RANDOM * length / 32768 + 1)) + head -n "$n" "$file" | tail -1 } -function passgen () -{ - about 'generates random password from dictionary words' - param 'optional integer length' - param 'if unset, defaults to 4' - example '$ passgen' - example '$ passgen 6' - group 'base' - local i pass length=${1:-4} - pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) - echo "With spaces (easier to memorize): $pass" - echo "Without (use this as the password): $(echo $pass | tr -d ' ')" +function passgen() { + about 'generates random password from dictionary words' + param 'optional integer length' + param 'if unset, defaults to 4' + example '$ passgen' + example '$ passgen 6' + group 'base' + local -i i length=${1:-4} + local pass + # shellcheck disable=SC2034 + pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)" + echo "With spaces (easier to memorize): ${pass//$'\n'/ }" + echo "Without spaces (easier to brute force): ${pass//$'\n'/}" } # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! command -v pass &>/dev/null || [ "$BASH_IT_LEGACY_PASS" = true ] -then - alias pass=passgen +if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then + alias pass=passgen fi -function pmdown () -{ - about 'preview markdown file in a browser' - param '1: markdown file' - example '$ pmdown README.md' - group 'base' - if command -v markdown &>/dev/null - then - markdown $1 | browser - else - echo "You don't have a markdown command installed!" - fi -} +if _command_exists markdown && _command_exists browser; then + function pmdown() { + about 'preview markdown file in a browser' + param '1: markdown file' + example '$ pmdown README.md' + group 'base' -function mkcd () -{ - about 'make one or more directories and cd into the last one' - param 'one or more directories to create' - example '$ mkcd foo' - example '$ mkcd /tmp/img/photos/large' - example '$ mkcd foo foo1 foo2 fooN' - example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing' - group 'base' - mkdir -p -- "$@" && eval cd -- "\"\$$#\"" -} + markdown "${1?}" | browser + } +fi -function lsgrep () -{ - about 'search through directory contents with grep' - group 'base' - ls | grep "$*" +function mkcd() { + about 'make one or more directories and cd into the last one' + param 'one or more directories to create' + example '$ mkcd foo' + example '$ mkcd /tmp/img/photos/large' + example '$ mkcd foo foo1 foo2 fooN' + example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing' + group 'base' + mkdir -p -- "$@" && cd -- "${!#}" || return } -function quiet () -{ - about 'what *does* this do?' - group 'base' - $* &> /dev/null & +# shellcheck disable=SC2010 +function lsgrep() { + about 'search through directory contents with grep' + group 'base' + ls | grep "$@" } -function banish-cookies () -{ - about 'redirect .adobe and .macromedia files to /dev/null' - group 'base' - rm -r ~/.macromedia ~/.adobe - ln -s /dev/null ~/.adobe - ln -s /dev/null ~/.macromedia +function quiet() { + about 'what *does* this do?' + group 'base' + nohup "$@" &> /dev/null < /dev/null & } -function usage () -{ - about 'disk usage per directory, in Mac OS X and Linux' - param '1: directory name' - group 'base' - if [ $(uname) = "Darwin" ]; then - if [ -n "$1" ]; then - du -hd 1 "$1" - else - du -hd 1 - fi - - elif [ $(uname) = "Linux" ]; then - if [ -n "$1" ]; then - du -h --max-depth=1 "$1" - else - du -h --max-depth=1 - fi - fi +function usage() { + about 'disk usage per directory, in Mac OS X and Linux' + param '1: directory name' + group 'base' + case $OSTYPE in + *'darwin'*) + du -hd 1 "$@" + ;; + *'linux'*) + du -h --max-depth=1 "$@" + ;; + esac } -if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then -# if user has installed todo plugin, skip this... - function t () - { - about 'one thing todo' - param 'if not set, display todo item' - param '1: todo text' - if [[ "$*" == "" ]] ; then - cat ~/.t - else - echo "$*" > ~/.t - fi - } +# shellcheck disable=SC2144 # the glob matches only one file +if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" && + ! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then + # if user has installed todo plugin, skip this... + function t() { + about 'one thing todo' + param 'if not set, display todo item' + param '1: todo text' + if [[ "$*" == "" ]]; then + cat ~/.t + else + echo "$*" > ~/.t + fi + } fi -function command_exists () -{ - about 'checks for existence of a command' - param '1: command to check' - example '$ command_exists ls && echo exists' - group 'base' - type "$1" &> /dev/null ; -} - -mkiso () -{ - about 'creates iso from current dir in the parent dir (unless defined)' - param '1: ISO name' - param '2: dest/path' - param '3: src/path' - example 'mkiso' - example 'mkiso ISO-Name dest/path src/path' - group 'base' - - if type "mkisofs" > /dev/null; then - [ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1 - [ -z ${2+x} ] && local destpath=../ || local destpath=$2 - [ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3 - - if [ ! -f "${destpath}${isoname}.iso" ]; then - echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" - mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}" - else - echo "${destpath}${isoname}.iso already exists" - fi - else - echo "mkisofs cmd does not exist, please install cdrtools" - fi -} +if _command_exists mkisofs; then + function mkiso() { + about 'creates iso from current dir in the parent dir (unless defined)' + param '1: ISO name' + param '2: dest/path' + param '3: src/path' + example 'mkiso' + example 'mkiso ISO-Name dest/path src/path' + group 'base' + + local isoname="${1:-${PWD##*/}}" + local destpath="${2:-../}" + local srcpath="${3:-${PWD}}" + + if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then + echo "writing ${isoname}.iso to ${destpath} from ${srcpath}" + mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}" + else + echo "${destpath%/}/${isoname}.iso already exists" + fi + } +fi # useful for administrators and configs -function buf () -{ - about 'back up file with timestamp' - param 'filename' - group 'base' - local filename=$1 - local filetime=$(date +%Y%m%d_%H%M%S) - cp -a "${filename}" "${filename}_${filetime}" +function buf() { + about 'back up file with timestamp' + param 'filename' + group 'base' + local filename="${1?}" filetime + filetime=$(date +%Y%m%d_%H%M%S) + cp -a "${filename}" "${filename}_${filetime}" } -function del() { - about 'move files to hidden folder in tmp, that gets cleared on each reboot' - param 'file or folder to be deleted' - example 'del ./file.txt' - group 'base' - mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; -} +if ! _command_exists del; then + function del() { + about 'move files to hidden folder in tmp, that gets cleared on each reboot' + param 'file or folder to be deleted' + example 'del ./file.txt' + group 'base' + mkdir -p /tmp/.trash && mv "$@" /tmp/.trash + } +fi diff --git a/plugins/available/blesh.plugin.bash b/plugins/available/blesh.plugin.bash new file mode 100644 index 0000000000..7b1ce74e68 --- /dev/null +++ b/plugins/available/blesh.plugin.bash @@ -0,0 +1,19 @@ +# shellcheck shell=bash +cite about-plugin +about-plugin 'load ble.sh, the Bash line editor!' + +if [[ ${BLE_VERSION-} ]]; then + _log_warning "ble.sh is already loaded!" + return +fi + +_bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh +if [[ -f $_bash_it_ble_path ]]; then + # shellcheck disable=1090 + source "$_bash_it_ble_path" +else + _log_error "Could not find ble.sh in $_bash_it_ble_path" + _log_error "Please install using the following command:" + _log_error "git clone https://github.com/akinomyoga/ble.sh && make -C ble.sh install" +fi +unset _bash_it_ble_path diff --git a/plugins/available/boot2docker.plugin.bash b/plugins/available/boot2docker.plugin.bash index c8b389c35c..f19e91ef84 100644 --- a/plugins/available/boot2docker.plugin.bash +++ b/plugins/available/boot2docker.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'Helpers to get Docker setup correctly for boot2docker' # Note, this might need to be different if you have an older version # of boot2docker, or its configured for a different IP -if [[ `uname -s` == "Darwin" ]]; then +if [[ "$OSTYPE" == 'darwin'* ]]; then export DOCKER_HOST="tcp://192.168.59.103:2376" export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm" export DOCKER_TLS_VERIFY=1 diff --git a/plugins/available/cmd-returned-notify.plugin.bash b/plugins/available/cmd-returned-notify.plugin.bash index a305087553..d9be5e4e9f 100644 --- a/plugins/available/cmd-returned-notify.plugin.bash +++ b/plugins/available/cmd-returned-notify.plugin.bash @@ -9,7 +9,7 @@ precmd_return_notification() { } preexec_return_notification() { - [ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s) + [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) } precmd_functions+=(precmd_return_notification) diff --git a/plugins/available/direnv.plugin.bash b/plugins/available/direnv.plugin.bash index 5fd564f53c..62788600be 100644 --- a/plugins/available/direnv.plugin.bash +++ b/plugins/available/direnv.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load direnv, if you are using it: https://direnv.net/' -[ -x "$(which direnv)" ] && eval "$(direnv hook bash)" +if _command_exists direnv; then + eval "$(direnv hook bash)" +fi diff --git a/plugins/available/dirs.plugin.bash b/plugins/available/dirs.plugin.bash index c215f7ecf7..2c1adf7add 100644 --- a/plugins/available/dirs.plugin.bash +++ b/plugins/available/dirs.plugin.bash @@ -23,7 +23,7 @@ alias 8="pushd +8" alias 9="pushd +9" # Clone this location -alias pc="pushd \$(pwd)" +alias pc='pushd "${PWD}"' # Push new location alias pu="pushd" @@ -73,7 +73,7 @@ G () { example '$ G ..' group 'dirs' - cd "${1:-$(pwd)}" ; + cd "${1:-${PWD}}" ; } S () { @@ -86,7 +86,7 @@ S () { sed "/$@/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; - echo "$@"=\"`pwd`\" >> ~/.dirs; + echo "$@"=\""${PWD}"\" >> ~/.dirs; source ~/.dirs ; } diff --git a/plugins/available/git.plugin.bash b/plugins/available/git.plugin.bash index e4efc3fe38..3a130955c1 100644 --- a/plugins/available/git.plugin.bash +++ b/plugins/available/git.plugin.bash @@ -2,12 +2,13 @@ cite about-plugin about-plugin 'git helper functions' +# shellcheck disable=SC2016 function git_remote { - about "adds remote $GIT_HOSTING:$1 to current repo" + about 'adds remote $GIT_HOSTING:$1 to current repo' group "git" - echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" - git remote add origin "$GIT_HOSTING:$1".git + echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git" + git remote add origin "${GIT_HOSTING}:${1}".git } function git_first_push { @@ -24,14 +25,14 @@ function git_pub() { BRANCH=$(git rev-parse --abbrev-ref HEAD) echo "Publishing ${BRANCH} to remote origin" - git push -u origin "$BRANCH" + git push -u origin "${BRANCH}" } function git_revert() { about 'applies changes to HEAD that revert all changes after this commit' group 'git' - git reset "$1" + git reset "${1:?}" git reset --soft "HEAD@{1}" git commit -m "Revert to ${1}" git reset --hard @@ -49,9 +50,7 @@ function git_rollback() { } function commit_exists() { - git rev-list --quiet "$1" - status=$? - if [ $status -ne 0 ]; then + if git rev-list --quiet "${1:?}"; then echo "Commit ${1} does not exist" kill -INT $$ fi @@ -61,7 +60,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) echo "Rolling back to commit ${1} with unstaged changes" @@ -87,7 +86,7 @@ function git_rollback() { while true; do # shellcheck disable=SC2162 read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP - case $RESP in + case "${RESP}" in [yY]) keep_changes "$1" @@ -134,8 +133,8 @@ function git_info() { # print all remotes and thier details for remote in $(git remote show); do - echo "$remote": - git remote show "$remote" + echo "${remote}": + git remote show "${remote}" echo done @@ -172,32 +171,32 @@ function git_stats { AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ') LOGOPTS="" if [ "$1" == '-w' ]; then - LOGOPTS="$LOGOPTS -w" + LOGOPTS="${LOGOPTS} -w" shift fi if [ "$1" == '-M' ]; then - LOGOPTS="$LOGOPTS -M" + LOGOPTS="${LOGOPTS} -M" shift fi if [ "$1" == '-C' ]; then - LOGOPTS="$LOGOPTS -C --find-copies-harder" + LOGOPTS="${LOGOPTS} -C --find-copies-harder" shift fi - for a in $AUTHORS; do + for a in ${AUTHORS}; do echo '-------------------' - echo "Statistics for: $a" + echo "Statistics for: ${a}" echo -n "Number of files changed: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l echo -n "Number of lines added: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}' echo -n "Number of lines deleted: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}' + git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}' echo -n "Number of merges: " # shellcheck disable=SC2086 - git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit' + git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit' done else echo "you're currently not in a git repository" @@ -212,18 +211,16 @@ function gittowork() { result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null) - if [[ $result =~ ERROR ]]; then + if [[ "${result}" =~ ERROR ]]; then echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'" - elif [[ $1 = list ]]; then - echo "$result" + elif [[ $1 == list ]]; then + echo "${result}" else if [[ -f .gitignore ]]; then - result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io") + result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}") echo ".gitignore already exists, appending..." - echo "$result" >> .gitignore - else - echo "$result" > .gitignore fi + echo "${result}" >> .gitignore fi } @@ -257,7 +254,7 @@ function gitignore-reload() { fi # Prompt user to commit or stash changes and exit - if [ $err = 1 ]; then + if [[ "${err}" == 1 ]]; then echo >&2 "Please commit or stash them." fi @@ -265,7 +262,7 @@ function gitignore-reload() { # If we're here, then there are no uncommited or unstaged changes dangling around. # Proceed to reload .gitignore - if [ $err = 0 ]; then + if [[ "${err}" == 0 ]]; then # Remove all cached files git rm -r --cached . @@ -290,6 +287,7 @@ function git-changelog() { return 1 fi + # shellcheck disable=SC2155 local NEXT=$(date +%F) if [[ "$2" == "md" ]]; then @@ -298,9 +296,9 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo "### $DATE" - git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "### ${DATE}" + git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + NEXT=${DATE} done else echo "CHANGELOG $1" @@ -309,9 +307,10 @@ function git-changelog() { # shellcheck disable=SC2162 git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do echo - echo [$DATE] - git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" - NEXT=$DATE + echo "[${DATE}]" + git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00" + # shellcheck disable=SC2034 + NEXT=${DATE} done fi } diff --git a/plugins/available/goenv.plugin.bash b/plugins/available/goenv.plugin.bash index d00fce67a3..17e4a0ffd3 100644 --- a/plugins/available/goenv.plugin.bash +++ b/plugins/available/goenv.plugin.bash @@ -30,7 +30,7 @@ eval "$(goenv init - bash)" # If moving to a directory with a goenv version set, reload the shell # to ensure the shell environment matches expectations. _bash-it-goenv-preexec() { - export GOENV_OLD_VERSION="$(goenv version-name)" + GOENV_OLD_VERSION="$(goenv version-name)" } _bash-it-goenv-precmd() { if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then diff --git a/plugins/available/gradle.plugin.bash b/plugins/available/gradle.plugin.bash index 6267bd842d..8dec1313e7 100644 --- a/plugins/available/gradle.plugin.bash +++ b/plugins/available/gradle.plugin.bash @@ -3,19 +3,10 @@ about-plugin 'Add a gw command to use gradle wrapper if present, else use system function gw() { local file="gradlew" - local curr_path="${PWD}" - local result="gradle" + local result - # Search recursively upwards for file. - until [[ "${curr_path}" == "/" ]]; do - if [[ -e "${curr_path}/${file}" ]]; then - result="${curr_path}/${file}" - break - else - curr_path=$(dirname "${curr_path}") - fi - done + result="$(_bash-it-find-in-ancestor "${file}")" # Call gradle - "${result}" $* + "${result:-gradle}" $* } diff --git a/plugins/available/hub.plugin.bash b/plugins/available/hub.plugin.bash index 0a67a7af08..e9a8cbab48 100644 --- a/plugins/available/hub.plugin.bash +++ b/plugins/available/hub.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load hub, if you are using it' -command -v hub &> /dev/null && eval "$(hub alias -s)" +if _command_exists hub; then + eval "$(hub alias -s)" +fi diff --git a/plugins/available/jekyll.plugin.bash b/plugins/available/jekyll.plugin.bash index 6254a87fed..c340c432cd 100644 --- a/plugins/available/jekyll.plugin.bash +++ b/plugins/available/jekyll.plugin.bash @@ -16,7 +16,7 @@ editpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -77,7 +77,7 @@ newpost() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site JEKYLL_FORMATTING=${MARKUPS[$loc]} @@ -280,7 +280,7 @@ function testsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -312,7 +312,7 @@ function buildsite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site break @@ -347,7 +347,7 @@ function deploysite() { for site in ${SITES[@]} do - if [ "$(basename $site)" = "$1" ] + if [ "${site##*/}" = "$1" ] then SITE=$site REMOTE=${REMOTES[$loc]} diff --git a/plugins/available/jump.plugin.bash b/plugins/available/jump.plugin.bash old mode 100755 new mode 100644 index 26d6467d31..1713d1b703 --- a/plugins/available/jump.plugin.bash +++ b/plugins/available/jump.plugin.bash @@ -1,9 +1,12 @@ +# shellcheck shell=bash +# shellcheck disable=SC2016 cite about-plugin about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding' -__init_jump() { - command -v jump &> /dev/null || return - eval "$(jump shell bash "${JUMP_OPTS[@]}")" +function __init_jump() { + if _command_exists jump; then + eval "$(jump shell bash "${JUMP_OPTS[@]}")" + fi } __init_jump diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index b6b9d1f05b..139e518819 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -1,31 +1,23 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'pygmentize instead of cat to terminal if possible' -if $(command -v pygmentize &> /dev/null) ; then - # get the full paths to binaries - CAT_BIN=$(which cat) - LESS_BIN=$(which less) - BASH_IT_CCAT_STYLE="${BASH_IT_CCAT_STYLE:=default}" - BASH_IT_CLESS_STYLE="${BASH_IT_CLESS_STYLE:=default}" +_command_exists pygmentize || return - # pigmentize cat and less outputs - call them ccat and cless to avoid that - # especially cat'ed output in scripts gets mangled with pygemtized meta characters - function ccat() - { - about 'runs either pygmentize or cat on each file passed in' - param '*: files to concatenate (as normally passed to cat)' - example 'cat mysite/manage.py dir/text-file.txt' - for var; - do - pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var"; - done - } +# pigmentize cat and less outputs - call them ccat and cless to avoid that +# especially cat'ed output in scripts gets mangled with pygemtized meta characters +function ccat() { + about 'runs pygmentize on each file passed in' + param '*: files to concatenate (as normally passed to cat)' + example 'ccat mysite/manage.py dir/text-file.txt' - function cless() - { - about 'it pigments the file passed in and passes it to less for pagination' - param '$1: the file to paginate with less' - example 'less mysite/manage.py' - pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R - } -fi + pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@" +} + +function cless() { + about 'pigments the files passed in and passes to less for pagination' + param '*: the files to paginate with less' + example 'cless mysite/manage.py' + + pygmentize -f 256 -O style="${BASH_IT_CLESS_STYLE:-default}" -g "$@" | command less -R +} diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 65df3da310..8bf876df24 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,13 +1,14 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Node.js helper functions' +# Check that we have npm +_command_exists npm || return + # Ensure local modules are preferred in PATH pathmunge "./node_modules/.bin" "after" -# Check that we have npm -out=$(command -v npm 2>&1) || return - # If not using nodenv, ensure global modules are in PATH -if [[ ! $out == *"nodenv/shims"* ]] ; then - pathmunge "$(npm config get prefix)/bin" "after" +if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then + pathmunge "$(npm config get prefix)/bin" "after" fi diff --git a/plugins/available/nodenv.plugin.bash b/plugins/available/nodenv.plugin.bash index 1bbe7fbde7..262a57c399 100644 --- a/plugins/available/nodenv.plugin.bash +++ b/plugins/available/nodenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load nodenv, if you are using it' export NODENV_ROOT="$HOME/.nodenv" pathmunge "$NODENV_ROOT/bin" -[[ `which nodenv` ]] && eval "$(nodenv init - bash)" +if _command_exists nodenv; then + eval "$(nodenv init - bash)" +fi diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index e845d9229b..0e6da5d8cf 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -1,22 +1,23 @@ -# Bash-it no longer bundles nvm, as this was quickly becoming outdated. +# shellcheck shell=bash # # BASH_IT_LOAD_PRIORITY: 225 # +# Bash-it no longer bundles nvm, as this was quickly becoming outdated. # Please install nvm from https://github.com/creationix/nvm.git if you want to use it. cite about-plugin about-plugin 'node version manager configuration' -export NVM_DIR=${NVM_DIR:-$HOME/.nvm} +export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" # This loads nvm -if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] +if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] then - . $(brew --prefix nvm)/nvm.sh + source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" else - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi -if ! command -v nvm &>/dev/null +if ! _command_exists nvm then function nvm() { echo "Bash-it no longer bundles the nvm script. Please install the latest version from" diff --git a/plugins/available/osx-timemachine.plugin.bash b/plugins/available/osx-timemachine.plugin.bash index f29d6ece98..3d7ff00c92 100644 --- a/plugins/available/osx-timemachine.plugin.bash +++ b/plugins/available/osx-timemachine.plugin.bash @@ -15,7 +15,7 @@ function time-machine-list-machines() { local tmdest="$(time-machine-destination)/Backups.backupdb" find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do - echo "$(basename "$line")" + echo "${line##*/}" done } diff --git a/plugins/available/osx.plugin.bash b/plugins/available/osx.plugin.bash index 2c16820c49..ca1f66b879 100644 --- a/plugins/available/osx.plugin.bash +++ b/plugins/available/osx.plugin.bash @@ -2,7 +2,7 @@ cite about-plugin about-plugin 'osx-specific functions' # OS X: Open new tabs in same directory -if [ $(uname) = "Darwin" ]; then +if [[ $OSTYPE == 'darwin'* ]]; then if type update_terminal_cwd > /dev/null 2>&1 ; then if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd" @@ -46,13 +46,13 @@ function dock-switch() { example '$ dock-switch 2d' group 'osx' - if [ $(uname) = "Darwin" ]; then + if [[ "$OSTYPE" = 'darwin'* ]]; then - if [ $1 = 3d ] ; then + if [[ $1 = 3d ]] ; then defaults write com.apple.dock no-glass -boolean NO killall Dock - elif [ $1 = 2d ] ; then + elif [[ $1 = 2d ]] ; then defaults write com.apple.dock no-glass -boolean YES killall Dock @@ -90,7 +90,7 @@ function prevcurl() { param '1: url' group 'osx' - if [ ! $(uname) = "Darwin" ] + if [[ ! $OSTYPE = 'darwin'* ]] then echo "This function only works with Mac OS X" return 1 @@ -103,7 +103,7 @@ function refresh-launchpad() { example '$ refresh-launchpad' group 'osx' - if [ $(uname) = "Darwin" ];then + if [[ "$OSTYPE" = 'darwin'* ]];then defaults write com.apple.dock ResetLaunchPad -bool TRUE killall Dock else diff --git a/plugins/available/percol.plugin.bash b/plugins/available/percol.plugin.bash index c1fc807cd7..027dfdc4af 100644 --- a/plugins/available/percol.plugin.bash +++ b/plugins/available/percol.plugin.bash @@ -1,3 +1,4 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Search&Select history with percol' @@ -12,24 +13,20 @@ about-plugin 'Search&Select history with percol' # Usage ## C-r to search&select from history -_replace_by_history() { - if command -v tac>/dev/null; then - alias _tac=tac - else - alias _tac="tail -r" - fi - local l=$(HISTTIMEFORMAT= history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "$READLINE_LINE") - READLINE_LINE="$l" - READLINE_POINT=${#l} -} - +_command_exists percol || return -if command -v percol>/dev/null; then - current_version=${BASH_VERSION%%[^0-9]*} - if [ $current_version -lt 4 ]; then - echo -e "\033[91mWarning: You have to upgrade Bash to Bash v4.x to use the 'percol' plugin.\033[m" - echo -e "\033[91m Your current Bash version is $BASH_VERSION.\033[m" - else - bind -x '"\C-r": _replace_by_history' - fi +if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then + _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin." + _log_warning "Your current Bash version is $BASH_VERSION." + return fi + +function _replace_by_history() { + local HISTTIMEFORMAT= # Ensure we can parse history properly + #TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}" + local l + l="$(history | tail -r | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")" + READLINE_LINE="${l}" + READLINE_POINT=${#l} +} +bind -x '"\C-r": _replace_by_history' diff --git a/plugins/available/plenv.plugin.bash b/plugins/available/plenv.plugin.bash index 1da2d61bfa..79a9cf4964 100644 --- a/plugins/available/plenv.plugin.bash +++ b/plugins/available/plenv.plugin.bash @@ -1,18 +1,16 @@ +# shellcheck shell=bash +# # plugin for plenv cite about-plugin about-plugin 'plenv plugin for Perl' -if [[ -e "${HOME}/.plenv/bin" ]] ; then - - # load plenv bin dir into path if it exists - pathmunge "${HOME}/.plenv/bin" - +if [[ -d "${HOME}/.plenv/bin" ]]; then + # load plenv bin dir into path if it exists + pathmunge "${HOME}/.plenv/bin" fi -if [[ `which plenv` ]] ; then - - # init plenv - eval "$(plenv init - bash)" - +if _command_exists plenv; then + # init plenv + eval "$(plenv init - bash)" fi diff --git a/plugins/available/powerline.plugin.bash b/plugins/available/powerline.plugin.bash index 3d91e658ed..1927bf3e24 100644 --- a/plugins/available/powerline.plugin.bash +++ b/plugins/available/powerline.plugin.bash @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite about-plugin about-plugin 'enables powerline daemon' -command -v powerline-daemon &>/dev/null || return +_command_exists powerline-daemon || return powerline-daemon -q #the following should not be executed if bashit powerline themes in use @@ -14,13 +14,13 @@ case "$BASH_IT_THEME" in esac POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 -bashPowerlineInit=$(python -c \ +bashPowerlineInit="$(python -c \ "import os; \ import powerline;\ print(os.path.join(os.path.dirname(\ powerline.__file__),\ 'bindings', \ 'bash', \ - 'powerline.sh'))") + 'powerline.sh'))")" [ -e $bashPowerlineInit ] || return -. $bashPowerlineInit +source $bashPowerlineInit diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 4d8db4fb93..05d2847812 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -1,12 +1,34 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load pyenv, if you are using it' -export PYENV_ROOT="$HOME/.pyenv" -pathmunge "$PYENV_ROOT/bin" +# https://github.com/pyenv/pyenv -[[ `which pyenv 2>/dev/null` ]] && eval "$(pyenv init - bash)" +# Load after basher +# BASH_IT_LOAD_PRIORITY: 260 -#Load pyenv virtualenv if the virtualenv plugin is installed. +# Don't modify the environment if we can't find the tool: +# - Check if in $PATH already +# - Check if installed manually to $PYENV_ROOT +# - Check if installed manually to $HOME +_command_exists pyenv \ + || [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \ + || [[ -x "$HOME/.pyenv/bin/pyenv" ]] \ + || return 0 + +# Set PYENV_ROOT, if not already set +export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}" + +# Add PYENV_ROOT/bin to PATH, if that's where it's installed +if ! _command_exists pyenv && [[ -x "$PYENV_ROOT/bin/pyenv" ]]; then + pathmunge "$PYENV_ROOT/bin" +fi + +# Initialize pyenv +pathmunge "$PYENV_ROOT/shims" +eval "$(pyenv init - bash)" + +# Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then - eval "$(pyenv virtualenv-init - bash)" + eval "$(pyenv virtualenv-init - bash)" fi diff --git a/plugins/available/python.plugin.bash b/plugins/available/python.plugin.bash index ceba6268b5..77fa7dd674 100644 --- a/plugins/available/python.plugin.bash +++ b/plugins/available/python.plugin.bash @@ -1,7 +1,7 @@ cite about-plugin about-plugin 'alias "shttp" to SimpleHTTPServer' -if [ $(uname) = "Linux" ] +if [[ "$OSTYPE" == 'linux'* ]] then alias shttp='python2 -m SimpleHTTPServer' else @@ -16,7 +16,7 @@ function pyedit() { xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"` - if [ "$xpyc" == "" ]; then + if [[ "$xpyc" == "" ]]; then echo "Python module $1 not found" return -1 diff --git a/plugins/available/rbenv.plugin.bash b/plugins/available/rbenv.plugin.bash index 2b01669de2..f3605f585c 100644 --- a/plugins/available/rbenv.plugin.bash +++ b/plugins/available/rbenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load rbenv, if you are using it' export RBENV_ROOT="$HOME/.rbenv" pathmunge "$RBENV_ROOT/bin" -[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)" +if _command_exists rbenv; then + eval "$(rbenv init - bash)" +fi diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index 4ab891d9f9..aed8daf8cd 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -1,16 +1,17 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ -if which ruby >/dev/null && which gem >/dev/null; then - pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after +if _command_exists ruby && _command_exists gem; then + pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after fi -function remove_gem { - about 'removes installed gem' - param '1: installed gem name' - group 'ruby' +function remove_gem() { + about 'removes installed gem' + param '1: installed gem name' + group 'ruby' - gem list | grep $1 | awk '{ print $1; }' | xargs sudo gem uninstall + gem list | grep "${1:?${FUNCNAME[0]}: no gem name provided}" | awk '{ print $1; }' | xargs sudo gem uninstall } diff --git a/plugins/available/textmate.plugin.bash b/plugins/available/textmate.plugin.bash index e3538c1e10..5c81f195ac 100644 --- a/plugins/available/textmate.plugin.bash +++ b/plugins/available/textmate.plugin.bash @@ -1,7 +1,9 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'set textmate as a default editor' -if $(command -v mate &> /dev/null) ; then - export EDITOR="$(which mate) -w" - export GIT_EDITOR=$EDITOR +if _command_exists mate; then + EDITOR="$(type -p mate) -w" + GIT_EDITOR="$EDITOR" + export EDITOR GIT_EDITOR fi diff --git a/plugins/available/todo.plugin.bash b/plugins/available/todo.plugin.bash old mode 100755 new mode 100644 diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index 468870cd4e..41d55ddfb1 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -1,12 +1,14 @@ +# shellcheck shell=bash +# # make sure virtualenvwrapper is enabled if available cite about-plugin about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions' if _command_exists pyenv; then - pyenv virtualenvwrapper -else - [[ `which virtualenvwrapper.sh` ]] && . virtualenvwrapper.sh + pyenv virtualenvwrapper +elif _command_exists virtualenvwrapper.sh; then + source virtualenvwrapper.sh fi @@ -14,8 +16,8 @@ function mkvenv { about 'create a new virtualenv for this directory' group 'virtualenv' - cwd=`basename \`pwd\`` - mkvirtualenv --distribute $cwd + local cwd="${PWD##*/}" + mkvirtualenv --distribute "$cwd" } @@ -23,19 +25,21 @@ function mkvbranch { about 'create a new virtualenv for the current branch' group 'virtualenv' - mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" } function wovbranch { about 'sets workon branch' group 'virtualenv' - workon "$(basename `pwd`)@$SCM_BRANCH" + local cwd="${PWD##*/}" + workon "${cwd}@${SCM_BRANCH}" } function wovenv { about 'works on the virtualenv for this directory' group 'virtualenv' - workon "$(basename `pwd`)" + workon "${PWD##*/}" } diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index 4f4fd50d2d..b8747a2584 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -3,29 +3,37 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' _short-dirname() { - local dir_name=$(dirs +0) - [ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" + local dir_name="${PWD/~/\~}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then + echo "${dir_name##*/}" + else + echo "${dir_name}" + fi } _short-command() { local input_command="$*" - [ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" + if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then + echo "${input_command%% *}" + else + echo "${input_command}" + fi } set_xterm_title() { - local title="$1" - echo -ne "\033]0;$title\007" + local title="${1:-}" + echo -ne "\033]0;${title}\007" } precmd_xterm_title() { - set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR" + set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}" } preexec_xterm_title() { - set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" + set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" } -case "$TERM" in +case "${TERM:-dumb}" in xterm* | rxvt*) precmd_functions+=(precmd_xterm_title) preexec_functions+=(preexec_xterm_title) diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 553a7ba3ea..a2f97d2833 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -11,7 +11,7 @@ autoenv_init() typeset target home _file typeset -a _files target=$1 - home="$(dirname "$HOME")" + home="${HOME%/*}" _files=( $( while [[ "$PWD" != "/" && "$PWD" != "$home" ]] diff --git a/scripts/reloader.bash b/scripts/reloader.bash old mode 100644 new mode 100755 index f22de67e81..4bc2494132 --- a/scripts/reloader.bash +++ b/scripts/reloader.bash @@ -5,6 +5,7 @@ function _set-prefix-based-on-path() { filename=$(_bash-it-get-component-name-from-path "$1") extension=$(_bash-it-get-component-type-from-path "$1") + # shellcheck disable=SC2034 BASH_IT_LOG_PREFIX="$extension: $filename: " } @@ -15,7 +16,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then alias|completion|plugin) _bash_it_config_type=$1 _log_debug "Loading enabled $1 components..." ;; - *|'') + ''|*) _log_debug "Loading all enabled components..." ;; esac diff --git a/test/fixtures/svn/broken/xcrun b/test/fixtures/svn/broken/xcrun new file mode 100755 index 0000000000..e69de29bb2 diff --git a/test/fixtures/svn/working/xcrun b/test/fixtures/svn/working/xcrun new file mode 100755 index 0000000000..e69de29bb2 diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index e60d5542ab..7f6664e04f 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -5,11 +5,11 @@ load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/utilities load ../../lib/search -load ../../plugins/available/base.plugin cite _about _param _example _group _author _version load ../../lib/helpers +load ../../plugins/available/base.plugin function local_setup { setup_test_fixture diff --git a/test/lib/log.bats b/test/lib/log.bats index 015068e68b..329386bd39 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -3,27 +3,28 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/appearance -load ../../plugins/available/base.plugin cite _about _param _example _group _author _version load ../../lib/log +load ../../lib/helpers +load ../../plugins/available/base.plugin @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL run _log_debug "test test test" - assert_output "DEBUG: test test test" + assert_output "DEBUG: default: test test test" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL run _log_warning "test test test" - assert_output " WARN: test test test" + assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { @@ -35,13 +36,13 @@ load ../../lib/log @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING run _log_warning "test test test" - assert_output " WARN: test test test" + assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @@ -60,7 +61,7 @@ load ../../lib/log @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR run _log_error "test test test" - assert_output "ERROR: test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 7daf26197f..6f1099cc08 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -2,6 +2,8 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load ../../lib/log +load ../../lib/helpers load ../../plugins/available/base.plugin @test 'plugins base: ips()' { @@ -40,7 +42,7 @@ load ../../plugins/available/base.plugin mkcd "${dir_name}" assert_success assert_dir_exist "${BASH_IT_ROOT}/${dir_name}" - assert_equal $(pwd) "${BASH_IT_ROOT}/${dir_name}" + assert_equal "${PWD}" "${BASH_IT_ROOT}/${dir_name}" } @test 'plugins base: lsgrep()' { diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats old mode 100644 new mode 100755 index 9af49697fc..fda52b020d --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -2,6 +2,8 @@ load ../test_helper load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load "${BASH_IT}/lib/log.bash" +load "${BASH_IT}/lib/helpers.bash" cite _about _param _example _group _author _version diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index c53f359f1f..110699e898 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -4,50 +4,52 @@ load ../test_helper load ../../lib/helpers load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +# We test `go version` in each test to account for users with goenv and no system go. + @test 'ensure _bash-it-gopath-pathmunge is defined' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' load ../../plugins/available/go.plugin run type -t _bash-it-gopath-pathmunge assert_line 'function' } @test 'plugins go: single entry in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin" } @test 'plugins go: single entry in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin" } @test 'plugins go: single entry in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin" } @test 'plugins go: multiple entries in GOPATH' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { - { [[ $CI ]] || _command_exists go; } || skip 'golang not found' + { _command_exists go && go version &>/dev/null; } || skip 'golang not found' export GOPATH="/foo:/foo\ bar" load ../../plugins/available/go.plugin assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin" diff --git a/test/run b/test/run index 8820291640..fe4ac8477d 100755 --- a/test/run +++ b/test/run @@ -6,7 +6,7 @@ git submodule init && git submodule update if [ -z "${BASH_IT}" ]; then declare BASH_IT - BASH_IT=$(cd ${test_directory} && dirname "$(pwd)") + BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" export BASH_IT fi diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index f2866c8da1..d1c2c31164 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -7,7 +7,6 @@ load ../../lib/log cite _about _param _example _group _author _version load ../../lib/helpers -load ../../themes/base.theme function local_setup { setup_test_fixture @@ -23,6 +22,8 @@ function local_setup { fi export OLD_PATH="$PATH" + + load ../../themes/base.theme } function local_teardown { @@ -56,8 +57,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -73,8 +74,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that the SVN command is used @@ -89,8 +90,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Load the base theme again so that the working SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the working SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used @@ -103,8 +104,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used @@ -120,8 +121,8 @@ function setup_svn_path { setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Load the base theme again so that the broken SVN script is detected - load ../../themes/base.theme + # Init the base theme again so that the broken SVN script is detected + _bash_it_appearance_scm_init scm # Make sure that no SVN command is used diff --git a/themes/90210/90210.theme.bash b/themes/90210/90210.theme.bash index 180764c869..3db3f17bae 100644 --- a/themes/90210/90210.theme.bash +++ b/themes/90210/90210.theme.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" SCM_THEME_PROMPT_PREFIX=" |" @@ -11,7 +14,7 @@ GIT_THEME_PROMPT_SUFFIX="${green}|" # Nicely formatted terminal prompt function prompt_command() { - export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " + PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " } safe_append_prompt_command prompt_command diff --git a/themes/agnoster/agnoster.theme.bash b/themes/agnoster/agnoster.theme.bash index ba3e2c9a84..20c184f382 100644 --- a/themes/agnoster/agnoster.theme.bash +++ b/themes/agnoster/agnoster.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # vim: ft=bash ts=2 sw=2 sts=2 # # agnoster's Theme - https://gist.github.com/3712874 @@ -220,7 +221,7 @@ prompt_virtualenv() { # Context: user@hostname (who am I and where am I) prompt_context() { - local user=$(whoami) + local user="${USER:-${LOGNAME:?}}" if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then prompt_segment black default "$user@\h" diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 6bde68011d..03dc9e9562 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Atomic Bash Prompt for Bash-it # By lfelipe base on the theme brainy of MunifTanjim diff --git a/themes/bakke/bakke.theme.bash b/themes/bakke/bakke.theme.bash index 725350a036..d7bfbbe836 100644 --- a/themes/bakke/bakke.theme.bash +++ b/themes/bakke/bakke.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/barbuk/barbuk.theme.bash b/themes/barbuk/barbuk.theme.bash index 8e09d4be3b..b614d148c1 100644 --- a/themes/barbuk/barbuk.theme.bash +++ b/themes/barbuk/barbuk.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Theme custom glyphs SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '} diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a1520397eb..f9f5190d19 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX='' @@ -85,42 +86,61 @@ RBENV_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_SUFFIX='|' -GIT_EXE=$(which git 2> /dev/null || true) -P4_EXE=$(which p4 2> /dev/null || true) -HG_EXE=$(which hg 2> /dev/null || true) -SVN_EXE=$(which svn 2> /dev/null || true) - -# Check for broken SVN exe that is caused by some versions of Xcode. -# See https://github.com/Bash-it/bash-it/issues/1612 for more details. -if [[ -x "$SVN_EXE" ]]; then - if ! "$SVN_EXE" --version > /dev/null 2>&1; then - # Unset the SVN exe variable so that SVN commands are avoided. - SVN_EXE="" +: "${GIT_EXE:=$SCM_GIT}" +: "${P4_EXE:=$SCM_P4}" +: "${HG_EXE:=$SCM_HG}" +: "${SVN_EXE:=$SCM_SVN}" + +function _bash_it_appearance_scm_init() { + GIT_EXE="$(type -P $SCM_GIT || true)" + P4_EXE="$(type -P $SCM_P4 || true)" + HG_EXE="$(type -P $SCM_HG || true)" + SVN_EXE="$(type -P $SCM_SVN || true)" + + # Check for broken SVN exe that is caused by some versions of Xcode. + # See https://github.com/Bash-it/bash-it/issues/1612 for more details. + if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then + if ! "$SVN_EXE" --version > /dev/null 2>&1; then + # Unset the SVN exe variable so that SVN commands are avoided. + SVN_EXE="" + fi fi -fi +} +_bash_it_appearance_scm_init function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then - SCM=$SCM_GIT - elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then - SCM=$SCM_P4 elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then SCM=$SCM_HG - elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then - SCM=$SCM_HG elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then SCM=$SCM_SVN + elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then + SCM=$SCM_GIT + elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then + SCM=$SCM_HG elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then SCM=$SCM_SVN + elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then + SCM=$SCM_P4 else SCM=$SCM_NONE fi } +scm_prompt() { + local CHAR + CHAR="$(scm_char)" + local format=${SCM_PROMPT_FORMAT:-'[%s%s]'} + + if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then + # shellcheck disable=2059 + printf "$format\n" "$CHAR" "$(scm_prompt_info)" + fi +} + function scm_prompt_char { if [[ -z $SCM ]]; then scm; fi if [[ $SCM == "$SCM_GIT" ]]; then @@ -332,15 +352,15 @@ function svn_prompt_vars { # - .hg is located in ~/Projects/Foo/.hg # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo function get_hg_root { - local CURRENT_DIR=$(pwd) + local CURRENT_DIR="${PWD}" - while [ "$CURRENT_DIR" != "/" ]; do - if [ -d "$CURRENT_DIR/.hg" ]; then + while [[ "${CURRENT_DIR:-/}" != "/" ]]; do + if [[ -d "$CURRENT_DIR/.hg" ]]; then echo "$CURRENT_DIR/.hg" return fi - CURRENT_DIR=$(dirname "$CURRENT_DIR") + CURRENT_DIR="${CURRENT_DIR%/*}" done } @@ -376,7 +396,7 @@ function hg_prompt_vars { function nvm_version_prompt { local node - if declare -f -F nvm &> /dev/null; then + if _is_function nvm; then node=$(nvm current 2> /dev/null) [[ "${node}" == "system" ]] && return echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}" @@ -413,8 +433,8 @@ function rbfu_version_prompt { } function chruby_version_prompt { - if declare -f -F chruby &> /dev/null; then - if declare -f -F chruby_auto &> /dev/null; then + if _is_function chruby; then + if _is_function chruby_auto; then chruby_auto fi @@ -437,6 +457,10 @@ function k8s_context_prompt { echo -e "$(kubectl config current-context 2> /dev/null)" } +function k8s_namespace_prompt { + echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)" +} + function virtualenv_prompt { if [[ -n "$VIRTUAL_ENV" ]]; then virtualenv=$(basename "$VIRTUAL_ENV") @@ -528,7 +552,7 @@ function prompt_char { function battery_char { if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then - echo -e "${bold_red}$(battery_percentage)%" + echo -e "${bold_red:-}$(battery_percentage)%" fi } @@ -570,7 +594,7 @@ function __check_precmd_conflict() { function safe_append_prompt_command { local prompt_re - if [ "${__bp_imported}" == "defined" ]; then + if [ "${__bp_imported:-missing}" == "defined" ]; then # We are using bash-preexec if ! __check_precmd_conflict "${1}"; then precmd_functions+=("${1}") @@ -585,7 +609,7 @@ function safe_append_prompt_command { prompt_re="\<${1}\>" fi - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then + if [[ ${PROMPT_COMMAND[*]:-} =~ ${prompt_re} ]]; then return elif [[ -z ${PROMPT_COMMAND} ]]; then PROMPT_COMMAND="${1}" diff --git a/themes/binaryanomaly/binaryanomaly.theme.bash b/themes/binaryanomaly/binaryanomaly.theme.bash index f6740f351d..c4488c4c96 100644 --- a/themes/binaryanomaly/binaryanomaly.theme.bash +++ b/themes/binaryanomaly/binaryanomaly.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Detect whether a reboot is required function show_reboot_required() { @@ -31,15 +33,6 @@ function set_user_color() { esac } -scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo "[$(scm_char)$(scm_prompt_info)]" - fi -} - # Define custom colors we need # non-printable bytes in PS1 need to be contained within \[ \]. # Otherwise, bash will count them in the length of the prompt diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index ae8f0efe1e..7db03000cd 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX=" ${yellow}‹" SCM_THEME_PROMPT_SUFFIX="›${reset_color}" diff --git a/themes/bobby-python/bobby-python.theme.bash b/themes/bobby-python/bobby-python.theme.bash index 9144e2519f..ebb3eab075 100644 --- a/themes/bobby-python/bobby-python.theme.bash +++ b/themes/bobby-python/bobby-python.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/bobby/bobby.theme.bash b/themes/bobby/bobby.theme.bash index bdf388f72a..98d2cd8d8b 100644 --- a/themes/bobby/bobby.theme.bash +++ b/themes/bobby/bobby.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${red}✗" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index db8377baf4..e1c3617531 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. # Brainy Bash Prompt for Bash-it # by MunifTanjim diff --git a/themes/brunton/brunton.theme.bash b/themes/brunton/brunton.theme.bash index c0bfd49ff2..166fcc84f8 100644 --- a/themes/brunton/brunton.theme.bash +++ b/themes/brunton/brunton.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" @@ -15,16 +17,8 @@ is_vim_shell() { fi } -scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo " $(scm_char) (${white}$(scm_prompt_info)${normal})" - fi -} - prompt() { + SCM_PROMPT_FORMAT=' %s (%s)' PS1="${white}${background_blue} \u${normal}${background_blue}@${red}${background_blue}\h $(clock_prompt) ${reset_color}${normal} $(battery_charge)\n${bold_black}${background_white} \w ${normal}$(scm_prompt)$(is_vim_shell)\n${white}>${normal} " } diff --git a/themes/candy/candy.theme.bash b/themes/candy/candy.theme.bash index be53d37356..7753e93426 100644 --- a/themes/candy/candy.theme.bash +++ b/themes/candy/candy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. function prompt_command() { PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} ${normal}" diff --git a/themes/codeword/codeword.theme.bash b/themes/codeword/codeword.theme.bash index 96723ce345..beab6a4a79 100644 --- a/themes/codeword/codeword.theme.bash +++ b/themes/codeword/codeword.theme.bash @@ -1,18 +1,10 @@ +# shellcheck shell=bash + SCM_THEME_PROMPT_PREFIX=${SCM_THEME_PROMPT_SUFFIX} SCM_THEME_PROMPT_DIRTY="${bold_red} ✗${normal}" SCM_THEME_PROMPT_CLEAN="${bold_green} ✓${normal}" SCM_GIT_CHAR="${green}±${normal}" -scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo " [$(scm_char)$(scm_prompt_info)]" - fi -} - mark_prompt() { echo "${green}\$${normal}" } @@ -25,14 +17,9 @@ user_host_path_prompt() { } prompt() { + SCM_PROMPT_FORMAT=' [%s%s]' PS1="$(user_host_path_prompt)$(virtualenv_prompt)$(scm_prompt) $(mark_prompt) " } -share_history() { - history -a - history -c - history -r -} - -safe_append_prompt_command share_history +safe_append_prompt_command '_save-and-reload-history 1' safe_append_prompt_command prompt diff --git a/themes/colors.theme.bash b/themes/colors.theme.bash index fbb1dc5c04..d5044d0505 100644 --- a/themes/colors.theme.bash +++ b/themes/colors.theme.bash @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2005 +# shellcheck disable=SC2034 function __ { echo "$@" diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index e85c18f7ca..7d8d6cc8fe 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -98,7 +98,7 @@ prompt() { local MOVE_CURSOR_RIGHTMOST='\033[500C' local MOVE_CURSOR_5_LEFT='\033[5D' - if [ $(uname) = "Linux" ]; + if [[ "$OSTYPE" = 'linux'* ]] then PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} $(safe_battery_charge)${RESTORE_CURSOR}\ diff --git a/themes/doubletime/doubletime.theme.bash b/themes/doubletime/doubletime.theme.bash index 3f686668b0..8186db736b 100644 --- a/themes/doubletime/doubletime.theme.bash +++ b/themes/doubletime/doubletime.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash SCM_THEME_PROMPT_DIRTY='' SCM_THEME_PROMPT_CLEAN='' @@ -28,45 +28,14 @@ else THEME_PROMPT_HOST_COLOR="$blue" fi -doubletime_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ]; then - return - elif [ $CHAR = $SCM_GIT_CHAR ]; then - echo "$(git_prompt_status)" - else - echo "[$(scm_prompt_info)]" - fi -} - function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [${THEME_PROMPT_HOST_COLOR}\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt)\w -$(doubletime_scm_prompt)$reset_color $ " +$(scm_prompt)$reset_color $ " PS2='> ' PS4='+ ' } safe_append_prompt_command prompt_setter - -git_prompt_status() { - local git_status_output - git_status_output=$(git status 2> /dev/null ) - if [ -n "$(echo $git_status_output | grep 'Changes not staged')" ]; then - git_status="${bold_red}$(scm_prompt_info) ✗" - elif [ -n "$(echo $git_status_output | grep 'Changes to be committed')" ]; then - git_status="${bold_yellow}$(scm_prompt_info) ^" - elif [ -n "$(echo $git_status_output | grep 'Untracked files')" ]; then - git_status="${bold_cyan}$(scm_prompt_info) +" - elif [ -n "$(echo $git_status_output | grep 'nothing to commit')" ]; then - git_status="${bold_green}$(scm_prompt_info) ${green}✓" - else - git_status="$(scm_prompt_info)" - fi - echo "[$git_status${normal}]" - -} diff --git a/themes/doubletime_multiline/doubletime_multiline.theme.bash b/themes/doubletime_multiline/doubletime_multiline.theme.bash index 6da882533b..182135717d 100644 --- a/themes/doubletime_multiline/doubletime_multiline.theme.bash +++ b/themes/doubletime_multiline/doubletime_multiline.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt)$(ruby_version_prompt) \w diff --git a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash index 5f1951e935..9bc4c33486 100644 --- a/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash +++ b/themes/doubletime_multiline_pyonly/doubletime_multiline_pyonly.theme.bash @@ -1,12 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash source "$BASH_IT/themes/doubletime/doubletime.theme.bash" function prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1=" $(clock_prompt) $(scm_char) [$THEME_PROMPT_HOST_COLOR\u@${THEME_PROMPT_HOST}$reset_color] $(virtualenv_prompt) \w diff --git a/themes/dulcie/dulcie.theme.bash b/themes/dulcie/dulcie.theme.bash old mode 100644 new mode 100755 index a83b62fbc5..f70c786491 --- a/themes/dulcie/dulcie.theme.bash +++ b/themes/dulcie/dulcie.theme.bash @@ -77,7 +77,7 @@ dulcie_prompt() { printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" # Open the new terminal in the same directory - declare -f __vte_osc7 > /dev/null && __vte_osc7 + _is_function __vte_osc7 && __vte_osc7 PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then diff --git a/themes/easy/easy.theme.bash b/themes/easy/easy.theme.bash index a48eb8243a..7e2e3389ef 100644 --- a/themes/easy/easy.theme.bash +++ b/themes/easy/easy.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="${bold_green}[ ${normal}" SCM_THEME_PROMPT_SUFFIX="${bold_green} ] " diff --git a/themes/gallifrey/gallifrey.theme.bash b/themes/gallifrey/gallifrey.theme.bash index ddb89778c2..3ba48d71f5 100644 --- a/themes/gallifrey/gallifrey.theme.bash +++ b/themes/gallifrey/gallifrey.theme.bash @@ -4,26 +4,18 @@ SCM_THEME_PROMPT_SUFFIX=")${normal}" SCM_THEME_PROMPT_DIRTY="*" SCM_THEME_PROMPT_CLEAN="" -SCM_GIT_CHAR="g" -SCM_SVN_CHAR="s" -SCM_HG_CHAR="h" +SCM_GIT_CHAR="${green}±${normal}" +SCM_SVN_CHAR="${bold_cyan}⑆${normal}" +SCM_HG_CHAR="${bold_red}☿${normal}" ### TODO: openSUSE has already colors enabled, check if those differs from stock # LS colors, made with http://geoff.greer.fm/lscolors/ # export LSCOLORS="Gxfxcxdxbxegedabagacad" # export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' -scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "$(scm_prompt_info) " - fi -} +gallifrey_prompt() { + SCM_PROMPT_FORMAT='%s%s' -pure_prompt() { ps_host="${green}\h${normal}"; ps_user_mark="${bold}\$${normal}"; ps_root_mark="${normal}§" @@ -38,4 +30,4 @@ pure_prompt() { esac } -safe_append_prompt_command pure_prompt +safe_append_prompt_command gallifrey_prompt diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash old mode 100755 new mode 100644 diff --git a/themes/mairan/mairan.theme.bash b/themes/mairan/mairan.theme.bash index e6728824b5..89466ead07 100644 --- a/themes/mairan/mairan.theme.bash +++ b/themes/mairan/mairan.theme.bash @@ -69,16 +69,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$GREEN$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -99,7 +89,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT="[%s$GREEN%s]" my_ps_host="$BOLD$ORANGE\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="$ORANGE\h${normal}"; @@ -114,10 +104,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + 0) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" ;; - *) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} + *) PS1="\n${TITLEBAR}${BRACKET_COLOR}┌─${normal}$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)${normal}$(__my_rvm_ruby_version)[${green}\w${normal}]$(is_vim_shell)${BRACKET_COLOR} └─▪ ${prompt_symbol} ${normal}" ;; esac diff --git a/themes/modern-t/modern-t.theme.bash b/themes/modern-t/modern-t.theme.bash index 48e923aa48..197f5a2345 100644 --- a/themes/modern-t/modern-t.theme.bash +++ b/themes/modern-t/modern-t.theme.bash @@ -32,26 +32,17 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' if [ $? -ne 0 ] then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. - PS1="${TITLEBAR}${bold_red}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]${reset_color}$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}${bold_red}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]${reset_color}$(scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) ${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]$(modern_scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}┌─[${cyan}$(t | wc -l | sed -e's/ *//')${reset_color}]$(scm_prompt)[${cyan}\W${normal}]$(is_vim_shell) └─▪ " fi } diff --git a/themes/modern-time/modern-time.theme.bash b/themes/modern-time/modern-time.theme.bash index e42226df14..fc8458fffe 100644 --- a/themes/modern-time/modern-time.theme.bash +++ b/themes/modern-time/modern-time.theme.bash @@ -28,30 +28,21 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - modern_current_time_prompt() { echo "[$(date '+%l:%M%p')]" } prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' if [ $? -ne 0 ] then # Yes, the indenting on these is weird, but it has to be like # this otherwise it won't display properly. - PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) ${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) + PS1="${TITLEBAR}┌─$(scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell) └─▪ " fi } diff --git a/themes/modern/modern.theme.bash b/themes/modern/modern.theme.bash index f14fd4fddc..eadb07624f 100644 --- a/themes/modern/modern.theme.bash +++ b/themes/modern/modern.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" @@ -26,15 +28,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - detect_venv() { python_venv="" # Detect python venv @@ -46,11 +39,12 @@ detect_venv() { } prompt() { + SCM_PROMPT_FORMAT='[%s][%s]' retval=$? if [[ retval -ne 0 ]]; then - PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} " + PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n${bold_red}└─▪${normal} " else - PS1="${TITLEBAR}┌─$(modern_scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ " + PS1="${TITLEBAR}┌─$(scm_prompt)[${cyan}\u${normal}][${cyan}\w${normal}]$(is_vim_shell)\n└─▪ " fi detect_venv PS1+="${python_venv}${dir_color}" diff --git a/themes/nwinkler/nwinkler.theme.bash b/themes/nwinkler/nwinkler.theme.bash index f9fe4933cc..983c8d0020 100644 --- a/themes/nwinkler/nwinkler.theme.bash +++ b/themes/nwinkler/nwinkler.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -29,9 +29,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [${blue}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash index f6eff908d7..05391b0b7b 100644 --- a/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash +++ b/themes/nwinkler_random_colors/nwinkler_random_colors.theme.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # Two line prompt showing the following information: # (time) SCM [username@hostname] pwd (SCM branch SCM status) @@ -96,9 +96,7 @@ prompt_setter() { else PROMPT_END=$PROMPT_END_DIRTY fi # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)${reset_color}) $(scm_char) [${USERNAME_COLOR}\u${reset_color}@${HOSTNAME_COLOR}\H${reset_color}] ${PATH_COLOR}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) " PS2='> ' PS4='+ ' diff --git a/themes/pete/pete.theme.bash b/themes/pete/pete.theme.bash index 73fdb05318..d29553f82d 100644 --- a/themes/pete/pete.theme.bash +++ b/themes/pete/pete.theme.bash @@ -1,10 +1,8 @@ -#!/usr/bin/env bash +# shellcheck shell=bash prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 PS1="($(clock_prompt)) $(scm_char) [$blue\u$reset_color@$green\H$reset_color] $yellow\w${reset_color}$(scm_prompt_info)$(ruby_version_prompt) $reset_color " PS2='> ' PS4='+ ' diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index e15c362178..b1c4efbadb 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -55,6 +55,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} @@ -94,6 +97,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} +COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129} + POWERLINE_LEFT_PROMPT=${POWERLINE_LEFT_PROMPT:="scm python_venv ruby node cwd"} POWERLINE_RIGHT_PROMPT=${POWERLINE_RIGHT_PROMPT:="in_vim clock battery user_info"} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 72c986baab..a857675717 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -50,6 +50,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 9ea6cde929..bdba9bd0a7 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -47,6 +47,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=60} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index ed0499c7f6..ce4fc29023 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -1,4 +1,7 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + # Define this here so it can be used by all of the Powerline themes THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true} @@ -85,6 +88,16 @@ function __powerline_k8s_context_prompt() { [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}" } +function __powerline_k8s_namespace_prompt() { + local kubernetes_namespace="" + + if _command_exists kubectl; then + kubernetes_namespace="$(k8s_namespace_prompt)" + fi + + [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}" +} + function __powerline_python_venv_prompt() { set +u local python_venv="" @@ -129,7 +142,7 @@ function __powerline_scm_prompt() { } function __powerline_cwd_prompt() { - local cwd=$(pwd | sed "s|^${HOME}|~|") + local cwd="${PWD/$HOME/\~}" echo "${cwd}|${CWD_THEME_PROMPT_COLOR}" } @@ -147,10 +160,10 @@ function __powerline_clock_prompt() { } function __powerline_battery_prompt() { - local color="" - local battery_status="$(battery_percentage 2> /dev/null)" + local color="" battery_status + battery_status="$(battery_percentage 2> /dev/null)" - if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then + if [[ -z "${battery_status}" || "${battery_status}" == "-1" || "${battery_status}" == "no" ]]; then true else if [[ "$((10#${battery_status}))" -le 5 ]]; then @@ -166,7 +179,7 @@ function __powerline_battery_prompt() { } function __powerline_in_vim_prompt() { - if [ -n "$VIMRUNTIME" ]; then + if [[ -n "$VIMRUNTIME" ]]; then echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}" fi } @@ -210,6 +223,12 @@ function __powerline_command_number_prompt() { echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}" } +function __powerline_duration_prompt() { + local duration + duration=$(_command_duration) + [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}" +} + function __powerline_left_segment() { local params IFS="|" read -ra params <<< "${1}" @@ -250,7 +269,7 @@ function __powerline_last_status_prompt() { function __powerline_prompt_command() { local last_status="$?" ## always the first - local separator_char="${POWERLINE_PROMPT_CHAR}" + local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color LEFT_PROMPT="" SEGMENTS_AT_LEFT=0 @@ -263,7 +282,7 @@ function __powerline_prompt_command() { ## left prompt ## for segment in $POWERLINE_PROMPT; do - local info="$(__powerline_"${segment}"_prompt)" + info="$(__powerline_"${segment}"_prompt)" [[ -n "${info}" ]] && __powerline_left_segment "${info}" done @@ -275,7 +294,7 @@ function __powerline_prompt_command() { # By default we try to match the prompt to the adjacent segment's background color, # but when part of the prompt exists within that segment, we instead match the foreground color. - local prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)" + prompt_color="$(set_color "${LAST_SEGMENT_COLOR}" -)" if [[ -n "${LEFT_PROMPT}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" ]]; then LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" prompt_color="${normal}" diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 794121b887..49b397aa1d 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # shellcheck source=../../themes/powerline/powerline.base.bash . "$BASH_IT/themes/powerline/powerline.base.bash" @@ -52,6 +53,9 @@ TERRAFORM_CHAR=${POWERLINE_TERRAFORM_CHAR:="❲t❳ "} KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "} KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_CONTEXT_COLOR:=26} +KUBERNETES_NAMESPACE_THEME_CHAR=${POWERLINE_KUBERNETES_NAMESPACE_CHAR:="⎈ "} +KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR=${POWERLINE_KUBERNETES_NAMESPACE_COLOR:=64} + AWS_PROFILE_CHAR=${POWERLINE_AWS_PROFILE_CHAR:="❲aws❳ "} AWS_PROFILE_PROMPT_COLOR=${POWERLINE_AWS_PROFILE_COLOR:=208} @@ -91,6 +95,8 @@ COMMAND_NUMBER_THEME_PROMPT_CHAR=${POWERLINE_COMMAND_NUMBER_CHAR:="#"} GCLOUD_THEME_PROMPT_COLOR=${POWERLINE_GCLOUD_COLOR:=161} GCLOUD_CHAR=${POWERLINE_GCLOUD_CHAR:="❲G❳ "} +COMMAND_DURATION_PROMPT_COLOR=${POWERLINE_COMMAND_DURATION_COLOR:=129} + POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"} safe_append_prompt_command __powerline_prompt_command diff --git a/themes/powerturk/powerturk.theme.bash b/themes/powerturk/powerturk.theme.bash index 4590a8aad3..3352f68006 100644 --- a/themes/powerturk/powerturk.theme.bash +++ b/themes/powerturk/powerturk.theme.bash @@ -43,7 +43,7 @@ _swd(){ begin="" # The unshortened beginning of the path. shortbegin="" # The shortened beginning of the path. current="" # The section of the path we're currently working on. - end="${2:-$(pwd)}/" # The unmodified rest of the path. + end="${2:-${PWD}}/" # The unmodified rest of the path. if [[ "$end" =~ "$HOME" ]]; then INHOME=1 diff --git a/themes/pure/pure.theme.bash b/themes/pure/pure.theme.bash index 0be40b5ae2..99476f4ade 100644 --- a/themes/pure/pure.theme.bash +++ b/themes/pure/pure.theme.bash @@ -1,3 +1,7 @@ +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. + # scm theming SCM_THEME_PROMPT_PREFIX="|" SCM_THEME_PROMPT_SUFFIX="" @@ -16,31 +20,22 @@ VIRTUALENV_THEME_PROMPT_SUFFIX=")" # export LSCOLORS="Gxfxcxdxbxegedabagacad" # export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' -scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)$(scm_prompt_info)]" - fi -} - pure_prompt() { - ps_host="${bold_blue}\h${normal}"; - ps_user="${green}\u${normal}"; - ps_user_mark="${green} $ ${normal}"; - ps_root="${red}\u${red}"; - ps_root_mark="${red} # ${normal}" - ps_path="${yellow}\w${normal}"; - - # make it work - case $(id -u) in - 0) PS1="$(virtualenv_prompt)$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark" - ;; - *) PS1="$(virtualenv_prompt)$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark" - ;; - esac + ps_host="${bold_blue}\h${normal}" + ps_user="${green}\u${normal}" + ps_user_mark="${green} $ ${normal}" + ps_root="${red}\u${red}" + ps_root_mark="${red} # ${normal}" + ps_path="${yellow}\w${normal}" + # make it work + case $(id -u) in + 0) + PS1="$(virtualenv_prompt)$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark" + ;; + *) + PS1="$(virtualenv_prompt)$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark" + ;; + esac } safe_append_prompt_command pure_prompt diff --git a/themes/purity/purity.theme.bash b/themes/purity/purity.theme.bash index 8fc03bf32d..22a3fbfbb6 100644 --- a/themes/purity/purity.theme.bash +++ b/themes/purity/purity.theme.bash @@ -1,4 +1,6 @@ # shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck disable=SC2154 #TODO: fix these all. SCM_THEME_PROMPT_DIRTY=" ${bold_red}⊘${normal}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" @@ -26,8 +28,8 @@ venv_prompt() { } function prompt_command() { - retval=$? - local ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" + local retval=$? ret_status + ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")" PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)" } diff --git a/themes/rainbowbrite/rainbowbrite.theme.bash b/themes/rainbowbrite/rainbowbrite.theme.bash index 63c64b72d2..07e5843fcf 100644 --- a/themes/rainbowbrite/rainbowbrite.theme.bash +++ b/themes/rainbowbrite/rainbowbrite.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # based off of n0qorg # looks like, if you're in a git repo: @@ -7,9 +7,7 @@ prompt_setter() { # Save history - history -a - history -c - history -r + _save-and-reload-history 1 # displays user@server in purple # PS1="$red$(scm_char) $purple\u@\h$reset_color:$blue\w$yellow$(scm_prompt_info)$(ruby_version_prompt) $black\$$reset_color " # no user@server diff --git a/themes/ramses/ramses.theme.bash b/themes/ramses/ramses.theme.bash index 7795cf7578..054a316024 100644 --- a/themes/ramses/ramses.theme.bash +++ b/themes/ramses/ramses.theme.bash @@ -36,16 +36,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -71,7 +61,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' my_ps_host="${green}\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="${green}\h${normal}"; @@ -86,10 +76,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] + 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}] ▪ " ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version) + *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version) |─[${bold_purple}\w${normal}] ▪ " ;; diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index 255303973f..3da74d6db7 100644 --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -181,7 +181,7 @@ prompt() { local MOVE_CURSOR_RIGHTMOST='\033[500C' local MOVE_CURSOR_5_LEFT='\033[5D' - if [ $(uname) = "Linux" ]; + if [[ "$OSTYPE" == 'linux'* ]]; then PS1="${TITLEBAR} ${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\ diff --git a/themes/rjorgenson/rjorgenson.theme.bash b/themes/rjorgenson/rjorgenson.theme.bash index e866f0ea4c..71d29e7866 100644 --- a/themes/rjorgenson/rjorgenson.theme.bash +++ b/themes/rjorgenson/rjorgenson.theme.bash @@ -57,16 +57,6 @@ todo_txt_count() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "${BRACKET_COLOR}[${CHAR}${BRACKET_COLOR}][${STRING_COLOR}$(scm_prompt_info)${BRACKET_COLOR}]$normal" - fi -} - my_prompt_char() { if [[ $OSTYPE =~ "darwin" ]]; then echo "${BRACKET_COLOR}➞ ${normal}" @@ -76,6 +66,7 @@ my_prompt_char() { } prompt() { + SCM_PROMPT_FORMAT="${BRACKET_COLOR}[%s${BRACKET_COLOR}][${STRING_COLOR}%s${BRACKET_COLOR}]" my_ps_host="${STRING_COLOR}\h${normal}"; my_ps_user="${STRING_COLOR}\u${normal}"; @@ -84,10 +75,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(modern_scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + 0) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_root${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(my_prompt_char)${normal}" ;; - *) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(modern_scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) + *) PS1="${TITLEBAR}${BRACKET_COLOR}┌─[$my_ps_user${BRACKET_COLOR}][$my_ps_host${BRACKET_COLOR}]$(scm_prompt)$(__my_rvm_ruby_version)${BRACKET_COLOR}[${STRING_COLOR}\w${BRACKET_COLOR}]$(is_vim_shell) ${BRACKET_COLOR}└─$(todo_txt_count)$(my_prompt_char)" ;; esac diff --git a/themes/slick/slick.theme.bash b/themes/slick/slick.theme.bash index aafdc25d15..b0979b7cb8 100644 --- a/themes/slick/slick.theme.bash +++ b/themes/slick/slick.theme.bash @@ -43,18 +43,8 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' case $HOSTNAME in "clappy"* ) my_ps_host="${green}\h${normal}"; ;; @@ -70,10 +60,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + 0) PS1="${TITLEBAR}[$my_ps_root][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) $ " ;; - *) PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) + *) PS1="${TITLEBAR}[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)$(__my_venv_prompt)[${cyan}\w${normal}]$(is_vim_shell) $ " ;; esac diff --git a/themes/zork/zork.theme.bash b/themes/zork/zork.theme.bash index b587231438..c80534501a 100644 --- a/themes/zork/zork.theme.bash +++ b/themes/zork/zork.theme.bash @@ -36,16 +36,6 @@ is_vim_shell() { fi } -modern_scm_prompt() { - CHAR=$(scm_char) - if [ $CHAR = $SCM_NONE_CHAR ] - then - return - else - echo "[$(scm_char)][$(scm_prompt_info)]" - fi -} - # show chroot if exist chroot(){ if [ -n "$debian_chroot" ] @@ -71,7 +61,7 @@ my_ve(){ } prompt() { - + SCM_PROMPT_FORMAT='[%s][%s]' my_ps_host="${green}\h${normal}"; # yes, these are the the same for now ... my_ps_host_root="${green}\h${normal}"; @@ -86,10 +76,10 @@ prompt() { # nice prompt case "`id -u`" in - 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + 0) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_root][$my_ps_host_root]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " ;; - *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(modern_scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) + *) PS1="${TITLEBAR}┌─$(my_ve)$(chroot)[$my_ps_user][$my_ps_host]$(scm_prompt)$(__my_rvm_ruby_version)[${cyan}\w${normal}]$(is_vim_shell) └─▪ " ;; esac