Merge branch 'master' into feature/yarn-alias-upgrade

pull/2079/head^2
Emily Grace Seville 2022-03-16 09:49:34 +10:00 committed by GitHub
commit 3bd3b6535d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
115 changed files with 1720 additions and 1687 deletions

0
.editorconfig 100755 → 100644
View File

View File

@ -1,46 +0,0 @@
---
name: Bug report
about: Create a bug report to help us improve
title: ''
labels: bug:general
assignees: ''
---
<!--- Provide a general summary of the issue in the Title above -->
## Expected Behavior
<!--- Tell us what should happen -->
## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->
## Steps to Reproduce
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
<!--- reproduce this bug. Include code to reproduce, if relevant -->
1.
2.
3.
4.
## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Bash-it version used:
* List of enabled plugins, themes and aliases (use ``bash-it show (plugins/themes/aliases)``):
* ``bash-it doctor`` output:
* Bash version:
* Operating System and version:
## Your Bash Config File
<!--- Please paste here your bash config file (.bashrc/.bash_profile) -->
<!--- This will help us debug and locate the problem -->
```bash
# Your bash config file should be here
```

View File

@ -0,0 +1,85 @@
name: 🐛 Bug report
title: "[Bug]: "
description: Create a bug report to help us improve
labels: "bug:general"
body:
- type: textarea
attributes:
label: Expected behavior
description: Tell us what should happen.
validations:
required: true
- type: textarea
attributes:
label: Current behavior
description: Tell us what happens instead of the expected behavior.
validations:
required: true
- type: textarea
attributes:
label: Possible solution
description: Tell us how it could be fixed at your glance.
validations:
required: false
- type: textarea
attributes:
label: Context
description: >
How has this issue affected you? What are you trying to accomplish?
Providing context helps us come up with a solution that is most useful in the real world.
validations:
required: false
- type: textarea
attributes:
label: Steps to reproduce
description: >
Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include code to reproduce, if relevant.
validations:
required: true
- type: input
attributes:
label: Bash-it version
placeholder: "How to get: bash-it version"
validations:
required: true
- type: input
attributes:
label: List of enabled plugins, themes and aliases
placeholder: "How to get: bash-it show plugins|themes|aliases (it is not a pipe)"
validations:
required: true
- type: input
attributes:
label: Bash version
placeholder: "How to get: bash --version"
validations:
required: true
- type: input
attributes:
label: Operating system and version
placeholder: "How to get: neofetch (or another command)"
validations:
required: true
- type: textarea
attributes:
label: "bash-it doctor output"
value: |
```
# How to get: bash-it doctor
```
validations:
required: false
- type: textarea
attributes:
label: Your ~/.bashrc
value: |
```bash
# How to get: cat ~/.bashrc
```
validations:
required: true
- type: textarea
attributes:
label: Notes
description: >
Provide any extra details here.

View File

@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Libera chat
url: https://web.libera.chat/?channel=#bash-it
about: You can ask and answer questions here

View File

@ -1,23 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: feature request
assignees: ''
---
<!--- Provide a general summary of the issue in the Title above -->
## Expected Behavior
<!--- Tell us how your feature should work -->
## Current Behavior
<!--- Explain the difference your feature will have from current behavior -->
## Possible Solution
<!--- Not obligatory, but suggest ideas on how to implement the addition or change -->
## Context
<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->

View File

@ -0,0 +1,34 @@
name: 💡 Feature request
title: "[Feature]: "
description: Suggest an idea for this project
labels: "feature request"
body:
- type: textarea
attributes:
label: Expected behavior
description: Tell us how your feature should work.
validations:
required: true
- type: textarea
attributes:
label: Current behavior
description: Explain the difference your feature will have from current behavior.
validations:
required: true
- type: textarea
attributes:
label: Possible solution
description: Tell us how it could be fixed at your glance.
validations:
required: false
- type: textarea
attributes:
label: Context
description: >
How has this issue affected you? What are you trying to accomplish?
Providing context helps us come up with a solution that is most useful in the real world.
- type: textarea
attributes:
label: Notes
description: >
Provide any extra details here.

0
.gitignore vendored 100755 → 100644
View File

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'the silver searcher (ag) aliases' about-alias 'the silver searcher (ag) aliases'
## Summary for args to less: ## Summary for args to less:

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'ansible abbreviations' about-alias 'ansible abbreviations'
alias ans=ansible alias ans=ansible

View File

@ -6,10 +6,8 @@ cite 'about-alias'
about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.' about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.'
# set apt aliases # set apt aliases
function _set_pkg_aliases() function _set_pkg_aliases() {
{ if _command_exists apt; then
if _command_exists apt
then
alias apts='apt-cache search' alias apts='apt-cache search'
alias aptshow='apt-cache show' alias aptshow='apt-cache show'
alias aptinst='sudo apt-get install -V' alias aptinst='sudo apt-get install -V'

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'Atom.io editor abbreviations' about-alias 'Atom.io editor abbreviations'
alias a='atom' alias a='atom'

View File

@ -1,4 +1,4 @@
cite about-alias # shellcheck shell=bash
about-alias 'Aliases for the bash-it command (these aliases are automatically included with the "general" aliases)' about-alias 'Aliases for the bash-it command (these aliases are automatically included with the "general" aliases)'
# Common misspellings of bash-it # Common misspellings of bash-it

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'puppet bolt aliases' about-alias 'puppet bolt aliases'
# Aliases # Aliases

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'ruby bundler' about-alias 'ruby bundler'
# Bundler Commands # Bundler Commands

View File

@ -1,5 +1,4 @@
# shellcheck shell=bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'xclip shortcuts' about-alias 'xclip shortcuts'
alias pbcopy="xclip -selection clipboard" alias pbcopy="xclip -selection clipboard"

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'common composer abbreviations' about-alias 'common composer abbreviations'
# Aliases # Aliases

View File

@ -1,23 +1,19 @@
#!/bin/bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'Curl aliases for convenience.' about-alias 'Curl aliases for convenience.'
# set apt aliases # set apt aliases
function _set_pkg_aliases() function _set_pkg_aliases() {
{ if _command_exists curl; then
if _command_exists curl
then
# follow redirects # follow redirects
alias cl='curl -L' alias cl='curl -L'
# follow redirects, download as original name # follow redirects, download as original name
alias clo='curl -L -O' alias clo='curl -L -O'
# follow redirects, download as original name, continue # follow redirects, download as original name, continue
alias cloc='curl -L -C - -O' alias cloc='curl -L -C - -O'
# follow redirects, download as original name, continue, retry 5 times # follow redirects, download as original name, continue, retry 5 times
alias clocr='curl -L -C - -O --retry 5' alias clocr='curl -L -C - -O --retry 5'
# follow redirects, fetch banner # follow redirects, fetch banner
alias clb='curl -L -I' alias clb='curl -L -I'
# see only response headers from a get request # see only response headers from a get request
alias clhead='curl -D - -so /dev/null' alias clhead='curl -D - -so /dev/null'
fi fi

View File

@ -1,5 +1,4 @@
# shellcheck shell=bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'dnf aliases for fedora 22+ distros' about-alias 'dnf aliases for fedora 22+ distros'
alias dnfl="dnf list" # List packages alias dnfl="dnf list" # List packages

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'docker-compose abbreviations' about-alias 'docker-compose abbreviations'
alias dco="docker-compose" alias dco="docker-compose"

View File

@ -1,32 +1,32 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'docker abbreviations' about-alias 'docker abbreviations'
alias dk='docker' alias dk='docker'
alias dklc='docker ps -l' # List last Docker container alias dklc='docker ps -l' # List last Docker container
alias dklcid='docker ps -l -q' # List last Docker container ID alias dklcid='docker ps -l -q' # List last Docker container ID
alias dklcip='docker inspect -f "{{.NetworkSettings.IPAddress}}" $(docker ps -l -q)' # Get IP of last Docker container alias dklcip='docker inspect -f "{{.NetworkSettings.IPAddress}}" $(docker ps -l -q)' # Get IP of last Docker container
alias dkps='docker ps' # List running Docker containers alias dkps='docker ps' # List running Docker containers
alias dkpsa='docker ps -a' # List all Docker containers alias dkpsa='docker ps -a' # List all Docker containers
alias dki='docker images' # List Docker images alias dki='docker images' # List Docker images
alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers
case $OSTYPE in case $OSTYPE in
darwin*|*bsd*|*BSD*) 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 docker rmi' # Delete all untagged Docker images
;; ;;
*) *)
alias dkrmui='docker images -q -f dangling=true | xargs -r 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 esac
if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then if _bash-it-component-item-is-enabled plugin docker; then
# Function aliases from docker plugin: # Function aliases from docker plugin:
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers 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 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 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 alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz
alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID
fi fi
alias dkelc='docker exec -it $(dklcid) bash --login' # Enter last container (works with Docker 1.3 and above) alias dkelc='docker exec -it $(dklcid) bash --login' # Enter last container (works with Docker 1.3 and above)
alias dkrmflast='docker rm -f $(dklcid)' alias dkrmflast='docker rm -f $(dklcid)'

View File

@ -1,16 +1,16 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'emacs editor' about-alias 'emacs editor'
case $OSTYPE in case $OSTYPE in
linux*) linux*)
alias em='emacs' alias em='emacs'
alias en='emacs -nw' alias en='emacs -nw'
alias e='emacsclient -n' alias e='emacsclient -n'
alias et='emacsclient -t' alias et='emacsclient -t'
alias ed='emacs --daemon' alias ed='emacs --daemon'
alias E='SUDO_EDITOR=emacsclient sudo -e' alias E='SUDO_EDITOR=emacsclient sudo -e'
;; ;;
darwin*) darwin*)
alias em='open -a emacs' alias em='open -a emacs'
;; ;;
esac esac

View File

@ -1,9 +1,9 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'fuck/please to retry last command with sudo' about-alias 'fuck/please to retry last command with sudo'
# Play nicely with 'thefuck' plugin # Play nicely with 'thefuck' plugin
if ! _command_exists fuck ; then if ! _command_exists fuck; then
alias fuck='sudo $(fc -ln -1)' alias fuck='sudo $(fc -ln -1)'
fi fi
alias please=fuck alias please=fuck
alias plz=please alias plz=please

View File

@ -1,51 +1,45 @@
cite about-alias # shellcheck shell=bash
about-alias 'general aliases' about-alias 'general aliases'
if ls --color -d . &> /dev/null if command ls --color -d . &> /dev/null; then
then alias ls='ls --color=auto'
alias ls="ls --color=auto" # BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set.
elif ls -G -d . &> /dev/null
then
alias ls='ls -G' # Compact view, show colors
fi fi
# List directory contents # List directory contents
alias sl=ls alias sl=ls
alias la='ls -AF' # Compact view, show hidden alias la='ls -AF' # Compact view, show hidden
alias ll='ls -al' alias ll='ls -al'
alias l='ls -a' alias l='ls -a'
alias l1='ls -1' alias l1='ls -1'
alias lf='ls -F' alias lf='ls -F'
alias _="sudo" alias _='sudo'
# Shortcuts to edit startup files # Shortcuts to edit startup files
alias vbrc="vim ~/.bashrc" alias vbrc='${VISUAL:-vim} ~/.bashrc'
alias vbpf="vim ~/.bash_profile" alias vbpf='${VISUAL:-vim} ~/.bash_profile'
# colored grep # colored grep
# Need to check an existing file for a pattern that will be found to ensure # 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 # that the check works when on an OS that supports the color option
if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null if command grep --color=auto "a" "${BASH_IT?}"/*.md &> /dev/null; then
then alias grep='grep --color=auto'
alias grep='grep --color=auto'
fi fi
if _command_exists gshuf if _command_exists gshuf; then
then alias shuf=gshuf
alias shuf=gshuf
fi fi
alias c='clear' alias c='clear'
alias k='clear'
alias cls='clear' alias cls='clear'
alias edit="$EDITOR" alias edit='${EDITOR:-${ALTERNATE_EDITOR?}}'
alias pager="$PAGER" alias pager='${PAGER:=less}'
alias q='exit' alias q='exit'
alias irc="${IRC_CLIENT:=irc}" alias irc='${IRC_CLIENT:=irc}'
# Language aliases # Language aliases
alias rb='ruby' alias rb='ruby'
@ -66,9 +60,8 @@ alias -- -='cd -' # Go back
alias h='history' alias h='history'
# Tree # Tree
if ! _command_exists tree if ! _command_exists tree; then
then alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
fi fi
# Directory # Directory
@ -76,21 +69,21 @@ alias md='mkdir -p'
alias rd='rmdir' alias rd='rmdir'
# Shorten extract # Shorten extract
alias xt="extract" alias xt='extract'
# sudo editors # sudo editors
alias svim="sudo vim" alias svim='sudo ${VISUAL:-vim}'
alias snano="sudo nano" alias snano='sudo nano'
# Display whatever file is regular file or folder # Display whatever file is regular file or folder
catt() { function catt() {
for i in "$@"; do for i in "$@"; do
if [ -d "$i" ]; then if [[ -d "$i" ]]; then
ls "$i" ls "$i"
else else
cat "$i" cat "$i"
fi fi
done done
} }
# The Bash-it aliases were moved to the `bash-it.aliases.bash` file. The intent of this # The Bash-it aliases were moved to the `bash-it.aliases.bash` file. The intent of this
@ -99,5 +92,5 @@ catt() {
# aliases and enable just the ones for Bash-it explicitly: # aliases and enable just the ones for Bash-it explicitly:
# bash-it disable alias general # bash-it disable alias general
# bash-it enable alias bash-it # bash-it enable alias bash-it
# shellcheck source=./bash-it.aliases.bash # shellcheck source-path=SCRIPTDIR
source "$BASH_IT/aliases/available/bash-it.aliases.bash" source "$BASH_IT/aliases/available/bash-it.aliases.bash"

View File

@ -1,5 +1,4 @@
# shellcheck shell=bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'common git abbreviations' about-alias 'common git abbreviations'
alias g='git' alias g='git'

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'common git-svn abbreviations' about-alias 'common git-svn abbreviations'
# Aliases # Aliases

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'heroku task abbreviations' about-alias 'heroku task abbreviations'
# heroku # heroku

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'mercurial abbreviations' about-alias 'mercurial abbreviations'
alias hs='hg status' alias hs='hg status'

View File

@ -1,7 +1,5 @@
# Some aliases for Homebrew Cask # shellcheck shell=bash
about-alias 'Some aliases for Homebrew Cask'
cite 'about-alias'
about-alias 'homebrew-cask abbreviations'
alias bcin='brew cask install' alias bcin='brew cask install'
alias bcrm='brew cask uninstall' alias bcrm='brew cask uninstall'

View File

@ -1,7 +1,5 @@
# Some aliases for Homebrew # shellcheck shell=bash
about-alias 'Some aliases for Homebrew'
cite 'about-alias'
about-alias 'homebrew abbreviations'
alias bup='brew update && brew upgrade' alias bup='brew update && brew upgrade'
alias bout='brew outdated' alias bout='brew outdated'

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'homesick aliases' about-alias 'homesick aliases'
# Aliases # Aliases
@ -19,6 +19,5 @@ alias sikpsh="homesick push dotfiles"
alias sikrc="homesick rc dotfiles" alias sikrc="homesick rc dotfiles"
alias sikpth="homesick show_path dotfiles" alias sikpth="homesick show_path dotfiles"
alias sikst="homesick status dotfiles" alias sikst="homesick status dotfiles"
alias siktrk="homesick track $1 dotfiles"
alias sikulnk="homesick unlink dotfiles" alias sikulnk="homesick unlink dotfiles"
alias sikv="homesick version" alias sikv="homesick version"

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'jitsu task abbreviations' about-alias 'jitsu task abbreviations'
# jitsu # jitsu

View File

@ -1,25 +1,20 @@
#!/bin/bash # shellcheck shell=bash
#
# -binaryanomaly
cite 'about-alias'
about-alias 'kubectl aliases' about-alias 'kubectl aliases'
function _set_pkg_aliases() function _set_pkg_aliases() {
{ if _command_exists kubectl; then
if _command_exists kubectl; then alias kc='kubectl'
alias kc='kubectl' alias kcgp='kubectl get pods'
alias kcgp='kubectl get pods' alias kcgd='kubectl get deployments'
alias kcgd='kubectl get deployments' alias kcgn='kubectl get nodes'
alias kcgn='kubectl get nodes' alias kcdp='kubectl describe pod'
alias kcdp='kubectl describe pod' alias kcdd='kubectl describe deployment'
alias kcdd='kubectl describe deployment' alias kcdn='kubectl describe node'
alias kcdn='kubectl describe node' alias kcgpan='kubectl get pods --all-namespaces'
alias kcgpan='kubectl get pods --all-namespaces' alias kcgdan='kubectl get deployments --all-namespaces'
alias kcgdan='kubectl get deployments --all-namespaces' # launches a disposable netshoot pod in the k8s cluster
# launches a disposable netshoot pod in the k8s cluster alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash'
alias kcnetshoot='kubectl run netshoot-$(date +%s) --rm -i --tty --image nicolaka/netshoot -- /bin/bash' fi
fi
} }
_set_pkg_aliases _set_pkg_aliases

View File

@ -1,9 +1,9 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'laravel artisan abbreviations' about-alias 'laravel artisan abbreviations'
# A list of useful laravel aliases # A list of useful laravel aliases
alias laravel="${HOME}/.composer/vendor/bin/laravel" alias laravel='${HOME?}/.composer/vendor/bin/laravel'
# asset # asset
alias a:apub='php artisan asset:publish' alias a:apub='php artisan asset:publish'

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'maven abbreviations' about-alias 'maven abbreviations'
alias mci='mvn clean install' alias mci='mvn clean install'

View File

@ -1,6 +1,4 @@
#!/bin/bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'MSYS2 aliases' about-alias 'MSYS2 aliases'
LS_COMMON="-hG" LS_COMMON="-hG"
@ -9,7 +7,7 @@ LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"
# alias # alias
# setup the main ls alias if we've established common args # setup the main ls alias if we've established common args
test -n "$LS_COMMON" && alias ls="command ls $LS_COMMON" alias ls='command ls ${LS_COMMON:-}'
alias ll="ls -l" alias ll="ls -l"
alias la="ls -a" alias la="ls -a"
alias lal="ll -a" alias lal="ll -a"

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'the Node.js environment aliases' about-alias 'the Node.js environment aliases'
# alias to setup nodejs development environment # alias to setup nodejs development environment

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'common npm abbreviations' about-alias 'common npm abbreviations'
# Aliases # Aliases

View File

@ -1,27 +1,28 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'osx-specific aliases' about-alias 'osx-specific aliases'
# Desktop Programs # Desktop Programs
alias fireworks="open -a '/Applications/Adobe Fireworks CS3/Adobe Fireworks CS3.app'" alias fireworks='open -a "/Applications/Adobe Fireworks CS3/Adobe Fireworks CS3.app"'
alias photoshop="open -a '/Applications/Adobe Photoshop CS3/Adobe Photoshop.app'" alias photoshop='open -a "/Applications/Adobe Photoshop CS3/Adobe Photoshop.app"'
alias preview="open -a '$PREVIEW'" alias preview='open -a "${PREVIEW?}"'
alias xcode="open -a '/Applications/XCode.app'" alias xcode='open -a "/Applications/XCode.app"'
alias filemerge="open -a '/Developer/Applications/Utilities/FileMerge.app'" alias filemerge='open -a "/Developer/Applications/Utilities/FileMerge.app"'
alias safari="open -a safari" alias safari='open -a safari'
alias firefox="open -a firefox" alias firefox='open -a firefox'
alias chrome="open -a google\ chrome" alias chrome='open -a "Google Chrome"'
alias chromium="open -a chromium" alias chromium='open -a chromium'
alias dashcode="open -a dashcode" alias brave='open -a "Brave Browser"'
alias dashcode='open -a dashcode'
alias f='open -a Finder ' alias f='open -a Finder '
alias fh='open -a Finder .' alias fh='open -a Finder .'
alias textedit='open -a TextEdit' alias textedit='open -a TextEdit'
alias hex='open -a "Hex Fiend"' alias hex='open -a "Hex Fiend"'
alias skype='open -a Skype' alias skype='open -a Skype'
alias mou='open -a Mou' alias mou='open -a Mou'
alias subl='open -a Sublime\ Text' alias subl='open -a "Sublime Text"'
if [ -s /usr/bin/firefox ] ; then if [[ -s /usr/bin/firefox ]]; then
unalias firefox unalias firefox
fi fi
# Requires growlnotify, which can be found in the Growl DMG under "Extras" # Requires growlnotify, which can be found in the Growl DMG under "Extras"
@ -37,19 +38,20 @@ alias whotunes='lsof -r 2 -n -P -F n -c iTunes -a -i TCP@`hostname`:3689'
alias flush='dscacheutil -flushcache' alias flush='dscacheutil -flushcache'
# Show/hide hidden files (for Mac OS X Mavericks) # Show/hide hidden files (for Mac OS X Mavericks)
alias showhidden="defaults write com.apple.finder AppleShowAllFiles TRUE" alias showhidden='defaults write com.apple.finder AppleShowAllFiles TRUE'
alias hidehidden="defaults write com.apple.finder AppleShowAllFiles FALSE" alias hidehidden='defaults write com.apple.finder AppleShowAllFiles FALSE'
# From http://apple.stackexchange.com/questions/110343/copy-last-command-in-terminal # From http://apple.stackexchange.com/questions/110343/copy-last-command-in-terminal
alias copyLastCmd='fc -ln -1 | awk '\''{$1=$1}1'\'' ORS='\'''\'' | pbcopy' # shellcheck disable=SC2142 # The quoting confuses `shellcheck`...
alias copyLastCmd="fc -ln -1 | awk '{\$1=\$1}1' ORS='' | pbcopy"
# Use Finder's Quick Look on a file (^C or space to close) # Use Finder's Quick Look on a file (^C or space to close)
alias ql='qlmanage -p 2>/dev/null' alias ql='qlmanage -p 2>/dev/null'
# Mute/Unmute the system volume. Plays nice with all other volume settings. # Mute/Unmute the system volume. Plays nice with all other volume settings.
alias mute="osascript -e 'set volume output muted true'" alias mute='osascript -e "set volume output muted true"'
alias unmute="osascript -e 'set volume output muted false'" alias unmute='osascript -e "set volume output muted false"'
# Pin to the tail of long commands for an audible alert after long processes # Pin to the tail of long commands for an audible alert after long processes
## curl http://downloads.com/hugefile.zip; lmk ## curl http://downloads.com/hugefile.zip; lmk
alias lmk="say 'Process complete.'" alias lmk='say "Process complete."'

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'phoenix abbreviations' about-alias 'phoenix abbreviations'
# Phoenix Commands # Phoenix Commands

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'puppet aliases' about-alias 'puppet aliases'
# Aliases # Aliases

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'pyrocms abbreviations' about-alias 'pyrocms abbreviations'
### ###
@ -7,146 +7,146 @@ about-alias 'pyrocms abbreviations'
### ###
# general # general
alias a:cl="php artisan clear-compiled" # Remove the compiled class file 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:d="php artisan down" # Put the application into maintenance mode
alias a:e="php artisan env" # Display the current framework environment alias a:e="php artisan env" # Display the current framework environment
alias a:h="php artisan help" # Displays help for a command alias a:h="php artisan help" # Displays help for a command
alias a:i="php artisan install" # Install the Streams Platform. alias a:i="php artisan install" # Install the Streams Platform.
alias a:ls="php artisan list" # Lists commands alias a:ls="php artisan list" # Lists commands
alias a:mg="php artisan migrate" # Run the database migrations 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: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: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: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 alias a:u="php artisan up" # Bring the application out of maintenance mode
# addon # addon
alias a:ad:i="php artisan addon:install" # Install an 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: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:r="php artisan addon:reinstall" # Reinstall an addon.
alias a:ad:u="php artisan addon:uninstall" # Uninstall an addon. alias a:ad:u="php artisan addon:uninstall" # Uninstall an addon.
# app # app
alias a:ap:n="php artisan app:name" # Set the application namespace 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. alias a:ap:p="php artisan app:publish" # Publish general application override files.
# assets # assets
alias a:as:cl="php artisan assets:clear" # Clear compiled public assets. alias a:as:cl="php artisan assets:clear" # Clear compiled public assets.
# auth # auth
alias a:au:clrs="php artisan auth:clear-resets" # Flush expired password reset tokens alias a:au:clrs="php artisan auth:clear-resets" # Flush expired password reset tokens
# cache # cache
alias a:ca:cl="php artisan cache:clear" # Flush the application 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: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 alias a:ca:t="php artisan cache:table" # Create a migration for the cache database table
# config # config
alias a:co:ca="php artisan config:cache" # Create a cache file for faster configuration loading 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 alias a:co:cl="php artisan config:clear" # Remove the configuration cache file
# db # db
alias a:db:s="php artisan db:seed" # Seed the database with records alias a:db:s="php artisan db:seed" # Seed the database with records
# env # env
alias a:en:s="php artisan env:set" # Set an environmental value. alias a:en:s="php artisan env:set" # Set an environmental value.
# event # event
alias a:ev:g="php artisan event:generate" # Generate the missing events and listeners based on registration alias a:ev:g="php artisan event:generate" # Generate the missing events and listeners based on registration
# extension # extension
alias a:ex:i="php artisan extension:install" # Install a 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:r="php artisan extension:reinstall" # Reinstall a extension.
alias a:ex:u="php artisan extension:uninstall" # Uninstall a extension. alias a:ex:u="php artisan extension:uninstall" # Uninstall a extension.
# files # files
alias a:fi:cl="php artisan files:clean" # Clean missing files from the files table. alias a:fi:cl="php artisan files:clean" # Clean missing files from the files table.
# key # key
alias a:ke:g="php artisan key:generate" # Set the application key alias a:ke:g="php artisan key:generate" # Set the application key
# make # make
alias a:mk:ad="php artisan make:addon" # Create a new addon. 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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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:st="php artisan make:stream" # Make a streams entity namespace.
alias a:mk:ts="php artisan make:test" # Create a new test class alias a:mk:ts="php artisan make:test" # Create a new test class
# migrate # migrate
alias a:mg:fr="php artisan migrate:fresh" # Drop all tables and re-run all migrations 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: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: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: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:rl="php artisan migrate:rollback" # Rollback the last database migration
alias a:mg:st="php artisan migrate:status" # Show the status of each migration alias a:mg:st="php artisan migrate:status" # Show the status of each migration
# module # module
alias a:mo:i="php artisan module:install" # Install a 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:r="php artisan module:reinstall" # Reinstall a module.
alias a:mo:u="php artisan module:uninstall" # Uninstall a module. alias a:mo:u="php artisan module:uninstall" # Uninstall a module.
# notifications # notifications
alias a:no:tb="php artisan notifications:table" # Create a migration for the notifications table alias a:no:tb="php artisan notifications:table" # Create a migration for the notifications table
# package # package
alias a:pk:d="php artisan package:discover" # Rebuild the cached package manifest alias a:pk:d="php artisan package:discover" # Rebuild the cached package manifest
# queue # queue
alias a:qu:fa="php artisan queue:failed" # List all of the failed queue jobs 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: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: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: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: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: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: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: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 alias a:qu:w="php artisan queue:work" # Start processing jobs on the queue as a daemon
# route # route
alias a:ro:ca="php artisan route:cache" # Create a route cache file for faster route registration 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:cl="php artisan route:clear" # Remove the route cache file
alias a:ro:ls="php artisan route:list" # List all registered routes alias a:ro:ls="php artisan route:list" # List all registered routes
# schedule # schedule
alias a:sc:r="php artisan schedule:run" # Run the scheduled commands alias a:sc:r="php artisan schedule:run" # Run the scheduled commands
# scout # scout
alias a:su:fl="php artisan scout:flush" # Flush all of the model's records from the index 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 alias a:su:im="php artisan scout:import" # Import the given model into the search index
# session # session
alias a:se:tb="php artisan session:table" # Create a migration for the session database table alias a:se:tb="php artisan session:table" # Create a migration for the session database table
# storage # storage
alias a:sg:l="php artisan storage:link" # Create a symbolic link from "public/storage" to "storage/app/public" alias a:sg:l="php artisan storage:link" # Create a symbolic link from "public/storage" to "storage/app/public"
# streams # streams
alias a:st:cl="php artisan streams:cleanup" # Cleanup streams entry models. 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:co="php artisan streams:compile" # Compile streams entry models.
alias a:st:d="php artisan streams:destroy" # Destroy a namespace. 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:p="php artisan streams:publish" # Publish configuration and translations for streams.
alias a:st:r="php artisan streams:refresh" # Refresh streams generated components. alias a:st:r="php artisan streams:refresh" # Refresh streams generated components.
# tntsearch # tntsearch
alias a:tn:im="php artisan tntsearch:import" # Import the given model into the search index alias a:tn:im="php artisan tntsearch:import" # Import the given model into the search index
# vendor # vendor
alias a:ve:p="php artisan vendor:publish" # Publish any publishable assets from vendor packages alias a:ve:p="php artisan vendor:publish" # Publish any publishable assets from vendor packages
# view # view
alias a:vi:cl="php artisan view:clear" # Clear all compiled view files alias a:vi:cl="php artisan view:clear" # Clear all compiled view files

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'rails abbreviations' about-alias 'rails abbreviations'
# Rails Commands # Rails Commands
@ -14,9 +14,9 @@ alias rd='rails destroy'
alias dbm='rake db:migrate' alias dbm='rake db:migrate'
alias ss='script/server' alias ss='script/server'
alias ts="thin start" # thin server alias ts="thin start" # thin server
alias sc='script/console' alias sc='script/console'
alias restartapp='touch tmp/restart.txt' alias restartapp='touch tmp/restart.txt'
alias restart='touch tmp/restart.txt' # restart passenger alias restart='touch tmp/restart.txt' # restart passenger
alias devlog='tail -f log/development.log' alias devlog='tail -f log/development.log'
alias taild='tail -f log/development.log' # tail dev log alias taild='tail -f log/development.log' # tail dev log

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'common svn abbreviations' about-alias 'common svn abbreviations'
# Aliases # Aliases

View File

@ -1,22 +1,22 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'systemd service' about-alias 'systemd service'
case $OSTYPE in case $OSTYPE in
linux*) linux*)
# Improve aliases by bringing the common root `sc|scd` + `sre` for action + `u` for user # Improve aliases by bringing the common root `sc|scd` + `sre` for action + `u` for user
alias sc='systemctl' alias sc='systemctl'
alias scu='systemctl --user' alias scu='systemctl --user'
alias scdr='systemctl daemon-reload' alias scdr='systemctl daemon-reload'
alias scdru='systemctl --user daemon-reload' alias scdru='systemctl --user daemon-reload'
alias scr='systemctl restart' alias scr='systemctl restart'
alias scru='systemctl --user restart' alias scru='systemctl --user restart'
alias sce='systemctl stop' alias sce='systemctl stop'
alias sceu='systemctl --user stop' alias sceu='systemctl --user stop'
alias scs='systemctl start' alias scs='systemctl start'
alias scsu='systemctl --user start' alias scsu='systemctl --user start'
# Keeping previous aliases for a non-breaking change. # Keeping previous aliases for a non-breaking change.
alias scue='sceu' alias scue='sceu'
alias scus='scsu' alias scus='scsu'
alias scur='scdru' alias scur='scdru'
;; ;;
esac esac

View File

@ -1,7 +1,5 @@
# Aliases for Terraform and Terragrunt # shellcheck shell=bash
about-alias 'Aliases for Terraform and Terragrunt'
cite 'about-alias'
about-alias 'Terraform abbreviations'
alias tf='terraform' alias tf='terraform'
alias tfv='terraform validate' alias tfv='terraform validate'

View File

@ -1,7 +1,5 @@
# Aliases for Terraform and Terragrunt # shellcheck shell=bash
about-alias 'Aliases for Terraform and Terragrunt'
cite 'about-alias'
about-alias 'Terragrunt abbreviations'
alias tg='terragrunt' alias tg='terragrunt'
alias tgv='terragrunt validate' alias tgv='terragrunt validate'

View File

@ -1,10 +1,10 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'textmate abbreviations' about-alias 'textmate abbreviations'
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
# Textmate # Textmate
alias e='mate . &' alias e='mate . &'
alias et='mate app config db lib public script test spec config.ru Gemfile Rakefile README &' alias et='mate app config db lib public script test spec config.ru Gemfile Rakefile README &'
;; ;;
esac esac

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'Tmux terminal multiplexer' about-alias 'Tmux terminal multiplexer'
alias txl='tmux ls' alias txl='tmux ls'

View File

@ -1,8 +1,8 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'todo.txt-cli abbreviations' about-alias 'todo.txt-cli abbreviations'
alias tls="$TODO ls" alias tls='"${TODO?}" ls'
alias ta="$TODO a" alias ta='"${TODO?}" a'
alias trm="$TODO rm" alias trm='"${TODO?}" rm'
alias tdo="$TODO do" alias tdo='"${TODO?}" do'
alias tpri="$TODO pri" alias tpri='"${TODO?}" pri'

View File

@ -1,11 +1,11 @@
cite 'uuid-alias' # shellcheck shell=bash
about-alias 'uuidgen aliases' about-alias 'uuidgen aliases'
if _command_exists uuid; then # Linux if _command_exists uuid; then # Linux
alias uuidu="uuid | tr '[:lower:]' '[:upper:]'" alias uuidu="uuid | tr '[:lower:]' '[:upper:]'"
alias uuidl=uuid alias uuidl=uuid
elif _command_exists uuidgen; then # macOS/BSD elif _command_exists uuidgen; then # macOS/BSD
alias uuidu="uuidgen" alias uuidu="uuidgen"
alias uuid="uuidgen | tr '[:upper:]' '[:lower:]'" # because upper case is like YELLING alias uuid="uuidgen | tr '[:upper:]' '[:lower:]'" # because upper case is like YELLING
alias uuidl=uuid alias uuidl=uuid
fi fi

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'vagrant aliases' about-alias 'vagrant aliases'
# Aliases # Aliases

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'vault aliases' about-alias 'vault aliases'
# Aliases # Aliases

View File

@ -1,5 +1,4 @@
# shellcheck shell=bash # shellcheck shell=bash
cite 'about-alias'
about-alias 'vim abbreviations' about-alias 'vim abbreviations'
_command_exists vim || return _command_exists vim || return

View File

@ -1,4 +1,4 @@
cite 'about-alias' # shellcheck shell=bash
about-alias 'yarn package manager aliases' about-alias 'yarn package manager aliases'
# Aliases # Aliases

View File

@ -1,145 +1,110 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# shellcheck source-path=SCRIPTDIR/lib source-path=SCRIPTDIR/scripts
# shellcheck disable=SC2034
#
# Initialize Bash It # Initialize Bash It
BASH_IT_LOG_PREFIX="core: main: " BASH_IT_LOG_PREFIX="core: main: "
: "${BASH_IT:=${BASH_SOURCE%/*}}"
# Only set $BASH_IT if it's not already set : "${BASH_IT_CUSTOM:=${BASH_IT}/custom}"
if [ -z "${BASH_IT:-}" ]; then : "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM}/themes"}"
# Setting $BASH to maintain backwards compatibility : "${BASH_IT_BASHRC:=${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}}"
export BASH_IT=$BASH
BASH="$(bash -c 'echo $BASH')"
export BASH
BASH_IT_OLD_BASH_SETUP=true
fi
# Load composure first, so we support function metadata # Load composure first, so we support function metadata
# shellcheck disable=SC1090 # shellcheck source-path=SCRIPTDIR/vendor/github.com/erichs/composure
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
# Declare our end-of-main finishing hook
declare -a _bash_it_library_finalize_hook
# We need to load logging module early in order to be able to log
# shellcheck source-path=SCRIPTDIR/lib
source "${BASH_IT}/lib/log.bash"
# We can only log it now
[ -z "${BASH_IT_OLD_BASH_SETUP:-}" ] || _log_warning "BASH_IT variable not initialized, please upgrade your bash-it version and reinstall it!"
# For backwards compatibility, look in old BASH_THEME location
if [ -z "${BASH_IT_THEME:-}" ]; then
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
export BASH_IT_THEME="${BASH_THEME:-}"
unset BASH_THEME
fi
# support 'plumbing' metadata # support 'plumbing' metadata
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
cite about-alias about-plugin about-completion cite about-alias about-plugin about-completion
# Declare our end-of-main finishing hook, but don't use `declare`/`typeset`
_bash_it_library_finalize_hook=()
# We need to load logging module early in order to be able to log
source "${BASH_IT}/lib/log.bash"
# libraries, but skip appearance (themes) for now # libraries, but skip appearance (themes) for now
_log_debug "Loading libraries(except appearance)..." _log_debug "Loading libraries(except appearance)..."
LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for _bash_it_config_file in $LIB; do for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then [[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue
filename=${_bash_it_config_file##*/} _bash-it-log-prefix-by-path "${_bash_it_main_file_lib}"
filename=${filename%.bash} _log_debug "Loading library file..."
BASH_IT_LOG_PREFIX="lib: ${filename}: " # shellcheck disable=SC1090
_log_debug "Loading library file..." source "$_bash_it_main_file_lib"
# shellcheck disable=SC1090 BASH_IT_LOG_PREFIX="core: main: "
source "$_bash_it_config_file"
fi
done done
BASH_IT_LOG_PREFIX="core: main: " # Load the global "enabled" directory, then enabled aliases, completion, plugins
# Load the global "enabled" directory # "_bash_it_main_file_type" param is empty so that files get sourced in glob order
# "family" param is empty so that files get sources in glob order for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do
# shellcheck source=./scripts/reloader.bash BASH_IT_LOG_PREFIX="core: reloader: "
source "${BASH_IT}/scripts/reloader.bash" # shellcheck disable=SC2140
source "${BASH_IT}/scripts/reloader.bash" ${_bash_it_main_file_type:+"skip" "$_bash_it_main_file_type"}
# Load enabled aliases, completion, plugins BASH_IT_LOG_PREFIX="core: main: "
for file_type in "aliases" "plugins" "completion"; do
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
done done
# Load theme, if a theme was set # Load theme, if a theme was set
if [[ -n "${BASH_IT_THEME}" ]]; then # shellcheck source-path=SCRIPTDIR/themes
_log_debug "Loading \"${BASH_IT_THEME}\" theme..." if [[ -n "${BASH_IT_THEME:-}" ]]; then
_log_debug "Loading theme '${BASH_IT_THEME}'."
BASH_IT_LOG_PREFIX="themes: githelpers: " BASH_IT_LOG_PREFIX="themes: githelpers: "
# shellcheck source=./themes/githelpers.theme.bash
source "${BASH_IT}/themes/githelpers.theme.bash" source "${BASH_IT}/themes/githelpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: p4helpers: " BASH_IT_LOG_PREFIX="themes: p4helpers: "
# shellcheck source=./themes/p4helpers.theme.bash
source "${BASH_IT}/themes/p4helpers.theme.bash" source "${BASH_IT}/themes/p4helpers.theme.bash"
BASH_IT_LOG_PREFIX="themes: command_duration: "
# shellcheck source=./themes/command_duration.theme.bash
source "${BASH_IT}/themes/command_duration.theme.bash"
BASH_IT_LOG_PREFIX="themes: base: " BASH_IT_LOG_PREFIX="themes: base: "
# shellcheck source=./themes/base.theme.bash
source "${BASH_IT}/themes/base.theme.bash" source "${BASH_IT}/themes/base.theme.bash"
BASH_IT_LOG_PREFIX="lib: appearance: " BASH_IT_LOG_PREFIX="lib: appearance: "
# appearance (themes) now, after all dependencies # appearance (themes) now, after all dependencies
# shellcheck source=./lib/appearance.bash # shellcheck source=SCRIPTDIR/lib/appearance.bash
source "$APPEARANCE_LIB" source "$APPEARANCE_LIB"
BASH_IT_LOG_PREFIX="core: main: "
fi fi
BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading custom aliases, completion, plugins..." _log_debug "Loading custom aliases, completion, plugins..."
for file_type in "aliases" "completion" "plugins"; do for _bash_it_main_file_type in "aliases" "completion" "plugins"; do
if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ]; then _bash_it_main_file_custom="${BASH_IT}/${_bash_it_main_file_type}/custom.${_bash_it_main_file_type}.bash"
BASH_IT_LOG_PREFIX="${file_type}: custom: " if [[ -s "${_bash_it_main_file_custom}" ]]; then
_bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
_log_debug "Loading component..." _log_debug "Loading component..."
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "${BASH_IT}/${file_type}/custom.${file_type}.bash" source "${_bash_it_main_file_custom}"
fi fi
BASH_IT_LOG_PREFIX="core: main: "
done done
# Custom # Custom
BASH_IT_LOG_PREFIX="core: main: "
_log_debug "Loading general custom files..." _log_debug "Loading general custom files..."
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" for _bash_it_main_file_custom in "${BASH_IT_CUSTOM}"/*.bash "${BASH_IT_CUSTOM}"/*/*.bash; do
for _bash_it_config_file in $CUSTOM; do if [[ -s "${_bash_it_main_file_custom}" ]]; then
if [ -e "${_bash_it_config_file}" ]; then _bash-it-log-prefix-by-path "${_bash_it_main_file_custom}"
filename=$(basename "${_bash_it_config_file}")
filename=${filename%*.bash}
# shellcheck disable=SC2034
BASH_IT_LOG_PREFIX="custom: $filename: "
_log_debug "Loading custom file..." _log_debug "Loading custom file..."
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$_bash_it_config_file" source "$_bash_it_main_file_custom"
fi fi
BASH_IT_LOG_PREFIX="core: main: "
done done
unset _bash_it_config_file
if [[ -n "${PROMPT:-}" ]]; then if [[ -n "${PROMPT:-}" ]]; then
export PS1="\[""$PROMPT""\]" PS1="${PROMPT}"
fi fi
# Adding Support for other OSes # Adding Support for other OSes
PREVIEW="less" if _command_exists gloobus-preview; then
if [ -s /usr/bin/gloobus-preview ]; then
PREVIEW="gloobus-preview" PREVIEW="gloobus-preview"
elif [ -s /Applications/Preview.app ]; then elif [[ -d /Applications/Preview.app ]]; then
# shellcheck disable=SC2034
PREVIEW="/Applications/Preview.app" PREVIEW="/Applications/Preview.app"
else
PREVIEW="less"
fi fi
# BASH_IT_RELOAD_LEGACY is set. # BASH_IT_RELOAD_LEGACY is set.
if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then if [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]] && ! _command_exists reload; then
case $OSTYPE in # shellcheck disable=SC2139
darwin*) alias reload="builtin source '${BASH_IT_BASHRC?}'"
alias reload='source ~/.bash_profile'
;;
*)
alias reload='source ~/.bashrc'
;;
esac
fi fi
for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do for _bash_it_library_finalize_f in "${_bash_it_library_finalize_hook[@]:-}"; do
eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`. eval "${_bash_it_library_finalize_f?}" # Use `eval` to achieve the same behavior as `$PROMPT_COMMAND`.
done done
unset "${!_bash_it_library_finalize_@}" unset "${!_bash_it_library_finalize_@}" "${!_bash_it_main_file_@}"

View File

@ -16,6 +16,7 @@
# root directories # root directories
# #
aliases/
docs/ docs/
hooks/ hooks/
scripts/ scripts/
@ -28,16 +29,11 @@ clean_files.txt
install.sh install.sh
lint_clean_files.sh lint_clean_files.sh
# aliases
#
aliases/available/dnf.aliases.bash
aliases/available/git.aliases.bash
aliases/available/vim.aliases.bash
# completions # completions
# #
completion/available/apm.completion.bash completion/available/apm.completion.bash
completion/available/awless.completion.bash completion/available/awless.completion.bash
completion/available/awscli.completion.bash
completion/available/bash-it.completion.bash completion/available/bash-it.completion.bash
completion/available/brew.completion.bash completion/available/brew.completion.bash
completion/available/cargo.completion.bash completion/available/cargo.completion.bash
@ -81,10 +77,14 @@ completion/available/vuejs.completion.bash
completion/available/wpscan.completion.bash completion/available/wpscan.completion.bash
# libraries # libraries
lib/appearance.bash
lib/colors.bash lib/colors.bash
lib/command_duration.bash
lib/helpers.bash lib/helpers.bash
lib/history.bash
lib/log.bash lib/log.bash
lib/preexec.bash lib/preexec.bash
lib/preview.bash
lib/search.bash lib/search.bash
lib/utilities.bash lib/utilities.bash
@ -137,10 +137,9 @@ plugins/available/zoxide.plugin.bash
# tests # tests
# #
test/plugins/alias-completion.plugin.bats test/completion/aliases.completion.bats
test/run test/run
test/test_helper.bash test/test_helper.bash
test/test_helper_libs.bash
# themes # themes
# #
@ -158,11 +157,13 @@ themes/bobby-python
themes/brainy themes/brainy
themes/brunton themes/brunton
themes/candy themes/candy
themes/command_duration.theme.bash
themes/easy themes/easy
themes/essential themes/essential
themes/githelpers.theme.bash
themes/modern themes/modern
themes/norbu themes/norbu
themes/oh-my-posh
themes/p4helpers.theme.bash
themes/pete themes/pete
themes/powerline themes/powerline
themes/pure themes/pure

View File

@ -0,0 +1,112 @@
# shellcheck shell=bash
about-plugin 'Automatic completion of aliases'
# Load after all aliases and completions to understand what needs to be completed
# BASH_IT_LOAD_PRIORITY: 800
# References:
# http://superuser.com/a/437508/119764
# http://stackoverflow.com/a/1793178/1228454
# Automatically add completion for all aliases to commands having completion functions
function _bash-it-component-completion-callback-on-init-aliases() {
local namespace="alias_completion"
local tmp_file completion_loader alias_name line completions chars
local alias_arg_words new_completion compl_func compl_wrapper alias_defn
# create array of function completion triggers, keeping multi-word triggers together
IFS=$'\n' read -d '' -ra completions < <(complete -p)
((${#completions[@]} == 0)) && return 0
completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s)
completions=("${completions[@]#complete -}") # strip anything missed
completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s)
completions=("${completions[@]#? }") # strip anything missed
#TODO: this will fail on some completions...
# create temporary file for wrapper functions and completions
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
IFS=$'\n' read -r completion_loader < <(complete -p -D 2> /dev/null)
if [[ "${completion_loader#complete }" =~ '-F'[[:space:]]([[:alnum:]_]+)[[:space:]] ]]; then
completion_loader="${BASH_REMATCH[1]}"
else
completion_loader=""
fi
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
# some aliases do have backslashes that needs to be interpreted
# shellcheck disable=SC2162
while read line; do
line="${line#alias -- }"
line="${line#alias }"
alias_name="${line%%=*}"
alias_defn="${line#*=\'}" # alias definition
alias_defn="${alias_defn%\'}"
alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias
if [[ ${alias_defn} == ${alias_cmd} ]]; then
alias_args=''
else
alias_args="${alias_defn#*[[:space:]]}" # everything after first word
fi
# skip aliases to pipes, boolean control structures and other command lists
chars='\|\&\;\)\(\n\<\>'
if [[ "${alias_defn}" =~ [$chars] ]]; then
continue
fi
# avoid expanding wildcards
read -ra alias_arg_words <<< "$alias_args"
# skip alias if there is no completion function triggered by the aliased command
if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then
if [[ -n "$completion_loader" ]]; then
# force loading of completions for the aliased command
"${completion_loader:?}" "${alias_cmd}"
# 124 means completion loader was successful
[[ $? -eq 124 ]] || continue
completions+=("$alias_cmd")
else
continue
fi
fi
new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
# create a wrapper inserting the alias arguments if any
if [[ -n $alias_args ]]; then
compl_func="${new_completion/#* -F /}"
compl_func="${compl_func%% *}"
# avoid recursive call loops by ignoring our own functions
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
compl_wrapper="_${namespace}::${alias_name}"
echo "function $compl_wrapper {
local compl_word=\${2?}
local prec_word=\${3?}
# check if prec_word is the alias itself. if so, replace it
# with the last word in the unaliased form, i.e.,
# alias_cmd + ' ' + alias_args.
if [[ \$COMP_LINE == \"\$prec_word \$compl_word\" ]]; then
prec_word='$alias_cmd $alias_args'
prec_word=\${prec_word#* }
fi
(( COMP_CWORD += ${#alias_arg_words[@]} ))
COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[@]}\" \"\${COMP_WORDS[@]:1}\")
(( COMP_POINT -= \${#COMP_LINE} ))
COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
(( COMP_POINT += \${#COMP_LINE} ))
\"$compl_func\" \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\"
}" >> "$tmp_file"
new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
fi
fi
# replace completion trigger by alias
if [[ -n $new_completion ]]; then
new_completion="${new_completion% *} $alias_name"
echo "$new_completion" >> "$tmp_file"
fi
done < <(alias -p)
# shellcheck source=/dev/null
source "$tmp_file" && command rm -f "$tmp_file"
}
_bash-it-component-completion-callback-on-init-aliases

View File

@ -1,6 +1,5 @@
# shellcheck shell=bash # shellcheck shell=bash
if _command_exists aws_completer if _command_exists aws_completer; then
then
complete -C "$(command -v aws_completer)" aws complete -C "$(command -v aws_completer)" aws
fi fi

View File

@ -13,7 +13,7 @@ function _bash-it() {
prev="${COMP_WORDS[COMP_CWORD - 1]}" prev="${COMP_WORDS[COMP_CWORD - 1]}"
verb="${COMP_WORDS[1]}" verb="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]:-}" file_type="${COMP_WORDS[2]:-}"
candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'profile' 'doctor' 'search' 'show' 'update' 'version') candidates=('disable' 'enable' 'help' 'migrate' 'reload' 'restart' 'preview' 'profile' 'doctor' 'search' 'show' 'update' 'version')
case "${verb}" in case "${verb}" in
show) show)
candidates=('aliases' 'completions' 'plugins') candidates=('aliases' 'completions' 'plugins')
@ -59,6 +59,10 @@ function _bash-it() {
_compreply_candidates _compreply_candidates
;; ;;
migrate | reload | restart | search | version) ;; migrate | reload | restart | search | version) ;;
preview)
_bash-it-preview # completes itself
return 0
;;
enable | disable) enable | disable)
if [[ "${verb}" == "enable" ]]; then if [[ "${verb}" == "enable" ]]; then
suffix="disabled" suffix="disabled"

View File

@ -55,12 +55,12 @@ _KAC_regen_cache() {
# cached files can't have spaces in their names # cached files can't have spaces in their names
_KAC_get_cache_name_from_command() { _KAC_get_cache_name_from_command() {
echo "${@/ /_SPACE_}" echo "${@// /_SPACE_}"
} }
# the reverse operation from the function above # the reverse operation from the function above
_KAC_get_command_from_cache_name() { _KAC_get_command_from_cache_name() {
echo "${@/_SPACE_/ }" echo "${@//_SPACE_/ }"
} }
# given a command as argument, it fetches the cache for that command if it can find it # given a command as argument, it fetches the cache for that command if it can find it

View File

@ -14,31 +14,24 @@ else
__bash_it_restore_nounset=false __bash_it_restore_nounset=false
fi fi
# shellcheck disable=SC1090 disable=SC1091
if [[ -r "${BASH_COMPLETION:-}" ]]; then if [[ -r "${BASH_COMPLETION:-}" ]]; then
# shellcheck disable=SC1090
source "${BASH_COMPLETION}" source "${BASH_COMPLETION}"
elif [[ -r /etc/bash_completion ]]; then elif [[ -r /etc/bash_completion ]]; then
# shellcheck disable=SC1091
source /etc/bash_completion source /etc/bash_completion
# Some distribution makes use of a profile.d script to import completion. # Some distribution makes use of a profile.d script to import completion.
elif [[ -r /etc/profile.d/bash_completion.sh ]]; then elif [[ -r /etc/profile.d/bash_completion.sh ]]; then
# shellcheck disable=SC1091
source /etc/profile.d/bash_completion.sh source /etc/profile.d/bash_completion.sh
elif _bash_it_homebrew_check; then elif _bash_it_homebrew_check; then
: "${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}" : "${BASH_COMPLETION_COMPAT_DIR:=${BASH_IT_HOMEBREW_PREFIX}/etc/bash_completion.d}"
case "${BASH_VERSION}" in case "${BASH_VERSION}" in
1* | 2* | 3.0* | 3.1*) 1* | 2* | 3.0* | 3.1*)
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?" _log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
;; ;;
3.2* | 4.0* | 4.1*) 3.2* | 4.0* | 4.1*)
# Import version 1.x of bash-completion, if installed. # Import version 1.x of bash-completion, if installed.
BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion" BASH_COMPLETION="${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@1/etc/bash_completion"
if [[ -r "$BASH_COMPLETION" ]]; then if [[ -r "$BASH_COMPLETION" ]]; then
# shellcheck disable=SC1090
source "$BASH_COMPLETION" source "$BASH_COMPLETION"
else else
unset BASH_COMPLETION unset BASH_COMPLETION
@ -46,9 +39,8 @@ elif _bash_it_homebrew_check; then
;; ;;
4.2* | 5* | *) 4.2* | 5* | *)
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh" ]]; then if [[ -r "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh" ]]; then
# shellcheck disable=SC1091 source "${BASH_IT_HOMEBREW_PREFIX}/opt/bash-completion@2/etc/profile.d/bash_completion.sh"
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/bash_completion.sh"
fi fi
;; ;;
esac esac

View File

@ -346,6 +346,19 @@ NWinkler
:alt: :alt:
----
.. _oh_my_posh_image:
Oh-My-Posh
^^^^^^^^^^
.. image:: https://bash-it.github.io/bash-it/docs/images/oh-my-posh.png
:target: https://bash-it.github.io/bash-it/docs/images/oh-my-posh.png
:alt:
---- ----
Pete Pete

View File

@ -0,0 +1,15 @@
.. _oh-my-posh:
Oh-My-Posh Theme
================
The oh-my-posh ״theme״ is really a plug to a whole other system
of managing your prompt. To use it please start here:
`Oh-My-Posh homepage <https://ohmyposh.dev/>`_
It is beyond the scope of bash-it to install and manage oh-my-posh,
this theme is here just to make sure your OMP setup doesn't clash
with other bash-it themes. Once installed, OMP will load a default
OMP theme (jandedobbeleer), which you can then customize or override.
Note: Nerd Fonts are highly recommended, as most of the themes are graphic candies.

View File

@ -22,7 +22,7 @@ Examples:
# Disable theming # Disable theming
export BASH_IT_THEME="" export BASH_IT_THEME=""
You can easily preview the themes in your own shell using ``BASH_PREVIEW=true bash-it reload``. You can easily preview the themes in your own shell using ``bash-it preview``.
If you've created your own custom prompts, we'd love it if you shared them with everyone else! Just submit a Pull Request. If you've created your own custom prompts, we'd love it if you shared them 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>`_. You can see theme screenshots on `wiki/Themes <https://github.com/Bash-it/bash-it/wiki/Themes>`_.

View File

@ -1,19 +1,18 @@
#!/usr/bin/env bash # shellcheck shell=bash
# colored ls : "${CLICOLOR:=$(tput colors)}"
export LSCOLORS='Gxfxcxdxdxegedabagacad' export CLICOLOR
if [[ -z "$CUSTOM_THEME_DIR" ]]; then : "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"}"
CUSTOM_THEME_DIR="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"
fi
# Load the theme # Load the theme
if [[ $BASH_IT_THEME ]]; then # shellcheck disable=SC1090
if [[ -f $BASH_IT_THEME ]]; then if [[ -n "${BASH_IT_THEME:-}" ]]; then
source $BASH_IT_THEME if [[ -f "${BASH_IT_THEME}" ]]; then
elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then source "${BASH_IT_THEME}"
source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then
else source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" else
fi source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash"
fi
fi fi

View File

@ -0,0 +1,61 @@
# shellcheck shell=bash
#
# Functions for measuring and reporting how long a command takes to run.
: "${COMMAND_DURATION_START_SECONDS:=${EPOCHREALTIME:-$SECONDS}}"
: "${COMMAND_DURATION_ICON:=🕘}"
: "${COMMAND_DURATION_MIN_SECONDS:=1}"
function _command_duration_pre_exec() {
COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
}
function _dynamic_clock_icon {
local clock_hand
# clock hand value is between 90 and 9b in hexadecimal.
# so between 144 and 155 in base 10.
printf -v clock_hand '%x' $(((${1:-${SECONDS}} % 12) + 144))
printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand"
}
function _command_duration() {
[[ -n "${BASH_IT_COMMAND_DURATION:-}" ]] || return
local command_duration=0 command_start="${COMMAND_DURATION_START_SECONDS:-0}"
local -i minutes=0 seconds=0 deciseconds=0
local -i command_start_seconds="${command_start%.*}"
local -i command_start_deciseconds=$((10#${command_start##*.}))
command_start_deciseconds="${command_start_deciseconds:0:1}"
local current_time="${EPOCHREALTIME:-$SECONDS}"
local -i current_time_seconds="${current_time%.*}"
local -i current_time_deciseconds="$((10#${current_time##*.}))"
current_time_deciseconds="${current_time_deciseconds:0:1}"
if [[ "${command_start_seconds:-0}" -gt 0 ]]; then
# seconds
command_duration="$((current_time_seconds - command_start_seconds))"
if ((current_time_deciseconds >= command_start_deciseconds)); then
deciseconds="$((current_time_deciseconds - command_start_deciseconds))"
else
((command_duration -= 1))
deciseconds="$((10 - (command_start_deciseconds - current_time_deciseconds)))"
fi
else
command_duration=0
fi
if ((command_duration > 0)); then
minutes=$((command_duration / 60))
seconds=$((command_duration % 60))
fi
_dynamic_clock_icon "${command_duration}"
if ((minutes > 0)); then
printf "%s %s%dm %ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$minutes" "$seconds"
elif ((seconds >= COMMAND_DURATION_MIN_SECONDS)); then
printf "%s %s%d.%01ds" "${COMMAND_DURATION_ICON:-}" "${COMMAND_DURATION_COLOR:-}" "$seconds" "$deciseconds"
fi
}
_bash_it_library_finalize_hook+=("safe_append_preexec '_command_duration_pre_exec'")

View File

@ -8,16 +8,19 @@
: "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}" : "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}"
BASH_IT_LOAD_PRIORITY_SEPARATOR="---" BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
# Handle the different ways of running `sed` without generating a backup file based on OS # Handle the different ways of running `sed` without generating a backup file based on provenance:
# - GNU sed (Linux) uses `-i` # - GNU sed (Linux) uses `-i''`
# - BSD sed (macOS) uses `-i ''` # - BSD sed (FreeBSD/macOS/Solaris/PlayStation) uses `-i ''`
# To use this in Bash-it for inline replacements with `sed`, use the following syntax: # To use this in Bash-it for inline replacements with `sed`, use the following syntax:
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file # sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
BASH_IT_SED_I_PARAMETERS=('-i')
# shellcheck disable=SC2034 # expected for this case # shellcheck disable=SC2034 # expected for this case
case "$OSTYPE" in if sed --version > /dev/null 2>&1; then
'darwin'*) BASH_IT_SED_I_PARAMETERS=('-i' '') ;; # GNU sed accepts "long" options
esac BASH_IT_SED_I_PARAMETERS=('-i')
else
# BSD sed errors on invalid option `-`
BASH_IT_SED_I_PARAMETERS=('-i' '')
fi
function _command_exists() { function _command_exists() {
_about 'checks for existence of a command' _about 'checks for existence of a command'
@ -98,7 +101,7 @@ alias reload_plugins="$(_make_reload_alias plugin plugins)"
function bash-it() { function bash-it() {
about 'Bash-it help and maintenance' about 'Bash-it help and maintenance'
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] ' param '1: verb [one of: help | show | enable | disable | migrate | update | search | preview | version | reload | restart | doctor ] '
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
param '3: specific component [optional]' param '3: specific component [optional]'
example '$ bash-it show plugins' example '$ bash-it show plugins'
@ -108,6 +111,8 @@ function bash-it() {
example '$ bash-it migrate' example '$ bash-it migrate'
example '$ bash-it update' example '$ bash-it update'
example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]' example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]'
example '$ bash-it preview'
example '$ bash-it preview essential'
example '$ bash-it version' example '$ bash-it version'
example '$ bash-it reload' example '$ bash-it reload'
example '$ bash-it restart' example '$ bash-it restart'
@ -142,6 +147,10 @@ function bash-it() {
_bash-it-search "$component" "$@" _bash-it-search "$component" "$@"
return return
;; ;;
preview)
_bash-it-preview "$component" "$@"
return
;;
update) update)
func="_bash-it-update-$component" func="_bash-it-update-$component"
;; ;;
@ -249,10 +258,10 @@ function _bash-it_update_migrate_and_restart() {
_about 'Checks out the wanted version, pops directory and restart. Does not return (because of the restart!)' _about 'Checks out the wanted version, pops directory and restart. Does not return (because of the restart!)'
_param '1: Which branch to checkout to' _param '1: Which branch to checkout to'
_param '2: Which type of version we are using' _param '2: Which type of version we are using'
if git checkout "$1" &> /dev/null; then if git checkout "${1?}" &> /dev/null; then
echo "Bash-it successfully updated." echo "Bash-it successfully updated."
echo "" echo ""
echo "Migrating your installation to the latest $2 version now..." echo "Migrating your installation to the latest ${2:-} version now..."
_bash-it-migrate _bash-it-migrate
echo "" echo ""
echo "All done, enjoy!" echo "All done, enjoy!"
@ -269,7 +278,7 @@ function _bash-it-update-() {
_param '1: What kind of update to do (stable|dev)' _param '1: What kind of update to do (stable|dev)'
_group 'lib' _group 'lib'
local silent word DIFF version TARGET revision status revert log_color num_of_lines description i RESP local silent word DIFF version TARGET revision status revert log_color RESP
for word in "$@"; do for word in "$@"; do
if [[ "${word}" == "--silent" || "${word}" == "-s" ]]; then if [[ "${word}" == "--silent" || "${word}" == "-s" ]]; then
silent=true silent=true
@ -294,7 +303,7 @@ function _bash-it-update-() {
BASH_IT_DEVELOPMENT_BRANCH="master" BASH_IT_DEVELOPMENT_BRANCH="master"
fi fi
# Defaults to stable update # Defaults to stable update
if [[ -z "$1" || "$1" == "stable" ]]; then if [[ -z "${1:-}" || "$1" == "stable" ]]; then
version="stable" version="stable"
TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null) TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null)
@ -325,15 +334,7 @@ function _bash-it-update-() {
log_color="%Cred" log_color="%Cred"
fi fi
for i in $(git rev-list --merges --first-parent "${revision}"); do git log --format="${log_color}%h: %s (%an)" "${revision}"
num_of_lines=$(git log -1 --format=%B "$i" | awk '!/^[[:space:]]*$/ {++i} END{print i}')
if [[ "$num_of_lines" -eq 1 ]]; then
description="%s"
else
description="%b"
fi
git log --format="${log_color}%h: $description (%an)" -1 "$i"
done
echo "" echo ""
if [[ -n "${silent}" ]]; then if [[ -n "${silent}" ]]; then
@ -505,7 +506,6 @@ function _bash-it-profile-save() {
case "$RESP" in case "$RESP" in
[yY]) [yY])
echo -e "${echo_green?}Overwriting profile '$name'...${echo_reset_color?}" echo -e "${echo_green?}Overwriting profile '$name'...${echo_reset_color?}"
rm "$profile_path"
break break
;; ;;
[nN] | "") [nN] | "")
@ -537,7 +537,7 @@ function _bash-it-profile-save() {
fi fi
done done
done done
if [[ -z "$something_exists" ]]; then if [[ -z "${something_exists:-}" ]]; then
echo "It seems like no configuration was enabled.." echo "It seems like no configuration was enabled.."
echo "Make sure to double check that this is the wanted behavior." echo "Make sure to double check that this is the wanted behavior."
fi fi
@ -555,30 +555,30 @@ _bash-it-profile-load-parse-profile() {
_example '$ _bash-it-profile-load-parse-profile "profile.bash_it" "dry"' _example '$ _bash-it-profile-load-parse-profile "profile.bash_it" "dry"'
local -i num=0 local -i num=0
local line local line enable_func subdirectory component to_enable bad
while read -r -a line; do while read -r -a line; do
((++num)) ((++num))
# Ignore comments and empty lines # Ignore comments and empty lines
[[ -z "${line[*]}" || "${line[*]}" =~ ^#.* ]] && continue [[ -z "${line[*]}" || "${line[*]}" =~ ^#.* ]] && continue
local enable_func="_enable-${line[0]}" enable_func="_enable-${line[0]}"
local subdirectory=${line[0]} subdirectory=${line[0]}
local component=${line[1]} component=${line[1]}
local to_enable=("${BASH_IT}/$subdirectory/available/$component.${subdirectory%s}"*.bash) to_enable=("${BASH_IT}/$subdirectory/available/$component.${subdirectory%s}"*.bash)
# Ignore botched lines # Ignore botched lines
if [[ ! -e "${to_enable[0]}" ]]; then if [[ ! -e "${to_enable[0]}" ]]; then
echo -e "${echo_orange?}Bad line(#$num) in profile, aborting load...${line[*]}${echo_reset_color?}" echo -e "${echo_orange?}Bad line(#$num) in profile, aborting load...${line[*]}${echo_reset_color?}"
local bad="bad line" bad="bad line"
break break
fi fi
# Do not actually modify config on dry run # Do not actually modify config on dry run
[[ -z $2 ]] || continue [[ -z "${2:-}" ]] || continue
# Actually enable the component # Actually enable the component
$enable_func "$component" $enable_func "$component"
done < "$1" done < "${1?}"
# Make sure to propagate the error # Make sure to propagate the error
[[ -z $bad ]] [[ -z ${bad:-} ]]
} }
_bash-it-profile-list() { _bash-it-profile-list() {
@ -597,7 +597,7 @@ _bash-it-profile-rm() {
about 'Removes a profile from the "profiles" directory' about 'Removes a profile from the "profiles" directory'
_group 'lib' _group 'lib'
local name="$1" local name="${1:-}"
if [[ -z $name ]]; then if [[ -z $name ]]; then
echo -e "${echo_orange?}Please specify profile name to remove...${echo_reset_color?}" echo -e "${echo_orange?}Please specify profile name to remove...${echo_reset_color?}"
return 1 return 1
@ -623,7 +623,7 @@ _bash-it-profile-load() {
_about 'loads a configuration from the "profiles" directory' _about 'loads a configuration from the "profiles" directory'
_group 'lib' _group 'lib'
local name="$1" local name="${1:-}"
if [[ -z $name ]]; then if [[ -z $name ]]; then
echo -e "${echo_orange?}Please specify profile name to load, not changing configuration...${echo_reset_color?}" echo -e "${echo_orange?}Please specify profile name to load, not changing configuration...${echo_reset_color?}"
return 1 return 1
@ -654,19 +654,15 @@ function _bash-it-restart() {
_about 'restarts the shell in order to fully reload it' _about 'restarts the shell in order to fully reload it'
_group 'lib' _group 'lib'
local saved_pwd="${PWD}" init_file="${BASH_IT_BASHRC:-${HOME?}/.bashrc}" exec "${0#-}" --rcfile "${BASH_IT_BASHRC:-${HOME?}/.bashrc}"
exec "${0/-/}" --rcfile <(echo "source \"${init_file}\"; cd \"$saved_pwd\"")
} }
function _bash-it-reload() { function _bash-it-reload() {
_about 'reloads a profile file' _about 'reloads the shell initialization file'
_group 'lib' _group 'lib'
pushd "${BASH_IT?}" > /dev/null || return
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "${BASH_IT_BASHRC:-${HOME?}/.bashrc}" source "${BASH_IT_BASHRC:-${HOME?}/.bashrc}"
popd > /dev/null || return
} }
function _bash-it-describe() { function _bash-it-describe() {
@ -704,7 +700,9 @@ function _on-disable-callback() {
_group 'lib' _group 'lib'
local callback="${1}_on_disable" local callback="${1}_on_disable"
_command_exists "$callback" && "$callback" if _command_exists "$callback"; then
"$callback"
fi
} }
function _disable-all() { function _disable-all() {
@ -723,8 +721,8 @@ function _disable-plugin() {
_example '$ disable-plugin rvm' _example '$ disable-plugin rvm'
_group 'lib' _group 'lib'
_disable-thing "plugins" "plugin" "$1" _disable-thing "plugins" "plugin" "${1?}"
_on-disable-callback "$1" _on-disable-callback "${1?}"
} }
function _disable-alias() { function _disable-alias() {
@ -733,7 +731,7 @@ function _disable-alias() {
_example '$ disable-alias git' _example '$ disable-alias git'
_group 'lib' _group 'lib'
_disable-thing "aliases" "alias" "$1" _disable-thing "aliases" "alias" "${1?}"
} }
function _disable-completion() { function _disable-completion() {
@ -742,7 +740,7 @@ function _disable-completion() {
_example '$ disable-completion git' _example '$ disable-completion git'
_group 'lib' _group 'lib'
_disable-thing "completion" "completion" "$1" _disable-thing "completion" "completion" "${1?}"
} }
function _disable-thing() { function _disable-thing() {
@ -776,7 +774,7 @@ function _disable-thing() {
# Either one will be matched by this glob # Either one will be matched by this glob
for plugin in "${BASH_IT}/enabled"/[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash" "${BASH_IT}/$subdirectory/enabled/"{[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash","${file_entity}.${suffix}.bash"}; do for plugin in "${BASH_IT}/enabled"/[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash" "${BASH_IT}/$subdirectory/enabled/"{[[:digit:]][[:digit:]][[:digit:]]"${BASH_IT_LOAD_PRIORITY_SEPARATOR}${file_entity}.${suffix}.bash","${file_entity}.${suffix}.bash"}; do
if [[ -e "${plugin}" ]]; then if [[ -e "${plugin}" ]]; then
rm "${plugin}" rm -f "${plugin}"
plugin= plugin=
break break
fi fi
@ -787,10 +785,11 @@ function _disable-thing() {
fi fi
fi fi
_bash-it-clean-component-cache "${file_type}" _bash-it-component-cache-clean "${file_type}"
if [[ "$file_entity" = "all" ]]; then if [[ "$file_entity" == "all" ]]; then
printf '%s\n' "$file_entity $(_bash-it-pluralize-component "$file_type") disabled." _bash-it-component-pluralize "$file_type" file_type
printf '%s\n' "$file_entity ${file_type} disabled."
else else
printf '%s\n' "$file_entity disabled." printf '%s\n' "$file_entity disabled."
fi fi
@ -802,7 +801,7 @@ function _enable-plugin() {
_example '$ enable-plugin rvm' _example '$ enable-plugin rvm'
_group 'lib' _group 'lib'
_enable-thing "plugins" "plugin" "$1" "$BASH_IT_LOAD_PRIORITY_PLUGIN" _enable-thing "plugins" "plugin" "${1?}" "$BASH_IT_LOAD_PRIORITY_PLUGIN"
} }
function _enable-plugins() { function _enable-plugins() {
@ -816,7 +815,7 @@ function _enable-alias() {
_example '$ enable-alias git' _example '$ enable-alias git'
_group 'lib' _group 'lib'
_enable-thing "aliases" "alias" "$1" "$BASH_IT_LOAD_PRIORITY_ALIAS" _enable-thing "aliases" "alias" "${1?}" "$BASH_IT_LOAD_PRIORITY_ALIAS"
} }
function _enable-aliases() { function _enable-aliases() {
@ -830,7 +829,7 @@ function _enable-completion() {
_example '$ enable-completion git' _example '$ enable-completion git'
_group 'lib' _group 'lib'
_enable-thing "completion" "completion" "$1" "$BASH_IT_LOAD_PRIORITY_COMPLETION" _enable-thing "completion" "completion" "${1?}" "$BASH_IT_LOAD_PRIORITY_COMPLETION"
} }
function _enable-thing() { function _enable-thing() {
@ -885,7 +884,7 @@ function _enable-thing() {
ln -s "../$subdirectory/available/$to_enable" "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" ln -s "../$subdirectory/available/$to_enable" "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
fi fi
_bash-it-clean-component-cache "${file_type}" _bash-it-component-cache-clean "${file_type}"
printf '%s\n' "$file_entity enabled with priority $use_load_priority." printf '%s\n' "$file_entity enabled with priority $use_load_priority."
} }
@ -903,7 +902,7 @@ function _help-aliases() {
_example '$ alias-help' _example '$ alias-help'
_example '$ alias-help git' _example '$ alias-help git'
if [[ -n "$1" ]]; then if [[ -n "${1:-}" ]]; then
case "$1" in case "$1" in
custom) custom)
alias_path='custom.aliases.bash' alias_path='custom.aliases.bash'
@ -1016,14 +1015,14 @@ function pathmunge() {
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]` # a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
# without any external dependencies. Let the shell do what it's good at. # without any external dependencies. Let the shell do what it's good at.
function _bash-it-find-in-ancestor() ( function _bash-it-find-in-ancestor() (
about 'searches parents of the current directory for any of the specified file names' : _about 'searches parents of the current directory for any of the specified file names'
group 'helpers' : _group 'helpers'
param '*: names of files or folders to search for' : _param '*: names of files or folders to search for'
returns '0: prints path of closest matching ancestor directory to stdout' : _returns '0: prints path of closest matching ancestor directory to stdout'
returns '1: no match found' : _returns '1: no match found'
returns '2: improper usage of shell builtin' # uncommon : _returns '2: improper usage of shell builtin' # uncommon
example '_bash-it-find-in-ancestor .git .hg' : _example '_bash-it-find-in-ancestor .git .hg'
example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile' : _example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile'
local kin local kin
# To keep things simple, we do not search the root dir. # To keep things simple, we do not search the root dir.

49
lib/history.bash 100644
View File

@ -0,0 +1,49 @@
# shellcheck shell=bash
#
# Functions for working with Bash's command history.
function _bash-it-history-init() {
safe_append_preexec '_bash-it-history-auto-save'
safe_append_prompt_command '_bash-it-history-auto-load'
}
function _bash-it-history-auto-save() {
case $HISTCONTROL in
*'noauto'* | *'autoload'*)
: # Do nothing, as configured.
;;
*'auto'*)
# Append new history from this session to the $HISTFILE
history -a
;;
*)
# Append *only* if shell option `histappend` has been enabled.
shopt -q histappend && history -a && return
;;
esac
}
function _bash-it-history-auto-load() {
case $HISTCONTROL in
*'noauto'*)
: # Do nothing, as configured.
;;
*'autosave'*)
# Append new history from this session to the $HISTFILE
history -a
;;
*'autoloadnew'*)
# Read new entries from $HISTFILE
history -n
;;
*'auto'*)
# Blank in-memory history, then read entire $HISTFILE fresh from disk.
history -a && history -c && history -r
;;
*)
: # Do nothing, default.
;;
esac
}
_bash_it_library_finalize_hook+=('_bash-it-history-init')

View File

@ -45,46 +45,56 @@ function _bash-it-log-prefix-by-path() {
function _has_colors() { function _has_colors() {
# Check that stdout is a terminal, and that it has at least 8 colors. # Check that stdout is a terminal, and that it has at least 8 colors.
[[ -t 1 && "${_bash_it_available_colors:=$(tput colors 2> /dev/null)}" -ge 8 ]] [[ -t 1 && "${CLICOLOR:=$(tput colors 2> /dev/null)}" -ge 8 ]]
} }
function _bash-it-log-message() { function _bash-it-log-message() {
about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix' : _about 'Internal function used for logging, uses BASH_IT_LOG_PREFIX as a prefix'
param '1: color of the message' : _param '1: color of the message'
param '2: log level to print before the prefix' : _param '2: log level to print before the prefix'
param '3: message to log' : _param '3: message to log'
group 'log' : _group 'log'
message="$2${BASH_IT_LOG_PREFIX:-default: }$3" local prefix="${BASH_IT_LOG_PREFIX:-default}"
_has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}" local color="${1-${echo_cyan:-}}"
local level="${2:-TRACE}"
local message="${level%: }: ${prefix%: }: ${3?}"
if _has_colors; then
printf '%b%s%b\n' "${color}" "${message}" "${echo_normal:-}"
else
printf '%s\n' "${message}"
fi
} }
function _log_debug() { function _log_debug() {
about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_INFO' : _about 'log a debug message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_INFO'
param '1: message to log' : _param '1: message to log'
example '$ _log_debug "Loading plugin git..."' : _example '$ _log_debug "Loading plugin git..."'
group 'log' : _group 'log'
[[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_INFO?}" ]] || return 0 if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_INFO?}" ]]; then
_bash-it-log-message "${echo_green:-}" "DEBUG: " "$1" _bash-it-log-message "${echo_green:-}" "DEBUG: " "$1"
fi
} }
function _log_warning() { function _log_warning() {
about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING' : _about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_WARNING'
param '1: message to log' : _param '1: message to log'
example '$ _log_warning "git binary not found, disabling git plugin..."' : _example '$ _log_warning "git binary not found, disabling git plugin..."'
group 'log' : _group 'log'
[[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_WARNING?}" ]] || return 0 if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_WARNING?}" ]]; then
_bash-it-log-message "${echo_yellow:-}" " WARN: " "$1" _bash-it-log-message "${echo_yellow:-}" " WARN: " "$1"
fi
} }
function _log_error() { function _log_error() {
about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR' : _about 'log a message by echoing to the screen. needs BASH_IT_LOG_LEVEL >= BASH_IT_LOG_LEVEL_ERROR'
param '1: message to log' : _param '1: message to log'
example '$ _log_error "Failed to load git plugin..."' : _example '$ _log_error "Failed to load git plugin..."'
group 'log' : _group 'log'
[[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_ERROR?}" ]] || return 0 if [[ "${BASH_IT_LOG_LEVEL:-0}" -ge "${BASH_IT_LOG_LEVEL_ERROR?}" ]]; then
_bash-it-log-message "${echo_red:-}" "ERROR: " "$1" _bash-it-log-message "${echo_red:-}" "ERROR: " "$1"
fi
} }

View File

@ -4,9 +4,8 @@
# Load the `bash-preexec.sh` library, and define helper functions # Load the `bash-preexec.sh` library, and define helper functions
## Prepare, load, fix, and install `bash-preexec.sh` ## Prepare, load, fix, and install `bash-preexec.sh`
: "${PROMPT_COMMAND:=}"
# Disable immediate `$PROMPT_COMMAND` modification # Disable `$PROMPT_COMMAND` modification for now.
__bp_delay_install="delayed" __bp_delay_install="delayed"
# shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec # shellcheck source-path=SCRIPTDIR/../vendor/github.com/rcaloras/bash-preexec
@ -18,12 +17,12 @@ function __bp_adjust_histcontrol() { :; }
# Don't fail on readonly variables # Don't fail on readonly variables
function __bp_require_not_readonly() { :; } function __bp_require_not_readonly() { :; }
# Disable trap DEBUG on subshells - https://github.com/Bash-it/bash-it/pull/1040 # For performance, testing, and to avoid unexpected behavior: disable DEBUG traps in subshells.
__bp_enable_subshells= # blank # See bash-it/bash-it#1040 and rcaloras/bash-preexec#26
set +T : "${__bp_enable_subshells:=}" # blank
# Modify `$PROMPT_COMMAND` now # Modify `$PROMPT_COMMAND` in finalize hook
__bp_install_after_session_init _bash_it_library_finalize_hook+=('__bp_install_after_session_init')
## Helper functions ## Helper functions
function __check_precmd_conflict() { function __check_precmd_conflict() {
@ -38,26 +37,20 @@ function __check_preexec_conflict() {
_bash-it-array-contains-element "${f}" "${preexec_functions[@]}" _bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
} }
function safe_append_prompt_command { function safe_append_prompt_command() {
local prompt_re f local prompt_re prompt_er f
__bp_trim_whitespace f "${1?}"
if [ "${__bp_imported:-missing}" == "defined" ]; then if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
# We are using bash-preexec # We are using bash-preexec
__bp_trim_whitespace f "${1?}"
if ! __check_precmd_conflict "${f}"; then if ! __check_precmd_conflict "${f}"; then
precmd_functions+=("${f}") precmd_functions+=("${f}")
fi fi
else else
# Set OS dependent exact match regular expression # Match on word-boundaries
if [[ ${OSTYPE} == darwin* ]]; then prompt_re='(^|[^[:alnum:]_])'
# macOS prompt_er='([^[:alnum:]_]|$)'
prompt_re="[[:<:]]${1}[[:>:]]" if [[ ${PROMPT_COMMAND} =~ ${prompt_re}"${1}"${prompt_er} ]]; then
else
# Linux, FreeBSD, etc.
prompt_re="\<${1}\>"
fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
return return
elif [[ -z ${PROMPT_COMMAND} ]]; then elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}" PROMPT_COMMAND="${1}"
@ -67,12 +60,12 @@ function safe_append_prompt_command {
fi fi
} }
function safe_append_preexec { function safe_append_preexec() {
local prompt_re f local prompt_re f
__bp_trim_whitespace f "${1?}"
if [ "${__bp_imported:-missing}" == "defined" ]; then if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
# We are using bash-preexec # We are using bash-preexec
__bp_trim_whitespace f "${1?}"
if ! __check_preexec_conflict "${f}"; then if ! __check_preexec_conflict "${f}"; then
preexec_functions+=("${f}") preexec_functions+=("${f}")
fi fi

View File

@ -1,19 +1,34 @@
if [[ "${BASH_PREVIEW:-}" ]]; # shellcheck shell=bash
then #
unset BASH_PREVIEW #Prevent infinite looping # Displays the prompt from each _Bash It_ theme.
echo "
Previewing Bash-it Themes function _bash-it-preview() {
local BASH_IT_THEME BASH_IT_LOG_LEVEL
local themes IFS=$'\n' cur
" if [[ $# -gt '0' ]]; then
themes=("$@")
else
themes=("${BASH_IT?}/themes"/*/*.theme.bash)
themes=("${themes[@]##*/}")
themes=("${themes[@]%.theme.bash}")
fi
THEMES="$BASH_IT/themes/*/*.theme.bash" if [[ ${COMP_CWORD:-} -gt '0' ]]; then
for theme in $THEMES cur="${COMP_WORDS[COMP_CWORD]}"
do read -d '' -ra COMPREPLY < <(compgen -W "all${IFS}${themes[*]}" -- "${cur}")
BASH_IT_THEME=${theme%.theme.bash} return
BASH_IT_THEME=${BASH_IT_THEME##*/} fi
echo " printf '\n\n\t%s\n\n' "Previewing Bash-it Themes"
$BASH_IT_THEME"
echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i # shellcheck disable=SC2034
done for BASH_IT_THEME in "${themes[@]}"; do
BASH_IT_LOG_LEVEL=0
bash --init-file "${BASH_IT?}/bash_it.sh" -i <<< '_bash-it-flash-term "${#BASH_IT_THEME}" "${BASH_IT_THEME}"'
done
}
if [[ -n "${BASH_PREVIEW:-}" ]]; then
_bash-it-preview "${BASH_PREVIEW}" "$@"
unset BASH_PREVIEW #Prevent infinite looping
fi fi

View File

@ -70,7 +70,7 @@ function _bash-it-search() {
return 0 return 0
;; ;;
'-r' | '--refresh') '-r' | '--refresh')
_bash-it-clean-component-cache _bash-it-component-cache-clean
;; ;;
'-c' | '--no-color') '-c' | '--no-color')
BASH_IT_SEARCH_USE_COLOR=false BASH_IT_SEARCH_USE_COLOR=false
@ -266,9 +266,11 @@ function _bash-it-search-result() {
shift shift
local color_component color_enable color_disable color_off local color_component color_enable color_disable color_off
local color_sep=':' line local match_color compatible_action suffix opposite_suffix
local color_sep=':' line match matched temp
local -i modified=0 enabled=0 len
local -a matches=() local -a matches=()
# Discard any empty arguments # Discard any empty arguments
while IFS='' read -r line; do while IFS='' read -r line; do
[[ -n "${line}" ]] && matches+=("$line") [[ -n "${line}" ]] && matches+=("$line")
@ -290,18 +292,13 @@ function _bash-it-search-result() {
color_off='' color_off=''
fi fi
local match
local -i modified=0
if [[ "${#matches[@]}" -gt 0 ]]; then if [[ "${#matches[@]}" -gt 0 ]]; then
printf "${color_component}%13s${color_sep}${color_off} " "${component}" printf "${color_component}%13s${color_sep}${color_off} " "${component}"
for match in "${matches[@]}"; do for match in "${matches[@]}"; do
local -i enabled=0 enabled=0
_bash-it-component-item-is-enabled "${component}" "${match}" && enabled=1 _bash-it-component-item-is-enabled "${component}" "${match}" && enabled=1
local match_color compatible_action suffix opposite_suffix
if ((enabled)); then if ((enabled)); then
match_color="${color_enable}" match_color="${color_enable}"
suffix="${suffix_enable}" suffix="${suffix_enable}"
@ -314,8 +311,8 @@ function _bash-it-search-result() {
compatible_action="enable" compatible_action="enable"
fi fi
local matched="${match}${suffix}" matched="${match}${suffix}"
local -i len="${#matched}" len="${#matched}"
printf '%b' "${match_color}${matched}" # print current state printf '%b' "${match_color}${matched}" # print current state
if [[ "${action}" == "${compatible_action}" ]]; then if [[ "${action}" == "${compatible_action}" ]]; then
@ -327,7 +324,7 @@ function _bash-it-search-result() {
modified=1 modified=1
# shellcheck disable=SC2034 # no idea if `$result` is ever used # shellcheck disable=SC2034 # no idea if `$result` is ever used
result=$("${action_func}" "${match}") result=$("${action_func}" "${match}")
local temp="color_${compatible_action}" temp="color_${compatible_action}"
match_color="${!temp}" match_color="${!temp}"
_bash-it-rewind "${len}" _bash-it-rewind "${len}"
printf '%b' "${match_color}${match}${opposite_suffix}" printf '%b' "${match_color}${match}${opposite_suffix}"
@ -336,7 +333,7 @@ function _bash-it-search-result() {
printf '%b' "${color_off} " printf '%b' "${color_off} "
done done
((modified)) && _bash-it-clean-component-cache "${component}" ((modified)) && _bash-it-component-cache-clean "${component}"
printf "\n" printf "\n"
fi fi
} }
@ -350,7 +347,7 @@ function _bash-it-flash-term() {
local -i len="${1:-0}" # redundant local -i len="${1:-0}" # redundant
local term="${2:-}" local term="${2:-}"
# as currently implemented, `$match` has already been printed to screen the first time # as currently implemented, `$match` has already been printed to screen the first time
local delay=0.1 local delay=0.2
local color local color
[[ "${#term}" -gt 0 ]] && len="${#term}" [[ "${#term}" -gt 0 ]] && len="${#term}"

View File

@ -62,13 +62,13 @@ function _bash-it-array-dedup() {
# Outputs a full path of the grep found on the filesystem # Outputs a full path of the grep found on the filesystem
function _bash-it-grep() { function _bash-it-grep() {
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}"
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}" printf "%s" "${BASH_IT_GREP:-/usr/bin/grep}"
} }
# Runs `grep` with extended regular expressions # Runs `grep` with extended regular expressions
function _bash-it-egrep() { function _bash-it-egrep() {
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}" : "${BASH_IT_GREP:=$(type -P egrep || type -P grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@" "${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
} }
@ -91,7 +91,7 @@ function _bash-it-component-help() {
function _bash-it-component-cache-file() { function _bash-it-component-cache-file() {
local _component_to_cache _file_path _result="${2:-${FUNCNAME[0]//-/_}}" local _component_to_cache _file_path _result="${2:-${FUNCNAME[0]//-/_}}"
_bash-it-component-pluralize "${1?${FUNCNAME[0]}: component name required}" _component_to_cache _bash-it-component-pluralize "${1?${FUNCNAME[0]}: component name required}" _component_to_cache
_file_path="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${_component_to_cache?}" _file_path="${XDG_CACHE_HOME:-${HOME?}/.cache}/bash/${_component_to_cache?}"
[[ -f "${_file_path}" ]] || mkdir -p "${_file_path%/*}" [[ -f "${_file_path}" ]] || mkdir -p "${_file_path%/*}"
printf -v "${_result?}" '%s' "${_file_path}" printf -v "${_result?}" '%s' "${_file_path}"
} }
@ -121,19 +121,17 @@ function _bash-it-component-pluralize() {
printf -v "${_result?}" '%s' "${_component_to_plural}" printf -v "${_result?}" '%s' "${_component_to_plural}"
} }
function _bash-it-clean-component-cache() { function _bash-it-component-cache-clean() {
local component="$1" local component="${1:-}"
local cache local cache
local -a BASH_IT_COMPONENTS=(aliases plugins completions) local -a components=('aliases' 'plugins' 'completions')
if [[ -z "${component}" ]]; then if [[ -z "${component}" ]]; then
for component in "${BASH_IT_COMPONENTS[@]}"; do for component in "${components[@]}"; do
_bash-it-clean-component-cache "${component}" _bash-it-component-cache-clean "${component}"
done done
else else
_bash-it-component-cache-file "${component}" cache _bash-it-component-cache-file "${component}" cache
if [[ -f "${cache}" ]]; then : >| "${cache:?}"
rm -f "${cache}"
fi
fi fi
} }
@ -170,18 +168,22 @@ function _bash-it-component-list-disabled() {
function _bash-it-component-item-is-enabled() { function _bash-it-component-item-is-enabled() {
local component_type item_name each_file local component_type item_name each_file
if [[ -f "${1}" ]]; then if [[ -f "${1?}" ]]; then
item_name="$(_bash-it-get-component-name-from-path "${1}")" item_name="$(_bash-it-get-component-name-from-path "${1}")"
component_type="$(_bash-it-get-component-type-from-path "${1}")" component_type="$(_bash-it-get-component-type-from-path "${1}")"
else else
component_type="${1}" item_name="${2}" component_type="${1}" item_name="${2?}"
fi fi
for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \ for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \
"${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \ "${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \
"${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do "${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do
[[ -f "${each_file}" ]] && return if [[ -f "${each_file}" ]]; then
return 0
fi
done done
return 1
} }
# Checks if a given item is disabled for a particular component/file-type. # Checks if a given item is disabled for a particular component/file-type.

View File

@ -1,105 +1,5 @@
# shellcheck shell=bash # shellcheck shell=bash
# Load after the other completions to understand what needs to be completed # stub for renamed file
# BASH_IT_LOAD_PRIORITY: 365
cite about-plugin _enable-completion aliases && _disable-plugin alias-completion
about-plugin 'Automatic completion of aliases' source "${BASH_IT?}/completion/available/aliases.completion.bash"
# References:
# http://superuser.com/a/437508/119764
# http://stackoverflow.com/a/1793178/1228454
# This needs to be a plugin so it gets executed after the completions and the aliases have been defined.
# Bash-it loads its components in the order
# 1) Aliases
# 2) Completions
# 3) Plugins
# 4) Custom scripts
# Automatically add completion for all aliases to commands having completion functions
function alias_completion {
local namespace="alias_completion"
local tmp_file completion_loader alias_name alias_tokens line completions
local alias_arg_words new_completion compl_func compl_wrapper
# parse function based completion definitions, where capture group 2 => function and 3 => trigger
local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
# parse alias definitions, where capture group 1 => trigger, 2 => command, 3 => command arguments
local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
# create array of function completion triggers, keeping multi-word triggers together
eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
((${#completions[@]} == 0)) && return 0
# create temporary file for wrapper functions and completions
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')"
# read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
# some aliases do have backslashes that needs to be interpreted
# shellcheck disable=SC2162
while read line; do
eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error
# shellcheck disable=SC2154 # see `eval` above
alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }"
# skip aliases to pipes, boolean control structures and other command lists
# (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
eval "alias_arg_words=($alias_args)" 2> /dev/null || continue
# avoid expanding wildcards
read -a alias_arg_words <<< "$alias_args"
# skip alias if there is no completion function triggered by the aliased command
if ! _bash-it-array-contains-element "$alias_cmd" "${completions[@]}"; then
if [[ -n "$completion_loader" ]]; then
# force loading of completions for the aliased command
eval "$completion_loader $alias_cmd"
# 124 means completion loader was successful
[[ $? -eq 124 ]] || continue
completions+=("$alias_cmd")
else
continue
fi
fi
new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
# create a wrapper inserting the alias arguments if any
if [[ -n $alias_args ]]; then
compl_func="${new_completion/#* -F /}"
compl_func="${compl_func%% *}"
# avoid recursive call loops by ignoring our own functions
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
compl_wrapper="_${namespace}::${alias_name}"
echo "function $compl_wrapper {
local compl_word=\$2
local prec_word=\$3
# check if prec_word is the alias itself. if so, replace it
# with the last word in the unaliased form, i.e.,
# alias_cmd + ' ' + alias_args.
if [[ \$COMP_LINE == \"\$prec_word \$compl_word\" ]]; then
prec_word='$alias_cmd $alias_args'
prec_word=\${prec_word#* }
fi
(( COMP_CWORD += ${#alias_arg_words[@]} ))
COMP_WORDS=($alias_cmd $alias_args \${COMP_WORDS[@]:1})
(( COMP_POINT -= \${#COMP_LINE} ))
COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
(( COMP_POINT += \${#COMP_LINE} ))
$compl_func \"$alias_cmd\" \"\$compl_word\" \"\$prec_word\"
}" >> "$tmp_file"
new_completion="${new_completion/ -F $compl_func / -F $compl_wrapper }"
fi
fi
# replace completion trigger by alias
if [[ -n $new_completion ]]; then
new_completion="${new_completion% *} $alias_name"
echo "$new_completion" >> "$tmp_file"
fi
done < <(alias -p | sed -Ene "s/$alias_regex/\2 '\3' '\4'/p")
# shellcheck source=/dev/null
source "$tmp_file" && command rm -f "$tmp_file"
}
alias_completion

View File

@ -2,8 +2,10 @@
about-plugin 'display info about your battery charge level' about-plugin 'display info about your battery charge level'
function ac_adapter_connected() { function ac_adapter_connected() {
local batteries
if _command_exists upower; then if _command_exists upower; then
upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'charging\|fully-charged' IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'charging\|fully-charged'
elif _command_exists acpi; then elif _command_exists acpi; then
acpi -a | grep -q "on-line" acpi -a | grep -q "on-line"
elif _command_exists pmset; then elif _command_exists pmset; then
@ -16,8 +18,10 @@ function ac_adapter_connected() {
} }
function ac_adapter_disconnected() { function ac_adapter_disconnected() {
local batteries
if _command_exists upower; then if _command_exists upower; then
upower -i "$(upower -e | grep -i BAT)" | grep 'state' | grep -q 'discharging' IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
upower -i "${batteries[0]:-}" | grep 'state' | grep -q 'discharging'
elif _command_exists acpi; then elif _command_exists acpi; then
acpi -a | grep -q "off-line" acpi -a | grep -q "off-line"
elif _command_exists pmset; then elif _command_exists pmset; then
@ -33,16 +37,17 @@ function battery_percentage() {
about 'displays battery charge as a percentage of full (100%)' about 'displays battery charge as a percentage of full (100%)'
group 'battery' group 'battery'
local command_output="no" local command_output batteries
if _command_exists upower; then if _command_exists upower; then
command_output=$(upower --show-info "$(upower --enumerate | grep -i BAT)" | grep percentage | grep -o "[0-9]\+" | head -1) IFS=$'\n' read -d '' -ra batteries < <(upower -e | grep -i BAT)
command_output="$(upower --show-info "${batteries[0]:-}" | grep percentage | grep -o '[0-9]\+' | head -1)"
elif _command_exists acpi; then elif _command_exists acpi; then
command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}') command_output=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}')
elif _command_exists pmset; then elif _command_exists pmset; then
command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o "[0-9]\+" | head -1) command_output=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p' | grep -o '[0-9]\+' | head -1)
elif _command_exists ioreg; then 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) 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 elif _command_exists WMIC; then
command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1) command_output=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List | grep -o '[0-9]\+' | head -1)
else else

View File

@ -10,7 +10,7 @@ fi
_bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh _bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh
if [[ -f $_bash_it_ble_path ]]; then if [[ -f $_bash_it_ble_path ]]; then
# shellcheck disable=1090 # shellcheck disable=1090
source "$_bash_it_ble_path" source "$_bash_it_ble_path" --attach=prompt
else else
_log_error "Could not find ble.sh in $_bash_it_ble_path" _log_error "Could not find ble.sh in $_bash_it_ble_path"
_log_error "Please install using the following command:" _log_error "Please install using the following command:"

View File

@ -2,15 +2,15 @@
cite about-plugin cite about-plugin
about-plugin 'Alert (BEL) when process ends after a threshold of seconds' about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
precmd_return_notification() { function precmd_return_notification() {
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)})) local command_start="${COMMAND_DURATION_START_SECONDS:=0}"
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a" local current_time="${EPOCHREALTIME:-$SECONDS}"
export LAST_COMMAND_TIME= local -i command_duration="$((${current_time%.*} - ${command_start%.*}))"
if [[ "${command_duration}" -gt "${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5}" ]]; then
printf '\a'
fi
return 0
} }
preexec_return_notification() { safe_append_prompt_command 'precmd_return_notification'
[[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s) safe_append_preexec '_command_duration_pre_exec'
}
precmd_functions+=(precmd_return_notification)
preexec_functions+=(preexec_return_notification)

View File

@ -59,7 +59,7 @@ function dirs-help() {
# Add bookmarking functionality # Add bookmarking functionality
# Usage: # Usage:
: "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-~/.local/state}/bash_it/dirs}" : "${BASH_IT_DIRS_BKS:=${XDG_STATE_HOME:-${HOME}/.local/state}/bash_it/dirs}"
if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then if [[ -f "${BASH_IT_DIRS_BKS?}" ]]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "${BASH_IT_DIRS_BKS?}" source "${BASH_IT_DIRS_BKS?}"

View File

@ -1,20 +1,22 @@
# shellcheck shell=bash # shellcheck shell=bash
about-plugin 'eternal bash history' about-plugin 'eternal bash history'
# Load after the history plugin if [[ ${BASH_VERSINFO[0]} -lt 4 ]] || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1]} -lt 3 ]]; then
# BASH_IT_LOAD_PRIORITY: 375 _log_warning "Bash version 4.3 introduced the 'unlimited' history size capability."
return 1
fi
# Modify history sizes before changing location to avoid unintentionally # Modify history sizes before changing location to avoid unintentionally
# truncating the history file early. # truncating the history file early.
# "Numeric values less than zero result in every command being saved on the history list (there is no limit)" # "Numeric values less than zero result in every command being saved on the history list (there is no limit)"
export HISTSIZE=-1 readonly HISTSIZE=-1 2> /dev/null || true
# "Non-numeric values and numeric values less than zero inhibit truncation" # "Non-numeric values and numeric values less than zero inhibit truncation"
export HISTFILESIZE='unlimited' readonly HISTFILESIZE='unlimited' 2> /dev/null || true
# Use a custom history file location so history is not truncated # Use a custom history file location so history is not truncated
# if the environment ever loses this "eternal" configuration. # if the environment ever loses this "eternal" configuration.
HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash" HISTDIR="${XDG_STATE_HOME:-${HOME?}/.local/state}/bash"
[[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}" [[ -d ${HISTDIR?} ]] || mkdir -p "${HISTDIR?}"
export HISTFILE="${HISTDIR?}/history" readonly HISTFILE="${HISTDIR?}/history" 2> /dev/null || true

View File

@ -1,9 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
about-plugin 'search history using the prefix already entered' about-plugin 'search history using the prefix already entered'
# Load after the history plugin
# BASH_IT_LOAD_PRIORITY: 375
# enter a few characters and press UpArrow/DownArrow # enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history # to search backwards/forwards through the history
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

View File

@ -1,9 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
about-plugin 'search history using the substring already entered' about-plugin 'search history using the substring already entered'
# Load after the history plugin
# BASH_IT_LOAD_PRIORITY: 375
# enter a few characters and press UpArrow/DownArrow # enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history # to search backwards/forwards through the history
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then if [[ ${SHELLOPTS} =~ (vi|emacs) ]]; then

View File

@ -5,14 +5,13 @@ about-plugin 'improve history handling with sane defaults'
# variable when the shell exits, rather than overwriting the file. # variable when the shell exits, rather than overwriting the file.
shopt -s histappend shopt -s histappend
# erase duplicates; alternative option: export HISTCONTROL=ignoredups # 'ignorespace': don't save command lines which begin with a space to history
export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups} # 'erasedups' (alternative 'ignoredups'): don't save duplicates to history
# 'autoshare': automatically share history between multiple running shells
: "${HISTCONTROL:=ignorespace:erasedups:autoshare}"
# resize history to 100x the default (500) # resize history to 100x the default (500)
export HISTSIZE=${HISTSIZE:-50000} : "${HISTSIZE:=50000}"
# Flush history to disk after each command.
export PROMPT_COMMAND="history -a;${PROMPT_COMMAND}"
function top-history() { function top-history() {
about 'print the name and count of the most commonly run tools' about 'print the name and count of the most commonly run tools'

View File

@ -1,10 +1,10 @@
# This is the default profile of Bash-it # This is the default profile of Bash-it
# plugins # plugins
plugins alias-completion
plugins base plugins base
# completion # completion
completion aliases
completion bash-it completion bash-it
completion system completion system

View File

@ -1,19 +1,11 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup {
setup_test_fixture
function local_setup_file() {
# Copy the test fixture to the Bash-it folder # Copy the test fixture to the Bash-it folder
if command -v rsync &> /dev/null cp -fRP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" || true
then # don't load any libraries as the tests here test the *whole* kit
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
else
find "$BASH_IT/test/fixtures/bash_it" \
-mindepth 1 -maxdepth 1 \
-exec cp -r {} "$BASH_IT/" \;
fi
} }
@test "bash-it: verify that the test fixture is available" { @test "bash-it: verify that the test fixture is available" {

View File

@ -1,27 +1,30 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../completion/available/capistrano.completion function local_setup_file() {
setup_libs "helpers"
# Load something, anything...
load ../../completion/available/capistrano.completion
}
@test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" { @test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" {
alias gtest="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 gtest="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"
load ../../plugins/available/alias-completion.plugin run load "${BASH_IT?}/completion/available/aliases.completion.bash"
assert_success assert_success
} }
@test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" { @test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" {
alias gtest='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 gtest='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'
load ../../plugins/available/alias-completion.plugin run load "${BASH_IT?}/completion/available/aliases.completion.bash"
assert_success assert_success
} }
@test "alias-completion: See that having aliased rm command does not output unnecessary output" { @test "alias-completion: See that having aliased rm command does not output unnecessary output" {
alias rm='rm -v' alias rm='rm -v'
load ../../plugins/available/alias-completion.plugin run load "${BASH_IT?}/completion/available/aliases.completion.bash"
refute_output refute_output
} }

View File

@ -1,17 +1,16 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../../lib/utilities
load ../../lib/helpers
load ../../completion/available/bash-it.completion
function local_setup { function local_setup_file() {
setup_test_fixture setup_libs "helpers"
load "${BASH_IT?}/completion/available/bash-it.completion.bash"
} }
@test "completion bash-it: ensure that the _bash-it function is available" { @test "completion bash-it: ensure that the _bash-it function is available" {
type -a _bash-it &> /dev/null run type -t _bash-it
assert_success assert_success
assert_output "function"
} }
function __check_completion () { function __check_completion () {
@ -81,32 +80,32 @@ function __check_completion () {
@test "completion bash-it: show options" { @test "completion bash-it: show options" {
run __check_completion 'bash-it ' run __check_completion 'bash-it '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bash-ti - show options" { @test "completion bash-it: bash-ti - show options" {
run __check_completion 'bash-ti ' run __check_completion 'bash-ti '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: shit - show options" { @test "completion bash-it: shit - show options" {
run __check_completion 'shit ' run __check_completion 'shit '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bashit - show options" { @test "completion bash-it: bashit - show options" {
run __check_completion 'bashit ' run __check_completion 'bashit '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: batshit - show options" { @test "completion bash-it: batshit - show options" {
run __check_completion 'batshit ' run __check_completion 'batshit '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: bash_it - show options" { @test "completion bash-it: bash_it - show options" {
run __check_completion 'bash_it ' run __check_completion 'bash_it '
assert_line -n 0 "disable enable help migrate reload restart profile doctor search show update version" assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version"
} }
@test "completion bash-it: profile - show options" { @test "completion bash-it: profile - show options" {

View File

@ -1,8 +1,8 @@
# plugins # plugins
plugins alias-completion
plugins base plugins base
# completion # completion
completion aliases
completion bash-it completion bash-it
completion system completion system

View File

@ -1,10 +1,10 @@
# plugins # plugins
plugins alias-completion
plugins base plugins base
# Bad type # Bad type
pluugins alias-completion compleetion aliases
# completion # completion
completion aliases
completion bash-it completion bash-it
completion system completion system

View File

@ -1,19 +1,22 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
# Determine which config file to use based on OS. function local_setup() {
case $OSTYPE in export HOME="$BATS_TEST_TMPDIR"
darwin*) }
export BASH_IT_CONFIG_FILE=.bash_profile
;;
*)
export BASH_IT_CONFIG_FILE=.bashrc
;;
esac
function local_setup { function local_setup_file() {
setup_test_fixture # 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
# don't load any libraries as the tests here test the *whole* kit
} }
@test "install: verify that the install script exists" { @test "install: verify that the install script exists" {
@ -25,11 +28,11 @@ function local_setup {
./install.sh --silent ./install.sh --silent
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
} }
@ -37,16 +40,16 @@ function local_setup {
@test "install: verify that a backup file is created" { @test "install: verify that a backup file is created" {
cd "$BASH_IT" cd "$BASH_IT"
touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" touch "$HOME/$BASH_IT_CONFIG_FILE"
echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
./install.sh --silent ./install.sh --silent
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
assert_equal "$md5_orig" "$md5_bak" assert_equal "$md5_orig" "$md5_bak"
} }
@ -70,15 +73,15 @@ function local_setup {
@test "install: verify that the template is appended" { @test "install: verify that the template is appended" {
cd "$BASH_IT" cd "$BASH_IT"
touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" touch "$HOME/$BASH_IT_CONFIG_FILE"
echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE"
./install.sh --silent --append-to-config ./install.sh --silent --append-to-config
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
run cat $BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE run cat "$HOME/$BASH_IT_CONFIG_FILE"
assert_line "test file content" assert_line "test file content"
assert_line "source \"\$BASH_IT\"/bash_it.sh" assert_line "source \"\$BASH_IT\"/bash_it.sh"

View File

@ -1,19 +1,22 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
# Determine which config file to use based on OS. function local_setup() {
case $OSTYPE in export HOME="$BATS_TEST_TMPDIR"
darwin*) }
export BASH_IT_CONFIG_FILE=.bash_profile
;;
*)
export BASH_IT_CONFIG_FILE=.bashrc
;;
esac
function local_setup { function local_setup_file() {
setup_test_fixture # 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
# don't load any libraries as the tests here test the *whole* kit
} }
@test "uninstall: verify that the uninstall script exists" { @test "uninstall: verify that the uninstall script exists" {
@ -23,19 +26,18 @@ function local_setup {
@test "uninstall: run the uninstall script with an existing backup file" { @test "uninstall: run the uninstall script with an existing backup file" {
cd "$BASH_IT" cd "$BASH_IT"
echo "test file content for backup" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak"
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}')
./uninstall.sh
run ./uninstall.sh
assert_success assert_success
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE"
local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
assert_equal "$md5_bak" "$md5_conf" assert_equal "$md5_bak" "$md5_conf"
} }
@ -43,18 +45,17 @@ function local_setup {
@test "uninstall: run the uninstall script without an existing backup file" { @test "uninstall: run the uninstall script without an existing backup file" {
cd "$BASH_IT" cd "$BASH_IT"
echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE"
local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}')
./uninstall.sh
run ./uninstall.sh
assert_success assert_success
assert_file_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak"
assert_file_not_exist "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE"
local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}')
assert_equal "$md5_orig" "$md5_uninstall" assert_equal "$md5_orig" "$md5_uninstall"
} }

View File

@ -1,6 +1,11 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
function local_setup_file() {
true
# don't load any libraries as the tests here test the *whole* kit
}
@test "lib composure: _composure_keywords()" { @test "lib composure: _composure_keywords()" {
run _composure_keywords run _composure_keywords

28
test/lib/helpers.bats 100755 → 100644
View File

@ -1,21 +1,15 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../plugins/available/base.plugin
load ../../lib/colors
function local_setup { function local_setup_file() {
setup_test_fixture setup_libs "colors"
load "${BASH_IT?}/plugins/available/base.plugin.bash"
}
function local_setup() {
# Copy the test fixture to the Bash-it folder # Copy the test fixture to the Bash-it folder
if command -v rsync &> /dev/null; then cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/"
rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/"
else
find "$BASH_IT/test/fixtures/bash_it" \
-mindepth 1 -maxdepth 1 \
-exec cp -r {} "$BASH_IT/" \;
fi
} }
# TODO Create global __is_enabled function # TODO Create global __is_enabled function
@ -296,7 +290,7 @@ function local_setup {
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash"
assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
} }
@ -356,7 +350,7 @@ function local_setup {
run _bash-it-profile-load "test" run _bash-it-profile-load "test"
assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash"
assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash"
assert_link_not_exist "$BASH_IT/enabled/365---alias-completion.plugin.bash" assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash"
assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash"
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
} }
@ -384,7 +378,7 @@ function local_setup {
@test "helpers: profile load corrupted profile file: bad subdirectory" { @test "helpers: profile load corrupted profile file: bad subdirectory" {
run _bash-it-profile-load "test-bad-type" run _bash-it-profile-load "test-bad-type"
assert_line -n 1 -p "Bad line(#5) in profile, aborting load..." assert_line -n 1 -p "Bad line(#4) in profile, aborting load..."
} }
@test "helpers: profile rm sanity" { @test "helpers: profile rm sanity" {

View File

@ -1,11 +1,10 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../../lib/colors
load ../../lib/log function local_setup_file() {
load ../../lib/helpers setup_libs "log"
load ../../plugins/available/base.plugin }
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL

View File

@ -111,7 +111,7 @@ function local_setup {
@test "lib preexec: __check_precmd_conflict()" { @test "lib preexec: __check_precmd_conflict()" {
test_precmd_function_name="test" test_precmd_function_name="test"
load ../test_helper_libs setup_libs "preexec"
run __check_precmd_conflict "$test_precmd_function_name" run __check_precmd_conflict "$test_precmd_function_name"
assert_failure assert_failure
@ -124,7 +124,7 @@ function local_setup {
@test "lib preexec: __check_preexec_conflict()" { @test "lib preexec: __check_preexec_conflict()" {
test_preexec_function_name="test" test_preexec_function_name="test"
load ../test_helper_libs setup_libs "preexec"
run __check_preexec_conflict "$test_preexec_function_name" run __check_preexec_conflict "$test_preexec_function_name"
assert_failure assert_failure
@ -137,7 +137,7 @@ function local_setup {
@test "lib preexec: safe_append_prompt_command()" { @test "lib preexec: safe_append_prompt_command()" {
test_precmd_function_name="test" test_precmd_function_name="test"
load ../test_helper_libs setup_libs "preexec"
export precmd_functions=() export precmd_functions=()
assert_equal "${precmd_functions[*]}" "" assert_equal "${precmd_functions[*]}" ""
@ -151,7 +151,7 @@ function local_setup {
@test "lib preexec: safe_append_preexec()" { @test "lib preexec: safe_append_preexec()" {
test_preexec_function_name="test" test_preexec_function_name="test"
load ../test_helper_libs setup_libs "preexec"
export preexec_functions=() export preexec_functions=()
assert_equal "${preexec_functions[*]}" "" assert_equal "${preexec_functions[*]}" ""

28
test/lib/search.bats 100755 → 100644
View File

@ -1,28 +1,14 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../plugins/available/base.plugin function local_setup_file() {
load ../../aliases/available/git.aliases setup_libs "search"
load ../../plugins/available/ruby.plugin
load ../../plugins/available/rails.plugin
load ../../completion/available/bundler.completion
load ../../completion/available/gem.completion
load ../../completion/available/rake.completion
load ../../lib/helpers
function local_setup {
setup_test_fixture
export OLD_PATH="$PATH"
export PATH="/usr/bin:/bin:/usr/sbin"
} }
function local_teardown { function local_setup() {
export PATH="$OLD_PATH" # shellcheck disable=SC2034
unset OLD_PATH BASH_IT_SEARCH_USE_COLOR=false
} }
@test "search: plugin base" { @test "search: plugin base" {

View File

@ -1,10 +1,9 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
function local_setup { function local_setup_file() {
setup_test_fixture setup_libs "helpers"
} }
@test "_bash-it-component-item-is-enabled() - for a disabled item" { @test "_bash-it-component-item-is-enabled() - for a disabled item" {

35
test/plugins/base.plugin.bats 100755 → 100644
View File

@ -1,14 +1,13 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../plugins/available/base.plugin function local_setup_file() {
setup_libs "helpers"
load "${BASH_IT?}/plugins/available/base.plugin.bash"
}
@test 'plugins base: ips()' { @test 'plugins base: ips()' {
if [[ $CI ]]; then
skip 'ifconfig probably requires sudo on TravisCI'
fi
declare -r localhost='127.0.0.1' declare -r localhost='127.0.0.1'
run ips run ips
assert_success assert_success
@ -23,7 +22,7 @@ load ../../plugins/available/base.plugin
} }
@test 'plugins base: pickfrom()' { @test 'plugins base: pickfrom()' {
stub_file="${BASH_IT_ROOT}/stub_file" stub_file="${BATS_TEST_TMPDIR}/stub_file"
printf "l1\nl2\nl3" > $stub_file printf "l1\nl2\nl3" > $stub_file
run pickfrom $stub_file run pickfrom $stub_file
assert_success assert_success
@ -31,28 +30,30 @@ load ../../plugins/available/base.plugin
} }
@test 'plugins base: mkcd()' { @test 'plugins base: mkcd()' {
cd "${BASH_IT_ROOT}" cd "${BATS_TEST_TMPDIR}"
declare -r dir_name="-dir_with_dash" declare -r dir_name="-dir_with_dash"
# Make sure that the directory does not exist prior to the test # Make sure that the directory does not exist prior to the test
rm -rf "${BASH_IT_ROOT}/${dir_name}" rm -rf "${BATS_TEST_TMPDIR}/${dir_name}"
run mkcd "${dir_name}"
assert_success
assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}"
mkcd "${dir_name}" mkcd "${dir_name}"
assert_success assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}"
assert_dir_exist "${BASH_IT_ROOT}/${dir_name}"
assert_equal "${PWD}" "${BASH_IT_ROOT//\/\///}/${dir_name}"
} }
@test 'plugins base: lsgrep()' { @test 'plugins base: lsgrep()' {
for i in 1 2 3; do mkdir -p "${BASH_IT_TEST_DIR}/${i}"; done for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done
cd $BASH_IT_TEST_DIR cd $BASH_IT
run lsgrep 2 run lsgrep 2
assert_success assert_success
assert_equal $output 2 assert_equal $output 2
} }
@test 'plugins base: buf()' { @test 'plugins base: buf()' {
declare -r file="${BASH_IT_ROOT}/file" declare -r file="${BATS_TEST_TMPDIR}/file"
touch $file touch $file
# Take one timestamp before running the `buf` function # Take one timestamp before running the `buf` function

View File

@ -1,9 +1,11 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../plugins/available/battery.plugin function local_setup_file() {
setup_libs "helpers"
load "${BASH_IT?}/plugins/available/battery.plugin.bash"
}
# Sets up the `_command_exists` function so that it only responds `true` if called with # 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`. # the name of the function that was passed in as an argument to `setup_command_exists`.
@ -193,11 +195,24 @@ function setup_acpi {
# Creates a `upower` function that simulates output like the real `upower` command. # Creates a `upower` function that simulates output like the real `upower` command.
# The passed in parameter is used for the remaining battery percentage. # The passed in parameter is used for the remaining battery percentage.
function setup_upower { function setup_upower {
percent="$1" percent="$1"
BAT0="/org/freedesktop/UPower/devices/battery_BAT$RANDOM"
function upower { function upower {
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" case $1 in
} '-e'|'--enumerate')
printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery"
;;
'-i'|'--show-info')
if [[ $2 == "$BAT0" ]]
then
printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}"
else
false
fi
;;
esac
}
} }
@test 'plugins battery: battery-percentage with upower, 100%' { @test 'plugins battery: battery-percentage with upower, 100%' {

View File

@ -1,46 +1,41 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
load ../../plugins/available/cmd-returned-notify.plugin function local_setup_file() {
setup_libs "command_duration"
load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash"
}
@test "plugins cmd-returned-notify: notify after elapsed time" { @test "plugins cmd-returned-notify: notify after elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
export LAST_COMMAND_TIME=$(date +%s) export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1 sleep 1
run precmd_return_notification run precmd_return_notification
assert_success assert_success
assert_output $'\a' assert_output $'\a'
} }
@test "plugins cmd-returned-notify: do not notify before elapsed time" { @test "plugins cmd-returned-notify: do not notify before elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
export LAST_COMMAND_TIME=$(date +%s) export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}"
sleep 1 sleep 1
run precmd_return_notification run precmd_return_notification
assert_success assert_success
assert_output $'' assert_output $''
} }
@test "plugins cmd-returned-notify: preexec no output" { @test "lib command_duration: preexec no output" {
export LAST_COMMAND_TIME= export COMMAND_DURATION_START_SECONDS=
run preexec_return_notification run _command_duration_pre_exec
assert_success assert_success
assert_output "" assert_output ""
} }
@test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" {
@test "plugins cmd-returned-notify: preexec no output env set" { export COMMAND_DURATION_START_SECONDS=
export LAST_COMMAND_TIME=$(date +%s) assert_equal "${COMMAND_DURATION_START_SECONDS}" ""
run preexec_return_notification NOW="${EPOCHREALTIME:-$SECONDS}"
assert_failure _command_duration_pre_exec
assert_output "" # We need to make sure to account for nanoseconds...
} assert_equal "${COMMAND_DURATION_START_SECONDS%.*}" "${NOW%.*}"
@test "plugins cmd-returned-notify: preexec set LAST_COMMAND_TIME" {
export LAST_COMMAND_TIME=
assert_equal "${LAST_COMMAND_TIME}" ""
NOW=$(date +%s)
preexec_return_notification
assert_equal "${LAST_COMMAND_TIME}" "${NOW}"
} }

View File

@ -1,11 +1,9 @@
#!/usr/bin/env bats # shellcheck shell=bats
load ../test_helper load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash"
load ../test_helper_libs
function local_setup() function local_setup_file() {
{ setup_libs "helpers"
setup_test_fixture
} }
function setup_go_path() function setup_go_path()

Some files were not shown because too many files have changed in this diff Show More