pull/1653/head
Pablo Palazon 2019-07-19 22:15:17 +02:00
commit c0760d196e
66 changed files with 4477 additions and 1454 deletions

View File

@ -1,7 +1,5 @@
# EditorConfig is awesome: http://EditorConfig.org
root = true
[*]
indent_style = space
indent_size = 2

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ bats
*.sublime-workspace
*.sublime-project
enabled/*
tmp/

View File

@ -19,9 +19,13 @@ Most of this is common sense, but please try to stick to the conventions listed
Create a _Pull Request_ from your feature branch against Bash-it's _master_ branch.
* Limit each Pull Request to one feature.
Don't bundle multiple features/changes (e.g. a new _Theme_ and a fix to an existing plugin) into a single Pull Request - create one PR for the theme, and a separate PR for the fix.
* For complex changes, try to _squash_ your changes into a single commit.
Don't create a PR consisting of 20 commits that show your work in progress.
Before you create the PR, _squash_ your changes into a single commit.
* For complex changes, try to _squash_ your changes into a single commit before
pushing code. Once you've pushed your code and opened a PR, please refrain
from force-pushing changes to the PR branch remember, Bash-it is a
distributed project and your branch may be in use already.
* When in doubt, open a PR with too many commits. Bash-it is a learning project
for everyone involved. Showing your work provides a great history for folks
to learn what works and what didn't.
## Code Style

View File

@ -0,0 +1,39 @@
cite 'about-alias'
about-alias 'common composer abbreviations'
# Aliases
alias coab='composer about'
alias coar='composer archive'
alias cob='composer browser'
alias cocpr='composer check-platform-reqs'
alias cocc='composer clear-cache'
alias cocfg='composer config'
alias cocp='composer create-project'
alias codp='composer depends'
alias codiag='composer diagnose'
alias codmp='composer dump-autoload'
alias coex='composer exec'
alias coglob='composer global'
alias coh='composer help'
alias cohome='composer home'
alias coi='composer install'
alias coinf='composer info'
alias coini='composer init'
alias coli='composer license'
alias colis='composer list'
alias coout='composer outdated'
alias cop='composer prohibits'
alias corem='composer remove'
alias coreq='composer require'
alias coreqd='composer require --dev'
alias cors='composer run-script'
alias cos='composer search'
alias cosu='composer self-update'
alias coshow='composer show'
alias costat='composer status'
alias cosugg='composer suggest'
alias coup='composer update'
alias coupg='composer upgrade'
alias coval='composer validate'
alias cowhy='composer why'
alias cowhyn='composer why-not'

View File

@ -1,6 +1,7 @@
cite 'about-alias'
about-alias 'docker abbreviations'
alias dk='docker'
alias dklc='docker ps -l' # List last Docker container
alias dklcid='docker ps -l -q' # List last Docker container ID
alias dklcip='docker inspect -f "{{.NetworkSettings.IPAddress}}" $(docker ps -l -q)' # Get IP of last Docker container
@ -8,7 +9,6 @@ alias dkps='docker ps' # List running Docker containers
alias dkpsa='docker ps -a' # List all Docker containers
alias dki='docker images' # List Docker images
alias dkrmac='docker rm $(docker ps -a -q)' # Delete all Docker containers
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
case $OSTYPE in
darwin*|*bsd*|*BSD*)
@ -19,13 +19,21 @@ case $OSTYPE in
;;
esac
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image
alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments
alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz
alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID
alias dkelc='docker exec -it `dklcid` bash' # Enter last container (works with Docker 1.3 and above)
if [ ! -z "$(command ls "${BASH_IT}/enabled/"{[0-9][0-9][0-9]${BASH_IT_LOAD_PRIORITY_SEPARATOR}docker,docker}.plugin.bash 2>/dev/null | head -1)" ]; then
# Function aliases from docker plugin:
alias dkrmlc='docker-remove-most-recent-container' # Delete most recent (i.e., last) Docker container
alias dkrmall='docker-remove-stale-assets' # Delete all untagged images and exited containers
alias dkrmli='docker-remove-most-recent-image' # Delete most recent (i.e., last) Docker image
alias dkrmi='docker-remove-images' # Delete images for supplied IDs or all if no IDs are passed as arguments
alias dkideps='docker-image-dependencies' # Output a graph of image dependencies using Graphiz
alias dkre='docker-runtime-environment' # List environmental variables of the supplied image ID
fi
alias dkelc='docker exec -it $(dklcid) bash --login' # Enter last container (works with Docker 1.3 and above)
alias dkrmflast='docker rm -f $(dklcid)'
alias dkbash='dkelc'
alias dkex='docker exec -it ' # Useful to run any commands into container without leaving host
alias dkri='docker run --rm -i '
alias dkrit='docker run --rm -it '
# Added more recent cleanup options from newer docker versions
alias dkip='docker image prune -a -f'

View File

@ -99,8 +99,9 @@ alias bshenc="bash-it enable completion"
# Shorten extract
alias xt="extract"
# sudo vim
# sudo editors
alias svim="sudo vim"
alias snano="sudo nano"
# Display whatever file is regular file or folder
catt() {

View File

@ -18,7 +18,6 @@ alias gm="git merge"
alias gmv='git mv'
alias g='git'
alias get='git'
alias gst='git status'
alias gs='git status'
alias gss='git status -s'
alias gsu='git submodule update --init --recursive'
@ -31,11 +30,13 @@ alias gp='git push'
alias gpo='git push origin'
alias gpu='git push --set-upstream'
alias gpuo='git push --set-upstream origin'
alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)'
alias gpom='git push origin master'
alias gr='git remote'
alias grv='git remote -v'
alias gra='git remote add'
alias gd='git diff'
alias gds='git diff --staged'
alias gdv='git diff -w "$@" | vim -R -'
alias gc='git commit -v'
alias gca='git commit -v -a'
@ -50,11 +51,13 @@ alias gbd='git branch -d'
alias gbD='git branch -D'
alias gcount='git shortlog -sn'
alias gcp='git cherry-pick'
alias gcpx='git cherry-pick -x'
alias gco='git checkout'
alias gcom='git checkout master'
alias gcb='git checkout -b'
alias gcob='git checkout -b'
alias gct='git checkout --track'
alias gcpd='git checkout master; git pull; git branch -D'
alias gexport='git archive --format zip --output'
alias gdel='git branch -D'
alias gmu='git fetch origin -v; git fetch upstream -v; git merge upstream/master'
@ -67,6 +70,7 @@ alias gt="git tag"
alias gta="git tag -a"
alias gtd="git tag -d"
alias gtl="git tag -l"
alias gpatch="git format-patch -1"
# From http://blogs.atlassian.com/2014/10/advanced-git-aliases/
# Show commits since last pull
alias gnew="git log HEAD@{1}..HEAD@{0}"
@ -74,9 +78,14 @@ alias gnew="git log HEAD@{1}..HEAD@{0}"
alias gcaa="git commit -a --amend -C HEAD"
alias ggui="git gui"
alias gcsam="git commit -S -am"
alias gst="git stash"
alias gstb="git stash branch"
alias gstd="git stash drop"
alias gstl="git stash list"
alias gstp="git stash pop"
alias gh='cd "$(git rev-parse --show-toplevel)"'
# Show untracked files
alias gu='git ls-files . --exclude-standard --others'
case $OSTYPE in
darwin*)

View File

@ -4,7 +4,6 @@ cite 'about-alias'
about-alias 'homebrew abbreviations'
alias bup='brew update && brew upgrade'
alias bupc='brew update && brew upgrade --cleanup'
alias bout='brew outdated'
alias bin='brew install'
alias brm='brew uninstall'

View File

@ -0,0 +1,15 @@
#!/bin/bash
cite 'about-alias'
about-alias 'MSYS2 aliases'
LS_COMMON="-hG"
LS_COMMON="$LS_COMMON --color=auto"
LS_COMMON="$LS_COMMON -I NTUSER.DAT\* -I ntuser.dat\*"
# alias
# setup the main ls alias if we've established common args
test -n "$LS_COMMON" && alias ls="command ls $LS_COMMON"
alias ll="ls -l"
alias la="ls -a"
alias lal="ll -a"

View File

@ -0,0 +1,9 @@
cite 'about-alias'
about-alias 'the Node.js environment aliases'
# alias to setup nodejs development environment
alias node-dev='export NODE_ENV=development'
# alias to setup nodejs production environment
alias node-prod='export NODE_ENV=production'

View File

@ -3,7 +3,7 @@ about-alias 'phoenix abbreviations'
# Phoenix Commands
alias i='iex'
alias ips='iex -S mix phoenix.server'
alias ips='iex -S mix phx.server'
alias ism='iex -S mix'
alias m='mix'
alias mab='mix archive.build'
@ -32,14 +32,14 @@ alias mho='mix hex.outdated'
alias mlh='mix local.hex'
alias mn='mix new'
alias mns='mix new --sup'
alias mpgc='mix phoenix.gen.channel'
alias mpgh='mix phoenix.gen.html'
alias mpgj='mix phoenix.gen.json'
alias mpgm='mix phoenix.gen.model'
alias mpgs='mix phoenix.gen.secret'
alias mpn='mix phoenix.new'
alias mpr='mix phoenix.routes'
alias mps='mix phoenix.server'
alias mpgc='mix phx.gen.channel'
alias mpgh='mix phx.gen.html'
alias mpgj='mix phx.gen.json'
alias mpgm='mix phx.gen.model'
alias mpgs='mix phx.gen.secret'
alias mpn='mix phx.new'
alias mpr='mix phx.routes'
alias mps='mix phx.server'
alias mr='mix run'
alias mrnh='mix run --no-halt'
alias mrl='mix release'

View File

@ -29,21 +29,24 @@ cite _about _param _example _group _author _version
# libraries, but skip appearance (themes) for now
LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for config_file in $LIB
for _bash_it_config_file in $LIB
do
if [ "$config_file" != "$APPEARANCE_LIB" ]; then
if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
# shellcheck disable=SC1090
source "$config_file"
source "$_bash_it_config_file"
fi
done
# Load the global "enabled" directory
_load_global_bash_it_files
# "family" param is empty so that files get sources in glob order
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash"
# Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion"
do
_load_bash_it_files $file_type
# shellcheck source=./scripts/reloader.bash
source "${BASH_IT}/scripts/reloader.bash" "skip" "$file_type"
done
# Load theme, if a theme was set
@ -75,15 +78,15 @@ done
# Custom
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for config_file in $CUSTOM
for _bash_it_config_file in $CUSTOM
do
if [ -e "${config_file}" ]; then
if [ -e "${_bash_it_config_file}" ]; then
# shellcheck disable=SC1090
source "$config_file"
source "$_bash_it_config_file"
fi
done
unset config_file
unset _bash_it_config_file
if [[ $PROMPT ]]; then
export PS1="\[""$PROMPT""\]"
fi

View File

@ -0,0 +1,10 @@
# bash completion support for Hashicorp consul
CONSUL_BIN=$(command -v consul 2>/dev/null)
if [[ -x "$CONSUL_BIN" ]]
then
complete -C "$CONSUL_BIN" consul
fi
unset CONSUL_BIN

View File

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

View File

@ -16,6 +16,8 @@
# below to your .bashrc after bash completion features are loaded
# . ~/.docker-compose-completion.sh
__docker_compose_previous_extglob_setting=$(shopt -p extglob)
shopt -s extglob
__docker_compose_q() {
docker-compose 2>/dev/null "${top_level_options[@]}" "$@"
@ -48,64 +50,56 @@ __docker_compose_has_option() {
return 1
}
# Returns `key` if we are currently completing the value of a map option (`key=value`)
# which matches the extglob passed in as an argument.
# This function is needed for key-specific completions.
__docker_compose_map_key_of_current_option() {
local glob="$1"
local key glob_pos
if [ "$cur" = "=" ] ; then # key= case
key="$prev"
glob_pos=$((cword - 2))
elif [[ $cur == *=* ]] ; then # key=value case (OSX)
key=${cur%=*}
glob_pos=$((cword - 1))
elif [ "$prev" = "=" ] ; then
key=${words[$cword - 2]} # key=value case
glob_pos=$((cword - 3))
else
return
fi
[ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax
[[ ${words[$glob_pos]} == @($glob) ]] && echo "$key"
}
# suppress trailing whitespace
__docker_compose_nospace() {
# compopt is not available in ancient bash versions
type compopt &>/dev/null && compopt -o nospace
}
# Extracts all service names from the compose file.
___docker_compose_all_services_in_compose_file() {
__docker_compose_q config --services
# Outputs a list of all defined services, regardless of their running state.
# Arguments for `docker-compose ps` may be passed in order to filter the service list,
# e.g. `status=running`.
__docker_compose_services() {
__docker_compose_q ps --services "$@"
}
# All services, even those without an existing container
__docker_compose_services_all() {
COMPREPLY=( $(compgen -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
}
# All services that have an entry with the given key in their compose_file section
___docker_compose_services_with_key() {
# flatten sections under "services" to one line, then filter lines containing the key and return section name
__docker_compose_q config \
| sed -n -e '/^services:/,/^[^ ]/p' \
| sed -n 's/^ //p' \
| awk '/^[a-zA-Z0-9]/{printf "\n"};{printf $0;next;}' \
| awk -F: -v key=": +$1:" '$0 ~ key {print $1}'
}
# All services that are defined by a Dockerfile reference
__docker_compose_services_from_build() {
COMPREPLY=( $(compgen -W "$(___docker_compose_services_with_key build)" -- "$cur") )
}
# All services that are defined by an image
__docker_compose_services_from_image() {
COMPREPLY=( $(compgen -W "$(___docker_compose_services_with_key image)" -- "$cur") )
}
# The services for which containers have been created, optionally filtered
# by a boolean expression passed in as argument.
__docker_compose_services_with() {
local containers names
containers="$(__docker_compose_q ps -q)"
names=$(docker 2>/dev/null inspect -f "{{if ${1:-true}}}{{range \$k, \$v := .Config.Labels}}{{if eq \$k \"com.docker.compose.service\"}}{{\$v}}{{end}}{{end}}{{end}}" $containers)
COMPREPLY=( $(compgen -W "$names" -- "$cur") )
}
# The services for which at least one paused container exists
__docker_compose_services_paused() {
__docker_compose_services_with '.State.Paused'
# Applies completion of services based on the current value of `$cur`.
# Arguments for `docker-compose ps` may be passed in order to filter the service list,
# see `__docker_compose_services`.
__docker_compose_complete_services() {
COMPREPLY=( $(compgen -W "$(__docker_compose_services "$@")" -- "$cur") )
}
# The services for which at least one running container exists
__docker_compose_services_running() {
__docker_compose_services_with '.State.Running'
}
# The services for which at least one stopped container exists
__docker_compose_services_stopped() {
__docker_compose_services_with 'not .State.Running'
__docker_compose_complete_running_services() {
local names=$(__docker_compose_services --filter status=running)
COMPREPLY=( $(compgen -W "$names" -- "$cur") )
}
@ -116,14 +110,17 @@ _docker_compose_build() {
__docker_compose_nospace
return
;;
--memory|-m)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--build-arg --force-rm --help --memory --no-cache --pull" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--build-arg --compress --force-rm --help --memory -m --no-cache --no-rm --pull --parallel -q --quiet" -- "$cur" ) )
;;
*)
__docker_compose_services_from_build
__docker_compose_complete_services --filter source=build
;;
esac
}
@ -142,7 +139,18 @@ _docker_compose_bundle() {
_docker_compose_config() {
COMPREPLY=( $( compgen -W "--help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
case "$prev" in
--hash)
if [[ $cur == \\* ]] ; then
COMPREPLY=( '\*' )
else
COMPREPLY=( $(compgen -W "$(__docker_compose_services) \\\* " -- "$cur") )
fi
return
;;
esac
COMPREPLY=( $( compgen -W "--hash --help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) )
}
@ -152,7 +160,7 @@ _docker_compose_create() {
COMPREPLY=( $( compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -168,18 +176,22 @@ _docker_compose_docker_compose() {
_filedir "y?(a)ml"
return
;;
--log-level)
COMPREPLY=( $( compgen -W "debug info warning error critical" -- "$cur" ) )
return
;;
--project-directory)
_filedir -d
return
;;
$(__docker_compose_to_extglob "$top_level_options_with_args") )
$(__docker_compose_to_extglob "$daemon_options_with_args") )
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "$top_level_boolean_options $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) )
COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) )
;;
*)
COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) )
@ -194,11 +206,14 @@ _docker_compose_down() {
COMPREPLY=( $( compgen -W "all local" -- "$cur" ) )
return
;;
--timeout|-t)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --rmi --volumes -v --remove-orphans" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--help --rmi --timeout -t --volumes -v --remove-orphans" -- "$cur" ) )
;;
esac
}
@ -216,7 +231,7 @@ _docker_compose_events() {
COMPREPLY=( $( compgen -W "--help --json" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -224,17 +239,17 @@ _docker_compose_events() {
_docker_compose_exec() {
case "$prev" in
--index|--user|-u)
--index|--user|-u|--workdir|-w)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --help --index --privileged -T --user -u" -- "$cur" ) )
COMPREPLY=( $( compgen -W "-d --detach --help --index --privileged -T --user -u --workdir -w" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -247,10 +262,10 @@ _docker_compose_help() {
_docker_compose_images() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help -q" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -268,7 +283,7 @@ _docker_compose_kill() {
COMPREPLY=( $( compgen -W "--help -s" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -286,7 +301,7 @@ _docker_compose_logs() {
COMPREPLY=( $( compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -298,7 +313,7 @@ _docker_compose_pause() {
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -320,19 +335,39 @@ _docker_compose_port() {
COMPREPLY=( $( compgen -W "--help --index --protocol" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
_docker_compose_ps() {
local key=$(__docker_compose_map_key_of_current_option '--filter')
case "$key" in
source)
COMPREPLY=( $( compgen -W "build image" -- "${cur##*=}" ) )
return
;;
status)
COMPREPLY=( $( compgen -W "paused restarting running stopped" -- "${cur##*=}" ) )
return
;;
esac
case "$prev" in
--filter)
COMPREPLY=( $( compgen -W "source status" -S "=" -- "$cur" ) )
__docker_compose_nospace
return;
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help -q" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--all -a --filter --help --quiet -q --services" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -341,10 +376,10 @@ _docker_compose_ps() {
_docker_compose_pull() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --parallel --quiet" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --include-deps --no-parallel --quiet -q" -- "$cur" ) )
;;
*)
__docker_compose_services_from_image
__docker_compose_complete_services --filter source=image
;;
esac
}
@ -356,7 +391,7 @@ _docker_compose_push() {
COMPREPLY=( $( compgen -W "--help --ignore-push-failures" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -374,7 +409,7 @@ _docker_compose_restart() {
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -387,9 +422,9 @@ _docker_compose_rm() {
;;
*)
if __docker_compose_has_option "--stop|-s" ; then
__docker_compose_services_all
__docker_compose_complete_services
else
__docker_compose_services_stopped
__docker_compose_complete_services --filter status=stopped
fi
;;
esac
@ -410,10 +445,10 @@ _docker_compose_run() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --user -u --volume -v --workdir -w" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--detach -d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --use-aliases --user -u --volume -v --workdir -w" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -435,7 +470,7 @@ _docker_compose_scale() {
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
COMPREPLY=( $(compgen -S "=" -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") )
__docker_compose_nospace
;;
esac
@ -448,7 +483,7 @@ _docker_compose_start() {
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_stopped
__docker_compose_complete_services --filter status=stopped
;;
esac
}
@ -466,7 +501,7 @@ _docker_compose_stop() {
COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -478,7 +513,7 @@ _docker_compose_top() {
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_running
__docker_compose_complete_running_services
;;
esac
}
@ -490,7 +525,7 @@ _docker_compose_unpause() {
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_compose_services_paused
__docker_compose_complete_services --filter status=paused
;;
esac
}
@ -503,11 +538,11 @@ _docker_compose_up() {
return
;;
--exit-code-from)
__docker_compose_services_all
__docker_compose_complete_services
return
;;
--scale)
COMPREPLY=( $(compgen -S "=" -W "$(___docker_compose_all_services_in_compose_file)" -- "$cur") )
COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") )
__docker_compose_nospace
return
;;
@ -518,10 +553,10 @@ _docker_compose_up() {
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "--abort-on-container-exit --build -d --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --remove-orphans --scale --timeout -t" -- "$cur" ) )
COMPREPLY=( $( compgen -W "--abort-on-container-exit --always-recreate-deps --build -d --detach --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --renew-anon-volumes -V --remove-orphans --scale --timeout -t" -- "$cur" ) )
;;
*)
__docker_compose_services_all
__docker_compose_complete_services
;;
esac
}
@ -571,14 +606,12 @@ _docker_compose() {
# Options for the docker daemon that have to be passed to secondary calls to
# docker-compose executed by this script.
# Other global otions that are not relevant for secondary calls are defined in
# `_docker_compose_docker_compose`.
local top_level_boolean_options="
local daemon_boolean_options="
--skip-hostname-check
--tls
--tlsverify
"
local top_level_options_with_args="
local daemon_options_with_args="
--file -f
--host -H
--project-directory
@ -588,6 +621,11 @@ _docker_compose() {
--tlskey
"
# These options are require special treatment when searching the command.
local top_level_options_with_args="
--log-level
"
COMPREPLY=()
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
@ -600,15 +638,18 @@ _docker_compose() {
while [ $counter -lt $cword ]; do
case "${words[$counter]}" in
$(__docker_compose_to_extglob "$top_level_boolean_options") )
$(__docker_compose_to_extglob "$daemon_boolean_options") )
local opt=${words[counter]}
top_level_options+=($opt)
;;
$(__docker_compose_to_extglob "$top_level_options_with_args") )
$(__docker_compose_to_extglob "$daemon_options_with_args") )
local opt=${words[counter]}
local arg=${words[++counter]}
top_level_options+=($opt $arg)
;;
$(__docker_compose_to_extglob "$top_level_options_with_args") )
(( counter++ ))
;;
-*)
;;
*)
@ -626,4 +667,7 @@ _docker_compose() {
return 0
}
complete -F _docker_compose docker-compose docker-compose.exe
eval "$__docker_compose_previous_extglob_setting"
unset __docker_compose_previous_extglob_setting
complete -F _docker_compose docker-compose docker-compose.exe

View File

@ -86,6 +86,40 @@ _docker_machine_map_key_of_current_option() {
[[ ${words[$glob_pos]} == $glob ]] && echo "$key"
}
# Finds the position of the first word that is neither option nor an option's argument.
# If there are options that require arguments, you need to pass a glob describing
# those options, e.g. "--option1|-o|--option2".
# Use this function to restrict completions to exact positions after the options.
_docker_machine_pos_first_nonflag() {
local argument_flags=$1
local counter=$((${subcommand_pos:-${command_pos}} + 1))
while [ "$counter" -le "$cword" ]; do
if [ -n "$argument_flags" ] && eval "case '${words[$counter]}' in $argument_flags) true ;; *) false ;; esac"; then
(( counter++ ))
# eat "=" in case of --option=arg syntax
[ "${words[$counter]}" = "=" ] && (( counter++ ))
else
case "${words[$counter]}" in
-*)
;;
*)
break
;;
esac
fi
# Bash splits words at "=", retaining "=" as a word, examples:
# "--debug=false" => 3 words, "--log-opt syslog-facility=daemon" => 4 words
while [ "${words[$counter + 1]}" = "=" ] ; do
counter=$(( counter + 2))
done
(( counter++ ))
done
echo $counter
}
# --- completion functions ---------------------------------------------------
_docker_machine_active() {
@ -128,7 +162,7 @@ _docker_machine_create() {
_docker_machine_env() {
case "${prev}" in
--shell)
COMPREPLY=($(compgen -W "cmd fish powershell tcsh" -- "${cur}"))
COMPREPLY=($(compgen -W "cmd emacs fish powershell tcsh" -- "${cur}"))
return
;;
esac
@ -208,6 +242,21 @@ _docker_machine_ls() {
fi
}
_docker_machine_mount() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help --unmount -u" -- "${cur}"))
else
local pos=$(_docker_machine_pos_first_nonflag)
if [ "$cword" -eq "$pos" ]; then
# We can't complete remote filesystems. All we can do here is to complete the machine.
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -S: -- "${cur}"))
_docker_machine_nospace
elif [ "$cword" -eq "$((pos + 1))" ]; then
_filedir -d
fi
fi
}
_docker_machine_provision() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--help" -- "${cur}"))
@ -218,7 +267,7 @@ _docker_machine_provision() {
_docker_machine_regenerate_certs() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--force -f --help" -- "${cur}"))
COMPREPLY=($(compgen -W "--client-certs --force -f --help" -- "${cur}"))
else
COMPREPLY=($(compgen -W "$(_docker_machine_machines --filter state=Running)" -- "${cur}"))
fi
@ -250,7 +299,7 @@ _docker_machine_ssh() {
_docker_machine_scp() {
if [[ "${cur}" == -* ]]; then
COMPREPLY=($(compgen -W "--delta -d --help --recursive -r" -- "${cur}"))
COMPREPLY=($(compgen -W "--delta -d --help --quiet -q --recursive -r" -- "${cur}"))
else
_filedir
# It would be really nice to ssh to the machine and ls to complete
@ -329,7 +378,7 @@ _docker_machine_docker_machine() {
_docker_machine() {
COMPREPLY=()
local commands=(active config create env inspect ip kill ls provision regenerate-certs restart rm ssh scp start status stop upgrade url version help)
local commands=(active config create env inspect ip kill ls mount provision regenerate-certs restart rm ssh scp start status stop upgrade url version help)
local flags=(--debug --native-ssh --github-api-token --bugsnag-api-token --help --version)
local wants_dir=(--storage-path)
@ -343,7 +392,7 @@ _docker_machine() {
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
local i
local command=docker-machine
local command=docker-machine command_pos=0
for (( i=1; i < ${cword}; ++i)); do
local word=${words[i]}
@ -352,6 +401,7 @@ _docker_machine() {
(( ++i ))
elif [[ " ${commands[*]} " =~ " ${word} " ]]; then
command=${word}
command_pos=$i
fi
done
@ -363,4 +413,4 @@ _docker_machine() {
return 0
}
complete -F _docker_machine docker-machine docker-machine.exe
complete -F _docker_machine docker-machine docker-machine.exe

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
#!/usr/bin/bash
if _command_exists flutter; then
eval "$(flutter bash-completion)"
fi

View File

@ -0,0 +1,9 @@
#/usr/bin/env bash
# Bash completion for Google Cloud SDK
if which gcloud >/dev/null 2>&1; then
GOOGLE_SDK_ROOT=${GOOGLE_SDK_ROOT:-$(gcloud info --format="value(installation.sdk_root)")}
for i in $(ls ${GOOGLE_SDK_ROOT}/*.bash.inc); do
source $i
done
fi

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
# helm (Kubernetes Package Manager) completion
if command -v helm &>/dev/null
then
eval "$(helm completion bash)"
fi

View File

@ -0,0 +1,207 @@
#!/usr/bin/env bash
##############
### CONFIG ###
##############
### feel free to change those constants
# the dir where to store the cache (must be writable and readable by the current user)
# must be an absolute path
_KNIFE_AUTOCOMPLETE_CACHE_DIR="$HOME/.knife_autocomplete_cache"
# the maximum # of _seconds_ after which a cache will be considered stale
# (a cache is refreshed whenever it is used! this is only for caches that might not have been used for a long time)
# WARNING: keep that value > 100
_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE=86400
###############################################
### END OF CONFIG - DON'T CHANGE CODE BELOW ###
###############################################
### init
_KAC_CACHE_TMP_DIR="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/tmp"
# make sure the cache dir exists
mkdir -p $_KAC_CACHE_TMP_DIR
##############################
### Cache helper functions ###
##############################
# GNU or BSD stat?
stat -c %Y /dev/null > /dev/null 2>&1 && _KAC_STAT_COMMAND="stat -c %Y" || _KAC_STAT_COMMAND="stat -f %m"
# returns 0 iff the file whose path is given as 1st argument
# exists and has last been modified in the last $2 seconds
# returns 1 otherwise
_KAC_is_file_newer_than()
{
[ -f "$1" ] || return 1
[ $(( $(date +%s) - $($_KAC_STAT_COMMAND "$1") )) -gt $2 ] && return 1 || return 0
}
# helper function for _KAC_get_and_regen_cache, see doc below
_KAC_regen_cache()
{
local CACHE_NAME=$1
local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
local TMP_FILE=$(mktemp "$_KAC_CACHE_TMP_DIR/$CACHE_NAME.XXXX")
shift 1
"$@" > $TMP_FILE 2> /dev/null
# discard the temp file if it's empty AND the previous command didn't exit successfully, but still mark the cache as updated
[[ $? != 0 ]] && [[ $(cat $TMP_FILE | wc -l) == 0 ]] && rm -f $TMP_FILE && touch $CACHE_PATH && return 1 \
|| mv -f $TMP_FILE $CACHE_PATH
}
# cached files can't have spaces in their names
_KAC_get_cache_name_from_command()
{
echo "$@" | sed 's/ /_SPACE_/g'
}
# the reverse operation from the function above
_KAC_get_command_from_cache_name()
{
echo "$@" | sed 's/_SPACE_/ /g'
}
# given a command as argument, it fetches the cache for that command if it can find it
# otherwise it waits for the cache to be generated
# 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)
_KAC_get_and_regen_cache()
{
# the cache name can't have space in it
local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@")
local REGEN_CMD="_KAC_regen_cache $CACHE_NAME $@"
_KAC_CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
# no need to wait for the regen if the file already exists
[ -f $_KAC_CACHE_PATH ] && ($REGEN_CMD &) || $REGEN_CMD
}
# performs two things: first, deletes all obsolete temp files
# then refreshes stale caches that haven't been called in a long time
_KAC_clean_cache()
{
local FILE CMD
# delete all obsolete temp files, could be lingering there for any kind of crash in the caching process
for FILE in $(ls $_KAC_CACHE_TMP_DIR)
do
_KAC_is_file_newer_than $FILE $_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE || rm -f $FILE
done
# refresh really stale caches
for FILE in $(find $_KNIFE_AUTOCOMPLETE_CACHE_DIR -maxdepth 1 -type f -not -name '.*')
do
_KAC_is_file_newer_than $FILE $_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE && continue
# first let's get the original command
CMD=$(_KAC_get_command_from_cache_name $(basename "$FILE"))
# then regen the cache
_KAC_get_and_regen_cache "$CMD" > /dev/null
done
}
# perform a cache cleaning when loading this file
_KAC_clean_cache
#####################################
### End of cache helper functions ###
#####################################
# returns all the possible knife sub-commands
_KAC_knife_commands()
{
knife --help | grep -E "^knife" | sed -E 's/ \(options\)//g'
}
# rebuilds the knife base command currently being completed, and assigns it to $_KAC_CURRENT_COMMAND
# additionnally, returns 1 iff the current base command is not complete, 0 otherwise
# also sets $_KAC_CURRENT_COMMAND_NB_WORDS if the base command is complete
_KAC_get_current_base_command()
{
local PREVIOUS="knife"
local I=1
local CURRENT
while [ $I -le $COMP_CWORD ]
do
# command words are all lower-case
echo ${COMP_WORDS[$I]} | grep -E "^[a-z]+$" > /dev/null || break
CURRENT="$PREVIOUS ${COMP_WORDS[$I]}"
cat $_KAC_CACHE_PATH | grep -E "^$CURRENT" > /dev/null || break
PREVIOUS=$CURRENT
I=$(( $I + 1))
done
_KAC_CURRENT_COMMAND=$PREVIOUS
[ $I -le $COMP_CWORD ] && _KAC_CURRENT_COMMAND_NB_WORDS=$I
}
# 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...)
# assumes the current base command is complete
_KAC_get_current_arg_position()
{
local CURRENT_ARG_POS=$(( $_KAC_CURRENT_COMMAND_NB_WORDS + 1 ))
local COMPLETE_COMMAND=$(cat $_KAC_CACHE_PATH | grep -E "^$_KAC_CURRENT_COMMAND")
local CURRENT_ARG
while [ $CURRENT_ARG_POS -le $COMP_CWORD ]
do
CURRENT_ARG=$(echo $COMPLETE_COMMAND | cut -d ' ' -f $CURRENT_ARG_POS)
# we break if the current arg is a "plural" arg
echo $CURRENT_ARG | grep -E "^\\[[^]]+(\\.\\.\\.\\]|$)" > /dev/null && break
CURRENT_ARG_POS=$(( $CURRENT_ARG_POS + 1 ))
done
echo $CURRENT_ARG_POS
}
# the actual auto-complete function
_knife()
{
_KAC_get_and_regen_cache _KAC_knife_commands
local RAW_LIST ITEM REGEN_CMD ARG_POSITION
COMREPLY=()
# get correct command & arg pos
_KAC_get_current_base_command && ARG_POSITION=$(_KAC_get_current_arg_position) || ARG_POSITION=$(( $COMP_CWORD + 1 ))
RAW_LIST=$(cat $_KAC_CACHE_PATH | grep -E "^$_KAC_CURRENT_COMMAND" | cut -d ' ' -f $ARG_POSITION | uniq)
# 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)
# as opposed to a generic approach by trying to find a 'list' knife command corresponding to the
# current base command - that might limit my script in some situation, but that way I'm sure it caches only
# not-sensitive stuff (a generic approach could be pretty bad e.g. with the knife-rackspace plugin)
LIST=""
for ITEM in $RAW_LIST
do
# always relevant if only lower-case chars : continuation of the base command
echo $ITEM | grep -E "^[a-z]+$" > /dev/null && LIST="$LIST $ITEM" && continue
case $ITEM in
*COOKBOOK*)
# special case for cookbooks : from site or local
[[ ${COMP_WORDS[2]} == 'site' ]] && REGEN_CMD="knife cookbook site list" || REGEN_CMD="knife cookbook list"
_KAC_get_and_regen_cache $REGEN_CMD
LIST="$LIST $(cat $_KAC_CACHE_PATH | cut -d ' ' -f 1)"
continue
;;
*ITEM*)
# data bag item : another special case
local DATA_BAG_NAME=${COMP_WORDS[$(( COMP_CWORD-1 ))]}
REGEN_CMD="knife data bag show $DATA_BAG_NAME"
;;
*INDEX*)
# see doc @ http://docs.opscode.com/knife_search.html
LIST="$LIST client environment node role"
REGEN_CMD="knife data bag list"
;;
*BAG*) REGEN_CMD="knife data bag list";;
*CLIENT*) REGEN_CMD="knife client list";;
*NODE*) REGEN_CMD="knife node list";;
*ENVIRONMENT*) REGEN_CMD="knife environment list";;
*ROLE*) REGEN_CMD="knife role list";;
*USER*) REGEN_CMD="knife user list";;
# not a generic argument we support...
*) continue;;
esac
_KAC_get_and_regen_cache $REGEN_CMD
LIST="$LIST $(cat $_KAC_CACHE_PATH)"
done
COMPREPLY=( $(compgen -W "${LIST}" -- ${COMP_WORDS[COMP_CWORD]}))
}
#complete -f -F _knife knife
complete -F _knife knife

View File

@ -0,0 +1,167 @@
#!/bin/bash
# ---------------------------------------------------------------------------+
# |
# Thanks to Alexander Korznikov |
# http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html |
# |
# ---------------------------------------------------------------------------+
if command -v sqlmap > /dev/null; then
_sqlmap()
{
local cur prev
COMPREPLY=()
cur=$(_get_cword)
prev=$(_get_pword)
case $prev in
# List directory content
--tamper)
COMPREPLY=( $( compgen -W "$tamper" -- "$cur" ) )
return 0
;;
--output-dir|-t|-l|-m|-r|--load-cookies|--proxy-file|--sql-file|--shared-lib|--file-write)
_filedir
return 0
;;
-c)
_filedir ini
return 0
;;
--method)
COMPREPLY=( $( compgen -W 'GET POST PUT' -- "$cur" ) )
return 0
;;
--auth-type)
COMPREPLY=( $( compgen -W 'Basic Digest NTLM PKI' -- "$cur" ) )
return 0
;;
--tor-type)
COMPREPLY=( $( compgen -W 'HTTP SOCKS4 SOCKS5' -- "$cur" ) )
return 0
;;
-v)
COMPREPLY=( $( compgen -W '1 2 3 4 5 6' -- "$cur" ) )
return 0
;;
--dbms)
COMPREPLY=( $( compgen -W 'mysql mssql access postgres' -- "$cur" ) )
return 0
;;
--level|--crawl)
COMPREPLY=( $( compgen -W '1 2 3 4 5' -- "$cur" ) )
return 0
;;
--risk)
COMPREPLY=( $( compgen -W '0 1 2 3' -- "$cur" ) )
return 0
;;
--technique)
COMPREPLY=( $( compgen -W 'B E U S T Q' -- "$cur" ) )
return 0
;;
-s)
_filedir sqlite
return 0
;;
--dump-format)
COMPREPLY=( $( compgen -W 'CSV HTML SQLITE' -- "$cur" ) )
return 0
;;
-x)
_filedir xml
return 0
;;
esac
if [[ "$cur" == * ]]; then
COMPREPLY=( $( compgen -W '-h --help -hh --version -v -d -u --url -l -x -m -r -g -c --method \
--data --param-del --cookie --cookie-del --load-cookies \
--drop-set-cookie --user-agent --random-agent --host --referer \
--headers --auth-type --auth-cred --auth-private --ignore-401 \
--proxy --proxy-cred --proxy-file --ignore-proxy --tor --tor-port \
--tor-type --check-tor --delay --timeout --retries --randomize \
--safe-url --safe-freq --skip-urlencode --csrf-token --csrf-url \
--force-ssl --hpp --eval -o --predict-output --keep-alive \
--null-connection --threads -p --skip --dbms --dbms-cred \
--os --invalid-bignum --invalid-logical --invalid-string \
--no-cast --no-escape --prefix --suffix --tamper --level \
--risk --string --not-string --regexp --code --text-only \
--titles --technique --time-sec --union-cols --union-char \
--union-from --dns-domain --second-order -f --fingerprint \
-a --all -b --banner --current-user --current-db --hostname \
--is-dba --users --passwords --privileges --roles --dbs --tables \
--columns --schema --count --dump --dump-all --search --comments \
-D -T -C -X -U --exclude-sysdbs --where --start --stop \
--first --last --sql-query --sql-shell --sql-file --common-tables \
--common-columns --udf-inject --shared-lib --file-read --file-write \
--file-dest --os-cmd --os-shell --os-pwn --os-smbrelay --os-bof \
--priv-esc --msf-path --tmp-path --reg-read --reg-add --reg-del \
--reg-key --reg-value --reg-data --reg-type -s -t --batch \
--charset --crawl --csv-del --dump-format --eta --flush-session \
--forms --fresh-queries --hex --output-dir --parse-errors \
--pivot-column --save --scope --test-filter --update \
-z --alert --answers --beep --check-waf --cleanup \
--dependencies --disable-coloring --gpage --identify-waf \
--mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard' -- "$cur" ) )
# this removes any options from the list of completions that have
# already been specified somewhere on the command line, as long as
# these options can only be used once (in a word, "options", in
# opposition to "tests" and "actions", as in the find(1) manpage).
onlyonce=' -h --help -hh --version -v -d -u --url -l -x -m -r -g -c \
--drop-set-cookie --random-agent \
--ignore-401 \
--ignore-proxy --tor \
--check-tor \
--skip-urlencode \
--force-ssl --hpp -o --predict-output --keep-alive \
--null-connection -p \
--invalid-bignum --invalid-logical --invalid-string \
--no-cast --no-escape \
--text-only \
--titles \
-f --fingerprint \
-a --all -b --banner --current-user --current-db --hostname \
--is-dba --users --passwords --privileges --roles --dbs --tables \
--columns --schema --count --dump --dump-all --search --comments \
-D -T -C -X -U --exclude-sysdbs \
--sql-shell --common-tables \
--common-columns --udf-inject \
--os-shell --os-pwn --os-smbrelay --os-bof \
--priv-esc --reg-read --reg-add --reg-del \
-s -t --batch \
--eta --flush-session \
--forms --fresh-queries --hex --parse-errors \
--save --update \
-z --beep --check-waf --cleanup \
--dependencies --disable-coloring --identify-waf \
--mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard '
COMPREPLY=( $( \
(while read -d ' ' i; do
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
continue
# flatten array with spaces on either side,
# otherwise we cannot grep on word boundaries of
# first and last word
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done
printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
) )
# else
# _filedir bat
fi
}
complete -F _sqlmap sqlmap
fi

View File

@ -37,4 +37,4 @@ _sshcomplete() {
return 0
}
complete -o default -o nospace -F _sshcomplete ssh scp
complete -o default -o nospace -F _sshcomplete ssh scp slogin

View File

@ -22,6 +22,7 @@ if [ $(uname) = "Darwin" ] && command -v brew &>/dev/null ; then
# homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path
if [ "${BASH_VERSINFO}" -ge 4 ] && [ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]; then
export BASH_COMPLETION_COMPAT_DIR="$BREW_PREFIX"/etc/bash_completion.d
. "$BREW_PREFIX"/share/bash-completion/bash_completion
fi
fi

View File

@ -0,0 +1,15 @@
#!/usr/bin/bash
if command -v vue > /dev/null; then
__vuejs_completion() {
local OPTS=("--version --help create add invoke inspect serve build ui init config upgrade info")
COMPREPLY=()
for _opt_ in ${OPTS[@]}; do
if [[ "$_opt_" == "$2"* ]]; then
COMPREPLY+=("$_opt_")
fi
done
}
complete -F __vuejs_completion vue
fi

View File

@ -0,0 +1,16 @@
#!/usr/bin/bash
if command -v wpscan > /dev/null; then
__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
fi

View File

@ -155,6 +155,7 @@ fi
# Load dependencies for enabling components
source "$BASH_IT/lib/composure.bash"
source "$BASH_IT/lib/utilities.bash"
cite _about _param _example _group _author _version
source "$BASH_IT/lib/helpers.bash"

View File

@ -14,49 +14,21 @@ function _command_exists ()
type "$1" &> /dev/null ;
}
# Helper function loading various enable-able files
function _load_bash_it_files() {
subdirectory="$1"
if [ -d "${BASH_IT}/${subdirectory}/enabled" ]
then
FILES="${BASH_IT}/${subdirectory}/enabled/*.bash"
for config_file in $FILES
do
if [ -e "${config_file}" ]; then
source $config_file
fi
done
fi
function _make_reload_alias() {
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
}
function _load_global_bash_it_files() {
# In the new structure
if [ -d "${BASH_IT}/enabled" ]
then
FILES="${BASH_IT}/enabled/*.bash"
for config_file in $FILES
do
if [ -e "${config_file}" ]; then
source $config_file
fi
done
fi
}
# Alias for reloading aliases
# shellcheck disable=SC2139
alias reload_aliases="$(_make_reload_alias alias aliases)"
# Function for reloading aliases
function reload_aliases() {
_load_bash_it_files "aliases"
}
# Alias for reloading auto-completion
# shellcheck disable=SC2139
alias reload_completion="$(_make_reload_alias completion completion)"
# Function for reloading auto-completion
function reload_completion() {
_load_bash_it_files "completion"
}
# Function for reloading plugins
function reload_plugins() {
_load_bash_it_files "plugins"
}
# Alias for reloading plugins
# shellcheck disable=SC2139
alias reload_plugins="$(_make_reload_alias plugin plugins)"
bash-it ()
{
@ -70,7 +42,7 @@ bash-it ()
example '$ bash-it disable alias hg [tmux]...'
example '$ bash-it migrate'
example '$ bash-it update'
example '$ bash-it search ruby [[-]rake]... [--enable | --disable]'
example '$ bash-it search [-|@]term1 [-|@]term2 ... [ -e/--enable ] [ -d/--disable ] [ -r/--refresh ] [ -c/--no-color ]'
example '$ bash-it version'
example '$ bash-it reload'
typeset verb=${1:-}
@ -78,6 +50,7 @@ bash-it ()
typeset component=${1:-}
shift
typeset func
case $verb in
show)
func=_bash-it-$component;;
@ -167,6 +140,8 @@ _bash-it_update() {
_about 'updates Bash-it'
_group 'lib'
local old_pwd="${PWD}"
cd "${BASH_IT}" || return
if [ -z $BASH_IT_REMOTE ]; then
@ -179,22 +154,44 @@ _bash-it_update() {
status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)"
if [[ -n "${status}" ]]; then
git pull --rebase &> /dev/null
if [[ $? -eq 0 ]]; then
echo "Bash-it successfully updated."
echo ""
echo "Migrating your installation to the latest version now..."
_bash-it-migrate
echo ""
echo "All done, enjoy!"
bash-it reload
else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
fi
for i in $(git rev-list --merges --first-parent master..${BASH_IT_REMOTE}); do
num_of_lines=$(git log -1 --format=%B $i | awk 'NF' | wc -l)
if [ $num_of_lines -eq 1 ]; then
description="%s"
else
description="%b"
fi
git log --format="%h: $description (%an)" -1 $i
done
echo ""
read -e -n 1 -p "Would you like to update to $(git log -1 --format=%h origin/master)? [Y/n] " RESP
case $RESP in
[yY]|"")
git pull --rebase &> /dev/null
if [[ $? -eq 0 ]]; then
echo "Bash-it successfully updated."
echo ""
echo "Migrating your installation to the latest version now..."
_bash-it-migrate
echo ""
echo "All done, enjoy!"
bash-it reload
else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
fi
;;
[nN])
echo "Not upgrading…"
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
else
echo "Bash-it is up to date, nothing to do!"
fi
cd - &> /dev/null || return
cd "${old_pwd}" &> /dev/null || return
}
_bash-it-migrate() {
@ -260,7 +257,7 @@ _bash-it-reload() {
_about 'reloads a profile file'
_group 'lib'
cd "${BASH_IT}" || return
pushd "${BASH_IT}" &> /dev/null || return
case $OSTYPE in
darwin*)
@ -271,7 +268,7 @@ _bash-it-reload() {
;;
esac
cd - &> /dev/null || return
popd &> /dev/null || return
}
_bash-it-describe ()
@ -391,6 +388,8 @@ _disable-thing ()
fi
fi
_bash-it-clean-component-cache "${file_type}"
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then
exec ${0/-/}
fi
@ -453,6 +452,9 @@ _enable-thing ()
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
to_enable=$(basename $f .$file_type.bash)
if [ "$file_type" = "alias" ]; then
to_enable=$(basename $f ".aliases.bash")
fi
_enable-thing $subdirectory $file_type $to_enable $load_priority
done
else
@ -486,6 +488,8 @@ _enable-thing ()
ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}"
fi
_bash-it-clean-component-cache "${file_type}"
if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then
exec ${0/-/}
fi

389
lib/search.bash 100644 → 100755
View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
#
# Search by Konstantin Gredeskoul «github.com/kigster»
#———————————————————————————————————————————————————————————————————————————————
@ -5,190 +6,356 @@
# whose name or description matches one of the search terms provided as arguments.
#
# Usage:
# bash-it search term1 [[-]term2] ... [[-]termN] [ --enable | --disable ]
# bash-it search [-|@]term1 [-|@]term2 ... \
# [ --enable | -e ] \
# [ --disable | -d ] \
# [ --no-color | -c ] \
# [ --refresh | -r ] \
# [ --help | -h ]
#
# Exmplanation:
# Single dash, as in "-chruby", indicates a negative search term.
# Double dash indicates a command that is to be applied to the search result.
# At the moment only --enable and --disable are supported.
# At the moment only --help, --enable and --disable are supported.
# An '@' sign indicates an exact (not partial) match.
#
# Examples:
# bash-it search ruby rbenv rvm gem rake
# aliases : bundler
# plugins : chruby chruby-auto rbenv ruby rvm
# completions : gem rake
# aliases: bundler
# plugins: chruby chruby-auto ruby rbenv rvm ruby
# completions: rvm gem rake
#
# bash-it search ruby rbenv rvm gem rake -chruby
# aliases : bundler
# plugins : rbenv ruby rvm
# completions : gem rake
# aliases: bundler
# plugins: ruby rbenv rvm ruby
# completions: rvm gem rake
#
# Examples of enabling or disabling results of the search:
#
# bash-it search ruby
# aliases => bundler
# plugins => chruby chruby-auto ruby
# aliases: bundler
# plugins: chruby chruby-auto ruby
#
# bash-it search ruby -chruby --enable
# aliases => ✓bundler
# plugins => ✓ruby
# aliases: bundler
# plugins: ruby
#
# Examples of using exact match:
# bash-it search @git @ruby
# aliases: git
# plugins: git ruby
# completions: git
#
_bash-it-search() {
_about 'searches for given terms amongst bash-it plugins, aliases and completions'
_param '1: term1'
_param '2: [ term2 ]...'
_example '$ _bash-it-search ruby rvm rake bundler'
_example '$ _bash-it-search @git ruby -rvm rake bundler'
declare -a _components=(aliases plugins completions)
[[ -z "$(type _bash-it-array-contains-element 2>/dev/null)" ]] && source "${BASH_IT}/lib/utilities.bash"
for _component in "${_components[@]}" ; do
_bash-it-search-component "${_component}" "$@"
local component
export BASH_IT_SEARCH_USE_COLOR=true
export BASH_IT_GREP=${BASH_IT_GREP:-$(which egrep)}
declare -a BASH_IT_COMPONENTS=(aliases plugins completions)
if [[ -z "$*" ]] ; then
_bash-it-search-help
return 0
fi
local -a args=()
for word in $@; do
if [[ ${word} == "--help" || ${word} == "-h" ]]; then
_bash-it-search-help
return 0
elif [[ ${word} == "--refresh" || ${word} == "-r" ]]; then
_bash-it-clean-component-cache
elif [[ ${word} == "--no-color" || ${word} == '-c' ]]; then
export BASH_IT_SEARCH_USE_COLOR=false
else
args=(${args[@]} ${word})
fi
done
if [[ ${#args} -gt 0 ]]; then
for component in "${BASH_IT_COMPONENTS[@]}" ; do
_bash-it-search-component "${component}" "${args[@]}"
done
fi
return 0
}
#———————————————————————————————————————————————————————————————————————————————
# array=("something to search for" "a string" "test2000")
# _bash-it-array-contains-element "a string" "${array[@]}"
# ( prints "true" or "false" )
_bash-it-array-contains-element () {
local e
local r=false
for e in "${@:2}"; do [[ "$e" == "$1" ]] && r=true; done
echo -n $r
_bash-it-search-help() {
printf "${echo_normal}
${echo_underline_yellow}USAGE${echo_normal}
bash-it search [-|@]term1 [-|@]term2 ... \\
[ --enable | -e ] \\
[ --disable | -d ] \\
[ --no-color | -c ] \\
[ --refresh | -r ] \\
[ --help | -h ]
${echo_underline_yellow}DESCRIPTION${echo_normal}
Use ${echo_bold_green}search${echo_normal} bash-it command to search for a list of terms or term negations
across all components: aliases, completions and plugins. Components that are
enabled are shown in green (or with a check box if --no-color option is used).
In addition to simply finding the right component, you can use the results
of the search to enable or disable all components that the search returns.
When search is used to enable/disable components it becomes clear that
you must be able to perform not just a partial match, but an exact match,
as well as be able to exclude some components.
* To exclude a component (or all components matching a substring) use
a search term with minus as a prefix, eg '-flow'
* To perform an exact match, use character '@' in front of the term,
eg. '@git' would only match aliases, plugins and completions named 'git'.
${echo_underline_yellow}FLAGS${echo_normal}
--enable | -e ${echo_purple}Enable all matching componenents.${echo_normal}
--disable | -d ${echo_purple}Disable all matching componenents.${echo_normal}
--help | -h ${echo_purple}Print this help.${echo_normal}
--refresh | -r ${echo_purple}Force a refresh of the search cache.${echo_normal}
--no-color | -c ${echo_purple}Disable color output and use monochrome text.${echo_normal}
${echo_underline_yellow}EXAMPLES${echo_normal}
For example, ${echo_bold_green}bash-it search git${echo_normal} would match any alias, completion
or plugin that has the word 'git' in either the module name or
it's description. You should see something like this when you run this
command:
${echo_bold_green} bash-it search git${echo_bold_blue}
${echo_bold_yellow}aliases: ${echo_bold_green}git ${echo_normal}gitsvn
${echo_bold_yellow}plugins: ${echo_normal}autojump fasd ${echo_bold_green}git ${echo_normal}git-subrepo jgitflow jump
${echo_bold_yellow}completions: ${echo_bold_green}git ${echo_normal}git_flow git_flow_avh${echo_normal}
You can exclude some terms by prefixing a term with a minus, eg:
${echo_bold_green} bash-it search git -flow -svn${echo_bold_blue}
${echo_bold_yellow}aliases: ${echo_normal}git
${echo_bold_yellow}plugins: ${echo_normal}autojump fasd git git-subrepo jump
${echo_bold_yellow}completions: ${echo_normal}git${echo_normal}
Finally, if you prefix a term with '@' symbol, that indicates an exact
match. Note, that we also pass the '--enable' flag, which would ensure
that all matches are automatically enabled. The example is below:
${echo_bold_green} bash-it search @git --enable${echo_bold_blue}
${echo_bold_yellow}aliases: ${echo_normal}git
${echo_bold_yellow}plugins: ${echo_normal}git
${echo_bold_yellow}completions: ${echo_normal}git${echo_normal}
${echo_underline_yellow}SUMMARY${echo_normal}
Take advantage of the search functionality to discover what Bash-It can do
for you. Try searching for partial term matches, mix and match with the
negative terms, or specify an exact matches of any number of terms. Once
you created the search command that returns ONLY the modules you need,
simply append '--enable' or '--disable' at the end to activate/deactivate
each module.
"
}
_bash-it-is-partial-match() {
local component="$1"
local term="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -i -q -- "${term}"
}
_bash-it-component-term-matches-negation() {
local match="$1"; shift
local negative
for negative in "$@"; do
[[ "${match}" =~ "${negative}" ]] && return 0
done
return 1
}
_bash-it-search-component() {
_about 'searches for given terms amongst a given component'
_param '1: component type, one of: [ aliases | plugins | completions ]'
_param '2: term1 '
_param '3: [-]term2 [-]term3 ...'
_example '$ _bash-it-search-component aliases rake bundler -chruby'
_component=$1
local func=_bash-it-${_component}
local help=$($func)
local component="$1"
shift
_about 'searches for given terms amongst a given component'
_param '1: component type, one of: [ aliases | plugins | completions ]'
_param '2: term1 term2 @term3'
_param '3: [-]term4 [-]term5 ...'
_example '$ _bash-it-search-component aliases @git rake bundler -chruby'
# if one of the search terms is --enable or --disable, we will apply
# this action to the matches further down.
local action action_func component_singular
declare -a _search_commands=(enable disable)
for _search_command in "${_search_commands[@]}"; do
if [[ $(_bash-it-array-contains-element "--${_search_command}" "$@") == "true" ]]; then
action=$_search_command
component_singular=${_component}
# this action to the matches further ` down.
local component_singular action action_func
local -a search_commands=(enable disable)
for search_command in "${search_commands[@]}"; do
if $(_bash-it-array-contains-element "--${search_command}" "$@"); then
component_singular=${component}
component_singular=${component_singular/es/} # aliases -> alias
component_singular=${component_singular/ns/n} # plugins -> plugin
action="${search_command}"
action_func="_${action}-${component_singular}"
break
fi
done
local _grep=$((which --skip-alias grep 2> /dev/null || which grep) | tail -n 1)
local -a terms=($@) # passed on the command line
declare -a terms=($@) # passed on the command line
declare -a matches=() # results that we found
declare -a negative_terms=() # terms that began with a dash
unset exact_terms
unset partial_terms
unset negative_terms
local -a exact_terms=() # terms that should be included only if they match exactly
local -a partial_terms=() # terms that should be included if they match partially
local -a negative_terms=() # negated partial terms that should be excluded
unset component_list
local -a component_list=( $(_bash-it-component-list "${component}") )
local term
for term in "${terms[@]}"; do
# -- can only be used for the actions: enable/disable
[[ "${term:0:2}" == "--" ]] && continue
[[ "${term:0:1}" == "-" ]] && negative_terms=(${negative_terms[@]} ${term:1}) && continue
# print asterisk next to each result that is already enabled by the user
local term_match=($(echo "${help}"| ${_grep} -i -- ${term} | ${_grep} -E '\[( |x)\]' | cut -b -30 | sed 's/ *\[ \]//g;s/ *\[x\]/*/g;' ))
[[ "${#term_match[@]}" -gt 0 ]] && {
matches=(${matches[@]} ${term_match[@]}) # append to the list of results
}
local search_term="${term:1}"
if [[ "${term:0:2}" == "--" ]] ; then
continue
elif [[ "${term:0:1}" == "-" ]] ; then
negative_terms=(${negative_terms[@]} "${search_term}")
elif [[ "${term:0:1}" == "@" ]] ; then
if $(_bash-it-array-contains-element "${search_term}" "${component_list[@]}"); then
exact_terms=(${exact_terms[@]} "${search_term}")
fi
else
partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}") )
fi
done
# now check if we found any negative terms, and subtract them
[[ ${#negative_terms} -gt 0 ]] && {
declare -a filtered_matches=()
for match in "${matches[@]}"; do
local negations=0
for nt in "${negative_terms[@]}"; do
[[ "${match}" =~ "${nt}" ]] && negations=$(($negations+1))
done
[[ $negations -eq 0 ]] && filtered_matches=(${filtered_matches[@]} ${match})
done
matches=(${filtered_matches[@]})
}
local -a total_matches=( $(_bash-it-array-dedup ${exact_terms[@]} ${partial_terms[@]}) )
_bash-it-search-result $action $action_func
unset matches filtered_matches terms
unset matches
declare -a matches=()
for match in ${total_matches[@]}; do
local include_match=true
if [[ ${#negative_terms[@]} -gt 0 ]]; then
( _bash-it-component-term-matches-negation "${match}" "${negative_terms[@]}" ) && include_match=false
fi
( ${include_match} ) && matches=(${matches[@]} "${match}")
done
_bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]}"
unset matches final_matches terms
}
_bash-it-search-result() {
local action=$1; shift
local action_func=$1; shift
local component="$1"; shift
local action="$1"; shift
local action_func="$1"; shift
local -a matches=($@)
local color_component color_enable color_disable color_off
[[ -z "$NO_COLOR" ]] && {
color_sep=':'
( ${BASH_IT_SEARCH_USE_COLOR} ) && {
color_component='\e[1;34m'
color_enable='\e[1;32m'
suffix_enable=''
suffix_disable=''
color_disable='\e[0;0m'
color_off='\e[0;0m'
color_sep=':'
}
[[ -n "$NO_COLOR" ]] && {
( ${BASH_IT_SEARCH_USE_COLOR} ) || {
color_component=''
color_sep=' => '
color_enable='✓'
suffix_enable=' ✓ '
suffix_disable=' '
color_enable=''
color_disable=''
color_off=''
}
if [[ "${#matches[*]}" -gt 0 ]] ; then
printf "${color_component}%13s${color_sep} ${color_off}" "${_component}"
local match
local modified=0
sorted_matches=($(echo "${matches[*]}" | tr ' ' '\n' | sort | uniq))
if [[ "${#matches[@]}" -gt 0 ]] ; then
printf "${color_component}%13s${color_sep} ${color_off}" "${component}"
for match in "${sorted_matches[@]}"; do
local match_color compatible_action
if [[ $match =~ "*" ]]; then
match_color=$color_enable
for match in "${matches[@]}"; do
local enabled=0
( _bash-it-component-item-is-enabled "${component}" "${match}" ) && enabled=1
local match_color compatible_action suffix opposite_suffix
(( ${enabled} )) && {
match_color=${color_enable}
suffix=${suffix_enable}
opposite_suffix=${suffix_disable}
compatible_action="disable"
else
match_color=$color_disable
}
(( ${enabled} )) || {
match_color=${color_disable}
suffix=${suffix_disable}
opposite_suffix=${suffix_enable}
compatible_action="enable"
fi
}
match_value=${match/\*/} # remove asterisk
len=${#match_value}
if [[ -n $NO_COLOR ]]; then
local m="${match_color}${match_value}"
len=${#m}
fi
printf " ${match_color}${match_value}" # print current state
local m="${match}${suffix}"
local len
len=${#m}
printf " ${match_color}${match}${suffix}" # print current state
if [[ "${action}" == "${compatible_action}" ]]; then
# oh, i see we need to either disable enabled, or enable disabled
# component. Let's start with the most important part: redrawing
# the search result backwards. Because style.
printf "\033[${len}D"
for a in {0..30}; do
[[ $a -gt $len ]] && break
printf "%.*s" $a " "
sleep 0.07 # who knew you could sleep for fraction of the cost :)
done
printf "\033[${len}D"
result=$(${action_func} ${match_value})
if [[ ${action} == "enable" && ${BASH_IT_SEARCH_USE_COLOR} == false ]]; then
_bash-it-flash-term ${len} "${match}${suffix}"
else
_bash-it-erase-term ${len}
fi
modified=1
result=$(${action_func} ${match})
local temp="color_${compatible_action}"
match_color=${!temp}
printf "${match_color}${match_value}"
_bash-it-rewind ${len}
printf "${match_color}${match}${opposite_suffix}"
fi
printf "${color_off}"
done
[[ ${modified} -gt 0 ]] && _bash-it-clean-component-cache ${component}
printf "\n"
fi
}
_bash-it-rewind() {
local len="$1"
printf "\033[${len}D"
}
_bash-it-flash-term() {
local len="$1"
local match="$2"
local delay=0.1
local color
for color in ${text_black} ${echo_bold_blue} ${bold_yellow} ${bold_red} ${echo_bold_green} ; do
sleep ${delay}
_bash-it-rewind "${len}"
printf "${color}${match}"
done
}
_bash-it-erase-term() {
local len="$1"
_bash-it-rewind ${len}
for a in {0..30}; do
[[ ${a} -gt ${len} ]] && break
printf "%.*s" $a " "
sleep 0.05
done
}

146
lib/utilities.bash 100644
View File

@ -0,0 +1,146 @@
#!/usr/bin/env bash
#
# A collection of reusable functions.
###########################################################################
# Component-specific functions (component is either an alias, a plugin, or a
# completion).
###########################################################################
_bash-it-component-help() {
local component=$(_bash-it-pluralize-component "${1}")
local file=$(_bash-it-component-cache-file ${component})
if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then
rm -f "${file}" 2>/dev/null
local func="_bash-it-${component}"
${func} | $(_bash-it-grep) -E ' \[' | cat > ${file}
fi
cat "${file}"
}
_bash-it-component-cache-file() {
local component=$(_bash-it-pluralize-component "${1}")
local file="${BASH_IT}/tmp/cache/${component}"
[[ -f ${file} ]] || mkdir -p $(dirname ${file})
printf "${file}"
}
_bash-it-pluralize-component() {
local component="${1}"
local len=$(( ${#component} - 1 ))
# pluralize component name for consistency
[[ ${component:${len}:1} != 's' ]] && component="${component}s"
[[ ${component} == "alias" ]] && component="aliases"
printf ${component}
}
_bash-it-clean-component-cache() {
local component="$1"
local cache
local -a BASH_IT_COMPONENTS=(aliases plugins completions)
if [[ -z ${component} ]] ; then
for component in "${BASH_IT_COMPONENTS[@]}" ; do
_bash-it-clean-component-cache "${component}"
done
else
cache="$(_bash-it-component-cache-file ${component})"
if [[ -f "${cache}" ]] ; then
rm -f "${cache}"
fi
fi
}
###########################################################################
# Generic utilies
###########################################################################
# This function searches an array for an exact match against the term passed
# as the first argument to the function. This function exits as soon as
# a match is found.
#
# Returns:
# 0 when a match is found, otherwise 1.
#
# Examples:
# $ declare -a fruits=(apple orange pear mandarin)
#
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
# contains apple
#
# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then
# echo "contains pear!"
# fi
# contains pear!
#
#
_bash-it-array-contains-element() {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0
done
return 1
}
# Dedupe a simple array of words without spaces.
_bash-it-array-dedup() {
echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' '
}
# Outputs a full path of the grep found on the filesystem
_bash-it-grep() {
if [[ -z "${BASH_IT_GREP}" ]] ; then
export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')"
fi
printf "%s " "${BASH_IT_GREP}"
}
# Returns an array of items within each compoenent.
_bash-it-component-list() {
local component="$1"
_bash-it-component-help "${component}" | awk '{print $1}' | uniq | sort | tr '\n' ' '
}
_bash-it-component-list-matching() {
local component="$1"; shift
local term="$1"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -- "${term}" | awk '{print $1}' | sort | uniq
}
_bash-it-component-list-enabled() {
local component="$1"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' '
}
_bash-it-component-list-disabled() {
local component="$1"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | awk '{print $1}' | uniq | sort | tr '\n' ' '
}
# Checks if a given item is enabled for a particular component/file-type.
# Uses the component cache if available.
#
# Returns:
# 0 if an item of the component is enabled, 1 otherwise.
#
# Examples:
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
_bash-it-component-item-is-enabled() {
local component="$1"
local item="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s"
}
# Checks if a given item is disabled for a particular component/file-type.
# Uses the component cache if available.
#
# Returns:
# 0 if an item of the component is enabled, 1 otherwise.
#
# Examples:
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
_bash-it-component-item-is-disabled() {
local component="$1"
local item="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s"
}

View File

@ -4,7 +4,7 @@ about-plugin 'display info about your battery charge level'
ac_adapter_connected(){
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'charging\|fully-charged'
upower -i $(upower -e | grep -i BAT) | grep 'state' | grep -q 'charging\|fully-charged'
return $?
elif _command_exists acpi;
then
@ -28,7 +28,7 @@ ac_adapter_connected(){
ac_adapter_disconnected(){
if _command_exists upower;
then
upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'discharging'
upower -i $(upower -e | grep -i BAT) | grep 'state' | grep -q 'discharging'
return $?
elif _command_exists acpi;
then
@ -57,7 +57,7 @@ battery_percentage(){
if _command_exists upower;
then
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
COMMAND_OUTPUT=$(upower --show-info $(upower --enumerate | grep -i BAT) | grep percentage | grep -o "[0-9]\+" | head -1)
elif _command_exists acpi;
then
COMMAND_OUTPUT=$(acpi -b | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' )

View File

@ -4,7 +4,11 @@
cite about-plugin
about-plugin 'load fzf, if you are using it'
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
if [ -f ~/.fzf.bash ]; then
source ~/.fzf.bash
elif [ -f "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash ]; then
source "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.bash
fi
if [ -z ${FZF_DEFAULT_COMMAND+x} ]; then
command -v fd &> /dev/null && export FZF_DEFAULT_COMMAND='fd --type f'

View File

@ -30,8 +30,20 @@ function v2gif {
example '$ v2gif -dh *.avi'
example '$ v2gif -thw 600 *.avi *.mov'
local convert=$(which convert) ; [[ -x "$convert" ]] || { echo "No convert found!" ; return 2 ;}
local ffmpeg=$(which ffmpeg) ; [[ -x "$ffmpeg" ]] || { echo "No ffmpeg found!" ; return 2 ;}
local mediainfo=$(which mediainfo) ; [[ -x "$mediainfo" ]] || { echo "No mediainfo found!" ; return 2 ;}
local gifsicle=$(which gifsicle) ; [[ -x "$gifsicle" ]] || { echo "No gifsicle found!" ; return 2 ;}
local getopt=$(which getopt)
if [[ "$OSTYPE" == "darwin"* ]] ; then
# Getopt on BSD is incompatible with GNU
getopt=/usr/local/opt/gnu-getopt/bin/getopt
[[ -x "$getopt" ]] || { echo "No GNU-getopt found!" ; return 2 ;}
fi
# Parse the options
local args=$(getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@")
local args=$($getopt -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@")
if [ $? -ne 0 ]; then
echo 'Terminating...' >&2
@ -65,6 +77,7 @@ function v2gif {
;;
-h|--high)
#High Quality, use gifski
local gifski=$(which gifski) ; [[ -x "$gifski" ]] || { echo "No gifski found!" ; return 2 ; }
use_gifski=true
giftag="${giftag}-h"
shift
@ -106,7 +119,15 @@ function v2gif {
done
if [[ -z "$*" ]]; then
echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w <max width (pixels)>] [-l <lossy level>] < $(tput sgr 0)"
echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w <max width (pixels)>] [-l <lossy level>] $(tput sgr 0)"
echo "-d/--del/--delete Delete original vid if done suceessfully (and file not over the size limit)"
echo "-h/--high High Quality - use Gifski instead of gifsicle"
echo "-w/--width N Lock maximum gif width to N pixels, resize if necessary"
echo "-t/--tag Add a tag to the output gif describing the options used (useful for comparing several options)"
echo "-l/--lossy N Use the Giflossy parameter for gifsicle (If your version supports it)"
echo "-f/--fps N Override autodetection of incoming vid FPS (useful for downsampling)"
echo "-a/--alert N Alert if over N kilobytes (Defaults to 5000)"
echo "-m/--webm Also create a webm file"
return 1
fi
@ -120,7 +141,7 @@ function v2gif {
local del_after=$opt_del_after
if [[ "$make_webm" ]] ; then
ffmpeg -loglevel panic -i "$file" \
$ffmpeg -loglevel panic -i "$file" \
-c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \
-quality best -loop 0 "${file%.*}.webm" || return 2
fi
@ -130,9 +151,9 @@ function v2gif {
fps=$infps
else
fps=$defaultfps
if [[ -x /usr/bin/mediainfo ]] ; then
fps=$(/usr/bin/mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
[[ -z "$fps" ]] && fps=$(/usr/bin/mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
if [[ -x $mediainfo ]] ; then
fps=$($mediainfo "$file" | grep "Frame rate " |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
[[ -z "$fps" ]] && fps=$($mediainfo "$file" | grep "Minimum frame rate" |sed 's/.*: \([0-9.]\+\) .*/\1/' | head -1)
fi
fi
@ -140,12 +161,12 @@ function v2gif {
if [[ "$use_gifski" = "true" ]] ; then
# I trust @pornel to do his own resizing optimization choices
ffmpeg -loglevel panic -i "$file" -r $fps -vcodec png v2gif-tmp-%05d.png && \
gifski $maxwidthski --fps $(printf "%.0f" $fps) -o "$output_file" v2gif-tmp-*.png || return 2
$ffmpeg -loglevel panic -i "$file" -r $fps -vcodec png v2gif-tmp-%05d.png && \
$gifski $maxwidthski --fps $(printf "%.0f" $fps) -o "$output_file" v2gif-tmp-*.png || return 2
else
ffmpeg -loglevel panic -i "$file" $maxsize -r $fps -vcodec png v2gif-tmp-%05d.png && \
convert +dither -layers Optimize v2gif-tmp-*.png GIF:- | \
gifsicle $lossiness --no-warnings --colors 256 --delay=$(echo "100/$fps"|bc) --loop --optimize=3 --multifile - > "$output_file" || return 2
$ffmpeg -loglevel panic -i "$file" $maxsize -r $fps -vcodec png v2gif-tmp-%05d.png && \
$convert +dither -layers Optimize v2gif-tmp-*.png GIF:- | \
$gifsicle $lossiness --no-warnings --colors 256 --delay=$(echo "100/$fps"|bc) --loop --optimize=3 --multifile - > "$output_file" || return 2
fi
rm v2gif-tmp-*.png
@ -255,7 +276,7 @@ function any2webm() {
echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)"
ffmpeg -loglevel panic -i "$file" \
$ffmpeg -loglevel panic -i "$file" \
-c:v libvpx -crf 4 -threads 0 -an -b:v $bandwidth -auto-alt-ref 0 \
-quality best $fps $size -loop 0 -pix_fmt yuva420p "$output_file" || return 2

View File

@ -5,7 +5,25 @@ about-plugin 'go environment variables & path configuration'
[ ! command -v go &>/dev/null ] && return
function _split_path_reverse() {
local a=( ${@//:/ } )
local i=${#a[@]}
local r=
while [ $i -gt 0 ] ; do
i=$(( i - 1 ))
if [ $(( i + 1 )) -eq ${#a[@]} ] ; then
r="${a[i]}"
else
r="${r} ${a[i]}"
fi
done
echo "$r"
}
export GOROOT=${GOROOT:-$(go env GOROOT)}
pathmunge "${GOROOT}/bin"
export GOPATH=${GOPATH:-$(go env GOPATH)}
pathmunge "${GOPATH}/bin"
for p in $( _split_path_reverse ${GOPATH} ) ; do
pathmunge "${p}/bin"
done

View File

@ -2,7 +2,7 @@ cite about-plugin
about-plugin 'history manipulation'
# enter a few characters and press UpArrow/DownArrow
# to search backwards/forwards through the history
if [ -t 1 ]
if [[ ${SHELLOPTS} =~ (vi|emacs) ]]
then
bind '"":history-search-backward'
bind '"":history-search-forward'

View File

@ -4,6 +4,4 @@ about-plugin 'load jenv, if you are using it'
export JENV_ROOT="$HOME/.jenv"
pathmunge "$JENV_ROOT/bin"
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
[[ -e $JENV_ROOT/completions/jenv.bash ]] && source $JENV_ROOT/completions/jenv.bash
if which jenv > /dev/null; then eval "$(jenv init - bash)"; fi

View File

@ -6,8 +6,9 @@ if $(command -v pygmentize &> /dev/null) ; then
CAT_BIN=$(which cat)
LESS_BIN=$(which less)
# pigmentize cat and less outputs
function cat()
# 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
function ccat()
{
about 'runs either pygmentize or cat on each file passed in'
param '*: files to concatenate (as normally passed to cat)'
@ -18,7 +19,7 @@ if $(command -v pygmentize &> /dev/null) ; then
done
}
function less()
function cless()
{
about 'it pigments the file passed in and passes it to less for pagination'
param '$1: the file to paginate with less'

View File

@ -4,7 +4,4 @@ about-plugin 'load nodenv, if you are using it'
export NODENV_ROOT="$HOME/.nodenv"
pathmunge "$NODENV_ROOT/bin"
[[ `which nodenv` ]] && eval "$(nodenv init -)"
# Load the auto-completion script if nodenv was loaded.
[[ -e $NODENV_ROOT/completions/nodenv.bash ]] && source $NODENV_ROOT/completions/nodenv.bash
[[ `which nodenv` ]] && eval "$(nodenv init - bash)"

View File

@ -111,5 +111,66 @@ function refresh-launchpad() {
fi
}
function list-jvms(){
about 'List java virtual machines and their states in macOS'
example 'list-jvms'
group 'osx'
JVMS_DIR="/Library/Java/JavaVirtualMachines"
JVMS=( $(ls ${JVMS_DIR}) )
JVMS_STATES=()
# Map state of JVM
for (( i = 0; i < ${#JVMS[@]}; i++ )); do
if [[ -f "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" ]]; then
JVMS_STATES[${i}]=enabled
else
JVMS_STATES[${i}]=disabled
fi
echo "${i} ${JVMS[$i]} ${JVMS_STATES[$i]}"
done
}
function pick-default-jvm(){
about 'Pick the default Java Virtual Machines in system-wide scope in macOS'
example 'pick-default-jvm'
# Call function for listing
list-jvms
# Declare variables
local DEFAULT_JVM_DIR=""
local DEFAULT_JVM=""
local OPTION=""
# OPTION for default jdk and set variables
while [[ ! "$OPTION" =~ ^[0-9]+$ || OPTION -ge "${#JVMS[@]}" ]]; do
read -p "Enter Default JVM: " OPTION
if [[ ! "$OPTION" =~ ^[0-9]+$ ]]; then
echo "Please enter a number"
fi
if [[ OPTION -ge "${#JVMS[@]}" ]]; then
echo "Please select one of the displayed JVMs"
fi
done
DEFAULT_JVM_DIR="${JVMS_DIR}/${JVMS[$OPTION]}"
DEFAULT_JVM="${JVMS[$OPTION]}"
# Disable all jdk
for (( i = 0; i < ${#JVMS[@]}; i++ )); do
if [[ -f "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" ]]; then
sudo mv "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist" "${JVMS_DIR}/${JVMS[$i]}/Contents/Info.plist.disable"
fi
done
# Enable default jdk
if [[ -f "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" ]]; then
sudo mv "${DEFAULT_JVM_DIR}/Contents/Info.plist.disable" "${DEFAULT_JVM_DIR}/Contents/Info.plist"
echo "Enabled ${DEFAULT_JVM} as default JVM"
fi
}
# Make this backwards compatible
alias pcurl='prevcurl'

View File

@ -0,0 +1,621 @@
# bash completion for pack -*- shell-script -*-
cite about-plugin
about-plugin 'CNB pack cli aliases'
__pack_debug()
{
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
fi
}
# Homebrew on Macs have version 1.3 of bash-completion which doesn't include
# _init_completion. This is a very minimal version of that function.
__pack_init_completion()
{
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
__pack_index_of_word()
{
local w word=$1
shift
index=0
for w in "$@"; do
[[ $w = "$word" ]] && return
index=$((index+1))
done
index=-1
}
__pack_contains_word()
{
local w word=$1; shift
for w in "$@"; do
[[ $w = "$word" ]] && return
done
return 1
}
__pack_handle_reply()
{
__pack_debug "${FUNCNAME[0]}"
case $cur in
-*)
if [[ $(type -t compopt) = "builtin" ]]; then
compopt -o nospace
fi
local allflags
if [ ${#must_have_one_flag[@]} -ne 0 ]; then
allflags=("${must_have_one_flag[@]}")
else
allflags=("${flags[*]} ${two_word_flags[*]}")
fi
COMPREPLY=( $(compgen -W "${allflags[*]}" -- "$cur") )
if [[ $(type -t compopt) = "builtin" ]]; then
[[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
fi
# complete after --flag=abc
if [[ $cur == *=* ]]; then
if [[ $(type -t compopt) = "builtin" ]]; then
compopt +o nospace
fi
local index flag
flag="${cur%=*}"
__pack_index_of_word "${flag}" "${flags_with_completion[@]}"
COMPREPLY=()
if [[ ${index} -ge 0 ]]; then
PREFIX=""
cur="${cur#*=}"
${flags_completion[${index}]}
if [ -n "${ZSH_VERSION}" ]; then
# zsh completion needs --flag= prefix
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
fi
fi
fi
return 0;
;;
esac
# check if we are handling a flag with special work handling
local index
__pack_index_of_word "${prev}" "${flags_with_completion[@]}"
if [[ ${index} -ge 0 ]]; then
${flags_completion[${index}]}
return
fi
# we are parsing a flag and don't have a special handler, no completion
if [[ ${cur} != "${words[cword]}" ]]; then
return
fi
local completions
completions=("${commands[@]}")
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
completions=("${must_have_one_noun[@]}")
fi
if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
completions+=("${must_have_one_flag[@]}")
fi
COMPREPLY=( $(compgen -W "${completions[*]}" -- "$cur") )
if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
COMPREPLY=( $(compgen -W "${noun_aliases[*]}" -- "$cur") )
fi
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
declare -F __custom_func >/dev/null && __custom_func
fi
# available in bash-completion >= 2, not always present on macOS
if declare -F __ltrim_colon_completions >/dev/null; then
__ltrim_colon_completions "$cur"
fi
# If there is only 1 completion and it is a flag with an = it will be completed
# but we don't want a space after the =
if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then
compopt -o nospace
fi
}
# The arguments should be in the form "ext1|ext2|extn"
__pack_handle_filename_extension_flag()
{
local ext="$1"
_filedir "@(${ext})"
}
__pack_handle_subdirs_in_dir_flag()
{
local dir="$1"
pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1
}
__pack_handle_flag()
{
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
# if a command required a flag, and we found it, unset must_have_one_flag()
local flagname=${words[c]}
local flagvalue
# if the word contained an =
if [[ ${words[c]} == *"="* ]]; then
flagvalue=${flagname#*=} # take in as flagvalue after the =
flagname=${flagname%=*} # strip everything after the =
flagname="${flagname}=" # but put the = back
fi
__pack_debug "${FUNCNAME[0]}: looking for ${flagname}"
if __pack_contains_word "${flagname}" "${must_have_one_flag[@]}"; then
must_have_one_flag=()
fi
# if you set a flag which only applies to this command, don't show subcommands
if __pack_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
commands=()
fi
# keep flag value with flagname as flaghash
# flaghash variable is an associative array which is only supported in bash > 3.
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
if [ -n "${flagvalue}" ] ; then
flaghash[${flagname}]=${flagvalue}
elif [ -n "${words[ $((c+1)) ]}" ] ; then
flaghash[${flagname}]=${words[ $((c+1)) ]}
else
flaghash[${flagname}]="true" # pad "true" for bool flag
fi
fi
# skip the argument to a two word flag
if __pack_contains_word "${words[c]}" "${two_word_flags[@]}"; then
c=$((c+1))
# if we are looking for a flags value, don't show commands
if [[ $c -eq $cword ]]; then
commands=()
fi
fi
c=$((c+1))
}
__pack_handle_noun()
{
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
if __pack_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
must_have_one_noun=()
elif __pack_contains_word "${words[c]}" "${noun_aliases[@]}"; then
must_have_one_noun=()
fi
nouns+=("${words[c]}")
c=$((c+1))
}
__pack_handle_command()
{
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
local next_command
if [[ -n ${last_command} ]]; then
next_command="_${last_command}_${words[c]//:/__}"
else
if [[ $c -eq 0 ]]; then
next_command="_pack_root_command"
else
next_command="_${words[c]//:/__}"
fi
fi
c=$((c+1))
__pack_debug "${FUNCNAME[0]}: looking for ${next_command}"
declare -F "$next_command" >/dev/null && $next_command
}
__pack_handle_word()
{
if [[ $c -ge $cword ]]; then
__pack_handle_reply
return
fi
__pack_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
if [[ "${words[c]}" == -* ]]; then
__pack_handle_flag
elif __pack_contains_word "${words[c]}" "${commands[@]}"; then
__pack_handle_command
elif [[ $c -eq 0 ]]; then
__pack_handle_command
elif __pack_contains_word "${words[c]}" "${command_aliases[@]}"; then
# aliashash variable is an associative array which is only supported in bash > 3.
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
words[c]=${aliashash[${words[c]}]}
__pack_handle_command
else
__pack_handle_noun
fi
else
__pack_handle_noun
fi
__pack_handle_word
}
_pack_build()
{
last_command="pack_build"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--builder=")
local_nonpersistent_flags+=("--builder=")
flags+=("--buildpack=")
local_nonpersistent_flags+=("--buildpack=")
flags+=("--clear-cache")
local_nonpersistent_flags+=("--clear-cache")
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
local_nonpersistent_flags+=("--env-file=")
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-pull")
local_nonpersistent_flags+=("--no-pull")
flags+=("--path=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--path=")
flags+=("--publish")
local_nonpersistent_flags+=("--publish")
flags+=("--run-image=")
local_nonpersistent_flags+=("--run-image=")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_run()
{
last_command="pack_run"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--builder=")
local_nonpersistent_flags+=("--builder=")
flags+=("--buildpack=")
local_nonpersistent_flags+=("--buildpack=")
flags+=("--clear-cache")
local_nonpersistent_flags+=("--clear-cache")
flags+=("--env=")
two_word_flags+=("-e")
local_nonpersistent_flags+=("--env=")
flags+=("--env-file=")
local_nonpersistent_flags+=("--env-file=")
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-pull")
local_nonpersistent_flags+=("--no-pull")
flags+=("--path=")
two_word_flags+=("-p")
local_nonpersistent_flags+=("--path=")
flags+=("--port=")
local_nonpersistent_flags+=("--port=")
flags+=("--run-image=")
local_nonpersistent_flags+=("--run-image=")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_rebase()
{
last_command="pack_rebase"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-pull")
local_nonpersistent_flags+=("--no-pull")
flags+=("--publish")
local_nonpersistent_flags+=("--publish")
flags+=("--run-image=")
local_nonpersistent_flags+=("--run-image=")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_create-builder()
{
last_command="pack_create-builder"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--builder-config=")
two_word_flags+=("-b")
local_nonpersistent_flags+=("--builder-config=")
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-pull")
local_nonpersistent_flags+=("--no-pull")
flags+=("--publish")
local_nonpersistent_flags+=("--publish")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_flag+=("--builder-config=")
must_have_one_flag+=("-b")
must_have_one_noun=()
noun_aliases=()
}
_pack_set-run-image-mirrors()
{
last_command="pack_set-run-image-mirrors"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--mirror=")
two_word_flags+=("-m")
local_nonpersistent_flags+=("--mirror=")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_flag+=("--mirror=")
must_have_one_flag+=("-m")
must_have_one_noun=()
noun_aliases=()
}
_pack_inspect-builder()
{
last_command="pack_inspect-builder"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_set-default-builder()
{
last_command="pack_set-default-builder"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_version()
{
last_command="pack_version"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_completion()
{
last_command="pack_completion"
command_aliases=()
commands=()
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
_pack_root_command()
{
last_command="pack"
command_aliases=()
commands=()
commands+=("build")
commands+=("run")
commands+=("rebase")
commands+=("create-builder")
commands+=("set-run-image-mirrors")
commands+=("inspect-builder")
commands+=("set-default-builder")
commands+=("version")
commands+=("completion")
flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()
flags+=("--help")
flags+=("-h")
local_nonpersistent_flags+=("--help")
flags+=("--no-color")
flags+=("--quiet")
flags+=("-q")
flags+=("--timestamps")
must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}
__start_pack()
{
local cur prev words cword
declare -A flaghash 2>/dev/null || :
declare -A aliashash 2>/dev/null || :
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -s || return
else
__pack_init_completion -n "=" || return
fi
local c=0
local flags=()
local two_word_flags=()
local local_nonpersistent_flags=()
local flags_with_completion=()
local flags_completion=()
local commands=("pack")
local must_have_one_flag=()
local must_have_one_noun=()
local last_command
local nouns=()
__pack_handle_word
}
if [[ $(type -t compopt) = "builtin" ]]; then
complete -o default -F __start_pack pack
else
complete -o default -o nospace -F __start_pack pack
fi
# ex: ts=4 sw=4 et filetype=sh

View File

@ -27,7 +27,7 @@ _replace_by_history() {
if command -v percol>/dev/null; then
local current_version=${BASH_VERSION%%[^0-9]*}
current_version=${BASH_VERSION%%[^0-9]*}
if [ $current_version -lt 4 ]; then
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"

View File

@ -4,18 +4,15 @@ cite about-plugin
about-plugin 'plenv plugin for Perl'
if [[ -e "${HOME}/.plenv/bin" ]] ; then
# load plenv bin dir into path if it exists
pathmunge "${HOME}/.plenv/bin"
fi
if [[ `which plenv` ]] ; then
# init plenv
eval "$(plenv init -)"
# Load the auto-completion script if it exists.
[[ -e "${HOME}/.plenv/completions/plenv.bash" ]] && source "${HOME}/.plenv/completions/plenv.bash"
eval "$(plenv init - bash)"
fi

View File

@ -4,12 +4,9 @@ about-plugin 'load pyenv, if you are using it'
export PYENV_ROOT="$HOME/.pyenv"
pathmunge "$PYENV_ROOT/bin"
[[ `which pyenv` ]] && eval "$(pyenv init -)"
[[ `which pyenv` ]] && eval "$(pyenv init - bash)"
#Load pyenv virtualenv if the virtualenv plugin is installed.
if pyenv virtualenv-init - &> /dev/null; then
eval "$(pyenv virtualenv-init -)"
eval "$(pyenv virtualenv-init - bash)"
fi
# Load the auto-completion script if pyenv was loaded.
[[ -e $PYENV_ROOT/completions/pyenv.bash ]] && source $PYENV_ROOT/completions/pyenv.bash

View File

@ -4,7 +4,4 @@ about-plugin 'load rbenv, if you are using it'
export RBENV_ROOT="$HOME/.rbenv"
pathmunge "$RBENV_ROOT/bin"
[[ `which rbenv` ]] && eval "$(rbenv init -)"
# Load the auto-completion script if rbenv was loaded.
[[ -e $RBENV_ROOT/completions/rbenv.bash ]] && source $RBENV_ROOT/completions/rbenv.bash
[[ `which rbenv` ]] && eval "$(rbenv init - bash)"

View File

@ -0,0 +1,36 @@
#!/bin/bash
pushd "${BASH_IT}" >/dev/null || exit 1
# TODO: Add debugging output
if [ "$1" != "skip" ] && [ -d "./enabled" ]; then
_bash_it_config_type=""
if [[ "${1}" =~ ^(alias|completion|plugin)$ ]]; then
_bash_it_config_type=$1
fi
for _bash_it_config_file in $(sort <(compgen -G "./enabled/*${_bash_it_config_type}.bash")); do
if [ -e "${_bash_it_config_file}" ]; then
# shellcheck source=/dev/null
source $_bash_it_config_file
else
echo "Unable to read ${_bash_it_config_file}" > /dev/stderr
fi
done
fi
if [ ! -z "${2}" ] && [[ "${2}" =~ ^(aliases|completion|plugins)$ ]] && [ -d "${2}/enabled" ]; then
# TODO: We should warn users they're using legacy enabling
for _bash_it_config_file in $(sort <(compgen -G "./${2}/enabled/*.bash")); do
if [ -e "$_bash_it_config_file" ]; then
# shellcheck source=/dev/null
source "$_bash_it_config_file"
else
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
fi
done
fi
unset _bash_it_config_file
unset _bash_it_config_type
popd >/dev/null || exit 1

View File

@ -1,5 +1,11 @@
#!/usr/bin/env bash
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# Path to the bash it configuration
export BASH_IT="{{BASH_IT}}"

View File

@ -2,6 +2,8 @@
load ../test_helper
load ../../lib/composure
load ../../lib/utilities
load ../../lib/search
load ../../plugins/available/base.plugin
cite _about _param _example _group _author _version

View File

@ -1,16 +1,21 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../lib/helpers
load ../../lib/utilities
load ../../lib/search
load ../../plugins/available/base.plugin
load ../../aliases/available/git.aliases
load ../../plugins/available/ruby.plugin
load ../../plugins/available/rails.plugin
load ../../completion/available/bundler.completion
load ../../completion/available/gem.completion
load ../../completion/available/rake.completion
cite _about _param _example _group _author _version
load ../../lib/helpers
load ../../lib/search
NO_COLOR=true
function local_setup {
mkdir -p "$BASH_IT"
@ -23,46 +28,69 @@ function local_setup {
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
rm -rf "$BASH_IT"/tmp/cache
mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled
export OLD_PATH="$PATH"
export PATH="/usr/bin:/bin:/usr/sbin"
}
function local_teardown {
export PATH="$OLD_PATH"
unset OLD_PATH
}
@test "search: plugin base" {
export BASH_IT_SEARCH_USE_COLOR=false
run _bash-it-search-component 'plugins' 'base'
[[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]]
assert_line -n 0 ' plugins: base '
}
@test "search: git" {
run _bash-it-search 'git' --no-color
assert_line -n 0 ' aliases: git gitsvn '
assert_line -n 1 ' plugins: autojump fasd git git-subrepo jgitflow jump '
assert_line -n 2 ' completions: git git_flow git_flow_avh '
}
@test "search: ruby gem bundle rake rails" {
# first disable them all, so that the output does not appear with a checkbox
# and we can compare the result
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
# Now perform the search
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
# And verify
assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ]
assert [ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto rails ruby' ]
assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]
run _bash-it-search rails ruby gem bundler rake --no-color
assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: chruby chruby-auto rails ruby '
assert_line -n 2 ' completions: bundler gem rake '
}
@test "search: ruby gem bundle -chruby rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _bash-it-search 'ruby' 'gem' 'bundle' '-chruby' 'rake' 'rails'
assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ]
assert [ "${lines[1]/✓/}" == ' plugins => rails ruby' ]
assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]
@test "search: rails ruby gem bundler rake -chruby" {
run _bash-it-search rails ruby gem bundler rake -chruby --no-color
assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: rails ruby '
assert_line -n 2 ' completions: bundler gem rake '
}
@test "search: (rails enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable'
run _enable-alias 'rails'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails'
assert_line -n 0 ' aliases => bundler ✓rails'
assert_line -n 1 ' plugins => chruby chruby-auto rails ruby'
assert_line -n 2 ' completions => bundler gem rake'
@test "search: @git" {
run _bash-it-search '@git' --no-color
assert_line -n 0 ' aliases: git '
assert_line -n 1 ' plugins: git '
assert_line -n 2 ' completions: git '
}
@test "search: (all enabled) ruby gem bundle rake rails" {
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable'
run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails'
assert_line -n 0 ' aliases => ✓bundler ✓rails'
assert_line -n 1 ' plugins => ✓rails ✓ruby'
assert_line -n 2 ' completions => ✓bundler ✓gem ✓rake'
@test "search: @git --enable / --disable" {
set -e
run _bash-it-search '@git' --enable --no-color
run _bash-it-search '@git' --no-color
[[ "${lines[0]}" =~ '✓' ]]
run _bash-it-search '@git' --disable --no-color
run _bash-it-search '@git' --no-color
assert_line -n 0 ' aliases: git '
assert_line -n 0 ' aliases: git '
assert_line -n 2 ' completions: git '
}

View File

@ -0,0 +1,108 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../lib/helpers
load ../../lib/utilities
load ../../lib/search
cite _about _param _example _group _author _version
function local_setup {
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
# Use rsync to copy Bash-it to the temp folder
# rsync is faster than cp, since we can exclude the large ".git" folder
rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../../.. "$BASH_IT"
rm -rf "$BASH_IT"/enabled
rm -rf "$BASH_IT"/aliases/enabled
rm -rf "$BASH_IT"/completion/enabled
rm -rf "$BASH_IT"/plugins/enabled
rm -rf "$BASH_IT"/tmp/cache
mkdir -p "$BASH_IT"/enabled
mkdir -p "$BASH_IT"/aliases/enabled
mkdir -p "$BASH_IT"/completion/enabled
mkdir -p "$BASH_IT"/plugins/enabled
}
function has_match() {
$(_bash-it-array-contains-element ${@}) && echo "has" "$1"
}
function item_enabled() {
$(_bash-it-component-item-is-enabled ${@}) && echo "$1" "$2" "is enabled"
}
function item_disabled() {
$(_bash-it-component-item-is-disabled ${@}) && echo "$1" "$2" "is disabled"
}
@test "_bash-it-component-item-is-enabled() - for a disabled item" {
run item_enabled aliases svn
assert_line -n 0 ''
}
@test "_bash-it-component-item-is-enabled() - for an enabled/disabled item" {
run bash-it enable alias svn
assert_line -n 0 'svn enabled with priority 150.'
run item_enabled alias svn
assert_line -n 0 'alias svn is enabled'
run bash-it disable alias svn
assert_line -n 0 'svn disabled.'
run item_enabled alias svn
assert_line -n 0 ''
}
@test "_bash-it-component-item-is-disabled() - for a disabled item" {
run item_disabled alias svn
assert_line -n 0 'alias svn is disabled'
}
@test "_bash-it-component-item-is-disabled() - for an enabled/disabled item" {
run bash-it enable alias svn
assert_line -n 0 'svn enabled with priority 150.'
run item_disabled alias svn
assert_line -n 0 ''
run bash-it disable alias svn
assert_line -n 0 'svn disabled.'
run item_disabled alias svn
assert_line -n 0 'alias svn is disabled'
}
@test "_bash-it-array-contains-element() - when match is found, and is the first" {
declare -a fruits=(apple pear orange mandarin)
run has_match apple "${fruits[@]}"
assert_line -n 0 'has apple'
}
@test "_bash-it-array-contains-element() - when match is found, and is the last" {
declare -a fruits=(apple pear orange mandarin)
run has_match mandarin "${fruits[@]}"
assert_line -n 0 'has mandarin'
}
@test "_bash-it-array-contains-element() - when match is found, and is in the middle" {
declare -a fruits=(apple pear orange mandarin)
run has_match pear "${fruits[@]}"
assert_line -n 0 'has pear'
}
@test "_bash-it-array-contains-element() - when match is found, and it has spaces" {
declare -a fruits=(apple pear orange mandarin "yellow watermelon")
run has_match "yellow watermelon" "${fruits[@]}"
assert_line -n 0 'has yellow watermelon'
}
@test "_bash-it-array-contains-element() - when match is not found" {
declare -a fruits=(apple pear orange mandarin)
run has_match xyz "${fruits[@]}"
assert_line -n 0 ''
}

View File

@ -0,0 +1,44 @@
#!/usr/bin/env bats
#load ../test_helper
load ../../lib/helpers
load ../../lib/composure
load ../../plugins/available/go.plugin
@test 'plugins go: reverse path: single entry' {
run _split_path_reverse '/foo'
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: single entry, colon empty' {
run _split_path_reverse '/foo:'
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: single entry, colon whitespace' {
run _split_path_reverse '/foo: '
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: multiple entries' {
run _split_path_reverse '/foo:/bar'
echo "output = ${output}"
[ "$output" = "/bar /foo" ]
}
@test 'plugins go: single entry in GOPATH' {
export GOPATH="/foo"
load ../../plugins/available/go.plugin
echo "$(echo $PATH | cut -d':' -f1,2)"
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ]
}
@test 'plugins go: multiple entries in GOPATH' {
export GOPATH="/foo:/bar"
load ../../plugins/available/go.plugin
echo "$(echo $PATH | cut -d':' -f1,2)"
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
}

View File

@ -115,6 +115,8 @@ setup_repo_with_upstream() {
git add file
git stash
SCM_GIT_SHOW_STASH_INFO=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} {1}"
@ -320,6 +322,8 @@ setup_repo_with_upstream() {
echo "line2" >> file1
git add file1
SCM_GIT_SHOW_DETAILS=true
git_prompt_vars
assert_equal "$SCM_BRANCH" "${pre} S:1"
assert_equal "$SCM_STATE" " ✗"

View File

@ -39,6 +39,7 @@ SCM_GIT_CHAR='±'
SCM_GIT_DETACHED_CHAR='⌿'
SCM_GIT_AHEAD_CHAR="↑"
SCM_GIT_BEHIND_CHAR="↓"
SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR=" "
SCM_GIT_UNTRACKED_CHAR="?:"
SCM_GIT_UNSTAGED_CHAR="U:"
SCM_GIT_STAGED_CHAR="S:"
@ -86,6 +87,7 @@ function scm {
elif [[ -d .hg ]] && which hg &> /dev/null; then SCM=$SCM_HG
elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG
elif [[ -d .svn ]] && which svn &> /dev/null; then SCM=$SCM_SVN
elif which svn &> /dev/null && [[ -n "$(svn info --show-item wc-root 2>/dev/null)" ]]; then SCM=$SCM_SVN
else SCM=$SCM_NONE
fi
}
@ -139,9 +141,9 @@ function scm_prompt_info_common {
fi
# TODO: consider adding minimal status information for hg and svn
[[ ${SCM} == ${SCM_P4} ]] && p4_prompt_info && return
[[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return
[[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return
{ [[ ${SCM} == ${SCM_P4} ]] && p4_prompt_info && return; } || true
{ [[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return; } || true
{ [[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return; } || true
}
function git_prompt_minimal_info {
@ -179,8 +181,8 @@ function git_prompt_vars {
fi
IFS=$'\t' read -r commits_behind commits_ahead <<< "$(_git-upstream-behind-ahead)"
[[ "${commits_ahead}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_AHEAD_CHAR}${commits_ahead}"
[[ "${commits_behind}" -gt 0 ]] && SCM_BRANCH+=" ${SCM_GIT_BEHIND_CHAR}${commits_behind}"
[[ "${commits_ahead}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_AHEAD_CHAR}${commits_ahead}"
[[ "${commits_behind}" -gt 0 ]] && SCM_BRANCH+="${SCM_GIT_AHEAD_BEHIND_PREFIX_CHAR}${SCM_GIT_BEHIND_CHAR}${commits_behind}"
if [[ "${SCM_GIT_SHOW_STASH_INFO}" = "true" ]]; then
local stash_count
@ -231,7 +233,7 @@ function p4_prompt_vars {
}
function svn_prompt_vars {
if [[ -n $(svn status 2> /dev/null) ]]; then
if [[ -n $(svn status |head -c1 2> /dev/null) ]]; then
SCM_DIRTY=1
SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
else
@ -240,8 +242,8 @@ function svn_prompt_vars {
fi
SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX}
SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
SCM_BRANCH=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
SCM_CHANGE=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' )
SCM_BRANCH=$(svn info --show-item=url 2> /dev/null | awk -F/ '{ for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return
SCM_CHANGE=$(svn info --show-item=revision 2> /dev/null)
}
# this functions returns absolute location of .hg directory if one exists
@ -336,6 +338,10 @@ function ruby_version_prompt {
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
}
function k8s_context_prompt {
echo -e "$(kubectl config current-context 2> /dev/null)"
}
function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=`basename "$VIRTUAL_ENV"`
@ -493,3 +499,8 @@ function safe_append_prompt_command {
fi
fi
}
function _save-and-reload-history() {
local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
}

View File

@ -0,0 +1,96 @@
#!/usr/bin/env bash
# https://github.com/koalaman/shellcheck/wiki/Sc2154
# shellcheck disable=SC2154
function _user-prompt() {
local -r user='\\u'
if [[ "${EUID}" -eq 0 ]]; then
# Privileged users:
local -r user_color="${bold_red}"
else
# Standard users:
local -r user_color="${bold_green}"
fi
# Print the current user's name (colored according to their current EUID):
echo -e "${user_color}${user}${normal}"
}
function _host-prompt() {
local -r host='\\h'
# Check whether or not $SSH_TTY is set:
if [[ -z "${SSH_TTY}" ]]; then
# For local hosts, set the host's prompt color to blue:
local -r host_color="${bold_blue}"
else
# For remote hosts, set the host's prompt color to red:
local -r host_color="${bold_red}"
fi
# Print the current hostname (colored according to $SSH_TTY's status):
echo -e "${host_color}${host}${normal}"
}
function _user-at-host-prompt() {
# Concatenate the user and host prompts into: user@host:
echo -e "$(_user-prompt)${bold_white}@$(_host-prompt)"
}
function _exit-status-prompt() {
local -r prompt_string="${1}"
local -r exit_status="${2}"
# Check the exit status of the last command captured by $exit_status:
if [[ "${exit_status}" -eq 0 ]]; then
# For commands that return an exit status of zero, set the exit status's
# notifier to green:
local -r exit_status_color="${bold_green}"
else
# For commands that return a non-zero exit status, set the exit status's
# notifier to red:
local -r exit_status_color="${bold_red}"
fi
echo -ne "${exit_status_color}"
if [[ "${prompt_string}" -eq 1 ]]; then
# $PS1:
echo -e " +${normal} "
elif [[ "${prompt_string}" -eq 2 ]]; then
# $PS2:
echo -e " |${normal} "
else
# Default:
echo -e " ?${normal} "
fi
}
function _ps1() {
local -r time='\\t'
echo -ne "${bold_white}${time} "
echo -ne "$(_user-at-host-prompt)"
echo -e "${bold_white}:${normal}${PWD}"
echo -e "$(_exit-status-prompt 1 "${exit_status}")"
}
function _ps2() {
echo -e "$(_exit-status-prompt 2 "${exit_status}")"
}
function prompt_command() {
# Capture the exit status of the last command:
local -r exit_status="${?}"
# Build the $PS1 prompt:
PS1="$(_ps1)"
# Build the $PS2 prompt:
PS2="$(_ps2)"
}
safe_append_prompt_command prompt_command
# vim: sw=2 ts=2 et:

View File

@ -72,7 +72,7 @@ function _git-hide-status {
function _git-status {
local git_status_flags=
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno'
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true
git status --porcelain ${git_status_flags} 2> /dev/null
}
@ -101,8 +101,9 @@ function _git-status-counts {
}
function _git-remote-info {
[[ "$(_git-upstream)" == "" ]] && return
[[ "$(_git-upstream)" == "" ]] && return || true
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true || true
local same_branch_name=
[[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true
if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "$(_git-num-remotes)" -ge 2 ]]) ||

View File

@ -0,0 +1,81 @@
#!/usr/bin/env bash
# Emoji-based theme to display source control management and
# virtual environment info beside the ordinary bash prompt.
# Theme inspired by:
# - Naming your Terminal tabs in OSX Lion - http://thelucid.com/2012/01/04/naming-your-terminal-tabs-in-osx-lion/
# - Bash_it sexy theme
# inspired by previous bash_it theme : cupcake
# Demo:
# ┌ⓔ virtualenv 🐲🤘user @ 💻 host in 🗂️ directory on 🌵 branch {1} ↑1 ↓1 +1 •1 ⌀1 ✗
# └❯ cd .bash-it/themes/cupcake
# virtualenv prompts
VIRTUALENV_CHAR="ⓔ "
VIRTUALENV_THEME_PROMPT_PREFIX=""
VIRTUALENV_THEME_PROMPT_SUFFIX=""
# SCM prompts
SCM_NONE_CHAR=""
SCM_GIT_CHAR="[±] "
SCM_GIT_BEHIND_CHAR="${red}${normal}"
SCM_GIT_AHEAD_CHAR="${bold_green}${normal}"
SCM_GIT_UNTRACKED_CHAR="⌀"
SCM_GIT_UNSTAGED_CHAR="${bold_yellow}${normal}"
SCM_GIT_STAGED_CHAR="${bold_green}+${normal}"
SCM_THEME_PROMPT_DIRTY=""
SCM_THEME_PROMPT_CLEAN=""
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
# Git status prompts
GIT_THEME_PROMPT_DIRTY=" ${red}${normal}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
GIT_THEME_PROMPT_PREFIX=""
GIT_THEME_PROMPT_SUFFIX=""
# ICONS =======================================================================
icon_start="┌"
icon_user="🤘-🐧"
icon_host="@ 💻 "
icon_directory=" - 🧱 "
icon_branch="🌵"
icon_end="└🤘-> "
# extra spaces ensure legiblity in prompt
# FUNCTIONS ===================================================================
# Display virtual environment info
function virtualenv_prompt {
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=`basename "$VIRTUAL_ENV"`
echo -e "$VIRTUALENV_CHAR$virtualenv "
fi
}
# Rename tab
function tabname {
printf "\e]1;$1\a"
}
# Rename window
function winname {
printf "\e]2;$1\a"
}
# PROMPT OUTPUT ===============================================================
# Displays the current prompt
function prompt_command() {
PS1="\n${icon_start}$(virtualenv_prompt)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} \")${white}$(scm_prompt_info)${normal}\n${icon_end}"
PS2="${icon_end}"
}
# Runs prompt (this bypasses bash_it $PROMPT setting)
safe_append_prompt_command prompt_command

View File

@ -0,0 +1,63 @@
# Modified version of the original modern theme in bash-it
# Removes the battery charge and adds the current time
SCM_THEME_PROMPT_PREFIX=""
SCM_THEME_PROMPT_SUFFIX=""
SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
case $TERM in
xterm*)
TITLEBAR="\[\033]0;\w\007\]"
;;
*)
TITLEBAR=""
;;
esac
PS3=">> "
is_vim_shell() {
if [ ! -z "$VIMRUNTIME" ]
then
echo "[${cyan}vim shell${normal}]"
fi
}
modern_scm_prompt() {
CHAR=$(scm_char)
if [ $CHAR = $SCM_NONE_CHAR ]
then
return
else
echo "[$(scm_char)][$(scm_prompt_info)]"
fi
}
modern_current_time_prompt() {
echo "[$(date '+%l:%M%p')]"
}
prompt() {
if [ $? -ne 0 ]
then
# Yes, the indenting on these is weird, but it has to be like
# this otherwise it won't display properly.
PS1="${TITLEBAR}${bold_red}┌─${reset_color}$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell)
${bold_red}└─▪${normal} "
else
PS1="${TITLEBAR}┌─$(modern_scm_prompt)$(modern_current_time_prompt)[${cyan}\W${normal}]$(is_vim_shell)
└─▪ "
fi
}
PS2="└─▪ "
safe_append_prompt_command prompt

View File

@ -0,0 +1,37 @@
# git branch parser
function parse_git_branch() {
echo -e "\033[1;34m$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\033[0m"
}
function parse_git_branch_no_color() {
echo -e "$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')"
}
function prompt() {
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
local force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
local color_prompt=yes
else
local color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]$(parse_git_branch) $\[\e[0m\] "
else
PS1='┌──[\u@\h]─[\w]\n└──╼ $(parse_git_branch_no_color) $ '
fi
}
safe_append_prompt_command prompt

View File

@ -14,6 +14,7 @@ A colorful theme, where shows a lot information about your shell session.
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/available/battery.plugin.bash](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Kubernetes environment
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (rvm and rbenv are supported) in use
* Last command exit code (only shown when the exit code is greater than 0)
@ -48,11 +49,12 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
* `cwd` - Current working directory including full folder hierarchy (c.f. `wd`)
* `hostname` - Host name of machine
* `in_vim` - Show identifier if running in `:terminal` from vim
* `k8s_context` - Show current kubernetes context
* `last_status` - Exit status of last run command
* `python_venv` - Python virtual environment information (`virtualenv`, `venv`
and `conda` supported)
* `ruby` - Current ruby version if using `rvm`
* `scm` - Version control information, `git`
* `scm` - Version control information, `git`
* `user_info` - Current user
* `wd` - Working directory, like `cwd` but doesn't show the full folder
hierarchy, only the directory you're currently in.

View File

@ -33,6 +33,9 @@ RBENV_THEME_PROMPT_SUFFIX=""
RUBY_THEME_PROMPT_COLOR=161
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="r "}
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "}
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=26
AWS_PROFILE_CHAR="${POWERLINE_AWS_PROFILE_CHAR:=aws }"
AWS_PROFILE_PROMPT_COLOR=208

View File

@ -12,6 +12,7 @@ A colorful theme, where shows a lot information about your shell session.
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/available/battery.plugin.bash](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Kubernetes environment
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (rvm and rbenv are supported) in use
* Last command exit code (only shown when the exit code is greater than 0)
@ -46,11 +47,12 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
* `cwd` - Current working directory including full folder hierarchy (c.f. `wd`)
* `hostname` - Host name of machine
* `in_vim` - Show identifier if running in `:terminal` from vim
* `k8s_context` - Show current kubernetes context
* `last_status` - Exit status of last run command
* `python_venv` - Python virtual environment information (`virtualenv`, `venv`
and `conda` supported)
* `ruby` - Current ruby version if using `rvm`
* `scm` - Version control information, `git`
* `scm` - Version control information, `git`
* `user_info` - Current user
* `wd` - Working directory, like `cwd` but doesn't show the full folder
hierarchy, only the directory you're currently in.

View File

@ -14,6 +14,8 @@ function __powerline_prompt_command {
LEFT_PROMPT=""
_save-and-reload-history "${HISTORY_AUTOSAVE:-0}"
## left prompt ##
for segment in $POWERLINE_PROMPT; do
local info="$(__powerline_${segment}_prompt)"

View File

@ -28,6 +28,9 @@ RBENV_THEME_PROMPT_SUFFIX=""
RUBY_THEME_PROMPT_COLOR=161
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="💎 "}
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "}
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=26
AWS_PROFILE_CHAR="${POWERLINE_AWS_PROFILE_CHAR:=aws }"
AWS_PROFILE_PROMPT_COLOR=208
@ -51,5 +54,4 @@ HOST_THEME_PROMPT_COLOR=0
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
safe_append_prompt_command __powerline_prompt_command
safe_append_prompt_command __powerline_prompt_command

View File

@ -16,6 +16,7 @@ A colorful theme, where shows a lot information about your shell session.
* An indicator when the current shell is inside the Vim editor
* Battery charging status (depends on the [../../plugins/available/battery.plugin.bash](battery plugin))
* SCM Repository status (e.g. Git, SVN)
* The current Kubernetes environment
* The current Python environment (Virtualenv, venv, and Conda are supported) in use
* The current Ruby environment (rvm and rbenv are supported) in use
* Last command exit code (only shown when the exit code is greater than 0)
@ -50,11 +51,12 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o
* `cwd` - Current working directory including full folder hierarchy (c.f. `wd`)
* `hostname` - Host name of machine
* `in_vim` - Show identifier if running in `:terminal` from vim
* `k8s_context` - Show current kubernetes context
* `last_status` - Exit status of last run command
* `python_venv` - Python virtual environment information (`virtualenv`, `venv`
and `conda` supported)
* `ruby` - Current ruby version if using `rvm`
* `scm` - Version control information, `git`
* `scm` - Version control information, `git`
* `user_info` - Current user
* `wd` - Working directory, like `cwd` but doesn't show the full folder
hierarchy, only the directory you're currently in.

View File

@ -52,6 +52,16 @@ function __powerline_ruby_prompt {
[[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}"
}
function __powerline_k8s_context_prompt {
local kubernetes_context=""
if _command_exists kubectl; then
kubernetes_context="$(k8s_context_prompt)"
fi
[[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}"
}
function __powerline_python_venv_prompt {
set +u
local python_venv=""
@ -88,8 +98,10 @@ function __powerline_scm_prompt {
scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
elif [[ "${SCM_HG_CHAR}" == "${SCM_CHAR}" ]]; then
scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
elif [[ "${SCM_SVN_CHAR}" == "${SCM_CHAR}" ]]; then
scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}"
fi
echo "${scm_prompt}${scm}|${color}"
echo "$(eval "echo ${scm_prompt}")${scm}|${color}"
fi
}

View File

@ -31,6 +31,9 @@ RBENV_THEME_PROMPT_SUFFIX=""
RUBY_THEME_PROMPT_COLOR=161
RUBY_CHAR=${POWERLINE_RUBY_CHAR:="r "}
KUBERNETES_CONTEXT_THEME_CHAR=${POWERLINE_KUBERNETES_CONTEXT_CHAR:="⎈ "}
KUBERNETES_CONTEXT_THEME_PROMPT_COLOR=26
AWS_PROFILE_CHAR="${POWERLINE_AWS_PROFILE_CHAR:=aws }"
AWS_PROFILE_PROMPT_COLOR=208
@ -54,4 +57,6 @@ HOST_THEME_PROMPT_COLOR=0
POWERLINE_PROMPT=${POWERLINE_PROMPT:="user_info scm python_venv ruby cwd"}
HISTORY_AUTOSAVE=${HISTORY_AUTOSAVE:-0}
safe_append_prompt_command __powerline_prompt_command