Skip to content

Commit

Permalink
Merge pull request Bash-it#2283 from seefood/ira/cleanup5
Browse files Browse the repository at this point in the history
  • Loading branch information
seefood authored Jan 29, 2025
2 parents c4baa6e + 6261b14 commit 719827f
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 172 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
name: Check .bash files against bash-it requirements
entry: ./hooks/dot-bash.sh
language: system
files: "\\.(bash)$"
files: "\\.bash$"
types: [file]
- id: clean-files-txt
name: Check that clean_files.txt is sorted alphabetically.
Expand Down
70 changes: 1 addition & 69 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ aliases/
docs/
hooks/
lib/
plugins/
scripts/
test/

Expand Down Expand Up @@ -87,75 +88,6 @@ completion/available/vuejs.completion.bash
completion/available/wpscan.completion.bash
completion/available/yarn.completion.bash

# plugins
#
plugins/available/alias-completion.plugin.bash
plugins/available/autojump.plugin.bash
plugins/available/base.plugin.bash
plugins/available/basher.plugin.bash
plugins/available/battery.plugin.bash
plugins/available/blesh.plugin.bash
plugins/available/browser.plugin.bash
plugins/available/cmd-returned-notify.plugin.bash
plugins/available/colors.plugin.bash
plugins/available/direnv.plugin.bash
plugins/available/dirs.plugin.bash
plugins/available/docker-compose.plugin.bash
plugins/available/docker-machine.plugin.bash
plugins/available/fasd.plugin.bash
plugins/available/fzf.plugin.bash
plugins/available/gif.plugin.bash
plugins/available/git-subrepo.plugin.bash
plugins/available/git.plugin.bash
plugins/available/gitstatus.plugin.bash
plugins/available/go.plugin.bash
plugins/available/goenv.plugin.bash
plugins/available/gradle.plugin.bash
plugins/available/hg.plugin.bash
plugins/available/history-eternal.plugin.bash
plugins/available/history-search.plugin.bash
plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash
plugins/available/java.plugin.bash
plugins/available/javascript.plugin.bash
plugins/available/jekyll.plugin.bash
plugins/available/jenv.plugin.bash
plugins/available/jgitflow.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/latex.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/man.plugin.bash
plugins/available/nginx.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/osx-timemachine.plugin.bash
plugins/available/osx.plugin.bash
plugins/available/pack.plugin.bash
plugins/available/percol.plugin.bash
plugins/available/plenv.plugin.bash
plugins/available/postgres.plugin.bash
plugins/available/projects.plugin.bash
plugins/available/proxy.plugin.bash
plugins/available/pyenv.plugin.bash
plugins/available/python.plugin.bash
plugins/available/rails.plugin.bash
plugins/available/rbenv.plugin.bash
plugins/available/ruby.plugin.bash
plugins/available/rvm.plugin.bash
plugins/available/ssh.plugin.bash
plugins/available/sshagent.plugin.bash
plugins/available/subversion.plugin.bash
plugins/available/sudo.plugin.bash
plugins/available/textmate.plugin.bash
plugins/available/thefuck.plugin.bash
plugins/available/todo.plugin.bash
plugins/available/url.plugin.bash
plugins/available/virtualenv.plugin.bash
plugins/available/xterm.plugin.bash
plugins/available/z_autoenv.plugin.bash
plugins/available/zoxide.plugin.bash

# themes
#
themes/90210
Expand Down
1 change: 1 addition & 0 deletions plugins/available/alias-completion.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
# stub for renamed file

_enable-completion aliases && _disable-plugin alias-completion
# shellcheck disable=SC1091
source "${BASH_IT?}/completion/available/aliases.completion.bash"
1 change: 1 addition & 0 deletions plugins/available/autojump.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ about-plugin 'Autojump configuration, see https://github.com/wting/autojump for
# Feel free to provide a PR to support other install locations
# shellcheck disable=SC1090
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then
# shellcheck disable=SC1091
source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh"
elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then
source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)"
Expand Down
172 changes: 90 additions & 82 deletions plugins/available/aws.plugin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,117 @@ AWS_CONFIG_FILE="${AWS_CONFIG_FILE:-$HOME/.aws/config}"
AWS_SHARED_CREDENTIALS_FILE="${AWS_SHARED_CREDENTIALS_FILE:-$HOME/.aws/credentials}"

function awskeys {
about 'helper function for AWS credentials file'
group 'aws'

if [[ ! -f "${AWS_SHARED_CREDENTIALS_FILE}" ]]; then
echo "AWS credentials file not found"
return 1
fi

if [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then
__awskeys_list "$2"
elif [[ $# -eq 1 ]] && [[ "$1" = "unset" ]]; then
__awskeys_unset "$2"
elif [[ $# -eq 2 ]] && [[ "$1" = "show" ]]; then
__awskeys_show "$2"
elif [[ $# -eq 2 ]] && [[ "$1" = "export" ]]; then
__awskeys_export "$2"
else
__awskeys_help
fi
about 'helper function for AWS credentials file'
group 'aws'

if [[ ! -f "${AWS_SHARED_CREDENTIALS_FILE}" ]]; then
echo "AWS credentials file not found"
return 1
fi

if [[ $# -eq 1 ]] && [[ "$1" = "list" ]]; then
__awskeys_list "$2"
elif [[ $# -eq 1 ]] && [[ "$1" = "unset" ]]; then
__awskeys_unset "$2"
elif [[ $# -eq 2 ]] && [[ "$1" = "show" ]]; then
__awskeys_show "$2"
elif [[ $# -eq 2 ]] && [[ "$1" = "export" ]]; then
__awskeys_export "$2"
else
__awskeys_help
fi
}

function __awskeys_help {
echo -e "Usage: awskeys [COMMAND] [profile]\n"
echo -e "Helper to AWS credentials file.\n"
echo -e "Commands:\n"
echo " help Show this help message"
echo " list List available AWS credentials profiles"
echo " show Show the AWS keys associated to a credentials profile"
echo " export Export an AWS credentials profile keys as environment variables"
echo " unset Unset the AWS keys variables from the environment"
echo -e "Usage: awskeys [COMMAND] [profile]\n"
echo -e "Helper to AWS credentials file.\n"
echo -e "Commands:\n"
echo " help Show this help message"
echo " list List available AWS credentials profiles"
echo " show Show the AWS keys associated to a credentials profile"
echo " export Export an AWS credentials profile keys as environment variables"
echo " unset Unset the AWS keys variables from the environment"
}

function __awskeys_get {
local ln=$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)
if [[ -n "${ln}" ]]; then
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 2 -e "aws_access_key_id" -e "aws_secret_access_key"
tail -n +${ln} "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 1 "aws_session_token"
fi
local ln
ln="$(grep -n "\[ *$1 *\]" "${AWS_SHARED_CREDENTIALS_FILE}" | cut -d ":" -f 1)"
if [[ -n "${ln}" ]]; then
tail -n +"${ln}" "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 2 -e "aws_access_key_id" -e "aws_secret_access_key"
tail -n +"${ln}" "${AWS_SHARED_CREDENTIALS_FILE}" | grep -F -m 1 "aws_session_token"
fi
}

function __awskeys_list {
local credentials_list="$((grep -E '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"; grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g") | sort | uniq)"
if [[ -n $"{credentials_list}" ]]; then
echo -e "Available credentials profiles:\n"
for profile in ${credentials_list}; do
echo " $(echo ${profile} | tr -d "[]")"
done
echo
else
echo "No profiles found in credentials file"
fi
local credentials_list
credentials_list="$(
grep -E '^\[ *[a-zA-Z0-9_-]+ *\]$' "${AWS_SHARED_CREDENTIALS_FILE}"
grep "\[profile" "${AWS_CONFIG_FILE}" | sed "s|\[profile |\[|g" | sort -u
)"
if [[ -n "${credentials_list}" ]]; then
echo -e "Available credentials profiles:\n"
for profile in ${credentials_list}; do
echo " $(echo "${profile}" | tr -d "[]")"
done
echo
else
echo "No profiles found in credentials file"
fi
}

function __awskeys_show {
local p_keys="$(__awskeys_get $1)"
if [[ -n "${p_keys}" ]]; then
echo "${p_keys}"
else
echo "Profile $1 not found in credentials file"
fi
local p_keys
IFS=" " read -r -a p_keys <<< "$(__awskeys_get "$1")"
if [[ -n "${p_keys[*]}" ]]; then
echo "${p_keys[@]}"
else
echo "Profile $1 not found in credentials file"
fi
}

function __awskeys_export {
if [[ $(__awskeys_list) == *"$1"* ]]; then
local p_keys=( $(__awskeys_get $1 | tr -d " ") )
if [[ -n "${p_keys}" ]]; then
for p_key in ${p_keys[@]}; do
local key="${p_key%=*}"
export "$(echo ${key} | tr [:lower:] [:upper:])=${p_key#*=}"
done
fi
export AWS_PROFILE="$1"
else
echo "Profile $1 not found in credentials file"
fi
if [[ $(__awskeys_list) == *"$1"* ]]; then
local p_keys
IFS=" " read -r -a p_keys <<< "$(__awskeys_get "$1" | tr -d " ")"
if [[ -n "${p_keys[*]}" ]]; then
for p_key in "${p_keys[@]}"; do
local key="${p_key%=*}"
export "$(echo "${key}" | tr "[:lower:]" "[:upper:]")=${p_key#*=}"
done
fi
export AWS_PROFILE="$1"
else
echo "Profile $1 not found in credentials file"
fi
}

function __awskeys_unset {
unset AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
unset AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN
}

function __awskeys_comp {
local cur prev opts prevprev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="help list show export unset"
case "${prev}" in
help|list|unset)
return 0
;;
show|export)
local profile_list="$(__awskeys_list | grep " ")"
COMPREPLY=( $(compgen -W "${profile_list}" -- ${cur}) )
return 0
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"

opts="help list show export unset"

case "${prev}" in
help | list | unset)
return 0
;;
show | export)
local profile_list
profile_list="$(__awskeys_list | grep " ")"
mapfile -t COMPREPLY < <(compgen -W "${profile_list}" -- "${cur}")
return 0
;;
esac

mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}")

return 0
}

complete -F __awskeys_comp awskeys
3 changes: 2 additions & 1 deletion plugins/available/boot2docker.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Helpers to get Docker setup correctly for boot2docker'

# Note, this might need to be different if you have an older version
# of boot2docker, or its configured for a different IP
if [[ "$OSTYPE" == 'darwin'* ]]; then
export DOCKER_HOST="tcp://192.168.59.103:2376"
export DOCKER_CERT_PATH="~/.boot2docker/certs/boot2docker-vm"
export DOCKER_CERT_PATH="${HOME}/.boot2docker/certs/boot2docker-vm"
export DOCKER_TLS_VERIFY=1
fi
2 changes: 2 additions & 0 deletions plugins/available/chruby-auto.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash
# shellcheck disable=SC1091
cite about-plugin
about-plugin 'load chruby + auto-switching (from /usr/local/share/chruby)'

Expand Down
2 changes: 2 additions & 0 deletions plugins/available/chruby.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# shellcheck shell=bash
# shellcheck disable=SC1091
cite about-plugin
about-plugin 'load chruby (from /usr/local/share/chruby)'

Expand Down
5 changes: 4 additions & 1 deletion plugins/available/cht-sh.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# shellcheck shell=bash
cite about-plugin
# shellcheck disable=SC2016
about-plugin 'Simplify `curl cht.sh/<query>` to `cht.sh <query>`'

# Play nicely if user already installed cht.sh cli tool
Expand All @@ -15,7 +17,8 @@ if ! _command_exists cht.sh; then
group 'cht-sh'

# Separate arguments with '/', preserving spaces within them
local query=$(
local query
query=$(
IFS=/
echo "$*"
)
Expand Down
Loading

0 comments on commit 719827f

Please sign in to comment.