diff --git a/.editorconfig b/.editorconfig index 6deb6378..e302645a 100755 --- a/.editorconfig +++ b/.editorconfig @@ -1,32 +1,15 @@ # EditorConfig is awesome: http://EditorConfig.org [*] -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 = true # like -kp -end_of_line = lf -charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false -[*.*sh] +[.git*] 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 = true # like -kp -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true diff --git a/.gitmodules b/.gitmodules index 095a6a5e..57b46adc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,16 @@ [submodule "test_lib/bats-core"] path = test_lib/bats-core url = https://github.com/bats-core/bats-core + branch = tags/v1.2.0 [submodule "test_lib/bats-support"] path = test_lib/bats-support - url = https://github.com/ztombol/bats-support + url = https://github.com/bats-core/bats-support + branch = tags/v0.3.0 [submodule "test_lib/bats-assert"] path = test_lib/bats-assert - url = https://github.com/ztombol/bats-assert + url = https://github.com/bats-core/bats-assert + branch = tags/v2.0.0 [submodule "test_lib/bats-file"] path = test_lib/bats-file - url = https://github.com/ztombol/bats-file + url = https://github.com/bats-core/bats-file + branch = tags/v0.3.0 diff --git a/.travis.yml b/.travis.yml index b3fa2728..12d5e15e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,31 @@ -sudo: false -script: test/run -language: c -os: - - linux - - osx +# YAML anchors need to appear first. +# Keys starting with an underscore are the custom ones, refer to +# https://docs.travis-ci.com/user/build-config-yaml#private-keys-as-yaml-anchors-and-aliases-and-external-tooling + +_native_job: &native_job + script: | + test/run + +language: shell + +os: linux + +dist: xenial + +jobs: + - <<: *native_job + name: Ubuntu 16.04 + + - <<: *native_job + name: Ubuntu 18.04 + dist: bionic + + - <<: *native_job + name: MacOS xcode9.4 + os: osx + osx_image: xcode9.4 # Default xcode on Travis. + + - <<: *native_job + name: MacOS xcode11.5 + os: osx + osx_image: xcode11.5 # Latest xcode on Travis. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index bb03ab49..2f7941cb 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -2,6 +2,22 @@ This page summarizes a couple of rules to keep in mind when developing features or making changes in Bash-it. +## Debugging and Logging + +### General Logging + +While developing feature or making changes in general, you can log error/warning/debug +using `_log_error` `_log_warning` and `_log_debug`. This will help you solve problems quicker +and also propagate important notes to other users of Bash-it. +You can see the logs by using `bash-it doctor` command to reload and see the logs. +Alternatively, you can set `BASH_IT_LOG_LEVEL` to `BASH_IT_LOG_LEVEL_ERROR`, `BASH_IT_LOG_LEVEL_WARNING` or `BASH_IT_LOG_LEVEL_ALL`. + +### Log Prefix/Context + +You can define `BASH_IT_LOG_PREFIX` in your files in order to a have a constant prefix before your logs. +Note that we prefer to uses "tags" based logging, i.e `plugins: git: DEBUG: Loading git plugin`. + + ## Load Order ### General Load Order @@ -44,6 +60,11 @@ Having the order based on a numeric priority in a common directory allows for mo These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. +## Plugin Disable Callbacks + +Plugins can define a function that will be called when the plugin is being disabled. +The callback name should be `{PLUGIN_NAME}_on_disable`, you can see `gitstatus` for usage example. + ## Using the pre-commit hook Note the file .pre-commit-config.yaml at the top of the repo. diff --git a/README.md b/README.md index ccaa7946..1da1f7eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Bash-it -[![Build Status](https://travis-ci.org/Bash-it/bash-it.svg?branch=master)](https://travis-ci.org/Bash-it/bash-it) [![Join the chat at https://gitter.im/Bash-it/bash-it](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![Build Status](https://travis-ci.com/Bash-it/bash-it.svg?branch=master)](https://travis-ci.com/Bash-it/bash-it) +[![Join the chat at https://gitter.im/Bash-it/bash-it](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) **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:) @@ -86,13 +87,24 @@ Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-i ### Updating -To update Bash-it to the latest version, simply run: +To update Bash-it to the latest stable version, simply run: ```bash -bash-it update +bash-it update stable ``` -that's all. +If you want to update to the latest dev version (directly from master), run: + +```bash +bash-it update dev +``` + +If you want to update automatically and unattended, you can add the optional +`-s/--silent` flag, for example: + +```bash +bash-it update dev --silent +``` If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated. For these cases, we provide a `migrate` command: @@ -394,6 +406,13 @@ $ git config --global --add bash-it.hide-status 1 Setting this flag globally has the same effect as `SCM_CHECK=true`, but only for Git repos. +### Speed up git status calculations + +As an alternative to ignoring repo status entirely, you can try out the `gitstatus` plugin. +This plugin speeds up all `git status` calculations by up to 10x times! + +**NOTE**: You will need to clone `gitstatus` repo from [here](https://github.com/romkatv/gitstatus). + ### Pass function renamed to passgen The Bash-it `pass` function has been renamed to `passgen` in order to avoid a naming conflict with the [pass password manager](https://www.passwordstore.org/). @@ -409,6 +428,20 @@ Unset `BASH_IT_LEGACY_PASS` to have Bash-it **return to default behavior**: * `unset BASH_IT_LEGACY_PASS` +### Debugging + +If you encounter problems with any part of Bash-it, run the following command: +```bash +bash-it doctor +``` +This will reload your bash profile and print out logs of various parts in Bash-it. +Note that this command at default will print all logs, including debug logs. +You can call it like this: +```bash +bash-it doctor [errors/warnings/all] +``` +In order to get wanted verbosity. + ### Proxy Support If you are working in a corporate environment where you have to go through a proxy server for internet access, diff --git a/aliases/available/bash-it.aliases.bash b/aliases/available/bash-it.aliases.bash new file mode 100644 index 00000000..d2975667 --- /dev/null +++ b/aliases/available/bash-it.aliases.bash @@ -0,0 +1,23 @@ +cite about-alias +about-alias 'Aliases for the bash-it command (these aliases are automatically included with the "general" aliases)' + +# Common misspellings of bash-it +alias shit='bash-it' +alias batshit='bash-it' +alias bashit='bash-it' +alias batbsh='bash-it' +alias babsh='bash-it' +alias bash_it='bash-it' +alias bash_ti='bash-it' + +# Additional bash-it aliases for help/show +alias bshsa='bash-it show aliases' +alias bshsc='bash-it show completions' +alias bshsp='bash-it show plugins' +alias bshha='bash-it help aliases' +alias bshhc='bash-it help completions' +alias bshhp='bash-it help plugins' +alias bshsch="bash-it search" +alias bshenp="bash-it enable plugin" +alias bshena="bash-it enable alias" +alias bshenc="bash-it enable completion" diff --git a/aliases/available/docker-compose.aliases.bash b/aliases/available/docker-compose.aliases.bash index f23c2689..82b39577 100644 --- a/aliases/available/docker-compose.aliases.bash +++ b/aliases/available/docker-compose.aliases.bash @@ -2,6 +2,8 @@ cite 'about-alias' about-alias 'docker-compose abbreviations' alias dco="docker-compose" + +# Defined in the `docker-compose` plugin, please check there for details. alias dcofresh="docker-compose-fresh" alias dcol="docker-compose logs -f --tail 100" alias dcou="docker-compose up" diff --git a/aliases/available/docker.aliases.bash b/aliases/available/docker.aliases.bash index 52ccc4c6..9f005aa7 100644 --- a/aliases/available/docker.aliases.bash +++ b/aliases/available/docker.aliases.bash @@ -33,7 +33,9 @@ alias dkrmflast='docker rm -f $(dklcid)' alias dkbash='dkelc' alias dkex='docker exec -it ' # Useful to run any commands into container without leaving host alias dkri='docker run --rm -i ' +alias dkric='docker run --rm -i -v $PWD:/cwd -w /cwd ' alias dkrit='docker run --rm -it ' +alias dkritc='docker run --rm -it -v $PWD:/cwd -w /cwd ' # Added more recent cleanup options from newer docker versions alias dkip='docker image prune -a -f' diff --git a/aliases/available/fuck.aliases.bash b/aliases/available/fuck.aliases.bash index 54648931..959807fb 100644 --- a/aliases/available/fuck.aliases.bash +++ b/aliases/available/fuck.aliases.bash @@ -1,3 +1,11 @@ -# https://github.com/nvbn/thefuck -alias fuck='eval $(thefuck $(fc -ln -1))' -alias please='fuck' +cite 'about-alias' +about-alias 'fuck/please to retry last command with sudo' + +# Play nicely with 'thefuck' plugin +if ! _command_exists fuck ; then + alias fuck='sudo $(fc -ln -1)' +fi +alias please=fuck +alias plz=please +alias fucking=sudo + diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 542b76cd..0c7bcd9d 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -28,7 +28,6 @@ alias vbpf="vim ~/.bash_profile" if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null then alias grep='grep --color=auto' - export GREP_COLOR='1;33' fi if which gshuf &> /dev/null @@ -75,27 +74,6 @@ fi alias md='mkdir -p' alias rd='rmdir' -# Common misspellings of bash-it -alias shit='bash-it' -alias batshit='bash-it' -alias bashit='bash-it' -alias batbsh='bash-it' -alias babsh='bash-it' -alias bash_it='bash-it' -alias bash_ti='bash-it' - -# Additional bash-it aliases for help/show -alias bshsa='bash-it show aliases' -alias bshsc='bash-it show completions' -alias bshsp='bash-it show plugins' -alias bshha='bash-it help aliases' -alias bshhc='bash-it help completions' -alias bshhp='bash-it help plugins' -alias bshsch="bash-it search" -alias bshenp="bash-it enable plugin" -alias bshena="bash-it enable alias" -alias bshenc="bash-it enable completion" - # Shorten extract alias xt="extract" @@ -113,3 +91,12 @@ catt() { fi done } + +# The Bash-it aliases were moved to the `bash-it.aliases.bash` file. The intent of this +# is to keep the script readable and less bloated. If you don't need to use +# the `general` aliases, but you want the Bash-it aliases, you can disable the `general` +# aliases and enable just the ones for Bash-it explicitly: +# bash-it disable alias general +# bash-it enable alias bash-it +# shellcheck source=./bash-it.aliases.bash +source "$BASH_IT/aliases/available/bash-it.aliases.bash" diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index fc95300d..be8d7330 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -22,12 +22,13 @@ alias gs='git status' alias gss='git status -s' alias gsu='git submodule update --init --recursive' alias gl='git pull' +alias gpl='git pull' alias glum='git pull upstream master' alias gpr='git pull --rebase' alias gpp='git pull && git push' alias gup='git fetch && git rebase' alias gp='git push' -alias gpo='git push origin' +alias gpo='git push origin HEAD' alias gpu='git push --set-upstream' alias gpuo='git push --set-upstream origin' alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' @@ -35,16 +36,23 @@ alias gpom='git push origin master' alias gr='git remote' alias grv='git remote -v' alias gra='git remote add' +alias grb='git rebase' +alias grm='git rebase master' +alias grmi='git rebase master -i' alias gd='git diff' alias gds='git diff --staged' +alias gdt='git difftool' alias gdv='git diff -w "$@" | vim -R -' alias gc='git commit -v' alias gca='git commit -v -a' alias gcm='git commit -v -m' alias gcam="git commit -v -am" alias gci='git commit --interactive' +alias gcamd='git commit --amend' alias gb='git branch' alias gba='git branch -a' +# FROM https://stackoverflow.com/a/58623139/10362396 +alias gbc='git for-each-ref --format="%(authorname) %09 %(if)%(HEAD)%(then)*%(else)%(refname:short)%(end) %09 %(creatordate)" refs/remotes/ --sort=authorname DESC' alias gbt='git branch --track' alias gbm='git branch -m' alias gbd='git branch -d' @@ -63,7 +71,9 @@ alias gdel='git branch -D' alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' alias gll='git log --graph --pretty=oneline --abbrev-commit' 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 gsh="git show" alias gsl="git shortlog -sn" alias gwc="git whatchanged" alias gt="git tag" @@ -76,14 +86,38 @@ alias gpatch="git format-patch -1" alias gnew="git log HEAD@{1}..HEAD@{0}" # Add uncommitted and unstaged changes to the last commit alias gcaa="git commit -a --amend -C HEAD" +# Rebase with latest remote master +alias gprom="git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master" +alias gpf="git push --force" +alias gpunch="git push --force-with-lease" alias ggui="git gui" alias gcsam="git commit -S -am" +# Stash aliases alias gst="git stash" alias gstb="git stash branch" alias gstd="git stash drop" alias gstl="git stash list" +# Push introduced in git v2.13.2 +alias gstpu="git stash push" +alias gstpum="git stash push -m" +# Save deprecated since git v2.16.0 +# - aliases now resolve to push +alias gsts="git stash push" +alias gstsm="git stash push -m" +# Alias gstpo added for symmetry with gstpu (push) +# - gstp remains as alias for pop due to long-standing usage +alias gstpo="git stash pop" alias gstp="git stash pop" -alias gh='cd "$(git rev-parse --show-toplevel)"' +# Switch aliases - Requires git v2.23+ +alias gsw="git switch" +alias gswm="git switch master" +alias gswc="git switch --create" +alias gswt="git switch --track" +# Git home +alias ghm='cd "$(git rev-parse --show-toplevel)"' +if ! _command_exists gh; then + alias gh='ghm' +fi # Show untracked files alias gu='git ls-files . --exclude-standard --others' diff --git a/aliases/available/kubectl.aliases.bash b/aliases/available/kubectl.aliases.bash index 58670ce5..9ce923a0 100644 --- a/aliases/available/kubectl.aliases.bash +++ b/aliases/available/kubectl.aliases.bash @@ -5,12 +5,11 @@ cite 'about-alias' about-alias 'kubectl aliases' -# set apt aliases function _set_pkg_aliases() { - if [ -x $(which kubectl) ]; then - alias kc='kubectl' - alias kcgp='kubectl get pods' + if _command_exists kubectl; then + alias kc='kubectl' + alias kcgp='kubectl get pods' alias kcgd='kubectl get deployments' alias kcgn='kubectl get nodes' alias kcdp='kubectl describe pod' @@ -18,7 +17,9 @@ function _set_pkg_aliases() alias kcdn='kubectl describe node' alias kcgpan='kubectl get pods --all-namespaces' alias kcgdan='kubectl get deployments --all-namespaces' - fi + # launches a disposable netshoot pod in the k8s cluster + alias kcnetshoot='kubectl run --generator=run-pod/v1 netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' + fi } _set_pkg_aliases diff --git a/aliases/available/npm.aliases.bash b/aliases/available/npm.aliases.bash index 2266fe22..f8f64595 100644 --- a/aliases/available/npm.aliases.bash +++ b/aliases/available/npm.aliases.bash @@ -2,6 +2,8 @@ cite 'about-alias' about-alias 'common npm abbreviations' # Aliases + +# npm alias ni='npm install' alias nis='npm install --save' alias nid='npm install --save-dev' @@ -20,3 +22,21 @@ alias nud='npm update' alias nr='npm run' alias nls='npm list --depth=0 2>/dev/null' alias nlsg='npm list -g --depth=0 2>/dev/null' + +# npx +alias nx='npx' +alias nxplease='npx $(fc -ln -1)' +alias nxn='npx --no-install ' +alias nxp='npx -p ' +alias nxnp='npx --no-install -p ' +alias nxq='npx -q ' +alias nxnq='npx --no-install -q ' +alias nxqp='npx -q -p ' +alias nxnqp='npx --no-install -q -p ' +alias nxni='npx --no-install --ignore-existing ' +alias nxip='npx --ignore-existing -p ' +alias nxnip='npx --no-install --ignore-existing -p ' +alias nxqi='npx -q --ignore-existing ' +alias nxniq='npx --no-install --ignore-existing -q ' +alias nxiqp='npx --ignore-existing -q -p ' +alias nxniqp='npx --no-install --ignore-existing -q -p ' diff --git a/aliases/available/terraform.aliases.bash b/aliases/available/terraform.aliases.bash new file mode 100644 index 00000000..af5276de --- /dev/null +++ b/aliases/available/terraform.aliases.bash @@ -0,0 +1,11 @@ +# Aliases for Terraform and Terragrunt + +cite 'about-alias' +about-alias 'Terraform abbreviations' + +alias tf='terraform' +alias tfv='terraform validate' +alias tfp='terraform plan' +alias tfa='terraform apply' +alias tfd='terraform destory' + diff --git a/aliases/available/terragrunt.aliases.bash b/aliases/available/terragrunt.aliases.bash new file mode 100644 index 00000000..f1d7e182 --- /dev/null +++ b/aliases/available/terragrunt.aliases.bash @@ -0,0 +1,16 @@ +# Aliases for Terraform and Terragrunt + +cite 'about-alias' +about-alias 'Terragrunt abbreviations' + +alias tg='terragrunt' +alias tgv='terragrunt validate' +alias tgp='terragrunt plan' +alias tga='terragrunt apply' +alias tgd='terragrunt destroy' + +alias tgva='terragrunt validate-all' +alias tgpa='terragrunt plan-all' +alias tgaa='terragrunt apply-all' +alias tgda='terragrunt destroy-all' + diff --git a/aliases/available/uuidgen.aliases.bash b/aliases/available/uuidgen.aliases.bash new file mode 100644 index 00000000..aada05fb --- /dev/null +++ b/aliases/available/uuidgen.aliases.bash @@ -0,0 +1,11 @@ +cite 'uuid-alias' +about-alias 'uuidgen aliases' + +if _command_exists uuid; then # Linux + alias uuidu="uuid | tr '[:lower:]' '[:upper:]'" + alias uuidl=uuid +elif _command_exists uuidgen; then # macOS/BSD + alias uuidu="uuidgen" + alias uuid="uuidgen | tr '[:upper:]' '[:lower:]'" # because upper case is like YELLING + alias uuidl=uuid +fi diff --git a/bash_it.sh b/bash_it.sh index ab911019..310aae42 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -1,37 +1,49 @@ #!/usr/bin/env bash # Initialize Bash It +BASH_IT_LOG_PREFIX="core: main: " # Only set $BASH_IT if it's not already set if [ -z "$BASH_IT" ]; then # Setting $BASH to maintain backwards compatibility - # TODO: warn users that they should upgrade their .bash_profile export BASH_IT=$BASH BASH="$(bash -c 'echo $BASH')" export BASH -fi - -# For backwards compatibility, look in old BASH_THEME location -if [ -z "$BASH_IT_THEME" ]; -then - # TODO: warn users that they should upgrade their .bash_profile - export BASH_IT_THEME="$BASH_THEME"; - unset BASH_THEME; + BASH_IT_OLD_BASH_SETUP=true fi # Load composure first, so we support function metadata # shellcheck source=./lib/composure.bash source "${BASH_IT}/lib/composure.bash" +# We need to load logging module first as well in order to be able to log +# shellcheck source=./lib/log.bash +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!" + +# For backwards compatibility, look in old BASH_THEME location +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"; + unset BASH_THEME; +fi # support 'plumbing' metadata cite _about _param _example _group _author _version # libraries, but skip appearance (themes) for now +_log_debug "Loading libraries(except appearance)..." LIB="${BASH_IT}/lib/*.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" for _bash_it_config_file in $LIB do if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then + filename=${_bash_it_config_file##*/} + filename=${filename%.bash} + BASH_IT_LOG_PREFIX="lib: ${filename}: " + _log_debug "Loading library file..." # shellcheck disable=SC1090 source "$_bash_it_config_file" fi @@ -51,36 +63,51 @@ done # Load theme, if a theme was set if [[ ! -z "${BASH_IT_THEME}" ]]; then + _log_debug "Loading \"${BASH_IT_THEME}\" theme..." # Load colors and helpers first so they can be used in base theme + BASH_IT_LOG_PREFIX="themes: colors: " # shellcheck source=./themes/colors.theme.bash source "${BASH_IT}/themes/colors.theme.bash" + BASH_IT_LOG_PREFIX="themes: githelpers: " # shellcheck source=./themes/githelpers.theme.bash source "${BASH_IT}/themes/githelpers.theme.bash" + BASH_IT_LOG_PREFIX="themes: p4helpers: " # shellcheck source=./themes/p4helpers.theme.bash source "${BASH_IT}/themes/p4helpers.theme.bash" + BASH_IT_LOG_PREFIX="themes: base: " # shellcheck source=./themes/base.theme.bash source "${BASH_IT}/themes/base.theme.bash" + BASH_IT_LOG_PREFIX="lib: appearance: " # appearance (themes) now, after all dependencies # shellcheck source=./lib/appearance.bash source "$APPEARANCE_LIB" fi -# Load custom aliases, completion, plugins +BASH_IT_LOG_PREFIX="core: main: " +_log_debug "Loading custom aliases, completion, plugins..." for file_type in "aliases" "completion" "plugins" do if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ] then + BASH_IT_LOG_PREFIX="${file_type}: custom: " + _log_debug "Loading component..." # shellcheck disable=SC1090 source "${BASH_IT}/${file_type}/custom.${file_type}.bash" fi done # Custom +BASH_IT_LOG_PREFIX="core: main: " +_log_debug "Loading general custom files..." CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" for _bash_it_config_file in $CUSTOM do if [ -e "${_bash_it_config_file}" ]; then + filename=$(basename "${_bash_it_config_file}") + filename=${filename%*.bash} + BASH_IT_LOG_PREFIX="custom: $filename: " + _log_debug "Loading custom file..." # shellcheck disable=SC1090 source "$_bash_it_config_file" fi diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 71ec8418..4fdd72d6 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -65,7 +65,7 @@ _bash-it-comp() prev="${COMP_WORDS[COMP_CWORD-1]}" chose_opt="${COMP_WORDS[1]}" file_type="${COMP_WORDS[2]}" - opts="disable enable help migrate reload search show update version" + opts="disable enable help migrate reload restart doctor search show update version" case "${chose_opt}" in show) local show_args="aliases completions plugins" @@ -82,7 +82,21 @@ _bash-it-comp() return 0 fi ;; - migrate | reload | search | update | version) + doctor) + local doctor_args="errors warnings all" + COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) ) + return 0 + ;; + update) + if [[ ${cur} == -* ]];then + local update_args="-s --silent" + else + local update_args="stable dev" + fi + COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) ) + return 0 + ;; + migrate | reload | search | version) return 0 ;; enable | disable) diff --git a/completion/available/brew.completion.bash b/completion/available/brew.completion.bash index 5cbd1595..4bdaf53d 100644 --- a/completion/available/brew.completion.bash +++ b/completion/available/brew.completion.bash @@ -1,11 +1,27 @@ -if which brew >/dev/null 2>&1; then - BREW_PREFIX=$(brew --prefix) +#!/usr/bin/env bash - if [ -f "$BREW_PREFIX"/etc/bash_completion.d/brew ]; then - . "$BREW_PREFIX"/etc/bash_completion.d/brew - fi +# Load late to make sure `system` completion loads first +# BASH_IT_LOAD_PRIORITY: 375 - if [ -f "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]; then - . "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh - fi +if [[ "$(uname -s)" != 'Darwin' ]] ; then + _log_warning "unsupported operating system - only 'Darwin' is supported" + return 0 +fi + +# Make sure brew is installed +_command_exists brew || return 0 + +BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} + +if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]] ; then + source "$BREW_PREFIX"/etc/bash_completion.d/brew + +elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]] ; then + source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh + +elif [[ -f "$BREW_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 + source "$BREW_PREFIX"/completions/bash/brew fi diff --git a/completion/available/bundler.completion.bash b/completion/available/bundler.completion.bash index cdb7cf54..4ad04bdc 100644 --- a/completion/available/bundler.completion.bash +++ b/completion/available/bundler.completion.bash @@ -1,7 +1,7 @@ #! bash # bash completion for the `bundle` command. # -# Copyright (c) 2011-2013 Daniel Luz . +# Copyright (c) 2011-2017 Daniel Luz . # Distributed under the MIT license. # http://mernen.com/projects/completion-ruby # @@ -9,28 +9,166 @@ # . completion-bundle __bundle() { - local cur=$2 - local prev=$3 - local bundle_command - __bundle_get_command - COMPREPLY=() + local bundle_bin=("${_RUBY_COMMAND_PREFIX[@]}" "$1") + local cur prev + _get_comp_words_by_ref -n : cur prev + local bundle_command + local bundle_command_index + __bundle_get_command + COMPREPLY=() - local options - if [[ $cur = -* ]]; then - options="--no-color --verbose" - if [[ -z $bundle_command ]]; then - options="$options --version --help" - fi - elif [[ $bundle_command = "exec" ]]; then - _bundle_exec_completions - return - else - if [[ -z $bundle_command || $bundle_command = help ]]; then - options="help install update package exec config check list show - console open viz init gem" - fi - fi - COMPREPLY=($(compgen -W "$options" -- "$cur")) + local options + if [[ $cur = -* && $bundle_command != exec ]]; then + options="-V --help --no-color --no-no-color --verbose --no-verbose" + case $bundle_command in + "") + options="$options --version";; + check) + options="$options --dry-run --gemfile --path -r --retry";; + clean) + options="$options --dry-run --force";; + config) + options="$options --local --global --delete";; + doctor) + options="$options --gemfile --quiet --no-quiet";; + gem) + options="$options -b -e -t --bin --coc --no-coc --edit --exe + --no-exe --ext --no-ext --mit --no-mit --test";; + init) + options="$options --gemspec";; + install) + options="$options --binstubs --clean --deployment --force --frozen + --full-index --gemfile --jobs --local --no-cache + --no-prune --path --quiet --retry --shebang --standalone + --system --trust-policy --with --without";; + lock) + options="$options --add-platform --conservative --full-index + --local --lockfile --major --minor --patch --print + --remove-platform --strict --update";; + package) + options="$options --all --all-platforms";; + platform) + options="$options --ruby";; + show) + options="$options --outdated --paths --no-paths";; + update) + options="$options --bundler --conservative --force --full-index + --group --jobs --local --major --minor --patch --quiet + --ruby --source --strict";; + viz) + options="$options -f -F -R -v -W --file --format --requirements + --no-requirements --version --no-version --without";; + esac + else + case $bundle_command in + "" | help) + options="help install update package exec config + check show outdated console open lock viz init gem + platform clean doctor" + ;; + check | install) + case $prev in + --binstubs | --path) + _filedir -d + return;; + --standalone | --with | --without) + __bundle_complete_groups + return;; + --trust-policy) + options="HighSecurity MediumSecurity LowSecurity + AlmostNoSecurity NoSecurity";; + esac + ;; + config) + case $prev in + config | --*) + case $cur in + local.*) + options=($(__bundle_exec_ruby 'puts Bundler.definition.specs.to_hash.keys')) + options=("${options[*]/#/local.}") + ;; + *) + options=(path frozen without bin gemfile ssl_ca_cert + ssl_client_cert cache_path disable_multisource + ignore_messages retry redirect timeout + force_ruby_platform specific_platform + disable_checksum_validation disable_version_check + allow_offline_install auto_install + cache_all_platforms cache_all clean console + disable_exec_load disable_local_branch_check + disable_shared_gems jobs major_deprecations + no_install no_prune only_update_to_newer_versions + plugins shebang silence_root_warning + ssl_verify_mode system_bindir user_agent) + # We want to suggest the options above as complete words, + # and also "local." and "mirror." as prefixes + # To achieve that, disable automatic space insertion, + # insert it manually, then add the non-spaced prefixes + compopt -o nospace + options=("${options[@]/%/ }") + # And add prefix suggestions + options+=(local. mirror.) + # Override $IFS for completion to work + local IFS=$'\n' + COMPREPLY=($(compgen -W '${options[@]}' -- "$cur")) + return + ;; + esac + ;; + path | local.*) + _filedir -d + return;; + esac + ;; + exec) + if [[ $COMP_CWORD -eq $bundle_command_index ]]; then + # Figure out Bundler's binaries dir + local bundler_bin=$(__bundle_exec_ruby 'puts Bundler.bundle_path + "bin"') + if [[ -d $bundler_bin ]]; then + local binaries=("$bundler_bin"/*) + # If there are binaries, strip directory name and use them + [[ -f "$binaries" ]] && options="${binaries[@]##*/}" + else + # No binaries found; use full command completion + COMPREPLY=($(compgen -c -- "$cur")) + return + fi + else + local _RUBY_COMMAND_PREFIX=("${bundle_bin[@]}" exec) + _command_offset $bundle_command_index + return + fi + ;; + gem) + case $prev in + -e | --edit) + COMPREPLY=($(compgen -c -- "$cur")) + return;; + -t | --test) + options="minitest rspec";; + esac + ;; + update) + case $prev in + --group) + __bundle_complete_groups + return;; + *) + options=($(__bundle_exec_ruby 'puts Bundler.definition.specs.to_hash.keys')) + esac + ;; + viz) + case $prev in + -F | --format) + options="dot jpg png svg";; + -W | --without) + __bundle_complete_groups + return;; + esac + ;; + esac + fi + COMPREPLY=($(compgen -W "${options[*]}" -- "$cur")) } __bundle_get_command() { @@ -41,25 +179,76 @@ __bundle_get_command() { case $arg in [^-]*) bundle_command=$arg + bundle_command_index=$((i + 1)) return;; --version) - # command-killer + # Command-killer bundle_command=- return;; --help) bundle_command=help + bundle_command_index=$((i + 1)) return;; esac done } +# Provides completion for Bundler group names. +# +# Multiple groups can be entered, separated either by spaces or by colons. +# Input is read from $cur, and the result is directly written to $COMPREPLY. +__bundle_complete_groups() { + # Group being currently written + local cur_group=${cur##*[ :]} + # All groups written before + local prefix=${cur%"$cur_group"} + local groups=$(__bundle_exec_ruby 'puts Bundler.definition.dependencies.map(&:groups).reduce(:|).map(&:to_s)') + if [[ ! $groups ]]; then + COMPREPLY=() + return + fi + # Duplicate "default" and anything already in $prefix, so that `uniq` + # strips it; groups may be separated by ':', ' ', or '\ ' + local excluded=$'\ndefault\n'${prefix//[: \'\"\\]/$'\n'} + # Include them twice to ensure they are duplicates + groups=$groups$excluded$excluded + COMPREPLY=($(compgen -W "$(sort <<<"$groups" | uniq -u)" -- "$cur_group")) + # Prepend prefix to all entries + COMPREPLY=("${COMPREPLY[@]/#/$prefix}") + __ltrim_colon_completions "$cur" +} -complete -F __bundle -o bashdefault -o default bundle -# vim: ai ft=sh sw=4 sts=2 et +# __bundle_exec_ruby