Merge branch 'master' of https://github.com/bash-it/bash-it into ira/autosave-history-plml

* 'master' of https://github.com/bash-it/bash-it: (114 commits)
  ci: Bump go to 1.17 from 1.14
  skip go tests when go is not available
  plugins: Add ble.sh plugin
  clean up pyenv plugin
  Lint: prepare `lib/utilities` for `shellcheck` (#1933)
  plugin/base: improvements (#1930)
  plugins/percol: `bind`
  completion/git: `shfmt` && `shellcheck`
  completion/git: expand search range
  plugin/percol: `shellcheck` & `shfmt`
  plugins/percol: use `_command_exists`
  completion/pip: simplify code flow
  plugin/less-pretty-cat: remove `|| cat`
  completion/wpscan: simplify code flow (whitespace)
  plugins/less-pretty-cat: simplify code flow
  plugins/less-pretty-cat: use `_command_exists`
  lib/helpers: cite `_bash-it-find-in-ancestor()`
  gradle: adopt `_bash_it_find_in_ancestor()`
  lib/helpers: new function `_bash-it-find-in-ancestor()`
  completion/laravel: simplify code flow
  ...
pull/1883/head
Ira Abramov 2021-10-11 08:32:15 +03:00
commit d6239cf190
134 changed files with 1174 additions and 1001 deletions

View File

@ -13,17 +13,18 @@ insert_final_newline = true
trim_trailing_whitespace = false trim_trailing_whitespace = false
[.git*] [.git*]
indent_size = tab
indent_style = tab indent_style = tab
[{**.*sh,test/run}] [{**.*sh,test/run}]
indent_size = tab
indent_style = tab indent_style = tab
indent_size = 4
shell_variant = bash shell_variant = bash
binary_next_line = true # like -bn binary_next_line = true # like -bn
switch_case_indent = true # like -ci switch_case_indent = true # like -ci
space_redirects = true # like -sr space_redirects = true # like -sr
keep_padding = false # like -kp keep_padding = false # like -kp
end_of_line = lf end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true

View File

@ -11,7 +11,7 @@ jobs:
bats-test: bats-test:
strategy: strategy:
matrix: matrix:
os: [ubuntu-20.04, ubuntu-18.04, ubuntu-16.04, macos-10.15] os: [ubuntu-20.04, ubuntu-18.04, macos-10.15, macos-11.0]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@ -45,7 +45,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.14 go-version: 1.17
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v2 uses: actions/setup-python@v2
with: with:

View File

@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending - id: mixed-line-ending
- id: check-added-large-files - id: check-added-large-files
- repo: https://github.com/jumanjihouse/pre-commit-hooks - repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.4 rev: 2.1.5
hooks: hooks:
- id: git-check # Configure in .gitattributes - id: git-check # Configure in .gitattributes
- id: shellcheck - id: shellcheck

View File

@ -1,6 +0,0 @@
# We use colors and not assigned
disable=SC2154
# Hard to fix
disable=SC2155
# shellcheck is wrong on some
disable=SC2034

View File

@ -1,4 +1,4 @@
#!/bin/bash # shellcheck shell=bash
# #
# -binaryanomaly # -binaryanomaly
@ -8,7 +8,8 @@ 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 [ -x $(which 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

@ -6,7 +6,8 @@ about-alias 'Curl aliases for convenience.'
# set apt aliases # set apt aliases
function _set_pkg_aliases() function _set_pkg_aliases()
{ {
if [ -x $(which 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

View File

@ -30,7 +30,7 @@ then
alias grep='grep --color=auto' alias grep='grep --color=auto'
fi fi
if which gshuf &> /dev/null if _command_exists gshuf
then then
alias shuf=gshuf alias shuf=gshuf
fi fi
@ -65,7 +65,7 @@ alias -- -='cd -' # Go back
alias h='history' alias h='history'
# Tree # Tree
if [ ! -x "$(which tree 2>/dev/null)" ] 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

View File

@ -37,8 +37,8 @@ alias gcb='git checkout -b'
alias gco='git checkout' alias gco='git checkout'
alias gcob='git checkout -b' alias gcob='git checkout -b'
alias gcobu='git checkout -b ${USER}/' alias gcobu='git checkout -b ${USER}/'
alias gcom='git checkout master' alias gcom='git checkout $(get_default_branch)'
alias gcpd='git checkout master; git pull; git branch -D' alias gcpd='git checkout $(get_default_branch); git pull; git branch -D'
alias gct='git checkout --track' alias gct='git checkout --track'
# clone # clone
@ -64,13 +64,14 @@ alias gf='git fetch --all --prune'
alias gft='git fetch --all --prune --tags' alias gft='git fetch --all --prune --tags'
alias gftv='git fetch --all --prune --tags --verbose' alias gftv='git fetch --all --prune --tags --verbose'
alias gfv='git fetch --all --prune --verbose' alias gfv='git fetch --all --prune --verbose'
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master' alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/$(get_default_branch)'
alias gup='git fetch && git rebase' alias gup='git fetch && git rebase'
# log # log
alias gg='git log --graph --pretty=format:'\''%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset'\'' --abbrev-commit --date=relative' alias gg='git log --graph --pretty=format:'\''%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset'\'' --abbrev-commit --date=relative'
alias ggf='git log --graph --date=short --pretty=format:'\''%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'\''' alias ggf='git log --graph --date=short --pretty=format:'\''%C(auto)%h %Cgreen%an%Creset %Cblue%cd%Creset %C(auto)%d %s'\'''
alias ggs='gg --stat' alias ggs='gg --stat'
alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # FROM https://stackoverflow.com/questions/39220870/in-git-list-names-of-branches-with-unpushed-commits
alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gll='git log --graph --pretty=oneline --abbrev-commit'
alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/
alias gwc='git whatchanged' alias gwc='git whatchanged'
@ -104,7 +105,7 @@ alias gp='git push'
alias gpd='git push --delete' alias gpd='git push --delete'
alias gpf='git push --force' alias gpf='git push --force'
alias gpo='git push origin HEAD' alias gpo='git push origin HEAD'
alias gpom='git push origin master' alias gpom='git push origin $(get_default_branch)'
alias gpu='git push --set-upstream' alias gpu='git push --set-upstream'
alias gpunch='git push --force-with-lease' alias gpunch='git push --force-with-lease'
alias gpuo='git push --set-upstream origin' alias gpuo='git push --set-upstream origin'
@ -112,7 +113,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
# pull # pull
alias gl='git pull' alias gl='git pull'
alias glum='git pull upstream master' alias glum='git pull upstream $(get_default_branch)'
alias gpl='git pull' alias gpl='git pull'
alias gpp='git pull && git push' alias gpp='git pull && git push'
alias gpr='git pull --rebase' alias gpr='git pull --rebase'
@ -128,9 +129,9 @@ alias grm='git rm'
# rebase # rebase
alias grb='git rebase' alias grb='git rebase'
alias grbc='git rebase --continue' alias grbc='git rebase --continue'
alias grm='git rebase master' alias grm='git rebase $(get_default_branch)'
alias grmi='git rebase master -i' alias grmi='git rebase $(get_default_branch) -i'
alias gprom='git fetch origin master && git rebase origin/master && git update-ref refs/heads/master origin/master' # Rebase with latest remote master alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote
# reset # reset
alias gus='git reset HEAD' alias gus='git reset HEAD'
@ -174,7 +175,7 @@ alias gsu='git submodule update --init --recursive'
# these aliases requires git v2.23+ # these aliases requires git v2.23+
alias gsw='git switch' alias gsw='git switch'
alias gswc='git switch --create' alias gswc='git switch --create'
alias gswm='git switch master' alias gswm='git switch $(get_default_branch)'
alias gswt='git switch --track' alias gswt='git switch --track'
# tag # tag
@ -196,3 +197,11 @@ esac
function gdv() { function gdv() {
git diff --ignore-all-space "$@" | vim -R - git diff --ignore-all-space "$@" | vim -R -
} }
function get_default_branch() {
if git branch | grep -q main; then
echo main
else
echo master
fi
}

View File

@ -2,24 +2,14 @@
cite 'about-alias' cite 'about-alias'
about-alias 'vim abbreviations' about-alias 'vim abbreviations'
VIM=$(command -v vim) _command_exists vim || return
GVIM=$(command -v gvim)
MVIM=$(command -v mvim)
if [[ -n $VIM ]]; then alias v='vim'
alias v='$VIM' # open the vim help in fullscreen incorporated from
# open the vim help in fullscreen incorporated from # https://stackoverflow.com/a/4687513
# https://stackoverflow.com/a/4687513 alias vimh='vim -c ":h | only"'
alias vimh='${VIM} -c ":h | only"'
fi
# open vim in new tab is taken from # open vim in new tab is taken from
# http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek # http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek
case $OSTYPE in _command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; }
darwin*) _command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; }
[[ -n $MVIM ]] && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; }
;;
*)
[[ -n $GVIM ]] && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; }
;;
esac

View File

@ -3,7 +3,7 @@
BASH_IT_LOG_PREFIX="core: main: " BASH_IT_LOG_PREFIX="core: main: "
# Only set $BASH_IT if it's not already set # Only set $BASH_IT if it's not already set
if [ -z "$BASH_IT" ]; then if [ -z "${BASH_IT:-}" ]; then
# Setting $BASH to maintain backwards compatibility # Setting $BASH to maintain backwards compatibility
export BASH_IT=$BASH export BASH_IT=$BASH
BASH="$(bash -c 'echo $BASH')" BASH="$(bash -c 'echo $BASH')"
@ -20,12 +20,12 @@ source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
source "${BASH_IT}/lib/log.bash" source "${BASH_IT}/lib/log.bash"
# We can only log it now # 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!" [ -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 # For backwards compatibility, look in old BASH_THEME location
if [ -z "$BASH_IT_THEME" ]; then if [ -z "${BASH_IT_THEME:-}" ]; then
_log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!" _log_warning "BASH_IT_THEME variable not initialized, please upgrade your bash-it version and reinstall it!"
export BASH_IT_THEME="$BASH_THEME" export BASH_IT_THEME="${BASH_THEME:-}"
unset BASH_THEME unset BASH_THEME
fi fi
@ -114,6 +114,7 @@ for _bash_it_config_file in $CUSTOM; do
if [ -e "${_bash_it_config_file}" ]; then if [ -e "${_bash_it_config_file}" ]; then
filename=$(basename "${_bash_it_config_file}") filename=$(basename "${_bash_it_config_file}")
filename=${filename%*.bash} filename=${filename%*.bash}
# shellcheck disable=SC2034
BASH_IT_LOG_PREFIX="custom: $filename: " BASH_IT_LOG_PREFIX="custom: $filename: "
_log_debug "Loading custom file..." _log_debug "Loading custom file..."
# shellcheck disable=SC1090 # shellcheck disable=SC1090
@ -122,7 +123,7 @@ for _bash_it_config_file in $CUSTOM; do
done done
unset _bash_it_config_file unset _bash_it_config_file
if [[ $PROMPT ]]; then if [[ -n "${PROMPT:-}" ]]; then
export PS1="\[""$PROMPT""\]" export PS1="\[""$PROMPT""\]"
fi fi
@ -144,7 +145,7 @@ if [ -e "$HOME/.jekyllconfig" ]; then
fi fi
# BASH_IT_RELOAD_LEGACY is set. # BASH_IT_RELOAD_LEGACY is set.
if ! command -v reload &> /dev/null && [ -n "$BASH_IT_RELOAD_LEGACY" ]; then if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
alias reload='source ~/.bash_profile' alias reload='source ~/.bash_profile'

View File

@ -42,12 +42,14 @@ completion/available/cargo.completion.bash
completion/available/composer.completion.bash completion/available/composer.completion.bash
completion/available/conda.completion.bash completion/available/conda.completion.bash
completion/available/consul.completion.bash completion/available/consul.completion.bash
completion/available/dart.completion.bash
completion/available/django.completion.bash completion/available/django.completion.bash
completion/available/dmidecode.completion.bash completion/available/dmidecode.completion.bash
completion/available/docker-machine.completion.bash completion/available/docker-machine.completion.bash
completion/available/docker.completion.bash completion/available/docker.completion.bash
completion/available/gcloud.completion.bash completion/available/gcloud.completion.bash
completion/available/gem.completion.bash completion/available/gem.completion.bash
completion/available/git.completion.bash
completion/available/github-cli.completion.bash completion/available/github-cli.completion.bash
completion/available/go.completion.bash completion/available/go.completion.bash
completion/available/helm.completion.bash completion/available/helm.completion.bash
@ -57,6 +59,7 @@ completion/available/jungle.completion.bash
completion/available/knife.completion.bash completion/available/knife.completion.bash
completion/available/kontena.completion.bash completion/available/kontena.completion.bash
completion/available/kubectl.completion.bash completion/available/kubectl.completion.bash
completion/available/laravel.completion.bash
completion/available/lerna.completion.bash completion/available/lerna.completion.bash
completion/available/minikube.completion.bash completion/available/minikube.completion.bash
completion/available/ngrok.completion.bash completion/available/ngrok.completion.bash
@ -71,12 +74,20 @@ completion/available/rustup.completion.bash
completion/available/sdkman.completion.bash completion/available/sdkman.completion.bash
completion/available/vault.completion.bash completion/available/vault.completion.bash
completion/available/vuejs.completion.bash completion/available/vuejs.completion.bash
completion/available/wpscan.completion.bash
# libraries
lib/utilities.bash
# plugins # plugins
# #
plugins/available/alias-completion.plugin.bash plugins/available/alias-completion.plugin.bash
plugins/available/autojump.plugin.bash
plugins/available/base.plugin.bash
plugins/available/basher.plugin.bash plugins/available/basher.plugin.bash
plugins/available/blesh.plugin.bash
plugins/available/cmd-returned-notify.plugin.bash plugins/available/cmd-returned-notify.plugin.bash
plugins/available/direnv.plugin.bash
plugins/available/docker-machine.plugin.bash plugins/available/docker-machine.plugin.bash
plugins/available/git.plugin.bash plugins/available/git.plugin.bash
plugins/available/go.plugin.bash plugins/available/go.plugin.bash
@ -84,6 +95,17 @@ plugins/available/goenv.plugin.bash
plugins/available/history-search.plugin.bash plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash
plugins/available/pyenv.plugin.bash
plugins/available/rbenv.plugin.bash
plugins/available/ruby.plugin.bash
plugins/available/textmate.plugin.bash
plugins/available/xterm.plugin.bash plugins/available/xterm.plugin.bash
# tests # tests
@ -111,6 +133,7 @@ themes/command_duration.theme.bash
themes/easy themes/easy
themes/modern themes/modern
themes/powerline themes/powerline
themes/pure
themes/purity themes/purity
# vendor init files # vendor init files

View File

@ -1 +1,6 @@
[[ -x "$(which aws_completer)" ]] && complete -C "$(which aws_completer)" aws # shellcheck shell=bash
if _command_exists aws_completer
then
complete -C "$(command -v aws_completer)" aws
fi

View File

@ -5,28 +5,26 @@ about-completion "brew completion"
# Load late to make sure `system` completion loads first # Load late to make sure `system` completion loads first
# BASH_IT_LOAD_PRIORITY: 375 # BASH_IT_LOAD_PRIORITY: 375
if [[ "$(uname -s)" != 'Darwin' ]]; then if [[ "$OSTYPE" != 'darwin'* ]]; then
_log_warning "unsupported operating system - only 'Darwin' is supported" _log_warning "unsupported operating system - only 'Darwin' is supported"
return 0 return 0
fi fi
# Make sure brew is installed # Make sure brew is installed
_command_exists brew || return 0 _bash_it_homebrew_check || return 0
BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} if [[ -r "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew" ]]; then
if [[ -r "$BREW_PREFIX"/etc/bash_completion.d/brew ]]; then
# shellcheck disable=1090 # shellcheck disable=1090
source "$BREW_PREFIX"/etc/bash_completion.d/brew source "$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d/brew"
elif [[ -r "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh ]]; then elif [[ -r "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh" ]]; then
# shellcheck disable=1090 # shellcheck disable=1090
source "$BREW_PREFIX"/Library/Contributions/brew_bash_completion.sh source "$BASH_IT_HOMEBREW_PREFIX/Library/Contributions/brew_bash_completion.sh"
elif [[ -f "$BREW_PREFIX"/completions/bash/brew ]]; then elif [[ -f "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew" ]]; then
# For the git-clone based installation, see here for more info: # For the git-clone based installation, see here for more info:
# https://github.com/Bash-it/bash-it/issues/1458 # https://github.com/Bash-it/bash-it/issues/1458
# https://docs.brew.sh/Shell-Completion # https://docs.brew.sh/Shell-Completion
# shellcheck disable=1090 # shellcheck disable=1090
source "$BREW_PREFIX"/completions/bash/brew source "$BASH_IT_HOMEBREW_PREFIX/completions/bash/brew"
fi fi

View File

@ -3,14 +3,14 @@ cite "about-completion"
about-completion "composer completion" about-completion "composer completion"
function __composer_completion() { function __composer_completion() {
local cur coms opts com local cur coms opts com words
COMPREPLY=() COMPREPLY=()
_get_comp_words_by_ref -n : cur words _get_comp_words_by_ref -n : cur words
# lookup for command # lookup for command
for word in "${words[@]:1}"; do for word in "${words[@]:1}"; do
if [[ $word != -* ]]; then if [[ "${word}" != -* ]]; then
com=$word com="${word}"
break break
fi fi
done done
@ -19,7 +19,7 @@ function __composer_completion() {
if [[ ${cur} == --* ]]; then if [[ ${cur} == --* ]]; then
opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir"
case "$com" in case "${com}" in
about) about)
opts="${opts} " opts="${opts} "
;; ;;
@ -109,18 +109,18 @@ function __composer_completion() {
# shellcheck disable=SC2207 # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
__ltrim_colon_completions "$cur" __ltrim_colon_completions "${cur}"
return 0 return 0
fi fi
# completing for a command # completing for a command
if [[ "$cur" == "$com" ]]; then if [[ "${cur}" == "${com}" ]]; then
coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate" coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate"
# shellcheck disable=SC2207 # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) COMPREPLY=($(compgen -W "${coms}" -- "${cur}"))
__ltrim_colon_completions "$cur" __ltrim_colon_completions "${cur}"
return 0 return 0
fi fi

View File

@ -3,5 +3,5 @@ cite "about-completion"
about-completion "Hashicorp consul completion" about-completion "Hashicorp consul completion"
if _command_exists consul; then if _command_exists consul; then
complete -C "$(which consul)" consul complete -C "$(command -v consul)" consul
fi fi

View File

@ -0,0 +1,48 @@
# shellcheck shell=bash
__dart_completion() {
# shellcheck disable=SC2155
local prev=$(_get_pword)
# shellcheck disable=SC2155
local curr=$(_get_cword)
local HELP="--help -h"
local VERBOSE="-v --verbose"
case $prev in
analyze)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP --fatal-infos --no-fatal-warnings --fatal-warnings" -- "$curr"))
;;
compile)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP aot-snapshot exe js jit-snapshot kernel" -- "$curr"))
;;
create)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP --template -t --no-pub --pub --force" -- "$curr"))
;;
-t | --template)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "console-simple console-full package-simple web-simple" -- "$curr"))
;;
format)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP $VERBOSE -o --output --fix -l --line-length" -- "$curr"))
;;
pub)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --no-trace --trace --verbosity cache deps downgrade get global logout outdated publish run upgrade uploader version" -- "$curr"))
;;
run)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP --observe --enable-vm-service --no-pause-isolates-on-exit --no-pause-isolates-on-unhandled-exceptions --no-warn-on-pause-with-no-debugger --pause-isolates-on-exit --pause-isolates-on-unhandled-exceptions --warn-on-pause-with-no-debugger" -- "$curr"))
;;
dart)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$HELP $VERBOSE --version --enable-analytics --disable-analytics help analyze compile create format pub run test" -- "$curr"))
;;
esac
}
complete -F __dart_completion dart

View File

@ -13,7 +13,7 @@ _defaults_domains()
COMPREPLY=() COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]} cur=${COMP_WORDS[COMP_CWORD]}
local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep -i "^$cur" ) local domains=$( defaults domains | sed -e 's/, /:/g' | tr : '\n' | sed -e 's/ /\\ /g' | grep "^$cur" )
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=( $domains ) COMPREPLY=( $domains )
if [[ $( echo '-app' | grep "^$cur" ) ]]; then if [[ $( echo '-app' | grep "^$cur" ) ]]; then
@ -41,8 +41,8 @@ _defaults()
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
return 0 return 0
elif [[ "$prev" == "-host" ]]; then elif [[ "$prev" == "-host" ]]; then
return 0
_known_hosts -a _known_hosts -a
return 0
else else
_defaults_domains _defaults_domains
return 0 return 0

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
function __dmidecode_completion() { function __dmidecode_completion() {
# shellcheck disable=SC2155
local prev=$(_get_pword) local prev=$(_get_pword)
# shellcheck disable=SC2155
local curr=$(_get_cword) local curr=$(_get_cword)
case $prev in case $prev in

View File

@ -676,7 +676,7 @@ _docker_compose() {
done done
local completions_func=_docker_compose_${command//-/_} local completions_func=_docker_compose_${command//-/_}
declare -F $completions_func >/dev/null && $completions_func _is_function $completions_func && $completions_func
eval "$previous_extglob_setting" eval "$previous_extglob_setting"
return 0 return 0

View File

@ -41,8 +41,8 @@ export FAB_COMPLETION_CACHED_TASKS_FILENAME=".fab_tasks~"
# Set command to get time of last file modification as seconds since Epoch # Set command to get time of last file modification as seconds since Epoch
case `uname` in case "$OSTYPE" in
Darwin|FreeBSD) 'darwin'*|'freebsd'*)
__FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'" __FAB_COMPLETION_MTIME_COMMAND="stat -f '%m'"
;; ;;
*) *)

View File

@ -1,39 +1,42 @@
#!/usr/bin/env bash # shellcheck shell=bash
#
# Only operate on MacOS since there are no linux paths # Locate and load completions for `git`.
if [[ "$(uname -s)" != 'Darwin' ]] ; then
_log_warning "unsupported operating system - only 'Darwin' is supported"
return 0
fi
# Make sure git is installed # Make sure git is installed
_command_exists git || return 0 _command_exists git || return
# Don't handle completion if it's already managed # Don't handle completion if it's already managed
if complete -p git &>/dev/null ; then if complete -p git &> /dev/null; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion" _log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0 return 0
fi fi
_git_bash_completion_found=false _git_bash_completion_xcrun_git=
if _command_exists xcrun; then
_git_bash_completion_xcrun_git="$(xcrun --find git)"
fi
_git_bash_completion_paths=( _git_bash_completion_paths=(
# MacOS non-system locations # Standard locations
'/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash' "${GIT_EXE%/*}/../share/git-core/git-completion.bash"
'/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash' "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash"
"${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash"
# MacOS non-system locations
"${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash"
) )
# Load the first completion file found # Load the first completion file found
for _comp_path in "${_git_bash_completion_paths[@]}" ; do _git_bash_completion_found=false
if [ -r "$_comp_path" ] ; then for _comp_path in "${_git_bash_completion_paths[@]}"; do
_git_bash_completion_found=true if [[ -r "$_comp_path" ]]; then
source "$_comp_path" _git_bash_completion_found=true
break # shellcheck disable=SC1090 # don't follow
fi source "$_comp_path"
break
fi
done done
# Cleanup # Cleanup
if [[ "${_git_bash_completion_found}" == false ]]; then if [[ "${_git_bash_completion_found}" == false ]]; then
_log_warning "no completion files found - please try enabling the 'system' completion instead." _log_warning "no completion files found - please try enabling the 'system' completion instead."
fi fi
unset _git_bash_completion_paths unset "${!_git_bash_completion@}"
unset _git_bash_completion_found

View File

@ -172,6 +172,7 @@ __git_flow_list_hotfixes ()
} }
# temporarily wrap __git_find_on_cmdline() for backwards compatibility # temporarily wrap __git_find_on_cmdline() for backwards compatibility
if [ -z "`type -t __git_find_subcommand`" ]; then if ! _command_exists __git_find_subcommand
then
alias __git_find_subcommand=__git_find_on_cmdline alias __git_find_subcommand=__git_find_on_cmdline
fi fi

View File

@ -505,6 +505,7 @@ __git_flow_list_branches ()
} }
# alias __git_find_on_cmdline for backwards compatibility # alias __git_find_on_cmdline for backwards compatibility
if [ -z "`type -t __git_find_on_cmdline`" ]; then if ! _command_exists __git_find_on_cmdline
then
alias __git_find_on_cmdline=__git_find_subcommand alias __git_find_on_cmdline=__git_find_subcommand
fi fi

View File

@ -22,17 +22,9 @@
# Avoid inaccurate completions for subproject tasks # Avoid inaccurate completions for subproject tasks
COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g') COMP_WORDBREAKS=$(echo "$COMP_WORDBREAKS" | sed -e 's/://g')
__gradle-set-project-root-dir() { function __gradle-set-project-root-dir() {
local dir=`pwd` project_root_dir="$(_bash-it-find-in-ancestor "settings.gradle" "gradlew")"
project_root_dir=`pwd` return "$?"
while [[ $dir != '/' ]]; do
if [[ -f "$dir/settings.gradle" || -f "$dir/gradlew" ]]; then
project_root_dir=$dir
return 0
fi
dir="$(dirname "$dir")"
done
return 1
} }
__gradle-init-cache-dir() { __gradle-init-cache-dir() {
@ -58,9 +50,9 @@ __gradle-set-cache-name() {
__gradle-set-files-checksum() { __gradle-set-files-checksum() {
# Cache MD5 sum of all Gradle scripts and modified timestamps # Cache MD5 sum of all Gradle scripts and modified timestamps
if builtin command -v md5 > /dev/null; then if _command_exists md5; then
gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)") gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)")
elif builtin command -v md5sum > /dev/null; then elif _command_exists md5sum; then
gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}') gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}')
else else
echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH" echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH"

View File

@ -23,12 +23,12 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# If there is no git tab completion, but we have the _completion loader try to load it # If there is no git tab completion, but we have the _completion loader try to load it
if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then if ! _is_function _git && _is_function _completion_loader; then
_completion_loader git _completion_loader git
fi fi
# Check that git tab completion is available and we haven't already set up completion # Check that git tab completion is available and we haven't already set up completion
if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then
# Duplicate and rename the 'list_all_commands' function # Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \ eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"
@ -227,7 +227,7 @@ EOF
((c++)) ((c++))
done done
if [ -z "$name" ]; then if [ -z "$name" ]; then
repo=$(basename "$(pwd)") repo="$(basename "${PWD}")"
fi fi
case "$prev" in case "$prev" in
-d|-h) -d|-h)

View File

@ -42,6 +42,7 @@ _KAC_is_file_newer_than() {
_KAC_regen_cache() { _KAC_regen_cache() {
local CACHE_NAME=$1 local CACHE_NAME=$1
local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME" local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
# shellcheck disable=SC2155
local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX") local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX")
shift 1 shift 1
# discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated # discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated
@ -66,6 +67,7 @@ _KAC_get_command_from_cache_name() {
# otherwise it waits for the cache to be generated # otherwise it waits for the cache to be generated
# in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable # in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable
# for obvious reason, do NOT call that in a sub-shell (in particular, no piping) # for obvious reason, do NOT call that in a sub-shell (in particular, no piping)
# shellcheck disable=SC2155
_KAC_get_and_regen_cache() { _KAC_get_and_regen_cache() {
# the cache name can't have space in it # the cache name can't have space in it
local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@") local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@")
@ -100,7 +102,7 @@ _KAC_clean_cache() {
# perform a cache cleaning when loading this file # perform a cache cleaning when loading this file
# On big systems this could baloon up to a 30 second run or more, so not enabling by default. # On big systems this could baloon up to a 30 second run or more, so not enabling by default.
[[ "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache [[ -n "${KNIFE_CACHE_CLEAN}" ]] && _KAC_clean_cache
##################################### #####################################
### End of cache helper functions ### ### End of cache helper functions ###
@ -118,7 +120,7 @@ _KAC_get_current_base_command() {
local PREVIOUS="knife" local PREVIOUS="knife"
local I=1 local I=1
local CURRENT local CURRENT
while [ $I -le "$COMP_CWORD" ]; do while [[ "${I}" -le "${COMP_CWORD}" ]]; do
# command words are all lower-case # command words are all lower-case
echo "${COMP_WORDS[$I]}" | grep -E "^[a-z]+$" > /dev/null || break echo "${COMP_WORDS[$I]}" | grep -E "^[a-z]+$" > /dev/null || break
CURRENT="$PREVIOUS ${COMP_WORDS[$I]}" CURRENT="$PREVIOUS ${COMP_WORDS[$I]}"
@ -127,12 +129,13 @@ _KAC_get_current_base_command() {
I=$((I + 1)) I=$((I + 1))
done done
_KAC_CURRENT_COMMAND=$PREVIOUS _KAC_CURRENT_COMMAND=$PREVIOUS
[ $I -le "$COMP_CWORD" ] && _KAC_CURRENT_COMMAND_NB_WORDS=$I [[ "${I}" -le "${COMP_CWORD}" ]] && _KAC_CURRENT_COMMAND_NB_WORDS="${I}"
} }
# searches the position of the currently completed argument in the current base command # searches the position of the currently completed argument in the current base command
# (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...) # (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...)
# assumes the current base command is complete # assumes the current base command is complete
# shellcheck disable=SC2155
_KAC_get_current_arg_position() { _KAC_get_current_arg_position() {
local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1)) local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1))
local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH") local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH")
@ -150,10 +153,11 @@ _KAC_get_current_arg_position() {
_knife() { _knife() {
_KAC_get_and_regen_cache _KAC_knife_commands _KAC_get_and_regen_cache _KAC_knife_commands
local RAW_LIST ITEM REGEN_CMD ARG_POSITION local RAW_LIST ITEM REGEN_CMD ARG_POSITION
# shellcheck disable=SC2034
COMREPLY=() COMREPLY=()
# get correct command & arg pos # get correct command & arg pos
_KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$((COMP_CWORD + 1)) _KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$((COMP_CWORD + 1))
RAW_LIST=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH" | cut -d ' ' -f $ARG_POSITION | uniq) RAW_LIST=$(grep -E "^${_KAC_CURRENT_COMMAND}" "${_KAC_CACHE_PATH}" | cut -d ' ' -f "${ARG_POSITION}" | uniq)
# we need to process that raw list a bit, most notably for placeholders # we need to process that raw list a bit, most notably for placeholders
# NOTE: I chose to explicitely fetch & cache _certain_ informations for the server (cookbooks & node names, etc) # NOTE: I chose to explicitely fetch & cache _certain_ informations for the server (cookbooks & node names, etc)

View File

@ -1,15 +1,16 @@
#!/usr/bin/bash # shellcheck shell=bash
if command -v laravel > /dev/null; then _command_exists laravel || return
__laravel_completion() {
local OPTS=("-h --help -q --quiet --ansi --no-ansi -n --no-interaction -v -vv -vvv --verbose help list new")
COMPREPLY=()
for _opt_ in ${OPTS[@]}; do
if [[ "$_opt_" == "$2"* ]]; then
COMPREPLY+=("$_opt_")
fi
done
}
complete -F __laravel_completion laravel function __laravel_completion() {
fi local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new')
local _opt_
COMPREPLY=()
for _opt_ in "${OPTS[@]}"; do
if [[ "$_opt_" == "$2"* ]]; then
COMPREPLY+=("$_opt_")
fi
done
}
complete -F __laravel_completion laravel

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
__ngrok_completion() { __ngrok_completion() {
# shellcheck disable=SC2155
local prev=$(_get_pword) local prev=$(_get_pword)
# shellcheck disable=SC2155
local curr=$(_get_cword) local curr=$(_get_cword)
local BASE_NO_CONF="--log --log-format --log-level --help" local BASE_NO_CONF="--log --log-format --log-level --help"

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
function __notify-send_completions() { function __notify-send_completions() {
# shellcheck disable=SC2155
local curr=$(_get_cword) local curr=$(_get_cword)
# shellcheck disable=SC2155
local prev=$(_get_pword) local prev=$(_get_pword)
case $prev in case $prev in

View File

@ -1 +1,6 @@
[[ -x "$(which pew)" ]] && source "$(pew shell_config)" # shellcheck shell=bash
if _command_exists pew
then
source "$(pew shell_config)"
fi

View File

@ -6,6 +6,15 @@
# If the pip package is installed within virtual environments, say, python managed by pyenv, # If the pip package is installed within virtual environments, say, python managed by pyenv,
# you should first initialize the corresponding environment. # you should first initialize the corresponding environment.
# So that pip is in the system's path. # So that pip is in the system's path.
if _command_exists pip; then _command_exists pip || return
eval "$(pip completion --bash)"
fi function __bash_it_complete_pip() {
if _command_exists _pip_completion; then
complete -o default -F _pip_completion pip
_pip_completion "$@"
else
eval "$(pip completion --bash)"
_pip_completion "$@"
fi
}
complete -o default -F __bash_it_complete_pip pip

View File

@ -6,6 +6,15 @@
# If the pip package is installed within virtual environments, say, python managed by pyenv, # If the pip package is installed within virtual environments, say, python managed by pyenv,
# you should first initialize the corresponding environment. # you should first initialize the corresponding environment.
# So that pip3 is in the system's path. # So that pip3 is in the system's path.
if _command_exists pip3; then _command_exists pip3 || return
eval "$(pip3 completion --bash)"
fi function __bash_it_complete_pip3() {
if _command_exists _pip_completion; then
complete -o default -F _pip_completion pip3
_pip_completion "$@"
else
eval "$(pip3 completion --bash)"
_pip_completion "$@"
fi
}
complete -o default -F __bash_it_complete_pip3 pip3

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
_sdkman_complete() {
function _sdkman_complete() {
local CANDIDATES local CANDIDATES
local CANDIDATE_VERSIONS local CANDIDATE_VERSIONS
local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}"
COMPREPLY=() COMPREPLY=()
@ -10,7 +12,7 @@ _sdkman_complete() {
elif [ "$COMP_CWORD" -eq 2 ]; then elif [ "$COMP_CWORD" -eq 2 ]; then
case "${COMP_WORDS[COMP_CWORD - 1]}" in case "${COMP_WORDS[COMP_CWORD - 1]}" in
"install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug") "install" | "i" | "uninstall" | "rm" | "list" | "ls" | "use" | "u" | "default" | "d" | "home" | "h" | "current" | "c" | "upgrade" | "ug")
CANDIDATES=$(echo "${SDKMAN_CANDIDATES_CSV}" | tr ',' ' ') CANDIDATES="${SDKMAN_CANDIDATES_CSV//,/${IFS:0:1}}"
mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}") mapfile -t COMPREPLY < <(compgen -W "$CANDIDATES" -- "${COMP_WORDS[COMP_CWORD]}")
;; ;;
"env") "env")
@ -46,17 +48,17 @@ _sdkman_complete() {
return 0 return 0
} }
_sdkman_candidate_local_versions() { function _sdkman_candidate_local_versions() {
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1") CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1")
} }
_sdkman_candidate_all_versions() { function _sdkman_candidate_all_versions() {
candidate="$1" candidate="$1"
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate") CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate")
if [ "$SDKMAN_OFFLINE_MODE" = "true" ]; then if [[ "${SDKMAN_OFFLINE_MODE:-false}" == "true" ]]; then
CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS CANDIDATE_VERSIONS=$CANDIDATE_LOCAL_VERSIONS
else else
# sdkman has a specific output format for Java candidate since # sdkman has a specific output format for Java candidate since
@ -70,12 +72,12 @@ _sdkman_candidate_all_versions() {
# "+" - local version # "+" - local version
# "*" - installed # "*" - installed
# ">" - currently in use # ">" - currently in use
CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort | uniq -u) " CANDIDATE_VERSIONS="$(echo "$CANDIDATE_ONLINE_VERSIONS $CANDIDATE_LOCAL_VERSIONS" | tr ' ' '\n' | grep -v -e '^[[:space:]|\*|\>|\+]*$' | sort -u) "
fi fi
} }
__sdkman_cleanup_local_versions() { function __sdkman_cleanup_local_versions() {
__sdkman_build_version_csv "$1" | tr ',' ' ' __sdkman_build_version_csv "$1" | tr ',' ' '

View File

@ -1,21 +1,22 @@
#!/bin/bash # shellcheck shell=bash
# ---------------------------------------------------------------------------+ # ---------------------------------------------------------------------------+
# | # |
# Thanks to Alexander Korznikov | # Thanks to Alexander Korznikov |
# http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html | # http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html |
# | # |
# ---------------------------------------------------------------------------+ # ---------------------------------------------------------------------------+
if command -v sqlmap > /dev/null; then if _command_exists sqlmap
then
_sqlmap() function _sqlmap()
{ {
local cur prev local cur prev
COMPREPLY=() COMPREPLY=()
cur=$(_get_cword) cur="$(_get_cword)"
prev=$(_get_pword) prev="$(_get_pword)"
case $prev in case $prev in
@ -143,7 +144,7 @@ if command -v sqlmap > /dev/null; then
--mobile --page-rank --purge-output --smart \ --mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard ' --sqlmap-shell --wizard '
COMPREPLY=( $( \ COMPREPLY=( $( \
(while read -d ' ' i; do (while read -d ' ' i; do
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] && [[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
continue continue
# flatten array with spaces on either side, # flatten array with spaces on either side,
@ -152,7 +153,7 @@ if command -v sqlmap > /dev/null; then
COMPREPLY=" ${COMPREPLY[@]} " COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions # remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } ) COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done done
printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}" printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
) ) ) )

View File

@ -1,9 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#
# Loads the system's Bash completion modules. # Loads the system's Bash completion modules.
# If Homebrew is installed (OS X), it's Bash completion modules are loaded. # If Homebrew is installed (OS X), it's Bash completion modules are loaded.
if [[ -r /etc/bash_completion ]] ; then if shopt -qo nounset
then # Bash-completion is too large and complex to expect to handle unbound variables throughout the whole codebase.
__bash_it_restore_nounset=true
shopt -uo nounset
else
__bash_it_restore_nounset=false
fi
if [[ -r "${BASH_COMPLETION:-}" ]] ; then
# shellcheck disable=SC1091
source "${BASH_COMPLETION}"
elif [[ -r /etc/bash_completion ]] ; then
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /etc/bash_completion source /etc/bash_completion
@ -12,14 +24,36 @@ elif [[ -r /etc/profile.d/bash_completion.sh ]] ; then
# shellcheck disable=SC1091 # shellcheck disable=SC1091
source /etc/profile.d/bash_completion.sh source /etc/profile.d/bash_completion.sh
elif _bash_it_homebrew_check
then
: ${BASH_COMPLETION_COMPAT_DIR:=$BASH_IT_HOMEBREW_PREFIX/etc/bash_completion.d}
case "${BASH_VERSION}" in
1*|2*|3.0*|3.1*)
_log_warning "Cannot load completion due to version of shell. Are you using Bash 3.2+?"
;;
3.2*|4.0*|4.1*)
# Import version 1.x of bash-completion, if installed.
BASH_COMPLETION="$BASH_IT_HOMEBREW_PREFIX/opt/bash-completion@1/etc/bash_completion"
if [[ -r "$BASH_COMPLETION" ]] ; then
# shellcheck disable=SC1090
source "$BASH_COMPLETION"
else
unset BASH_COMPLETION
fi
;;
4.2*|5*|*)
# 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
# shellcheck disable=SC1090
source "$BASH_IT_HOMEBREW_PREFIX"/etc/profile.d/bash_completion.sh
fi
;;
esac
fi fi
if [[ "$(uname -s)" == 'Darwin' ]] && _command_exists brew ; then if $__bash_it_restore_nounset
BREW_PREFIX=${BREW_PREFIX:-$(brew --prefix)} then
shopt -so nounset
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [[ -r "$BREW_PREFIX"/etc/profile.d/bash_completion.sh ]] ; then
# shellcheck disable=SC1090
source "$BREW_PREFIX"/etc/profile.d/bash_completion.sh
fi
fi fi
unset __bash_it_restore_nounset

View File

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

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash # shellcheck shell=bash
__vuejs_completion() { __vuejs_completion() {
# shellcheck disable=SC2155
local prev=$(_get_pword) local prev=$(_get_pword)
# shellcheck disable=SC2155
local curr=$(_get_cword) local curr=$(_get_cword)
case $prev in case $prev in

View File

@ -1,15 +1,16 @@
#!/usr/bin/bash # shellcheck shell=bash
if command -v wpscan > /dev/null; then _command_exists wpscan || return
__wpscan_completion() {
local OPTS=("--help --hh --version --url --ignore-main-redirect --verbose --output --format --detection-mode --scope --headers --user-agent --vhost --random-user-agent --user-agents-list --http-auth --max-threads --throttle --request-timeout --connect-timeout --disable-tlc-checks --proxy --proxy-auth --cookie-string --cookie-jar --cache-ttl --clear-cache --server --cache-dir --update --no-update --wp-content-dir --wp-plugins-dir --wp-version-detection --main-theme-detection --enumerate --exclude-content-based --plugins-list --plugins-detection --plugins-version-all --plugins-version-detection --themes-list --themes-detection --themes-version-all --themes-version-detection --timthumbs-list --timthumbs-detection --config-backups-list --config-backups-detection --db-exports-list --db-exports-detection --medias-detection --users-list --users-detection --passwords --usernames --multicall-max-passwords --password-attack --stealthy")
COMPREPLY=()
for _opt_ in ${OPTS[@]}; do
if [[ "$_opt_" == "$2"* ]]; then
COMPREPLY+=("$_opt_")
fi
done
}
complete -F __wpscan_completion wpscan function __wpscan_completion() {
fi local _opt_
local OPTS=('--help' '--hh' '--version' '--url' '--ignore-main-redirect' '--verbose' '--output' '--format' '--detection-mode' '--scope' '--headers' '--user-agent' '--vhost' '--random-user-agent' '--user-agents-list' '--http-auth' '--max-threads' '--throttle' '--request-timeout' '--connect-timeout' '--disable-tlc-checks' '--proxy' '--proxy-auth' '--cookie-string' '--cookie-jar' '--cache-ttl' '--clear-cache' '--server' '--cache-dir' '--update' '--no-update' '--wp-content-dir' '--wp-plugins-dir' '--wp-version-detection' '--main-theme-detection' '--enumerate' '--exclude-content-based' '--plugins-list' '--plugins-detection' '--plugins-version-all' '--plugins-version-detection' '--themes-list' '--themes-detection' '--themes-version-all' '--themes-version-detection' '--timthumbs-list' '--timthumbs-detection' '--config-backups-list' '--config-backups-detection' '--db-exports-list' '--db-exports-detection' '--medias-detection' '--users-list' '--users-detection' '--passwords' '--usernames' '--multicall-max-passwords' '--password-attack' '--stealthy')
COMPREPLY=()
for _opt_ in "${OPTS[@]}"; do
if [[ "$_opt_" == "$2"* ]]; then
COMPREPLY+=("$_opt_")
fi
done
}
complete -F __wpscan_completion wpscan

View File

@ -4,7 +4,7 @@
![Docs Status](https://readthedocs.org/projects/bash-it/badge/) ![Docs Status](https://readthedocs.org/projects/bash-it/badge/)
![License](https://img.shields.io/github/license/Bash-it/bash-it) ![License](https://img.shields.io/github/license/Bash-it/bash-it)
![shell](https://img.shields.io/badge/Shell-Bash-blue) ![shell](https://img.shields.io/badge/Shell-Bash-blue)
[![Join the chat at https://webchat.freenode.net/?channel=#bash-it](https://img.shields.io/badge/chat-on%20freenode-brightgreen.svg)](https://webchat.freenode.net/?channel=#bash-it) [![Join the chat at https://web.libera.chat/?channel=#bash-it](https://img.shields.io/badge/chat-on%20Libera.Chat-brightgreen.svg)](https://web.libera.chat/?channel=#bash-it)
**Bash-it** is a collection of community Bash commands and scripts for Bash 3.2+. **Bash-it** is a collection of community Bash commands and scripts for Bash 3.2+.
(And a shameless ripoff of [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) :smiley:) (And a shameless ripoff of [oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) :smiley:)

View File

@ -70,11 +70,13 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
* ``battery`` - Battery information (you'll need to enable the ``battery`` plugin) * ``battery`` - Battery information (you'll need to enable the ``battery`` plugin)
* ``clock`` - Current time in ``HH:MM:SS`` format * ``clock`` - Current time in ``HH:MM:SS`` format
* ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ ) * ``cwd`` - Current working directory including full folder hierarchy (c.f. ``wd``\ )
* ``duration`` - Duration of the last command. See :ref:`Command duration <command_duration>` for details.
* ``gcloud`` - Current gcloud active account * ``gcloud`` - Current gcloud active account
* ``hostname`` - Host name of machine * ``hostname`` - Host name of machine
* ``in_toolbox`` - Show identifier if running inside a `toolbox <https://github.com/containers/toolbox>`_ * ``in_toolbox`` - Show identifier if running inside a `toolbox <https://github.com/containers/toolbox>`_
* ``in_vim`` - Show identifier if running in ``:terminal`` from vim * ``in_vim`` - Show identifier if running in ``:terminal`` from vim
* ``k8s_context`` - Show current kubernetes context * ``k8s_context`` - Show current kubernetes context
* ``k8s_namespace`` - Show current kubernetes namespace
* ``last_status`` - Exit status of last run command * ``last_status`` - Exit status of last run command
* ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv``
and ``conda`` supported) and ``conda`` supported)

View File

@ -18,4 +18,4 @@ for file in "$@"; do
fi fi
done done
exit $exit_code exit "${exit_code:-0}"

View File

@ -18,4 +18,4 @@ for file in "$@"; do
fi fi
done done
exit $exit_code exit "${exit_code:-0}"

View File

@ -83,8 +83,8 @@ function _bash-it_check_for_backup() {
fi fi
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2 echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
if ! [[ $overwrite_backup ]]; then if [[ -z "${overwrite_backup}" ]]; then
while ! [[ $silent ]]; do while [[ -z "${silent}" ]]; do
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in case $RESP in
[yY]) [yY])
@ -100,9 +100,9 @@ function _bash-it_check_for_backup() {
esac esac
done done
fi fi
if ! [[ $overwrite_backup ]]; then if [[ -z "${overwrite_backup}" ]]; then
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m" echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
if [[ $silent ]]; then if [[ -n "${silent}" ]]; then
echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m" echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m"
fi fi
exit 1 exit 1
@ -114,8 +114,8 @@ function _bash-it_check_for_backup() {
function _bash-it_modify_config_files() { function _bash-it_modify_config_files() {
_bash-it_check_for_backup _bash-it_check_for_backup
if ! [[ $silent ]]; then if [[ -z "${silent}" ]]; then
while ! [[ $append_to_config ]]; do while [[ -z "${append_to_config}" ]]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in case $choice in
[yY]) [yY])
@ -131,7 +131,7 @@ function _bash-it_modify_config_files() {
esac esac
done done
fi fi
if [[ $append_to_config ]]; then if [[ -n "${append_to_config}" ]]; then
# backup/append # backup/append
_bash-it_backup_append _bash-it_backup_append
else else
@ -174,17 +174,17 @@ done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
if [[ $silent ]] && [[ $interactive ]]; then if [[ -n "${silent}" && -n "${interactive}" ]]; then
echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m" echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
exit 1 exit 1
fi fi
if [[ $no_modify_config ]] && [[ $append_to_config ]]; then if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then
echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m" echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m"
exit 1 exit 1
fi fi
BASH_IT="$(cd "$(dirname "$0")" && pwd)" BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)"
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
@ -197,7 +197,7 @@ esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it" echo "Installing bash-it"
if ! [[ $no_modify_config ]]; then if [[ -z "${no_modify_config}" ]]; then
_bash-it_modify_config_files _bash-it_modify_config_files
fi fi
@ -212,10 +212,10 @@ cite _about _param _example _group _author _version
# shellcheck source=./lib/helpers.bash # shellcheck source=./lib/helpers.bash
source "$BASH_IT/lib/helpers.bash" source "$BASH_IT/lib/helpers.bash"
if [[ $interactive ]] && ! [[ $silent ]]; then if [[ -n $interactive && -z "${silent}" ]]; then
for type in "aliases" "plugins" "completion"; do for type in "aliases" "plugins" "completion"; do
echo -e "\033[0;32mEnabling $type\033[0m" echo -e "\033[0;32mEnabling ${type}\033[0m"
_bash-it_load_some $type _bash-it_load_some "$type"
done done
else else
echo "" echo ""
@ -230,7 +230,7 @@ fi
echo "" echo ""
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m" echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
echo -e "\033[0;32mTo start using it, open a new tab or 'source "$HOME/$CONFIG_FILE"'.\033[0m" echo -e "\033[0;32mTo start using it, open a new tab or 'source "~/$CONFIG_FILE"'.\033[0m"
echo "" echo ""
echo "To show the available aliases/completions/plugins, type one of the following:" echo "To show the available aliases/completions/plugins, type one of the following:"
echo " bash-it show aliases" echo " bash-it show aliases"

105
lib/helpers.bash 100644 → 100755
View File

@ -11,8 +11,8 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
# 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) BASH_IT_SED_I_PARAMETERS=(-i)
case "$(uname)" in case "$OSTYPE" in
Darwin*) BASH_IT_SED_I_PARAMETERS=(-i "") 'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
esac esac
function _command_exists () function _command_exists ()
@ -23,7 +23,13 @@ function _command_exists ()
_example '$ _command_exists ls && echo exists' _example '$ _command_exists ls && echo exists'
_group 'lib' _group 'lib'
local msg="${2:-Command '$1' does not exist!}" local msg="${2:-Command '$1' does not exist!}"
type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; if type -t "$1" &> /dev/null
then
return 0
else
_log_warning "$msg"
return 1
fi
} }
function _binary_exists () function _binary_exists ()
@ -34,7 +40,13 @@ function _binary_exists ()
_example '$ _binary_exists ls && echo exists' _example '$ _binary_exists ls && echo exists'
_group 'lib' _group 'lib'
local msg="${2:-Binary '$1' does not exist!}" local msg="${2:-Binary '$1' does not exist!}"
type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; if type -P "$1" &> /dev/null
then
return 0
else
_log_warning "$msg"
return 1
fi
} }
function _completion_exists () function _completion_exists ()
@ -48,6 +60,22 @@ function _completion_exists ()
complete -p "$1" &> /dev/null && _log_warning "$msg" ; complete -p "$1" &> /dev/null && _log_warning "$msg" ;
} }
function _bash_it_homebrew_check()
{
if _binary_exists 'brew'
then # Homebrew is installed
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]
then # variable isn't set
BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)"
else
true # Variable is set already, don't invoke `brew`.
fi
else # Homebrew is not installed.
BASH_IT_HOMEBREW_PREFIX= # clear variable, if set to anything.
false # return failure if brew not installed.
fi
}
function _make_reload_alias() { function _make_reload_alias() {
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
} }
@ -140,7 +168,7 @@ bash-it ()
$func $arg $func $arg
done done
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then if [ -n "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:-}" ]; then
_bash-it-reload _bash-it-reload
fi fi
else else
@ -194,7 +222,10 @@ _bash-it-update-stable() {
_bash-it-update- stable "$@" _bash-it-update- stable "$@"
} }
_bash-it_pull_and_update_inner() { _bash-it_update_migrate_and_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 '2: Which type of version we are using'
git checkout "$1" &> /dev/null git checkout "$1" &> /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "Bash-it successfully updated." echo "Bash-it successfully updated."
@ -203,7 +234,9 @@ _bash-it_pull_and_update_inner() {
_bash-it-migrate _bash-it-migrate
echo "" echo ""
echo "All done, enjoy!" echo "All done, enjoy!"
bash-it reload # Don't forget to restore the original pwd!
popd &> /dev/null
_bash-it-restart
else else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
fi fi
@ -220,9 +253,11 @@ _bash-it-update-() {
silent=true silent=true
fi fi
done done
local old_pwd="${PWD}"
cd "${BASH_IT}" || return pushd "${BASH_IT}" &> /dev/null || return
DIFF=$(git diff --name-status)
[ -n "$DIFF" ] && echo -e "Local changes detected in bash-it directory. Clean '$BASH_IT' directory to proceed.\n$DIFF" && return 1
if [ -z "$BASH_IT_REMOTE" ]; then if [ -z "$BASH_IT_REMOTE" ]; then
BASH_IT_REMOTE="origin" BASH_IT_REMOTE="origin"
@ -240,6 +275,7 @@ _bash-it-update-() {
if [[ -z "$TARGET" ]]; then if [[ -z "$TARGET" ]]; then
echo "Can not find tags, so can not update to latest stable version..." echo "Can not find tags, so can not update to latest stable version..."
popd &> /dev/null
return return
fi fi
else else
@ -280,12 +316,12 @@ _bash-it-update-() {
if [[ $silent ]]; then if [[ $silent ]]; then
echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..."
_bash-it_pull_and_update_inner $TARGET $version _bash-it_update_migrate_and_restart $TARGET $version
else else
read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP
case $RESP in case $RESP in
[yY]|"") [yY]|"")
_bash-it_pull_and_update_inner $TARGET $version _bash-it_update_migrate_and_restart $TARGET $version
;; ;;
[nN]) [nN])
echo "Not updating…" echo "Not updating…"
@ -302,7 +338,7 @@ _bash-it-update-() {
echo "Bash-it is up to date, nothing to do!" echo "Bash-it is up to date, nothing to do!"
fi fi
fi fi
cd "${old_pwd}" &> /dev/null || return popd &> /dev/null
} }
_bash-it-migrate() { _bash-it-migrate() {
@ -316,7 +352,7 @@ _bash-it-migrate() {
do do
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
do do
typeset ff=$(basename $f) typeset ff="${f##*/}"
# Get the type of component from the extension # Get the type of component from the extension
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
@ -330,8 +366,8 @@ _bash-it-migrate() {
disable_func="_disable-$single_type" disable_func="_disable-$single_type"
enable_func="_enable-$single_type" enable_func="_enable-$single_type"
$disable_func $component_name $disable_func "$component_name"
$enable_func $component_name $enable_func "$component_name"
done done
done done
@ -351,7 +387,7 @@ _bash-it-version() {
cd "${BASH_IT}" || return cd "${BASH_IT}" || return
if [ -z $BASH_IT_REMOTE ]; then if [ -z "${BASH_IT_REMOTE:-}" ]; then
BASH_IT_REMOTE="origin" BASH_IT_REMOTE="origin"
fi fi
@ -425,7 +461,7 @@ _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'
saved_pwd=$(pwd) saved_pwd="${PWD}"
case $OSTYPE in case $OSTYPE in
darwin*) darwin*)
@ -477,7 +513,7 @@ _bash-it-describe ()
do do
# Check for both the old format without the load priority, and the extended format with the priority # Check for both the old format without the load priority, and the extended format with the priority
declare enabled_files enabled_file declare enabled_files enabled_file
enabled_file=$(basename $f) enabled_file="${f##*/}"
enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l) enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l)
if [ $enabled_files -gt 0 ]; then if [ $enabled_files -gt 0 ]; then
@ -579,9 +615,9 @@ _disable-thing ()
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return return
fi fi
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}"
else else
rm "${BASH_IT}/enabled/$(basename $plugin_global)" rm "${BASH_IT}/enabled/${plugin_global##*/}"
fi fi
fi fi
@ -657,7 +693,7 @@ _enable-thing ()
return return
fi fi
to_enable=$(basename $to_enable) to_enable="${to_enable##*/}"
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin" ] ; then if [ ! -z "$enabled_plugin" ] ; then
@ -813,3 +849,30 @@ then
fi fi
} }
fi fi
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
# 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.
function _bash-it-find-in-ancestor() (
about 'searches parents of the current directory for any of the specified file names'
group 'helpers'
param '*: names of files or folders to search for'
returns '0: prints path of closest matching ancestor directory to stdout'
returns '1: no match found'
returns '2: improper usage of shell builtin' # uncommon
example '_bash-it-find-in-ancestor .git .hg'
example '_bash-it-find-in-ancestor GNUmakefile Makefile makefile'
local kin
# To keep things simple, we do not search the root dir.
while [[ "${PWD}" != '/' ]]; do
for kin in "$@"; do
if [[ -r "${PWD}/${kin}" ]]; then
printf '%s' "${PWD}"
return "$?"
fi
done
command cd .. || return "$?"
done
return 1
)

View File

@ -22,8 +22,8 @@ function _log_general()
param '3: message to log' param '3: message to log'
group 'log' group 'log'
message=$2${BASH_IT_LOG_PREFIX}$3 message=$2${BASH_IT_LOG_PREFIX:-default: }$3
_has_colors && echo -e "$1${message}${echo_normal}" || echo -e "${message}" _has_colors && echo -e "$1${message}${echo_normal:-}" || echo -e "${message}"
} }
function _log_debug() function _log_debug()
@ -33,8 +33,8 @@ function _log_debug()
example '$ _log_debug "Loading plugin git..."' example '$ _log_debug "Loading plugin git..."'
group 'log' group 'log'
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0 [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ALL ]] || return 0
_log_general "${echo_green}" "DEBUG: " "$1" _log_general "${echo_green:-}" "DEBUG: " "$1"
} }
function _log_warning() function _log_warning()
@ -44,8 +44,8 @@ function _log_warning()
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" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0 [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_WARNING ]] || return 0
_log_general "${echo_yellow}" " WARN: " "$1" _log_general "${echo_yellow:-}" " WARN: " "$1"
} }
function _log_error() function _log_error()
@ -55,6 +55,6 @@ function _log_error()
example '$ _log_error "Failed to load git plugin..."' example '$ _log_error "Failed to load git plugin..."'
group 'log' group 'log'
[[ "$BASH_IT_LOG_LEVEL" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0 [[ "${BASH_IT_LOG_LEVEL:-0}" -ge $BASH_IT_LOG_LEVEL_ERROR ]] || return 0
_log_general "${echo_red}" "ERROR: " "$1" _log_general "${echo_red:-}" "ERROR: " "$1"
} }

View File

@ -1,4 +1,4 @@
if [[ $BASH_PREVIEW ]]; if [[ "${BASH_PREVIEW:-}" ]];
then then
unset BASH_PREVIEW #Prevent infinite looping unset BASH_PREVIEW #Prevent infinite looping
echo " echo "

0
lib/search.bash 100755 → 100644
View File

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash # shellcheck shell=bash
# #
# A collection of reusable functions. # A collection of reusable functions.
@ -6,22 +6,25 @@
# Generic utilies # Generic utilies
########################################################################### ###########################################################################
_bash-it-get-component-name-from-path() { function _bash-it-get-component-name-from-path() {
# filename without path local filename
filename=${1##*/} # filename without path
# filename without path or priority filename="${1##*/}"
filename=${filename##*---} # filename without path or priority
# filename without path, priority or extension filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}"
echo ${filename%.*.bash} # filename without path, priority or extension
echo "${filename%.*.bash}"
} }
_bash-it-get-component-type-from-path() { function _bash-it-get-component-type-from-path() {
# filename without path local filename
filename=${1##*/} # filename without path
# filename without path or priority filename="${1##*/}"
filename=${filename##*---} # filename without extension
# extension filename="${filename%.bash}"
echo ${filename} | cut -d '.' -f 2 # extension without priority or name
filename="${filename##*.}"
echo "${filename}"
} }
# This function searches an array for an exact match against the term passed # This function searches an array for an exact match against the term passed
@ -43,96 +46,97 @@ _bash-it-get-component-type-from-path() {
# contains pear! # contains pear!
# #
# #
_bash-it-array-contains-element() { function _bash-it-array-contains-element() {
local e local e
for e in "${@:2}"; do for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0 [[ "$e" == "$1" ]] && return 0
done done
return 1 return 1
} }
# Dedupe a simple array of words without spaces. # Dedupe a simple array of words without spaces.
_bash-it-array-dedup() { function _bash-it-array-dedup() {
echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' ' local IFS=$'\n'
echo "$@" | tr ' ' '\n' | sort -u
} }
# Outputs a full path of the grep found on the filesystem # Outputs a full path of the grep found on the filesystem
_bash-it-grep() { function _bash-it-grep() {
if [[ -z "${BASH_IT_GREP}" ]] ; then : "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')" printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
fi
printf "%s " "${BASH_IT_GREP}"
} }
########################################################################### ###########################################################################
# Component-specific functions (component is either an alias, a plugin, or a # Component-specific functions (component is either an alias, a plugin, or a
# completion). # completion).
########################################################################### ###########################################################################
_bash-it-component-help() { function _bash-it-component-help() {
local component=$(_bash-it-pluralize-component "${1}") local component file func
local file=$(_bash-it-component-cache-file ${component}) component="$(_bash-it-pluralize-component "${1}")"
if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then file="$(_bash-it-component-cache-file "${component}")"
rm -f "${file}" 2>/dev/null if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then
local func="_bash-it-${component}" rm -f "${file}" 2> /dev/null
${func} | $(_bash-it-grep) -E ' \[' | cat > ${file} func="_bash-it-${component}"
fi "${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}"
cat "${file}" fi
cat "${file}"
} }
_bash-it-component-cache-file() { function _bash-it-component-cache-file() {
local component=$(_bash-it-pluralize-component "${1}") local component file
local file="${BASH_IT}/tmp/cache/${component}" component="$(_bash-it-pluralize-component "${1}")"
[[ -f ${file} ]] || mkdir -p $(dirname ${file}) file="${BASH_IT?}/tmp/cache/${component}"
printf "${file}" [[ -f "${file}" ]] || mkdir -p "${file%/*}"
printf '%s' "${file}"
} }
_bash-it-pluralize-component() { function _bash-it-pluralize-component() {
local component="${1}" local component="${1}"
local len=$(( ${#component} - 1 )) local -i len=$((${#component} - 1))
# pluralize component name for consistency # pluralize component name for consistency
[[ ${component:${len}:1} != 's' ]] && component="${component}s" [[ "${component:${len}:1}" != 's' ]] && component="${component}s"
[[ ${component} == "alias" ]] && component="aliases" [[ "${component}" == "alias" ]] && component="aliases"
printf ${component} printf '%s' "${component}"
} }
_bash-it-clean-component-cache() { function _bash-it-clean-component-cache() {
local component="$1" local component="$1"
local cache local cache
local -a BASH_IT_COMPONENTS=(aliases plugins completions) local -a BASH_IT_COMPONENTS=(aliases plugins completions)
if [[ -z ${component} ]] ; then if [[ -z "${component}" ]]; then
for component in "${BASH_IT_COMPONENTS[@]}" ; do for component in "${BASH_IT_COMPONENTS[@]}"; do
_bash-it-clean-component-cache "${component}" _bash-it-clean-component-cache "${component}"
done done
else else
cache="$(_bash-it-component-cache-file ${component})" cache="$(_bash-it-component-cache-file "${component}")"
if [[ -f "${cache}" ]] ; then if [[ -f "${cache}" ]]; then
rm -f "${cache}" rm -f "${cache}"
fi fi
fi fi
} }
# Returns an array of items within each compoenent. # Returns an array of items within each compoenent.
_bash-it-component-list() { function _bash-it-component-list() {
local component="$1" local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | awk '{print $1}' | uniq | sort | tr '\n' ' ' _bash-it-component-help "${component}" | awk '{print $1}' | sort -u
} }
_bash-it-component-list-matching() { function _bash-it-component-list-matching() {
local component="$1"; shift local component="$1"
local term="$1" shift
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -- "${term}" | awk '{print $1}' | sort | uniq local term="$1"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -- "${term}" | awk '{print $1}' | sort -u
} }
_bash-it-component-list-enabled() { function _bash-it-component-list-enabled() {
local component="$1" local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | awk '{print $1}' | sort -u
} }
_bash-it-component-list-disabled() { function _bash-it-component-list-disabled() {
local component="$1" local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' ' _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | awk '{print $1}' | sort -u
} }
# Checks if a given item is enabled for a particular component/file-type. # Checks if a given item is enabled for a particular component/file-type.
@ -143,10 +147,10 @@ _bash-it-component-list-disabled() {
# #
# Examples: # Examples:
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled" # _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
_bash-it-component-item-is-enabled() { function _bash-it-component-item-is-enabled() {
local component="$1" local component="$1"
local item="$2" local item="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
} }
# 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.
@ -157,8 +161,8 @@ _bash-it-component-item-is-enabled() {
# #
# Examples: # Examples:
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled" # _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
_bash-it-component-item-is-disabled() { function _bash-it-component-item-is-disabled() {
local component="$1" local component="$1"
local item="$2" local item="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s" _bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
} }

View File

@ -19,6 +19,8 @@ about-plugin 'Automatic completion of aliases'
# Automatically add completion for all aliases to commands having completion functions # Automatically add completion for all aliases to commands having completion functions
function alias_completion { function alias_completion {
local namespace="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 # parse function based completion definitions, where capture group 2 => function and 3 => trigger
local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)' local compl_regex='complete( +[^ ]+)* -F ([^ ]+) ("[^"]+"|[^ ]+)'
@ -26,28 +28,25 @@ function alias_completion {
local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'" local alias_regex="alias( -- | )([^=]+)='(\"[^\"]+\"|[^ ]+)(( +[^ ]+)*)'"
# create array of function completion triggers, keeping multi-word triggers together # create array of function completion triggers, keeping multi-word triggers together
eval "local completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))" eval "completions=($(complete -p | sed -Ene "/$compl_regex/s//'\3'/p"))"
((${#completions[@]} == 0)) && return 0 ((${#completions[@]} == 0)) && return 0
# create temporary file for wrapper functions and completions # create temporary file for wrapper functions and completions
local tmp_file
tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1 tmp_file="$(mktemp -t "${namespace}-${RANDOM}XXXXXX")" || return 1
local completion_loader
completion_loader="$(complete -p -D 2> /dev/null | sed -Ene 's/.* -F ([^ ]*).*/\1/p')" 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 # read in "<alias> '<aliased command>' '<command args>'" lines from defined aliases
local line
# shellcheck disable=SC2162
# some aliases do have backslashes that needs to be interpreted # some aliases do have backslashes that needs to be interpreted
# shellcheck disable=SC2162
while read line; do while read line; do
eval "local alias_tokens; alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error eval "alias_tokens=($line)" 2> /dev/null || continue # some alias arg patterns cause an eval parse error
local alias_name="${alias_tokens[0]}" alias_cmd="${alias_tokens[1]}" alias_args="${alias_tokens[2]# }" # 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 # skip aliases to pipes, boolean control structures and other command lists
# (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters) # (leveraging that eval errs out if $alias_args contains unquoted shell metacharacters)
eval "local alias_arg_words; alias_arg_words=($alias_args)" 2> /dev/null || continue eval "alias_arg_words=($alias_args)" 2> /dev/null || continue
# avoid expanding wildcards # avoid expanding wildcards
read -a alias_arg_words <<< "$alias_args" read -a alias_arg_words <<< "$alias_args"
@ -63,15 +62,15 @@ function alias_completion {
continue continue
fi fi
fi fi
local new_completion="$(complete -p "$alias_cmd" 2> /dev/null)" new_completion="$(complete -p "$alias_cmd" 2> /dev/null)"
# create a wrapper inserting the alias arguments if any # create a wrapper inserting the alias arguments if any
if [[ -n $alias_args ]]; then if [[ -n $alias_args ]]; then
local compl_func="${new_completion/#* -F /}" compl_func="${new_completion/#* -F /}"
compl_func="${compl_func%% *}" compl_func="${compl_func%% *}"
# avoid recursive call loops by ignoring our own functions # avoid recursive call loops by ignoring our own functions
if [[ "${compl_func#_$namespace::}" == "$compl_func" ]]; then if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
local compl_wrapper="_${namespace}::${alias_name}" compl_wrapper="_${namespace}::${alias_name}"
echo "function $compl_wrapper { echo "function $compl_wrapper {
local compl_word=\$2 local compl_word=\$2
local prec_word=\$3 local prec_word=\$3

View File

@ -1,12 +1,15 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details' about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details'
# Only supports the Homebrew variant, Debian and Arch at the moment. # Only supports the Homebrew variant, Debian and Arch at the moment.
# Feel free to provide a PR to support other install locations # Feel free to provide a PR to support other install locations
if command -v brew &>/dev/null && [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]]; then if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
. $(brew --prefix)/etc/profile.d/autojump.sh source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then
. "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" # shellcheck disable=SC1090
elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)"
. "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" elif _command_exists pacman && pacman -Q autojump &> /dev/null; then
# shellcheck disable=SC1090
source "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)"
fi fi

341
plugins/available/base.plugin.bash 100755 → 100644
View File

@ -1,215 +1,180 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'miscellaneous tools' about-plugin 'miscellaneous tools'
function ips () function ips() {
{ about 'display all ip addresses for this host'
about 'display all ip addresses for this host' group 'base'
group 'base' if _command_exists ifconfig; then
if command -v ifconfig &>/dev/null ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }'
then elif _command_exists ip; then
ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' ip addr | grep -oP 'inet \K[\d.]+'
elif command -v ip &>/dev/null else
then echo "You don't have ifconfig or ip command installed!"
ip addr | grep -oP 'inet \K[\d.]+' fi
else
echo "You don't have ifconfig or ip command installed!"
fi
} }
function down4me () function down4me() {
{ about 'checks whether a website is down for you, or everybody'
about 'checks whether a website is down for you, or everybody' param '1: website url'
param '1: website url' example '$ down4me http://www.google.com'
example '$ down4me http://www.google.com' group 'base'
group 'base' curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
} }
function myip () function myip() {
{ about 'displays your ip address, as seen by the Internet'
about 'displays your ip address, as seen by the Internet' group 'base'
group 'base' list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/") for url in "${list[@]}"; do
for url in ${list[*]} if res="$(curl -fs "${url}")"; then
do break
res=$(curl -fs "${url}") fi
if [ $? -eq 0 ];then done
break; res="$(echo "$res" | grep -Eo '[0-9\.]+')"
fi echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
done
res=$(echo "$res" | grep -Eo '[0-9\.]+')
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
} }
function pickfrom () function pickfrom() {
{ about 'picks random line from file'
about 'picks random line from file' param '1: filename'
param '1: filename' example '$ pickfrom /usr/share/dict/words'
example '$ pickfrom /usr/share/dict/words' group 'base'
group 'base' local file=${1:-}
local file=$1 local -i n=0 length
[ -z "$file" ] && reference $FUNCNAME && return if [[ ! -r "$file" ]]; then
length=$(cat $file | wc -l) reference "${FUNCNAME[0]}" && return
n=$(expr $RANDOM \* $length \/ 32768 + 1) fi
head -n $n $file | tail -1 length="$(wc -l < "$file")"
n=$((RANDOM * length / 32768 + 1))
head -n "$n" "$file" | tail -1
} }
function passgen () function passgen() {
{ about 'generates random password from dictionary words'
about 'generates random password from dictionary words' param 'optional integer length'
param 'optional integer length' param 'if unset, defaults to 4'
param 'if unset, defaults to 4' example '$ passgen'
example '$ passgen' example '$ passgen 6'
example '$ passgen 6' group 'base'
group 'base' local -i i length=${1:-4}
local i pass length=${1:-4} local pass
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) # shellcheck disable=SC2034
echo "With spaces (easier to memorize): $pass" pass="$(for i in $(eval "echo {1..$length}"); do pickfrom /usr/share/dict/words; done)"
echo "Without (use this as the password): $(echo $pass | tr -d ' ')" echo "With spaces (easier to memorize): ${pass//$'\n'/ }"
echo "Without spaces (easier to brute force): ${pass//$'\n'/}"
} }
# Create alias pass to passgen when pass isn't installed or # Create alias pass to passgen when pass isn't installed or
# BASH_IT_LEGACY_PASS is true. # BASH_IT_LEGACY_PASS is true.
if ! command -v pass &>/dev/null || [ "$BASH_IT_LEGACY_PASS" = true ] if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then
then alias pass=passgen
alias pass=passgen
fi fi
function pmdown () if _command_exists markdown && _command_exists browser; then
{ function pmdown() {
about 'preview markdown file in a browser' about 'preview markdown file in a browser'
param '1: markdown file' param '1: markdown file'
example '$ pmdown README.md' example '$ pmdown README.md'
group 'base' group 'base'
if command -v markdown &>/dev/null
then
markdown $1 | browser
else
echo "You don't have a markdown command installed!"
fi
}
function mkcd () markdown "${1?}" | browser
{ }
about 'make one or more directories and cd into the last one'
param 'one or more directories to create'
example '$ mkcd foo'
example '$ mkcd /tmp/img/photos/large'
example '$ mkcd foo foo1 foo2 fooN'
example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
group 'base'
mkdir -p -- "$@" && eval cd -- "\"\$$#\""
}
function lsgrep ()
{
about 'search through directory contents with grep'
group 'base'
ls | grep "$*"
}
function quiet ()
{
about 'what *does* this do?'
group 'base'
$* &> /dev/null &
}
function banish-cookies ()
{
about 'redirect .adobe and .macromedia files to /dev/null'
group 'base'
rm -r ~/.macromedia ~/.adobe
ln -s /dev/null ~/.adobe
ln -s /dev/null ~/.macromedia
}
function usage ()
{
about 'disk usage per directory, in Mac OS X and Linux'
param '1: directory name'
group 'base'
if [ $(uname) = "Darwin" ]; then
if [ -n "$1" ]; then
du -hd 1 "$1"
else
du -hd 1
fi
elif [ $(uname) = "Linux" ]; then
if [ -n "$1" ]; then
du -h --max-depth=1 "$1"
else
du -h --max-depth=1
fi
fi
}
if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then
# if user has installed todo plugin, skip this...
function t ()
{
about 'one thing todo'
param 'if not set, display todo item'
param '1: todo text'
if [[ "$*" == "" ]] ; then
cat ~/.t
else
echo "$*" > ~/.t
fi
}
fi fi
function command_exists () function mkcd() {
{ about 'make one or more directories and cd into the last one'
about 'checks for existence of a command' param 'one or more directories to create'
param '1: command to check' example '$ mkcd foo'
example '$ command_exists ls && echo exists' example '$ mkcd /tmp/img/photos/large'
group 'base' example '$ mkcd foo foo1 foo2 fooN'
type "$1" &> /dev/null ; example '$ mkcd /tmp/img/photos/large /tmp/img/photos/self /tmp/img/photos/Beijing'
group 'base'
mkdir -p -- "$@" && cd -- "${!#}" || return
} }
mkiso () # shellcheck disable=SC2010
{ function lsgrep() {
about 'creates iso from current dir in the parent dir (unless defined)' about 'search through directory contents with grep'
param '1: ISO name' group 'base'
param '2: dest/path' ls | grep "$@"
param '3: src/path'
example 'mkiso'
example 'mkiso ISO-Name dest/path src/path'
group 'base'
if type "mkisofs" > /dev/null; then
[ -z ${1+x} ] && local isoname=${PWD##*/} || local isoname=$1
[ -z ${2+x} ] && local destpath=../ || local destpath=$2
[ -z ${3+x} ] && local srcpath=${PWD} || local srcpath=$3
if [ ! -f "${destpath}${isoname}.iso" ]; then
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
mkisofs -V ${isoname} -iso-level 3 -r -o "${destpath}${isoname}.iso" "${srcpath}"
else
echo "${destpath}${isoname}.iso already exists"
fi
else
echo "mkisofs cmd does not exist, please install cdrtools"
fi
} }
function quiet() {
about 'what *does* this do?'
group 'base'
nohup "$@" &> /dev/null < /dev/null &
}
function usage() {
about 'disk usage per directory, in Mac OS X and Linux'
param '1: directory name'
group 'base'
case $OSTYPE in
*'darwin'*)
du -hd 1 "$@"
;;
*'linux'*)
du -h --max-depth=1 "$@"
;;
esac
}
# shellcheck disable=SC2144 # the glob matches only one file
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
# if user has installed todo plugin, skip this...
function t() {
about 'one thing todo'
param 'if not set, display todo item'
param '1: todo text'
if [[ "$*" == "" ]]; then
cat ~/.t
else
echo "$*" > ~/.t
fi
}
fi
if _command_exists mkisofs; then
function mkiso() {
about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name'
param '2: dest/path'
param '3: src/path'
example 'mkiso'
example 'mkiso ISO-Name dest/path src/path'
group 'base'
local isoname="${1:-${PWD##*/}}"
local destpath="${2:-../}"
local srcpath="${3:-${PWD}}"
if [[ ! -f "${destpath%/}/${isoname}.iso" ]]; then
echo "writing ${isoname}.iso to ${destpath} from ${srcpath}"
mkisofs -V "${isoname}" -iso-level 3 -r -o "${destpath%/}/${isoname}.iso" "${srcpath}"
else
echo "${destpath%/}/${isoname}.iso already exists"
fi
}
fi
# useful for administrators and configs # useful for administrators and configs
function buf () function buf() {
{ about 'back up file with timestamp'
about 'back up file with timestamp' param 'filename'
param 'filename' group 'base'
group 'base' local filename="${1?}" filetime
local filename=$1 filetime=$(date +%Y%m%d_%H%M%S)
local filetime=$(date +%Y%m%d_%H%M%S) cp -a "${filename}" "${filename}_${filetime}"
cp -a "${filename}" "${filename}_${filetime}"
} }
function del() { if ! _command_exists del; then
about 'move files to hidden folder in tmp, that gets cleared on each reboot' function del() {
param 'file or folder to be deleted' about 'move files to hidden folder in tmp, that gets cleared on each reboot'
example 'del ./file.txt' param 'file or folder to be deleted'
group 'base' example 'del ./file.txt'
mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; group 'base'
} mkdir -p /tmp/.trash && mv "$@" /tmp/.trash
}
fi

View File

@ -0,0 +1,19 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'load ble.sh, the Bash line editor!'
if [[ ${BLE_VERSION-} ]]; then
_log_warning "ble.sh is already loaded!"
return
fi
_bash_it_ble_path=${XDG_DATA_HOME:-$HOME/.local/share}/blesh/ble.sh
if [[ -f $_bash_it_ble_path ]]; then
# shellcheck disable=1090
source "$_bash_it_ble_path"
else
_log_error "Could not find ble.sh in $_bash_it_ble_path"
_log_error "Please install using the following command:"
_log_error "git clone https://github.com/akinomyoga/ble.sh && make -C ble.sh install"
fi
unset _bash_it_ble_path

View File

@ -3,7 +3,7 @@ about-plugin 'Helpers to get Docker setup correctly for boot2docker'
# Note, this might need to be different if you have an older version # Note, this might need to be different if you have an older version
# of boot2docker, or its configured for a different IP # of boot2docker, or its configured for a different IP
if [[ `uname -s` == "Darwin" ]]; then if [[ "$OSTYPE" == 'darwin'* ]]; then
export DOCKER_HOST="tcp://192.168.59.103:2376" export DOCKER_HOST="tcp://192.168.59.103:2376"
export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm" export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm"
export DOCKER_TLS_VERIFY=1 export DOCKER_TLS_VERIFY=1

View File

@ -9,7 +9,7 @@ precmd_return_notification() {
} }
preexec_return_notification() { preexec_return_notification() {
[ -z "${LAST_COMMAND_TIME}" ] && export LAST_COMMAND_TIME=$(date +%s) [[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s)
} }
precmd_functions+=(precmd_return_notification) precmd_functions+=(precmd_return_notification)

View File

@ -1,4 +1,7 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'load direnv, if you are using it: https://direnv.net/' about-plugin 'load direnv, if you are using it: https://direnv.net/'
[ -x "$(which direnv)" ] && eval "$(direnv hook bash)" if _command_exists direnv; then
eval "$(direnv hook bash)"
fi

View File

@ -23,7 +23,7 @@ alias 8="pushd +8"
alias 9="pushd +9" alias 9="pushd +9"
# Clone this location # Clone this location
alias pc="pushd \$(pwd)" alias pc='pushd "${PWD}"'
# Push new location # Push new location
alias pu="pushd" alias pu="pushd"
@ -73,7 +73,7 @@ G () {
example '$ G ..' example '$ G ..'
group 'dirs' group 'dirs'
cd "${1:-$(pwd)}" ; cd "${1:-${PWD}}" ;
} }
S () { S () {
@ -86,7 +86,7 @@ S () {
sed "/$@/d" ~/.dirs > ~/.dirs1; sed "/$@/d" ~/.dirs > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs; \mv ~/.dirs1 ~/.dirs;
echo "$@"=\"`pwd`\" >> ~/.dirs; echo "$@"=\""${PWD}"\" >> ~/.dirs;
source ~/.dirs ; source ~/.dirs ;
} }

View File

@ -2,12 +2,13 @@
cite about-plugin cite about-plugin
about-plugin 'git helper functions' about-plugin 'git helper functions'
# shellcheck disable=SC2016
function git_remote { function git_remote {
about "adds remote $GIT_HOSTING:$1 to current repo" about 'adds remote $GIT_HOSTING:$1 to current repo'
group "git" group "git"
echo "Running: git remote add origin ${GIT_HOSTING}:$1.git" echo "Running: git remote add origin ${GIT_HOSTING:?}:$1.git"
git remote add origin "$GIT_HOSTING:$1".git git remote add origin "${GIT_HOSTING}:${1}".git
} }
function git_first_push { function git_first_push {
@ -24,14 +25,14 @@ function git_pub() {
BRANCH=$(git rev-parse --abbrev-ref HEAD) BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Publishing ${BRANCH} to remote origin" echo "Publishing ${BRANCH} to remote origin"
git push -u origin "$BRANCH" git push -u origin "${BRANCH}"
} }
function git_revert() { function git_revert() {
about 'applies changes to HEAD that revert all changes after this commit' about 'applies changes to HEAD that revert all changes after this commit'
group 'git' group 'git'
git reset "$1" git reset "${1:?}"
git reset --soft "HEAD@{1}" git reset --soft "HEAD@{1}"
git commit -m "Revert to ${1}" git commit -m "Revert to ${1}"
git reset --hard git reset --hard
@ -49,9 +50,7 @@ function git_rollback() {
} }
function commit_exists() { function commit_exists() {
git rev-list --quiet "$1" if git rev-list --quiet "${1:?}"; then
status=$?
if [ $status -ne 0 ]; then
echo "Commit ${1} does not exist" echo "Commit ${1} does not exist"
kill -INT $$ kill -INT $$
fi fi
@ -61,7 +60,7 @@ function git_rollback() {
while true; do while true; do
# shellcheck disable=SC2162 # shellcheck disable=SC2162
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
case $RESP in case "${RESP}" in
[yY]) [yY])
echo "Rolling back to commit ${1} with unstaged changes" echo "Rolling back to commit ${1} with unstaged changes"
@ -87,7 +86,7 @@ function git_rollback() {
while true; do while true; do
# shellcheck disable=SC2162 # shellcheck disable=SC2162
read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP read -p "WARNING: This will change your history and move the current HEAD back to commit ${1}, continue? [Y/N]" RESP
case $RESP in case "${RESP}" in
[yY]) [yY])
keep_changes "$1" keep_changes "$1"
@ -134,8 +133,8 @@ function git_info() {
# print all remotes and thier details # print all remotes and thier details
for remote in $(git remote show); do for remote in $(git remote show); do
echo "$remote": echo "${remote}":
git remote show "$remote" git remote show "${remote}"
echo echo
done done
@ -172,32 +171,32 @@ function git_stats {
AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ') AUTHORS=$(git shortlog -sn --all | cut -f2 | cut -f1 -d' ')
LOGOPTS="" LOGOPTS=""
if [ "$1" == '-w' ]; then if [ "$1" == '-w' ]; then
LOGOPTS="$LOGOPTS -w" LOGOPTS="${LOGOPTS} -w"
shift shift
fi fi
if [ "$1" == '-M' ]; then if [ "$1" == '-M' ]; then
LOGOPTS="$LOGOPTS -M" LOGOPTS="${LOGOPTS} -M"
shift shift
fi fi
if [ "$1" == '-C' ]; then if [ "$1" == '-C' ]; then
LOGOPTS="$LOGOPTS -C --find-copies-harder" LOGOPTS="${LOGOPTS} -C --find-copies-harder"
shift shift
fi fi
for a in $AUTHORS; do for a in ${AUTHORS}; do
echo '-------------------' echo '-------------------'
echo "Statistics for: $a" echo "Statistics for: ${a}"
echo -n "Number of files changed: " echo -n "Number of files changed: "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f3 | sort -iu | wc -l git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f3 | sort -iu | wc -l
echo -n "Number of lines added: " echo -n "Number of lines added: "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f1 | awk '{s+=$1} END {print s}' git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f1 | awk '{s+=$1} END {print s}'
echo -n "Number of lines deleted: " echo -n "Number of lines deleted: "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
git log $LOGOPTS --all --numstat --format="%n" --author="$a" | cut -f2 | awk '{s+=$1} END {print s}' git log ${LOGOPTS} --all --numstat --format="%n" --author="${a}" | cut -f2 | awk '{s+=$1} END {print s}'
echo -n "Number of merges: " echo -n "Number of merges: "
# shellcheck disable=SC2086 # shellcheck disable=SC2086
git log $LOGOPTS --all --merges --author="$a" | grep -c '^commit' git log ${LOGOPTS} --all --merges --author="${a}" | grep -c '^commit'
done done
else else
echo "you're currently not in a git repository" echo "you're currently not in a git repository"
@ -212,18 +211,16 @@ function gittowork() {
result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null) result=$(curl -L "https://www.gitignore.io/api/$1" 2> /dev/null)
if [[ $result =~ ERROR ]]; then if [[ "${result}" =~ ERROR ]]; then
echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'" echo "Query '$1' has no match. See a list of possible queries with 'gittowork list'"
elif [[ $1 = list ]]; then elif [[ $1 == list ]]; then
echo "$result" echo "${result}"
else else
if [[ -f .gitignore ]]; then if [[ -f .gitignore ]]; then
result=$(echo "$result" | grep -v "# Created by http://www.gitignore.io") result=$(grep -v "# Created by http://www.gitignore.io" <<< "${result}")
echo ".gitignore already exists, appending..." echo ".gitignore already exists, appending..."
echo "$result" >> .gitignore
else
echo "$result" > .gitignore
fi fi
echo "${result}" >> .gitignore
fi fi
} }
@ -257,7 +254,7 @@ function gitignore-reload() {
fi fi
# Prompt user to commit or stash changes and exit # Prompt user to commit or stash changes and exit
if [ $err = 1 ]; then if [[ "${err}" == 1 ]]; then
echo >&2 "Please commit or stash them." echo >&2 "Please commit or stash them."
fi fi
@ -265,7 +262,7 @@ function gitignore-reload() {
# If we're here, then there are no uncommited or unstaged changes dangling around. # If we're here, then there are no uncommited or unstaged changes dangling around.
# Proceed to reload .gitignore # Proceed to reload .gitignore
if [ $err = 0 ]; then if [[ "${err}" == 0 ]]; then
# Remove all cached files # Remove all cached files
git rm -r --cached . git rm -r --cached .
@ -290,6 +287,7 @@ function git-changelog() {
return 1 return 1
fi fi
# shellcheck disable=SC2155
local NEXT=$(date +%F) local NEXT=$(date +%F)
if [[ "$2" == "md" ]]; then if [[ "$2" == "md" ]]; then
@ -298,9 +296,9 @@ function git-changelog() {
# shellcheck disable=SC2162 # shellcheck disable=SC2162
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo echo
echo "### $DATE" echo "### ${DATE}"
git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="$DATE 00:00:00" --until="$DATE 24:00:00" git log --no-merges --format=" * (%h) %s by [%an](mailto:%ae)" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
NEXT=$DATE NEXT=${DATE}
done done
else else
echo "CHANGELOG $1" echo "CHANGELOG $1"
@ -309,9 +307,10 @@ function git-changelog() {
# shellcheck disable=SC2162 # shellcheck disable=SC2162
git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do git log "$1" --no-merges --format="%cd" --date=short | sort -u -r | while read DATE; do
echo echo
echo [$DATE] echo "[${DATE}]"
git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="$DATE 00:00:00" --until="$DATE 24:00:00" git log --no-merges --format=" * (%h) %s by %an <%ae>" --since="${DATE} 00:00:00" --until="${DATE} 24:00:00"
NEXT=$DATE # shellcheck disable=SC2034
NEXT=${DATE}
done done
fi fi
} }

View File

@ -30,7 +30,7 @@ eval "$(goenv init - bash)"
# If moving to a directory with a goenv version set, reload the shell # If moving to a directory with a goenv version set, reload the shell
# to ensure the shell environment matches expectations. # to ensure the shell environment matches expectations.
_bash-it-goenv-preexec() { _bash-it-goenv-preexec() {
export GOENV_OLD_VERSION="$(goenv version-name)" GOENV_OLD_VERSION="$(goenv version-name)"
} }
_bash-it-goenv-precmd() { _bash-it-goenv-precmd() {
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then

View File

@ -3,19 +3,10 @@ about-plugin 'Add a gw command to use gradle wrapper if present, else use system
function gw() { function gw() {
local file="gradlew" local file="gradlew"
local curr_path="${PWD}" local result
local result="gradle"
# Search recursively upwards for file. result="$(_bash-it-find-in-ancestor "${file}")"
until [[ "${curr_path}" == "/" ]]; do
if [[ -e "${curr_path}/${file}" ]]; then
result="${curr_path}/${file}"
break
else
curr_path=$(dirname "${curr_path}")
fi
done
# Call gradle # Call gradle
"${result}" $* "${result:-gradle}" $*
} }

View File

@ -1,4 +1,7 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'load hub, if you are using it' about-plugin 'load hub, if you are using it'
command -v hub &> /dev/null && eval "$(hub alias -s)" if _command_exists hub; then
eval "$(hub alias -s)"
fi

View File

@ -16,7 +16,7 @@ editpost() {
for site in ${SITES[@]} for site in ${SITES[@]}
do do
if [ "$(basename $site)" = "$1" ] if [ "${site##*/}" = "$1" ]
then then
SITE=$site SITE=$site
break break
@ -77,7 +77,7 @@ newpost() {
for site in ${SITES[@]} for site in ${SITES[@]}
do do
if [ "$(basename $site)" = "$1" ] if [ "${site##*/}" = "$1" ]
then then
SITE=$site SITE=$site
JEKYLL_FORMATTING=${MARKUPS[$loc]} JEKYLL_FORMATTING=${MARKUPS[$loc]}
@ -280,7 +280,7 @@ function testsite() {
for site in ${SITES[@]} for site in ${SITES[@]}
do do
if [ "$(basename $site)" = "$1" ] if [ "${site##*/}" = "$1" ]
then then
SITE=$site SITE=$site
break break
@ -312,7 +312,7 @@ function buildsite() {
for site in ${SITES[@]} for site in ${SITES[@]}
do do
if [ "$(basename $site)" = "$1" ] if [ "${site##*/}" = "$1" ]
then then
SITE=$site SITE=$site
break break
@ -347,7 +347,7 @@ function deploysite() {
for site in ${SITES[@]} for site in ${SITES[@]}
do do
if [ "$(basename $site)" = "$1" ] if [ "${site##*/}" = "$1" ]
then then
SITE=$site SITE=$site
REMOTE=${REMOTES[$loc]} REMOTE=${REMOTES[$loc]}

View File

@ -1,9 +1,12 @@
# shellcheck shell=bash
# shellcheck disable=SC2016
cite about-plugin cite about-plugin
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding' about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding'
__init_jump() { function __init_jump() {
command -v jump &> /dev/null || return if _command_exists jump; then
eval "$(jump shell bash "${JUMP_OPTS[@]}")" eval "$(jump shell bash "${JUMP_OPTS[@]}")"
fi
} }
__init_jump __init_jump

View File

@ -1,31 +1,23 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'pygmentize instead of cat to terminal if possible' about-plugin 'pygmentize instead of cat to terminal if possible'
if $(command -v pygmentize &> /dev/null) ; then _command_exists pygmentize || return
# get the full paths to binaries
CAT_BIN=$(which cat)
LESS_BIN=$(which less)
BASH_IT_CCAT_STYLE="${BASH_IT_CCAT_STYLE:=default}"
BASH_IT_CLESS_STYLE="${BASH_IT_CLESS_STYLE:=default}"
# pigmentize cat and less outputs - call them ccat and cless to avoid that # pigmentize cat and less outputs - call them ccat and cless to avoid that
# especially cat'ed output in scripts gets mangled with pygemtized meta characters # especially cat'ed output in scripts gets mangled with pygemtized meta characters
function ccat() function ccat() {
{ about 'runs pygmentize on each file passed in'
about 'runs either pygmentize or cat on each file passed in' param '*: files to concatenate (as normally passed to cat)'
param '*: files to concatenate (as normally passed to cat)' example 'ccat mysite/manage.py dir/text-file.txt'
example 'cat mysite/manage.py dir/text-file.txt'
for var;
do
pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var";
done
}
function cless() pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@"
{ }
about 'it pigments the file passed in and passes it to less for pagination'
param '$1: the file to paginate with less' function cless() {
example 'less mysite/manage.py' about 'pigments the files passed in and passes to less for pagination'
pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R param '*: the files to paginate with less'
} example 'cless mysite/manage.py'
fi
pygmentize -f 256 -O style="${BASH_IT_CLESS_STYLE:-default}" -g "$@" | command less -R
}

View File

@ -1,13 +1,14 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'Node.js helper functions' about-plugin 'Node.js helper functions'
# Check that we have npm
_command_exists npm || return
# Ensure local modules are preferred in PATH # Ensure local modules are preferred in PATH
pathmunge "./node_modules/.bin" "after" pathmunge "./node_modules/.bin" "after"
# Check that we have npm
out=$(command -v npm 2>&1) || return
# If not using nodenv, ensure global modules are in PATH # If not using nodenv, ensure global modules are in PATH
if [[ ! $out == *"nodenv/shims"* ]] ; then if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
pathmunge "$(npm config get prefix)/bin" "after" pathmunge "$(npm config get prefix)/bin" "after"
fi fi

View File

@ -1,7 +1,10 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'load nodenv, if you are using it' about-plugin 'load nodenv, if you are using it'
export NODENV_ROOT="$HOME/.nodenv" export NODENV_ROOT="$HOME/.nodenv"
pathmunge "$NODENV_ROOT/bin" pathmunge "$NODENV_ROOT/bin"
[[ `which nodenv` ]] && eval "$(nodenv init - bash)" if _command_exists nodenv; then
eval "$(nodenv init - bash)"
fi

View File

@ -1,22 +1,23 @@
# Bash-it no longer bundles nvm, as this was quickly becoming outdated. # shellcheck shell=bash
# #
# BASH_IT_LOAD_PRIORITY: 225 # BASH_IT_LOAD_PRIORITY: 225
# #
# Bash-it no longer bundles nvm, as this was quickly becoming outdated.
# Please install nvm from https://github.com/creationix/nvm.git if you want to use it. # Please install nvm from https://github.com/creationix/nvm.git if you want to use it.
cite about-plugin cite about-plugin
about-plugin 'node version manager configuration' about-plugin 'node version manager configuration'
export NVM_DIR=${NVM_DIR:-$HOME/.nvm} export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
# This loads nvm # This loads nvm
if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]]
then then
. $(brew --prefix nvm)/nvm.sh source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh"
else else
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
fi fi
if ! command -v nvm &>/dev/null if ! _command_exists nvm
then then
function nvm() { function nvm() {
echo "Bash-it no longer bundles the nvm script. Please install the latest version from" echo "Bash-it no longer bundles the nvm script. Please install the latest version from"

View File

@ -15,7 +15,7 @@ function time-machine-list-machines() {
local tmdest="$(time-machine-destination)/Backups.backupdb" local tmdest="$(time-machine-destination)/Backups.backupdb"
find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do
echo "$(basename "$line")" echo "${line##*/}"
done done
} }

View File

@ -2,7 +2,7 @@ cite about-plugin
about-plugin 'osx-specific functions' about-plugin 'osx-specific functions'
# OS X: Open new tabs in same directory # OS X: Open new tabs in same directory
if [ $(uname) = "Darwin" ]; then if [[ $OSTYPE == 'darwin'* ]]; then
if type update_terminal_cwd > /dev/null 2>&1 ; then if type update_terminal_cwd > /dev/null 2>&1 ; then
if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then if ! [[ $PROMPT_COMMAND =~ (^|;)update_terminal_cwd($|;) ]] ; then
PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd" PROMPT_COMMAND="${PROMPT_COMMAND%;};update_terminal_cwd"
@ -46,13 +46,13 @@ function dock-switch() {
example '$ dock-switch 2d' example '$ dock-switch 2d'
group 'osx' group 'osx'
if [ $(uname) = "Darwin" ]; then if [[ "$OSTYPE" = 'darwin'* ]]; then
if [ $1 = 3d ] ; then if [[ $1 = 3d ]] ; then
defaults write com.apple.dock no-glass -boolean NO defaults write com.apple.dock no-glass -boolean NO
killall Dock killall Dock
elif [ $1 = 2d ] ; then elif [[ $1 = 2d ]] ; then
defaults write com.apple.dock no-glass -boolean YES defaults write com.apple.dock no-glass -boolean YES
killall Dock killall Dock
@ -90,7 +90,7 @@ function prevcurl() {
param '1: url' param '1: url'
group 'osx' group 'osx'
if [ ! $(uname) = "Darwin" ] if [[ ! $OSTYPE = 'darwin'* ]]
then then
echo "This function only works with Mac OS X" echo "This function only works with Mac OS X"
return 1 return 1
@ -103,7 +103,7 @@ function refresh-launchpad() {
example '$ refresh-launchpad' example '$ refresh-launchpad'
group 'osx' group 'osx'
if [ $(uname) = "Darwin" ];then if [[ "$OSTYPE" = 'darwin'* ]];then
defaults write com.apple.dock ResetLaunchPad -bool TRUE defaults write com.apple.dock ResetLaunchPad -bool TRUE
killall Dock killall Dock
else else

View File

@ -1,3 +1,4 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'Search&Select history with percol' about-plugin 'Search&Select history with percol'
@ -12,24 +13,20 @@ about-plugin 'Search&Select history with percol'
# Usage # Usage
## C-r to search&select from history ## C-r to search&select from history
_replace_by_history() { _command_exists percol || return
if command -v tac>/dev/null; then
alias _tac=tac
else
alias _tac="tail -r"
fi
local l=$(HISTTIMEFORMAT= history | _tac | sed -e 's/^\ *[0-9]*\ *//' | percol --query "$READLINE_LINE")
READLINE_LINE="$l"
READLINE_POINT=${#l}
}
if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
if command -v percol>/dev/null; then _log_warning "You have to upgrade Bash to Bash v4.x to use the 'percol' plugin."
current_version=${BASH_VERSION%%[^0-9]*} _log_warning "Your current Bash version is $BASH_VERSION."
if [ $current_version -lt 4 ]; then return
echo -e "\033[91mWarning: You have to upgrade Bash to Bash v4.x to use the 'percol' plugin.\033[m"
echo -e "\033[91m Your current Bash version is $BASH_VERSION.\033[m"
else
bind -x '"\C-r": _replace_by_history'
fi
fi fi
function _replace_by_history() {
local HISTTIMEFORMAT= # Ensure we can parse history properly
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
local l
l="$(history | tail -r | sed -e 's/^\ *[0-9]*\ *//' | percol --query "${READLINE_LINE:-}")"
READLINE_LINE="${l}"
READLINE_POINT=${#l}
}
bind -x '"\C-r": _replace_by_history'

View File

@ -1,18 +1,16 @@
# shellcheck shell=bash
#
# plugin for plenv # plugin for plenv
cite about-plugin cite about-plugin
about-plugin 'plenv plugin for Perl' about-plugin 'plenv plugin for Perl'
if [[ -e "${HOME}/.plenv/bin" ]] ; then if [[ -d "${HOME}/.plenv/bin" ]]; then
# load plenv bin dir into path if it exists
# load plenv bin dir into path if it exists pathmunge "${HOME}/.plenv/bin"
pathmunge "${HOME}/.plenv/bin"
fi fi
if [[ `which plenv` ]] ; then if _command_exists plenv; then
# init plenv
# init plenv eval "$(plenv init - bash)"
eval "$(plenv init - bash)"
fi fi

View File

@ -1,9 +1,9 @@
#!/usr/bin/env bash # shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'enables powerline daemon' about-plugin 'enables powerline daemon'
command -v powerline-daemon &>/dev/null || return _command_exists powerline-daemon || return
powerline-daemon -q powerline-daemon -q
#the following should not be executed if bashit powerline themes in use #the following should not be executed if bashit powerline themes in use
@ -14,13 +14,13 @@ case "$BASH_IT_THEME" in
esac esac
POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1 POWERLINE_BASH_SELECT=1
bashPowerlineInit=$(python -c \ bashPowerlineInit="$(python -c \
"import os; \ "import os; \
import powerline;\ import powerline;\
print(os.path.join(os.path.dirname(\ print(os.path.join(os.path.dirname(\
powerline.__file__),\ powerline.__file__),\
'bindings', \ 'bindings', \
'bash', \ 'bash', \
'powerline.sh'))") 'powerline.sh'))")"
[ -e $bashPowerlineInit ] || return [ -e $bashPowerlineInit ] || return
. $bashPowerlineInit source $bashPowerlineInit

View File

@ -1,12 +1,34 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'load pyenv, if you are using it' about-plugin 'load pyenv, if you are using it'
export PYENV_ROOT="$HOME/.pyenv" # https://github.com/pyenv/pyenv
pathmunge "$PYENV_ROOT/bin"
[[ `which pyenv 2>/dev/null` ]] && eval "$(pyenv init - bash)" # Load after basher
# BASH_IT_LOAD_PRIORITY: 260
#Load pyenv virtualenv if the virtualenv plugin is installed. # Don't modify the environment if we can't find the tool:
if pyenv virtualenv-init - &> /dev/null; then # - Check if in $PATH already
eval "$(pyenv virtualenv-init - bash)" # - Check if installed manually to $PYENV_ROOT
# - Check if installed manually to $HOME
_command_exists pyenv \
|| [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \
|| [[ -x "$HOME/.pyenv/bin/pyenv" ]] \
|| return 0
# Set PYENV_ROOT, if not already set
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
# Add PYENV_ROOT/bin to PATH, if that's where it's installed
if ! _command_exists pyenv && [[ -x "$PYENV_ROOT/bin/pyenv" ]]; then
pathmunge "$PYENV_ROOT/bin"
fi
# Initialize pyenv
pathmunge "$PYENV_ROOT/shims"
eval "$(pyenv init - bash)"
# Load pyenv virtualenv if the virtualenv plugin is installed.
if pyenv virtualenv-init - &> /dev/null; then
eval "$(pyenv virtualenv-init - bash)"
fi fi

View File

@ -1,7 +1,7 @@
cite about-plugin cite about-plugin
about-plugin 'alias "shttp" to SimpleHTTPServer' about-plugin 'alias "shttp" to SimpleHTTPServer'
if [ $(uname) = "Linux" ] if [[ "$OSTYPE" == 'linux'* ]]
then then
alias shttp='python2 -m SimpleHTTPServer' alias shttp='python2 -m SimpleHTTPServer'
else else
@ -16,7 +16,7 @@ function pyedit() {
xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"` xpyc=`python -c "import os, sys; f = open(os.devnull, 'w'); sys.stderr = f; module = __import__('$1'); sys.stdout.write(module.__file__)"`
if [ "$xpyc" == "" ]; then if [[ "$xpyc" == "" ]]; then
echo "Python module $1 not found" echo "Python module $1 not found"
return -1 return -1

View File

@ -1,7 +1,10 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'load rbenv, if you are using it' about-plugin 'load rbenv, if you are using it'
export RBENV_ROOT="$HOME/.rbenv" export RBENV_ROOT="$HOME/.rbenv"
pathmunge "$RBENV_ROOT/bin" pathmunge "$RBENV_ROOT/bin"
[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)" if _command_exists rbenv; then
eval "$(rbenv init - bash)"
fi

View File

@ -1,16 +1,17 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'ruby and rubygems specific functions and settings' about-plugin 'ruby and rubygems specific functions and settings'
# Make commands installed with 'gem install --user-install' available # Make commands installed with 'gem install --user-install' available
# ~/.gem/ruby/${RUBY_VERSION}/bin/ # ~/.gem/ruby/${RUBY_VERSION}/bin/
if which ruby >/dev/null && which gem >/dev/null; then if _command_exists ruby && _command_exists gem; then
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
fi fi
function remove_gem { function remove_gem() {
about 'removes installed gem' about 'removes installed gem'
param '1: installed gem name' param '1: installed gem name'
group 'ruby' group 'ruby'
gem list | grep $1 | awk '{ print $1; }' | xargs sudo gem uninstall gem list | grep "${1:?${FUNCNAME[0]}: no gem name provided}" | awk '{ print $1; }' | xargs sudo gem uninstall
} }

View File

@ -1,7 +1,9 @@
# shellcheck shell=bash
cite about-plugin cite about-plugin
about-plugin 'set textmate as a default editor' about-plugin 'set textmate as a default editor'
if $(command -v mate &> /dev/null) ; then if _command_exists mate; then
export EDITOR="$(which mate) -w" EDITOR="$(type -p mate) -w"
export GIT_EDITOR=$EDITOR GIT_EDITOR="$EDITOR"
export EDITOR GIT_EDITOR
fi fi

View File

View File

@ -1,12 +1,14 @@
# shellcheck shell=bash
#
# make sure virtualenvwrapper is enabled if available # make sure virtualenvwrapper is enabled if available
cite about-plugin cite about-plugin
about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions' about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions'
if _command_exists pyenv; then if _command_exists pyenv; then
pyenv virtualenvwrapper pyenv virtualenvwrapper
else elif _command_exists virtualenvwrapper.sh; then
[[ `which virtualenvwrapper.sh` ]] && . virtualenvwrapper.sh source virtualenvwrapper.sh
fi fi
@ -14,8 +16,8 @@ function mkvenv {
about 'create a new virtualenv for this directory' about 'create a new virtualenv for this directory'
group 'virtualenv' group 'virtualenv'
cwd=`basename \`pwd\`` local cwd="${PWD##*/}"
mkvirtualenv --distribute $cwd mkvirtualenv --distribute "$cwd"
} }
@ -23,19 +25,21 @@ function mkvbranch {
about 'create a new virtualenv for the current branch' about 'create a new virtualenv for the current branch'
group 'virtualenv' group 'virtualenv'
mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH" local cwd="${PWD##*/}"
mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}"
} }
function wovbranch { function wovbranch {
about 'sets workon branch' about 'sets workon branch'
group 'virtualenv' group 'virtualenv'
workon "$(basename `pwd`)@$SCM_BRANCH" local cwd="${PWD##*/}"
workon "${cwd}@${SCM_BRANCH}"
} }
function wovenv { function wovenv {
about 'works on the virtualenv for this directory' about 'works on the virtualenv for this directory'
group 'virtualenv' group 'virtualenv'
workon "$(basename `pwd`)" workon "${PWD##*/}"
} }

View File

@ -3,29 +3,37 @@ cite about-plugin
about-plugin 'automatically set your xterm title with host and location info' about-plugin 'automatically set your xterm title with host and location info'
_short-dirname() { _short-dirname() {
local dir_name=$(dirs +0) local dir_name="${PWD/~/\~}"
[ "$SHORT_TERM_LINE" = true ] && [ "${#dir_name}" -gt 8 ] && echo "${dir_name##*/}" || echo "${dir_name}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
echo "${dir_name##*/}"
else
echo "${dir_name}"
fi
} }
_short-command() { _short-command() {
local input_command="$*" local input_command="$*"
[ "$SHORT_TERM_LINE" = true ] && [ "${#input_command}" -gt 8 ] && echo "${input_command%% *}" || echo "${input_command}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
echo "${input_command%% *}"
else
echo "${input_command}"
fi
} }
set_xterm_title() { set_xterm_title() {
local title="$1" local title="${1:-}"
echo -ne "\033]0;$title\007" echo -ne "\033]0;${title}\007"
} }
precmd_xterm_title() { precmd_xterm_title() {
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) $PROMPT_CHAR" set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
} }
preexec_xterm_title() { preexec_xterm_title() {
set_xterm_title "$(_short-command "${1}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})" set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
} }
case "$TERM" in case "${TERM:-dumb}" in
xterm* | rxvt*) xterm* | rxvt*)
precmd_functions+=(precmd_xterm_title) precmd_functions+=(precmd_xterm_title)
preexec_functions+=(preexec_xterm_title) preexec_functions+=(preexec_xterm_title)

View File

@ -11,7 +11,7 @@ autoenv_init()
typeset target home _file typeset target home _file
typeset -a _files typeset -a _files
target=$1 target=$1
home="$(dirname "$HOME")" home="${HOME%/*}"
_files=( $( _files=( $(
while [[ "$PWD" != "/" && "$PWD" != "$home" ]] while [[ "$PWD" != "/" && "$PWD" != "$home" ]]

3
scripts/reloader.bash 100644 → 100755
View File

@ -5,6 +5,7 @@ function _set-prefix-based-on-path()
{ {
filename=$(_bash-it-get-component-name-from-path "$1") filename=$(_bash-it-get-component-name-from-path "$1")
extension=$(_bash-it-get-component-type-from-path "$1") extension=$(_bash-it-get-component-type-from-path "$1")
# shellcheck disable=SC2034
BASH_IT_LOG_PREFIX="$extension: $filename: " BASH_IT_LOG_PREFIX="$extension: $filename: "
} }
@ -15,7 +16,7 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
alias|completion|plugin) alias|completion|plugin)
_bash_it_config_type=$1 _bash_it_config_type=$1
_log_debug "Loading enabled $1 components..." ;; _log_debug "Loading enabled $1 components..." ;;
*|'') ''|*)
_log_debug "Loading all enabled components..." ;; _log_debug "Loading all enabled components..." ;;
esac esac

0
test/fixtures/svn/broken/xcrun vendored 100755
View File

View File

View File

@ -5,11 +5,11 @@ load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log load ../../lib/log
load ../../lib/utilities load ../../lib/utilities
load ../../lib/search load ../../lib/search
load ../../plugins/available/base.plugin
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
load ../../lib/helpers load ../../lib/helpers
load ../../plugins/available/base.plugin
function local_setup { function local_setup {
setup_test_fixture setup_test_fixture

View File

@ -3,27 +3,28 @@
load ../test_helper load ../test_helper
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/appearance load ../../lib/appearance
load ../../plugins/available/base.plugin
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
load ../../lib/log load ../../lib/log
load ../../lib/helpers
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
run _log_debug "test test test" run _log_debug "test test test"
assert_output "DEBUG: test test test" assert_output "DEBUG: default: test test test"
} }
@test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic warning 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
run _log_warning "test test test" run _log_warning "test test test"
assert_output " WARN: test test test" assert_output " WARN: default: test test test"
} }
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { @test "lib log: basic error 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
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: test test test" assert_output "ERROR: default: test test test"
} }
@test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" {
@ -35,13 +36,13 @@ load ../../lib/log
@test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING
run _log_warning "test test test" run _log_warning "test test test"
assert_output " WARN: test test test" assert_output " WARN: default: test test test"
} }
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: test test test" assert_output "ERROR: default: test test test"
} }
@ -60,7 +61,7 @@ load ../../lib/log
@test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" {
BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR
run _log_error "test test test" run _log_error "test test test"
assert_output "ERROR: test test test" assert_output "ERROR: default: test test test"
} }
@test "lib log: basic debug silent logging" { @test "lib log: basic debug silent logging" {

View File

@ -2,6 +2,8 @@
load ../test_helper load ../test_helper
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load ../../lib/log
load ../../lib/helpers
load ../../plugins/available/base.plugin load ../../plugins/available/base.plugin
@test 'plugins base: ips()' { @test 'plugins base: ips()' {
@ -40,7 +42,7 @@ load ../../plugins/available/base.plugin
mkcd "${dir_name}" mkcd "${dir_name}"
assert_success assert_success
assert_dir_exist "${BASH_IT_ROOT}/${dir_name}" assert_dir_exist "${BASH_IT_ROOT}/${dir_name}"
assert_equal $(pwd) "${BASH_IT_ROOT}/${dir_name}" assert_equal "${PWD}" "${BASH_IT_ROOT}/${dir_name}"
} }
@test 'plugins base: lsgrep()' { @test 'plugins base: lsgrep()' {

2
test/plugins/battery.plugin.bats 100644 → 100755
View File

@ -2,6 +2,8 @@
load ../test_helper load ../test_helper
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
load "${BASH_IT}/lib/log.bash"
load "${BASH_IT}/lib/helpers.bash"
cite _about _param _example _group _author _version cite _about _param _example _group _author _version

View File

@ -4,50 +4,52 @@ load ../test_helper
load ../../lib/helpers load ../../lib/helpers
load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
# We test `go version` in each test to account for users with goenv and no system go.
@test 'ensure _bash-it-gopath-pathmunge is defined' { @test 'ensure _bash-it-gopath-pathmunge is defined' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
run type -t _bash-it-gopath-pathmunge run type -t _bash-it-gopath-pathmunge
assert_line 'function' assert_line 'function'
} }
@test 'plugins go: single entry in GOPATH' { @test 'plugins go: single entry in GOPATH' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo" export GOPATH="/foo"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin" assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin"
} }
@test 'plugins go: single entry in GOPATH, with space' { @test 'plugins go: single entry in GOPATH, with space' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo bar" export GOPATH="/foo bar"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin" assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin"
} }
@test 'plugins go: single entry in GOPATH, with escaped space' { @test 'plugins go: single entry in GOPATH, with escaped space' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo\ bar" export GOPATH="/foo\ bar"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin" assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin"
} }
@test 'plugins go: multiple entries in GOPATH' { @test 'plugins go: multiple entries in GOPATH' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo:/bar" export GOPATH="/foo:/bar"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin" assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin"
} }
@test 'plugins go: multiple entries in GOPATH, with space' { @test 'plugins go: multiple entries in GOPATH, with space' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo:/foo bar" export GOPATH="/foo:/foo bar"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin" assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin"
} }
@test 'plugins go: multiple entries in GOPATH, with escaped space' { @test 'plugins go: multiple entries in GOPATH, with escaped space' {
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found' { _command_exists go && go version &>/dev/null; } || skip 'golang not found'
export GOPATH="/foo:/foo\ bar" export GOPATH="/foo:/foo\ bar"
load ../../plugins/available/go.plugin load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin" assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin"

View File

@ -6,7 +6,7 @@ git submodule init && git submodule update
if [ -z "${BASH_IT}" ]; then if [ -z "${BASH_IT}" ]; then
declare BASH_IT declare BASH_IT
BASH_IT=$(cd ${test_directory} && dirname "$(pwd)") BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")"
export BASH_IT export BASH_IT
fi fi

View File

@ -7,7 +7,6 @@ load ../../lib/log
cite _about _param _example _group _author _version cite _about _param _example _group _author _version
load ../../lib/helpers load ../../lib/helpers
load ../../themes/base.theme
function local_setup { function local_setup {
setup_test_fixture setup_test_fixture
@ -23,6 +22,8 @@ function local_setup {
fi fi
export OLD_PATH="$PATH" export OLD_PATH="$PATH"
load ../../themes/base.theme
} }
function local_teardown { function local_teardown {
@ -56,8 +57,8 @@ function setup_svn_path {
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Load the base theme again so that the working SVN script is detected # Init the base theme again so that the working SVN script is detected
load ../../themes/base.theme _bash_it_appearance_scm_init
scm scm
# Make sure that the SVN command is used # Make sure that the SVN command is used
@ -73,8 +74,8 @@ function setup_svn_path {
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Load the base theme again so that the working SVN script is detected # init the base theme again so that the working SVN script is detected
load ../../themes/base.theme _bash_it_appearance_scm_init
scm scm
# Make sure that the SVN command is used # Make sure that the SVN command is used
@ -89,8 +90,8 @@ function setup_svn_path {
setup_svn_path "$BASH_IT/test/fixtures/svn/working" setup_svn_path "$BASH_IT/test/fixtures/svn/working"
# Load the base theme again so that the working SVN script is detected # Init the base theme again so that the working SVN script is detected
load ../../themes/base.theme _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is used # Make sure that no SVN command is used
@ -103,8 +104,8 @@ function setup_svn_path {
setup_svn_path "$BASH_IT/test/fixtures/svn/broken" setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Load the base theme again so that the broken SVN script is detected # Init the base theme again so that the broken SVN script is detected
load ../../themes/base.theme _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is not used # Make sure that no SVN command is not used
@ -120,8 +121,8 @@ function setup_svn_path {
setup_svn_path "$BASH_IT/test/fixtures/svn/broken" setup_svn_path "$BASH_IT/test/fixtures/svn/broken"
# Load the base theme again so that the broken SVN script is detected # Init the base theme again so that the broken SVN script is detected
load ../../themes/base.theme _bash_it_appearance_scm_init
scm scm
# Make sure that no SVN command is used # Make sure that no SVN command is used

View File

@ -1,4 +1,7 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
SCM_THEME_PROMPT_DIRTY=" ${red}" SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |" SCM_THEME_PROMPT_PREFIX=" |"
@ -11,7 +14,7 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
# Nicely formatted terminal prompt # Nicely formatted terminal prompt
function prompt_command() { function prompt_command() {
export PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ " PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ "
} }
safe_append_prompt_command prompt_command safe_append_prompt_command prompt_command

View File

@ -1,4 +1,5 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# vim: ft=bash ts=2 sw=2 sts=2 # vim: ft=bash ts=2 sw=2 sts=2
# #
# agnoster's Theme - https://gist.github.com/3712874 # agnoster's Theme - https://gist.github.com/3712874
@ -220,7 +221,7 @@ prompt_virtualenv() {
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
prompt_context() { prompt_context() {
local user=$(whoami) local user="${USER:-${LOGNAME:?}}"
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
prompt_segment black default "$user@\h" prompt_segment black default "$user@\h"

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
# Atomic Bash Prompt for Bash-it # Atomic Bash Prompt for Bash-it
# By lfelipe base on the theme brainy of MunifTanjim # By lfelipe base on the theme brainy of MunifTanjim

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
SCM_THEME_PROMPT_DIRTY=" ${red}" SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}"

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
# Theme custom glyphs # Theme custom glyphs
SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '} SCM_GIT_CHAR_GITLAB=${BARBUK_GITLAB_CHAR:=' '}

View File

@ -1,4 +1,5 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
CLOCK_CHAR_THEME_PROMPT_PREFIX='' CLOCK_CHAR_THEME_PROMPT_PREFIX=''
CLOCK_CHAR_THEME_PROMPT_SUFFIX='' CLOCK_CHAR_THEME_PROMPT_SUFFIX=''
@ -85,42 +86,61 @@ RBENV_THEME_PROMPT_SUFFIX='|'
RBFU_THEME_PROMPT_PREFIX=' |' RBFU_THEME_PROMPT_PREFIX=' |'
RBFU_THEME_PROMPT_SUFFIX='|' RBFU_THEME_PROMPT_SUFFIX='|'
GIT_EXE=$(which git 2> /dev/null || true) : "${GIT_EXE:=$SCM_GIT}"
P4_EXE=$(which p4 2> /dev/null || true) : "${P4_EXE:=$SCM_P4}"
HG_EXE=$(which hg 2> /dev/null || true) : "${HG_EXE:=$SCM_HG}"
SVN_EXE=$(which svn 2> /dev/null || true) : "${SVN_EXE:=$SCM_SVN}"
# Check for broken SVN exe that is caused by some versions of Xcode. function _bash_it_appearance_scm_init() {
# See https://github.com/Bash-it/bash-it/issues/1612 for more details. GIT_EXE="$(type -P $SCM_GIT || true)"
if [[ -x "$SVN_EXE" ]]; then P4_EXE="$(type -P $SCM_P4 || true)"
if ! "$SVN_EXE" --version > /dev/null 2>&1; then HG_EXE="$(type -P $SCM_HG || true)"
# Unset the SVN exe variable so that SVN commands are avoided. SVN_EXE="$(type -P $SCM_SVN || true)"
SVN_EXE=""
# Check for broken SVN exe that is caused by some versions of Xcode.
# See https://github.com/Bash-it/bash-it/issues/1612 for more details.
if [[ -x "$SVN_EXE" && -x "${SVN_EXE%/*}/xcrun" ]]; then
if ! "$SVN_EXE" --version > /dev/null 2>&1; then
# Unset the SVN exe variable so that SVN commands are avoided.
SVN_EXE=""
fi
fi fi
fi }
_bash_it_appearance_scm_init
function scm { function scm {
if [[ "$SCM_CHECK" = false ]]; then if [[ "$SCM_CHECK" = false ]]; then
SCM=$SCM_NONE SCM=$SCM_NONE
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
SCM=$SCM_GIT SCM=$SCM_GIT
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
SCM=$SCM_GIT
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
SCM=$SCM_P4
elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then elif [[ -d .hg ]] && [[ -x "$HG_EXE" ]]; then
SCM=$SCM_HG SCM=$SCM_HG
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
SCM=$SCM_HG
elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then elif [[ -d .svn ]] && [[ -x "$SVN_EXE" ]]; then
SCM=$SCM_SVN SCM=$SCM_SVN
elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then
SCM=$SCM_GIT
elif [[ -x "$HG_EXE" ]] && [[ -n "$(hg root 2> /dev/null)" ]]; then
SCM=$SCM_HG
elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then elif [[ -x "$SVN_EXE" ]] && [[ -n "$(svn info --show-item wc-root 2> /dev/null)" ]]; then
SCM=$SCM_SVN SCM=$SCM_SVN
elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then
SCM=$SCM_P4
else else
SCM=$SCM_NONE SCM=$SCM_NONE
fi fi
} }
scm_prompt() {
local CHAR
CHAR="$(scm_char)"
local format=${SCM_PROMPT_FORMAT:-'[%s%s]'}
if [[ "${CHAR}" != "$SCM_NONE_CHAR" ]]; then
# shellcheck disable=2059
printf "$format\n" "$CHAR" "$(scm_prompt_info)"
fi
}
function scm_prompt_char { function scm_prompt_char {
if [[ -z $SCM ]]; then scm; fi if [[ -z $SCM ]]; then scm; fi
if [[ $SCM == "$SCM_GIT" ]]; then if [[ $SCM == "$SCM_GIT" ]]; then
@ -332,15 +352,15 @@ function svn_prompt_vars {
# - .hg is located in ~/Projects/Foo/.hg # - .hg is located in ~/Projects/Foo/.hg
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo # - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
function get_hg_root { function get_hg_root {
local CURRENT_DIR=$(pwd) local CURRENT_DIR="${PWD}"
while [ "$CURRENT_DIR" != "/" ]; do while [[ "${CURRENT_DIR:-/}" != "/" ]]; do
if [ -d "$CURRENT_DIR/.hg" ]; then if [[ -d "$CURRENT_DIR/.hg" ]]; then
echo "$CURRENT_DIR/.hg" echo "$CURRENT_DIR/.hg"
return return
fi fi
CURRENT_DIR=$(dirname "$CURRENT_DIR") CURRENT_DIR="${CURRENT_DIR%/*}"
done done
} }
@ -376,7 +396,7 @@ function hg_prompt_vars {
function nvm_version_prompt { function nvm_version_prompt {
local node local node
if declare -f -F nvm &> /dev/null; then if _is_function nvm; then
node=$(nvm current 2> /dev/null) node=$(nvm current 2> /dev/null)
[[ "${node}" == "system" ]] && return [[ "${node}" == "system" ]] && return
echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}" echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}"
@ -413,8 +433,8 @@ function rbfu_version_prompt {
} }
function chruby_version_prompt { function chruby_version_prompt {
if declare -f -F chruby &> /dev/null; then if _is_function chruby; then
if declare -f -F chruby_auto &> /dev/null; then if _is_function chruby_auto; then
chruby_auto chruby_auto
fi fi
@ -437,6 +457,10 @@ function k8s_context_prompt {
echo -e "$(kubectl config current-context 2> /dev/null)" echo -e "$(kubectl config current-context 2> /dev/null)"
} }
function k8s_namespace_prompt {
echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)"
}
function virtualenv_prompt { function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=$(basename "$VIRTUAL_ENV") virtualenv=$(basename "$VIRTUAL_ENV")
@ -528,7 +552,7 @@ function prompt_char {
function battery_char { function battery_char {
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
echo -e "${bold_red}$(battery_percentage)%" echo -e "${bold_red:-}$(battery_percentage)%"
fi fi
} }
@ -570,7 +594,7 @@ function __check_precmd_conflict() {
function safe_append_prompt_command { function safe_append_prompt_command {
local prompt_re local prompt_re
if [ "${__bp_imported}" == "defined" ]; then if [ "${__bp_imported:-missing}" == "defined" ]; then
# We are using bash-preexec # We are using bash-preexec
if ! __check_precmd_conflict "${1}"; then if ! __check_precmd_conflict "${1}"; then
precmd_functions+=("${1}") precmd_functions+=("${1}")
@ -585,7 +609,7 @@ function safe_append_prompt_command {
prompt_re="\<${1}\>" prompt_re="\<${1}\>"
fi fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then if [[ ${PROMPT_COMMAND[*]:-} =~ ${prompt_re} ]]; then
return return
elif [[ -z ${PROMPT_COMMAND} ]]; then elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}" PROMPT_COMMAND="${1}"

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
# Detect whether a reboot is required # Detect whether a reboot is required
function show_reboot_required() { function show_reboot_required() {
@ -31,15 +33,6 @@ function set_user_color() {
esac esac
} }
scm_prompt() {
CHAR=$(scm_char)
if [ "$CHAR" = "$SCM_NONE_CHAR" ]; then
return
else
echo "[$(scm_char)$(scm_prompt_info)]"
fi
}
# Define custom colors we need # Define custom colors we need
# non-printable bytes in PS1 need to be contained within \[ \]. # non-printable bytes in PS1 need to be contained within \[ \].
# Otherwise, bash will count them in the length of the prompt # Otherwise, bash will count them in the length of the prompt

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
SCM_THEME_PROMPT_PREFIX=" ${yellow}" SCM_THEME_PROMPT_PREFIX=" ${yellow}"
SCM_THEME_PROMPT_SUFFIX="${reset_color}" SCM_THEME_PROMPT_SUFFIX="${reset_color}"

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
SCM_THEME_PROMPT_DIRTY=" ${red}" SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}"

View File

@ -1,4 +1,6 @@
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
SCM_THEME_PROMPT_DIRTY=" ${red}" SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}" SCM_THEME_PROMPT_CLEAN=" ${bold_green}"

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