updated theme to latest
- fixed minor errors in powerline.base when pulling from origin masterpull/891/head
commit
0eb02456e2
|
|
@ -0,0 +1,2 @@
|
|||
*.sh text eol=lf
|
||||
*.bash text eol=lf
|
||||
|
|
@ -14,3 +14,4 @@ bats
|
|||
.idea
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
enabled/*
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,3 +1,6 @@
|
|||
sudo: false
|
||||
script: test/run
|
||||
language: c
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
|
|
|||
|
|
@ -1,34 +1,87 @@
|
|||
# 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.
|
||||
|
||||
Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on [Travis CI](https://travis-ci.org/Bash-it/bash-it), where the test suite is run on both Linux and macOS.
|
||||
The Pull Request will then show the result of the Travis build, indicating whether all tests ran fine, or whether there were issues.
|
||||
Please pay attention to this, Pull Requests with build issues will not be merged.
|
||||
|
||||
Adding new functionality or changing existing functionality is a good opportunity to increase Bash-it's test coverage.
|
||||
When you're changing the Bash-it codebase, please consider adding some unit tests that cover the new or changed functionality.
|
||||
Ideally, when fixing a bug, a matching unit test that verifies that the bug is no longer present, is added at the same time.
|
||||
|
||||
To run the test suite, simply execute the following in the directory where you cloned Bash-it:
|
||||
|
||||
```bash
|
||||
test/run
|
||||
```
|
||||
|
||||
This command will ensure that the [Bats Test Framework](https://github.com/bats-core/bats-core) is available in the local `test_lib` directory (Bats is included as a Git submodule) and then run the test suite found in the [test](test) folder.
|
||||
The test script will execute each test in turn, and will print a status for each test case.
|
||||
|
||||
When adding new test cases, please take a look at the existing test cases for examples.
|
||||
|
||||
The following libraries are used to help with the tests:
|
||||
|
||||
* Test Framework: https://github.com/bats-core/bats-core
|
||||
* Support library for Bats-Assert: https://github.com/ztombol/bats-support
|
||||
* General `assert` functions: https://github.com/ztombol/bats-assert
|
||||
* File `assert` functions: https://github.com/ztombol/bats-file
|
||||
|
||||
When verifying test results, please try to use the `assert` functions found in these libraries.
|
||||
|
||||
## Features
|
||||
|
||||
* When adding new completions or plugins, please don't simply copy existing tools into the Bash-it codebase, try to load/integrate the tools instead. An example is using `nvm`: Instead of copying the existing `nvm` script into Bash-it, the `nvm.plugin.bash` file tries to load an existing installation of `nvm`. This means an additional step for the user (installing `nvm` from its own repo, or through a package manager), but it will also ensure that `nvm` can be upgraded in an easy way.
|
||||
* 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.
|
||||
* 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.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
# Bash-it Development
|
||||
|
||||
This page summarizes a couple of rules to keep in mind when developing features or making changes in Bash-it.
|
||||
|
||||
## Load Order
|
||||
|
||||
### General Load Order
|
||||
|
||||
The main `bash_it.sh` script loads the frameworks individual components in the following order:
|
||||
|
||||
* `lib/composure.bash`
|
||||
* Files in `lib` with the exception of `appearance.bash` - this means that `composure.bash` is loaded again here (possible improvement?)
|
||||
* Enabled `aliases`
|
||||
* Enabled `plugins`
|
||||
* Enabled `completions`
|
||||
* `themes/colors.theme.bash`
|
||||
* `themes/base.theme.bash`
|
||||
* `lib/appearance.bash`, which loads the selected theme
|
||||
* Custom `aliases`
|
||||
* Custom `plugins`
|
||||
* Custom `completions`
|
||||
* Additional custom files from either `$BASH_IT/custom` or `$BASH_IT_CUSTOM`
|
||||
|
||||
This order is subject to change.
|
||||
|
||||
### Individual Component Load Order
|
||||
|
||||
For `aliases`, `plugins` and `completions`, the following rules are applied that influence the load order:
|
||||
|
||||
* There is a global `enabled` directory, which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/enabled` for example. All component types are linked into the same common `$BASH_IT/enabled` directory.
|
||||
* Within the common `enabled` directories, the files are loaded in alphabetical order, which is based on the item's load priority (see next item).
|
||||
* When enabling a component, a _load priority_ is assigned to the file. The following default priorities are used:
|
||||
* Aliases: 150
|
||||
* Plugins: 250
|
||||
* Completions: 350
|
||||
* When symlinking a component into the `enabled` directory, the load priority is used as a prefix for the linked name, separated with three dashes from the name of the component. The `node.plugin.bash` would be symlinked to `250---node.plugin.bash` for example.
|
||||
* Each file can override the default load priority by specifying a new value. To do this, the file needs to include a comment in the following form. This example would cause the `node.plugin.bash` (if included in that file) to be linked to `225---node.plugin.bash`:
|
||||
|
||||
```bash
|
||||
# BASH_IT_LOAD_PRIORITY: 225
|
||||
```
|
||||
|
||||
Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name.
|
||||
|
||||
These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well.
|
||||
194
README.md
194
README.md
|
|
@ -2,31 +2,50 @@
|
|||
|
||||
[](https://travis-ci.org/Bash-it/bash-it) [](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. (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
|
||||
|
||||
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.
|
||||
|
||||
## Install
|
||||
|
||||
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
|
||||
|
|
@ -34,32 +53,42 @@ 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
|
||||
|
||||
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
|
||||
|
||||
To update Bash-it, simply run:
|
||||
To update Bash-it to the latest version, simply run:
|
||||
|
||||
```
|
||||
```bash
|
||||
bash-it update
|
||||
```
|
||||
|
||||
that's all.
|
||||
|
||||
If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated.
|
||||
For these cases, we provide a `migrate` command:
|
||||
|
||||
```bash
|
||||
bash-it migrate
|
||||
```
|
||||
|
||||
This command will automatically migrate the Bash-it structure to the latest version.
|
||||
The `migrate` command is run automatically if you run the `update`, `enable` or `disable` commands.
|
||||
|
||||
## Help Screens
|
||||
|
||||
```
|
||||
```bash
|
||||
bash-it show aliases # shows installed and available aliases
|
||||
bash-it show completions # shows installed and available completions
|
||||
bash-it show plugins # shows installed and available plugins
|
||||
|
|
@ -70,11 +99,8 @@ 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
|
||||
|
||||
|
|
@ -82,10 +108,8 @@ provided.
|
|||
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
|
||||
|
|
@ -98,9 +122,9 @@ Currently enabled modules will be shown in green.
|
|||
|
||||
#### Search 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
|
||||
|
|
@ -111,15 +135,13 @@ follows:
|
|||
|
||||
#### 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
|
||||
|
||||
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
|
||||
|
|
@ -140,17 +162,32 @@ 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 a few Bash-it themes. If you've created your own custom prompts, I'd love it if you shared with everyone else! Just submit a Pull Request.
|
||||
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.
|
||||
|
||||
You can see the theme screenshots [here](https://github.com/Bash-it/bash-it/wiki/Themes).
|
||||
Examples:
|
||||
|
||||
Alternatively, you can preview the themes in your own shell using `BASH_PREVIEW=true reload`.
|
||||
```bash
|
||||
# Use the "powerline-multiline" theme
|
||||
export BASH_IT_THEME="powerline-multiline"
|
||||
|
||||
**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid extrange behaviors in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if isn't American English.
|
||||
# Use a theme outside of the Bash-it folder
|
||||
export BASH_IT_THEME="/home/foo/my_theme/my_theme.theme.bash"
|
||||
```
|
||||
|
||||
You can easily preview the themes in your own shell using `BASH_PREVIEW=true reload`.
|
||||
|
||||
If you've created your own custom prompts, we'd love it if you shared with everyone else! Just submit a Pull Request.
|
||||
You can see theme screenshots on [wiki/Themes](https://github.com/Bash-it/bash-it/wiki/Themes).
|
||||
|
||||
**NOTE**: Bash-it and some themes use UTF-8 characters, so to avoid strange behavior in your terminal, set your locale to `LC_ALL=en_US.UTF-8` or the equivalent to your language if it isn't American English.
|
||||
|
||||
## Uninstalling
|
||||
|
||||
|
|
@ -161,11 +198,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.
|
||||
|
||||
## Contributing
|
||||
|
||||
Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before reporting a bug or providing a new feature.
|
||||
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
|
||||
|
||||
|
|
@ -174,13 +208,17 @@ Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before repo
|
|||
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:
|
||||
|
||||
|
|
@ -191,7 +229,9 @@ 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
|
||||
|
||||
|
|
@ -201,7 +241,8 @@ Bash-it has some nice features related to Git, continue reading to know more abo
|
|||
|
||||
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:
|
||||
|
||||
|
|
@ -215,7 +256,7 @@ Set `SCM_GIT_SHOW_DETAILS` to 'false' to **don't show** it:
|
|||
|
||||
#### 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:
|
||||
|
||||
|
|
@ -235,7 +276,11 @@ Set `SCM_GIT_SHOW_REMOTE_INFO` to 'false' to **disable the feature**:
|
|||
|
||||
#### 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:
|
||||
|
||||
|
|
@ -245,17 +290,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
|
||||
|
||||
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:
|
||||
|
||||
|
|
@ -269,7 +321,7 @@ And
|
|||
|
||||
#### 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
|
||||
|
|
@ -277,7 +329,8 @@ export SCM_GIT_SHOW_MINIMAL_INFO=true
|
|||
|
||||
#### 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:
|
||||
|
||||
|
|
@ -291,11 +344,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:
|
||||
|
||||
|
|
@ -309,7 +363,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:
|
||||
|
||||
|
|
@ -318,13 +374,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`
|
||||
|
|
@ -333,16 +392,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.
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,17 @@ 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
|
||||
alias dkrmui='docker images -q -f dangling=true |xargs -r docker rmi' # Delete all untagged Docker images
|
||||
|
||||
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
|
||||
alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz
|
||||
|
|
|
|||
|
|
@ -18,17 +18,20 @@ alias l1='ls -1'
|
|||
|
||||
alias _="sudo"
|
||||
|
||||
# Shortcuts to edit startup files
|
||||
alias vbrc="vim ~/.bashrc"
|
||||
alias vbpf="vim ~/.bash_profile"
|
||||
|
||||
# colored grep
|
||||
# Need to check an existing file for a pattern that will be found to ensure
|
||||
# that the check works when on an OS that supports the color option
|
||||
if grep --color=auto "a" $BASH_IT/*.md &> /dev/null
|
||||
if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null
|
||||
then
|
||||
alias grep='grep --color=auto'
|
||||
export GREP_COLOR='1;33'
|
||||
fi
|
||||
|
||||
which gshuf &> /dev/null
|
||||
if [ $? -eq 0 ]
|
||||
if which gshuf &> /dev/null
|
||||
then
|
||||
alias shuf=gshuf
|
||||
fi
|
||||
|
|
@ -42,7 +45,7 @@ alias pager="$PAGER"
|
|||
|
||||
alias q='exit'
|
||||
|
||||
alias irc="$IRC_CLIENT"
|
||||
alias irc="${IRC_CLIENT:=irc}"
|
||||
|
||||
# Language aliases
|
||||
alias rb='ruby'
|
||||
|
|
@ -54,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
|
||||
|
|
@ -71,6 +75,33 @@ fi
|
|||
alias md='mkdir -p'
|
||||
alias rd='rmdir'
|
||||
|
||||
# Common misspellings of bash-it
|
||||
alias shit='bash-it'
|
||||
alias batshit='bash-it'
|
||||
alias bashit='bash-it'
|
||||
alias batbsh='bash-it'
|
||||
alias babsh='bash-it'
|
||||
alias bash_it='bash-it'
|
||||
alias bash_ti='bash-it'
|
||||
|
||||
# Additional bash-it aliases for help/show
|
||||
alias bshsa='bash-it show aliases'
|
||||
alias bshsc='bash-it show completions'
|
||||
alias bshsp='bash-it show plugins'
|
||||
alias bshha='bash-it help aliases'
|
||||
alias bshhc='bash-it help completions'
|
||||
alias bshhp='bash-it help plugins'
|
||||
alias bshsch="bash-it search"
|
||||
alias bshenp="bash-it enable plugin"
|
||||
alias bshena="bash-it enable alias"
|
||||
alias bshenc="bash-it enable completion"
|
||||
|
||||
# Shorten extract
|
||||
alias xt="extract"
|
||||
|
||||
# sudo vim
|
||||
alias svim="sudo vim"
|
||||
|
||||
# Display whatever file is regular file or folder
|
||||
catt() {
|
||||
for i in "$@"; do
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ about-alias 'common git abbreviations'
|
|||
# Aliases
|
||||
alias gcl='git clone'
|
||||
alias ga='git add'
|
||||
alias grm='git rm'
|
||||
alias gap='git add -p'
|
||||
alias gall='git add -A'
|
||||
alias gf='git fetch --all --prune'
|
||||
|
|
@ -14,6 +15,7 @@ alias gus='git reset HEAD'
|
|||
alias gpristine='git reset --hard && git clean -dfx'
|
||||
alias gclean='git clean -fd'
|
||||
alias gm="git merge"
|
||||
alias gmv='git mv'
|
||||
alias g='git'
|
||||
alias get='git'
|
||||
alias gst='git status'
|
||||
|
|
@ -32,14 +34,19 @@ alias gpom='git push origin master'
|
|||
alias gr='git remote'
|
||||
alias grv='git remote -v'
|
||||
alias gra='git remote add'
|
||||
alias gd='git diff'
|
||||
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 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'
|
||||
|
|
@ -54,7 +61,7 @@ alias gll='git log --graph --pretty=oneline --abbrev-commit'
|
|||
alias gg="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative"
|
||||
alias ggs="gg --stat"
|
||||
alias gsl="git shortlog -sn"
|
||||
alias gw="git whatchanged"
|
||||
alias gwc="git whatchanged"
|
||||
alias gt="git tag"
|
||||
alias gta="git tag -a"
|
||||
alias gtd="git tag -d"
|
||||
|
|
@ -65,6 +72,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 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*)
|
||||
|
|
@ -74,19 +85,3 @@ case $OSTYPE in
|
|||
alias gtls='git tag -l | sort -V'
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$EDITOR" ]; then
|
||||
case $OSTYPE in
|
||||
linux*)
|
||||
alias gd='git diff | vim -R -'
|
||||
;;
|
||||
darwin*)
|
||||
alias gd='git diff | mate'
|
||||
;;
|
||||
*)
|
||||
alias gd='git diff'
|
||||
;;
|
||||
esac
|
||||
else
|
||||
alias gd="git diff | $EDITOR"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
cite 'about-alias'
|
||||
about-alias 'homesick aliases'
|
||||
|
||||
# Aliases
|
||||
alias sikhm="homesick cd dotfiles"
|
||||
alias sikclone="homesick clone"
|
||||
alias sikcomt="homesick commit dotfiles"
|
||||
alias sikdstry="homesick destroy"
|
||||
alias sikdif="homesick diff dotfiles"
|
||||
alias sikexec="homesick exec dotfiles"
|
||||
alias sikexeca="homesick exec_all"
|
||||
alias sikgen="homesick generate"
|
||||
alias sikhlp="homesick help"
|
||||
alias siklnk="homesick link dotfiles"
|
||||
alias sikls="homesick list"
|
||||
alias sikopn="homesick open dotfiles"
|
||||
alias sikpll="homesick pull dotfiles"
|
||||
alias sikpsh="homesick push dotfiles"
|
||||
alias sikrc="homesick rc dotfiles"
|
||||
alias sikpth="homesick show_path dotfiles"
|
||||
alias sikst="homesick status dotfiles"
|
||||
alias siktrk="homesick track $1 dotfiles"
|
||||
alias sikulnk="homesick unlink dotfiles"
|
||||
alias sikv="homesick version"
|
||||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ alias nits='npm install-test --save'
|
|||
alias nitd='npm install-test --save-dev'
|
||||
alias nu='npm uninstall'
|
||||
alias nus='npm uninstall --save'
|
||||
alias nud='npm uninstall --save-dev'
|
||||
alias nusd='npm uninstall --save-dev'
|
||||
alias np='npm publish'
|
||||
alias nup='npm unpublish'
|
||||
alias nlk='npm link'
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ alias textedit='open -a TextEdit'
|
|||
alias hex='open -a "Hex Fiend"'
|
||||
alias skype='open -a Skype'
|
||||
alias mou='open -a Mou'
|
||||
alias subl='open -a Sublime\ Text --args'
|
||||
alias subl='open -a Sublime\ Text'
|
||||
|
||||
if [ -s /usr/bin/firefox ] ; then
|
||||
unalias firefox
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -2,6 +2,10 @@ cite 'about-alias'
|
|||
about-alias 'vagrant aliases'
|
||||
|
||||
# Aliases
|
||||
alias vhl='vagrant hosts list'
|
||||
alias vscp='vagrant scp'
|
||||
alias vsl='vagrant snapshot list'
|
||||
alias vst='vagrant snapshot take'
|
||||
alias vup="vagrant up"
|
||||
alias vupl="vagrant up 2>&1 | tee vagrant.log"
|
||||
alias vh="vagrant halt"
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
35
bash_it.sh
35
bash_it.sh
|
|
@ -29,32 +29,40 @@ then
|
|||
fi
|
||||
|
||||
# Load composure first, so we support function metadata
|
||||
# shellcheck source=./lib/composure.bash
|
||||
source "${BASH_IT}/lib/composure.bash"
|
||||
|
||||
# support 'plumbing' metadata
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
# Load colors first so they can be use in base theme
|
||||
source "${BASH_IT}/themes/colors.theme.bash"
|
||||
source "${BASH_IT}/themes/base.theme.bash"
|
||||
|
||||
# libraries, but skip appearance (themes) for now
|
||||
LIB="${BASH_IT}/lib/*.bash"
|
||||
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
|
||||
# shellcheck source=./themes/colors.theme.bash
|
||||
source "${BASH_IT}/themes/colors.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 +70,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
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
[[ -x "$(which awless)" ]] && source <(awless completion bash)
|
||||
|
|
@ -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) ]
|
||||
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
|
||||
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"
|
||||
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 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)
|
||||
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}) )
|
||||
|
|
@ -110,4 +117,10 @@ _bash-it-comp()
|
|||
return 0
|
||||
}
|
||||
|
||||
# Activate completion for bash-it and its common misspellings
|
||||
complete -F _bash-it-comp bash-it
|
||||
complete -F _bash-it-comp bash-ti
|
||||
complete -F _bash-it-comp shit
|
||||
complete -F _bash-it-comp bashit
|
||||
complete -F _bash-it-comp batshit
|
||||
complete -F _bash-it-comp bash_it
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
. <(ng completion --bash)
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
[ -x "$(which oc)" ] && eval "$(oc completion bash)"
|
||||
|
|
@ -0,0 +1 @@
|
|||
[[ -x "$(which pew)" ]] && source "$(pew shell_config)"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
# pip bash completion start
|
||||
_pip_completion()
|
||||
{
|
||||
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
|
||||
COMP_CWORD=$COMP_CWORD \
|
||||
PIP_AUTO_COMPLETE=1 $1 ) )
|
||||
}
|
||||
complete -o default -F _pip_completion pip3
|
||||
# pip bash completion end
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
[[ -x "$(which pipenv)" ]] && source <(env _PIPENV_COMPLETE="source-bash" pipenv)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# Bash completion support for RVM.
|
||||
# Source: https://rvm.io/workflow/completion
|
||||
|
||||
[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion
|
||||
|
|
@ -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 ',' ' '
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
24
install.sh
24
install.sh
|
|
@ -30,16 +30,19 @@ function load_one() {
|
|||
# Interactively enable several things
|
||||
function load_some() {
|
||||
file_type=$1
|
||||
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
|
||||
enable_func="_enable-$single_type"
|
||||
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
|
||||
for path in `ls $BASH_IT/${file_type}/available/[^_]*`
|
||||
for path in "$BASH_IT/${file_type}/available/"[^_]*
|
||||
do
|
||||
file_name=$(basename "$path")
|
||||
while true
|
||||
do
|
||||
read -e -n 1 -p "Would you like to enable the ${file_name%%.*} $file_type? [y/N] " RESP
|
||||
just_the_name="${file_name%%.*}"
|
||||
read -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP
|
||||
case $RESP in
|
||||
[yY])
|
||||
ln -s "../available/${file_name}" "$BASH_IT/$file_type/enabled"
|
||||
$enable_func $just_the_name
|
||||
break
|
||||
;;
|
||||
[nN]|"")
|
||||
|
|
@ -150,6 +153,11 @@ elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
|
|||
backup_new
|
||||
fi
|
||||
|
||||
# Load dependencies for enabling components
|
||||
source "$BASH_IT/lib/composure.bash"
|
||||
cite _about _param _example _group _author _version
|
||||
source "$BASH_IT/lib/helpers.bash"
|
||||
|
||||
if [[ $interactive ]] && ! [[ $silent ]] ;
|
||||
then
|
||||
for type in "aliases" "plugins" "completion"
|
||||
|
|
@ -160,11 +168,11 @@ then
|
|||
else
|
||||
echo ""
|
||||
echo -e "\033[0;32mEnabling sane defaults\033[0m"
|
||||
load_one completion bash-it.completion.bash
|
||||
load_one completion system.completion.bash
|
||||
load_one plugins base.plugin.bash
|
||||
load_one plugins alias-completion.plugin.bash
|
||||
load_one aliases general.aliases.bash
|
||||
_enable-completion bash-it
|
||||
_enable-completion system
|
||||
_enable-plugin base
|
||||
_enable-plugin alias-completion
|
||||
_enable-alias general
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ fi
|
|||
|
||||
# Load the theme
|
||||
if [[ $BASH_IT_THEME ]]; then
|
||||
if [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
|
||||
if [[ -f $BASH_IT_THEME ]]; then
|
||||
source $BASH_IT_THEME
|
||||
elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
|
||||
source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
|
||||
else
|
||||
source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
|
||||
|
|
|
|||
|
|
@ -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)'
|
||||
|
|
|
|||
236
lib/helpers.bash
236
lib/helpers.bash
|
|
@ -1,3 +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"
|
||||
|
|
@ -13,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"
|
||||
|
|
@ -31,15 +61,17 @@ function reload_plugins() {
|
|||
bash-it ()
|
||||
{
|
||||
about 'Bash-it help and maintenance'
|
||||
param '1: verb [one of: help | show | enable | disable | 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'
|
||||
example '$ bash-it help aliases'
|
||||
example '$ bash-it enable plugin git [tmux]...'
|
||||
example '$ bash-it disable alias hg [tmux]...'
|
||||
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:-}
|
||||
|
|
@ -55,10 +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;;
|
||||
|
|
@ -79,13 +115,16 @@ 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
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
$func $arg
|
||||
done
|
||||
else
|
||||
$func $*
|
||||
$func "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -125,16 +164,26 @@ _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
|
||||
echo "Bash-it successfully updated, enjoy!"
|
||||
echo "Bash-it successfully updated."
|
||||
echo ""
|
||||
echo "Migrating your installation to the latest version now..."
|
||||
_bash-it-migrate
|
||||
echo ""
|
||||
echo "All done, enjoy!"
|
||||
reload
|
||||
else
|
||||
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
|
||||
|
|
@ -142,7 +191,65 @@ _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
|
||||
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
|
||||
do
|
||||
typeset ff=$(basename $f)
|
||||
|
||||
# Get the type of component from the extension
|
||||
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
|
||||
# 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."
|
||||
|
||||
disable_func="_disable-$single_type"
|
||||
enable_func="_enable-$single_type"
|
||||
|
||||
$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
|
||||
}
|
||||
|
||||
_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 ()
|
||||
|
|
@ -162,14 +269,19 @@ _bash-it-describe ()
|
|||
typeset f
|
||||
typeset enabled
|
||||
printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description'
|
||||
for f in $BASH_IT/$subdirectory/available/*.bash
|
||||
for f in "${BASH_IT}/$subdirectory/available/"*.bash
|
||||
do
|
||||
if [ -e $BASH_IT/$subdirectory/enabled/$(basename $f) ]; then
|
||||
# Check for both the old format without the load priority, and the extended format with the priority
|
||||
declare enabled_files enabled_file
|
||||
enabled_file=$(basename $f)
|
||||
enabled_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=' '
|
||||
fi
|
||||
printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$file_type)"
|
||||
printf "%-20s%-10s%s\n" "$(basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(cat $f | metafor about-$file_type)"
|
||||
done
|
||||
printf '\n%s\n' "to enable $preposition $file_type, do:"
|
||||
printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all"
|
||||
|
|
@ -224,22 +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
|
||||
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=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1)
|
||||
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.$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)
|
||||
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
|
||||
|
|
@ -256,7 +383,7 @@ _enable-plugin ()
|
|||
_example '$ enable-plugin rvm'
|
||||
_group 'lib'
|
||||
|
||||
_enable-thing "plugins" "plugin" $1
|
||||
_enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN
|
||||
}
|
||||
|
||||
_enable-alias ()
|
||||
|
|
@ -266,7 +393,7 @@ _enable-alias ()
|
|||
_example '$ enable-alias git'
|
||||
_group 'lib'
|
||||
|
||||
_enable-thing "aliases" "alias" $1
|
||||
_enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS
|
||||
}
|
||||
|
||||
_enable-completion ()
|
||||
|
|
@ -276,7 +403,7 @@ _enable-completion ()
|
|||
_example '$ enable-completion git'
|
||||
_group 'lib'
|
||||
|
||||
_enable-thing "completion" "completion" $1
|
||||
_enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION
|
||||
}
|
||||
|
||||
_enable-thing ()
|
||||
|
|
@ -286,11 +413,13 @@ _enable-thing ()
|
|||
_param '1: subdirectory'
|
||||
_param '2: file_type'
|
||||
_param '3: file_entity'
|
||||
_example '$ _enable-thing "plugins" "plugin" "ssh"'
|
||||
_param '4: load priority'
|
||||
_example '$ _enable-thing "plugins" "plugin" "ssh" "150"'
|
||||
|
||||
subdirectory="$1"
|
||||
file_type="$2"
|
||||
file_entity="$3"
|
||||
load_priority="$4"
|
||||
|
||||
if [ -z "$file_entity" ]; then
|
||||
reference "enable-$file_type"
|
||||
|
|
@ -299,36 +428,47 @@ _enable-thing ()
|
|||
|
||||
if [ "$file_entity" = "all" ]; then
|
||||
typeset f $file_type
|
||||
for f in $BASH_IT/$subdirectory/available/*.bash
|
||||
for f in "${BASH_IT}/$subdirectory/available/"*.bash
|
||||
do
|
||||
plugin=$(basename $f)
|
||||
if [ ! -h $BASH_IT/$subdirectory/enabled/$plugin ]; then
|
||||
ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$plugin
|
||||
fi
|
||||
to_enable=$(basename $f .$file_type.bash)
|
||||
_enable-thing $subdirectory $file_type $to_enable $load_priority
|
||||
done
|
||||
else
|
||||
typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1)
|
||||
if [ -z "$plugin" ]; then
|
||||
typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1)
|
||||
if [ -z "$to_enable" ]; then
|
||||
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
|
||||
return
|
||||
fi
|
||||
|
||||
plugin=$(basename $plugin)
|
||||
if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then
|
||||
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][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
|
||||
|
||||
ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$plugin
|
||||
mkdir -p "${BASH_IT}/enabled"
|
||||
|
||||
# Load the priority from the file if it present there
|
||||
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 ../$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
|
||||
exec ${0/-/}
|
||||
fi
|
||||
|
||||
printf '%s\n' "$file_entity enabled."
|
||||
printf '%s\n' "$file_entity enabled with priority $use_load_priority."
|
||||
}
|
||||
|
||||
_help-completions()
|
||||
|
|
@ -355,21 +495,25 @@ _help-aliases()
|
|||
alias_path="available/$1.aliases.bash"
|
||||
;;
|
||||
esac
|
||||
cat $BASH_IT/aliases/$alias_path | metafor alias | sed "s/$/'/"
|
||||
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
|
||||
_help-list-aliases $BASH_IT/aliases/custom.aliases.bash
|
||||
|
||||
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/$/'/"
|
||||
}
|
||||
|
|
@ -381,7 +525,7 @@ _help-plugins()
|
|||
|
||||
# display a brief progress message...
|
||||
printf '%s' 'please wait, building help...'
|
||||
typeset grouplist=$(mktemp /tmp/grouplist.XXXX)
|
||||
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
|
||||
typeset func
|
||||
for func in $(typeset_functions)
|
||||
do
|
||||
|
|
@ -414,13 +558,21 @@ _help-update () {
|
|||
echo "Check for a new version of Bash-it and update it."
|
||||
}
|
||||
|
||||
_help-migrate () {
|
||||
_about 'help message for migrate command'
|
||||
_group 'lib'
|
||||
|
||||
echo "Migrates internal Bash-it structure to the latest version in case of changes."
|
||||
echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'."
|
||||
}
|
||||
|
||||
all_groups ()
|
||||
{
|
||||
about 'displays all unique metadata 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
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ then
|
|||
BASH_IT_THEME=${BASH_IT_THEME##*/}
|
||||
echo "
|
||||
$BASH_IT_THEME"
|
||||
echo "" | bash --init-file $BASH_IT/bash_it.sh -i
|
||||
echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i
|
||||
done
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
# Load after the other completions to understand what needs to be completed
|
||||
# BASH_IT_LOAD_PRIORITY: 365
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'Automatic completion of aliases'
|
||||
|
||||
|
|
@ -26,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')"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
cite about-plugin
|
||||
about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details'
|
||||
|
||||
# Only supports the Homebrew variant at the moment.
|
||||
# Only supports the Homebrew variant, Debian and Arch at the moment.
|
||||
# Feel free to provide a PR to support other install locations
|
||||
if command -v brew &>/dev/null && [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]]; then
|
||||
. $(brew --prefix)/etc/profile.d/autojump.sh
|
||||
elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then
|
||||
. "$(dpkg-query -S autojump.sh | cut -d' ' -f2)"
|
||||
elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then
|
||||
. "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)"
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ function ips ()
|
|||
group 'base'
|
||||
if command -v ifconfig &>/dev/null
|
||||
then
|
||||
ifconfig | awk '/inet /{ print $2 }'
|
||||
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
|
||||
elif command -v ip &>/dev/null
|
||||
then
|
||||
ip addr | grep -oP 'inet \K[\d.]+'
|
||||
|
|
@ -22,14 +22,22 @@ 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 ()
|
||||
{
|
||||
about 'displays your ip address, as seen by the Internet'
|
||||
group 'base'
|
||||
res=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+')
|
||||
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
|
||||
for url in ${list[*]}
|
||||
do
|
||||
res=$(curl -s "${url}")
|
||||
if [ $? -eq 0 ];then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
res=$(echo "$res" | grep -Eo '[0-9\.]+')
|
||||
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
|
||||
}
|
||||
|
||||
|
|
@ -83,13 +91,14 @@ function pmdown ()
|
|||
|
||||
function mkcd ()
|
||||
{
|
||||
about 'make a directory and cd into it'
|
||||
param 'path to create'
|
||||
about 'make one or more directories and cd into the last one'
|
||||
param 'one or more directories to create'
|
||||
example '$ mkcd foo'
|
||||
example '$ mkcd /tmp/img/photos/large'
|
||||
example '$ mkcd foo foo1 foo2 fooN'
|
||||
example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
|
||||
group 'base'
|
||||
mkdir -p -- "$*"
|
||||
cd -- "$*"
|
||||
mkdir -p -- "$@" && eval cd -- "\"\$$#\""
|
||||
}
|
||||
|
||||
function lsgrep ()
|
||||
|
|
@ -136,7 +145,7 @@ function usage ()
|
|||
fi
|
||||
}
|
||||
|
||||
if [ ! -e $BASH_IT/plugins/enabled/todo.plugin.bash ]; then
|
||||
if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then
|
||||
# if user has installed todo plugin, skip this...
|
||||
function t ()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,14 +2,50 @@ cite about-plugin
|
|||
about-plugin 'display info about your battery charge level'
|
||||
|
||||
ac_adapter_connected(){
|
||||
if command_exists acpi;
|
||||
if _command_exists upower;
|
||||
then
|
||||
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'charging\|fully-charged'
|
||||
return $?
|
||||
elif _command_exists acpi;
|
||||
then
|
||||
acpi -a | grep -q "on-line"
|
||||
return $?
|
||||
elif command_exists ioreg;
|
||||
elif _command_exists pmset;
|
||||
then
|
||||
pmset -g batt | grep -q 'AC Power'
|
||||
return $?
|
||||
elif _command_exists ioreg;
|
||||
then
|
||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes'
|
||||
return $?
|
||||
elif _command_exists WMIC;
|
||||
then
|
||||
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2'
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
ac_adapter_disconnected(){
|
||||
if _command_exists upower;
|
||||
then
|
||||
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'discharging'
|
||||
return $?
|
||||
elif _command_exists acpi;
|
||||
then
|
||||
acpi -a | grep -q "off-line"
|
||||
return $?
|
||||
elif _command_exists pmset;
|
||||
then
|
||||
pmset -g batt | grep -q 'Battery Power'
|
||||
return $?
|
||||
elif _command_exists ioreg;
|
||||
then
|
||||
ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No'
|
||||
return $?
|
||||
elif _command_exists WMIC;
|
||||
then
|
||||
WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1'
|
||||
return $?
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -17,49 +53,31 @@ battery_percentage(){
|
|||
about 'displays battery charge as a percentage of full (100%)'
|
||||
group 'battery'
|
||||
|
||||
if 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 ioreg;
|
||||
if _command_exists upower;
|
||||
then
|
||||
# http://hints.macworld.com/article.php?story=20100130123935998
|
||||
#local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
|
||||
#local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}')
|
||||
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
|
||||
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
|
||||
elif _command_exists acpi;
|
||||
then
|
||||
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )
|
||||
elif _command_exists pmset;
|
||||
then
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)"
|
||||
|
|
@ -11,7 +11,7 @@ about-plugin 'directory stack navigation'
|
|||
# Show directory stack
|
||||
alias d="dirs -v -l"
|
||||
|
||||
# Change to location in stack bu number
|
||||
# Change to location in stack by number
|
||||
alias 1="pushd"
|
||||
alias 2="pushd +2"
|
||||
alias 3="pushd +3"
|
||||
|
|
@ -44,19 +44,19 @@ function dirs-help() {
|
|||
echo "po : Remove current location from stack."
|
||||
echo "pc : Adds current location to stack."
|
||||
echo "pu <dir>: Adds given location to stack."
|
||||
echo "1 : Chance to stack location 1."
|
||||
echo "2 : Chance to stack location 2."
|
||||
echo "3 : Chance to stack location 3."
|
||||
echo "4 : Chance to stack location 4."
|
||||
echo "5 : Chance to stack location 5."
|
||||
echo "6 : Chance to stack location 6."
|
||||
echo "7 : Chance to stack location 7."
|
||||
echo "8 : Chance to stack location 8."
|
||||
echo "9 : Chance to stack location 9."
|
||||
echo "1 : Change to stack location 1."
|
||||
echo "2 : Change to stack location 2."
|
||||
echo "3 : Change to stack location 3."
|
||||
echo "4 : Change to stack location 4."
|
||||
echo "5 : Change to stack location 5."
|
||||
echo "6 : Change to stack location 6."
|
||||
echo "7 : Change to stack location 7."
|
||||
echo "8 : Change to stack location 8."
|
||||
echo "9 : Change to stack location 9."
|
||||
}
|
||||
|
||||
# ADD BOOKMARKing functionality
|
||||
# usage:
|
||||
# Add bookmarking functionality
|
||||
# Usage:
|
||||
|
||||
if [ ! -f ~/.dirs ]; then # if doesn't exist, create it
|
||||
touch ~/.dirs
|
||||
|
|
@ -66,7 +66,7 @@ fi
|
|||
|
||||
alias L='cat ~/.dirs'
|
||||
|
||||
# goes to distination dir otherwise, stay in the dir
|
||||
# Goes to destination dir, otherwise stay in the dir
|
||||
G () {
|
||||
about 'goes to destination dir'
|
||||
param '1: directory'
|
||||
|
|
@ -102,6 +102,6 @@ R () {
|
|||
\mv ~/.dirs1 ~/.dirs;
|
||||
}
|
||||
|
||||
alias U='source ~/.dirs' # Update BOOKMARK stack
|
||||
# set the bash option so that no '$' is required when using the above facility
|
||||
alias U='source ~/.dirs' # Update bookmark stack
|
||||
# Set the Bash option so that no '$' is required when using the above facility
|
||||
shopt -s cdable_vars
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,20 @@ about-plugin 'Helpers to more easily work with Docker'
|
|||
function docker-remove-most-recent-container() {
|
||||
about 'attempt to remove the most recent container from docker ps -a'
|
||||
group 'docker'
|
||||
docker ps -a | head -2 | tail -1 | awk '{print $NF}' | xargs docker rm
|
||||
docker ps -ql | xargs docker rm
|
||||
}
|
||||
|
||||
function docker-remove-most-recent-image() {
|
||||
about 'attempt to remove the most recent image from docker images'
|
||||
group 'docker'
|
||||
docker images | head -2 | tail -1 | awk '{print $3}' | xargs docker rmi
|
||||
docker images -q | head -1 | xargs docker rmi
|
||||
}
|
||||
|
||||
function docker-remove-stale-assets() {
|
||||
about 'attempt to remove exited containers and dangling images'
|
||||
group 'docker'
|
||||
docker ps --filter status=exited -q | xargs docker rm --volumes
|
||||
docker images --filter dangling=true -q | xargs docker rmi
|
||||
}
|
||||
|
||||
function docker-enter() {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,41 @@
|
|||
# Load after the system completion to make sure that the fzf completions are working
|
||||
# BASH_IT_LOAD_PRIORITY: 375
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'load fzf, if you are using it'
|
||||
|
||||
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
|
||||
|
||||
fe() {
|
||||
about "Open the selected file in the default editor"
|
||||
group "fzf"
|
||||
param "1: Search term"
|
||||
example "fe foo"
|
||||
|
||||
local IFS=$'\n'
|
||||
local files
|
||||
files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
|
||||
[[ -n "$files" ]] && ${EDITOR:-vim} "${files[@]}"
|
||||
}
|
||||
|
||||
fd() {
|
||||
about "cd to the selected directory"
|
||||
group "fzf"
|
||||
param "1: Directory to browse, or . if omitted"
|
||||
example "fd aliases"
|
||||
|
||||
local dir
|
||||
dir=$(find ${1:-.} -path '*/\.*' -prune \
|
||||
-o -type d -print 2> /dev/null | fzf +m) &&
|
||||
cd "$dir"
|
||||
}
|
||||
|
||||
vf() {
|
||||
about "Use fasd to search the file to open in vim"
|
||||
group "fzf"
|
||||
param "1: Search term for fasd"
|
||||
example "vf xml"
|
||||
|
||||
local file
|
||||
file="$(fasd -Rfl "$1" | fzf -1 -0 --no-sort +m)" && vi "${file}" || return 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,34 +1,151 @@
|
|||
cite about-plugin
|
||||
about-plugin 'gif helper functions'
|
||||
about-plugin 'video to gif 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.'
|
||||
# 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)'
|
||||
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:" -o "a:l:w:f:dht" -- "$@")
|
||||
|
||||
local use_gifski=""
|
||||
local del_after=""
|
||||
local maxsize=""
|
||||
local lossiness=""
|
||||
local maxwidthski=""
|
||||
local giftagopt=""
|
||||
local giftag=""
|
||||
local defaultfps=10
|
||||
local infps=""
|
||||
local fps=""
|
||||
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
|
||||
;;
|
||||
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"
|
||||
local output_file="${file%.*}${giftag}.gif"
|
||||
|
||||
# Set FPS to match the video if possible, otherwise fallback to default.
|
||||
if [[ "$infps" ]] ; then
|
||||
fps=$infps
|
||||
else
|
||||
maxsize=""
|
||||
fps=$defaultfps
|
||||
if [[ -x /usr/bin/mediainfo ]] ; then
|
||||
if /usr/bin/mediainfo "$file" | grep -q "Frame rate mode *: Variable" ; then
|
||||
fps=$(/usr/bin/mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
||||
else
|
||||
fps=$(/usr/bin/mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
|
||||
fi
|
||||
fi
|
||||
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
|
||||
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)"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
# Bash-it no longer bundles nvm, as this was quickly becoming outdated.
|
||||
#
|
||||
# BASH_IT_LOAD_PRIORITY: 225
|
||||
#
|
||||
# Please install nvm from https://github.com/creationix/nvm.git if you want to use it.
|
||||
|
||||
cite about-plugin
|
||||
about-plugin 'node version manager configuration'
|
||||
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
export NVM_DIR=${NVM_DIR:-$HOME/.nvm}
|
||||
# This loads nvm
|
||||
if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ]
|
||||
then
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ if command -v percol>/dev/null; then
|
|||
bind -x '"\C-r": _replace_by_history'
|
||||
|
||||
# bind zz to percol if fasd enable
|
||||
unalias zz
|
||||
if command -v fasd>/dev/null; then
|
||||
function zz() {
|
||||
local l=$(fasd -d | awk '{print $2}' | percol)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ function pyedit() {
|
|||
example '$ pyedit requests'
|
||||
group 'python'
|
||||
|
||||
xpyc=`python -c "import sys; stdout = sys.stdout; sys.stdout = sys.stderr; import $1; stdout.write($1.__file__)"`
|
||||
xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"`
|
||||
|
||||
if [ "$xpyc" == "" ]; then
|
||||
echo "Python module $1 not found"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -1,18 +1,28 @@
|
|||
cite about-plugin
|
||||
about-plugin 'automatically set your xterm title with host and location info'
|
||||
|
||||
|
||||
_short-dirname () {
|
||||
local dir_name=`dirs -0`
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name
|
||||
}
|
||||
|
||||
_short-command () {
|
||||
local input_command="$@"
|
||||
[ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command
|
||||
}
|
||||
|
||||
set_xterm_title () {
|
||||
local title="$1"
|
||||
echo -ne "\033]0;$title\007"
|
||||
}
|
||||
|
||||
|
||||
precmd () {
|
||||
set_xterm_title "${USER}@${SHORT_HOSTNAME:-${HOSTNAME}} `dirs -0` $PROMPTCHAR"
|
||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `_short-dirname` $PROMPTCHAR"
|
||||
}
|
||||
|
||||
preexec () {
|
||||
set_xterm_title "$1 {`dirs -0`} (${USER}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
set_xterm_title "`_short-command $1` {`_short-dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||
}
|
||||
|
||||
case "$TERM" in
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ about-plugin ' z is DEPRECATED, use fasd instead'
|
|||
# * z -t foo # goes to most recently accessed dir matching foo
|
||||
# * z -l foo # list all dirs matching foo (by frecency)
|
||||
|
||||
if [ -e $BASH_IT/plugins/enabled/fasd.plugin.bash ]; then
|
||||
if [ -e "${BASH_IT}/plugins/enabled/fasd.plugin.bash" ] || [ -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}fasd.plugin.bash" ]; then
|
||||
printf '%s\n' 'sorry, the z plugin is incompatible with the fasd plugin. you may use either, but not both.'
|
||||
return
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -31,6 +31,15 @@ export SCM_CHECK=true
|
|||
# Will otherwise fall back on $HOSTNAME.
|
||||
#export SHORT_HOSTNAME=$(hostname -s)
|
||||
|
||||
# Set Xterm/screen/Tmux title with only a short username.
|
||||
# Uncomment this (or set SHORT_USER to something else),
|
||||
# Will otherwise fall back on $USER.
|
||||
#export SHORT_USER=${USER:0:8}
|
||||
|
||||
# Set Xterm/screen/Tmux title with shortened command and directory.
|
||||
# Uncomment this to set.
|
||||
#export SHORT_TERM_LINE=true
|
||||
|
||||
# Set vcprompt executable path for scm advance info in prompt (demula theme)
|
||||
# https://github.com/djl/vcprompt
|
||||
#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt
|
||||
|
|
@ -40,4 +49,4 @@ export SCM_CHECK=true
|
|||
# export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1
|
||||
|
||||
# Load Bash It
|
||||
source $BASH_IT/bash_it.sh
|
||||
source "$BASH_IT"/bash_it.sh
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
alias test_alias="a"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
alias test_alias="b"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
alias test_alias="c"
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
|
||||
# Determine which config file to use based on OS.
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
export BASH_IT_CONFIG_FILE=.bash_profile
|
||||
;;
|
||||
*)
|
||||
export BASH_IT_CONFIG_FILE=.bashrc
|
||||
;;
|
||||
esac
|
||||
|
||||
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
|
||||
|
||||
# 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 "install: verify that the install script exists" {
|
||||
assert_file_exist "$BASH_IT/install.sh"
|
||||
}
|
||||
|
||||
@test "install: run the install script silently" {
|
||||
cd "$BASH_IT"
|
||||
|
||||
./install.sh --silent
|
||||
|
||||
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
|
||||
|
||||
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" {
|
||||
cd "$BASH_IT"
|
||||
|
||||
touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
|
||||
echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
|
||||
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
./install.sh --silent
|
||||
|
||||
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}')
|
||||
|
||||
assert_equal "$md5_orig" "$md5_bak"
|
||||
}
|
||||
|
||||
@test "install: verify that silent and interactive can not be used at the same time" {
|
||||
cd "$BASH_IT"
|
||||
|
||||
run ./install.sh --silent --interactive
|
||||
|
||||
assert_failure
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
|
||||
# Determine which config file to use based on OS.
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
export BASH_IT_CONFIG_FILE=.bash_profile
|
||||
;;
|
||||
*)
|
||||
export BASH_IT_CONFIG_FILE=.bashrc
|
||||
;;
|
||||
esac
|
||||
|
||||
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
|
||||
|
||||
# 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 "uninstall: verify that the uninstall script exists" {
|
||||
assert_file_exist "$BASH_IT/uninstall.sh"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script with an existing backup file" {
|
||||
cd "$BASH_IT"
|
||||
|
||||
echo "test file content for backup" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak"
|
||||
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
|
||||
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
|
||||
|
||||
./uninstall.sh
|
||||
|
||||
assert_success
|
||||
|
||||
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}')
|
||||
|
||||
assert_equal "$md5_bak" "$md5_conf"
|
||||
}
|
||||
|
||||
@test "uninstall: run the uninstall script without an existing backup file" {
|
||||
cd "$BASH_IT"
|
||||
|
||||
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE"
|
||||
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
|
||||
|
||||
./uninstall.sh
|
||||
|
||||
assert_success
|
||||
|
||||
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}')
|
||||
|
||||
assert_equal "$md5_orig" "$md5_uninstall"
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
load ../../plugins/available/base.plugin
|
||||
|
||||
|
|
@ -7,4 +8,566 @@ cite _about _param _example _group _author _version
|
|||
|
||||
load ../../lib/helpers
|
||||
|
||||
## TODO: write some tests.
|
||||
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
|
||||
}
|
||||
|
||||
# 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 "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 -n 0 'todo.txt-cli enabled with priority 150.'
|
||||
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable the curl aliases" {
|
||||
run _enable-alias "curl"
|
||||
assert_line -n 0 'curl enabled with priority 150.'
|
||||
assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable the apm completion through the bash-it function" {
|
||||
run bash-it enable completion "apm"
|
||||
assert_line -n 0 'apm enabled with priority 350.'
|
||||
assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable the brew completion" {
|
||||
run _enable-completion "brew"
|
||||
assert_line -n 0 'brew enabled with priority 350.'
|
||||
assert_link_exist "$BASH_IT/enabled/350---brew.completion.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable the node plugin" {
|
||||
run _enable-plugin "node"
|
||||
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 "helpers: enable the node plugin through the bash-it function" {
|
||||
run bash-it enable plugin "node"
|
||||
assert_line -n 0 'node enabled with priority 250.'
|
||||
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable the node and nvm plugins through the bash-it function" {
|
||||
run bash-it enable plugin "node" "nvm"
|
||||
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 "helpers: enable the foo-unkown and nvm plugins through the bash-it function" {
|
||||
run bash-it enable plugin "foo-unknown" "nvm"
|
||||
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 "helpers: enable the nvm plugin" {
|
||||
run _enable-plugin "nvm"
|
||||
assert_line -n 0 'nvm enabled with priority 225.'
|
||||
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
|
||||
}
|
||||
|
||||
@test "helpers: enable an unknown plugin" {
|
||||
run _enable-plugin "unknown-foo"
|
||||
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 "helpers: enable an unknown plugin through the bash-it function" {
|
||||
run bash-it enable plugin "unknown-foo"
|
||||
echo "${lines[@]}"
|
||||
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 "helpers: disable a plugin that is not enabled" {
|
||||
run _disable-plugin "sdkman"
|
||||
assert_line -n 0 'sorry, sdkman does not appear to be an enabled plugin.'
|
||||
}
|
||||
|
||||
@test "helpers: enable and disable the nvm plugin" {
|
||||
run _enable-plugin "nvm"
|
||||
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 -n 0 'nvm disabled.'
|
||||
assert [ ! -L "$BASH_IT/enabled/225---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 -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 "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_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
|
||||
|
||||
run _enable-plugin "nvm"
|
||||
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 "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 -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 "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"
|
||||
|
||||
run _enable-plugin "nvm"
|
||||
assert_line -n 0 'nvm is already enabled.'
|
||||
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.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"
|
||||
|
||||
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_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 "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"
|
||||
|
||||
run _enable-plugin "ssh"
|
||||
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
|
||||
|
||||
run _bash-it-migrate
|
||||
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 "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_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
|
||||
|
||||
run bash-it enable plugin "node"
|
||||
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_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
|
||||
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
|
||||
}
|
||||
|
||||
@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_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_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
|
||||
|
||||
run bash-it disable plugin "node"
|
||||
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_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 "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/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
|
||||
assert_equal "$available" "$enabled"
|
||||
}
|
||||
|
||||
@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/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 "0" "$enabled2"
|
||||
assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash"
|
||||
}
|
||||
|
||||
@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 "helpers: describe the nvm plugin after enabling it" {
|
||||
run _enable-plugin "nvm"
|
||||
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 "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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
|
||||
load ../../lib/composure
|
||||
load ../../plugins/available/base.plugin
|
||||
|
||||
|
|
@ -10,44 +12,57 @@ load ../../lib/search
|
|||
|
||||
NO_COLOR=true
|
||||
|
||||
@test "helpers search aliases" {
|
||||
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
|
||||
}
|
||||
|
||||
@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 compoare the result
|
||||
# and we can compare the result
|
||||
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
|
||||
# Now perform the search
|
||||
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
|
||||
# And verify
|
||||
[[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \
|
||||
[[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto rails ruby' ]] && \
|
||||
[[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]]
|
||||
assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ]
|
||||
assert [ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto rails ruby' ]
|
||||
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'
|
||||
[[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \
|
||||
[[ "${lines[1]/✓/}" == ' plugins => rails ruby' ]] && \
|
||||
[[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]]
|
||||
assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ]
|
||||
assert [ "${lines[1]/✓/}" == ' plugins => rails ruby' ]
|
||||
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'
|
||||
[[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] && \
|
||||
[[ "${lines[1]}" == ' plugins => chruby chruby-auto rails ruby' ]] && \
|
||||
[[ "${lines[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'
|
||||
[[ "${lines[0]}" == ' aliases => ✓bundler ✓rails' ]] && \
|
||||
[[ "${lines[1]}" == ' plugins => ✓rails ✓ruby' ]] && \
|
||||
[[ "${lines[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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
[[ -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}" ]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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 ]]
|
||||
}
|
||||
|
|
|
|||
17
test/run
17
test/run
|
|
@ -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}/{lib,plugins}
|
||||
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[@]}"
|
||||
|
|
|
|||
|
|
@ -13,84 +13,74 @@ 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
|
||||
}
|
||||
|
||||
local_teardown() {
|
||||
true
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p -- "${BASH_IT_ROOT}"
|
||||
|
||||
local_setup
|
||||
}
|
||||
|
||||
teardown() {
|
||||
local_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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
load ../test_helper
|
||||
load ../../lib/composure
|
||||
|
||||
cite _about _param _example _group _author _version
|
||||
|
||||
load ../../lib/helpers
|
||||
load ../../themes/base.theme
|
||||
|
||||
@test 'themes base: battery_percentage should not exist' {
|
||||
run type -a battery_percentage &> /dev/null
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test 'themes base: battery_percentage should exist if battery plugin loaded' {
|
||||
load ../../plugins/available/battery.plugin
|
||||
|
||||
run type -a battery_percentage &> /dev/null
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test 'themes base: battery_char should exist' {
|
||||
run type -a battery_char &> /dev/null
|
||||
assert_success
|
||||
|
||||
run battery_char
|
||||
assert_success
|
||||
assert_line -n 0 ""
|
||||
|
||||
run type -a battery_char
|
||||
assert_line " echo -n"
|
||||
}
|
||||
|
||||
@test 'themes base: battery_char should exist if battery plugin loaded' {
|
||||
unset -f battery_char
|
||||
load ../../plugins/available/battery.plugin
|
||||
load ../../themes/base.theme
|
||||
|
||||
run type -a battery_char &> /dev/null
|
||||
assert_success
|
||||
|
||||
run battery_char
|
||||
assert_success
|
||||
|
||||
run type -a battery_char
|
||||
assert_line ' if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then'
|
||||
}
|
||||
|
||||
@test 'themes base: battery_charge should exist' {
|
||||
run type -a battery_charge &> /dev/null
|
||||
assert_success
|
||||
|
||||
run battery_charge
|
||||
assert_success
|
||||
assert_line -n 0 ""
|
||||
}
|
||||
|
||||
@test 'themes base: battery_charge should exist if battery plugin loaded' {
|
||||
unset -f battery_charge
|
||||
load ../../plugins/available/battery.plugin
|
||||
load ../../themes/base.theme
|
||||
|
||||
run type -a battery_charge &> /dev/null
|
||||
assert_success
|
||||
|
||||
run battery_charge
|
||||
assert_success
|
||||
|
||||
run type -a battery_charge
|
||||
assert_line ' no)'
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 9f88b4207da750093baabc4e3f41bf68f0dd3630
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 85388685632f85d5a1c32e6bca2deec401964cf7
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 2fddb2b831d65cdf2e411f3b47f4677fbb15729c
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 004e707638eedd62e0481e8cdc9223ad471f12ee
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env bash
|
||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||
SCM_THEME_PROMPT_PREFIX=" |"
|
||||
SCM_THEME_PROMPT_SUFFIX="${green}|"
|
||||
|
||||
GIT_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||
GIT_THEME_PROMPT_PREFIX=" ${green}|"
|
||||
GIT_THEME_PROMPT_SUFFIX="${green}|"
|
||||
|
||||
# Nicely formatted terminal prompt
|
||||
function prompt_command(){
|
||||
export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ "
|
||||
}
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
# Atomic theme
|
||||
|
||||
The Best ColorFull terminal prompt theme inspired by a number of themes and based on the theme of @MunifTanjim [`brainy`](../brainy/README.md).
|
||||
|
||||
Supported on all operating systems.
|
||||
|
||||
In constant maintenance and improvement
|
||||
|
||||

|
||||
|
||||
## Install Theme
|
||||
|
||||
### Manually
|
||||
|
||||
You can install the theme manually by following these steps:
|
||||
Edit your modified config `~/.bashrc` file in order to customize Bash-it, set `BASH_IT_THEME` to the theme name `atomic`.
|
||||
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
# Use the "atomic" theme
|
||||
export BASH_IT_THEME="atomic"
|
||||
```
|
||||
|
||||
### Automatically via terminal
|
||||
|
||||
1. You can install the theme automatically using the `sed` command from your Linux or OSX Terminal.
|
||||
2. On macOS, the ~/.bash_profile is used, not the ~/.bashrc.
|
||||
3. For installation on windows you should use [`Git-Bash`](https://git-for-windows.github.io/) or make sure the terminal emulator you use (ej: cygwin, mintty, etc) has the `sed` command installed.
|
||||
|
||||
Command to execute For Windows and Linux:
|
||||
```bash
|
||||
# Set the "atomic" theme replacing the theme you are using of bash-it
|
||||
sed -i 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bashrc
|
||||
```
|
||||
Command to execute for macOS:
|
||||
```bash
|
||||
# Set the "atomic" theme replacing the theme you are using of bash-it
|
||||
sed -i '' 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bash_profile
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
### Prompt Segments
|
||||
|
||||
- Username & Hostname
|
||||
- Current Directory
|
||||
- SCM Information
|
||||
- Battery Charge
|
||||
- Clock
|
||||
- [Todo.txt](https://github.com/ginatrapani/todo.txt-cli) status
|
||||
- Ruby Environment
|
||||
- Python Environment
|
||||
- Exit Code
|
||||
|
||||
### Others
|
||||
|
||||
- Indicator for cached `sudo` credential
|
||||
- Indicator for abort (ctrl + C) the current task and regain user control
|
||||
- `atomic` command for showing/hiding various prompt segments on-the-fly
|
||||
|
||||
## Configuration
|
||||
|
||||
Various prompt segments can be shown/hidden or modified according to your choice. There are two ways for doing that:
|
||||
|
||||
1. On-the-fly using `atomic` command
|
||||
2. Theme Environment Variables
|
||||
|
||||
### On-the-fly using `atomic` command
|
||||
|
||||
This theme provides a command for showing/hiding prompt segments.
|
||||
|
||||
`atomic show <segment>`
|
||||
|
||||
`atomic hide <segment>`
|
||||
|
||||
Tab-completion for this command is enabled by default.
|
||||
|
||||
Configuration specified by this command will only be applied to current and subsequent child shells.
|
||||
|
||||
### Theme Environment Variables
|
||||
|
||||
This is used for permanent settings that apply to all terminal sessions. You have to define the value of specific theme variables in your `bashrc` (or equivalent) file.
|
||||
|
||||
The name of the variables are listed below along with their default values.
|
||||
|
||||
#### User Information
|
||||
|
||||
Indicator for cached `sudo` credential (see `sudo` manpage for more information):
|
||||
|
||||
`THEME_SHOW_SUDO=true`
|
||||
|
||||
#### SCM Information
|
||||
|
||||
Information about SCM repository status:
|
||||
|
||||
`THEME_SHOW_SCM=true`
|
||||
|
||||
#### Ruby Environment
|
||||
|
||||
Ruby environment version information:
|
||||
|
||||
`THEME_SHOW_RUBY=false`
|
||||
|
||||
#### Python Environment
|
||||
|
||||
Python environment version information:
|
||||
|
||||
`THEME_SHOW_PYTHON=false`
|
||||
|
||||
#### ToDo.txt status
|
||||
|
||||
[Todo.txt](https://github.com/ginatrapani/todo.txt-cli) status:
|
||||
|
||||
`THEME_SHOW_TODO=false`
|
||||
|
||||
#### Clock
|
||||
|
||||
`THEME_SHOW_CLOCK=true`
|
||||
|
||||
`THEME_CLOCK_COLOR=$bold_cyan`
|
||||
|
||||
Format of the clock (see `date` manpage for more information):
|
||||
|
||||
`THEME_CLOCK_FORMAT="%H:%M:%S"`
|
||||
|
||||
#### Battery Charge
|
||||
|
||||
Battery charge percentage:
|
||||
|
||||
`THEME_SHOW_BATTERY=false`
|
||||
|
||||
#### Exit Code
|
||||
|
||||
Exit code of the last command:
|
||||
|
||||
`THEME_SHOW_EXITCODE=true`
|
||||
|
||||
## Prompt Segments Order
|
||||
|
||||
Currently available prompt segments are:
|
||||
|
||||
- battery
|
||||
- char
|
||||
- clock
|
||||
- dir
|
||||
- exitcode
|
||||
- python
|
||||
- ruby
|
||||
- scm
|
||||
- todo
|
||||
- user_info
|
||||
|
||||
Three environment variables can be defined to rearrange the segments order. The default values are:
|
||||
|
||||
`___ATOMIC_TOP_LEFT="user_info dir scm"`
|
||||
|
||||
`___ATOMIC_TOP_RIGHT="exitcode python ruby todo clock battery"`
|
||||
|
||||
`___ATOMIC_BOTTOM="char"`
|
||||
|
||||
### Development by
|
||||
|
||||
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.
|
||||
|
|
@ -0,0 +1,320 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Atomic Bash Prompt for Bash-it
|
||||
# By lfelipe base on the theme brainy of MunifTanjim
|
||||
|
||||
############
|
||||
## Colors ##
|
||||
############
|
||||
IRed="\e[1;49;31m"
|
||||
IGreen="\e[1;49;32m"
|
||||
IYellow="\e[1;49;33m"
|
||||
IWhite="\e[1;49;37m"
|
||||
BIWhite="\e[1;49;37m"
|
||||
BICyan="\e[1;49;36m"
|
||||
|
||||
#############
|
||||
## Symbols ##
|
||||
#############
|
||||
Line="\342\224\200"
|
||||
LineA="\342\224\214\342\224\200"
|
||||
SX="\342\234\227"
|
||||
LineB="\342\224\224\342\224\200\342\224\200"
|
||||
Circle="\342\227\217"
|
||||
Face="\342\230\273"
|
||||
|
||||
#############
|
||||
## Parsers ##
|
||||
#############
|
||||
|
||||
____atomic_top_left_parse() {
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
args=( $1 )
|
||||
IFS="${ifs_old}"
|
||||
if [ -n "${args[3]}" ]; then
|
||||
_TOP_LEFT+="${args[2]}${args[3]}"
|
||||
fi
|
||||
_TOP_LEFT+="${args[0]}${args[1]}"
|
||||
if [ -n "${args[4]}" ]; then
|
||||
_TOP_LEFT+="${args[2]}${args[4]}"
|
||||
fi
|
||||
_TOP_LEFT+=""
|
||||
}
|
||||
|
||||
____atomic_top_right_parse() {
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
args=( $1 )
|
||||
IFS="${ifs_old}"
|
||||
_TOP_RIGHT+=" "
|
||||
if [ -n "${args[3]}" ]; then
|
||||
_TOP_RIGHT+="${args[2]}${args[3]}"
|
||||
fi
|
||||
_TOP_RIGHT+="${args[0]}${args[1]}"
|
||||
if [ -n "${args[4]}" ]; then
|
||||
_TOP_RIGHT+="${args[2]}${args[4]}"
|
||||
fi
|
||||
__TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN + ${#args[1]} + ${#args[3]} + ${#args[4]} + 1 ))
|
||||
(( __SEG_AT_RIGHT += 1 ))
|
||||
}
|
||||
|
||||
____atomic_bottom_parse() {
|
||||
ifs_old="${IFS}"
|
||||
IFS="|"
|
||||
args=( $1 )
|
||||
IFS="${ifs_old}"
|
||||
_BOTTOM+="${args[0]}${args[1]}"
|
||||
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
||||
}
|
||||
|
||||
____atomic_top() {
|
||||
_TOP_LEFT=""
|
||||
_TOP_RIGHT=""
|
||||
__TOP_RIGHT_LEN=0
|
||||
__SEG_AT_RIGHT=0
|
||||
|
||||
for seg in ${___ATOMIC_TOP_LEFT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_left_parse "${info}"
|
||||
done
|
||||
|
||||
___cursor_right="\e[500C"
|
||||
_TOP_LEFT+="${___cursor_right}"
|
||||
|
||||
for seg in ${___ATOMIC_TOP_RIGHT}; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_top_right_parse "${info}"
|
||||
done
|
||||
|
||||
[ $__TOP_RIGHT_LEN -gt 0 ] && __TOP_RIGHT_LEN=$(( __TOP_RIGHT_LEN - 0 ))
|
||||
___cursor_adjust="\e[${__TOP_RIGHT_LEN}D"
|
||||
_TOP_LEFT+="${___cursor_adjust}"
|
||||
|
||||
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
||||
}
|
||||
|
||||
____atomic_bottom() {
|
||||
_BOTTOM=""
|
||||
for seg in $___ATOMIC_BOTTOM; do
|
||||
info="$(___atomic_prompt_"${seg}")"
|
||||
[ -n "${info}" ] && ____atomic_bottom_parse "${info}"
|
||||
done
|
||||
printf "\n%s" "${_BOTTOM}"
|
||||
}
|
||||
|
||||
##############
|
||||
## Segments ##
|
||||
##############
|
||||
|
||||
___atomic_prompt_user_info() {
|
||||
color=$white
|
||||
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
|
||||
info="${IYellow}\u${IRed}@${IGreen}\h"
|
||||
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_dir() {
|
||||
color=${IRed}
|
||||
box="[|]${normal}${Line}"
|
||||
info="\w"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_scm() {
|
||||
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
||||
color=$bold_green
|
||||
box="[${IWhite}$(scm_char)] "
|
||||
info="$(scm_prompt_info)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_python() {
|
||||
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
||||
color=$bold_yellow
|
||||
box="[|]"
|
||||
info="$(python_version_prompt)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_ruby() {
|
||||
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
||||
color=$bold_white
|
||||
box="[|]"
|
||||
info="rb-$(ruby_version_prompt)"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_todo() {
|
||||
[ "${THEME_SHOW_TODO}" != "true" ] ||
|
||||
[ -z "$(which todo.sh)" ] && return
|
||||
color=$bold_white
|
||||
box="[|]"
|
||||
info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_clock() {
|
||||
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
||||
color=$THEME_CLOCK_COLOR
|
||||
box="[|]"
|
||||
info="$(date +"${THEME_CLOCK_FORMAT}")"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_battery() {
|
||||
! _command_exists battery_percentage ||
|
||||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
|
||||
[ "$(battery_percentage)" = "no" ] && return
|
||||
|
||||
batp=$(battery_percentage)
|
||||
if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then
|
||||
color=$bold_green
|
||||
elif [ "$batp" -lt 50 ] && [ "$batp" -gt 25 ]; then
|
||||
color=$bold_yellow
|
||||
elif [ "$batp" -eq 25 ] || [ "$batp" -lt 25 ]; then
|
||||
color=$IRed
|
||||
fi
|
||||
box="[|]"
|
||||
ac_adapter_connected && info="+"
|
||||
ac_adapter_disconnected && info="-"
|
||||
info+=$batp
|
||||
[ "$batp" -eq 100 ] || [ "$batp" -gt 100 ] && info="AC"
|
||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||
}
|
||||
|
||||
___atomic_prompt_exitcode() {
|
||||
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
||||
color=$bold_purple
|
||||
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
||||
}
|
||||
|
||||
___atomic_prompt_char() {
|
||||
color=$white
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
|
||||
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
||||
if [ $(sudo -n id -u 2>&1 | grep 0) ]; then
|
||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1_SUDO}"
|
||||
fi
|
||||
fi
|
||||
printf "%s|%s" "${color}" "${prompt_char}"
|
||||
}
|
||||
|
||||
#########
|
||||
## cli ##
|
||||
#########
|
||||
|
||||
__atomic_show() {
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export THEME_SHOW_${_seg}=true
|
||||
}
|
||||
|
||||
__atomic_hide() {
|
||||
typeset _seg=${1:-}
|
||||
shift
|
||||
export THEME_SHOW_${_seg}=false
|
||||
}
|
||||
|
||||
_atomic_completion() {
|
||||
local cur _action actions segments
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
_action="${COMP_WORDS[1]}"
|
||||
actions="show hide"
|
||||
segments="battery clock exitcode python ruby scm sudo todo"
|
||||
case "${_action}" in
|
||||
show)
|
||||
COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
hide)
|
||||
COMPREPLY=( $(compgen -W "${segments}" -- "${cur}") )
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
COMPREPLY=( $(compgen -W "${actions}" -- "${cur}") )
|
||||
return 0
|
||||
}
|
||||
|
||||
atomic() {
|
||||
typeset action=${1:-}
|
||||
shift
|
||||
typeset segs=${*:-}
|
||||
typeset func
|
||||
case $action in
|
||||
show)
|
||||
func=__atomic_show;;
|
||||
hide)
|
||||
func=__atomic_hide;;
|
||||
esac
|
||||
for seg in ${segs}; do
|
||||
seg=$(printf "%s" "${seg}" | tr '[:lower:]' '[:upper:]')
|
||||
$func "${seg}"
|
||||
done
|
||||
}
|
||||
|
||||
complete -F _atomic_completion atomic
|
||||
|
||||
###############
|
||||
## Variables ##
|
||||
###############
|
||||
|
||||
export SCM_THEME_PROMPT_PREFIX=""
|
||||
export SCM_THEME_PROMPT_SUFFIX=""
|
||||
|
||||
export RBENV_THEME_PROMPT_PREFIX=""
|
||||
export RBENV_THEME_PROMPT_SUFFIX=""
|
||||
export RBFU_THEME_PROMPT_PREFIX=""
|
||||
export RBFU_THEME_PROMPT_SUFFIX=""
|
||||
export RVM_THEME_PROMPT_PREFIX=""
|
||||
export RVM_THEME_PROMPT_SUFFIX=""
|
||||
|
||||
export SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗${normal}"
|
||||
export SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}"
|
||||
|
||||
THEME_SHOW_SUDO=${THEME_SHOW_SUDO:-"true"}
|
||||
THEME_SHOW_SCM=${THEME_SHOW_SCM:-"true"}
|
||||
THEME_SHOW_RUBY=${THEME_SHOW_RUBY:-"false"}
|
||||
THEME_SHOW_PYTHON=${THEME_SHOW_PYTHON:-"false"}
|
||||
THEME_SHOW_CLOCK=${THEME_SHOW_CLOCK:-"true"}
|
||||
THEME_SHOW_TODO=${THEME_SHOW_TODO:-"false"}
|
||||
THEME_SHOW_BATTERY=${THEME_SHOW_BATTERY:-"true"}
|
||||
THEME_SHOW_EXITCODE=${THEME_SHOW_EXITCODE:-"false"}
|
||||
|
||||
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"${BICyan}"}
|
||||
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%a %b %d - %H:%M"}
|
||||
|
||||
__ATOMIC_PROMPT_CHAR_PS1=${THEME_PROMPT_CHAR_PS1:-"${normal}${LineB}${bold_white}${Circle}"}
|
||||
__ATOMIC_PROMPT_CHAR_PS2=${THEME_PROMPT_CHAR_PS2:-"${normal}${LineB}${bold_white}${Circle}"}
|
||||
|
||||
__ATOMIC_PROMPT_CHAR_PS1_SUDO=${THEME_PROMPT_CHAR_PS1_SUDO:-"${normal}${LineB}${bold_red}${Face}"}
|
||||
__ATOMIC_PROMPT_CHAR_PS2_SUDO=${THEME_PROMPT_CHAR_PS2_SUDO:-"${normal}${LineB}${bold_red}${Face}"}
|
||||
|
||||
___ATOMIC_TOP_LEFT=${___ATOMIC_TOP_LEFT:-"user_info dir scm"}
|
||||
___ATOMIC_TOP_RIGHT=${___ATOMIC_TOP_RIGHT:-"exitcode python ruby todo clock battery"}
|
||||
___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"}
|
||||
|
||||
############
|
||||
## Prompt ##
|
||||
############
|
||||
|
||||
__atomic_ps1() {
|
||||
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
|
||||
}
|
||||
|
||||
__atomic_ps2() {
|
||||
color=$bold_white
|
||||
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
|
||||
}
|
||||
|
||||
_atomic_prompt() {
|
||||
exitcode="$?"
|
||||
|
||||
PS1="$(__atomic_ps1)"
|
||||
PS2="$(__atomic_ps2)"
|
||||
}
|
||||
|
||||
safe_append_prompt_command _atomic_prompt
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function prompt_command() {
|
|||
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
|
||||
#PS1="\n${purple}\h: ${reset_color} ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} "
|
||||
#PS1="\n${cyan}\h: ${reset_color} ${yellow}\w\n${red}$(scm_char)${red}$(scm_prompt_info) ${green}→${reset_color} "
|
||||
PS1="\n${cyan}\h: ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}→ "
|
||||
PS1="\n${cyan}\h:$(virtualenv_prompt) ${reset_color} ${yellow}\w ${green}$(scm_prompt_info)\n${reset_color}→ "
|
||||
}
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ SCM_THEME_BRANCH_TRACK_PREFIX=' → '
|
|||
SCM_THEME_BRANCH_GONE_PREFIX=' ⇢ '
|
||||
SCM_THEME_CURRENT_USER_PREFFIX=' ☺︎ '
|
||||
SCM_THEME_CURRENT_USER_SUFFIX=''
|
||||
SCM_THEME_CHAR_PREFIX=''
|
||||
SCM_THEME_CHAR_SUFFIX=''
|
||||
|
||||
THEME_BATTERY_PERCENTAGE_CHECK=${THEME_BATTERY_PERCENTAGE_CHECK:=true}
|
||||
|
||||
|
|
@ -37,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='☿'
|
||||
|
|
@ -50,6 +54,10 @@ SCM_NONE_CHAR='○'
|
|||
RVM_THEME_PROMPT_PREFIX=' |'
|
||||
RVM_THEME_PROMPT_SUFFIX='|'
|
||||
|
||||
THEME_SHOW_USER_HOST=${THEME_SHOW_USER_HOST:=false}
|
||||
USER_HOST_THEME_PROMPT_PREFIX=''
|
||||
USER_HOST_THEME_PROMPT_SUFFIX=''
|
||||
|
||||
VIRTUALENV_THEME_PROMPT_PREFIX=' |'
|
||||
VIRTUALENV_THEME_PROMPT_SUFFIX='|'
|
||||
|
||||
|
|
@ -92,6 +100,16 @@ function scm_prompt_vars {
|
|||
function scm_prompt_info {
|
||||
scm
|
||||
scm_prompt_char
|
||||
scm_prompt_info_common
|
||||
}
|
||||
|
||||
function scm_prompt_char_info {
|
||||
scm_prompt_char
|
||||
echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
||||
scm_prompt_info_common
|
||||
}
|
||||
|
||||
function scm_prompt_info_common {
|
||||
SCM_DIRTY=0
|
||||
SCM_STATE=''
|
||||
|
||||
|
|
@ -111,6 +129,15 @@ function scm_prompt_info {
|
|||
[[ ${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
|
||||
|
|
@ -119,9 +146,9 @@ function git_prompt_minimal_info {
|
|||
|
||||
if [[ "$(command git config --get bash-it.hide-status)" != "1" ]]; then
|
||||
# Get the branch reference
|
||||
ref=$(command git symbolic-ref -q HEAD 2> /dev/null) || \
|
||||
ref=$(git_clean_branch) || \
|
||||
ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
|
||||
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref#refs/heads/}
|
||||
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref}
|
||||
|
||||
# Get the status
|
||||
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags+='-untracked-files=no'
|
||||
|
|
@ -195,10 +222,11 @@ function git_prompt_vars {
|
|||
|
||||
SCM_CHANGE=$(git rev-parse --short HEAD 2>/dev/null)
|
||||
|
||||
local ref=$(git symbolic-ref -q HEAD 2> /dev/null)
|
||||
local ref=$(git_clean_branch)
|
||||
|
||||
if [[ -n "$ref" ]]; then
|
||||
SCM_BRANCH=${SCM_THEME_BRANCH_PREFIX}${ref#refs/heads/}
|
||||
local tracking_info="$(grep "${SCM_BRANCH}\.\.\." <<< "${status}")"
|
||||
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}...}
|
||||
|
|
@ -245,7 +273,7 @@ function git_prompt_vars {
|
|||
[[ "${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}}"
|
||||
[[ "${stash_count}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_STASH_CHAR_PREFIX}${stash_count}${SCM_GIT_STASH_CHAR_SUFFIX}"
|
||||
|
||||
SCM_BRANCH+=${details}
|
||||
|
||||
|
|
@ -348,7 +376,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,25 +439,31 @@ function clock_prompt {
|
|||
fi
|
||||
}
|
||||
|
||||
function user_host_prompt {
|
||||
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
|
||||
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
|
||||
fi
|
||||
}
|
||||
|
||||
# backwards-compatibility
|
||||
function git_prompt_info {
|
||||
git_prompt_vars
|
||||
echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX"
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
||||
function svn_prompt_info {
|
||||
svn_prompt_vars
|
||||
echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX"
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
||||
function hg_prompt_info() {
|
||||
hg_prompt_vars
|
||||
echo -e "$SCM_PREFIX$SCM_BRANCH:${SCM_CHANGE#*:}$SCM_STATE$SCM_SUFFIX"
|
||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
|
||||
}
|
||||
|
||||
function scm_char {
|
||||
scm_prompt_char
|
||||
echo -e "$SCM_CHAR"
|
||||
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
||||
}
|
||||
|
||||
function prompt_char {
|
||||
|
|
@ -442,13 +476,17 @@ function battery_char {
|
|||
fi
|
||||
}
|
||||
|
||||
if [ ! -e $BASH_IT/plugins/enabled/battery.plugin.bash ]; then
|
||||
if ! _command_exists battery_charge ; then
|
||||
# if user has installed battery plugin, skip this...
|
||||
function battery_charge (){
|
||||
# no op
|
||||
echo -n
|
||||
}
|
||||
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
|
||||
function battery_char (){
|
||||
# no op
|
||||
echo -n
|
||||
|
|
@ -463,12 +501,40 @@ 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 {
|
||||
if [[ -n $1 ]] ; then
|
||||
case $PROMPT_COMMAND in
|
||||
*$1*) ;;
|
||||
"") PROMPT_COMMAND="$1";;
|
||||
*) PROMPT_COMMAND="$1;$PROMPT_COMMAND";;
|
||||
esac
|
||||
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
|
||||
prompt_re="[[:<:]]${1}[[:>:]]"
|
||||
else
|
||||
# Linux, FreeBSD, etc.
|
||||
prompt_re="\<${1}\>"
|
||||
fi
|
||||
|
||||
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
|
||||
return
|
||||
elif [[ -z ${PROMPT_COMMAND} ]]; then
|
||||
PROMPT_COMMAND="${1}"
|
||||
else
|
||||
PROMPT_COMMAND="${1};${PROMPT_COMMAND}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||
SCM_THEME_PROMPT_PREFIX=" |"
|
||||
SCM_THEME_PROMPT_PREFIX=" ${green}|"
|
||||
SCM_THEME_PROMPT_SUFFIX="${green}|"
|
||||
|
||||
GIT_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
|
|
@ -23,7 +23,7 @@ __bobby_clock() {
|
|||
|
||||
function prompt_command() {
|
||||
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
|
||||
PS1="\n$(battery_char) $(__bobby_clock)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} "
|
||||
PS1="\n$(battery_char) $(__bobby_clock)${yellow}$(ruby_version_prompt) ${purple}\h ${reset_color}in ${green}\w\n${bold_cyan}$(scm_prompt_char_info) ${green}→${reset_color} "
|
||||
}
|
||||
|
||||
THEME_SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
|
||||
|
|
|
|||
|
|
@ -152,8 +152,10 @@ ___brainy_prompt_clock() {
|
|||
}
|
||||
|
||||
___brainy_prompt_battery() {
|
||||
[ ! -e $BASH_IT/plugins/enabled/battery.plugin.bash ] ||
|
||||
[ "${THEME_SHOW_BATTERY}" != "true" ] && return
|
||||
! _command_exists battery_percentage ||
|
||||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
|
||||
[ "$(battery_percentage)" = "no" ] && return
|
||||
|
||||
info=$(battery_percentage)
|
||||
color=$bold_green
|
||||
if [ "$info" -lt 50 ]; then
|
||||
|
|
@ -162,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}"
|
||||
}
|
||||
|
|
@ -249,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}"
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ yellow="\[\e[0;33m\]"
|
|||
blue="\[\e[0;34m\]"
|
||||
purple="\[\e[0;35m\]"
|
||||
cyan="\[\e[0;36m\]"
|
||||
white="\[\e[0;37;1m\]"
|
||||
white="\[\e[0;37m\]"
|
||||
orange="\[\e[0;91m\]"
|
||||
|
||||
bold_black="\[\e[30;1m\]"
|
||||
|
|
|
|||
|
|
@ -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 [ -e "${BASH_IT}/plugins/enabled/battery.plugin.bash" ];
|
||||
if _command_exists battery_charge ;
|
||||
then
|
||||
battery_charge
|
||||
fi
|
||||
|
|
@ -127,4 +127,3 @@ ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}"
|
|||
|
||||
# Runs prompt (this bypasses bash_it $PROMPT setting)
|
||||
safe_append_prompt_command prompt
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# One line prompt showing the following configurable information
|
||||
# for git:
|
||||
# time (virtual_env) username@hostname pwd git_char|git_branch git_dirty_status|→
|
||||
#
|
||||
# The → arrow shows the exit status of the last command:
|
||||
# - bold green: 0 exit status
|
||||
# - bold red: non-zero exit status
|
||||
#
|
||||
# Example outside git repo:
|
||||
# 07:45:05 user@host ~ →
|
||||
#
|
||||
# Example inside clean git repo:
|
||||
# 07:45:05 user@host .bash_it ±|master|→
|
||||
#
|
||||
# Example inside dirty git repo:
|
||||
# 07:45:05 user@host .bash_it ±|master ✗|→
|
||||
#
|
||||
# Example with virtual environment:
|
||||
# 07:45:05 (venv) user@host ~ →
|
||||
#
|
||||
|
||||
SCM_NONE_CHAR=''
|
||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||
SCM_THEME_PROMPT_CLEAN=""
|
||||
SCM_THEME_PROMPT_PREFIX="${green}|"
|
||||
SCM_THEME_PROMPT_SUFFIX="${green}|"
|
||||
SCM_GIT_SHOW_MINIMAL_INFO=true
|
||||
|
||||
CLOCK_THEME_PROMPT_PREFIX=''
|
||||
CLOCK_THEME_PROMPT_SUFFIX=' '
|
||||
THEME_SHOW_CLOCK=false
|
||||
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$bold_blue"}
|
||||
THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%I:%M:%S"}
|
||||
|
||||
THEME_SHOW_USER_HOST=true
|
||||
USER_HOST_THEME_PROMPT_PREFIX="${bold_black}"
|
||||
USER_HOST_THEME_PROMPT_SUFFIX=" "
|
||||
|
||||
VIRTUALENV_THEME_PROMPT_PREFIX='('
|
||||
VIRTUALENV_THEME_PROMPT_SUFFIX=') '
|
||||
|
||||
function prompt_command() {
|
||||
# This needs to be first to save last command return code
|
||||
local RC="$?"
|
||||
|
||||
hostname="${bold_black}\u@\h"
|
||||
virtualenv="${white}$(virtualenv_prompt)"
|
||||
|
||||
# Set return status color
|
||||
if [[ ${RC} == 0 ]]; then
|
||||
ret_status="${bold_green}"
|
||||
else
|
||||
ret_status="${bold_red}"
|
||||
fi
|
||||
|
||||
# Append new history lines to history file
|
||||
history -a
|
||||
|
||||
PS1="$(clock_prompt)${virtualenv}$(user_host_prompt)${bold_cyan}\W $(scm_prompt_char_info)${ret_status}→ ${normal}"
|
||||
}
|
||||
|
||||
safe_append_prompt_command prompt_command
|
||||
|
|
@ -52,7 +52,7 @@ function prompt_command() {
|
|||
fi
|
||||
|
||||
local wrap_char=""
|
||||
[[ ${#new_PS1} -gt $(($COLUMNS/1)) ]] && wrap_char="\n"
|
||||
[[ $COLUMNS && ${#new_PS1} > $(($COLUMNS/1)) ]] && wrap_char="\n"
|
||||
PS1="${new_PS1}${green}${wrap_char}→${reset_color} "
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
liquidprompt
|
||||
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env bash
|
||||
# Wrapper to use liquidprompt with bashit
|
||||
|
||||
targetdir="$BASH_IT/themes/liquidprompt/liquidprompt"
|
||||
gray="\[\e[1;90m\]"
|
||||
|
||||
cwd="$PWD"
|
||||
if cd "$targetdir" &>/dev/null && git rev-parse --is-inside-work-tree &>/dev/null; then
|
||||
true
|
||||
else
|
||||
git clone https://github.com/nojhan/liquidprompt.git "$targetdir" && \
|
||||
echo -e "Successfully cloned liquidprompt!\n More configuration in '$targetdir/liquid.theme'."
|
||||
fi
|
||||
cd "$cwd"
|
||||
|
||||
export LP_ENABLE_TIME=1
|
||||
export LP_HOSTNAME_ALWAYS=1
|
||||
export LP_USER_ALWAYS=1
|
||||
export LP_MARK_LOAD="📈 "
|
||||
export LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
|
||||
export LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
|
||||
export LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80}
|
||||
|
||||
|
||||
source "$targetdir/liquidprompt"
|
||||
prompt() { true; }
|
||||
export PS2=" ┃ "
|
||||
export LP_PS1_PREFIX="┌─"
|
||||
export LP_PS1_POSTFIX="\n└▪ "
|
||||
export LP_ENABLE_RUNTIME=0
|
||||
|
||||
_lp_git_branch()
|
||||
{
|
||||
(( LP_ENABLE_GIT )) || return
|
||||
|
||||
\git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return
|
||||
|
||||
local branch
|
||||
# Recent versions of Git support the --short option for symbolic-ref, but
|
||||
# not 1.7.9 (Ubuntu 12.04)
|
||||
if branch="$(\git symbolic-ref -q HEAD)"; then
|
||||
_lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}"
|
||||
else
|
||||
# In detached head state, use commit instead
|
||||
# No escape needed
|
||||
\git rev-parse --short -q HEAD 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
_lp_time() {
|
||||
if (( LP_ENABLE_TIME )) && (( ! LP_TIME_ANALOG )); then
|
||||
LP_TIME="${gray}$(date +%d-%H:%M)${normal}"
|
||||
else
|
||||
LP_TIME=""
|
||||
fi
|
||||
}
|
||||
|
||||
# Implementation using lm-sensors
|
||||
_lp_temp_sensors()
|
||||
{
|
||||
local -i i
|
||||
for i in $(sensors -u |
|
||||
sed -n 's/^ temp[0-9][0-9]*_input: \([0-9]*\)\..*$/\1/p'); do
|
||||
(( $i > ${temperature:-0} )) && (( $i != 127 )) && temperature=i
|
||||
done
|
||||
}
|
||||
|
||||
# Implementation using 'acpi -t'
|
||||
_lp_temp_acpi()
|
||||
{
|
||||
local -i i
|
||||
for i in $(LANG=C acpi -t |
|
||||
sed 's/.* \(-\?[0-9]*\)\.[0-9]* degrees C$/\1/p'); do
|
||||
(( $i > ${temperature:-0} )) && (( $i != 127 )) && temperature=i
|
||||
done
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ A colorful theme, where shows a lot information about your shell session.
|
|||
|
||||
**IMPORTANT:** This theme requires that [a font with the Powerline symbols](https://github.com/powerline/fonts) needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator.
|
||||
|
||||
**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where `sudo` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your `~/.bashrc` or `~/.bash_profile` to disable the Powerline theme's `sudo` check. This will apply to all `powerline*` themes.
|
||||
|
||||
## Provided Information
|
||||
|
||||
* Current path
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
# Define this here so it can be used by all of the Powerline themes
|
||||
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
|
||||
|
||||
function set_color {
|
||||
set +u
|
||||
if [[ "${1}" != "-" ]]; then
|
||||
fg="38;5;${1}"
|
||||
fi
|
||||
|
|
@ -22,7 +26,7 @@ function __powerline_user_info_prompt {
|
|||
;;
|
||||
*)
|
||||
if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then
|
||||
user_info="${USER_INFO_SSH_CHAR}${USER}@${HOSTNAME}"
|
||||
user_info="${USER_INFO_SSH_CHAR}${USER}"
|
||||
else
|
||||
user_info="${USER}"
|
||||
fi
|
||||
|
|
@ -34,9 +38,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
|
||||
|
||||
|
|
@ -44,6 +48,7 @@ function __powerline_ruby_prompt {
|
|||
}
|
||||
|
||||
function __powerline_python_venv_prompt {
|
||||
set +u
|
||||
local python_venv=""
|
||||
|
||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||
|
|
@ -91,6 +96,13 @@ function __powerline_cwd_prompt {
|
|||
|
||||
function __powerline_hostname_prompt {
|
||||
echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}"
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
}
|
||||
|
||||
function __powerline_wd_prompt {
|
||||
echo "\W|${CWD_THEME_PROMPT_COLOR}"
|
||||
>>>>>>> master
|
||||
}
|
||||
|
||||
function __powerline_clock_prompt {
|
||||
|
|
@ -154,12 +166,22 @@ function __powerline_prompt_command {
|
|||
LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)"
|
||||
fi
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
local OLD_IFS="${IFS}"; IFS=" "
|
||||
|
||||
>>>>>>> master
|
||||
## left prompt ##
|
||||
for segment in $POWERLINE_PROMPT; do
|
||||
local info="$(__powerline_${segment}_prompt)"
|
||||
[[ -n "${info}" ]] && __powerline_left_segment "${info}"
|
||||
done
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
IFS="${OLD_IFS}"
|
||||
|
||||
>>>>>>> master
|
||||
[[ "${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}"
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ SCM_GIT_CHAR="${green}±${normal}"
|
|||
SCM_SVN_CHAR="${bold_cyan}⑆${normal}"
|
||||
SCM_HG_CHAR="${bold_red}☿${normal}"
|
||||
|
||||
VIRTUALENV_THEME_PROMPT_PREFIX="("
|
||||
VIRTUALENV_THEME_PROMPT_SUFFIX=")"
|
||||
|
||||
### TODO: openSUSE has already colors enabled, check if those differs from stock
|
||||
# LS colors, made with http://geoff.greer.fm/lscolors/
|
||||
# export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
||||
|
|
@ -33,9 +36,9 @@ pure_prompt() {
|
|||
|
||||
# make it work
|
||||
case $(id -u) in
|
||||
0) PS1="$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark"
|
||||
0) PS1="$(virtualenv_prompt)$ps_root@$ps_host$(scm_prompt):$ps_path$ps_root_mark"
|
||||
;;
|
||||
*) PS1="$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark"
|
||||
*) PS1="$(virtualenv_prompt)$ps_user@$ps_host$(scm_prompt):$ps_path$ps_user_mark"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue