diff --git a/.editorconfig b/.editorconfig index 87e50155..3997f583 100755 --- a/.editorconfig +++ b/.editorconfig @@ -5,8 +5,26 @@ 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 + +[.git*] +indent_style = tab + +[*.*sh] +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/.gitattributes b/.gitattributes index d4c710cb..bb7d1461 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,5 @@ *.sh text eol=lf *.bash text eol=lf + +# Windows files +*.bat text eol=crlf diff --git a/.github/no-response.yml b/.github/no-response.yml new file mode 100644 index 00000000..e80a98be --- /dev/null +++ b/.github/no-response.yml @@ -0,0 +1,11 @@ +# Configuration for probot-no-response - https://github.com/probot/no-response + +# Number of days of inactivity before an Issue is closed for lack of response +daysUntilClose: 14 +# Label requiring a response +responseRequiredLabel: waiting-for-response +# Comment to post when closing an Issue for lack of response. Set to `false` to disable +closeComment: > + This issue has been automatically closed because there has been no response + to our request for more information from the original author. + You can always reopen the issue if needed. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..03b75882 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +name: CI + +# Triggers the workflow on push or pull request events +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + bats-test: + strategy: + matrix: + os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15, macos-11.0] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Install greadlink + if: startsWith(runner.os, 'macOS') + run: brew install coreutils + - name: Test code + run: test/run + + build-docs: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install docs dependencies + run: python3 -m pip install -r docs/requirements.txt + - name: Build the docs + run: sphinx-build -W -b html docs docs/_build/html + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install shfmt + run: GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt + - name: Install shellcheck + run: brew install shellcheck + - name: Install pre-commit + run: python3 -m pip install -r test/lint-requirements.txt + - name: Run lint + run: ./lint_clean_files.sh diff --git a/.gitignore b/.gitignore index 6fad6279..a17b6e82 100755 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ bats *.sublime-workspace *.sublime-project enabled/* +/enabled tmp/ 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/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..84ed6ee7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +--- +# fail_fast: true +minimum_pre_commit_version: 1.18.1 +exclude: "docs/_build/" +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-merge-conflict + - id: mixed-line-ending + - id: check-added-large-files + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 2.1.4 + hooks: + - id: git-check # Configure in .gitattributes + - id: shellcheck + exclude: ".bats$" + - id: shfmt + exclude: ".bats$" + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.1.7 + hooks: + # - id: forbid-crlf + - id: remove-crlf + exclude: ".bat$" diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 00000000..751f3175 --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,10 @@ +version: 2 + +sphinx: + builder: htmldir + configuration: docs/conf.py + +python: + version: 3.7 + install: + - requirements: docs/requirements.txt diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 00000000..6418bd8f --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,6 @@ +# We use colors and not assigned +disable=SC2154 +# Hard to fix +disable=SC2155 +# shellcheck is wrong on some +disable=SC2034 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b3fa2728..00000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -sudo: false -script: test/run -language: c -os: - - linux - - osx diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 8c251c6c..00000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,91 +0,0 @@ -# Contribution Guidelines - -When contributing a new feature, a bug fix, a new theme, or any other change to Bash-it, please consider the following guidelines. -Most of this is common sense, but please try to stick to the conventions listed here. - -## Issues - -* When opening a new issue in the issue tracker, please include information about which _Operating System_ you're using, and which version of _Bash_. -* In many cases, it also makes sense to show which Bash-it plugins you are using. - This information can be obtained using `bash-it show plugins`. -* If the issue happens while loading Bash-it, please also include your `~/.bash_profile` or `~/.bashrc` file, - as well as the install location of Bash-it (default should be `~/.bash_it`). -* When reporting a bug or requesting a new feature, consider providing a Pull Request that fixes the issue or can be used as a starting point for the new feature. - Don't be afraid, most things aren't that complex... - -## Pull Requests - -* Fork the Bash-it repo, create a new feature branch from _master_ and apply your changes there. - Create a _Pull Request_ from your feature branch against Bash-it's _master_ branch. -* Limit each Pull Request to one feature. - Don't bundle multiple features/changes (e.g. a new _Theme_ and a fix to an existing plugin) into a single Pull Request - create one PR for the theme, and a separate PR for the fix. -* For complex changes, try to _squash_ your changes into a single commit before - pushing code. Once you've pushed your code and opened a PR, please refrain - from force-pushing changes to the PR branch – remember, Bash-it is a - distributed project and your branch may be in use already. -* When in doubt, open a PR with too many commits. Bash-it is a learning project - for everyone involved. Showing your work provides a great history for folks - to learn what works and what didn't. - -## Code Style - -* Try to stick to the existing code style. Please don't reformat or change the syntax of existing code simply because you don't like that style. -* Indentation is using spaces, not tabs. Most of the code is indented with 2 spaces, some with 4 spaces. Please try to stick to 2 spaces. - If you're using an editor that supports [EditorConfig](http://EditorConfig.org), the editor should automatically use the settings defined in Bash-it's [.editorconfig file](.editorconfig). -* When creating new functions, please use a dash ("-") to separate the words of the function's name, e.g. `my-new-function`. - Don't use underscores, e.g. `my_new_function`. -* Internal functions that aren't to be used by the end user should start with an underscore, e.g. `_my-new-internal-function`. -* Use the provided meta functions to document your code, e.g. `about-plugin`, `about`, `group`, `param`, `example`. - This will make it easier for other people to use your new functionality. - Take a look at the existing code for an example (e.g. [the base plugin](plugins/available/base.plugin.bash)). -* When adding files, please use the existing file naming conventions, e.g. plugin files need to end in `.plugin.bash`. - This is important for the installation functionality. -* When using the `$BASH_IT` variable, please always enclose it in double quotes to ensure that the code also works when Bash-it is installed in a directory that contains spaces in its name: `for f in "${BASH_IT}/plugins/available"/*.bash ; do echo "$f" ; done` -* Bash-it supports Bash 3.2 and higher. Please don't use features only available in Bash 4, such as associative arrays. - -## Unit Tests - -When adding features or making changes/fixes, please run our growing unit test suite to ensure that you did not break existing functionality. -The test suite does not cover all aspects of Bash-it, but please run it anyway to verify that you did not introduce any regression issues. - -Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on [Travis CI](https://travis-ci.org/Bash-it/bash-it), where the test suite is run on both Linux and macOS. -The Pull Request will then show the result of the Travis build, indicating whether all tests ran fine, or whether there were issues. -Please pay attention to this, Pull Requests with build issues will not be merged. - -Adding new functionality or changing existing functionality is a good opportunity to increase Bash-it's test coverage. -When you're changing the Bash-it codebase, please consider adding some unit tests that cover the new or changed functionality. -Ideally, when fixing a bug, a matching unit test that verifies that the bug is no longer present, is added at the same time. - -To run the test suite, simply execute the following in the directory where you cloned Bash-it: - -```bash -test/run -``` - -This command will ensure that the [Bats Test Framework](https://github.com/bats-core/bats-core) is available in the local `test_lib` directory (Bats is included as a Git submodule) and then run the test suite found in the [test](test) folder. -The test script will execute each test in turn, and will print a status for each test case. - -When adding new test cases, please take a look at the existing test cases for examples. - -The following libraries are used to help with the tests: - -* Test Framework: https://github.com/bats-core/bats-core -* Support library for Bats-Assert: https://github.com/ztombol/bats-support -* General `assert` functions: https://github.com/ztombol/bats-assert -* File `assert` functions: https://github.com/ztombol/bats-file - -When verifying test results, please try to use the `assert` functions found in these libraries. - -## Features - -* When adding new completions or plugins, please don't simply copy existing tools into the Bash-it codebase, try to load/integrate the tools instead. - An example is using `nvm`: Instead of copying the existing `nvm` script into Bash-it, the `nvm.plugin.bash` file tries to load an existing installation of `nvm`. - This means an additional step for the user (installing `nvm` from its own repo, or through a package manager), - but it will also ensure that `nvm` can be upgraded in an easy way. - -## Themes - -* When adding a new theme, please include a screenshot and a short description about what makes this theme unique in the Pull Request's description field. - Please do not add theme screenshots to the repo itself, as they will add unnecessary bloat to the repo. - The project's Wiki has a _Themes_ page where you can add a screenshot if you want. -* Ideally, each theme's folder should contain a `README.md` file describing the theme and its configuration options. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md deleted file mode 100644 index ba9efe60..00000000 --- a/DEVELOPMENT.md +++ /dev/null @@ -1,45 +0,0 @@ -# Bash-it Development - -This page summarizes a couple of rules to keep in mind when developing features or making changes in Bash-it. - -## Load Order - -### General Load Order - -The main `bash_it.sh` script loads the frameworks individual components in the following order: - -* `lib/composure.bash` -* Files in `lib` with the exception of `appearance.bash` - this means that `composure.bash` is loaded again here (possible improvement?) -* Enabled `aliases` -* Enabled `plugins` -* Enabled `completions` -* `themes/colors.theme.bash` -* `themes/base.theme.bash` -* `lib/appearance.bash`, which loads the selected theme -* Custom `aliases` -* Custom `plugins` -* Custom `completions` -* Additional custom files from either `$BASH_IT/custom` or `$BASH_IT_CUSTOM` - -This order is subject to change. - -### Individual Component Load Order - -For `aliases`, `plugins` and `completions`, the following rules are applied that influence the load order: - -* There is a global `enabled` directory, which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/enabled` for example. All component types are linked into the same common `$BASH_IT/enabled` directory. -* Within the common `enabled` directories, the files are loaded in alphabetical order, which is based on the item's load priority (see next item). -* When enabling a component, a _load priority_ is assigned to the file. The following default priorities are used: - * Aliases: 150 - * Plugins: 250 - * Completions: 350 -* When symlinking a component into the `enabled` directory, the load priority is used as a prefix for the linked name, separated with three dashes from the name of the component. The `node.plugin.bash` would be symlinked to `250---node.plugin.bash` for example. -* Each file can override the default load priority by specifying a new value. To do this, the file needs to include a comment in the following form. This example would cause the `node.plugin.bash` (if included in that file) to be linked to `225---node.plugin.bash`: - - ```bash - # BASH_IT_LOAD_PRIORITY: 225 - ``` - -Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name. - -These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. diff --git a/README.md b/README.md deleted file mode 100644 index 13a991da..00000000 --- a/README.md +++ /dev/null @@ -1,456 +0,0 @@ -# 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) - -**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:) - -Includes autocompletion, themes, aliases, custom functions, a few stolen pieces from Steve Losh, and more. - -Bash-it provides a solid framework for using, developing and maintaining shell scripts and custom commands for your daily work. -If you're using the _Bourne Again Shell_ (Bash) on a regular basis and have been looking for an easy way on how to keep all of these nice little scripts and aliases under control, then Bash-it is for you! -Stop polluting your `~/bin` directory and your `.bashrc` file, fork/clone Bash-it and start hacking away. - -- [Contributing](#contributing) -- [Installation](#installation) - - [Install Options](#install-options) - - [via Docker](#install-using-docker) - - [Updating](#updating) -- [Help](#help-screens) -- [Search](#search) - - [Syntax](#syntax) - - [Searching with Negations](#searching-with-negations) - - [Using Search to Enable or Disable Components](#using-search-to-enable-or-disable-components) - - [Disabling ASCII Color](#disabling-ascii-color) -- [Custom scripts, aliases, themes, and functions](#custom-scripts-aliases-themes-and-functions) -- [Themes](#themes) -- [Uninstalling](#uninstalling) -- [Misc](#misc) -- [Help Out](#help-out) -- [Contributors](#contributors) - -## Contributing - -Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before reporting a bug or providing a new feature. - -The [Development Guidelines](DEVELOPMENT.md) have more information on some of the internal workings of Bash-it, -please feel free to read through this page if you're interested in how Bash-it loads its components. - -## Installation - -1. Check out a clone of this repo to a location of your choice, such as - `git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it` -2. Run `~/.bash_it/install.sh` (it automatically backs up your `~/.bash_profile` or `~/.bashrc`, depending on your OS) -3. Edit your modified config (`~/.bash_profile` or `~/.bashrc`) file in order to customize Bash-it. -4. Check out available aliases, completions, and plugins and enable the ones you want to use (see the next section for more details). - -### Install Options - -The install script can take the following options: - -* `--interactive`: Asks the user which aliases, completions and plugins to enable. -* `--silent`: Ask nothing and install using default settings. -* `--no-modify-config`: Do not modify the existing config file (`~/.bash_profile` or `~/.bashrc`). - -When run without the `--interactive` switch, Bash-it only enables a sane default set of functionality to keep your shell clean and to avoid issues with missing dependencies. -Feel free to enable the tools you want to use after the installation. - -When you run without the `--no-modify-config` switch, the Bash-it installer automatically modifies/replaces your existing config file. -Use the `--no-modify-config` switch to avoid unwanted modifications, e.g. if your Bash config file already contains the code that loads Bash-it. - -**NOTE**: Keep in mind how Bash load its configuration files, -`.bash_profile` for login shells (and in macOS in terminal emulators like [Terminal.app](http://www.apple.com/osx/apps/) or -[iTerm2](https://www.iterm2.com/)) and `.bashrc` for interactive shells (default mode in most of the GNU/Linux terminal emulators), -to ensure that Bash-it is loaded correctly. -A good "practice" is sourcing `.bashrc` into `.bash_profile` to keep things working in all the scenarios. -To achieve this, you can add this snippet in your `.bash_profile`: - -``` -if [ -f ~/.bashrc ]; then - . ~/.bashrc -fi -``` - -Refer to the official [Bash documentation](https://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files) to get more info. - - -### Install using Docker - -You can try Bash-it in an isolated environment without changing any local files via a [Docker](https://www.docker.com/) Container. -(Bash Shell v4.4 with Bash-it, [bats](https://github.com/sstephenson/bats) and bash-completion based on [Alpine Linux](https://alpinelinux.org/)). - -`docker pull ellerbrock/bash-it` - -Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-it-docker) for further information. - - -### Updating - -To update Bash-it to the latest version, simply run: - -```bash -bash-it update -``` - -that's all. - -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: - -```bash -bash-it migrate -``` - -This command will automatically migrate the Bash-it structure to the latest version. -The `migrate` command is run automatically if you run the `update`, `enable` or `disable` commands. - -## Help Screens - -```bash -bash-it show aliases # shows installed and available aliases -bash-it show completions # shows installed and available completions -bash-it show plugins # shows installed and available plugins -bash-it help aliases # shows help for installed aliases -bash-it help completions # shows help for installed completions -bash-it help plugins # shows help for installed plugins -``` - -## Search - -If you need to quickly find out which of the plugins, aliases or completions are available for a specific framework, programming language, or an environment, you can _search_ for multiple terms related to the commands you use frequently. -Search will find and print out modules with the name or description matching the terms provided. - -### Syntax - -```bash - bash-it search term1 [[-]term2] [[-]term3].... -``` - -As an example, a ruby developer might want to enable everything related to the commands such as `ruby`, `rake`, `gem`, `bundler`, and `rails`. -Search command helps you find related modules so that you can decide which of them you'd like to use: - -```bash -❯ bash-it search ruby rake gem bundle irb rails - aliases: bundler rails - plugins: chruby chruby-auto ruby - completions: bundler gem rake -``` - -Currently enabled modules will be shown in green. - -### Searching with Negations - -You can prefix a search term with a "-" to exclude it from the results. -In the above example, if we wanted to hide `chruby` and `chruby-auto`, -we could change the command as follows: - -```bash -❯ bash-it search ruby rake gem bundle irb rails -chruby - aliases: bundler rails - plugins: ruby - completions: bundler gem rake -``` - -### Using Search to Enable or Disable Components - -By adding a `--enable` or `--disable` to the search command, you can automatically enable all modules that come up as a result of a search query. -This could be quite handy if you like to enable a bunch of components related to the same topic. - -### Disabling ASCII Color - -To remove non-printing non-ASCII characters responsible for the coloring of the search output, you can set environment variable `NO_COLOR`. -Enabled components will then be shown with a checkmark: - -```bash -❯ NO_COLOR=1 bash-it search ruby rake gem bundle irb rails -chruby - aliases => ✓bundler ✓rails - plugins => ✓ruby - completions => bundler gem rake -``` - -## Custom scripts, aliases, themes, and functions - -For custom scripts, and aliases, just create the following files (they'll be ignored by the git repo): - -* `aliases/custom.aliases.bash` -* `completion/custom.completion.bash` -* `lib/custom.bash` -* `plugins/custom.plugins.bash` -* `custom/themes//.theme.bash` - -Anything in the custom directory will be ignored, with the exception of `custom/example.bash`. - -Alternately, if you would like to keep your custom scripts under version control, you can set `BASH_IT_CUSTOM` in your `~/.bashrc` to another location outside of the `$BASH_IT` folder. -In this case, any `*.bash` file under every directory below `BASH_IT_CUSTOM` folder will be used. - -## Themes - -There are over 50+ Bash-it themes to pick from in `$BASH_IT/themes`. -The default theme is `bobby`. -Set `BASH_IT_THEME` to the theme name you want, or if you've developed your own custom theme outside of `$BASH_IT/themes`, -point the `BASH_IT_THEME` variable directly to the theme file. -To disable theming completely, leave the variable empty. - -Examples: - -```bash -# Use the "powerline-multiline" theme -export BASH_IT_THEME="powerline-multiline" - -# Use a theme outside of the Bash-it folder -export BASH_IT_THEME="/home/foo/my_theme/my_theme.theme.bash" - -# Disable theming -export BASH_IT_THEME="" -``` - -You can easily preview the themes in your own shell using `BASH_PREVIEW=true bash-it reload`. - -If you've created your own custom prompts, we'd love it if you shared with everyone else! Just submit a Pull Request. -You can see theme screenshots on [wiki/Themes](https://github.com/Bash-it/bash-it/wiki/Themes). - -**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if it isn't American English. - -## Uninstalling - -To uninstall Bash-it, run the `uninstall.sh` script found in the `$BASH_IT` directory: - -``` -cd $BASH_IT -./uninstall.sh -``` - -This will restore your previous Bash profile. -After the uninstall script finishes, remove the Bash-it directory from your machine (`rm -rf $BASH_IT`) and start a new shell. - -## Misc - -### Bash Profile Aliases - -Bash-it creates a `reload` alias that makes it convenient to reload -your Bash profile when you make changes. - -Additionally, if you export `BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE` as a non-null value, -Bash-it will automatically reload itself after activating or deactivating plugins, aliases, or completions. - -### Prompt Version Control Check - -Bash-it provides prompt themes the ability to check and display version control information for the current directory. -The information is retrieved for each directory and can slow down the navigation of projects with a large number of files and folders. -Turn version control checking off to prevent slow directory navigation within large projects. - -Bash-it provides a flag (`SCM_CHECK`) within the `~/.bash_profile` file that turns off/on version control information checking and display within all themes. -Version control checking is on by default unless explicitly turned off. - -Set `SCM_CHECK` to 'false' to **turn off** version control checks for all themes: - -* `export SCM_CHECK=false` - -Set `SCM_CHECK` to 'true' (the default value) to **turn on** version control checks for all themes: - -* `export SCM_CHECK=true` - -**NOTE:** -It is possible for themes to ignore the `SCM_CHECK` flag and query specific version control information directly. -For example, themes that use functions like `git_prompt_vars` skip the `SCM_CHECK` flag to retrieve and display git prompt information. -If you turned version control checking off and you still see version control information within your prompt, then functions like `git_prompt_vars` are most likely the reason why. - -### Git prompt - -Bash-it has some nice features related to Git, continue reading to know more about these features. - -### Repository info in the prompt - -Bash-it can show some information about Git repositories in the shell prompt: the current branch, tag or commit you are at, how many commits the local branch is ahead or behind from the remote branch, and if you have changes stashed. - -Additionally, you can view the status of your working copy and get the count of *staged*, *unstaged* and *untracked* files. -This feature is controlled through the flag `SCM_GIT_SHOW_DETAILS` as follows: - -Set `SCM_GIT_SHOW_DETAILS` to 'true' (the default value) to **show** the working copy details in your prompt: - -* `export SCM_GIT_SHOW_DETAILS=true` - -Set `SCM_GIT_SHOW_DETAILS` to 'false' to **don't show** it: - -* `export SCM_GIT_SHOW_DETAILS=false` - -**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_DETAILS` is ignored. - -### Remotes and remote branches - -In some git workflows, you must work with various remotes, for this reason, Bash-it can provide some useful information about your remotes and your remote branches, for example, the remote on you are working, or if your local branch is tracking a remote branch. - -You can control this feature with the flag `SCM_GIT_SHOW_REMOTE_INFO` as follows: - -Set `SCM_GIT_SHOW_REMOTE_INFO` to 'auto' (the default value) to activate it only when more than one remote is configured in the current repo: - -* `export SCM_GIT_SHOW_REMOTE_INFO=auto` - -Set `SCM_GIT_SHOW_REMOTE_INFO` to 'true' to always activate the feature: - -* `export SCM_GIT_SHOW_REMOTE_INFO=true` - -Set `SCM_GIT_SHOW_REMOTE_INFO` to 'false' to **disable the feature**: - -* `export SCM_GIT_SHOW_REMOTE_INFO=false` - -**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_REMOTE_INFO` is ignored. - -### Untracked files - -By default, the `git status` command shows information about *untracked* files. -This behavior can be controlled through command-line flags or git configuration files. -For big repositories, ignoring *untracked* files can make git faster. -Bash-it uses `git status` to gather the repo information it shows in the prompt, so in some circumstances, it can be useful to instruct Bash-it to ignore these files. -You can control this behavior with the flag `SCM_GIT_IGNORE_UNTRACKED`: - -Set `SCM_GIT_IGNORE_UNTRACKED` to 'false' (the default value) to get information about *untracked* files: - -* `export SCM_GIT_IGNORE_UNTRACKED=false` - -Set `SCM_GIT_IGNORE_UNTRACKED` to 'true' to **ignore** *untracked* files: - -* `export SCM_GIT_IGNORE_UNTRACKED=true` - -Also, with this flag to false, Bash-it will not show the repository as dirty when the repo has *untracked* files, and will not display the count of *untracked* files. - -**NOTE:** If you set in git configuration file the option to ignore *untracked* files, this flag has no effect, and Bash-it will ignore *untracked* files always. - -### Stash item count - -When `SCM_GIT_SHOW_DETAILS` is enabled, you can get the count of *stashed* items. This feature can be useful when a user has a lot of stash items. -This feature is controlled through the flag `SCM_GIT_SHOW_STASH_INFO` as follows: - -Set `SCM_GIT_SHOW_STASH_INFO` to 'true' (the default value) to **show** the count of stashed items: - -* `export SCM_GIT_SHOW_STASH_INFO=true` - -Set `SCM_GIT_SHOW_STASH_INFO` to 'false' to **don't show** it: - -* `export SCM_GIT_SHOW_STASH_INFO=false` - -### Git user - -In some environments, it is useful to know the value of the current git user, which is used to mark all new commits. -For example, any organization that uses the practice of pair programming will typically author each commit with [combined names of the two authors](https://github.com/pivotal/git_scripts). -When another pair uses the same pairing station, the authors are changed at the beginning of the session. - -To get up and running with this technique, run `gem install pivotal_git_scripts`, and then edit your `~/.pairs` file, according to the specification on the [gem's homepage](https://github.com/pivotal/git_scripts). -After that, you should be able to run `git pair kg as` to set the author to, eg. "Konstantin Gredeskoul and Alex Saxby", assuming they've been added to the `~/.pairs` file. -Please see gem's documentation for more information. - -To enable the display of the current pair in the prompt, you must set `SCM_GIT_SHOW_CURRENT_USER` to `true`. -Once set, the `SCM_CURRENT_USER` variable will be automatically populated with the initials of the git author(s). -It will also be included in the default git prompt. -Even if you do not have `git pair` installed, as long as your `user.name` is set, your initials will be computed from your name and shown in the prompt. - -You can control the prefix and the suffix of this component using the two variables: - -* `export SCM_THEME_CURRENT_USER_PREFFIX=' ☺︎ '` - -And - -* `export SCM_THEME_CURRENT_USER_SUFFIX=' ☺︎ '` - -**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_CURRENT_USER` is ignored. - -### Git show minimal status info - -To speed up the prompt while still getting minimal git status information displayed such as the value of `HEAD` and whether there are any dirty objects, you can set: - -``` -export SCM_GIT_SHOW_MINIMAL_INFO=true -``` - -### Ignore repo status - -When working in repos with a large codebase, Bash-it can slow down your prompt when checking the repo status. -To avoid it, there is an option you can set via Git config to disable checking repo status in Bash-it. - -To disable checking the status in the current repo: - -``` -$ git config --add bash-it.hide-status 1 -``` - -But if you would like to disable it globally, and stop checking the status for all of your repos: - -``` -$ 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. - -### 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/). -In order to minimize the impact on users of the legacy Bash-it `pass` function, Bash-it will create the alias `pass` that calls the new `passgen` function if the `pass` password manager command is not found on the `PATH` (default behavior). - -This behavior can be overridden with the `BASH_IT_LEGACY_PASS` flag as follows: - -Set `BASH_IT_LEGACY_PASS` to 'true' to force Bash-it to always **create** the `pass` alias to `passgen`: - -* `export BASH_IT_LEGACY_PASS=true` - -Unset `BASH_IT_LEGACY_PASS` to have Bash-it **return to default behavior**: - -* `unset BASH_IT_LEGACY_PASS` - -### Proxy Support - -If you are working in a corporate environment where you have to go through a proxy server for internet access, -then you know how painful it is to configure the OS proxy variables in the shell, -especially if you are switching between environments, e.g. office (with proxy) and home (without proxy). - -The Bash shell (and many shell tools) use the following variables to define the proxy to use: - -* `HTTP_PROXY` (and `http_proxy`): Defines the proxy server for HTTP requests -* `HTTPS_PROXY` (and `https_proxy`): Defines the proxy server for HTTPS requests -* `ALL_PROXY` (and `all_proxy`): Used by some tools for the same purpose as above -* `NO_PROXY` (and `no_proxy`): Comma-separated list of hostnames that don't have to go through the proxy - -Bash-it's `proxy` plugin allows to enable and disable these variables with a simple command. -To start using the `proxy` plugin, run the following: - -```bash -bash-it enable plugin proxy -``` - -Bash-it also provides support for enabling/disabling proxy settings for various shell tools. -The following backends are currently supported (in addition to the shell's environment variables): Git, SVN, npm, ssh. -The `proxy` plugin changes the configuration files of these tools to enable or disable the proxy settings. - -Bash-it uses the following variables to set the shell's proxy settings when you call `enable-proxy`. -These variables are best defined in a custom script in Bash-it's custom script folder (`$BASH_IT/custom`), e.g. `$BASH_IT/custom/proxy.env.bash` -* `BASH_IT_HTTP_PROXY` and `BASH_IT_HTTPS_PROXY`: Define the proxy URL to be used, e.g. 'http://localhost:1234' -* `BASH_IT_NO_PROXY`: A comma-separated list of proxy exclusions, e.g. `127.0.0.1,localhost` - -Once you have defined these variables (and have run `reload` to load the changes), you can use the following commands to enable or disable the proxy settings in your current shell: - -* `enable-proxy`: This sets the shell's proxy environment variables and configures proxy support in your SVN, npm, and SSH configuration files. -* `disable-proxy`: This unsets the shell's proxy environment variables and disables proxy support in your SVN, npm, and SSH configuration files. - -There are many more proxy commands, e.g. for changing the local Git project's proxy settings. -Run `glossary proxy` to show the available proxy functions with a short description. - -## Help out - -We think everyone has their own custom scripts accumulated over time. -And so, following in the footsteps of oh-my-zsh, Bash-it is a framework for easily customizing your Bash shell. -Everyone's got a custom toolbox, so let's start making them even better, **as a community!** - -Send us a pull request and we'll merge it as long as it looks good. -If you change an existing command, please give an explanation why. -That will help a lot when we merge your changes in. - -Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before reporting a bug or providing a new feature. - -Thanks, and happing bashing! - - -## Contributors - -* [List of contributors][contribute] - -[contribute]: https://github.com/Bash-it/bash-it/contributors -[pass password manager]: http://www.passwordstore.org/ 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/clipboard.aliases.bash b/aliases/available/clipboard.aliases.bash index 528e2d0e..c6c15519 100644 --- a/aliases/available/clipboard.aliases.bash +++ b/aliases/available/clipboard.aliases.bash @@ -7,7 +7,7 @@ case $OSTYPE in [[ $XCLIP ]] && \ alias pbcopy="$XCLIP -selection clipboard" && \ alias pbpaste="$XCLIP -selection clipboard -o" - ;; + ;; esac # to use it just install xclip on your distribution and it would work like: 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..495ea851 100644 --- a/aliases/available/fuck.aliases.bash +++ b/aliases/available/fuck.aliases.bash @@ -1,3 +1,10 @@ -# 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 d3f25425..a46b44fa 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -22,12 +22,14 @@ 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 gpd='git push --delete' +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,26 +37,35 @@ 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' alias gbD='git branch -D' alias gcount='git shortlog -sn' alias gcp='git cherry-pick' +alias gcpx='git cherry-pick -x' alias gco='git checkout' alias gcom='git checkout master' alias gcb='git checkout -b' alias gcob='git checkout -b' +alias gcobu='git checkout -b ${USER}/' alias gct='git checkout --track' alias gcpd='git checkout master; git pull; git branch -D' alias gexport='git archive --format zip --output' @@ -62,7 +73,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" @@ -75,17 +88,45 @@ 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' +# Git SVN +alias gsr='git svn rebase' +alias gsd='git svn dcommit' + case $OSTYPE in darwin*) alias gtls="git tag -l | gsort -V" 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/node.aliases.bash b/aliases/available/node.aliases.bash new file mode 100644 index 00000000..a1408f26 --- /dev/null +++ b/aliases/available/node.aliases.bash @@ -0,0 +1,8 @@ +cite 'about-alias' +about-alias 'the Node.js environment aliases' + +# alias to setup nodejs development environment +alias node-dev='export NODE_ENV=development' + +# alias to setup nodejs production environment +alias node-prod='export NODE_ENV=production' 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/puppet.aliases.bash b/aliases/available/puppet.aliases.bash index bb5b4a1a..15b69923 100644 --- a/aliases/available/puppet.aliases.bash +++ b/aliases/available/puppet.aliases.bash @@ -7,4 +7,3 @@ alias puplint="puppet-lint *.pp" alias pupagt="puppet agent -t" alias pupagtd="puppet agent -t --debug" alias pupapp="puppet apply" - diff --git a/aliases/available/terraform.aliases.bash b/aliases/available/terraform.aliases.bash new file mode 100644 index 00000000..d62a8c2c --- /dev/null +++ b/aliases/available/terraform.aliases.bash @@ -0,0 +1,10 @@ +# 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..9395b351 --- /dev/null +++ b/aliases/available/terragrunt.aliases.bash @@ -0,0 +1,15 @@ +# 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/clean_files.txt b/clean_files.txt new file mode 100644 index 00000000..8c4e5926 --- /dev/null +++ b/clean_files.txt @@ -0,0 +1,36 @@ +####################################################################### +# Allow-list of files to be lint-checked by CI +# +# Directory Suport +# Directory references are allowed within the file, ie: +# +# themes/powerline +# +# All files under the referenced directory will be checked +# +# Checking Files Locally +# You can manually invoke the check via: +# +# lint_clean_files.sh +# + +# root directories +# +docs + +# root files +# +.gitattributes +lint_clean_files.sh + +# themes +# +themes/90210 +themes/powerline + +# completions +# +completion/available/cargo.completion.bash +completion/available/knife.completion.bash +completion/available/pipx.completion.bash +completion/available/rustup.completion.bash 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