Merge branch 'master' into fix-go-pathmunge

pull/1284/head
cornfeedhobo 2019-05-12 12:50:39 -05:00
commit c94e540668
No known key found for this signature in database
GPG Key ID: 724357093F994B26
35 changed files with 3770 additions and 1340 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

@ -9,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*)
@ -20,12 +19,18 @@ 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 '

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'
@ -55,6 +56,7 @@ 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 +69,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 +77,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

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

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

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

@ -42,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:-}
@ -50,6 +50,7 @@ bash-it ()
typeset component=${1:-}
shift
typeset func
case $verb in
show)
func=_bash-it-$component;;
@ -256,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*)
@ -267,7 +268,7 @@ _bash-it-reload() {
;;
esac
cd - &> /dev/null || return
popd &> /dev/null || return
}
_bash-it-describe ()
@ -387,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
@ -449,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
@ -482,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

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

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

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

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

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

@ -99,7 +99,7 @@ function __powerline_scm_prompt {
elif [[ "${SCM_HG_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
}