Merge remote-tracking branch 'upstream/master'

pull/1237/head
ari.mourao 2017-08-05 16:19:49 +00:00
commit 6e6a7a7196
43 changed files with 1578 additions and 169 deletions

View File

@ -1,3 +1,6 @@
sudo: false
script: test/run
language: c
os:
- linux
- osx

View File

@ -23,6 +23,26 @@ When contributing a new feature, a bug fix, a new theme, or any other change to
* Internal functions that aren't to be used by the end user should start with an underscore, e.g. `_my-new-internal-function`.
* Use the provided meta functions to document your code, e.g. `about-plugin`, `about`, `group`, `param`, `example`. This will make it easier for other people to use your new functionality. Take a look at the existing code for an example (e.g. [the base plugin](plugins/available/base.plugin.bash)).
* When adding files, please use the existing file naming conventions, e.g. plugin files need to end in `.plugin.bash`. This is important for the installation functionality.
* When using the `$BASH_IT` variable, please always enclose it in double quotes to ensure that the code also works when Bash-it is installed in a directory that contains spaces in its name: `for f in "${BASH_IT}/plugins/available"/*.bash ; do echo "$f" ; done`
* Bash-it supports Bash 3.2 and higher. Please don't use features only available in Bash 4, such as associative arrays.
## Unit Tests
When adding features or making changes/fixes, please run our growing unit test suite to ensure that you did not break existing functionality. The test suite does not cover all aspects of Bash-it, but please run it anyway to verify that you did not introduce any regression issues.
Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on [Travis CI](https://travis-ci.org/Bash-it/bash-it), where the test suite is run on both Linux and macOS. The Pull Request will then show the result of the Travis build, indicating whether all tests ran fine, or whether there were issues. Please pay attention to this, Pull Requests with build issues will not be merged.
Adding new functionality or changing existing functionality is a good opportunity to increase Bash-it's test coverage. When you're changing the Bash-it codebase, please consider adding some unit tests that cover the new or changed functionality. Ideally, when fixing a bug, a matching unit test that verifies that the bug is no longer present, is added at the same time.
To run the test suite, simply execute the following in the directory where you cloned Bash-it:
```bash
test/run
```
This command will clone the [Bats Test Framework](https://github.com/sstephenson/bats) to a local directory and then run the test suite found in the [test](test) folder. The test script will execute each test in turn, and will print a status for each test case.
When adding new test cases, please take a look at the existing test cases for examples.
## Features
@ -30,5 +50,5 @@ When contributing a new feature, a bug fix, a new theme, or any other change to
## 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.

43
DEVELOPMENT.md 100644
View File

@ -0,0 +1,43 @@
# 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:
* Each type has its own `enabled` directory, into which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/plugins/enabled` for example.
* Within each of the `enabled` directories, the files are loaded in alphabetical order.
* When enabling a component, a _load priority_ is assigned to the file. The following default priorities are used:
* Aliases: 150
* Plugins: 250
* Completions: 350
* When symlinking a component into an `enabled` directory, the load priority is used as a prefix for the linked name, separated with three dashes from the name of the component. The `node.plugin.bash` would be symlinked to `250---node.plugin.bash` for example.
* 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
```
These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well.

View File

@ -2,12 +2,18 @@
[![Build Status](https://travis-ci.org/Bash-it/bash-it.svg?branch=master)](https://travis-ci.org/Bash-it/bash-it) [![Join the chat at https://gitter.im/Bash-it/bash-it](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Bash-it/bash-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
**Bash-it** is a collection of community Bash commands and scripts. (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.
## 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`
@ -49,17 +55,25 @@ Have a look at our [bash-it-docker respository](https://github.com/Bash-it/bash-
## 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
@ -174,10 +188,6 @@ cd $BASH_IT
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.
## Misc
### Bash Profile Aliases

View File

@ -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
@ -75,9 +78,29 @@ alias rd='rmdir'
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

View File

@ -59,7 +59,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"

View File

@ -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"

View File

@ -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"

View File

@ -34,10 +34,6 @@ 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"
@ -54,6 +50,10 @@ do
_load_bash_it_files $file_type
done
# Load colors first so they can be used in base theme
source "${BASH_IT}/themes/colors.theme.bash"
source "${BASH_IT}/themes/base.theme.bash"
# appearance (themes) now, after all dependencies
source $APPEARANCE_LIB

View File

@ -10,9 +10,9 @@ _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=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`;
do
if [ ! -e $BASH_IT/$subdirectory/enabled/$(basename $f) ]
if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]
then
basename $f | cut -d'.' -f1
fi
@ -25,9 +25,9 @@ _bash-it-comp-list-enabled()
{
subdirectory="$1"
local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/enabled/*.bash`;
local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/enabled/"*.bash`;
do
basename $f | cut -d'.' -f1
basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g"
done)
COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) )
@ -37,7 +37,7 @@ _bash-it-comp-list-available()
{
subdirectory="$1"
local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`;
local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`;
do
basename $f | cut -d'.' -f1
done)
@ -53,7 +53,7 @@ _bash-it-comp()
prev="${COMP_WORDS[COMP_CWORD-1]}"
chose_opt="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}"
opts="help show enable disable update search"
opts="help show enable disable update search migrate"
case "${chose_opt}" in
show)
local show_args="plugins aliases completions"
@ -61,11 +61,11 @@ _bash-it-comp()
return 0
;;
help)
local help_args="plugins aliases completions update"
local help_args="plugins aliases completions migrate update"
COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) )
return 0
;;
update | search)
update | search | migrate)
return 0
;;
enable | disable)

View File

@ -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 ""

View File

@ -1,3 +1,8 @@
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="---"
# Helper function loading various enable-able files
function _load_bash_it_files() {
subdirectory="$1"
@ -31,13 +36,14 @@ 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 ] '
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]'
typeset verb=${1:-}
@ -59,6 +65,8 @@ bash-it ()
return;;
update)
func=_bash-it_update;;
migrate)
func=_bash-it-migrate;;
*)
reference bash-it
return;;
@ -80,6 +88,9 @@ bash-it ()
fi
if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then
# Automatically run a migration if required
_bash-it-migrate
for arg in "$@"
do
$func $arg
@ -134,7 +145,12 @@ _bash-it_update() {
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."
@ -145,6 +161,36 @@ _bash-it_update() {
cd - &> /dev/null
}
_bash-it-migrate() {
_about 'migrates Bash-it configuration from a previous format to the current one'
_group 'lib'
for file_type in "aliases" "plugins" "completion"
do
shopt -s nullglob
for f in "${BASH_IT}/$file_type/enabled/"*.bash
do
typeset ff=$(basename $f)
# Only process the ones that don't use the new structure
if ! [[ $ff =~ ^[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR.*\.bash$ ]] ; then
# Get the type of component from the extension
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
typeset component_name=$(echo $ff | cut -d'.' -f1)
echo "Migrating $single_type $component_name."
disable_func="_disable-$single_type"
enable_func="_enable-$single_type"
$disable_func $component_name
$enable_func $component_name
fi
done
shopt -u nullglob
done
}
_bash-it-describe ()
{
_about 'summarizes available bash_it components'
@ -162,14 +208,15 @@ _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
if [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; 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"
@ -226,20 +273,27 @@ _disable-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 [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then
rm $BASH_IT/$subdirectory/enabled/$(basename $plugin)
if [ -e "${BASH_IT}/$subdirectory/enabled/$plugin" ]; then
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)"
fi
if [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then
rm "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin)
fi
done
else
typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1)
# Use a glob to search for both possible patterns
# 250---node.plugin.bash
# node.plugin.bash
# Either one will be matched by this glob
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1)
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)"
fi
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then
@ -256,7 +310,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 +320,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 +330,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 +340,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 +355,40 @@ _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]*$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
mkdir -p "${BASH_IT}/$subdirectory/enabled"
ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$plugin
# Load the priority from the file if it present there
local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }')
local use_load_priority=${local_file_priority:-$load_priority}
ln -s ../available/$to_enable "${BASH_IT}/$subdirectory/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,14 +415,14 @@ _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 "${BASH_IT}/aliases/enabled/"*
do
_help-list-aliases $f
done
_help-list-aliases $BASH_IT/aliases/custom.aliases.bash
_help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash"
fi
}
@ -381,7 +441,7 @@ _help-plugins()
# display a brief progress message...
printf '%s' 'please wait, building help...'
typeset grouplist=$(mktemp /tmp/grouplist.XXXX)
typeset grouplist=$(mktemp /tmp/grouplist.XXXXXX)
typeset func
for func in $(typeset_functions)
do
@ -414,6 +474,14 @@ _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'

View 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

View File

@ -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'

View File

@ -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

23
plugins/available/base.plugin.bash 100644 → 100755
View 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.]+'
@ -29,7 +29,15 @@ 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 ()
{

View File

@ -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 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,7 +53,11 @@ battery_percentage(){
about 'displays battery charge as a percentage of full (100%)'
group 'battery'
if command_exists acpi;
if command_exists upower;
then
local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | tail --bytes 5)
echo ${UPOWER_OUTPUT: : -1}
elif command_exists acpi;
then
local ACPI_OUTPUT=$(acpi -b)
case $ACPI_OUTPUT in
@ -44,11 +84,19 @@ battery_percentage(){
echo '-1'
;;
esac
elif command_exists pmset;
then
local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p')
case $PMSET_OUTPUT in
100*)
echo '100'
;;
*)
echo $PMSET_OUTPUT | head -c 2
;;
esac
elif command_exists ioreg;
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*)
@ -58,6 +106,17 @@ battery_percentage(){
echo $IOREG_OUTPUT | head -c 2
;;
esac
elif command_exists WMIC;
then
local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*')
case $WINPC in
100*)
echo '100'
;;
*)
echo $WINPC
;;
esac
else
echo "no"
fi

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,79 @@
#!/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)"
cp -r $lib_directory/../../* $BASH_IT/
rm -rf "$BASH_IT/aliases/enabled" "$BASH_IT/completion/enabled" "$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 [ -e "$BASH_IT/install.sh" ]
}
@test "install: run the install script silently" {
cd "$BASH_IT"
./install.sh --silent
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert [ -L "$BASH_IT/aliases/enabled/150---general.aliases.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/365---alias-completion.plugin.bash" ]
assert [ -L "$BASH_IT/completion/enabled/350---bash-it.completion.bash" ]
assert [ -L "$BASH_IT/completion/enabled/350---system.completion.bash" ]
}
@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 [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
assert [ -e "$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
}

View File

@ -0,0 +1,78 @@
#!/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)"
cp -r $lib_directory/../../* $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 "uninstall: verify that the uninstall script exists" {
assert [ -e "$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 [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ]
assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
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 [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ]
assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ]
local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
assert_equal "$md5_orig" "$md5_uninstall"
}

View File

@ -1,5 +1,6 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../plugins/available/base.plugin
@ -7,4 +8,233 @@ 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)"
cp -r $lib_directory/../.. $BASH_IT
mkdir -p $BASH_IT/aliases/enabled
mkdir -p $BASH_IT/completion/enabled
mkdir -p $BASH_IT/plugins/enabled
}
@test "bash-it: enable the ansible aliases through the bash-it function" {
run bash-it enable alias "ansible"
assert_line "0" 'ansible enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---ansible.aliases.bash" ]
}
@test "bash-it: enable the todo.txt-cli aliases through the bash-it function" {
run bash-it enable alias "todo.txt-cli"
assert_line "0" 'todo.txt-cli enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ]
}
@test "bash-it: enable the curl aliases" {
run _enable-alias "curl"
assert_line "0" 'curl enabled with priority 150.'
assert [ -L "$BASH_IT/aliases/enabled/150---curl.aliases.bash" ]
}
@test "bash-it: enable the apm completion through the bash-it function" {
run bash-it enable completion "apm"
assert_line "0" 'apm enabled with priority 350.'
assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ]
}
@test "bash-it: enable the brew completion" {
run _enable-completion "brew"
assert_line "0" 'brew enabled with priority 350.'
assert [ -L "$BASH_IT/completion/enabled/350---brew.completion.bash" ]
}
@test "bash-it: enable the node plugin" {
run _enable-plugin "node"
assert_line "0" 'node enabled with priority 250.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable the node plugin through the bash-it function" {
run bash-it enable plugin "node"
assert_line "0" 'node enabled with priority 250.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable the node and nvm plugins through the bash-it function" {
run bash-it enable plugin "node" "nvm"
assert_line "0" 'node enabled with priority 250.'
assert_line "1" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: enable the foo-unkown and nvm plugins through the bash-it function" {
run bash-it enable plugin "foo-unknown" "nvm"
assert_line "0" 'sorry, foo-unknown does not appear to be an available plugin.'
assert_line "1" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: enable an unknown plugin" {
run _enable-plugin "unknown-foo"
assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.'
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
}
@test "bash-it: enable an unknown plugin through the bash-it function" {
run bash-it enable plugin "unknown-foo"
echo "${lines[@]}"
assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.'
assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ]
}
@test "bash-it: disable a plugin that is not enabled" {
run _disable-plugin "sdkman"
assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.'
}
@test "bash-it: enable and disable the nvm plugin" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
run _disable-plugin "nvm"
assert_line "0" 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: disable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
run _disable-plugin "nvm"
assert_line "0" 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin if it was enabled without a priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
run _enable-plugin "nvm"
assert_line "0" 'nvm is already enabled.'
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: enable the nvm plugin twice" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
run _enable-plugin "nvm"
assert_line "0" 'nvm is already enabled.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
}
@test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash
assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ]
run _enable-plugin "ssh"
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
run _bash-it-migrate
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ]
}
@test "bash-it: run the migrate command without anything to migrate and nothing enabled" {
run _bash-it-migrate
}
@test "bash-it: run the migrate command without anything to migrate" {
run _enable-plugin "ssh"
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
run _bash-it-migrate
assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ]
}
@test "bash-it: verify that existing components are automatically migrated when something is enabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
run bash-it enable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node enabled with priority 250.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: verify that existing components are automatically migrated when something is disabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
run bash-it disable plugin "node"
assert_line "0" 'Migrating plugin nvm.'
assert_line "1" 'nvm disabled.'
assert_line "2" 'nvm enabled with priority 225.'
assert_line "3" 'node disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
}
@test "bash-it: enable all plugins" {
run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "$available" "$enabled"
}
@test "bash-it: disable all plugins" {
run _enable-plugin "all"
local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs)
local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs)
assert_equal "$available" "$enabled"
run _disable-plugin "all"
local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "$enabled2" "0"
}
@test "bash-it: describe the nvm plugin without enabling it" {
_bash-it-plugins | grep "nvm" | grep "\[ \]"
}
@test "bash-it: describe the nvm plugin after enabling it" {
run _enable-plugin "nvm"
assert_line "0" 'nvm enabled with priority 225.'
assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
@test "bash-it: describe the todo.txt-cli aliases without enabling them" {
run _bash-it-aliases
assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations"
}

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../plugins/available/base.plugin
@ -10,44 +12,50 @@ load ../../lib/search
NO_COLOR=true
@test "helpers search aliases" {
function local_setup {
mkdir -p $BASH_IT
lib_directory="$(cd "$(dirname "$0")" && pwd)"
cp -r $lib_directory/../../* $BASH_IT/
}
@test "helpers search plugins" {
run _bash-it-search-component 'plugins' 'base'
[[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]]
}
@test "helpers 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" {
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" {
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 "0" ' aliases => bundler ✓rails'
assert_line "1" ' plugins => chruby chruby-auto rails ruby'
assert_line "2" ' completions => bundler gem rake'
}
@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 "0" ' aliases => ✓bundler ✓rails'
assert_line "1" ' plugins => ✓rails ✓ruby'
assert_line "2" ' completions => ✓bundler ✓gem ✓rake'
}

View File

@ -52,5 +52,5 @@ load ../../plugins/available/base.plugin
declare -r file="${BASH_IT_ROOT}/file"
touch $file
run buf $file
[[ -e ${file}_$(date +%Y%m%d_%H%M%S) ]]
assert [ -e ${file}_$(date +%Y%m%d_%H%M%S) ]
}

View File

@ -9,4 +9,4 @@ if [ -z "${BASH_IT}" ]; then
export BASH_IT=$(cd ${test_directory} && dirname $(pwd))
fi
exec $bats_executable ${CI:+--tap} ${test_directory}/{lib,plugins}
exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins,themes}

View File

@ -13,11 +13,23 @@ if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then
export BASH_IT=$BASH_IT_TEST_DIR
fi
local_setup() {
true
}
local_teardown() {
true
}
setup() {
mkdir -p -- "${BASH_IT_ROOT}"
local_setup
}
teardown() {
local_teardown
rm -rf "${BASH_IT_TEST_DIR}"
}

View File

@ -0,0 +1,69 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../plugins/available/base.plugin
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 "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 "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)'
}

View File

@ -0,0 +1,169 @@
# 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
![alt text](https://www.lfsystems.xyz/img/AtomicTheme.gif)
## 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"`
## Follow me
I'm on the social media.
* [@lfelipe1501](https://twitter.com/lfelipe1501) on Twitter.
* [Luis Felipe](https://www.facebook.com/lfelipe1501) on Facebook.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

View File

@ -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

View File

@ -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

View File

@ -52,6 +52,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='|'
@ -123,6 +127,15 @@ function scm_prompt_info_common {
[[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return
}
# This is added to address bash shell interpolation vulnerability described
# here: https://github.com/njhartwell/pw3nage
function git_clean_branch {
local unsafe_ref=$(command git symbolic-ref -q HEAD 2> /dev/null)
local stripped_ref=${unsafe_ref##refs/heads/}
local clean_ref=${stripped_ref//[^a-zA-Z0-9\/]/-}
echo $clean_ref
}
function git_prompt_minimal_info {
local ref
local status
@ -131,9 +144,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'
@ -207,10 +220,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}...}
@ -423,20 +437,26 @@ 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 {
@ -454,13 +474,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

View File

@ -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

View File

@ -84,7 +84,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if [ -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

View File

@ -30,10 +30,14 @@ SCM_GIT_SHOW_MINIMAL_INFO=true
CLOCK_THEME_PROMPT_PREFIX=''
CLOCK_THEME_PROMPT_SUFFIX=' '
THEME_SHOW_CLOCK=true
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=') '
@ -54,7 +58,7 @@ function prompt_command() {
# Append new history lines to history file
history -a
PS1="$(clock_prompt)${virtualenv}${hostname} ${bold_cyan}\W $(scm_prompt_char_info)${ret_status}${normal}"
PS1="$(clock_prompt)${virtualenv}$(user_host_prompt)${bold_cyan}\W $(scm_prompt_char_info)${ret_status}${normal}"
}
safe_append_prompt_command prompt_command

View File

@ -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} "
}

2
themes/liquidprompt/.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
liquidprompt

View File

@ -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
}

View File

@ -117,7 +117,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}"
# checks if the plugin is installed before calling battery_charge
safe_battery_charge() {
if [ -e "${BASH_IT}/plugins/enabled/battery.plugin.bash" ];
if command_exists battery_charge ;
then
battery_charge
fi