Merge remote-tracking branch 'upstream/master'

pull/1237/head
Ari Mourao 2018-01-08 15:36:46 +00:00
commit 55179e1996
81 changed files with 4052 additions and 842 deletions

3
.gitignore vendored
View File

@ -12,3 +12,6 @@ plugins/custom.plugins.bash
.*.un~
bats
.idea
*.sublime-workspace
*.sublime-project
enabled/*

12
.gitmodules vendored 100644
View File

@ -0,0 +1,12 @@
[submodule "test_lib/bats-core"]
path = test_lib/bats-core
url = https://github.com/bats-core/bats-core
[submodule "test_lib/bats-support"]
path = test_lib/bats-support
url = https://github.com/ztombol/bats-support
[submodule "test_lib/bats-assert"]
path = test_lib/bats-assert
url = https://github.com/ztombol/bats-assert
[submodule "test_lib/bats-file"]
path = test_lib/bats-file
url = https://github.com/ztombol/bats-file

View File

@ -1,38 +1,56 @@
# 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.
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...
* 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. Don't create a PR consisting of 20 commits that show your work in progress. Before you create the PR, _squash_ your changes into a single commit.
* 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.
Don't create a PR consisting of 20 commits that show your work in progress.
Before you create the PR, _squash_ your changes into a single commit.
## 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`.
* 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.
* 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.
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.
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.
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:
@ -40,15 +58,30 @@ To run the test suite, simply execute the following in the directory where you c
test/run
```
This command will clone the [Bats Test Framework](https://github.com/sstephenson/bats) to a local directory 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.
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.
* 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.
* 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.

View File

@ -27,17 +27,19 @@ This order is subject to change.
For `aliases`, `plugins` and `completions`, the following rules are applied that influence the load order:
* Each type has its own `enabled` directory, into which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/plugins/enabled` for example.
* Within each of the `enabled` directories, the files are loaded in alphabetical 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 an `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.
* 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.

209
README.md
View File

@ -2,37 +2,68 @@
[![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:)
**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.
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.
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.
## Install
## 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`
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).
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
**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 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.
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 Mac OS X 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`:
**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
@ -40,20 +71,20 @@ if [ -f ~/.bashrc ]; then
fi
```
Refer to the official [Bash documention](https://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files) to get more info.
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
### Install using Docker
You can try Bash-it in an isolated enviroment without changing any local files via a [Docker](https://www.docker.com/) Container.
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 respository](https://github.com/Bash-it/bash-it-docker) for further information.
Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-it-docker) for further information.
## Update
### Updating
To update Bash-it to the latest version, simply run:
@ -63,13 +94,15 @@ 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:
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.
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
@ -84,22 +117,17 @@ 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.
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
### 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:
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
@ -110,11 +138,11 @@ of them you'd like to use:
Currently enabled modules will be shown in green.
#### Search with Negations
### 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:
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
@ -123,17 +151,15 @@ follows:
completions: bundler gem rake
```
#### Using Search to Enable or Disable Components
### 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.
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
### 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:
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
@ -142,7 +168,7 @@ then be shown with a checkmark:
completions => bundler gem rake
```
## Your Custom scripts, aliases, themes, and functions
## Custom scripts, aliases, themes, and functions
For custom scripts, and aliases, just create the following files (they'll be ignored by the git repo):
@ -154,11 +180,15 @@ For custom scripts, and aliases, just create the following files (they'll be ign
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.
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.
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.
Examples:
@ -175,7 +205,7 @@ You can easily preview the themes in your own shell using `BASH_PREVIEW=true rel
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 isn't American English.
**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
@ -186,7 +216,8 @@ 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.
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
@ -195,13 +226,17 @@ This will restore your previous Bash profile. After the uninstall script finishe
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.
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 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.
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:
@ -212,17 +247,20 @@ Set `SCM_CHECK` to 'true' (the default value) to **turn on** version control che
* `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.
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
### 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:
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:
@ -234,9 +272,9 @@ Set `SCM_GIT_SHOW_DETAILS` to 'false' to **don't show** it:
**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_DETAILS` is ignored.
#### Remotes and remote branches
### 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.
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:
@ -254,9 +292,13 @@ Set `SCM_GIT_SHOW_REMOTE_INFO` to 'false' to **disable the feature**:
**NOTE:** If using `SCM_GIT_SHOW_MINIMAL_INFO=true`, then the value of `SCM_GIT_SHOW_REMOTE_INFO` is ignored.
#### Untracked files
### Untracked files
By default, `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, can be useful to instruct Bash-it to ignore these files. You can control this behavior with the flag `SCM_GIT_IGNORE_UNTRACKED`:
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:
@ -266,17 +308,24 @@ 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 have *untracked* files, and will not display the count of *untracked* files.
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.
#### Git user
### 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 a [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.
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 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.
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:
@ -284,21 +333,22 @@ You can control the prefix and the suffix of this component using the two variab
And
* `export SCM_THEME_CURRENT_USER_SUFFIX=' '``
* `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
### 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:
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
### Ignore repo status
When working in repos with a large code base 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.
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:
@ -312,11 +362,12 @@ But if you would like to disable it globally, and stop checking the status for a
$ git config --global --add bash-it.hide-status 1
```
setting this flag globally has the same effect that `SCM_CHECK=true` but only for Git repos.
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]. 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).
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:
@ -330,7 +381,9 @@ Unset `BASH_IT_LEGACY_PASS` to have Bash-it **return to default behavior**:
### 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).
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:
@ -339,13 +392,16 @@ The Bash shell (and many shell tools) use the following variables to define the
* `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-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 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`
@ -354,16 +410,21 @@ These variables are best defined in a custom script in Bash-it's custom script f
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.
* `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.
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!**
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.
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.

View File

@ -9,7 +9,16 @@ alias dkpsa='docker ps -a' # List all Docker containers
alias dki='docker images' # List Docker images
alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
case $OSTYPE in
darwin*|*bsd*|*BSD*)
alias dkrmui='docker images -q -f dangling=true | xargs docker rmi' # Delete all untagged Docker images
;;
*)
alias dkrmui='docker images -q -f dangling=true | xargs -r docker rmi' # Delete all untagged Docker images
;;
esac
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image
alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments

View File

@ -45,7 +45,7 @@ alias pager="$PAGER"
alias q='exit'
alias irc="$IRC_CLIENT"
alias irc="${IRC_CLIENT:=irc}"
# Language aliases
alias rb='ruby'
@ -57,6 +57,7 @@ alias ipy='ipython'
alias piano='pianobar'
alias ..='cd ..' # Go up one directory
alias cd..='cd ..' # Common misspelling for going up one directory
alias ...='cd ../..' # Go up two directories
alias ....='cd ../../..' # Go up three directories
alias -- -='cd -' # Go back

View File

@ -39,12 +39,15 @@ 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 gcam='git commit -a -m'
alias gb='git branch'
alias gba='git branch -a'
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 gco='git checkout'
@ -70,10 +73,10 @@ 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"
alias ggui="git gui"
alias gcam="git commit -am"
alias gcsam="git commit -S -am"
alias gstd="git stash drop"
alias gstl="git stash list"
alias gh='cd "$(git rev-parse --show-toplevel)"'
case $OSTYPE in
darwin*)

View File

@ -3,7 +3,7 @@ about-alias 'laravel artisan abbreviations'
# A list of useful laravel aliases
alias laravel="/home/${USER}/.composer/vendor/bin/laravel"
alias laravel="${HOME}/.composer/vendor/bin/laravel"
# asset
alias a:apub='php artisan asset:publish'

View File

@ -0,0 +1,152 @@
cite 'about-alias'
about-alias 'pyrocms abbreviations'
###
## PyroCMS 3.4 bash aliases
## @author Denis Efremov <efremov.a.denis@gmail.com>
###
# general
alias a:cl="php artisan clear-compiled" # Remove the compiled class file
alias a:d="php artisan down" # Put the application into maintenance mode
alias a:e="php artisan env" # Display the current framework environment
alias a:h="php artisan help" # Displays help for a command
alias a:i="php artisan install" # Install the Streams Platform.
alias a:ls="php artisan list" # Lists commands
alias a:mg="php artisan migrate" # Run the database migrations
alias a:op="php artisan optimize" # Optimize the framework for better performance (deprecated)
alias a:pr="php artisan preset" # Swap the front-end scaffolding for the application
alias a:s="php artisan serve" # Serve the application on the PHP development server
alias a:u="php artisan up" # Bring the application out of maintenance mode
# addon
alias a:ad:i="php artisan addon:install" # Install an addon.
alias a:ad:p="php artisan addon:publish" # Publish an the configuration and translations for an addon.
alias a:ad:r="php artisan addon:reinstall" # Reinstall an addon.
alias a:ad:u="php artisan addon:uninstall" # Uninstall an addon.
# app
alias a:ap:n="php artisan app:name" # Set the application namespace
alias a:ap:p="php artisan app:publish" # Publish general application override files.
# assets
alias a:as:cl="php artisan assets:clear" # Clear compiled public assets.
# auth
alias a:au:clrs="php artisan auth:clear-resets" # Flush expired password reset tokens
# cache
alias a:ca:cl="php artisan cache:clear" # Flush the application cache
alias a:ca:f="php artisan cache:forget" # Remove an item from the cache
alias a:ca:t="php artisan cache:table" # Create a migration for the cache database table
# config
alias a:co:ca="php artisan config:cache" # Create a cache file for faster configuration loading
alias a:co:cl="php artisan config:clear" # Remove the configuration cache file
# db
alias a:db:s="php artisan db:seed" # Seed the database with records
# env
alias a:en:s="php artisan env:set" # Set an environmental value.
# event
alias a:ev:g="php artisan event:generate" # Generate the missing events and listeners based on registration
# extension
alias a:ex:i="php artisan extension:install" # Install a extension.
alias a:ex:r="php artisan extension:reinstall" # Reinstall a extension.
alias a:ex:u="php artisan extension:uninstall" # Uninstall a extension.
# files
alias a:fi:cl="php artisan files:clean" # Clean missing files from the files table.
# key
alias a:ke:g="php artisan key:generate" # Set the application key
# make
alias a:mk:ad="php artisan make:addon" # Create a new addon.
alias a:mk:au="php artisan make:auth" # Scaffold basic login and registration views and routes
alias a:mk:cm="php artisan make:command" # Create a new Artisan command
alias a:mk:ct="php artisan make:controller" # Create a new controller class
alias a:mk:ev="php artisan make:event" # Create a new event class
alias a:mk:fa="php artisan make:factory" # Create a new model factory
alias a:mk:j="php artisan make:job" # Create a new job class
alias a:mk:li="php artisan make:listener" # Create a new event listener class
alias a:mk:ma="php artisan make:mail" # Create a new email class
alias a:mk:mw="php artisan make:middleware" # Create a new middleware class
alias a:mk:mg="php artisan make:migration" # Create a new migration file
alias a:mk:md="php artisan make:model" # Create a new Eloquent model class
alias a:mk:no="php artisan make:notification" # Create a new notification class
alias a:mk:po="php artisan make:policy" # Create a new policy class
alias a:mk:pr="php artisan make:provider" # Create a new service provider class
alias a:mk:rq="php artisan make:request" # Create a new form request class
alias a:mk:rs="php artisan make:resource" # Create a new resource
alias a:mk:rl="php artisan make:rule" # Create a new validation rule
alias a:mk:sd="php artisan make:seeder" # Create a new seeder class
alias a:mk:st="php artisan make:stream" # Make a streams entity namespace.
alias a:mk:ts="php artisan make:test" # Create a new test class
# migrate
alias a:mg:fr="php artisan migrate:fresh" # Drop all tables and re-run all migrations
alias a:mg:i="php artisan migrate:install" # Create the migration repository
alias a:mg:rf="php artisan migrate:refresh" # Reset and re-run all migrations
alias a:mg:rs="php artisan migrate:reset" # Rollback all database migrations
alias a:mg:rl="php artisan migrate:rollback" # Rollback the last database migration
alias a:mg:st="php artisan migrate:status" # Show the status of each migration
# module
alias a:mo:i="php artisan module:install" # Install a module.
alias a:mo:r="php artisan module:reinstall" # Reinstall a module.
alias a:mo:u="php artisan module:uninstall" # Uninstall a module.
# notifications
alias a:no:tb="php artisan notifications:table" # Create a migration for the notifications table
# package
alias a:pk:d="php artisan package:discover" # Rebuild the cached package manifest
# queue
alias a:qu:fa="php artisan queue:failed" # List all of the failed queue jobs
alias a:qu:ft="php artisan queue:failed-table" # Create a migration for the failed queue jobs database table
alias a:qu:fl="php artisan queue:flush" # Flush all of the failed queue jobs
alias a:qu:fg="php artisan queue:forget" # Delete a failed queue job
alias a:qu:li="php artisan queue:listen" # Listen to a given queue
alias a:qu:rs="php artisan queue:restart" # Restart queue worker daemons after their current job
alias a:qu:rt="php artisan queue:retry" # Retry a failed queue job
alias a:qu:tb="php artisan queue:table" # Create a migration for the queue jobs database table
alias a:qu:w="php artisan queue:work" # Start processing jobs on the queue as a daemon
# route
alias a:ro:ca="php artisan route:cache" # Create a route cache file for faster route registration
alias a:ro:cl="php artisan route:clear" # Remove the route cache file
alias a:ro:ls="php artisan route:list" # List all registered routes
# schedule
alias a:sc:r="php artisan schedule:run" # Run the scheduled commands
# scout
alias a:su:fl="php artisan scout:flush" # Flush all of the model's records from the index
alias a:su:im="php artisan scout:import" # Import the given model into the search index
# session
alias a:se:tb="php artisan session:table" # Create a migration for the session database table
# storage
alias a:sg:l="php artisan storage:link" # Create a symbolic link from "public/storage" to "storage/app/public"
# streams
alias a:st:cl="php artisan streams:cleanup" # Cleanup streams entry models.
alias a:st:co="php artisan streams:compile" # Compile streams entry models.
alias a:st:d="php artisan streams:destroy" # Destroy a namespace.
alias a:st:p="php artisan streams:publish" # Publish configuration and translations for streams.
alias a:st:r="php artisan streams:refresh" # Refresh streams generated components.
# tntsearch
alias a:tn:im="php artisan tntsearch:import" # Import the given model into the search index
# vendor
alias a:ve:p="php artisan vendor:publish" # Publish any publishable assets from vendor packages
# view
alias a:vi:cl="php artisan view:clear" # Clear all compiled view files

View File

@ -0,0 +1,15 @@
cite 'about-alias'
about-alias 'systemd service'
case $OSTYPE in
linux*)
alias sc='systemctl'
alias scr='systemctl daemon-reload'
alias scu='systemctl --user'
alias scur='systemctl --user daemon-reload'
alias sce='systemctl stop'
alias scue='systemctl --user stop'
alias scs='systemctl start'
alias scus='systemctl --user start'
;;
esac

View File

@ -16,7 +16,7 @@ alias yaru='yarn run'
alias yat='yarn test'
alias yacc='yarn cache clean'
alias yack='yarn check'
alias yals='yarn ls'
alias yals='yarn list'
alias yain='yarn info'
alias yali='yarn licenses ls'
alias yaloi='yarn login'

View File

@ -29,6 +29,7 @@ then
fi
# Load composure first, so we support function metadata
# shellcheck source=./lib/composure.bash
source "${BASH_IT}/lib/composure.bash"
# support 'plumbing' metadata
@ -40,21 +41,30 @@ APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for config_file in $LIB
do
if [ $config_file != $APPEARANCE_LIB ]; then
# shellcheck disable=SC1090
source $config_file
fi
done
# Load the global "enabled" directory
_load_global_bash_it_files
# Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion"
do
_load_bash_it_files $file_type
done
# Load colors first so they can be used in base theme
# Load colors and helpers first so they can be used in base theme
# shellcheck source=./themes/colors.theme.bash
source "${BASH_IT}/themes/colors.theme.bash"
# shellcheck source=./themes/githelpers.theme.bash
source "${BASH_IT}/themes/githelpers.theme.bash"
# shellcheck source=./themes/base.theme.bash
source "${BASH_IT}/themes/base.theme.bash"
# appearance (themes) now, after all dependencies
# shellcheck source=./lib/appearance.bash
source $APPEARANCE_LIB
# Load custom aliases, completion, plugins
@ -62,32 +72,43 @@ for file_type in "aliases" "completion" "plugins"
do
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]
then
# shellcheck disable=SC1090
source "${BASH_IT}/${file_type}/custom.${file_type}.bash"
fi
done
# Custom
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash"
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for config_file in $CUSTOM
do
if [ -e "${config_file}" ]; then
# shellcheck disable=SC1090
source $config_file
fi
done
unset config_file
if [[ $PROMPT ]]; then
export PS1="\["$PROMPT"\]"
export PS1="\[""$PROMPT""\]"
fi
# Adding Support for other OSes
PREVIEW="less"
[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview"
[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app"
if [ -s /usr/bin/gloobus-preview ]; then
PREVIEW="gloobus-preview"
elif [ -s /Applications/Preview.app ]; then
# shellcheck disable=SC2034
PREVIEW="/Applications/Preview.app"
fi
# Load all the Jekyll stuff
if [ -e "$HOME/.jekyllconfig" ]
then
# shellcheck disable=SC1090
. "$HOME/.jekyllconfig"
fi
# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040
set +T

View File

@ -0,0 +1 @@
[[ -x "$(which awless)" ]] && source <(awless completion bash)

View File

@ -2,7 +2,7 @@
_bash-it-comp-enable-disable()
{
local enable_disable_args="alias plugin completion"
local enable_disable_args="alias completion plugin"
COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) )
}
@ -10,11 +10,18 @@ _bash-it-comp-list-available-not-enabled()
{
subdirectory="$1"
local available_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`;
local available_things
available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`;
do
if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]
file_entity=$(basename $f)
typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1)
typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1)
if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ]
then
basename $f | cut -d'.' -f1
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g'
fi
done)
@ -23,11 +30,14 @@ _bash-it-comp-list-available-not-enabled()
_bash-it-comp-list-enabled()
{
subdirectory="$1"
local subdirectory="$1"
local suffix enabled_things
local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/enabled/"*.bash`;
suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')
enabled_things=$(for f in `sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`;
do
basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g"
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*---//g"
done)
COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) )
@ -37,9 +47,11 @@ _bash-it-comp-list-available()
{
subdirectory="$1"
local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`;
local enabled_things
enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`;
do
basename $f | cut -d'.' -f1
basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g'
done)
COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) )
@ -47,25 +59,30 @@ _bash-it-comp-list-available()
_bash-it-comp()
{
local cur prev opts prevprev
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
chose_opt="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}"
opts="help show enable disable update search migrate"
opts="disable enable help migrate search show update version"
case "${chose_opt}" in
show)
local show_args="plugins aliases completions"
local show_args="aliases completions plugins"
COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) )
return 0
;;
help)
local help_args="plugins aliases completions migrate update"
if [ x"${prev}" == x"aliases" ]; then
_bash-it-comp-list-available aliases
return 0
else
local help_args="aliases completions migrate plugins update"
COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) )
return 0
fi
;;
update | search | migrate)
update | search | migrate | version)
return 0
;;
enable | disable)
@ -93,16 +110,6 @@ _bash-it-comp()
;;
esac
;;
aliases)
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
case "${prevprev}" in
help)
_bash-it-comp-list-available aliases
return 0
;;
esac
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

View File

@ -1,9 +1,11 @@
if which brew >/dev/null 2>&1; then
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
BREW_PREFIX=$(brew --prefix)
if [ -f "$BREW_PREFIX"/etc/bash_completion.d/brew ]; then
. "$BREW_PREFIX"/etc/bash_completion.d/brew
fi
if [ -f `brew --prefix`/Library/Contributions/brew_bash_completion.sh ]; then
. `brew --prefix`/Library/Contributions/brew_bash_completion.sh
if [ -f "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]; then
. "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh
fi
fi

View File

@ -1,4 +1,4 @@
#!bash
#!/bin/bash
#
# bash completion for docker-compose
#
@ -18,7 +18,7 @@
__docker_compose_q() {
docker-compose 2>/dev/null $daemon_options "$@"
docker-compose 2>/dev/null "${top_level_options[@]}" "$@"
}
# Transforms a multiline list of strings into a single line string
@ -36,6 +36,18 @@ __docker_compose_to_extglob() {
echo "@($extglob)"
}
# Determines whether the option passed as the first argument exist on
# the commandline. The option may be a pattern, e.g. `--force|-f`.
__docker_compose_has_option() {
local pattern="$1"
for (( i=2; i < $cword; ++i)); do
if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then
return 0
fi
done
return 1
}
# suppress trailing whitespace
__docker_compose_nospace() {
# compopt is not available in ancient bash versions
@ -98,9 +110,17 @@ __docker_compose_services_stopped() {
_docker_compose_build() {
case "$prev" in
--build-arg)
COMPREPLY=( $( compgen -e -- "$cur" ) )
__docker_compose_nospace
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force-rm --help --no-cache --pull" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--build-arg --force-rm --help --no-cache --pull" -- "$cur" ) )
;;
*)
__docker_compose_services_from_build
@ -117,19 +137,19 @@ _docker_compose_bundle() {
;;
esac
COMPREPLY=( $( compgen -W "--fetch-digests --help --output -o" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--push-images --help --output -o" -- "$cur" ) )
}
_docker_compose_config() {
COMPREPLY=( $( compgen -W "--help --quiet -q --services" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
}
_docker_compose_create() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force-recreate --help --no-build --no-recreate" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur" ) )
;;
*)
__docker_compose_services_all
@ -148,14 +168,18 @@ _docker_compose_docker_compose() {
_filedir "y?(a)ml"
return
;;
$(__docker_compose_to_extglob "$daemon_options_with_args") )
--project-directory)
_filedir -d
return
;;
$(__docker_compose_to_extglob "$top_level_options_with_args") )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args --help -h --verbose --version -v" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$top_level_boolean_options $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
@ -200,14 +224,14 @@ _docker_compose_events() {
_docker_compose_exec() {
case "$prev" in
--index|--user)
--index|--user|-u)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user" -- "$cur" ) )
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user -u" -- "$cur" ) )
;;
*)
__docker_compose_services_running
@ -220,6 +244,16 @@ _docker_compose_help() {
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
}
_docker_compose_images() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help -q" -- "$cur" ) )
;;
*)
__docker_compose_services_all
;;
esac
}
_docker_compose_kill() {
case "$prev" in
@ -307,7 +341,7 @@ _docker_compose_ps() {
_docker_compose_pull() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --parallel --quiet" -- "$cur" ) )
;;
*)
__docker_compose_services_from_image
@ -349,10 +383,14 @@ _docker_compose_restart() {
_docker_compose_rm() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--force -f --help -v" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--force -f --help --stop -s -v" -- "$cur" ) )
;;
*)
if __docker_compose_has_option "--stop|-s" ; then
__docker_compose_services_all
else
__docker_compose_services_stopped
fi
;;
esac
}
@ -365,14 +403,14 @@ _docker_compose_run() {
__docker_compose_nospace
return
;;
--entrypoint|--name|--user|-u|--workdir|-w)
--entrypoint|--name|--user|-u|--volume|-v|--workdir|-w)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --name --no-deps --publish -p --rm --service-ports -T --user -u --workdir -w" -- "$cur" ) )
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --name --no-deps --publish -p --rm --service-ports -T --user -u --volume -v --workdir -w" -- "$cur" ) )
;;
*)
__docker_compose_services_all
@ -434,6 +472,18 @@ _docker_compose_stop() {
}
_docker_compose_top() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_running
;;
esac
}
_docker_compose_unpause() {
case "$cur" in
-*)
@ -448,6 +498,19 @@ _docker_compose_unpause() {
_docker_compose_up() {
case "$prev" in
=)
COMPREPLY=("$cur")
return
;;
--exit-code-from)
__docker_compose_services_all
return
;;
--scale)
COMPREPLY=( $(compgen -S "=" -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
__docker_compose_nospace
return
;;
--timeout|-t)
return
;;
@ -455,7 +518,7 @@ _docker_compose_up() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --force-recreate --help --no-build --no-color --no-deps --no-recreate --timeout -t --remove-orphans" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --remove-orphans --scale --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_all
@ -486,6 +549,7 @@ _docker_compose() {
events
exec
help
images
kill
logs
pause
@ -499,21 +563,25 @@ _docker_compose() {
scale
start
stop
top
unpause
up
version
)
# options for the docker daemon that have to be passed to secondary calls to
# docker-compose executed by this script
local daemon_boolean_options="
# Options for the docker daemon that have to be passed to secondary calls to
# docker-compose executed by this script.
# Other global otions that are not relevant for secondary calls are defined in
# `_docker_compose_docker_compose`.
local top_level_boolean_options="
--skip-hostname-check
--tls
--tlsverify
"
local daemon_options_with_args="
local top_level_options_with_args="
--file -f
--host -H
--project-directory
--project-name -p
--tlscacert
--tlscert
@ -527,19 +595,19 @@ _docker_compose() {
# search subcommand and invoke its handler.
# special treatment of some top-level options
local command='docker_compose'
local daemon_options=()
local top_level_options=()
local counter=1
while [ $counter -lt $cword ]; do
case "${words[$counter]}" in
$(__docker_compose_to_extglob "$daemon_boolean_options") )
$(__docker_compose_to_extglob "$top_level_boolean_options") )
local opt=${words[counter]}
daemon_options+=($opt)
top_level_options+=($opt)
;;
$(__docker_compose_to_extglob "$daemon_options_with_args") )
$(__docker_compose_to_extglob "$top_level_options_with_args") )
local opt=${words[counter]}
local arg=${words[++counter]}
daemon_options+=($opt $arg)
top_level_options+=($opt $arg)
;;
-*)
;;
@ -558,4 +626,4 @@ _docker_compose() {
return 0
}
complete -F _docker_compose docker-compose
complete -F _docker_compose docker-compose docker-compose.exe

View File

@ -1701,7 +1701,7 @@ _docker_service_tasks() {
}
_docker_service_update() {
local $subcommand="${words[$subcommand_pos]}"
local subcommand="${words[$subcommand_pos]}"
local options_with_args="
--constraint

View File

@ -0,0 +1 @@
complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export

View File

@ -1,50 +1,304 @@
function __gradle {
# Bash breaks words on : by default. Subproject tasks have ':'
# Avoid inaccurate completions for subproject tasks
COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g')
__gradle-set-project-root-dir() {
local dir=`pwd`
project_root_dir=`pwd`
while [[ $dir != '/' ]]; do
if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then
project_root_dir=$dir
return 0
fi
dir="$(dirname "$dir")"
done
return 1
}
__gradle-init-cache-dir() {
cache_dir="$HOME/.gradle/completion"
mkdir -p $cache_dir
}
__gradle-set-build-file() {
# Look for default build script in the settings file (settings.gradle by default)
# Otherwise, default is the file 'build.gradle' in the current directory.
gradle_build_file="$project_root_dir/build.gradle"
if [[ -f "$project_root_dir/settings.gradle" ]]; then
local build_file_name=$(grep "^rootProject\.buildFileName" "$project_root_dir/settings.gradle" | \
sed -n -e "s/rootProject\.buildFileName = [\'\"]\(.*\)[\'\"]/\1/p")
gradle_build_file="$project_root_dir/${build_file_name:-build.gradle}"
fi
}
__gradle-set-cache-name() {
# Cache name is constructed from the absolute path of the build file.
cache_name=$(echo $gradle_build_file | sed -e 's/\//_/g')
}
__gradle-set-files-checksum() {
# Cache MD5 sum of all Gradle scripts and modified timestamps
if builtin command -v md5 > /dev/null; then
gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)")
elif builtin command -v md5sum > /dev/null; then
gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}')
else
echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH"
fi
}
__gradle-generate-script-cache() {
# Invalidate cache after 3 weeks by default
local cache_ttl_mins=${GRADLE_CACHE_TTL_MINUTES:-30240}
local script_exclude_pattern=${GRADLE_COMPLETION_EXCLUDE_PATTERN:-"/(build|integTest|out)/"}
if [[ ! $(find $cache_dir/$cache_name -mmin -$cache_ttl_mins 2>/dev/null) ]]; then
# Cache all Gradle scripts
local gradle_build_scripts=$(find $project_root_dir -type f -name "*.gradle" -o -name "*.gradle.kts" 2>/dev/null | egrep -v "$script_exclude_pattern")
printf "%s\n" "${gradle_build_scripts[@]}" > $cache_dir/$cache_name
fi
}
__gradle-long-options() {
local args="--build-cache - Enables the Gradle build cache
--build-file - Specifies the build file
--configure-on-demand - Only relevant projects are configured
--console - Type of console output to generate (plain auto rich)
--continue - Continues task execution after a task failure
--continuous - Continuous mode. Automatically re-run build after changes
--daemon - Use the Gradle Daemon
--debug - Log at the debug level
--dry-run - Runs the build with all task actions disabled
--exclude-task - Specify a task to be excluded
--full-stacktrace - Print out the full (very verbose) stacktrace
--gradle-user-home - Specifies the Gradle user home directory
--gui - Launches the Gradle GUI app (Deprecated)
--help - Shows a help message
--include-build - Run the build as a composite, including the specified build
--info - Set log level to INFO
--init-script - Specifies an initialization script
--max-workers - Set the maximum number of workers that Gradle may use
--no-build-cache - Do not use the Gradle build cache
--no-daemon - Do not use the Gradle Daemon
--no-rebuild - Do not rebuild project dependencies
--no-scan - Do not create a build scan
--no-search-upwards - Do not search in parent directories for a settings.gradle
--offline - Build without accessing network resources
--parallel - Build projects in parallel
--profile - Profile build time and create report
--project-cache-dir - Specifies the project-specific cache directory
--project-dir - Specifies the start directory for Gradle
--project-prop - Sets a project property of the root project
--quiet - Log errors only
--recompile-scripts - Forces scripts to be recompiled, bypassing caching
--refresh-dependencies - Refresh the state of dependencies
--rerun-tasks - Specifies that any task optimization is ignored
--scan - Create a build scan
--settings-file - Specifies the settings file
--stacktrace - Print out the stacktrace also for user exceptions
--status - Print Gradle Daemon status
--stop - Stop all Gradle Daemons
--system-prop - Set a system property
--version - Prints Gradle version info
--warn - Log warnings and errors only"
COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") )
}
__gradle-properties() {
local args="-Dorg.gradle.cache.reserved.mb= - Reserve Gradle Daemon memory for operations
-Dorg.gradle.caching= - Set true to enable Gradle build cache
-Dorg.gradle.daemon.debug= - Set true to debug Gradle Daemon
-Dorg.gradle.daemon.idletimeout= - Kill Gradle Daemon after # idle millis
-Dorg.gradle.debug= - Set true to debug Gradle Client
-Dorg.gradle.jvmargs= - Set JVM arguments
-Dorg.gradle.java.home= - Set JDK home dir
-Dorg.gradle.logging.level= - Set default Gradle log level (quiet warn lifecycle info debug)
-Dorg.gradle.parallel= - Set true to enable parallel project builds (incubating)
-Dorg.gradle.parallel.intra= - Set true to enable intra-project parallel builds (incubating)
-Dorg.gradle.workers.max= - Set the number of workers Gradle is allowed to use"
COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") )
return 0
}
__gradle-short-options() {
local args="-? - Shows a help message
-a - Do not rebuild project dependencies
-b - Specifies the build file
-c - Specifies the settings file
-d - Log at the debug level
-g - Specifies the Gradle user home directory
-h - Shows a help message
-i - Set log level to INFO
-m - Runs the build with all task actions disabled
-p - Specifies the start directory for Gradle
-q - Log errors only
-s - Print out the stacktrace also for user exceptions
-t - Continuous mode. Automatically re-run build after changes
-u - Do not search in parent directories for a settings.gradle
-v - Prints Gradle version info
-w - Log warnings and errors only
-x - Specify a task to be excluded
-D - Set a system property
-I - Specifies an initialization script
-P - Sets a project property of the root project
-S - Print out the full (very verbose) stacktrace"
COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") )
}
__gradle-notify-tasks-cache-build() {
# Notify user of cache rebuild
echo -e " (Building completion cache. Please wait)\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c"
__gradle-generate-tasks-cache
# Remove "please wait" message by writing a bunch of spaces then moving back to the left
echo -e " \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\c"
}
__gradle-generate-tasks-cache() {
__gradle-set-files-checksum
# Use Gradle wrapper when it exists.
local gradle_cmd="gradle"
if [[ -x "$project_root_dir/gradlew" ]]; then
gradle_cmd="$project_root_dir/gradlew"
fi
# Run gradle to retrieve possible tasks and cache.
# Reuse Gradle Daemon if IDLE but don't start a new one.
local gradle_tasks_output
if [[ ! -z "$($gradle_cmd --status 2>/dev/null | grep IDLE)" ]]; then
gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --daemon -q tasks --all)"
else
gradle_tasks_output="$($gradle_cmd -b $gradle_build_file --no-daemon -q tasks --all)"
fi
local output_line
local task_description
local -a gradle_all_tasks=()
local -a root_tasks=()
local -a subproject_tasks=()
for output_line in $gradle_tasks_output; do
if [[ $output_line =~ ^([[:lower:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))? ]]; then
task_name="${BASH_REMATCH[1]}"
task_description="${BASH_REMATCH[3]}"
gradle_all_tasks+=( "$task_name - $task_description" )
# Completion for subproject tasks with ':' prefix
if [[ $task_name =~ ^([[:alnum:][:punct:]]+):([[:alnum:]]+) ]]; then
gradle_all_tasks+=( ":$task_name - $task_description" )
subproject_tasks+=( "${BASH_REMATCH[2]}" )
else
root_tasks+=( "$task_name" )
fi
fi
done
# subproject tasks can be referenced implicitly from root project
if [[ $GRADLE_COMPLETION_UNQUALIFIED_TASKS == "true" ]]; then
local -a implicit_tasks=()
implicit_tasks=( $(comm -23 <(printf "%s\n" "${subproject_tasks[@]}" | sort) <(printf "%s\n" "${root_tasks[@]}" | sort)) )
for task in $(printf "%s\n" "${implicit_tasks[@]}"); do
gradle_all_tasks+=( $task )
done
fi
printf "%s\n" "${gradle_all_tasks[@]}" > $cache_dir/$gradle_files_checksum
echo $gradle_files_checksum > $cache_dir/$cache_name.md5
}
__gradle-completion-init() {
local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir
local OLDIFS="$IFS"
local IFS=$'\n'
__gradle-init-cache-dir
__gradle-set-project-root-dir
__gradle-set-build-file
if [[ -f $gradle_build_file ]]; then
__gradle-set-cache-name
__gradle-generate-script-cache
__gradle-set-files-checksum
__gradle-notify-tasks-cache-build
fi
IFS="$OLDIFS"
return 0
}
_gradle() {
local cache_dir cache_name gradle_build_file gradle_files_checksum project_root_dir
local cur=${COMP_WORDS[COMP_CWORD]}
local tasks=''
local cache_dir="$HOME/.gradle/completion_cache"
# Set bash internal field separator to '\n'
# This allows us to provide descriptions for options and tasks
local OLDIFS="$IFS"
local IFS=$'\n'
case $OSTYPE in
darwin*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5 -q | md5 -q"
;;
*)
local checksum_command="find . -name build.gradle -print0 | xargs -0 md5sum | md5sum | cut -d ' ' -f 1"
;;
esac
local parsing_command="gradle --console=plain --quiet tasks | grep -v Rules | sed -nE -e 's/^([a-zA-Z]+)($| - .+)/\1/p'"
mkdir -p "${cache_dir}"
local gradle_files_checksum='no_cache_file'
if [[ -f build.gradle ]]; then
gradle_files_checksum="$(eval "${checksum_command}")"
if [[ -f "${cache_dir}/${gradle_files_checksum}" ]]; then
newest_gradle_file="$(find . -type f -name build.gradle -newer "${cache_dir}/${gradle_files_checksum}")"
if [ -n "${newest_gradle_file}" ]; then
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
if [[ ${cur} == --* ]]; then
__gradle-long-options
elif [[ ${cur} == -D* ]]; then
__gradle-properties
elif [[ ${cur} == -* ]]; then
__gradle-short-options
else
tasks="$(cat "${cache_dir}/${gradle_files_checksum}")"
touch "${cache_dir}/${gradle_files_checksum}"
__gradle-init-cache-dir
__gradle-set-project-root-dir
__gradle-set-build-file
if [[ -f $gradle_build_file ]]; then
__gradle-set-cache-name
__gradle-generate-script-cache
__gradle-set-files-checksum
# The cache key is md5 sum of all gradle scripts, so it's valid if it exists.
if [[ -f $cache_dir/$cache_name.md5 ]]; then
local cached_checksum="$(cat $cache_dir/$cache_name.md5)"
local -a cached_tasks
if [[ -z $cur ]]; then
cached_tasks=( $(cat $cache_dir/$cached_checksum) )
else
cached_tasks=( $(grep "^$cur" $cache_dir/$cached_checksum) )
fi
COMPREPLY=( $(compgen -W "${cached_tasks[*]}" -- "$cur") )
else
__gradle-notify-tasks-cache-build
fi
# Regenerate tasks cache in the background
if [[ $gradle_files_checksum != "$(cat $cache_dir/$cache_name.md5)" || ! -f $cache_dir/$gradle_files_checksum ]]; then
$(__gradle-generate-tasks-cache 1>&2 2>/dev/null &)
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
# Default tasks available outside Gradle projects
local args="buildEnvironment - Displays all buildscript dependencies declared in root project.
components - Displays the components produced by root project.
dependencies - Displays all dependencies declared in root project.
dependencyInsight - Displays the insight into a specific dependency in root project.
dependentComponents - Displays the dependent components of components in root project.
help - Displays a help message.
init - Initializes a new Gradle build.
model - Displays the configuration model of root project.
projects - Displays the sub-projects of root project.
properties - Displays the properties of root project.
tasks - Displays the tasks runnable from root project.
wrapper - Generates Gradle wrapper files."
COMPREPLY=( $(compgen -W "$args" -- "${COMP_WORDS[COMP_CWORD]}") )
fi
else
tasks="$(eval "${parsing_command}")"
[[ -n "${tasks}" ]] && echo "${tasks}" > "${cache_dir}/${gradle_files_checksum}"
fi
COMPREPLY=( $(compgen -W "${tasks}" -- "${cur}") )
IFS="$OLDIFS"
# Remove description ("[:space:]" and after) if only one possibility
if [[ ${#COMPREPLY[*]} -eq 1 ]]; then
COMPREPLY=( ${COMPREPLY[0]%% *} )
fi
return 0
}
complete -F _gradle gradle
complete -F _gradle gradle.bat
complete -F _gradle gradlew
complete -F _gradle gradlew.bat
complete -F _gradle ./gradlew
complete -F _gradle ./gradlew.bat
function __clear_gradle_cache {
local cache_dir="$HOME/.gradle/completion_cache"
[[ -d "${cache_dir}" ]] && find "${cache_dir}" -type f -mtime +7 -exec rm -f {} \;
}
__clear_gradle_cache
complete -F __gradle gradle
complete -F __gradle gradlew
complete -F __gradle ./gradlew
if hash gw 2>/dev/null || alias gw >/dev/null 2>&1; then
complete -F _gradle gw
fi

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
[ -x "$(which oc)" ] && eval "$(oc completion bash)"

View File

@ -0,0 +1 @@
[[ -x "$(which pew)" ]] && source "$(pew shell_config)"

View File

@ -0,0 +1 @@
[[ -x "$(which pipenv)" ]] && source <(env _PIPENV_COMPLETE="source-bash" pipenv)

View File

@ -53,8 +53,7 @@ _sdkman_candidate_versions(){
__sdkman_cleanup_local_versions(){
__sdkman_build_version_csv $1
echo $CSV | tr ',' ' '
__sdkman_build_version_csv $1 | tr ',' ' '
}

View File

@ -14,7 +14,7 @@ _sshcomplete() {
# parse all defined hosts from .ssh/config
if [ -r "$HOME/.ssh/config" ]; then
COMPREPLY=($(compgen -W "$(grep ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
COMPREPLY=($(compgen -W "$(grep -i ^Host "$HOME/.ssh/config" | awk '{for (i=2; i<=NF; i++) print $i}' )" ${OPTIONS}) )
fi
# parse all hosts found in .ssh/known_hosts

View File

@ -0,0 +1,5 @@
if [[ -x "$(which travis)" ]]; then
__TRAVIS_COMPLETION_SCRIPT="${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh"
[[ -f "${__TRAVIS_COMPLETION_SCRIPT}" ]] && source "${__TRAVIS_COMPLETION_SCRIPT}"
unset __TRAVIS_COMPLETION_SCRIPT
fi

View File

@ -111,7 +111,7 @@ __vboxmanage_default() {
for WORD in $opts; do
MATCH=0
for OPT in ${COMP_WORDS[@]}; do
for OPT in "${COMP_WORDS[@]}"; do
# opts=$(echo ${opts} | grep -v $OPT);
if [ "$OPT" == "$WORD" ]; then
MATCH=1

View File

@ -196,7 +196,7 @@ draft ()
cmd=$(eval "history | grep '^[[:blank:]]*$num' | head -1" | sed 's/^[[:blank:][:digit:]]*//')
fi
eval "$func() { $cmd; }"
typeset file=$(mktemp /tmp/draft.XXXX)
typeset file=$(mktemp -t draft.XXXX)
typeset -f $func > $file
transcribe $func $file draft
rm $file 2>/dev/null
@ -300,7 +300,7 @@ revise ()
group composure
typeset func=$1
typeset temp=$(mktemp /tmp/revise.XXXX)
typeset temp=$(mktemp -t revise.XXXX)
if [ -z "$func" ]; then
printf '%s\n' 'missing parameter(s)'

View File

@ -1,8 +1,19 @@
#!/usr/bin/env bash
BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS=${BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS:-150}
BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=${BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN:-250}
BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION:-350}
BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
function _command_exists ()
{
_about 'checks for existence of a command'
_param '1: command to check'
_example '$ _command_exists ls && echo exists'
_group 'lib'
type "$1" &> /dev/null ;
}
# Helper function loading various enable-able files
function _load_bash_it_files() {
subdirectory="$1"
@ -18,6 +29,20 @@ function _load_bash_it_files() {
fi
}
function _load_global_bash_it_files() {
# In the new structure
if [ -d "${BASH_IT}/enabled" ]
then
FILES="${BASH_IT}/enabled/*.bash"
for config_file in $FILES
do
if [ -e "${config_file}" ]; then
source $config_file
fi
done
fi
}
# Function for reloading aliases
function reload_aliases() {
_load_bash_it_files "aliases"
@ -36,7 +61,7 @@ function reload_plugins() {
bash-it ()
{
about 'Bash-it help and maintenance'
param '1: verb [one of: help | show | enable | disable | migrate | update | search ] '
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version ] '
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
param '3: specific component [optional]'
example '$ bash-it show plugins'
@ -46,6 +71,7 @@ bash-it ()
example '$ bash-it migrate'
example '$ bash-it update'
example '$ bash-it search ruby [[-]rake]... [--enable | --disable]'
example '$ bash-it version'
typeset verb=${1:-}
shift
typeset component=${1:-}
@ -61,12 +87,14 @@ bash-it ()
help)
func=_help-$component;;
search)
_bash-it-search $component $*
_bash-it-search $component "$@"
return;;
update)
func=_bash-it_update;;
migrate)
func=_bash-it-migrate;;
version)
func=_bash-it-version;;
*)
reference bash-it
return;;
@ -87,7 +115,7 @@ bash-it ()
fi
fi
if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then
if [ x"$verb" == x"enable" ] || [ x"$verb" == x"disable" ]; then
# Automatically run a migration if required
_bash-it-migrate
@ -96,7 +124,7 @@ bash-it ()
$func $arg
done
else
$func $*
$func "$@"
fi
}
@ -136,12 +164,17 @@ _bash-it_update() {
_about 'updates Bash-it'
_group 'lib'
cd "${BASH_IT}"
cd "${BASH_IT}" || return
if [ -z $BASH_IT_REMOTE ]; then
BASH_IT_REMOTE="origin"
fi
git fetch &> /dev/null
local status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)"
declare status
status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)"
if [[ -n "${status}" ]]; then
git pull --rebase &> /dev/null
if [[ $? -eq 0 ]]; then
@ -158,25 +191,28 @@ _bash-it_update() {
else
echo "Bash-it is up to date, nothing to do!"
fi
cd - &> /dev/null
cd - &> /dev/null || return
}
_bash-it-migrate() {
_about 'migrates Bash-it configuration from a previous format to the current one'
_group 'lib'
declare migrated_something
migrated_something=false
for file_type in "aliases" "plugins" "completion"
do
shopt -s nullglob
for f in "${BASH_IT}/$file_type/enabled/"*.bash
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
do
typeset ff=$(basename $f)
# Only process the ones that don't use the new structure
if ! [[ $ff =~ ^[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR.*\.bash$ ]] ; then
# Get the type of component from the extension
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
typeset component_name=$(echo $ff | cut -d'.' -f1)
# Cut off the optional "250---" prefix and the suffix
typeset component_name=$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g')
migrated_something=true
echo "Migrating $single_type $component_name."
@ -185,10 +221,35 @@ _bash-it-migrate() {
$disable_func $component_name
$enable_func $component_name
done
done
if [ "$migrated_something" = "true" ]; then
echo ""
echo "If any migration errors were reported, please try the following: reload && bash-it migrate"
fi
done
shopt -u nullglob
done
}
_bash-it-version() {
_about 'shows current Bash-it version'
_group 'lib'
cd "${BASH_IT}" || return
if [ -z $BASH_IT_REMOTE ]; then
BASH_IT_REMOTE="origin"
fi
BASH_IT_GIT_REMOTE=$(git remote get-url $BASH_IT_REMOTE)
BASH_IT_GIT_URL=${BASH_IT_GIT_REMOTE%.git}
BASH_IT_GIT_VERSION_INFO="$(git log --pretty=format:'%h on %aI' -n 1)"
BASH_IT_GIT_SHA=${BASH_IT_GIT_VERSION_INFO%% *}
echo "Current git SHA: $BASH_IT_GIT_VERSION_INFO"
echo "$BASH_IT_GIT_URL/commit/$BASH_IT_GIT_SHA"
cd - &> /dev/null || return
}
_bash-it-describe ()
@ -211,7 +272,11 @@ _bash-it-describe ()
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
# Check for both the old format without the load priority, and the extended format with the priority
if [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then
declare enabled_files enabled_file
enabled_file=$(basename $f)
enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l)
if [ $enabled_files -gt 0 ]; then
enabled='x'
else
enabled=' '
@ -271,29 +336,37 @@ _disable-thing ()
return
fi
typeset f suffix
suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g')
if [ "$file_entity" = "all" ]; then
typeset f $file_type
for f in "${BASH_IT}/$subdirectory/available/"*.bash
# Disable everything that's using the old structure
for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"`
do
plugin=$(basename $f)
if [ -e "${BASH_IT}/$subdirectory/enabled/$plugin" ]; then
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)"
fi
if [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then
rm "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin)
fi
rm "$f"
done
# Disable everything in the global "enabled" directory
for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"`
do
rm "$f"
done
else
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1)
if [ -z "$plugin_global" ]; then
# Use a glob to search for both possible patterns
# 250---node.plugin.bash
# node.plugin.bash
# Either one will be matched by this glob
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1)
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1)
if [ -z "$plugin" ]; then
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return
fi
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)"
else
rm "${BASH_IT}/enabled/$(basename $plugin_global)"
fi
fi
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then
@ -369,19 +442,26 @@ _enable-thing ()
to_enable=$(basename $to_enable)
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin" ] ; then
printf '%s\n' "$file_entity is already enabled."
return
fi
mkdir -p "${BASH_IT}/$subdirectory/enabled"
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin_global" ] ; then
printf '%s\n' "$file_entity is already enabled."
return
fi
mkdir -p "${BASH_IT}/enabled"
# Load the priority from the file if it present there
local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }')
local use_load_priority=${local_file_priority:-$load_priority}
declare local_file_priority use_load_priority
local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }')
use_load_priority=${local_file_priority:-$load_priority}
ln -s ../available/$to_enable "${BASH_IT}/$subdirectory/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
fi
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then
@ -418,18 +498,22 @@ _help-aliases()
cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/"
else
typeset f
for f in "${BASH_IT}/aliases/enabled/"*
for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")`
do
_help-list-aliases $f
done
if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then
_help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash"
fi
fi
}
_help-list-aliases ()
{
typeset file=$(basename $1)
printf '\n\n%s:\n' "${file%%.*}"
typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g')
printf '\n\n%s:\n' "${file}"
# metafor() strips trailing quotes, restore them with sed..
cat $1 | metafor alias | sed "s/$/'/"
}
@ -441,7 +525,7 @@ _help-plugins()
# display a brief progress message...
printf '%s' 'please wait, building help...'
typeset grouplist=$(mktemp /tmp/grouplist.XXXXXX)
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
typeset func
for func in $(typeset_functions)
do
@ -488,7 +572,7 @@ all_groups ()
group 'lib'
typeset func
typeset file=$(mktemp /tmp/composure.XXXX)
typeset file=$(mktemp -t composure.XXXX)
for func in $(typeset_functions)
do
typeset -f $func | metafor group >> $file

View File

@ -29,8 +29,7 @@ function alias_completion {
(( ${#completions[@]} == 0 )) && return 0
# create temporary file for wrapper functions and completions
rm -f "/tmp/${namespace}-*.tmp" # preliminary cleanup
local tmp_file; tmp_file="$(mktemp "/tmp/${namespace}-${RANDOM}XXX.tmp")" || return 1
local tmp_file; tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXX.tmp")" || return 1
local completion_loader; completion_loader="$(complete -p -D 2>/dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"

View File

@ -42,7 +42,7 @@ function __awskeys_get {
}
function __awskeys_list {
local credentials_list="$(egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials)"
local credentials_list="$((egrep '^\[ *[a-zA-Z0-9_-]+ *\]$' ~/.aws/credentials; grep "\[profile" ~/.aws/config | sed "s|\[profile |\[|g") | sort | uniq)"
if [[ -n $"{credentials_list}" ]]; then
echo -e "Available credentials profiles:\n"
for profile in ${credentials_list}; do
@ -64,12 +64,14 @@ function __awskeys_show {
}
function __awskeys_export {
if [[ $(__awskeys_list) == *"$1"* ]]; then
local p_keys=( $(__awskeys_get $1 | tr -d " ") )
if [[ -n "${p_keys}" ]]; then
for p_key in ${p_keys[@]}; do
local key="${p_key%=*}"
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
done
fi
export AWS_DEFAULT_PROFILE="$1"
else
echo "Profile $1 not found in credentials file"

View File

@ -22,7 +22,7 @@ function down4me ()
param '1: website url'
example '$ down4me http://www.google.com'
group 'base'
curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
}
function myip ()

View File

@ -2,23 +2,23 @@ cite about-plugin
about-plugin 'display info about your battery charge level'
ac_adapter_connected(){
if command_exists upower;
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'charging\|fully-charged'
return $?
elif command_exists acpi;
elif _command_exists acpi;
then
acpi -a | grep -q "on-line"
return $?
elif command_exists pmset;
elif _command_exists pmset;
then
pmset -g batt | grep -q 'AC Power'
return $?
elif command_exists ioreg;
elif _command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
return $?
elif command_exists WMIC;
elif _command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
return $?
@ -26,23 +26,23 @@ ac_adapter_connected(){
}
ac_adapter_disconnected(){
if command_exists upower;
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'discharging'
return $?
elif command_exists acpi;
elif _command_exists acpi;
then
acpi -a | grep -q "off-line"
return $?
elif command_exists pmset;
elif _command_exists pmset;
then
pmset -g batt | grep -q 'Battery Power'
return $?
elif command_exists ioreg;
elif _command_exists ioreg;
then
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
return $?
elif command_exists WMIC;
elif _command_exists WMIC;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
return $?
@ -53,72 +53,31 @@ battery_percentage(){
about 'displays battery charge as a percentage of full (100%)'
group 'battery'
if command_exists upower;
then
local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | tail --bytes 5)
echo ${UPOWER_OUTPUT: : -1}
elif command_exists acpi;
then
local ACPI_OUTPUT=$(acpi -b)
case $ACPI_OUTPUT in
*" Unknown"*)
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
case $PERC_OUTPUT in
*%)
echo "0${PERC_OUTPUT}" | head -c 2
;;
*)
echo ${PERC_OUTPUT}
;;
esac
;;
declare COMMAND_OUTPUT="no"
*" Charging"* | *" Discharging"*)
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
echo ${PERC_OUTPUT}
;;
*" Full"*)
echo '100'
;;
*)
echo '-1'
;;
esac
elif command_exists pmset;
if _command_exists upower;
then
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
case $PMSET_OUTPUT in
100*)
echo '100'
;;
*)
echo $PMSET_OUTPUT | head -c 2
;;
esac
elif command_exists ioreg;
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
elif _command_exists acpi;
then
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
case $IOREG_OUTPUT in
100*)
echo '100'
;;
*)
echo $IOREG_OUTPUT | head -c 2
;;
esac
elif command_exists WMIC;
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
elif _command_exists pmset;
then
local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*')
case $WINPC in
100*)
echo '100'
;;
*)
echo $WINPC
;;
esac
COMMAND_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1)
elif _command_exists ioreg;
then
COMMAND_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}' | grep -o "[0-9]\+" | head -1)
elif _command_exists WMIC;
then
COMMAND_OUTPUT=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
else
echo "no"
COMMAND_OUTPUT="no"
fi
if [ "${COMMAND_OUTPUT}" != "no" ]; then
printf "%02d" "${COMMAND_OUTPUT:--1}"
else
echo "${COMMAND_OUTPUT}"
fi
}

View File

@ -0,0 +1,4 @@
cite about-plugin
about-plugin 'load direnv, if you are using it: https://direnv.net/'
[ -x "$(which direnv)" ] && eval "$(direnv hook bash)"

View File

@ -14,7 +14,7 @@ function docker-compose-fresh() {
fi
docker-compose $DCO_FILE_PARAM stop
docker-compose $DCO_FILE_PARAM rm -f --all
docker-compose $DCO_FILE_PARAM rm -f
docker-compose $DCO_FILE_PARAM up -d
docker-compose $DCO_FILE_PARAM logs -f --tail 100
}

View File

@ -1,34 +1,269 @@
cite about-plugin
about-plugin 'gif helper functions'
about-plugin 'video to gif, gif to WebM helper functions'
# From https://gist.github.com/SlexAxton/4989674#comment-1199058
# Requirements (Mac OS X using Homebrew): brew install ffmpeg gifsicle imagemagick
function gifify {
about 'Converts a .mov file into an into an animated GIF.'
# Based loosely on:
# https://gist.github.com/SlexAxton/4989674#comment-1199058
# https://linustechtips.com/main/topic/343253-tutorial-convert-videogifs-to-webm/
# and other sources
# Renamed gifify to v2gif to go avoid clobbering https://github.com/jclem/gifify
# Requirements (Mac OS X using Homebrew): brew install ffmpeg giflossy imagemagick
# Requirements on Ubuntu: sudo apt install ffmpeg imagemagick ; plus install https://github.com/pornel/giflossy
# Optional: install mediainfo for autodetection of original video FPS.
# Optional: if lossy is not important, Ubuntu has gifsicle packaged for apt-get, instead of giflossy
# Optional: gifski (from `brew install gifski` or github.com/ImageOptim/gifski)
# for high quality huge files.
function v2gif {
about 'Converts a .mov/.avi/.mp4 file into an into an animated GIF.'
group 'gif'
param '1: MOV file name'
param '2: max width in pixels (optional)'
example '$ gifify foo.mov'
example '$ gifify foo.mov 600'
param '1: MOV/AVI/MP4 file name(s)'
param '2: -w <num> ; Optional: max width in pixels'
param '3: -l <num> ; Optional: extra lossy level for smaller files (80-200 make sense, needs giflossy instead of gifsicle)'
param '4: -h ; Optional: high quality using gifski (installed seperately) - overrides "--lossy" above!'
param '5: -d ; Optional: delete the original video file if succeeded'
param '6: -t ; Optional: Tag the result with quality stamp for comparison use'
param '7: -f <num> ; Optional: Change number of frames per second (default 10 or original FPS if mediainfo installed)'
param '8: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)'
param '9: -m ; Optional: Also create a WebM file (will one day replace GIF, Smaller and higher quality than mp4)'
example '$ v2gif foo.mov'
example '$ v2gif foo.mov -w 600'
example '$ v2gif -l 100 -d *.mp4'
example '$ v2gif -dh *.avi'
example '$ v2gif -thw 600 *.avi *.mov'
if [ -z "$1" ]; then
echo "$(tput setaf 1)No input file given. Example: gifify example.mov [max width (pixels)]$(tput sgr 0)"
# Parse the options
local args=$(getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@")
local use_gifski=""
local del_after=""
local maxsize=""
local lossiness=""
local maxwidthski=""
local giftagopt=""
local giftag=""
local defaultfps=10
local infps=""
local fps=""
local make_webm=""
local alert=5000
eval set -- "$args"
while [ $# -ge 1 ]; do
case "$1" in
--)
# No more options left.
shift
break
;;
-d|--del|--delete)
# Delete after
del_after="true"
shift
;;
-h|--high)
#High Quality, use gifski
use_gifski=true
giftag="${giftag}-h"
shift
;;
-w|--width)
maxsize="-vf scale=$2:-1"
maxwidthski="-W $2"
giftag="${giftag}-w$2"
shift 2
;;
-t|--tag)
# mark with a quality tag
giftagopt="true"
shift
;;
-l|--lossy)
# Use giflossy parameter
lossiness="--lossy=$2"
giftag="${giftag}-l$2"
shift 2
;;
-f|--fps)
# select fps
infps="$2"
giftag="${giftag}-f$2"
shift 2
;;
-a|--alert)
# set size alert
alert="$2"
shift 2
;;
-m|--webm)
# set size alert
make_webm="true"
shift
;;
esac
done
# Done Parsing, all that's left are the filenames
local movies="$*"
if [[ -z "$movies" ]]; then
echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w <max width (pixels)>] [-l <lossy level>] < $(tput sgr 0)"
return 1
fi
output_file="${1%.*}.gif"
# Prepare the quality tag if requested.
[[ -z "$giftag" ]] && giftag="-default"
[[ -z "$giftagopt" ]] && giftag=""
echo "$(tput setaf 2)Creating $output_file...$(tput sgr 0)"
for file in $movies ; do
if [ ! -z "$2" ]; then
maxsize="-vf scale=$2:-1"
else
maxsize=""
local output_file="${file%.*}${giftag}.gif"
if [[ "$make_webm" ]] ; then
ffmpeg -loglevel panic -i "$file" \
-c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 -quality best \
"${file%.*}.webm" || return 2
fi
ffmpeg -loglevel panic -i $1 $maxsize -r 10 -vcodec png gifify-tmp-%05d.png
convert +dither -layers Optimize gifify-tmp-*.png GIF:- | gifsicle --no-warnings --colors 256 --delay=10 --loop --optimize=3 --multifile - > $output_file
rm gifify-tmp-*.png
# Set FPS to match the video if possible, otherwise fallback to default.
if [[ "$infps" ]] ; then
fps=$infps
else
fps=$defaultfps
if [[ -x /usr/bin/mediainfo ]] ; then
fps=$(/usr/bin/mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
[[ -z "$fps" ]] && fps=$(/usr/bin/mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
fi
fi
echo "$(tput setaf 2)Creating '$output_file' at $fps FPS ...$(tput sgr 0)"
if [[ "$use_gifski" = "true" ]] ; then
# I trust @pornel to do his own resizing optimization choices
ffmpeg -loglevel panic -i "$file" -r $fps -vcodec png v2gif-tmp-%05d.png && \
gifski $maxwidthski --fps $(printf "%.0f" $fps) -o "$output_file" v2gif-tmp-*.png || return 2
else
ffmpeg -loglevel panic -i "$file" $maxsize -r $fps -vcodec png v2gif-tmp-%05d.png && \
convert +dither -layers Optimize v2gif-tmp-*.png GIF:- | \
gifsicle $lossiness --no-warnings --colors 256 --delay=$(echo "100/$fps"|bc) --loop --optimize=3 --multifile - > "$output_file" || return 2
fi
rm v2gif-tmp-*.png
# Checking if the file is bigger than Twitter likes and warn
if [[ $alert -gt 0 ]] ; then
local out_size=$(wc --bytes < "$output_file")
if [[ $out_size -gt $(( alert * 1000 )) ]] ; then
echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb, keeping '$file' even if --del requested.$(tput sgr 0)"
del_after=""
fi
fi
[[ "$del_after" = "true" ]] && rm "$file"
done
echo "$(tput setaf 2)Done.$(tput sgr 0)"
}
function any2webm() {
about 'Converts an movies and Animated GIF files into an into a modern quality WebM video.'
group 'gif'
param '1: GIF/video file name(s)'
param '2: -s <WxH> ; Optional: set <W>idth and <H>eight in pixels'
param '3: -d ; Optional: delete the original file if succeeded'
param '4: -t ; Optional: Tag the result with quality stamp for comparison use'
param '5: -f <num> ; Optional: Change number of frames per second'
param '6: -b <num> ; Optional: Set Bandwidth (quality/size of resulting file), Defaults to 2M (bits/sec, accepts fractions)"'
param '7: -a <num> ; Optional: Alert if resulting file is over <num> kilobytes (default is 5000, 0 turns off)'
example '$ any2webm foo.gif'
example '$ any2webm *.mov -b 1.5M -s 600x480'
# Parse the options
local args=$(getopt -l alert -l "bandwidth:" -l "width:" -l del,delete -l tag -l "fps:" -l webm -o "a:b:w:f:dt" -- "$@")
local del_after=""
local size=""
local webmtagopt=""
local webmtag=""
local defaultfps=10
local fps=""
local bandwidth="2M"
local alert=5000
eval set -- "$args"
while [ $# -ge 1 ]; do
case "$1" in
--)
# No more options left.
shift
break
;;
-d|--del|--delete)
# Delete after
del_after="true"
shift
;;
-s|--size)
size="-s $2"
webmtag="${webmtag}-s$2"
shift 2
;;
-t|--tag)
# mark with a quality tag
webmtagopt="true"
shift
;;
-f|--fps)
# select fps
fps="-r $2"
webmtag="${webmtag}-f$2"
shift 2
;;
-b|--bandwidth)
# select bandwidth
bandwidth="$2"
webmtag="${webmtag}-b$2"
shift 2
;;
-a|--alert)
# set size alert
alert="$2"
shift 2
;;
esac
done
# Done Parsing, all that's left are the filenames
local movies="$*"
if [[ -z "$movies" ]]; then
echo "$(tput setaf 1)No input files given. Example: any2webm file [file...] [-w <max width (pixels)>] < $(tput sgr 0)"
return 1
fi
# Prepare the quality tag if requested.
[[ -z "$webmtag" ]] && webmtag="-default"
[[ -z "$webmtagopt" ]] && webmtag=""
for file in $movies ; do
local output_file="${file%.*}${webmtag}.webm"
echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)"
ffmpeg -loglevel panic -i "$file" \
-c:v libvpx -crf 4 -threads 0 -an -b:v $bandwidth -auto-alt-ref 0 \
-quality best $fps $size -pix_fmt yuva420p "$output_file" || return 2
# Checking if the file is bigger than Twitter likes and warn
if [[ $alert -gt 0 ]] ; then
local out_size=$(wc --bytes < "$output_file")
if [[ $out_size -gt $(( alert * 1000 )) ]] ; then
echo "$(tput setaf 3)Warning: '$output_file' is $((out_size/1000))kb, keeping '$file' even if --del requested.$(tput sgr 0)"
del_after=""
fi
fi
[[ "$del_after" = "true" ]] && rm "$file"
done
echo "$(tput setaf 2)Done.$(tput sgr 0)"
}

View File

@ -7,5 +7,5 @@ about-plugin 'go environment variables & path configuration'
export GOROOT=${GOROOT:-$(go env | grep GOROOT | cut -d'"' -f2)}
pathmunge "${GOROOT}/bin"
export GOPATH=${GOPATH:-"$HOME/.go"}
export GOPATH=${GOPATH:-"$HOME/go"}
pathmunge "${GOPATH}/bin"

View File

@ -5,7 +5,10 @@ about-plugin 'osx-specific functions'
if [ $(uname) = "Darwin" ]; then
if type update_terminal_cwd > /dev/null 2>&1 ; then
if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then
export PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd"
PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd"
declared="$(declare -p PROMPT_COMMAND)"
[[ "$declared" =~ \ -[aAilrtu]*x[aAilrtu]*\ ]] 2>/dev/null
[[ $? -eq 0 ]] && export PROMPT_COMMAND
fi
fi
fi

View File

@ -1,5 +1,9 @@
cite about-plugin
about-plugin 'Load Software Development Kit Manager'
export SDKMAN_DIR="$HOME/.sdkman"
# Use $SDKMAN_DIR if defined,
# otherwise default to ~/.sdkman
export SDKMAN_DIR=${SDKMAN_DIR:-$HOME/.sdkman}
[[ -s "${SDKMAN_DIR}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR}/bin/sdkman-init.sh"

View File

@ -0,0 +1,144 @@
#!/usr/bin/env bash
cite about-plugin
about-plugin 'sshagent helper functions'
function _get_sshagent_pid_from_env_file() {
local env_file="${1}"
[[ -r "${env_file}" ]] || {
echo "";
return
}
tail -1 "${env_file}" \
| cut -d' ' -f4 \
| cut -d';' -f1
}
function _get_process_status_field() {
# uses /proc filesystem
local \
pid \
status_file \
field
pid="${1}"
field="${2}"
status_file="/proc/${pid}/status"
if ! ([[ -d "${status_file%/*}" ]] \
&& [[ -r "${status_file}" ]]); then
echo ""; return;
fi
grep "${field}:" "${status_file}" \
| cut -d':' -f2 \
| sed -e 's/[[:space:]]\+//g' \
| cut -d'(' -f1
}
function _is_item_in_list() {
local item
for item in "${@:1}"; do
if [[ "${item}" == "${1}" ]]; then
return 1
fi
done
return 0
}
function _is_proc_alive_at_pid() {
local \
pid \
expected_name \
actual_name \
actual_state
pid="${1?}"
expected_name="ssh-agent"
# we want to exclude: X (killed), T (traced), Z (zombie)
actual_name=$(_get_process_status_field "${pid}" "Name")
[[ "${expected_name}" == "${actual_name}" ]] || return 1
actual_state=$(_get_process_status_field "${pid}" "State")
if _is_item_in_list "${actual_state}" "X" "T" "Z"; then
return 1
fi
return 0
}
function _ensure_valid_sshagent_env() {
local \
agent_pid \
tmp_res
mkdir -p "${HOME}/.ssh"
type restorecon &> /dev/null
tmp_res="$?"
if [[ "${tmp_res}" -eq 0 ]]; then
restorecon -rv "${HOME}/.ssh"
fi
# no env file -> shoot a new agent
if ! [[ -r "${SSH_AGENT_ENV}" ]]; then
ssh-agent > "${SSH_AGENT_ENV}"
return
fi
## do not trust pre-existing SSH_AGENT_ENV
agent_pid=$(_get_sshagent_pid_from_env_file "${SSH_AGENT_ENV}")
if [[ -z "${agent_pid}" ]]; then
# no pid detected -> shoot a new agent
ssh-agent > "${SSH_AGENT_ENV}"
return
fi
## do not trust SSH_AGENT_PID
if _is_proc_alive_at_pid "${agent_pid}"; then
return
fi
echo "There's a dead ssh-agent at the landing..."
ssh-agent > "${SSH_AGENT_ENV}"
return
}
function _ensure_sshagent_dead() {
[[ -r "${SSH_AGENT_ENV}" ]] \
|| return ## no agent file - no problems
## ensure the file indeed points to a really running agent:
agent_pid=$(
_get_sshagent_pid_from_env_file \
"${SSH_AGENT_ENV}"
)
[[ -n "${agent_pid}" ]] \
|| return # no pid - no problem
_is_proc_alive_at_pid "${agent_pid}" \
|| return # process is not alive - no problem
echo -e -n "Killing ssh-agent (pid:${agent_pid}) ... "
kill -9 "${agent_pid}" && echo "DONE" || echo "FAILED"
rm -f "${SSH_AGENT_ENV}"
}
function sshagent() {
about 'ensures ssh-agent is up and running'
param '1: on|off '
example '$ sshagent on'
group 'ssh'
[[ -z "${SSH_AGENT_ENV}" ]] \
&& export SSH_AGENT_ENV="${HOME}/.ssh/agent_env.${HOSTNAME}"
case "${1}" in
on) _ensure_valid_sshagent_env;
# shellcheck disable=SC1090
source "${SSH_AGENT_ENV}" > /dev/null;
;;
off) _ensure_sshagent_dead
;;
*)
;;
esac
}
sshagent on

View File

@ -1,4 +1,13 @@
## Testing with [Bats](https://github.com/sstephenson/bats#installing-bats-from-source)
To execute the unit tests, please run the `run` script:
```bash
# If you are in the `test` directory:
./run
# If you are in the root `.bash_it` directory:
test/run
```
bats test/{lib,plugins}
```
The `run` script will automatically install [Bats](https://github.com/sstephenson/bats#installing-bats-from-source) if it is not already present, and will then run all tests found under the `test` directory, including subdirectories.

View File

@ -0,0 +1,371 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
function local_setup {
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
echo "Bi : $BASH_IT"
echo "Lib: $lib_directory"
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
# Copy the test fixture to the Bash-it folder
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
# Don't pollute the user's actual $HOME directory
# Use a test home directory instead
export BASH_IT_TEST_CURRENT_HOME="${HOME}"
export BASH_IT_TEST_HOME="$(cd "${BASH_IT}/.." && pwd)/BASH_IT_TEST_HOME"
mkdir -p "${BASH_IT_TEST_HOME}"
export HOME="${BASH_IT_TEST_HOME}"
}
function local_teardown {
export HOME="${BASH_IT_TEST_CURRENT_HOME}"
rm -rf "${BASH_IT_TEST_HOME}"
assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}"
}
@test "bash-it: verify that the test fixture is available" {
assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash"
assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash"
}
@test "bash-it: load aliases in order" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='b'"
}
@test "bash-it: load aliases in priority order" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='a'"
}
@test "bash-it: load aliases and plugins in priority order" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='c'"
}
@test "bash-it: load aliases, plugins and completions in priority order" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
mkdir -p $BASH_IT/completion/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
# "b" wins since completions are loaded last in the old directory structure
assert_line -n 0 "alias test_alias='b'"
}
@test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
mkdir -p $BASH_IT/completion/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
# "b" wins since completions are loaded last in the old directory structure
assert_line -n 0 "alias test_alias='b'"
}
@test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
# This will be c, loaded from the c plugin, since the individual directories
# are loaded one by one.
assert_line -n 0 "alias test_alias='c'"
}
@test "bash-it: load global aliases in order" {
mkdir -p $BASH_IT/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='b'"
}
@test "bash-it: load global aliases in priority order" {
mkdir -p $BASH_IT/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash
assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='a'"
}
@test "bash-it: load global aliases and plugins in priority order" {
mkdir -p $BASH_IT/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
assert_line -n 0 "alias test_alias='c'"
}
@test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" {
mkdir -p $BASH_IT/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash
assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
# This will be a, loaded from the a aliases, since the global directory
# loads all component types at once
assert_line -n 0 "alias test_alias='a'"
}
@test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" {
mkdir -p $BASH_IT/enabled
mkdir -p $BASH_IT/aliases/enabled
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash
assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash"
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash"
ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash"
# Add one file in the old directory structure
ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash"
# The `test_alias` alias should not exist
run alias test_alias &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias test_alias &> /dev/null
assert_success
# This will be "b", loaded from the b aliases in the individual directory, since
# the individual directories are loaded after the global one.
assert_line -n 0 "alias test_alias='b'"
}
@test "bash-it: load enabled aliases from new structure, priority-based" {
mkdir -p $BASH_IT/enabled
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
# The `ah` alias should not exist
run alias ah &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias ah &> /dev/null
assert_success
}
@test "bash-it: load enabled aliases from old structure, priority-based" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash"
# The `ah` alias should not exist
run alias ah &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias ah &> /dev/null
assert_success
}
@test "bash-it: load enabled aliases from old structure, without priorities" {
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/plugins/enabled
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash"
ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash"
# The `ah` alias should not exist
run alias ah &> /dev/null
assert_failure
load "$BASH_IT/bash_it.sh"
run alias ah &> /dev/null
assert_success
}

View File

@ -0,0 +1,368 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../completion/available/bash-it.completion
function local_setup {
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled
# Don't pollute the user's actual $HOME directory
# Use a test home directory instead
export BASH_IT_TEST_CURRENT_HOME="${HOME}"
export BASH_IT_TEST_HOME="$(cd "${BASH_IT}/.." && pwd)/BASH_IT_TEST_HOME"
mkdir -p "${BASH_IT_TEST_HOME}"
export HOME="${BASH_IT_TEST_HOME}"
}
function local_teardown {
export HOME="${BASH_IT_TEST_CURRENT_HOME}"
rm -rf "${BASH_IT_TEST_HOME}"
assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}"
}
@test "completion bash-it: ensure that the _bash-it-comp function is available" {
type -a _bash-it-comp &> /dev/null
assert_success
}
function __check_completion () {
# Get the parameters as a single value
COMP_LINE=$*
# Get the parameters as an array
eval set -- "$@"
COMP_WORDS=("$@")
# Index of the cursor in the line
COMP_POINT=${#COMP_LINE}
# Get the last character of the line that was entered
COMP_LAST=$((${COMP_POINT} - 1))
# If the last character was a space...
if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then
# ...then add an empty array item
COMP_WORDS+=('')
fi
# Word index of the last word
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 ))
# Run the Bash-it completion function
_bash-it-comp
# Return the completion output
echo "${COMPREPLY[@]}"
}
@test "completion bash-it: help - show options" {
run __check_completion 'bash-it help '
assert_line -n 0 "aliases completions migrate plugins update"
}
@test "completion bash-it: help - aliases v" {
run __check_completion 'bash-it help aliases v'
assert_line -n 0 "vagrant vault vim"
}
@test "completion bash-it: update - show no options" {
run __check_completion 'bash-it update '
assert_line -n 0 ""
}
@test "completion bash-it: search - show no options" {
run __check_completion 'bash-it search '
assert_line -n 0 ""
}
@test "completion bash-it: migrate - show no options" {
run __check_completion 'bash-it migrate '
assert_line -n 0 ""
}
@test "completion bash-it: show options" {
run __check_completion 'bash-it '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: bash-ti - show options" {
run __check_completion 'bash-ti '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: shit - show options" {
run __check_completion 'shit '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: bashit - show options" {
run __check_completion 'bashit '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: batshit - show options" {
run __check_completion 'batshit '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: bash_it - show options" {
run __check_completion 'bash_it '
assert_line -n 0 "disable enable help migrate search show update version"
}
@test "completion bash-it: show - show options" {
run __check_completion 'bash-it show '
assert_line -n 0 "aliases completions plugins"
}
@test "completion bash-it: enable - show options" {
run __check_completion 'bash-it enable '
assert_line -n 0 "alias completion plugin"
}
@test "completion bash-it: enable - show options a" {
run __check_completion 'bash-it enable a'
assert_line -n 0 "alias"
}
@test "completion bash-it: disable - show options" {
run __check_completion 'bash-it disable '
assert_line -n 0 "alias completion plugin"
}
@test "completion bash-it: disable - show options a" {
run __check_completion 'bash-it disable a'
assert_line -n 0 "alias"
}
@test "completion bash-it: disable - provide nothing when atom is not enabled" {
run __check_completion 'bash-it disable alias ato'
assert_line -n 0 ""
}
@test "completion bash-it: disable - provide all when atom is not enabled" {
run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all"
}
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash"
ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/apm.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash"
run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom"
}
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/350---apm.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash"
run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom"
}
@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash"
ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/enabled/350---apm.completion.bash
assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash"
run __check_completion 'bash-it disable alias a'
assert_line -n 0 "all atom"
}
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/docker-machine.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine"
}
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/350---docker-machine.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine"
}
@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/enabled/350---docker-machine.plugin.bash
assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash"
run __check_completion 'bash-it disable plugin docker'
assert_line -n 0 "docker-machine"
}
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash"
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash"
run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli"
}
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash"
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli"
}
@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/enabled/150---todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash
assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it disable alias to'
assert_line -n 0 "todo.txt-cli"
}
@test "completion bash-it: enable - provide the atom aliases when not enabled" {
run __check_completion 'bash-it enable alias ato'
assert_line -n 0 "atom"
}
@test "completion bash-it: enable - provide the a* aliases when not enabled" {
run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt atom"
}
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash"
run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt"
}
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash"
run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt"
}
@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash"
run __check_completion 'bash-it enable alias a'
assert_line -n 0 "all ag ansible apt"
}
@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker-compose docker-machine docker"
}
@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker-compose docker-machine docker"
}
@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable plugin docker'
assert_line -n 0 "docker-compose docker-machine docker"
}
@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine"
}
@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine"
}
@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the new location and priority-based name" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash"
run __check_completion 'bash-it enable completion docker'
assert_line -n 0 "docker docker-compose docker-machine"
}
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" {
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash"
run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli"
}
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" {
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli"
}
@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" {
ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash
assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash"
run __check_completion 'bash-it enable alias to'
assert_line -n 0 "todo.txt-cli"
}

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
alias test_alias="a"

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
alias test_alias="b"

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
alias test_alias="c"

View File

@ -14,10 +14,16 @@ case $OSTYPE in
esac
function local_setup {
mkdir -p $BASH_IT
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
cp -r $lib_directory/../../* $BASH_IT/
rm -rf "$BASH_IT/aliases/enabled" "$BASH_IT/completion/enabled" "$BASH_IT/plugins/enabled"
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
# Don't pollute the user's actual $HOME directory
# Use a test home directory instead
@ -36,7 +42,7 @@ function local_teardown {
}
@test "install: verify that the install script exists" {
assert [ -e "$BASH_IT/install.sh" ]
assert_file_exist "$BASH_IT/install.sh"
}
@test "install: run the install script silently" {
@ -44,13 +50,13 @@ function local_teardown {
./install.sh --silent
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
assert [ -L "$BASH_IT/aliases/enabled/150---general.aliases.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/365---alias-completion.plugin.bash" ]
assert [ -L "$BASH_IT/completion/enabled/350---bash-it.completion.bash" ]
assert [ -L "$BASH_IT/completion/enabled/350---system.completion.bash" ]
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---system.completion.bash"
}
@test "install: verify that a backup file is created" {
@ -62,8 +68,8 @@ function local_teardown {
./install.sh --silent
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ]
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')

View File

@ -14,9 +14,16 @@ case $OSTYPE in
esac
function local_setup {
mkdir -p $BASH_IT
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
cp -r $lib_directory/../../* $BASH_IT/
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
# Don't pollute the user's actual $HOME directory
# Use a test home directory instead
@ -35,7 +42,7 @@ function local_teardown {
}
@test "uninstall: verify that the uninstall script exists" {
assert [ -e "$BASH_IT/uninstall.sh" ]
assert_file_exist "$BASH_IT/uninstall.sh"
}
@test "uninstall: run the uninstall script with an existing backup file" {
@ -49,9 +56,9 @@ function local_teardown {
assert_success
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ]
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
@ -68,9 +75,9 @@ function local_teardown {
assert_success
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')

View File

@ -9,232 +9,565 @@ cite _about _param _example _group _author _version
load ../../lib/helpers
function local_setup {
mkdir -p $BASH_IT
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
cp -r $lib_directory/../.. $BASH_IT
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/completion/enabled
mkdir -p $BASH_IT/plugins/enabled
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled
}
@test "bash-it: enable the ansible aliases through the bash-it function" {
run bash-it enable alias "ansible"
assert_line "0" 'ansible enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---ansible.aliases.bash" ]
# TODO Create global __is_enabled function
# TODO Create global __get_base_name function
# TODO Create global __get_enabled_name function
@test "helpers: _command_exists function exists" {
type -a _command_exists &> /dev/null
assert_success
}
@test "bash-it: enable the todo.txt-cli aliases through the bash-it function" {
@test "helpers: _command_exists function positive test ls" {
run _command_exists ls
assert_success
}
@test "helpers: _command_exists function positive test bash-it" {
run _command_exists bash-it
assert_success
}
@test "helpers: _command_exists function negative test" {
run _command_exists __addfkds_dfdsjdf
assert_failure
}
@test "helpers: bash-it help aliases ag" {
run bash-it help aliases "ag"
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"
}
@test "helpers: bash-it help aliases without any aliases enabled" {
run bash-it help aliases
assert_line -n 0 ""
}
@test "helpers: bash-it help list aliases without any aliases enabled" {
run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash"
assert_line -n 0 "ag:"
}
@test "helpers: bash-it help list aliases with ag aliases enabled" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash"
assert_line -n 0 "ag:"
}
@test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" {
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash"
assert_line -n 0 "todo.txt-cli:"
}
@test "helpers: bash-it help list aliases with docker-compose aliases enabled" {
ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash"
assert_line -n 0 "docker-compose:"
}
@test "helpers: bash-it help list aliases with ag aliases enabled in global directory" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash"
assert_line -n 0 "ag:"
}
@test "helpers: bash-it help aliases one alias enabled in the old directory" {
ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash"
run bash-it help aliases
assert_line -n 0 "ag:"
}
@test "helpers: bash-it help aliases one alias enabled in global directory" {
run bash-it enable alias "ag"
assert_line -n 0 'ag enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run bash-it enable plugin "aws"
assert_line -n 0 'aws enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash"
run bash-it help aliases
assert_line -n 0 "ag:"
assert_line -n 1 "ag='ag --smart-case --pager=\"less -MIRFX'"
}
@test "helpers: enable the todo.txt-cli aliases through the bash-it function" {
run bash-it enable alias "todo.txt-cli"
assert_line "0" 'todo.txt-cli enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ]
assert_line -n 0 'todo.txt-cli enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
}
@test "bash-it: enable the curl aliases" {
@test "helpers: enable the curl aliases" {
run _enable-alias "curl"
assert_line "0" 'curl enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---curl.aliases.bash" ]
assert_line -n 0 'curl enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash"
}
@test "bash-it: enable the apm completion through the bash-it function" {
@test "helpers: enable the apm completion through the bash-it function" {
run bash-it enable completion "apm"
assert_line "0" 'apm enabled with priority 350.'
assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ]
assert_line -n 0 'apm enabled with priority 350.'
assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash"
}
@test "bash-it: enable the brew completion" {
@test "helpers: enable the brew completion" {
run _enable-completion "brew"
assert_line "0" 'brew enabled with priority 350.'
assert [ -L "$BASH_IT/completion/enabled/350---brew.completion.bash" ]
assert_line -n 0 'brew enabled with priority 350.'
assert_link_exist "$BASH_IT/enabled/350---brew.completion.bash"
}
@test "bash-it: enable the node plugin" {
@test "helpers: enable the node plugin" {
run _enable-plugin "node"
assert_line "0" 'node enabled with priority 250.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash"
}
@test "bash-it: enable the node plugin through the bash-it function" {
@test "helpers: enable the node plugin through the bash-it function" {
run bash-it enable plugin "node"
assert_line "0" 'node enabled with priority 250.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
}
@test "bash-it: enable the node and nvm plugins through the bash-it function" {
@test "helpers: enable the node and nvm plugins through the bash-it function" {
run bash-it enable plugin "node" "nvm"
assert_line "0" 'node enabled with priority 250.'
assert_line "1" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'node enabled with priority 250.'
assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
}
@test "bash-it: enable the foo-unkown and nvm plugins through the bash-it function" {
@test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" {
run bash-it enable plugin "foo-unknown" "nvm"
assert_line "0" 'sorry, foo-unknown does not appear to be an available plugin.'
assert_line "1" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.'
assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
}
@test "bash-it: enable the nvm plugin" {
@test "helpers: enable the nvm plugin" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
}
@test "bash-it: enable an unknown plugin" {
@test "helpers: enable an unknown plugin" {
run _enable-plugin "unknown-foo"
assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.'
assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.'
# Check for both old an new structure
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ]
}
@test "bash-it: enable an unknown plugin through the bash-it function" {
@test "helpers: enable an unknown plugin through the bash-it function" {
run bash-it enable plugin "unknown-foo"
echo "${lines[@]}"
assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.'
assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.'
# Check for both old an new structure
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ]
}
@test "bash-it: disable a plugin that is not enabled" {
@test "helpers: disable a plugin that is not enabled" {
run _disable-plugin "sdkman"
assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.'
assert_line -n 0 'sorry, sdkman does not appear to be an enabled plugin.'
}
@test "bash-it: enable and disable the nvm plugin" {
@test "helpers: enable and disable the nvm plugin" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
run _disable-plugin "nvm"
assert_line "0" 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: disable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
@test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
run _disable-plugin "nvm"
assert_line "0" 'nvm disabled.'
assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
}
@test "helpers: disable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin if it was enabled without a priority" {
@test "helpers: enable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
run _enable-plugin "nvm"
assert_line "0" 'nvm is already enabled.'
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin twice" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
@test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
run _enable-plugin "nvm"
assert_line "0" 'nvm is already enabled.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm is already enabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
@test "helpers: enable the nvm plugin twice" {
run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
}
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash
assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ]
@test "helpers: migrate plugins and completions that share the same name" {
ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash
assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash"
run _enable-plugin "ssh"
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash"
run _bash-it-migrate
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ]
assert_line -n 0 'Migrating plugin dirs.'
assert_line -n 1 'dirs disabled.'
assert_line -n 2 'dirs enabled with priority 250.'
assert_line -n 3 'Migrating completion dirs.'
assert_line -n 4 'dirs disabled.'
assert_line -n 5 'dirs enabled with priority 350.'
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash"
assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash"
assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ]
}
@test "helpers: migrate enabled plugins that don't use the new priority-based configuration" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash"
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash"
run _enable-plugin "ssh"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
run _bash-it-migrate
assert_line -n 0 'Migrating alias todo.txt-cli.'
assert_line -n 1 'todo.txt-cli disabled.'
assert_line -n 2 'todo.txt-cli enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ]
}
@test "bash-it: run the migrate command without anything to migrate and nothing enabled" {
run _bash-it-migrate
}
@test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash"
@test "bash-it: run the migrate command without anything to migrate" {
run _enable-plugin "ssh"
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
run _bash-it-migrate
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ]
}
@test "bash-it: verify that existing components are automatically migrated when something is enabled" {
@test "helpers: run the migrate command without anything to migrate and nothing enabled" {
run _bash-it-migrate
}
@test "helpers: run the migrate command without anything to migrate" {
run _enable-plugin "ssh"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
run _bash-it-migrate
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
}
function __migrate_all_components() {
subdirectory="$1"
one_type="$2"
priority="$3"
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
to_enable=$(basename $f)
if [ -z "$priority" ]; then
ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable"
else
ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable"
fi
done
ls ${BASH_IT}/${subdirectory}/enabled
all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs)
all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs)
assert_equal "$all_available" "$all_enabled_old"
run bash-it migrate
all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs)
assert_equal "0" "$all_enabled_old_after"
all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l | xargs)
assert_equal "$all_enabled_old" "$all_enabled_new_after"
}
@test "helpers: migrate all plugins" {
subdirectory="plugins"
one_type="plugin"
__migrate_all_components "$subdirectory" "$one_type"
}
@test "helpers: migrate all aliases" {
subdirectory="aliases"
one_type="aliases"
__migrate_all_components "$subdirectory" "$one_type"
}
@test "helpers: migrate all completions" {
subdirectory="completion"
one_type="completion"
__migrate_all_components "$subdirectory" "$one_type"
}
@test "helpers: migrate all plugins with previous priority" {
subdirectory="plugins"
one_type="plugin"
__migrate_all_components "$subdirectory" "$one_type" "100"
}
@test "helpers: migrate all aliases with previous priority" {
subdirectory="aliases"
one_type="aliases"
__migrate_all_components "$subdirectory" "$one_type" "100"
}
@test "helpers: migrate all completions with previous priority" {
subdirectory="completion"
one_type="completion"
__migrate_all_components "$subdirectory" "$one_type" "100"
}
@test "helpers: verify that existing components are automatically migrated when something is enabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
run bash-it enable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node enabled with priority 250.'
assert_line -n 0 'Migrating plugin nvm.'
assert_line -n 1 'nvm disabled.'
assert_line -n 2 'nvm enabled with priority 225.'
assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 4 'node enabled with priority 250.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
}
@test "bash-it: verify that existing components are automatically migrated when something is disabled" {
@test "helpers: verify that existing components are automatically migrated when something is disabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
run bash-it disable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node disabled.'
assert_line -n 0 'Migrating plugin node.'
assert_line -n 1 'node disabled.'
assert_line -n 2 'node enabled with priority 250.'
assert_line -n 3 'Migrating plugin nvm.'
assert_line -n 4 'nvm disabled.'
assert_line -n 5 'nvm enabled with priority 225.'
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 7 'node disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable all plugins" {
@test "helpers: enable all plugins" {
run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "$available" "$enabled"
}
@test "bash-it: disable all plugins" {
@test "helpers: disable all plugins" {
run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "$available" "$enabled"
run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run _disable-plugin "all"
local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
}
@test "helpers: disable all plugins in the old directory structure" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash"
local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "2" "$enabled"
run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run _disable-plugin "all"
local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "$enabled2" "0"
assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
}
@test "bash-it: describe the nvm plugin without enabling it" {
@test "helpers: disable all plugins in the old directory structure with priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "2" "$enabled"
run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run _disable-plugin "all"
local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
}
@test "helpers: disable all plugins without anything enabled" {
local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "0" "$enabled"
run _enable-alias "ag"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
run _disable-plugin "all"
local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "0" "$enabled2"
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
}
@test "helpers: enable the ansible aliases through the bash-it function" {
run bash-it enable alias "ansible"
assert_line -n 0 'ansible enabled with priority 150.'
assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash"
}
@test "helpers: describe the nvm plugin without enabling it" {
_bash-it-plugins | grep "nvm" | grep "\[ \]"
}
@test "bash-it: describe the nvm plugin after enabling it" {
@test "helpers: describe the nvm plugin after enabling it" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
@test "bash-it: describe the todo.txt-cli aliases without enabling them" {
@test "helpers: describe the nvm plugin after enabling it in the old directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
@test "helpers: describe the nvm plugin after enabling it in the old directory with priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
@test "helpers: describe the todo.txt-cli aliases without enabling them" {
run _bash-it-aliases
assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations"
}

View File

@ -13,17 +13,24 @@ load ../../lib/search
NO_COLOR=true
function local_setup {
mkdir -p $BASH_IT
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
cp -r $lib_directory/../../* $BASH_IT/
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
}
@test "helpers search plugins" {
@test "search: plugin base" {
run _bash-it-search-component 'plugins' 'base'
[[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]]
}
@test "helpers search ruby gem bundle rake rails" {
@test "search: ruby gem bundle rake rails" {
# first disable them all, so that the output does not appear with a checkbox
# and we can compare the result
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
@ -35,7 +42,7 @@ function local_setup {
assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]
}
@test "search ruby gem bundle -chruby rake rails" {
@test "search: ruby gem bundle -chruby rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _bash-it-search 'ruby' 'gem' 'bundle' '-chruby' 'rake' 'rails'
assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ]
@ -43,19 +50,19 @@ function local_setup {
assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]
}
@test "search (rails enabled) ruby gem bundle rake rails" {
@test "search: (rails enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _enable-alias 'rails'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
assert_line "0" ' aliases => bundler ✓rails'
assert_line "1" ' plugins => chruby chruby-auto rails ruby'
assert_line "2" ' completions => bundler gem rake'
assert_line -n 0 ' aliases => bundler ✓rails'
assert_line -n 1 ' plugins => chruby chruby-auto rails ruby'
assert_line -n 2 ' completions => bundler gem rake'
}
@test "search (all enabled) ruby gem bundle rake rails" {
@test "search: (all enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails'
assert_line "0" ' aliases => ✓bundler ✓rails'
assert_line "1" ' plugins => ✓rails ✓ruby'
assert_line "2" ' completions => ✓bundler ✓gem ✓rake'
assert_line -n 0 ' aliases => ✓bundler ✓rails'
assert_line -n 1 ' plugins => ✓rails ✓ruby'
assert_line -n 2 ' completions => ✓bundler ✓gem ✓rake'
}

View File

@ -36,8 +36,15 @@ load ../../plugins/available/base.plugin
@test 'plugins base: mkcd()' {
cd "${BASH_IT_ROOT}"
run mkcd -dir_with_dash
declare -r dir_name="-dir_with_dash"
# Make sure that the directory does not exist prior to the test
rm -rf "${BASH_IT_ROOT}/${dir_name}"
mkcd "${dir_name}"
assert_success
assert_file_exist "${BASH_IT_ROOT}/${dir_name}"
assert_equal $(pwd) "${BASH_IT_ROOT}/${dir_name}"
}
@test 'plugins base: lsgrep()' {
@ -45,12 +52,28 @@ load ../../plugins/available/base.plugin
cd $BASH_IT_TEST_DIR
run lsgrep 2
assert_success
assert_equal 2 $output
assert_equal $output 2
}
@test 'plugins base: buf()' {
declare -r file="${BASH_IT_ROOT}/file"
touch $file
# Take one timestamp before running the `buf` function
declare -r stamp1=$(date +%Y%m%d_%H%M%S)
run buf $file
assert [ -e ${file}_$(date +%Y%m%d_%H%M%S) ]
# Take another timestamp after running `buf`.
declare -r stamp2=$(date +%Y%m%d_%H%M%S)
# Verify that the backup file ends with one of the two timestamps.
# This is done to avoid race conditions where buf is run close to the end
# of a second, in which case the second timestamp might be in the next second,
# causing the test to fail.
# By using `or` for the two checks, we can verify that one of the two files is present.
# In most cases, it's going to have the same timestamp anyway.
# We can't use `assert_file_exist` here, since it only checks for a single file name.
assert [ -e "${file}_${stamp1}" \
-o -e "${file}_${stamp2}" ]
}

View File

@ -0,0 +1,371 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
cite _about _param _example _group _author _version
load ../../plugins/available/battery.plugin
# Sets up the `_command_exists` function so that it only responds `true` if called with
# the name of the function that was passed in as an argument to `setup_command_exists`.
# This is used to ensure that the test cases can test the various energy management tools
# without actually having them. When called like
#
# setup_command_exists "pmset"
#
# then calling `_command_exists "pmset"` will return `true`,
# while calling `_command_exists "ioreg"` (or other commands) will return `false`.
#
# It's cool that Bash allows to define functions within functions, works almost like
# a closure in JavaScript.
function setup_command_exists {
success_command="$1"
function _command_exists {
case "$1" in
"${success_command}")
true
;;
*)
false
;;
esac
}
}
#######################
#
# no tool
#
@test 'plugins battery: battery-percentage with no tool' {
setup_command_exists "fooooo"
run battery_percentage
assert_output "no"
}
#######################
#
# pmset
#
# Creates a `pmset` function that simulates output like the real `pmset` command.
# The passed in parameter is used for the remaining battery percentage.
function setup_pmset {
percent="$1"
function pmset {
printf "\-InternalBattery-0 (id=12345) %s; discharging; 16:00 remaining present: true" "${percent}"
}
}
@test 'plugins battery: battery-percentage with pmset, 100%' {
setup_command_exists "pmset"
setup_pmset "100%"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with pmset, 98%' {
setup_command_exists "pmset"
setup_pmset "98%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with pmset, 98.5%' {
setup_command_exists "pmset"
setup_pmset "98.5%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with pmset, 4%' {
setup_command_exists "pmset"
setup_pmset "4%"
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with pmset, no status' {
setup_command_exists "pmset"
setup_pmset ""
run battery_percentage
assert_output "-1"
}
#######################
#
# acpi
#
# Creates a `acpi` function that simulates output like the real `acpi` command.
# The passed in parameters are used for
# 1) the remaining battery percentage.
# 2) the battery status
function setup_acpi {
percent="$1"
status="$2"
function acpi {
printf "Battery 0: %s, %s, 01:02:48 until charged" "${status}" "${percent}"
}
}
@test 'plugins battery: battery-percentage with acpi, 100% Full' {
setup_command_exists "acpi"
setup_acpi "100%" "Full"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with acpi, 98% Charging' {
setup_command_exists "acpi"
setup_acpi "98%" "Charging"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with acpi, 98% Discharging' {
setup_command_exists "acpi"
setup_acpi "98%" "Discharging"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with acpi, 98% Unknown' {
setup_command_exists "acpi"
setup_acpi "98%" "Unknown"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with acpi, 4% Charging' {
setup_command_exists "acpi"
setup_acpi "4%" "Charging"
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with acpi, 4% no status' {
setup_command_exists "acpi"
setup_acpi "4%" ""
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with acpi, no status' {
setup_command_exists "acpi"
setup_acpi "" ""
run battery_percentage
assert_output "-1"
}
#######################
#
# upower
#
# Creates a `upower` function that simulates output like the real `upower` command.
# The passed in parameter is used for the remaining battery percentage.
function setup_upower {
percent="$1"
function upower {
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
}
}
@test 'plugins battery: battery-percentage with upower, 100%' {
setup_command_exists "upower"
setup_upower "100.00%"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with upower, 98%' {
setup_command_exists "upower"
setup_upower "98.4567%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with upower, 98.5%' {
setup_command_exists "upower"
setup_upower "98.5%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with upower, 4%' {
setup_command_exists "upower"
setup_upower "4.2345%"
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with upower, no output' {
setup_command_exists "upower"
setup_upower ""
run battery_percentage
assert_output "-1"
}
#######################
#
# ioreg
#
# Creates a `ioreg` function that simulates output like the real `ioreg` command.
# The passed in parameter is used for the remaining battery percentage.
function setup_ioreg {
percent="$1"
function ioreg {
printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}"
}
}
@test 'plugins battery: battery-percentage with ioreg, 100%' {
setup_command_exists "ioreg"
setup_ioreg "100%"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with ioreg, 98%' {
setup_command_exists "ioreg"
setup_ioreg "98%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with ioreg, 98.5%' {
setup_command_exists "ioreg"
setup_ioreg "98.5%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with ioreg, 4%' {
setup_command_exists "ioreg"
setup_ioreg "4%"
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with ioreg, no status' {
setup_command_exists "ioreg"
# Simulate that no battery is present
function ioreg {
printf ""
}
run battery_percentage
assert_output "-1"
}
#######################
#
# WMIC
#
# Creates a `WMIC` function that simulates output like the real `WMIC` command.
# The passed in parameter is used for the remaining battery percentage.
function setup_WMIC {
percent="$1"
function WMIC {
printf "Charge: %s" "${percent}"
}
}
@test 'plugins battery: battery-percentage with WMIC, 100%' {
setup_command_exists "WMIC"
setup_WMIC "100%"
run battery_percentage
assert_output "100"
}
@test 'plugins battery: battery-percentage with WMIC, 98%' {
setup_command_exists "WMIC"
setup_WMIC "98%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with WMIC, 98.5%' {
setup_command_exists "WMIC"
setup_WMIC "98.5%"
run battery_percentage
assert_output "98"
}
@test 'plugins battery: battery-percentage with WMIC, 4%' {
setup_command_exists "WMIC"
setup_WMIC "4%"
run battery_percentage
assert_output "04"
}
@test 'plugins battery: battery-percentage with WMIC, no status' {
setup_command_exists "WMIC"
setup_WMIC ""
run battery_percentage
assert_output "-1"
}

View File

@ -5,12 +5,44 @@ load ../../lib/helpers
load ../../lib/composure
load ../../plugins/available/ruby.plugin
function local_setup {
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled
export OLD_PATH="$PATH"
export PATH="/usr/bin:/bin:/usr/sbin"
}
function local_teardown {
export PATH="$OLD_PATH"
unset OLD_PATH
}
@test "plugins ruby: remove_gem is defined" {
run type remove_gem
assert_line 1 "remove_gem () "
assert_line -n 1 "remove_gem () "
}
@test "plugins ruby: PATH includes ~/.gem/ruby/bin" {
last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1);
if ! which ruby >/dev/null; then
skip 'ruby not installed'
fi
load ../../plugins/available/ruby.plugin
local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1)
[[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]]
}

View File

@ -1,12 +1,19 @@
#!/usr/bin/env bash
test_directory="$(cd "$(dirname "$0")" && pwd)"
bats_executable="${test_directory}/../bats/bin/bats"
bats_executable="${test_directory}/../test_lib/bats-core/bin/bats"
[ ! -e $bats_executable ] && \
git clone --depth 1 https://github.com/sstephenson/bats.git ${test_directory}/../bats
git submodule init && git submodule update
if [ -z "${BASH_IT}" ]; then
export BASH_IT=$(cd ${test_directory} && dirname $(pwd))
declare BASH_IT
BASH_IT=$(cd ${test_directory} && dirname "$(pwd)")
export BASH_IT
fi
exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins,themes}
if [ -z "$1" ]; then
test_dirs=( ${test_directory}/{bash_it,completion,install,lib,plugins,themes} )
else
test_dirs=( "$1" )
fi
exec $bats_executable ${CI:+--tap} "${test_dirs[@]}"

View File

@ -13,6 +13,13 @@ if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then
export BASH_IT=$BASH_IT_TEST_DIR
fi
export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.."
export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/../test_lib}"
load "${TEST_DEPS_DIR}/bats-support/load.bash"
load "${TEST_DEPS_DIR}/bats-assert/load.bash"
load "${TEST_DEPS_DIR}/bats-file/load.bash"
local_setup() {
true
}
@ -33,76 +40,47 @@ teardown() {
rm -rf "${BASH_IT_TEST_DIR}"
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "$@"
fi
} | sed "s:${BASH_IT_TEST_DIR}:TEST_DIR:g" >&2
return 1
}
assert_success() {
if [ "$status" -ne 0 ]; then
flunk "command failed with exit status $status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
assert_equal "$2" "${lines[$1]}"
# Fail and display path of the link if it does not exist. Also fails
# if the path exists, but is not a link.
# This function is the logical complement of `assert_file_not_exist'.
# There is no dedicated function for checking that a link does not exist.
#
# Globals:
# BATSLIB_FILE_PATH_REM
# BATSLIB_FILE_PATH_ADD
# Arguments:
# $1 - path
# Returns:
# 0 - link exists and is a link
# 1 - otherwise
# Outputs:
# STDERR - details, on failure
assert_link_exist() {
local -r file="$1"
local -r target="$2"
if [[ ! -L "$file" ]]; then
local -r rem="$BATSLIB_FILE_PATH_REM"
local -r add="$BATSLIB_FILE_PATH_ADD"
if [[ -e "$file" ]]; then
batslib_print_kv_single 4 'path' "${file/$rem/$add}" \
| batslib_decorate 'exists, but is not a link' \
| fail
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then return 0; fi
done
flunk "expected line \`$1'"
fi
}
refute_line() {
if [ "$1" -ge 0 ] 2>/dev/null; then
local num_lines="${#lines[@]}"
if [ "$1" -lt "$num_lines" ]; then
flunk "output has $num_lines lines"
batslib_print_kv_single 4 'path' "${file/$rem/$add}" \
| batslib_decorate 'link does not exist' \
| fail
fi
else
local line
for line in "${lines[@]}"; do
if [ "$line" = "$1" ]; then
flunk "expected to not find line \`$line'"
if [ -n "$target" ]; then
local link_target=''
link_target=$(readlink "$file")
if [[ "$link_target" != "$target" ]]; then
batslib_print_kv_single_or_multi 8 'path' "${file/$rem/$add}" \
'expected' "$target" \
'actual' "$link_target" \
| batslib_decorate 'link exists, but does not point to target file' \
| fail
fi
fi
done
fi
}

View File

@ -2,7 +2,10 @@
load ../test_helper
load ../../lib/composure
load ../../plugins/available/base.plugin
cite _about _param _example _group _author _version
load ../../lib/helpers
load ../../themes/base.theme
@test 'themes base: battery_percentage should not exist' {
@ -23,7 +26,7 @@ load ../../themes/base.theme
run battery_char
assert_success
assert_line "0" ""
assert_line -n 0 ""
run type -a battery_char
assert_line " echo -n"
@ -50,7 +53,7 @@ load ../../themes/base.theme
run battery_charge
assert_success
assert_line "0" ""
assert_line -n 0 ""
}
@test 'themes base: battery_charge should exist if battery plugin loaded' {

View File

@ -0,0 +1,376 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
cite _about _param _example _group _author _version
load ../../lib/helpers
load ../../themes/githelpers.theme
load ../../themes/base.theme
add_commit() {
local file_name="general-${RANDOM}"
touch "${file_name}"
echo "" >> "${file_name}"
git add "${file_name}"
git commit -m"message"
}
enter_new_git_repo() {
repo="$(setup_repo)"
pushd "${repo}"
}
setup_repo() {
upstream="$(mktemp -d)"
pushd "$upstream" > /dev/null
git init . > /dev/null
echo "$upstream"
}
setup_repo_with_upstream() {
upstream="$(setup_repo)"
pushd "$upstream" > /dev/null
add_commit > /dev/null
git checkout -b branch-two
git checkout -b gone-branch
git checkout master
popd > /dev/null
downstream="$(setup_repo)"
pushd "$downstream" > /dev/null
add_commit > /dev/null
git remote add my-remote "$upstream"
git fetch my-remote
git branch -u my-remote/master > /dev/null
popd > /dev/null
pushd "$upstream" > /dev/null
git branch -d gone-branch > /dev/null
popd > /dev/null
pushd "$downstream" > /dev/null
git fetch my-remote
popd > /dev/null
echo "$downstream"
}
@test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' {
pre="\$(_git-friendly-ref)"
remote="$(setup_repo)"
pushd "$remote"
add_commit
add_commit
popd
clone="$(mktemp -d)"
pushd "$clone"
git clone "$remote" clone
cd clone
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑1"
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2"
popd
pushd "$remote"
add_commit
add_commit
add_commit
popd
pushd "$clone/clone"
git fetch
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3"
git reset HEAD~2 --hard
SCM_GIT_BEHIND_CHAR="↓"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ↓3"
}
@test 'themes base: Git: when stashes exist: it shows the number of stashes' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
add_commit
touch file
git add file
git stash
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {1}"
touch file2
git add file2
git stash
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {2}"
}
@test 'themes base: Git: remote info: when there is no upstream remote: is empty' {
pre="\$(_git-friendly-ref)"
post=" ↑1 ↓1"
enter_new_git_repo
add_commit
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
}
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' {
pre="\$(_git-friendly-ref) → "
eval_pre="master → "
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}"
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}"
}
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' {
pre="\$(_git-friendly-ref)"
eval_pre="master"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=auto
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}"
pre="${pre} → "
eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}"
git remote add second-remote "$(mktemp -d)"
git branch -u my-remote/master
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}my-remote${post}"
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}"
}
@test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' {
pre="\$(_git-friendly-ref)"
eval_pre="master"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
git remote add second-remote "$(mktemp -d)"
git remote add third-remote "$(mktemp -d)"
SCM_GIT_SHOW_REMOTE_INFO=false
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}${post}"
pre="${pre} → "
eval_pre="${eval_pre} → "
git branch -u my-remote/branch-two
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}"
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}"
}
@test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' {
pre="\$(_git-friendly-ref)"
post=" ↑1 ↓1"
repo="$(setup_repo_with_upstream)"
pushd "${repo}"
SCM_GIT_SHOW_REMOTE_INFO=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}"
git checkout gone-branch
git fetch --prune --all
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ⇢ my-remote"
}
@test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' {
enter_new_git_repo
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master"
git checkout -b second-branch
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch"
}
@test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' {
enter_new_git_repo
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master"
git checkout -b second-branch
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch"
}
@test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' {
enter_new_git_repo
add_commit
git tag first-tag
git checkout -b second-branch
add_commit
git checkout HEAD~1
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "tag:first-tag"
}
@test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' {
enter_new_git_repo
add_commit
git checkout -b second-branch
add_commit
git checkout HEAD~1
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master"
}
@test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' {
enter_new_git_repo
add_commit
add_commit
git checkout HEAD~1
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master~1"
}
@test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' {
enter_new_git_repo
add_commit
add_commit
sha="$(git rev-parse --short HEAD)"
git reset --hard HEAD~1
git checkout "$sha"
git_prompt_vars
assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha"
}
@test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
echo "line1" > file1
echo "line1" > file2
echo "line1" > file3
echo "line1" > file4
git add .
git commit -m"commit1"
git_prompt_vars
assert_equal "$SCM_STATE" " ✓"
echo "line2" >> file1
git add file1
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1"
assert_equal "$SCM_STATE" " ✗"
assert_equal "$SCM_DIRTY" "3"
echo "line2" >> file2
echo "line2" >> file3
echo "line2" >> file4
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3"
assert_equal "$SCM_DIRTY" "2"
echo "line1" > newfile5
echo "line1" > newfile6
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2"
assert_equal "$SCM_DIRTY" "1"
git config bash-it.hide-status 1
SCM_DIRTY='nope'
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
assert_equal "$SCM_DIRTY" "nope"
}
@test 'themes base: Git: git user info: shows user initials' {
pre="\$(_git-friendly-ref)"
enter_new_git_repo
git config user.name "Cool User"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre}"
SCM_GIT_SHOW_CURRENT_USER=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu"
git config user.name "Çool Üser"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü"
# show initials set by `git pair`
git config user.initials "ab cd"
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd"
}

@ -0,0 +1 @@
Subproject commit 9f88b4207da750093baabc4e3f41bf68f0dd3630

@ -0,0 +1 @@
Subproject commit 85388685632f85d5a1c32e6bca2deec401964cf7

@ -0,0 +1 @@
Subproject commit 2fddb2b831d65cdf2e411f3b47f4677fbb15729c

@ -0,0 +1 @@
Subproject commit 004e707638eedd62e0481e8cdc9223ad471f12ee

View File

@ -6,7 +6,7 @@ Supported on all operating systems.
In constant maintenance and improvement
![alt text](https://www.lfsystems.xyz/img/AtomicTheme.gif)
![Atomic-Theme](https://raw.githubusercontent.com/lfelipe1501/lfelipe-projects/master/AtomicTheme.gif)
## Install Theme
@ -159,11 +159,8 @@ Three environment variables can be defined to rearrange the segments order. The
`___ATOMIC_BOTTOM="char"`
## Follow me
### Development by
I'm on the social media.
* [@lfelipe1501](https://twitter.com/lfelipe1501) on Twitter.
* [Luis Felipe](https://www.facebook.com/lfelipe1501) on Facebook.
Developer / Author: [Luis Felipe Sánchez](https://github.com/lfelipe1501)
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

View File

@ -164,7 +164,7 @@ ___atomic_prompt_clock() {
}
___atomic_prompt_battery() {
! command_exists battery_percentage ||
! _command_exists battery_percentage ||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
[ "$(battery_percentage)" = "no" ] && return

View File

@ -3,10 +3,6 @@
# Axin Bash Prompt, inspired by theme "Sexy" and "Bobby"
# thanks to them
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
@ -34,7 +30,7 @@ else
fi
function prompt_command() {
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]\$(scm_prompt_info) \n\$ \[$RESET\]"
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]$(scm_prompt_info) \n\$ \[$RESET\]"
}
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"${white}"}

View File

@ -39,6 +39,8 @@ SCM_GIT_BEHIND_CHAR="↓"
SCM_GIT_UNTRACKED_CHAR="?:"
SCM_GIT_UNSTAGED_CHAR="U:"
SCM_GIT_STAGED_CHAR="S:"
SCM_GIT_STASH_CHAR_PREFIX="{"
SCM_GIT_STASH_CHAR_SUFFIX="}"
SCM_HG='hg'
SCM_HG_CHAR='☿'
@ -127,32 +129,14 @@ function scm_prompt_info_common {
[[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return
}
# This is added to address bash shell interpolation vulnerability described
# here: https://github.com/njhartwell/pw3nage
function git_clean_branch {
local unsafe_ref=$(command git symbolic-ref -q HEAD 2> /dev/null)
local stripped_ref=${unsafe_ref##refs/heads/}
local clean_ref=${stripped_ref//[^a-zA-Z0-9\/]/-}
echo $clean_ref
}
function git_prompt_minimal_info {
local ref
local status
local git_status_flags=('--porcelain')
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
if [[ "$(command git config --get bash-it.hide-status)" != "1" ]]; then
# Get the branch reference
ref=$(git_clean_branch) || \
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref}
_git-hide-status && return
# Get the status
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags+='-untracked-files=no'
status=$(command git status ${git_status_flags} 2> /dev/null | tail -n1)
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)"
if [[ -n ${status} ]]; then
if [[ -n "$(_git-status | tail -n1)" ]]; then
SCM_DIRTY=1
SCM_STATE=${SCM_THEME_PROMPT_DIRTY}
fi
@ -161,122 +145,52 @@ function git_prompt_minimal_info {
SCM_PREFIX=${SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${SCM_THEME_PROMPT_SUFFIX}
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
fi
}
function git_status_summary {
awk '
BEGIN {
untracked=0;
unstaged=0;
staged=0;
}
{
if (!after_first && $0 ~ /^##.+/) {
print $0
seen_header = 1
} else if ($0 ~ /^\?\? .+/) {
untracked += 1
} else {
if ($0 ~ /^.[^ ] .+/) {
unstaged += 1
}
if ($0 ~ /^[^ ]. .+/) {
staged += 1
}
}
after_first = 1
}
END {
if (!seen_header) {
print
}
print untracked "\t" unstaged "\t" staged
}'
}
function git_prompt_vars {
local details=''
if _git-branch &> /dev/null; then
SCM_GIT_DETACHED="false"
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}\$(_git-friendly-ref)$(_git-remote-info)"
else
SCM_GIT_DETACHED="true"
local detached_prefix
if _git-tag &> /dev/null; then
detached_prefix=${SCM_THEME_TAG_PREFIX}
else
detached_prefix=${SCM_THEME_DETACHED_PREFIX}
fi
SCM_BRANCH="${detached_prefix}\$(_git-friendly-ref)"
fi
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
[[ "${commits_ahead}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${commits_ahead}"
[[ "${commits_behind}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_BEHIND_CHAR}${commits_behind}"
local stash_count
stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}"
SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN}
if [[ "$(git config --get bash-it.hide-status)" != "1" ]]; then
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && local git_status_flags='-uno'
local status_lines=$((git status --porcelain ${git_status_flags} -b 2> /dev/null ||
git status --porcelain ${git_status_flags} 2> /dev/null) | git_status_summary)
local status=$(awk 'NR==1' <<< "$status_lines")
local counts=$(awk 'NR==2' <<< "$status_lines")
IFS=$'\t' read untracked_count unstaged_count staged_count <<< "$counts"
if ! _git-hide-status; then
IFS=$'\t' read -r untracked_count unstaged_count staged_count <<< "$(_git-status-counts)"
if [[ "${untracked_count}" -gt 0 || "${unstaged_count}" -gt 0 || "${staged_count}" -gt 0 ]]; then
SCM_DIRTY=1
if [[ "${SCM_GIT_SHOW_DETAILS}" = "true" ]]; then
[[ "${staged_count}" -gt 0 ]] && details+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3
[[ "${unstaged_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2
[[ "${untracked_count}" -gt 0 ]] && details+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1
[[ "${staged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STAGED_CHAR}${staged_count}" && SCM_DIRTY=3
[[ "${unstaged_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNSTAGED_CHAR}${unstaged_count}" && SCM_DIRTY=2
[[ "${untracked_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_UNTRACKED_CHAR}${untracked_count}" && SCM_DIRTY=1
fi
SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
fi
fi
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && details+="$(git_user_info)"
SCM_CHANGE=$(git rev-parse --short HEAD 2>/dev/null)
local ref=$(git_clean_branch)
if [[ -n "$ref" ]]; then
SCM_BRANCH="${SCM_THEME_BRANCH_PREFIX}${ref}"
local tracking_info="$(grep -- "${SCM_BRANCH}\.\.\." <<< "${status}")"
if [[ -n "${tracking_info}" ]]; then
[[ "${tracking_info}" =~ .+\[gone\]$ ]] && local branch_gone="true"
tracking_info=${tracking_info#\#\# ${SCM_BRANCH}...}
tracking_info=${tracking_info% [*}
local remote_name=${tracking_info%%/*}
local remote_branch=${tracking_info#${remote_name}/}
local remote_info=""
local num_remotes=$(git remote | wc -l 2> /dev/null)
[[ "${SCM_BRANCH}" = "${remote_branch}" ]] && local same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "${num_remotes}" -ge 2 ]]) ||
[[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then
remote_info="${remote_name}"
[[ "${same_branch_name}" != "true" ]] && remote_info+="/${remote_branch}"
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="${remote_branch}"
fi
if [[ -n "${remote_info}" ]];then
if [[ "${branch_gone}" = "true" ]]; then
SCM_BRANCH+="${SCM_THEME_BRANCH_GONE_PREFIX}${remote_info}"
else
SCM_BRANCH+="${SCM_THEME_BRANCH_TRACK_PREFIX}${remote_info}"
fi
fi
fi
SCM_GIT_DETACHED="false"
else
local detached_prefix=""
ref=$(git describe --tags --exact-match 2> /dev/null)
if [[ -n "$ref" ]]; then
detached_prefix=${SCM_THEME_TAG_PREFIX}
else
ref=$(git describe --contains --all HEAD 2> /dev/null)
ref=${ref#remotes/}
[[ -z "$ref" ]] && ref=${SCM_CHANGE}
detached_prefix=${SCM_THEME_DETACHED_PREFIX}
fi
SCM_BRANCH=${detached_prefix}${ref}
SCM_GIT_DETACHED="true"
fi
local ahead_re='.+ahead ([0-9]+).+'
local behind_re='.+behind ([0-9]+).+'
[[ "${status}" =~ ${ahead_re} ]] && SCM_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${BASH_REMATCH[1]}"
[[ "${status}" =~ ${behind_re} ]] && SCM_BRANCH+=" ${SCM_GIT_BEHIND_CHAR}${BASH_REMATCH[1]}"
local stash_count="$(git stash list 2> /dev/null | wc -l | tr -d ' ')"
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" {${stash_count}}"
SCM_BRANCH+=${details}
[[ "${SCM_GIT_SHOW_CURRENT_USER}" == "true" ]] && SCM_BRANCH+="$(git_user_info)"
SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
SCM_CHANGE=$(_git-short-sha 2>/dev/null || echo "")
}
function svn_prompt_vars {
@ -374,7 +288,7 @@ function chruby_version_prompt {
ruby_version=$(ruby --version | awk '{print $1, $2;}') || return
if [[ ! $(chruby | grep '*') ]]; then
if [[ ! $(chruby | grep '\*') ]]; then
ruby_version="${ruby_version} (system)"
fi
echo -e "${CHRUBY_THEME_PROMPT_PREFIX}${ruby_version}${CHRUBY_THEME_PROMPT_SUFFIX}"
@ -411,7 +325,7 @@ function git_user_info {
# support two or more initials, set by 'git pair' plugin
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
# if `user.initials` weren't set, attempt to extract initials from `user.name`
[[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | tr 'A-Z' 'a-z'); do printf "%1.1s" $word; done))
[[ -z "${SCM_CURRENT_USER}" ]] && SCM_CURRENT_USER=$(printf "%s" $(for word in $(git config user.name | PERLIO=:utf8 perl -pe '$_=lc'); do printf "%s" "${word:0:1}"; done))
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
}
@ -474,7 +388,7 @@ function battery_char {
fi
}
if ! command_exists battery_charge ; then
if ! _command_exists battery_charge ; then
# if user has installed battery plugin, skip this...
function battery_charge (){
# no op
@ -484,7 +398,7 @@ fi
# The battery_char function depends on the presence of the battery_percentage function.
# If battery_percentage is not defined, then define battery_char as a no-op.
if ! command_exists battery_percentage ; then
if ! _command_exists battery_percentage ; then
function battery_char (){
# no op
echo -n
@ -499,9 +413,25 @@ function aws_profile {
fi
}
function __check_precmd_conflict() {
local f
for f in "${precmd_functions[@]}"; do
if [[ "${f}" == "${1}" ]]; then
return 0
fi
done
return 1
}
function safe_append_prompt_command {
local prompt_re
if [ "${__bp_imported}" == "defined" ]; then
# We are using bash-preexec
if ! __check_precmd_conflict "${1}" ; then
precmd_functions+=("${1}")
fi
else
# Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then
# macOS
@ -518,4 +448,5 @@ function safe_append_prompt_command {
else
PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
fi
fi
}

View File

@ -1,13 +1,7 @@
#!/usr/bin/env bash
# Set term to 256color mode, if 256color is not supported, colors won't work properly
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# Detect whether a rebbot is required
# Detect whether a reboot is required
function show_reboot_required() {
if [ ! -z "$_bf_prompt_reboot_info" ]; then
if [ -f /var/run/reboot-required ]; then

View File

@ -152,7 +152,7 @@ ___brainy_prompt_clock() {
}
___brainy_prompt_battery() {
! command_exists battery_percentage ||
! _command_exists battery_percentage ||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
[ "$(battery_percentage)" = "no" ] && return
@ -164,7 +164,9 @@ ___brainy_prompt_battery() {
color=$bold_red
fi
box="[|]"
ac_adapter_connected && info+="+"
ac_adapter_connected && charging="+"
ac_adapter_disconnected && charging="-"
info+=$charging
[ "$info" == "100+" ] && info="AC"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
@ -251,6 +253,8 @@ export RBFU_THEME_PROMPT_PREFIX=""
export RBFU_THEME_PROMPT_SUFFIX=""
export RVM_THEME_PROMPT_PREFIX=""
export RVM_THEME_PROMPT_SUFFIX=""
export VIRTUALENV_THEME_PROMPT_PREFIX=""
export VIRTUALENV_THEME_PROMPT_SUFFIX=""
export SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
export SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"

View File

@ -1,8 +1,8 @@
# git theming
ZSH_THEME_GIT_PROMPT_PREFIX="${bold_blue}(${yellow}%B"
ZSH_THEME_GIT_PROMPT_SUFFIX="%b${bold_blue})${reset_color} "
ZSH_THEME_GIT_PROMPT_CLEAN=""
ZSH_THEME_GIT_PROMPT_DIRTY="${bold_red}"
SCM_THEME_PROMPT_PREFIX="${bold_blue}(${yellow}"
SCM_THEME_PROMPT_SUFFIX="${bold_blue})${reset_color} "
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_DIRTY="${bold_red}"
# LS colors, made with http://geoff.greer.fm/lscolors/
@ -13,8 +13,7 @@ function prompt_command() {
if [ "$(whoami)" = root ]; then no_color=$red; else no_color=$white; fi
PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} \[\$(scm_prompt_info)\]$ "
RPROMPT='[\t]'
PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} \[$(scm_prompt_info)\]${normal}$ "
}
safe_append_prompt_command prompt_command

View File

@ -84,7 +84,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if command_exists battery_charge ;
if _command_exists battery_charge ;
then
battery_charge
fi

View File

@ -0,0 +1,157 @@
#!/usr/bin/env bash
function _git-symbolic-ref {
git symbolic-ref -q HEAD 2> /dev/null
}
# When on a branch, this is often the same as _git-commit-description,
# but this can be different when two branches are pointing to the
# same commit. _git-branch is used to explicitly choose the checked-out
# branch.
function _git-branch {
git symbolic-ref -q --short HEAD 2> /dev/null || return 1
}
function _git-tag {
git describe --tags --exact-match 2> /dev/null
}
function _git-commit-description {
git describe --contains --all 2> /dev/null
}
function _git-short-sha {
git rev-parse --short HEAD
}
# Try the checked-out branch first to avoid collision with branches pointing to the same ref.
function _git-friendly-ref {
_git-branch || _git-tag || _git-commit-description || _git-short-sha
}
function _git-num-remotes {
git remote | wc -l
}
function _git-upstream {
local ref
ref="$(_git-symbolic-ref)" || return 1
git for-each-ref --format="%(upstream:short)" "${ref}"
}
function _git-upstream-remote {
local upstream
upstream="$(_git-upstream)" || return 1
local branch
branch="$(_git-upstream-branch)" || return 1
echo "${upstream%"/${branch}"}"
}
function _git-upstream-branch {
local ref
ref="$(_git-symbolic-ref)" || return 1
# git versions < 2.13.0 do not support "strip" for upstream format
# regex replacement gives the wrong result for any remotes with slashes in the name,
# so only use when the strip format fails.
git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///"
}
function _git-upstream-behind-ahead {
git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null
}
function _git-upstream-branch-gone {
[[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]]
}
function _git-hide-status {
[[ "$(git config --get bash-it.hide-status)" == "1" ]]
}
function _git-status {
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && local git_status_flags='-uno'
git status --porcelain ${git_status_flags} 2> /dev/null
}
function _git-status-counts {
_git-status | awk '
BEGIN {
untracked=0;
unstaged=0;
staged=0;
}
{
if ($0 ~ /^\?\? .+/) {
untracked += 1
} else {
if ($0 ~ /^.[^ ] .+/) {
unstaged += 1
}
if ($0 ~ /^[^ ]. .+/) {
staged += 1
}
}
}
END {
print untracked "\t" unstaged "\t" staged
}'
}
function _git-remote-info {
[[ "$(_git-upstream)" == "" ]] && return
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "$(_git-num-remotes)" -ge 2 ]]) ||
[[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then
if [[ "${same_branch_name}" != "true" ]]; then
remote_info="\$(_git-upstream)"
else
remote_info="$(_git-upstream-remote)"
fi
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="\$(_git-upstream-branch)"
fi
if [[ -n "${remote_info}" ]];then
local branch_prefix
if _git-upstream-branch-gone; then
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
else
branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
fi
echo "${branch_prefix}${remote_info}"
fi
}
# Unused by bash-it, present for API compatibility
function git_status_summary {
awk '
BEGIN {
untracked=0;
unstaged=0;
staged=0;
}
{
if (!after_first && $0 ~ /^##.+/) {
print $0
seen_header = 1
} else if ($0 ~ /^\?\? .+/) {
untracked += 1
} else {
if ($0 ~ /^.[^ ] .+/) {
unstaged += 1
}
if ($0 ~ /^[^ ]. .+/) {
staged += 1
}
}
after_first = 1
}
END {
if (!seen_header) {
print
}
print untracked "\t" unstaged "\t" staged
}'
}

View File

@ -26,7 +26,9 @@ This theme is pretty configurable, all the configuration is done by setting envi
By default, the username and hostname are shown on the right hand side, but you can change this behavior by setting the value of the following variable:
POWERLINE_PROMPT_USER_INFO_MODE="sudo"
```bash
export POWERLINE_PROMPT_USER_INFO_MODE="sudo"
```
For now, the only supported value is `sudo`, which hides the username and hostname, and shows an indicator when `sudo` has the credentials cached. Other values have no effect at this time.
@ -34,7 +36,9 @@ For now, the only supported value is `sudo`, which hides the username and hostna
By default, the current time is shown on the right hand side, you can change the format using the following variable:
THEME_CLOCK_FORMAT="%H:%M:%S"
```bash
export THEME_CLOCK_FORMAT="%H:%M:%S"
```
The time/date is printed by the `date` command, so refer to its man page to change the format.
@ -53,7 +57,21 @@ The contents of both prompt sides can be "reordered", all the "segments" (every
Two variables can be defined to set the order of the prompt segments:
POWERLINE_LEFT_PROMPT="scm python_venv ruby cwd"
POWERLINE_RIGHT_PROMPT="in_vim clock battery user_info"
```bash
export POWERLINE_LEFT_PROMPT="scm python_venv ruby cwd"
export POWERLINE_RIGHT_PROMPT="in_vim clock battery user_info"
```
The example values above are the current default values, but if you want to remove anything from the prompt, simply remove the "string" that represents the segment from the corresponding variable.
### Padding
To get the length of the left and right segments right, a _padding_ value is used.
In most cases, the default value (_2_) works fine, but on some operating systems, this needs to be adjusted.
One example is _macOS High Sierra_, where the default padding causes the right segment to extend to the next line.
On macOS High Sierra, the padding value needs to be changed to _3_ to make the theme look right.
This can be done by setting the `POWERLINE_PADDING` variable before Bash-it is loaded, e.g. in your `~/.bash_profile` or `~/.bashrc` file:
```bash
export POWERLINE_PADDING=3
```

View File

@ -9,10 +9,11 @@ function __powerline_right_segment {
local params=( $1 )
IFS="${OLD_IFS}"
local separator_char="${POWERLINE_RIGHT_SEPARATOR}"
local padding=2
local padding="${POWERLINE_PADDING}"
local separator_color=""
if [[ "${SEGMENTS_AT_RIGHT}" -eq 0 ]]; then
separator_char="${POWERLINE_RIGHT_END}"
separator_color="$(set_color ${params[1]} -)"
else
separator_color="$(set_color ${params[1]} ${LAST_SEGMENT_COLOR})"
@ -41,7 +42,7 @@ function __powerline_prompt_command {
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
done
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}"
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${POWERLINE_LEFT_END}${normal}"
## right prompt ##
if [[ -n "${POWERLINE_RIGHT_PROMPT}" ]]; then

View File

@ -1,10 +1,14 @@
#!/usr/bin/env bash
. "$BASH_IT/themes/powerline-multiline/powerline-multiline.base.bash"
PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""}
POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""}
POWERLINE_RIGHT_SEPARATOR=${POWERLINE_RIGHT_SEPARATOR:=""}
POWERLINE_LEFT_END=${POWERLINE_LEFT_END:=""}
POWERLINE_RIGHT_END=${POWERLINE_RIGHT_END:=""}
POWERLINE_PADDING=${POWERLINE_PADDING:=2}
USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "}
USER_INFO_THEME_PROMPT_COLOR=32

View File

@ -14,7 +14,6 @@ function set_color {
}
function __powerline_user_info_prompt {
set +u
local user_info=""
local color=${USER_INFO_THEME_PROMPT_COLOR}
@ -23,15 +22,16 @@ function __powerline_user_info_prompt {
color=${USER_INFO_THEME_PROMPT_COLOR_SUDO}
fi
fi
case "${POWERLINE_PROMPT_USER_INFO_MODE}" in
"sudo")
if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then
if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then
user_info="!"
fi
;;
*)
if [[ -n "${SSH_CLIENT}" ]]; then
user_info="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}"
if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then
user_info="${USER_INFO_SSH_CHAR}${USER}"
else
user_info="${USER}"
fi
@ -43,9 +43,9 @@ function __powerline_user_info_prompt {
function __powerline_ruby_prompt {
local ruby_version=""
if command_exists rvm; then
if _command_exists rvm; then
ruby_version="$(rvm_version_prompt)"
elif command_exists rbenv; then
elif _command_exists rbenv; then
ruby_version=$(rbenv_version_prompt)
fi
@ -90,7 +90,17 @@ function __powerline_scm_prompt {
}
function __powerline_cwd_prompt {
echo "$(pwd | sed "s|^${HOME}|~|")|${CWD_THEME_PROMPT_COLOR}"
local cwd=$(pwd | sed "s|^${HOME}|~|")
echo "${cwd}|${CWD_THEME_PROMPT_COLOR}"
}
function __powerline_hostname_prompt {
echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}"
}
function __powerline_wd_prompt {
echo "\W|${CWD_THEME_PROMPT_COLOR}"
}
function __powerline_clock_prompt {
@ -149,11 +159,17 @@ function __powerline_prompt_command {
SEGMENTS_AT_LEFT=0
LAST_SEGMENT_COLOR=""
if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then
LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)"
fi
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_${segment}_prompt)"
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
done
[[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status})
[[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}"
@ -164,3 +180,4 @@ function __powerline_prompt_command {
LEFT_PROMPT \
SEGMENTS_AT_LEFT
}

View File

@ -12,10 +12,11 @@ GIT_THEME_PROMPT_SUFFIX=" ${reset_color})"
STATUS_THEME_PROMPT_BAD="${bold_red}${reset_color}${normal} "
STATUS_THEME_PROMPT_OK="${bold_green}${reset_color}${normal} "
PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}"
function prompt_command() {
local ret_status="$( [ $? -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")"
PS1="\n${blue}\w $(scm_prompt_info)\n${ret_status} "
PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status} "
}
safe_append_prompt_command prompt_command

View File

@ -117,7 +117,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if command_exists battery_charge ;
if _command_exists battery_charge ;
then
battery_charge
fi

View File

@ -0,0 +1,43 @@
# Redline Theme
changed up the powerline base a little.
It plays nicest with this font: [DroidSansMonoForPowerline](https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/DroidSansMono)
Read the [powerline theme documentation](https://github.com/Bash-it/bash-it/blob/master/themes/powerline/README.md)
## added
* hostname
* distro logo
## changed
* sudo credential check
* required font
* some icons
Works real good like with:
```bash
## set the theme
export BASH_IT_THEME='redline'
# Set this to false to turn off version control status checking within the prompt for all themes
export SCM_CHECK=true
## Set Xterm/screen/Tmux title with only a short hostname.
export SHORT_HOSTNAME=$(hostname -s)
## enable sudo prompt
export POWERLINE_PROMPT_USER_INFO_MODE="sudo"
## prompt part string
export POWERLINE_PROMPT="python_venv user_info hostname cwd scm"
```
## enable your distro logo with
```bash
export POWERLINE_PROMPT_DISTRO_LOGO="yes"
```
![screenshot](screenshot.png?raw=true)

View File

@ -0,0 +1,60 @@
#!/usr/bin/env bash
. "$BASH_IT/themes/powerline/powerline.base.bash"
PROMPT_DISTRO_LOGO=" "
PROMPT_DISTRO_LOGO_COLOR=15
PROMPT_DISTRO_LOGO_COLORBG=52
PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""}
POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""}
USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "}
USER_INFO_SUDO_CHAR=${POWERLINE_USER_INFO_SUDO_CHAR:=" "}
USER_INFO_THEME_PROMPT_COLOR=52
USER_INFO_THEME_PROMPT_COLOR_SUDO=52
PYTHON_VENV_CHAR=${POWERLINE_PYTHON_VENV_CHAR:=" "}
CONDA_PYTHON_VENV_CHAR=${POWERLINE_CONDA_PYTHON_VENV_CHAR:="c "}
PYTHON_VENV_THEME_PROMPT_COLOR=23
SCM_NONE_CHAR=""
SCM_GIT_CHAR=${POWERLINE_SCM_GIT_CHAR:=" "}
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_DIRTY=""
SCM_THEME_PROMPT_CLEAN_COLOR=235
SCM_THEME_PROMPT_DIRTY_COLOR=235 #124
SCM_THEME_PROMPT_STAGED_COLOR=235 #52
SCM_THEME_PROMPT_UNSTAGED_COLOR=88
SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR}
RVM_THEME_PROMPT_PREFIX=""
RVM_THEME_PROMPT_SUFFIX=""
RBENV_THEME_PROMPT_PREFIX=""
RBENV_THEME_PROMPT_SUFFIX=""
RUBY_THEME_PROMPT_COLOR=161
RUBY_CHAR=${POWERLINE_RUBY_CHAR:=" "}
CWD_THEME_DIR_SEPARATOR=""
CWD_THEME_DIR_SEPARATOR_COLOR=52
CWD_THEME_PROMPT_COLOR=238
HOST_THEME_PROMPT_COLOR=88
LAST_STATUS_THEME_PROMPT_COLOR=52
CLOCK_THEME_PROMPT_COLOR=240
BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"}
BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70
BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208
BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"}
IN_VIM_THEME_PROMPT_COLOR=245
IN_VIM_THEME_PROMPT_TEXT="vim"
POWERLINE_PROMPT=${POWERLINE_PROMPT:="python_venv ruby user_info hostname cwd scm"}
safe_append_prompt_command __powerline_prompt_command

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 KiB

View File

@ -2,10 +2,6 @@
# Screenshot: http://cloud.gf3.ca/M5rG
# A big thanks to \amethyst on Freenode
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then export TERM=gnome-256color
elif [[ $TERM != dumb ]] && infocmp xterm-256color >/dev/null 2>&1; then export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)

View File

@ -13,7 +13,7 @@ case $TERM in
esac
function prompt_command() {
PS1="${TITLEBAR}${orange}${reset_color}${green}\w${bold_blue}\[\$(scm_prompt_info)\]${normal} "
PS1="${TITLEBAR}${orange}${reset_color}${green}\w${bold_blue}\[$(scm_prompt_info)\]${normal} "
}
# scm themeing