pull/1948/head
John D Pell 2021-10-22 11:15:41 -07:00
parent 8bcc44fa13
commit 70f3b56dcc
63 changed files with 1794 additions and 1450 deletions

View File

@ -194,11 +194,13 @@ case $OSTYPE in
esac
# functions
function gdv() {
function gdv()
{
git diff --ignore-all-space "$@" | vim -R -
}
function get_default_branch() {
function get_default_branch()
{
if git branch | grep -q main; then
echo main
else

View File

@ -11,5 +11,11 @@ alias vimh='vim -c ":h | only"'
# open vim in new tab is taken from
# http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek
_command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; }
_command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; }
_command_exists mvim && function mvimt
{
command mvim --remote-tab-silent "$@" || command mvim "$@"
}
_command_exists gvim && function gvimt
{
command gvim --remote-tab-silent "$@" || command gvim "$@"
}

View File

@ -2,7 +2,8 @@
cite "about-completion"
about-completion "composer completion"
function __composer_completion() {
function __composer_completion()
{
local cur coms opts com words
COMPREPLY=()
_get_comp_words_by_ref -n : cur words

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
__dart_completion() {
__dart_completion()
{
# shellcheck disable=SC2155
local prev=$(_get_pword)
# shellcheck disable=SC2155

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
function __dmidecode_completion() {
function __dmidecode_completion()
{
# shellcheck disable=SC2155
local prev=$(_get_pword)
# shellcheck disable=SC2155

View File

@ -2,7 +2,8 @@
cite "about-completion"
about-completion "gem completion"
__gem_completion() {
__gem_completion()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD - 1]}
case $prev in

View File

@ -33,13 +33,15 @@ stat -c %Y /dev/null > /dev/null 2>&1 && _KAC_STAT_COMMAND="stat -c %Y" || _KAC_
# returns 0 iff the file whose path is given as 1st argument
# exists and has last been modified in the last $2 seconds
# returns 1 otherwise
_KAC_is_file_newer_than() {
_KAC_is_file_newer_than()
{
[ -f "$1" ] || return 1
[ $(($(date +%s) - $($_KAC_STAT_COMMAND "$1"))) -gt "$2" ] && return 1 || return 0
}
# helper function for _KAC_get_and_regen_cache, see doc below
_KAC_regen_cache() {
_KAC_regen_cache()
{
local CACHE_NAME=$1
local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
# shellcheck disable=SC2155
@ -54,12 +56,14 @@ _KAC_regen_cache() {
}
# cached files can't have spaces in their names
_KAC_get_cache_name_from_command() {
_KAC_get_cache_name_from_command()
{
echo "${@/ /_SPACE_}"
}
# the reverse operation from the function above
_KAC_get_command_from_cache_name() {
_KAC_get_command_from_cache_name()
{
echo "${@/_SPACE_/ }"
}
@ -68,7 +72,8 @@ _KAC_get_command_from_cache_name() {
# in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable
# for obvious reason, do NOT call that in a sub-shell (in particular, no piping)
# shellcheck disable=SC2155
_KAC_get_and_regen_cache() {
_KAC_get_and_regen_cache()
{
# the cache name can't have space in it
local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@")
local REGEN_CMD="_KAC_regen_cache $CACHE_NAME $*"
@ -83,15 +88,16 @@ _KAC_get_and_regen_cache() {
# performs two things: first, deletes all obsolete temp files
# then refreshes stale caches that haven't been called in a long time
_KAC_clean_cache() {
_KAC_clean_cache()
{
local FILE CMD
# delete all obsolete temp files, could be lingering there for any kind of crash in the caching process
for FILE in "$_KAC_CACHE_TMP_DIR"/*; do
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" || rm -f "$FILE"
done
# refresh really stale caches
find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' \
| while read -r FILE; do
find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' |
while read -r FILE; do
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" && continue
# first let's get the original command
CMD=$(_KAC_get_command_from_cache_name "$(basename "$FILE")")
@ -109,14 +115,16 @@ _KAC_clean_cache() {
#####################################
# returns all the possible knife sub-commands
_KAC_knife_commands() {
_KAC_knife_commands()
{
knife --help | grep -E "^knife" | sed -E 's/ \(options\)//g'
}
# rebuilds the knife base command currently being completed, and assigns it to $_KAC_CURRENT_COMMAND
# additionnally, returns 1 iff the current base command is not complete, 0 otherwise
# also sets $_KAC_CURRENT_COMMAND_NB_WORDS if the base command is complete
_KAC_get_current_base_command() {
_KAC_get_current_base_command()
{
local PREVIOUS="knife"
local I=1
local CURRENT
@ -136,7 +144,8 @@ _KAC_get_current_base_command() {
# (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...)
# assumes the current base command is complete
# shellcheck disable=SC2155
_KAC_get_current_arg_position() {
_KAC_get_current_arg_position()
{
local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1))
local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH")
local CURRENT_ARG
@ -150,7 +159,8 @@ _KAC_get_current_arg_position() {
}
# the actual auto-complete function
_knife() {
_knife()
{
_KAC_get_and_regen_cache _KAC_knife_commands
local RAW_LIST ITEM REGEN_CMD ARG_POSITION
# shellcheck disable=SC2034

View File

@ -2,7 +2,8 @@
_command_exists laravel || return
function __laravel_completion() {
function __laravel_completion()
{
local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new')
local _opt_
COMPREPLY=()

View File

@ -2,7 +2,8 @@
cite "about-completion"
about-completion "lerna(javascript project manager tool) completion"
function __lerna_completion() {
function __lerna_completion()
{
local cur compls
# The currently-being-completed word.

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
__ngrok_completion() {
__ngrok_completion()
{
# shellcheck disable=SC2155
local prev=$(_get_pword)
# shellcheck disable=SC2155

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
function __notify-send_completions() {
function __notify-send_completions()
{
# shellcheck disable=SC2155
local curr=$(_get_cword)
# shellcheck disable=SC2155

View File

@ -8,7 +8,8 @@
# So that pip is in the system's path.
_command_exists pip || return
function __bash_it_complete_pip() {
function __bash_it_complete_pip()
{
if _command_exists _pip_completion; then
complete -o default -F _pip_completion pip
_pip_completion "$@"

View File

@ -8,7 +8,8 @@
# So that pip3 is in the system's path.
_command_exists pip3 || return
function __bash_it_complete_pip3() {
function __bash_it_complete_pip3()
{
if _command_exists _pip_completion; then
complete -o default -F _pip_completion pip3
_pip_completion "$@"

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
function _sdkman_complete() {
function _sdkman_complete()
{
local CANDIDATES
local CANDIDATE_VERSIONS
local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}"
@ -48,13 +49,15 @@ function _sdkman_complete() {
return 0
}
function _sdkman_candidate_local_versions() {
function _sdkman_candidate_local_versions()
{
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1")
}
function _sdkman_candidate_all_versions() {
function _sdkman_candidate_all_versions()
{
candidate="$1"
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate")
@ -77,7 +80,8 @@ function _sdkman_candidate_all_versions() {
}
function __sdkman_cleanup_local_versions() {
function __sdkman_cleanup_local_versions()
{
__sdkman_build_version_csv "$1" | tr ',' ' '

View File

@ -1,6 +1,7 @@
# shellcheck shell=bash
__vuejs_completion() {
__vuejs_completion()
{
# shellcheck disable=SC2155
local prev=$(_get_pword)
# shellcheck disable=SC2155

View File

@ -2,7 +2,8 @@
_command_exists wpscan || return
function __wpscan_completion() {
function __wpscan_completion()
{
local _opt_
local OPTS=('--help' '--hh' '--version' '--url' '--ignore-main-redirect' '--verbose' '--output' '--format' '--detection-mode' '--scope' '--headers' '--user-agent' '--vhost' '--random-user-agent' '--user-agents-list' '--http-auth' '--max-threads' '--throttle' '--request-timeout' '--connect-timeout' '--disable-tlc-checks' '--proxy' '--proxy-auth' '--cookie-string' '--cookie-jar' '--cache-ttl' '--clear-cache' '--server' '--cache-dir' '--update' '--no-update' '--wp-content-dir' '--wp-plugins-dir' '--wp-version-detection' '--main-theme-detection' '--enumerate' '--exclude-content-based' '--plugins-list' '--plugins-detection' '--plugins-version-all' '--plugins-version-detection' '--themes-list' '--themes-detection' '--themes-version-all' '--themes-version-detection' '--timthumbs-list' '--timthumbs-detection' '--config-backups-list' '--config-backups-detection' '--db-exports-list' '--db-exports-detection' '--medias-detection' '--users-list' '--users-detection' '--passwords' '--usernames' '--multicall-max-passwords' '--password-attack' '--stealthy')
COMPREPLY=()

View File

@ -7,7 +7,8 @@ if [ "$file" != "clean_files.txt" ]; then
exit 1
fi
function compare_lines() {
function compare_lines()
{
prev=""
while read -r line; do
# Skip unimportant lines

View File

@ -2,7 +2,8 @@
# bash-it installer
# Show how to use this installer
function _bash-it_show_usage() {
function _bash-it_show_usage()
{
echo -e "\n$0 : Install bash-it"
echo -e "Usage:\n$0 [arguments] \n"
echo "Arguments:"
@ -16,7 +17,8 @@ function _bash-it_show_usage() {
}
# enable a thing
function _bash-it_load_one() {
function _bash-it_load_one()
{
file_type=$1
file_to_enable=$2
mkdir -p "$BASH_IT/${file_type}/enabled"
@ -30,7 +32,8 @@ function _bash-it_load_one() {
}
# Interactively enable several things
function _bash-it_load_some() {
function _bash-it_load_some()
{
file_type=$1
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
enable_func="_enable-$single_type"
@ -57,27 +60,31 @@ function _bash-it_load_some() {
}
# Back up existing profile
function _bash-it_backup() {
test -w "$HOME/$CONFIG_FILE" \
&& cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" \
&& echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
function _bash-it_backup()
{
test -w "$HOME/$CONFIG_FILE" &&
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
}
# Back up existing profile and create new one for bash-it
function _bash-it_backup_new() {
function _bash-it_backup_new()
{
_bash-it_backup
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
}
# Back up existing profile and append bash-it templates at the end
function _bash-it_backup_append() {
function _bash-it_backup_append()
{
_bash-it_backup
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
}
function _bash-it_check_for_backup() {
function _bash-it_check_for_backup()
{
if ! [[ -e "$HOME/$BACKUP_FILE" ]]; then
return
fi
@ -111,7 +118,8 @@ function _bash-it_check_for_backup() {
fi
}
function _bash-it_modify_config_files() {
function _bash-it_modify_config_files()
{
_bash-it_check_for_backup
if [[ -z "${silent}" ]]; then

View File

@ -12,10 +12,10 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
BASH_IT_SED_I_PARAMETERS=(-i)
case "$OSTYPE" in
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") ;;
esac
function _command_exists ()
function _command_exists()
{
_about 'checks for existence of a command'
_param '1: command to check'
@ -23,8 +23,7 @@ function _command_exists ()
_example '$ _command_exists ls && echo exists'
_group 'lib'
local msg="${2:-Command '$1' does not exist!}"
if type -t "$1" &> /dev/null
then
if type -t "$1" &> /dev/null; then
return 0
else
_log_warning "$msg"
@ -32,7 +31,7 @@ function _command_exists ()
fi
}
function _binary_exists ()
function _binary_exists()
{
_about 'checks for existence of a binary'
_param '1: binary to check'
@ -40,8 +39,7 @@ function _binary_exists ()
_example '$ _binary_exists ls && echo exists'
_group 'lib'
local msg="${2:-Binary '$1' does not exist!}"
if type -P "$1" &> /dev/null
then
if type -P "$1" &> /dev/null; then
return 0
else
_log_warning "$msg"
@ -49,7 +47,7 @@ function _binary_exists ()
fi
}
function _completion_exists ()
function _completion_exists()
{
_about 'checks for existence of a completion'
_param '1: command to check'
@ -57,15 +55,13 @@ function _completion_exists ()
_example '$ _completion_exists gh && echo exists'
_group 'lib'
local msg="${2:-Completion for '$1' already exists!}"
complete -p "$1" &> /dev/null && _log_warning "$msg" ;
complete -p "$1" &> /dev/null && _log_warning "$msg"
}
function _bash_it_homebrew_check()
{
if _binary_exists 'brew'
then # Homebrew is installed
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]
then # variable isn't set
if _binary_exists 'brew'; then # Homebrew is installed
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]; then # variable isn't set
BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)"
else
true # Variable is set already, don't invoke `brew`.
@ -76,7 +72,8 @@ function _bash_it_homebrew_check()
fi
}
function _make_reload_alias() {
function _make_reload_alias()
{
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
}
@ -92,7 +89,7 @@ alias reload_completion="$(_make_reload_alias completion completion)"
# shellcheck disable=SC2139
alias reload_plugins="$(_make_reload_alias plugin plugins)"
bash-it ()
bash-it()
{
about 'Bash-it help and maintenance'
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] '
@ -117,31 +114,43 @@ bash-it ()
case $verb in
show)
func=_bash-it-$component;;
func=_bash-it-$component
;;
enable)
func=_enable-$component;;
func=_enable-$component
;;
disable)
func=_disable-$component;;
func=_disable-$component
;;
help)
func=_help-$component;;
func=_help-$component
;;
doctor)
func=_bash-it-doctor-$component;;
func=_bash-it-doctor-$component
;;
search)
_bash-it-search $component "$@"
return;;
return
;;
update)
func=_bash-it-update-$component;;
func=_bash-it-update-$component
;;
migrate)
func=_bash-it-migrate;;
func=_bash-it-migrate
;;
version)
func=_bash-it-version;;
func=_bash-it-version
;;
restart)
func=_bash-it-restart;;
func=_bash-it-restart
;;
reload)
func=_bash-it-reload;;
func=_bash-it-reload
;;
*)
reference bash-it
return;;
return
;;
esac
# pluralize component if necessary
@ -163,8 +172,7 @@ bash-it ()
# Automatically run a migration if required
_bash-it-migrate
for arg in "$@"
do
for arg in "$@"; do
$func $arg
done
@ -176,15 +184,15 @@ bash-it ()
fi
}
_is_function ()
_is_function()
{
_about 'sets $? to true if parameter is the name of a function'
_param '1: name of alleged function'
_group 'lib'
[ -n "$(LANG=C type -t $1 2>/dev/null | grep 'function')" ]
[ -n "$(LANG=C type -t $1 2> /dev/null | grep 'function')" ]
}
_bash-it-aliases ()
_bash-it-aliases()
{
_about 'summarizes available bash_it aliases'
_group 'lib'
@ -192,7 +200,7 @@ _bash-it-aliases ()
_bash-it-describe "aliases" "an" "alias" "Alias"
}
_bash-it-completions ()
_bash-it-completions()
{
_about 'summarizes available bash_it completions'
_group 'lib'
@ -200,7 +208,7 @@ _bash-it-completions ()
_bash-it-describe "completion" "a" "completion" "Completion"
}
_bash-it-plugins ()
_bash-it-plugins()
{
_about 'summarizes available bash_it plugins'
_group 'lib'
@ -208,21 +216,24 @@ _bash-it-plugins ()
_bash-it-describe "plugins" "a" "plugin" "Plugin"
}
_bash-it-update-dev() {
_bash-it-update-dev()
{
_about 'updates Bash-it to the latest master'
_group 'lib'
_bash-it-update- dev "$@"
}
_bash-it-update-stable() {
_bash-it-update-stable()
{
_about 'updates Bash-it to the latest tag'
_group 'lib'
_bash-it-update- stable "$@"
}
_bash-it_update_migrate_and_restart() {
_bash-it_update_migrate_and_restart()
{
_about 'Checks out the wanted version, pops directory and restart. Does not return (because of the restart!)'
_param '1: Which branch to checkout to'
_param '2: Which type of version we are using'
@ -242,7 +253,8 @@ _bash-it_update_migrate_and_restart() {
fi
}
_bash-it-update-() {
_bash-it-update-()
{
_about 'updates Bash-it'
_param '1: What kind of update to do (stable|dev)'
_group 'lib'
@ -320,7 +332,7 @@ _bash-it-update-() {
else
read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP
case $RESP in
[yY]|"")
[yY] | "")
_bash-it_update_migrate_and_restart $TARGET $version
;;
[nN])
@ -341,17 +353,16 @@ _bash-it-update-() {
popd &> /dev/null
}
_bash-it-migrate() {
_bash-it-migrate()
{
_about 'migrates Bash-it configuration from a previous format to the current one'
_group 'lib'
declare migrated_something
migrated_something=false
for file_type in "aliases" "plugins" "completion"
do
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
do
for file_type in "aliases" "plugins" "completion"; do
for f in $(sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")); do
typeset ff="${f##*/}"
# Get the type of component from the extension
@ -381,7 +392,8 @@ _bash-it-migrate() {
fi
}
_bash-it-version() {
_bash-it-version()
{
_about 'shows current Bash-it version'
_group 'lib'
@ -419,7 +431,8 @@ _bash-it-version() {
cd - &> /dev/null || return
}
_bash-it-doctor() {
_bash-it-doctor()
{
_about 'reloads a profile file with a BASH_IT_LOG_LEVEL set'
_param '1: BASH_IT_LOG_LEVEL argument: "errors" "warnings" "all"'
_group 'lib'
@ -429,35 +442,40 @@ _bash-it-doctor() {
unset BASH_IT_LOG_LEVEL
}
_bash-it-doctor-all() {
_bash-it-doctor-all()
{
_about 'reloads a profile file with error, warning and debug logs'
_group 'lib'
_bash-it-doctor $BASH_IT_LOG_LEVEL_ALL
}
_bash-it-doctor-warnings() {
_bash-it-doctor-warnings()
{
_about 'reloads a profile file with error and warning logs'
_group 'lib'
_bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING
}
_bash-it-doctor-errors() {
_bash-it-doctor-errors()
{
_about 'reloads a profile file with error logs'
_group 'lib'
_bash-it-doctor $BASH_IT_LOG_LEVEL_ERROR
}
_bash-it-doctor-() {
_bash-it-doctor-()
{
_about 'default bash-it doctor behavior, behaves like bash-it doctor all'
_group 'lib'
_bash-it-doctor-all
}
_bash-it-restart() {
_bash-it-restart()
{
_about 'restarts the shell in order to fully reload it'
_group 'lib'
@ -474,7 +492,8 @@ _bash-it-restart() {
exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"")
}
_bash-it-reload() {
_bash-it-reload()
{
_about 'reloads a profile file'
_group 'lib'
@ -492,7 +511,7 @@ _bash-it-reload() {
popd &> /dev/null || return
}
_bash-it-describe ()
_bash-it-describe()
{
_about 'summarizes available bash_it components'
_param '1: subdirectory'
@ -509,8 +528,7 @@ _bash-it-describe ()
typeset f
typeset enabled
printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description'
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
for f in "${BASH_IT}/$subdirectory/available/"*.bash; do
# Check for both the old format without the load priority, and the extended format with the priority
declare enabled_files enabled_file
enabled_file="${f##*/}"
@ -540,7 +558,7 @@ _on-disable-callback()
_command_exists $callback && $callback
}
_disable-plugin ()
_disable-plugin()
{
_about 'disables bash_it plugin'
_param '1: plugin name'
@ -551,7 +569,7 @@ _disable-plugin ()
_on-disable-callback $1
}
_disable-alias ()
_disable-alias()
{
_about 'disables bash_it alias'
_param '1: alias name'
@ -561,7 +579,7 @@ _disable-alias ()
_disable-thing "aliases" "alias" $1
}
_disable-completion ()
_disable-completion()
{
_about 'disables bash_it completion'
_param '1: completion name'
@ -571,7 +589,7 @@ _disable-completion ()
_disable-thing "completion" "completion" $1
}
_disable-thing ()
_disable-thing()
{
_about 'disables a bash_it component'
_param '1: subdirectory'
@ -593,24 +611,22 @@ _disable-thing ()
if [ "$file_entity" = "all" ]; then
# Disable everything that's using the old structure
for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"`
do
for f in $(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"); do
rm "$f"
done
# Disable everything in the global "enabled" directory
for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"`
do
for f in $(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"); do
rm "$f"
done
else
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1)
typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2> /dev/null | head -1)
if [ -z "$plugin_global" ]; then
# Use a glob to search for both possible patterns
# 250---node.plugin.bash
# node.plugin.bash
# Either one will be matched by this glob
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1)
typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2> /dev/null | head -1)
if [ -z "$plugin" ]; then
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return
@ -626,7 +642,7 @@ _disable-thing ()
printf '%s\n' "$file_entity disabled."
}
_enable-plugin ()
_enable-plugin()
{
_about 'enables bash_it plugin'
_param '1: plugin name'
@ -636,7 +652,7 @@ _enable-plugin ()
_enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN
}
_enable-alias ()
_enable-alias()
{
_about 'enables bash_it alias'
_param '1: alias name'
@ -646,7 +662,7 @@ _enable-alias ()
_enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS
}
_enable-completion ()
_enable-completion()
{
_about 'enables bash_it completion'
_param '1: completion name'
@ -656,7 +672,7 @@ _enable-completion ()
_enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION
}
_enable-thing ()
_enable-thing()
{
cite _about _param _example
_about 'enables a bash_it component'
@ -678,8 +694,7 @@ _enable-thing ()
if [ "$file_entity" = "all" ]; then
typeset f $file_type
for f in "${BASH_IT}/$subdirectory/available/"*.bash
do
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")
@ -687,7 +702,7 @@ _enable-thing ()
_enable-thing $subdirectory $file_type $to_enable $load_priority
done
else
typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1)
typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2> /dev/null | head -1)
if [ -z "$to_enable" ]; then
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
return
@ -695,14 +710,14 @@ _enable-thing ()
to_enable="${to_enable##*/}"
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin" ] ; then
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2> /dev/null | head -1)
if [ ! -z "$enabled_plugin" ]; then
printf '%s\n' "$file_entity is already enabled."
return
fi
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin_global" ] ; then
typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2> /dev/null | head -1)
if [ ! -z "$enabled_plugin_global" ]; then
printf '%s\n' "$file_entity is already enabled."
return
fi
@ -750,8 +765,7 @@ _help-aliases()
else
typeset f
for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")`
do
for f in $(sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")); do
_help-list-aliases $f
done
@ -761,7 +775,7 @@ _help-aliases()
fi
}
_help-list-aliases ()
_help-list-aliases()
{
typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g')
printf '\n\n%s:\n' "${file}"
@ -778,8 +792,7 @@ _help-plugins()
printf '%s' 'please wait, building help...'
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
typeset func
for func in $(_typeset_functions)
do
for func in $(_typeset_functions); do
typeset group="$(typeset -f $func | metafor group)"
if [ -z "$group" ]; then
group='misc'
@ -792,8 +805,7 @@ _help-plugins()
printf '\r%s\n' ' '
typeset group
typeset gfile
for gfile in $(cat $grouplist | sort | uniq)
do
for gfile in $(cat $grouplist | sort | uniq); do
printf '%s\n' "${gfile##*.}:"
cat $gfile
printf '\n'
@ -802,14 +814,16 @@ _help-plugins()
rm $grouplist 2> /dev/null
}
_help-update () {
_help-update()
{
_about 'help message for update command'
_group 'lib'
echo "Check for a new version of Bash-it and update it."
}
_help-migrate () {
_help-migrate()
{
_about 'help message for migrate command'
_group 'lib'
@ -817,31 +831,30 @@ _help-migrate () {
echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'."
}
all_groups ()
all_groups()
{
about 'displays all unique metadata groups'
group 'lib'
typeset func
typeset file=$(mktemp -t composure.XXXX)
for func in $(_typeset_functions)
do
for func in $(_typeset_functions); do
typeset -f $func | metafor group >> $file
done
cat $file | sort | uniq
rm $file
}
if ! type pathmunge > /dev/null 2>&1
then
function pathmunge () {
if ! type pathmunge > /dev/null 2>&1; then
function pathmunge()
{
about 'prevent duplicate directories in you PATH variable'
group 'helpers'
example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH'
example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir'
if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then
if [ "$2" = "after" ] ; then
if ! [[ $PATH =~ (^|:)$1($|:) ]]; then
if [ "$2" = "after" ]; then
export PATH=$PATH:$1
else
export PATH=$1:$PATH
@ -853,7 +866,8 @@ fi
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
# a subshell to simplify our search to a simple `cd ..` and `[[ -r $1 ]]`
# without any external dependencies. Let the shell do what it's good at.
function _bash-it-find-in-ancestor() (
function _bash-it-find-in-ancestor()
(
about 'searches parents of the current directory for any of the specified file names'
group 'helpers'
param '*: names of files or folders to search for'

View File

@ -1,5 +1,4 @@
if [[ "${BASH_PREVIEW:-}" ]];
then
if [[ "${BASH_PREVIEW:-}" ]]; then
unset BASH_PREVIEW #Prevent infinite looping
echo "
@ -8,8 +7,7 @@ then
"
THEMES="$BASH_IT/themes/*/*.theme.bash"
for theme in $THEMES
do
for theme in $THEMES; do
BASH_IT_THEME=${theme%.theme.bash}
BASH_IT_THEME=${BASH_IT_THEME##*/}
echo "

View File

@ -47,20 +47,21 @@
# completions: git
#
_bash-it-search() {
_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 @git ruby -rvm rake bundler'
[[ -z "$(type _bash-it-array-contains-element 2>/dev/null)" ]] && source "${BASH_IT}/lib/utilities.bash"
[[ -z "$(type _bash-it-array-contains-element 2> /dev/null)" ]] && source "${BASH_IT}/lib/utilities.bash"
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
if [[ -z "$*" ]]; then
_bash-it-search-help
return 0
fi
@ -80,7 +81,7 @@ _bash-it-search() {
done
if [[ ${#args} -gt 0 ]]; then
for component in "${BASH_IT_COMPONENTS[@]}" ; do
for component in "${BASH_IT_COMPONENTS[@]}"; do
_bash-it-search-component "${component}" "${args[@]}"
done
fi
@ -88,7 +89,8 @@ _bash-it-search() {
return 0
}
_bash-it-search-help() {
_bash-it-search-help()
{
printf "${echo_normal}
${echo_underline_yellow}USAGE${echo_normal}
@ -165,14 +167,17 @@ ${echo_underline_yellow}SUMMARY${echo_normal}
"
}
_bash-it-is-partial-match() {
_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
_bash-it-component-term-matches-negation()
{
local match="$1"
shift
local negative
for negative in "$@"; do
[[ "${match}" =~ "${negative}" ]] && return 0
@ -181,7 +186,8 @@ _bash-it-component-term-matches-negation() {
return 1
}
_bash-it-search-component() {
_bash-it-search-component()
{
local component="$1"
shift
@ -218,50 +224,54 @@ _bash-it-search-component() {
local -a negative_terms=() # negated partial terms that should be excluded
unset component_list
local -a component_list=( $(_bash-it-component-list "${component}") )
local -a component_list=($(_bash-it-component-list "${component}"))
local term
for term in "${terms[@]}"; do
local search_term="${term:1}"
if [[ "${term:0:2}" == "--" ]] ; then
if [[ "${term:0:2}" == "--" ]]; then
continue
elif [[ "${term:0:1}" == "-" ]] ; then
elif [[ "${term:0:1}" == "-" ]]; then
negative_terms=(${negative_terms[@]} "${search_term}")
elif [[ "${term:0:1}" == "@" ]] ; then
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}") )
partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}"))
fi
done
local -a total_matches=( $(_bash-it-array-dedup ${exact_terms[@]} ${partial_terms[@]}) )
local -a total_matches=($(_bash-it-array-dedup ${exact_terms[@]} ${partial_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
(_bash-it-component-term-matches-negation "${match}" "${negative_terms[@]}") && include_match=false
fi
( ${include_match} ) && matches=(${matches[@]} "${match}")
(${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 component="$1"; shift
local action="$1"; shift
local action_func="$1"; shift
_bash-it-search-result()
{
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
color_sep=':'
( ${BASH_IT_SEARCH_USE_COLOR} ) && {
(${BASH_IT_SEARCH_USE_COLOR}) && {
color_component='\e[1;34m'
color_enable='\e[1;32m'
suffix_enable=''
@ -270,7 +280,7 @@ _bash-it-search-result() {
color_off='\e[0;0m'
}
( ${BASH_IT_SEARCH_USE_COLOR} ) || {
(${BASH_IT_SEARCH_USE_COLOR}) || {
color_component=''
suffix_enable=' ✓ '
suffix_disable=' '
@ -282,23 +292,23 @@ _bash-it-search-result() {
local match
local modified=0
if [[ "${#matches[@]}" -gt 0 ]] ; then
if [[ "${#matches[@]}" -gt 0 ]]; then
printf "${color_component}%13s${color_sep} ${color_off}" "${component}"
for match in "${matches[@]}"; do
local enabled=0
( _bash-it-component-item-is-enabled "${component}" "${match}" ) && enabled=1
(_bash-it-component-item-is-enabled "${component}" "${match}") && enabled=1
local match_color compatible_action suffix opposite_suffix
(( ${enabled} )) && {
((${enabled})) && {
match_color=${color_enable}
suffix=${suffix_enable}
opposite_suffix=${suffix_disable}
compatible_action="disable"
}
(( ${enabled} )) || {
((${enabled})) || {
match_color=${color_disable}
suffix=${suffix_disable}
opposite_suffix=${suffix_enable}
@ -332,25 +342,28 @@ _bash-it-search-result() {
fi
}
_bash-it-rewind() {
_bash-it-rewind()
{
local len="$1"
printf "\033[${len}D"
}
_bash-it-flash-term() {
_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
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() {
_bash-it-erase-term()
{
local len="$1"
_bash-it-rewind ${len}
for a in {0..30}; do

View File

@ -6,7 +6,8 @@
# Generic utilies
###########################################################################
function _bash-it-get-component-name-from-path() {
function _bash-it-get-component-name-from-path()
{
local filename
# filename without path
filename="${1##*/}"
@ -16,7 +17,8 @@ function _bash-it-get-component-name-from-path() {
echo "${filename%.*.bash}"
}
function _bash-it-get-component-type-from-path() {
function _bash-it-get-component-type-from-path()
{
local filename
# filename without path
filename="${1##*/}"
@ -46,7 +48,8 @@ function _bash-it-get-component-type-from-path() {
# contains pear!
#
#
function _bash-it-array-contains-element() {
function _bash-it-array-contains-element()
{
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0
@ -55,18 +58,21 @@ function _bash-it-array-contains-element() {
}
# Dedupe an array (without embedded newlines).
function _bash-it-array-dedup() {
function _bash-it-array-dedup()
{
printf '%s\n' "$@" | sort -u
}
# Outputs a full path of the grep found on the filesystem
function _bash-it-grep() {
function _bash-it-grep()
{
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
}
# Runs `grep` with extended regular expressions
function _bash-it-egrep() {
function _bash-it-egrep()
{
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
}
@ -76,7 +82,8 @@ function _bash-it-egrep() {
# completion).
###########################################################################
function _bash-it-component-help() {
function _bash-it-component-help()
{
local component file func
component="$(_bash-it-pluralize-component "${1}")"
file="$(_bash-it-component-cache-file "${component}")"
@ -87,7 +94,8 @@ function _bash-it-component-help() {
cat "${file}"
}
function _bash-it-component-cache-file() {
function _bash-it-component-cache-file()
{
local component file
component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")"
file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}"
@ -95,7 +103,8 @@ function _bash-it-component-cache-file() {
printf '%s' "${file}"
}
function _bash-it-pluralize-component() {
function _bash-it-pluralize-component()
{
local component="${1}"
local -i len=$((${#component} - 1))
# pluralize component name for consistency
@ -104,7 +113,8 @@ function _bash-it-pluralize-component() {
printf '%s' "${component}"
}
function _bash-it-clean-component-cache() {
function _bash-it-clean-component-cache()
{
local component="$1"
local cache
local -a BASH_IT_COMPONENTS=(aliases plugins completions)
@ -121,24 +131,28 @@ function _bash-it-clean-component-cache() {
}
# Returns an array of items within each compoenent.
function _bash-it-component-list() {
function _bash-it-component-list()
{
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | awk '{print $1}' | sort -u
}
function _bash-it-component-list-matching() {
function _bash-it-component-list-matching()
{
local component="$1"
shift
local term="$1"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -- "${term}" | awk '{print $1}' | sort -u
}
function _bash-it-component-list-enabled() {
function _bash-it-component-list-enabled()
{
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | awk '{print $1}' | sort -u
}
function _bash-it-component-list-disabled() {
function _bash-it-component-list-disabled()
{
local IFS=$'\n' component="$1"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | awk '{print $1}' | sort -u
}
@ -151,7 +165,8 @@ function _bash-it-component-list-disabled() {
#
# Examples:
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
function _bash-it-component-item-is-enabled() {
function _bash-it-component-item-is-enabled()
{
local component="$1"
local item="$2"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
@ -165,7 +180,8 @@ function _bash-it-component-item-is-enabled() {
#
# Examples:
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
function _bash-it-component-item-is-disabled() {
function _bash-it-component-item-is-disabled()
{
local component="$1"
local item="$2"
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"

View File

@ -7,10 +7,10 @@
#
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
mapfile -t FILES < <(
cat clean_files.txt \
| grep -v -E '^\s*$' \
| grep -v -E '^\s*#' \
| xargs -n1 -I{} find "{}" -type f
cat clean_files.txt |
grep -v -E '^\s*$' |
grep -v -E '^\s*#' |
xargs -n1 -I{} find "{}" -type f
)
# We clear the BASH_IT variable to help the shellcheck checker

View File

@ -17,7 +17,8 @@ about-plugin 'Automatic completion of aliases'
# 4) Custom scripts
# Automatically add completion for all aliases to commands having completion functions
function alias_completion {
function alias_completion
{
local namespace="alias_completion"
local tmp_file completion_loader alias_name alias_tokens line completions
local alias_arg_words new_completion compl_func compl_wrapper

View File

@ -2,7 +2,8 @@
cite about-plugin
about-plugin 'miscellaneous tools'
function ips() {
function ips()
{
about 'display all ip addresses for this host'
group 'base'
if _command_exists ifconfig; then
@ -14,7 +15,8 @@ function ips() {
fi
}
function down4me() {
function down4me()
{
about 'checks whether a website is down for you, or everybody'
param '1: website url'
example '$ down4me http://www.google.com'
@ -22,7 +24,8 @@ function down4me() {
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
}
function myip() {
function myip()
{
about 'displays your ip address, as seen by the Internet'
group 'base'
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
@ -35,7 +38,8 @@ function myip() {
echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
}
function pickfrom() {
function pickfrom()
{
about 'picks random line from file'
param '1: filename'
example '$ pickfrom /usr/share/dict/words'
@ -50,7 +54,8 @@ function pickfrom() {
head -n "$n" "$file" | tail -1
}
function passgen() {
function passgen()
{
about 'generates random password from dictionary words'
param 'optional integer length'
param 'if unset, defaults to 4'
@ -72,7 +77,8 @@ if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then
fi
if _command_exists markdown && _command_exists browser; then
function pmdown() {
function pmdown()
{
about 'preview markdown file in a browser'
param '1: markdown file'
example '$ pmdown README.md'
@ -82,7 +88,8 @@ if _command_exists markdown && _command_exists browser; then
}
fi
function mkcd() {
function mkcd()
{
about 'make one or more directories and cd into the last one'
param 'one or more directories to create'
example '$ mkcd foo'
@ -94,19 +101,22 @@ function mkcd() {
}
# shellcheck disable=SC2010
function lsgrep() {
function lsgrep()
{
about 'search through directory contents with grep'
group 'base'
ls | grep "$@"
}
function quiet() {
function quiet()
{
about 'what *does* this do?'
group 'base'
nohup "$@" &> /dev/null < /dev/null &
}
function usage() {
function usage()
{
about 'disk usage per directory, in Mac OS X and Linux'
param '1: directory name'
group 'base'
@ -124,7 +134,8 @@ function usage() {
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
# if user has installed todo plugin, skip this...
function t() {
function t()
{
about 'one thing todo'
param 'if not set, display todo item'
param '1: todo text'
@ -137,7 +148,8 @@ if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
fi
if _command_exists mkisofs; then
function mkiso() {
function mkiso()
{
about 'creates iso from current dir in the parent dir (unless defined)'
param '1: ISO name'
param '2: dest/path'
@ -160,7 +172,8 @@ if _command_exists mkisofs; then
fi
# useful for administrators and configs
function buf() {
function buf()
{
about 'back up file with timestamp'
param 'filename'
group 'base'
@ -170,7 +183,8 @@ function buf() {
}
if ! _command_exists del; then
function del() {
function del()
{
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
param 'file or folder to be deleted'
example 'del ./file.txt'

View File

@ -2,13 +2,15 @@
cite about-plugin
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
precmd_return_notification() {
precmd_return_notification()
{
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}))
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
export LAST_COMMAND_TIME=
}
preexec_return_notification() {
preexec_return_notification()
{
[[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s)
}

View File

@ -31,7 +31,8 @@ alias pu="pushd"
# Pop current location
alias po="popd"
function dirs-help() {
function dirs-help()
{
about 'directory navigation alias usage'
group 'dirs'
@ -67,39 +68,48 @@ fi
alias L='cat ~/.dirs'
# Goes to destination dir, otherwise stay in the dir
G () {
G()
{
about 'goes to destination dir'
param '1: directory'
example '$ G ..'
group 'dirs'
cd "${1:-${PWD}}" ;
cd "${1:-${PWD}}"
}
S () {
S()
{
about 'save a bookmark'
param '1: bookmark name'
example '$ S mybkmrk'
group 'dirs'
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
[[ $# -eq 1 ]] || {
echo "${FUNCNAME[0]} function requires 1 argument"
return 1
}
sed "/$@/d" ~/.dirs > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs;
echo "$@"=\""${PWD}"\" >> ~/.dirs;
source ~/.dirs ;
sed "/$@/d" ~/.dirs > ~/.dirs1
\mv ~/.dirs1 ~/.dirs
echo "$@"=\""${PWD}"\" >> ~/.dirs
source ~/.dirs
}
R () {
R()
{
about 'remove a bookmark'
param '1: bookmark name'
example '$ R mybkmrk'
group 'dirs'
[[ $# -eq 1 ]] || { echo "${FUNCNAME[0]} function requires 1 argument"; return 1; }
[[ $# -eq 1 ]] || {
echo "${FUNCNAME[0]} function requires 1 argument"
return 1
}
sed "/$@/d" ~/.dirs > ~/.dirs1;
\mv ~/.dirs1 ~/.dirs;
sed "/$@/d" ~/.dirs > ~/.dirs1
\mv ~/.dirs1 ~/.dirs
}
alias U='source ~/.dirs' # Update bookmark stack

View File

@ -3,7 +3,8 @@ cite about-plugin
about-plugin 'git helper functions'
# shellcheck disable=SC2016
function git_remote {
function git_remote
{
about 'adds remote $GIT_HOSTING:$1 to current repo'
group "git"
@ -11,7 +12,8 @@ function git_remote {
git remote add origin "${GIT_HOSTING}:${1}".git
}
function git_first_push {
function git_first_push
{
about 'push into origin refs/heads/master'
group 'git'
@ -19,7 +21,8 @@ function git_first_push {
git push origin master:refs/heads/master
}
function git_pub() {
function git_pub()
{
about 'publishes current branch to remote origin'
group 'git'
BRANCH=$(git rev-parse --abbrev-ref HEAD)
@ -28,7 +31,8 @@ function git_pub() {
git push -u origin "${BRANCH}"
}
function git_revert() {
function git_revert()
{
about 'applies changes to HEAD that revert all changes after this commit'
group 'git'
@ -38,25 +42,29 @@ function git_revert() {
git reset --hard
}
function git_rollback() {
function git_rollback()
{
about 'resets the current HEAD to this commit'
group 'git'
function is_clean() {
function is_clean()
{
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo "Your branch is dirty, please commit your changes"
kill -INT $$
fi
}
function commit_exists() {
function commit_exists()
{
if git rev-list --quiet "${1:?}"; then
echo "Commit ${1} does not exist"
kill -INT $$
fi
}
function keep_changes() {
function keep_changes()
{
while true; do
# shellcheck disable=SC2162
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
@ -105,7 +113,8 @@ function git_rollback() {
fi
}
function git_remove_missing_files() {
function git_remove_missing_files()
{
about "git rm's missing files"
group 'git'
@ -113,7 +122,8 @@ function git_remove_missing_files() {
}
# Adds files to git's exclude file (same as .gitignore)
function local-ignore() {
function local-ignore()
{
about 'adds file or path to git exclude file'
param '1: file or path fragment to ignore'
group 'git'
@ -121,7 +131,8 @@ function local-ignore() {
}
# get a quick overview for your git repo
function git_info() {
function git_info()
{
about 'overview for your git repo'
group 'git'
@ -158,7 +169,8 @@ function git_info() {
fi
}
function git_stats {
function git_stats
{
about 'display stats per author'
group 'git'
@ -203,7 +215,8 @@ function git_stats {
fi
}
function gittowork() {
function gittowork()
{
about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore'
group 'git'
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
@ -224,7 +237,8 @@ function gittowork() {
fi
}
function gitignore-reload() {
function gitignore-reload()
{
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
group 'git'
example '$ gitignore-reload'
@ -274,7 +288,8 @@ function gitignore-reload() {
fi
}
function git-changelog() {
function git-changelog()
{
# ---------------------------------------------------------------
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
# ---------------------------------------------------------------

View File

@ -7,7 +7,9 @@ about-plugin 'go environment variables & path configuration'
# Test `go version` because goenv creates shim scripts that will be found in PATH
# but do not always resolve to a working install.
{ _command_exists go && go version &> /dev/null; } || return 0
{
_command_exists go && go version &> /dev/null
} || return 0
export GOROOT="${GOROOT:-$(go env GOROOT)}"
export GOPATH="${GOPATH:-$(go env GOPATH)}"
@ -16,7 +18,8 @@ export GOPATH="${GOPATH:-$(go env GOPATH)}"
# might be managed differently, we add each path's /bin folder to PATH using pathmunge,
# while preserving ordering.
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin
_bash-it-gopath-pathmunge() {
_bash-it-gopath-pathmunge()
{
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended'
_group 'go'
if [[ -z $GOPATH ]]; then

View File

@ -11,10 +11,10 @@ about-plugin 'load goenv, if you are using it'
# - Check if in $PATH already
# - Check if installed manually to $GOENV_ROOT
# - Check if installed manually to $HOME
_command_exists goenv \
|| [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \
|| [[ -x "$HOME/.goenv/bin/goenv" ]] \
|| return 0
_command_exists goenv ||
[[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] ||
[[ -x "$HOME/.goenv/bin/goenv" ]] ||
return 0
# Set GOENV_ROOT, if not already set
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
@ -29,10 +29,12 @@ eval "$(goenv init - bash)"
# If moving to a directory with a goenv version set, reload the shell
# to ensure the shell environment matches expectations.
_bash-it-goenv-preexec() {
_bash-it-goenv-preexec()
{
GOENV_OLD_VERSION="$(goenv version-name)"
}
_bash-it-goenv-precmd() {
_bash-it-goenv-precmd()
{
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
fi

View File

@ -11,7 +11,8 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
# resize history to 100x the default (500)
export HISTSIZE=${HISTSIZE:-50000}
top-history() {
top-history()
{
about 'print the name and count of the most commonly run tools'
if [[ -n $HISTTIMEFORMAT ]]; then
@ -23,16 +24,16 @@ top-history() {
unset HISTTIMEFORMAT
fi
history \
| awk '{
history |
awk '{
a[$2]++
}END{
for(i in a)
printf("%s\t%s\n", a[i], i)
}' \
| sort --reverse --numeric-sort \
| head \
| column \
}' |
sort --reverse --numeric-sort |
head |
column \
--table \
--table-columns 'Command Count,Command Name' \
--output-separator ' | '

View File

@ -3,7 +3,8 @@
cite about-plugin
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding'
function __init_jump() {
function __init_jump()
{
if _command_exists jump; then
eval "$(jump shell bash "${JUMP_OPTS[@]}")"
fi

View File

@ -6,7 +6,8 @@ _command_exists pygmentize || return
# 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() {
function ccat()
{
about 'runs pygmentize on each file passed in'
param '*: files to concatenate (as normally passed to cat)'
example 'ccat mysite/manage.py dir/text-file.txt'
@ -14,7 +15,8 @@ function ccat() {
pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@"
}
function cless() {
function cless()
{
about 'pigments the files passed in and passes to less for pagination'
param '*: the files to paginate with less'
example 'cless mysite/manage.py'

View File

@ -21,7 +21,8 @@ if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
return
fi
function _replace_by_history() {
function _replace_by_history()
{
local HISTTIMEFORMAT= # Ensure we can parse history properly
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
local l

View File

@ -11,10 +11,10 @@ about-plugin 'load pyenv, if you are using it'
# - Check if in $PATH already
# - Check if installed manually to $PYENV_ROOT
# - Check if installed manually to $HOME
_command_exists pyenv \
|| [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \
|| [[ -x "$HOME/.pyenv/bin/pyenv" ]] \
|| return 0
_command_exists pyenv ||
[[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] ||
[[ -x "$HOME/.pyenv/bin/pyenv" ]] ||
return 0
# Set PYENV_ROOT, if not already set
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"

View File

@ -8,7 +8,8 @@ if _command_exists ruby && _command_exists gem; then
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
fi
function remove_gem() {
function remove_gem()
{
about 'removes installed gem'
param '1: installed gem name'
group 'ruby'

View File

@ -2,7 +2,8 @@
cite about-plugin
about-plugin 'automatically set your xterm title with host and location info'
_short-dirname() {
_short-dirname()
{
local dir_name="${PWD/~/\~}"
if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
echo "${dir_name##*/}"
@ -11,7 +12,8 @@ _short-dirname() {
fi
}
_short-command() {
_short-command()
{
local input_command="$*"
if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
echo "${input_command%% *}"
@ -20,16 +22,19 @@ _short-command() {
fi
}
set_xterm_title() {
set_xterm_title()
{
local title="${1:-}"
echo -ne "\033]0;${title}\007"
}
precmd_xterm_title() {
precmd_xterm_title()
{
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
}
preexec_xterm_title() {
preexec_xterm_title()
{
set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
}

View File

@ -13,11 +13,13 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
_bash_it_config_type=""
case $1 in
alias|completion|plugin)
alias | completion | plugin)
_bash_it_config_type=$1
_log_debug "Loading enabled $1 components..." ;;
''|*)
_log_debug "Loading all enabled components..." ;;
_log_debug "Loading enabled $1 components..."
;;
'' | *)
_log_debug "Loading all enabled components..."
;;
esac
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do
@ -34,7 +36,7 @@ fi
if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
case $2 in
aliases|completion|plugins)
aliases | completion | plugins)
_log_warning "Using legacy enabling for $2, please update your bash-it version and migrate"
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do
if [[ -e "$_bash_it_config_file" ]]; then
@ -45,7 +47,8 @@ if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
else
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
fi
done ;;
done
;;
esac
fi

View File

@ -22,11 +22,13 @@ load "${TEST_DEPS_DIR}/bats-file/load.bash"
# support 'plumbing' metadata
cite _about _param _example _group _author _version
local_setup() {
local_setup()
{
true
}
local_teardown() {
local_teardown()
{
true
}
@ -34,7 +36,8 @@ local_teardown() {
# fresh and isolated Bash-it directory. This is done to avoid
# messing with your own Bash-it source directory.
# If you need this, call it in your .bats file's `local_setup` function.
setup_test_fixture() {
setup_test_fixture()
{
mkdir -p "$BASH_IT"
lib_directory="$(cd "$(dirname "$0")" && pwd)"
local src_topdir="$lib_directory/../../../.."
@ -66,7 +69,8 @@ setup_test_fixture() {
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
}
setup() {
setup()
{
# The `temp_make` function from "bats-file" requires the tralston/bats-file fork,
# since the original ztombol/bats-file's `temp_make` does not work on macOS.
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
@ -96,7 +100,8 @@ setup() {
local_setup
}
teardown() {
teardown()
{
local_teardown
rm -rf "${BASH_IT_TEST_DIR}"

View File

@ -13,7 +13,8 @@ GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
# Nicely formatted terminal prompt
function prompt_command() {
function prompt_command()
{
PS1="\n${bold_black}[${blue}\@${bold_black}]-${bold_black}[${green}\u${yellow}@${green}\h${bold_black}]-${bold_black}[${purple}\w${bold_black}]-$(scm_prompt_info)\n${reset_color}\$ "
}

View File

@ -70,7 +70,8 @@ PROMPT_DIRTRIM=2 # bash4 and above
######################################################################
DEBUG=0
debug() {
debug()
{
if [[ ${DEBUG} -ne 0 ]]; then
echo >&2 -e "$@"
fi
@ -87,7 +88,8 @@ RIGHT_SEPARATOR=''
LEFT_SUBSEG=''
RIGHT_SUBSEG=''
text_effect() {
text_effect()
{
case "$1" in
reset) echo 0 ;;
bold) echo 1 ;;
@ -98,7 +100,8 @@ text_effect() {
# to add colors, see
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
# under the "256 (8-bit) Colors" section, and follow the example for orange below
fg_color() {
fg_color()
{
case "$1" in
black) echo 30 ;;
red) echo 31 ;;
@ -112,7 +115,8 @@ fg_color() {
esac
}
bg_color() {
bg_color()
{
case "$1" in
black) echo 40 ;;
red) echo 41 ;;
@ -129,7 +133,8 @@ bg_color() {
# TIL: declare is global not local, so best use a different name
# for codes (mycodes) as otherwise it'll clobber the original.
# this changes from BASH v3 to BASH v4.
ansi() {
ansi()
{
local seq
declare -a mycodes=("${!1}")
@ -147,14 +152,16 @@ ansi() {
# PR="$PR\[\033[${seq}m\]"
}
ansi_single() {
ansi_single()
{
echo -ne '\[\033['"$1"'m\]'
}
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
prompt_segment()
{
local bg fg
declare -a codes
@ -196,7 +203,8 @@ prompt_segment() {
}
# End the prompt, closing any open segments
prompt_end() {
prompt_end()
{
if [[ -n $CURRENT_BG ]]; then
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
@ -207,7 +215,8 @@ prompt_end() {
}
### virtualenv prompt
prompt_virtualenv() {
prompt_virtualenv()
{
if [[ -n $VIRTUAL_ENV ]]; then
color=cyan
prompt_segment $color "$PRIMARY_FG"
@ -220,7 +229,8 @@ prompt_virtualenv() {
# Each component will draw itself, and hide itself if no information needs to be shown
# Context: user@hostname (who am I and where am I)
prompt_context() {
prompt_context()
{
local user="${USER:-${LOGNAME:?}}"
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
@ -230,17 +240,20 @@ prompt_context() {
# prints history followed by HH:MM, useful for remembering what
# we did previously
prompt_histdt() {
prompt_histdt()
{
prompt_segment black default "\! [\A]"
}
git_status_dirty() {
git_status_dirty()
{
dirty=$(git status -s 2> /dev/null | tail -n 1)
[[ -n $dirty ]] && echo " ●"
}
# Git: branch/detached head, dirty status
prompt_git() {
prompt_git()
{
local ref dirty
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
ZSH_THEME_GIT_PROMPT_DIRTY='±'
@ -256,7 +269,8 @@ prompt_git() {
}
# Dir: current working directory
prompt_dir() {
prompt_dir()
{
prompt_segment blue black '\w'
}
@ -264,7 +278,8 @@ prompt_dir() {
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
prompt_status()
{
local symbols
symbols=()
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")")
@ -280,12 +295,14 @@ prompt_status() {
# requires setting prompt_foo to use PRIGHT vs PR
# doesn't quite work per above
rightprompt() {
rightprompt()
{
printf "%*s" $COLUMNS "$PRIGHT"
}
# quick right prompt I grabbed to test things.
__command_rprompt() {
__command_rprompt()
{
local times=n=$COLUMNS tz
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
MTV:US/Pacific TOK:Asia/Tokyo; do
@ -299,7 +316,8 @@ __command_rprompt() {
# PROMPT_COMMAND=__command_rprompt
# this doens't wrap code in \[ \]
ansi_r() {
ansi_r()
{
local seq
declare -a mycodes2=("${!1}")
@ -320,7 +338,8 @@ ansi_r() {
# Begin a segment on the right
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_right_segment() {
prompt_right_segment()
{
local bg fg
declare -a codes
@ -383,7 +402,8 @@ prompt_right_segment() {
# (add-hook 'comint-preoutput-filter-functions
# 'dirtrack-filter-out-pwd-prompt t t)))
prompt_emacsdir() {
prompt_emacsdir()
{
# no color or other setting... this will be deleted per above
PR="DIR \w DIR$PR"
}
@ -391,7 +411,8 @@ prompt_emacsdir() {
######################################################################
## Main prompt
build_prompt() {
build_prompt()
{
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
prompt_status
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
@ -407,7 +428,8 @@ build_prompt() {
# this doesn't work... new model: create a prompt via a PR variable and
# use that.
set_bash_prompt() {
set_bash_prompt()
{
RETVAL=$?
PR=""
PRIGHT=""

View File

@ -29,7 +29,8 @@ Face="\342\230\273"
## Parsers ##
#############
____atomic_top_left_parse() {
____atomic_top_left_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -44,7 +45,8 @@ ____atomic_top_left_parse() {
_TOP_LEFT+=""
}
____atomic_top_right_parse() {
____atomic_top_right_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -61,7 +63,8 @@ ____atomic_top_right_parse() {
((__SEG_AT_RIGHT += 1))
}
____atomic_bottom_parse() {
____atomic_bottom_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -70,7 +73,8 @@ ____atomic_bottom_parse() {
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
}
____atomic_top() {
____atomic_top()
{
_TOP_LEFT=""
_TOP_RIGHT=""
__TOP_RIGHT_LEN=0
@ -96,7 +100,8 @@ ____atomic_top() {
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
}
____atomic_bottom() {
____atomic_bottom()
{
_BOTTOM=""
for seg in $___ATOMIC_BOTTOM; do
info="$(___atomic_prompt_"${seg}")"
@ -109,7 +114,8 @@ ____atomic_bottom() {
## Segments ##
##############
___atomic_prompt_user_info() {
___atomic_prompt_user_info()
{
color=$white
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
info="${IYellow}\u${IRed}@${IGreen}\h"
@ -117,14 +123,16 @@ ___atomic_prompt_user_info() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
}
___atomic_prompt_dir() {
___atomic_prompt_dir()
{
color=${IRed}
box="[|]${normal}"
info="\w"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___atomic_prompt_scm() {
___atomic_prompt_scm()
{
[ "${THEME_SHOW_SCM}" != "true" ] && return
color=$bold_green
box="${Line}[${IWhite}$(scm_char)] "
@ -132,7 +140,8 @@ ___atomic_prompt_scm() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___atomic_prompt_python() {
___atomic_prompt_python()
{
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
color=$bold_yellow
box="[|]"
@ -140,7 +149,8 @@ ___atomic_prompt_python() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
}
___atomic_prompt_ruby() {
___atomic_prompt_ruby()
{
[ "${THEME_SHOW_RUBY}" != "true" ] && return
color=$bold_white
box="[|]"
@ -148,16 +158,18 @@ ___atomic_prompt_ruby() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
}
___atomic_prompt_todo() {
[ "${THEME_SHOW_TODO}" != "true" ] \
|| [ -z "$(which todo.sh)" ] && return
___atomic_prompt_todo()
{
[ "${THEME_SHOW_TODO}" != "true" ] ||
[ -z "$(which todo.sh)" ] && return
color=$bold_white
box="[|]"
info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
}
___atomic_prompt_clock() {
___atomic_prompt_clock()
{
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
color=$THEME_CLOCK_COLOR
box="[|]"
@ -165,10 +177,11 @@ ___atomic_prompt_clock() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___atomic_prompt_battery() {
! _command_exists battery_percentage \
|| [ "${THEME_SHOW_BATTERY}" != "true" ] \
|| [ "$(battery_percentage)" = "no" ] && return
___atomic_prompt_battery()
{
! _command_exists battery_percentage ||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
[ "$(battery_percentage)" = "no" ] && return
batp=$(battery_percentage)
if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then
@ -186,13 +199,15 @@ ___atomic_prompt_battery() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___atomic_prompt_exitcode() {
___atomic_prompt_exitcode()
{
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
color=$bold_purple
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
}
___atomic_prompt_char() {
___atomic_prompt_char()
{
color=$white
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
@ -207,19 +222,22 @@ ___atomic_prompt_char() {
## cli ##
#########
__atomic_show() {
__atomic_show()
{
typeset _seg=${1:-}
shift
export "THEME_SHOW_${_seg}"=true
}
__atomic_hide() {
__atomic_hide()
{
typeset _seg=${1:-}
shift
export "THEME_SHOW_${_seg}"=false
}
_atomic_completion() {
_atomic_completion()
{
local cur _action actions segments
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
@ -239,7 +257,8 @@ _atomic_completion() {
return 0
}
atomic() {
atomic()
{
typeset action=${1:-}
shift
typeset segs=${*:-}
@ -303,16 +322,19 @@ ___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"}
## Prompt ##
############
__atomic_ps1() {
__atomic_ps1()
{
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
}
__atomic_ps2() {
__atomic_ps2()
{
color=$bold_white
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
}
_atomic_prompt() {
_atomic_prompt()
{
exitcode="$?"
PS1="$(__atomic_ps1)"

View File

@ -29,7 +29,8 @@ else
RESET="\033[m"
fi
function prompt_command() {
function prompt_command()
{
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]$(scm_prompt_info) \n\$ \[$RESET\]"
}

View File

@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
function prompt_command() {
function prompt_command()
{
#PS1="${bold_cyan}$(scm_char)${green}$(scm_prompt_info)${purple}$(ruby_version_prompt) ${yellow}\h ${reset_color}in ${green}\w ${reset_color}\n${green}→${reset_color} "
#PS1="\n${purple}\h: ${reset_color} ${green}\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}→${reset_color} "
#PS1="\n${cyan}\h: ${reset_color} ${yellow}\w\n${red}$(scm_char)${red}$(scm_prompt_info) ${green}→${reset_color} "

View File

@ -41,7 +41,8 @@ SCM_THEME_BRANCH_TRACK_PREFIX="${normal} ⤏ ${cyan}"
SCM_THEME_CURRENT_USER_PREFFIX='  '
SCM_GIT_SHOW_CURRENT_USER=false
function _git-uptream-remote-logo {
function _git-uptream-remote-logo
{
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
local remote remote_domain
@ -59,12 +60,14 @@ function _git-uptream-remote-logo {
esac
}
function git_prompt_info {
function git_prompt_info
{
git_prompt_vars
echo -e " on $SCM_GIT_CHAR_ICON_BRANCH $SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_GIT_AHEAD$SCM_GIT_BEHIND$SCM_GIT_STASH$SCM_SUFFIX"
}
function _exit-code {
function _exit-code
{
if [[ "$1" -ne 0 ]]; then
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
else
@ -72,7 +75,8 @@ function _exit-code {
fi
}
function _prompt {
function _prompt
{
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
command_duration=$(_command_duration)

View File

@ -91,7 +91,8 @@ RBFU_THEME_PROMPT_SUFFIX='|'
: "${HG_EXE:=$SCM_HG}"
: "${SVN_EXE:=$SCM_SVN}"
function _bash_it_appearance_scm_init() {
function _bash_it_appearance_scm_init()
{
GIT_EXE="$(type -P $SCM_GIT || true)"
P4_EXE="$(type -P $SCM_P4 || true)"
HG_EXE="$(type -P $SCM_HG || true)"
@ -108,7 +109,8 @@ function _bash_it_appearance_scm_init() {
}
_bash_it_appearance_scm_init
function scm {
function scm
{
if [[ "$SCM_CHECK" = false ]]; then
SCM=$SCM_NONE
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
@ -130,7 +132,8 @@ function scm {
fi
}
scm_prompt() {
scm_prompt()
{
local CHAR
CHAR="$(scm_char)"
local format=${SCM_PROMPT_FORMAT:-'[%s%s]'}
@ -141,7 +144,8 @@ scm_prompt() {
fi
}
function scm_prompt_char {
function scm_prompt_char
{
if [[ -z $SCM ]]; then scm; fi
if [[ $SCM == "$SCM_GIT" ]]; then
SCM_CHAR=$SCM_GIT_CHAR
@ -156,7 +160,8 @@ function scm_prompt_char {
fi
}
function scm_prompt_vars {
function scm_prompt_vars
{
scm
scm_prompt_char
SCM_DIRTY=0
@ -167,19 +172,22 @@ function scm_prompt_vars {
[[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return
}
function scm_prompt_info {
function scm_prompt_info
{
scm
scm_prompt_char
scm_prompt_info_common
}
function scm_prompt_char_info {
function scm_prompt_char_info
{
scm_prompt_char
echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
scm_prompt_info_common
}
function scm_prompt_info_common {
function scm_prompt_info_common
{
SCM_DIRTY=0
SCM_STATE=''
@ -195,12 +203,19 @@ function scm_prompt_info_common {
fi
# TODO: consider adding minimal status information for hg and svn
{ [[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return; } || true
{ [[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return; } || true
{ [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true
{
[[ ${SCM} == "${SCM_P4}" ]] && p4_prompt_info && return
} || true
{
[[ ${SCM} == "${SCM_HG}" ]] && hg_prompt_info && return
} || true
{
[[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return
} || true
}
function terraform_workspace_prompt {
function terraform_workspace_prompt
{
if _command_exists terraform; then
if [ -d .terraform ]; then
echo -e "$(terraform workspace show 2> /dev/null)"
@ -208,13 +223,15 @@ function terraform_workspace_prompt {
fi
}
function active_gcloud_account_prompt {
function active_gcloud_account_prompt
{
if _command_exists gcloud; then
echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)"
fi
}
function git_prompt_minimal_info {
function git_prompt_minimal_info
{
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
_git-hide-status && return
@ -232,7 +249,8 @@ function git_prompt_minimal_info {
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
}
function git_prompt_vars {
function git_prompt_vars
{
if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then
# we can use faster gitstatus
# use this variable in githelpers and below to choose gitstatus output
@ -310,7 +328,8 @@ function git_prompt_vars {
SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "")
}
function p4_prompt_vars {
function p4_prompt_vars
{
IFS=$'\t' read -r \
opened_count non_default_changes default_count \
add_file_count edit_file_count delete_file_count \
@ -330,7 +349,8 @@ function p4_prompt_vars {
SCM_SUFFIX=${P4_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX}
}
function svn_prompt_vars {
function svn_prompt_vars
{
if [[ -n $(svn status | head -c1 2> /dev/null) ]]; then
SCM_DIRTY=1
SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
@ -351,7 +371,8 @@ function svn_prompt_vars {
# - lets say we cd into ~/Projects/Foo/Bar
# - .hg is located in ~/Projects/Foo/.hg
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
function get_hg_root {
function get_hg_root
{
local CURRENT_DIR="${PWD}"
while [[ "${CURRENT_DIR:-/}" != "/" ]]; do
@ -364,7 +385,8 @@ function get_hg_root {
done
}
function hg_prompt_vars {
function hg_prompt_vars
{
if [[ -n $(hg status 2> /dev/null) ]]; then
SCM_DIRTY=1
SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
@ -394,7 +416,8 @@ function hg_prompt_vars {
fi
}
function nvm_version_prompt {
function nvm_version_prompt
{
local node
if _is_function nvm; then
node=$(nvm current 2> /dev/null)
@ -403,11 +426,13 @@ function nvm_version_prompt {
fi
}
function node_version_prompt {
function node_version_prompt
{
echo -e "$(nvm_version_prompt)"
}
function rvm_version_prompt {
function rvm_version_prompt
{
if which rvm &> /dev/null; then
rvm=$(rvm-prompt) || return
if [ -n "$rvm" ]; then
@ -416,7 +441,8 @@ function rvm_version_prompt {
fi
}
function rbenv_version_prompt {
function rbenv_version_prompt
{
if which rbenv &> /dev/null; then
rbenv=$(rbenv version-name) || return
rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
@ -426,13 +452,15 @@ function rbenv_version_prompt {
fi
}
function rbfu_version_prompt {
function rbfu_version_prompt
{
if [[ $RBFU_RUBY_VERSION ]]; then
echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}"
fi
}
function chruby_version_prompt {
function chruby_version_prompt
{
if _is_function chruby; then
if _is_function chruby_auto; then
chruby_auto
@ -447,43 +475,51 @@ function chruby_version_prompt {
fi
}
function ruby_version_prompt {
function ruby_version_prompt
{
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
fi
}
function k8s_context_prompt {
function k8s_context_prompt
{
echo -e "$(kubectl config current-context 2> /dev/null)"
}
function k8s_namespace_prompt {
function k8s_namespace_prompt
{
echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)"
}
function virtualenv_prompt {
function virtualenv_prompt
{
if [[ -n "$VIRTUAL_ENV" ]]; then
virtualenv=$(basename "$VIRTUAL_ENV")
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
fi
}
function condaenv_prompt {
function condaenv_prompt
{
if [[ $CONDA_DEFAULT_ENV ]]; then
echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}"
fi
}
function py_interp_prompt {
function py_interp_prompt
{
py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return
echo -e "${PYTHON_THEME_PROMPT_PREFIX}${py_version}${PYTHON_THEME_PROMPT_SUFFIX}"
}
function python_version_prompt {
function python_version_prompt
{
echo -e "$(virtualenv_prompt)$(condaenv_prompt)$(py_interp_prompt)"
}
function git_user_info {
function git_user_info
{
# support two or more initials, set by 'git pair' plugin
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
# if `user.initials` weren't set, attempt to extract initials from `user.name`
@ -491,7 +527,8 @@ function git_user_info {
[[ -n "${SCM_CURRENT_USER}" ]] && printf "%s" "$SCM_THEME_CURRENT_USER_PREFFIX$SCM_CURRENT_USER$SCM_THEME_CURRENT_USER_SUFFIX"
}
function clock_char {
function clock_char
{
CLOCK_CHAR=${THEME_CLOCK_CHAR:-"⌚"}
CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"}
SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
@ -501,7 +538,8 @@ function clock_char {
fi
}
function clock_prompt {
function clock_prompt
{
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
[ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
@ -513,44 +551,52 @@ function clock_prompt {
fi
}
function user_host_prompt {
function user_host_prompt
{
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
fi
}
# backwards-compatibility
function git_prompt_info {
function git_prompt_info
{
_git-hide-status && return
git_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
}
function p4_prompt_info() {
function p4_prompt_info()
{
p4_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
}
function svn_prompt_info {
function svn_prompt_info
{
svn_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
}
function hg_prompt_info() {
function hg_prompt_info()
{
hg_prompt_vars
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
}
function scm_char {
function scm_char
{
scm_prompt_char
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
}
function prompt_char {
function prompt_char
{
scm_char
}
function battery_char {
function battery_char
{
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
echo -e "${bold_red:-}$(battery_percentage)%"
fi
@ -558,7 +604,8 @@ function battery_char {
if ! _command_exists battery_charge; then
# if user has installed battery plugin, skip this...
function battery_charge() {
function battery_charge()
{
# no op
echo -n
}
@ -567,13 +614,15 @@ fi
# The battery_char function depends on the presence of the battery_percentage function.
# If battery_percentage is not defined, then define battery_char as a no-op.
if ! _command_exists battery_percentage; then
function battery_char() {
function battery_char()
{
# no op
echo -n
}
fi
function aws_profile {
function aws_profile
{
if [[ $AWS_DEFAULT_PROFILE ]]; then
echo -e "${AWS_DEFAULT_PROFILE}"
else
@ -581,7 +630,8 @@ function aws_profile {
fi
}
function __check_precmd_conflict() {
function __check_precmd_conflict()
{
local f
for f in "${precmd_functions[@]}"; do
if [[ "${f}" == "${1}" ]]; then
@ -591,7 +641,8 @@ function __check_precmd_conflict() {
return 1
}
function safe_append_prompt_command {
function safe_append_prompt_command
{
local prompt_re
if [ "${__bp_imported:-missing}" == "defined" ]; then
@ -619,7 +670,8 @@ function safe_append_prompt_command {
fi
}
function _save-and-reload-history() {
function _save-and-reload-history()
{
local autosave=${1:-0}
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
}

View File

@ -3,7 +3,8 @@
# shellcheck disable=SC2154 #TODO: fix these all.
# Detect whether a reboot is required
function show_reboot_required() {
function show_reboot_required()
{
if [ -n "$_bf_prompt_reboot_info" ]; then
if [ -f /var/run/reboot-required ]; then
printf "Reboot required!"
@ -12,7 +13,8 @@ function show_reboot_required() {
}
# Set different host color for local and remote sessions
function set_host_color() {
function set_host_color()
{
# Detect if connection is through SSH
if [[ -n $SSH_CLIENT ]]; then
printf '%s' "${lime_yellow}"
@ -22,7 +24,8 @@ function set_host_color() {
}
# Set different username color for users and root
function set_user_color() {
function set_user_color()
{
case $(id -u) in
0)
printf '%s' "${red}"
@ -36,7 +39,8 @@ function set_user_color() {
# Define custom colors we need
# non-printable bytes in PS1 need to be contained within \[ \].
# Otherwise, bash will count them in the length of the prompt
function set_custom_colors() {
function set_custom_colors()
{
dark_grey="\[$(tput setaf 8)\]"
light_grey="\[$(tput setaf 248)\]"
@ -47,11 +51,13 @@ function set_custom_colors() {
powder_blue="\[$(tput setaf 153)\]"
}
__ps_time() {
__ps_time()
{
printf '%s' "$(clock_prompt)${normal}\n"
}
function prompt_command() {
function prompt_command()
{
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
ps_username="$(set_user_color)\u${normal}"

View File

@ -16,7 +16,8 @@ else
user_host="${bold_green}\u@\h${normal}${reset_color}"
fi
function prompt_command() {
function prompt_command()
{
local current_dir=" ${bold_blue}\w${normal}${reset_color}"
PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}"
}

View File

@ -14,7 +14,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
CONDAENV_THEME_PROMPT_SUFFIX="|"
function prompt_command() {
function prompt_command()
{
PS1="\n${yellow}$(python_version_prompt) " # Name of virtual env followed by python version
PS1+="${purple}\h "
PS1+="${reset_color}in "

View File

@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
__bobby_clock() {
__bobby_clock()
{
printf '%s' "$(clock_prompt) "
if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then
@ -23,7 +24,8 @@ __bobby_clock() {
fi
}
function prompt_command() {
function prompt_command()
{
PS1="\n$(battery_char) $(__bobby_clock)"
PS1+="${yellow}$(ruby_version_prompt) "
PS1+="${purple}\h "

View File

@ -9,7 +9,8 @@
## Parsers ##
#############
____brainy_top_left_parse() {
____brainy_top_left_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -24,7 +25,8 @@ ____brainy_top_left_parse() {
_TOP_LEFT+=" "
}
____brainy_top_right_parse() {
____brainy_top_right_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -41,7 +43,8 @@ ____brainy_top_right_parse() {
((__SEG_AT_RIGHT += 1))
}
____brainy_bottom_parse() {
____brainy_bottom_parse()
{
ifs_old="${IFS}"
IFS="|"
read -r -a args <<< "$@"
@ -50,7 +53,8 @@ ____brainy_bottom_parse() {
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
}
____brainy_top() {
____brainy_top()
{
_TOP_LEFT=""
_TOP_RIGHT=""
__TOP_RIGHT_LEN=0
@ -76,7 +80,8 @@ ____brainy_top() {
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
}
____brainy_bottom() {
____brainy_bottom()
{
_BOTTOM=""
for seg in $___BRAINY_BOTTOM; do
info="$(___brainy_prompt_"${seg}")"
@ -89,7 +94,8 @@ ____brainy_bottom() {
## Segments ##
##############
___brainy_prompt_user_info() {
___brainy_prompt_user_info()
{
color=$bold_blue
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
if sudo -vn 1> /dev/null 2>&1; then
@ -105,14 +111,16 @@ ___brainy_prompt_user_info() {
fi
}
___brainy_prompt_dir() {
___brainy_prompt_dir()
{
color=$bold_yellow
box="[|]"
info="\w"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_scm() {
___brainy_prompt_scm()
{
[ "${THEME_SHOW_SCM}" != "true" ] && return
color=$bold_green
box="$(scm_char) "
@ -120,7 +128,8 @@ ___brainy_prompt_scm() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_python() {
___brainy_prompt_python()
{
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
color=$bold_yellow
box="[|]"
@ -128,7 +137,8 @@ ___brainy_prompt_python() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
}
___brainy_prompt_ruby() {
___brainy_prompt_ruby()
{
[ "${THEME_SHOW_RUBY}" != "true" ] && return
color=$bold_white
box="[|]"
@ -136,16 +146,18 @@ ___brainy_prompt_ruby() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
}
___brainy_prompt_todo() {
[ "${THEME_SHOW_TODO}" != "true" ] \
|| [ -z "$(which todo.sh)" ] && return
___brainy_prompt_todo()
{
[ "${THEME_SHOW_TODO}" != "true" ] ||
[ -z "$(which todo.sh)" ] && return
color=$bold_white
box="[|]"
info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')"
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
}
___brainy_prompt_clock() {
___brainy_prompt_clock()
{
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
color=$THEME_CLOCK_COLOR
box="[|]"
@ -153,10 +165,11 @@ ___brainy_prompt_clock() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_purple}" "${box}"
}
___brainy_prompt_battery() {
! _command_exists battery_percentage \
|| [ "${THEME_SHOW_BATTERY}" != "true" ] \
|| [ "$(battery_percentage)" = "no" ] && return
___brainy_prompt_battery()
{
! _command_exists battery_percentage ||
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
[ "$(battery_percentage)" = "no" ] && return
info=$(battery_percentage)
color=$bold_green
@ -173,13 +186,15 @@ ___brainy_prompt_battery() {
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
}
___brainy_prompt_exitcode() {
___brainy_prompt_exitcode()
{
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
color=$bold_purple
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
}
___brainy_prompt_char() {
___brainy_prompt_char()
{
color=$bold_white
prompt_char="${__BRAINY_PROMPT_CHAR_PS1}"
printf "%s|%s" "${color}" "${prompt_char}"
@ -189,19 +204,22 @@ ___brainy_prompt_char() {
## cli ##
#########
__brainy_show() {
__brainy_show()
{
typeset _seg=${1:-}
shift
export "THEME_SHOW_${_seg}"=true
}
__brainy_hide() {
__brainy_hide()
{
typeset _seg=${1:-}
shift
export "THEME_SHOW_${_seg}"=false
}
_brainy_completion() {
_brainy_completion()
{
local cur _action actions segments
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
@ -221,7 +239,8 @@ _brainy_completion() {
return 0
}
brainy() {
brainy()
{
typeset action=${1:-}
shift
typeset segs=${*:-}
@ -284,16 +303,19 @@ ___BRAINY_BOTTOM=${___BRAINY_BOTTOM:-"exitcode char"}
## Prompt ##
############
__brainy_ps1() {
__brainy_ps1()
{
printf "%s%s%s" "$(____brainy_top)" "$(____brainy_bottom)" "${normal}"
}
__brainy_ps2() {
__brainy_ps2()
{
color=$bold_white
printf "%s%s%s" "${color}" "${__BRAINY_PROMPT_CHAR_PS2} " "${normal}"
}
_brainy_prompt() {
_brainy_prompt()
{
exitcode="$?"
PS1="$(__brainy_ps1)"

View File

@ -11,13 +11,15 @@ SCM_GIT_CHAR="${bold_green}±${normal}"
SCM_SVN_CHAR="${bold_cyan}${normal}"
SCM_HG_CHAR="${bold_red}${normal}"
is_vim_shell() {
is_vim_shell()
{
if [ -n "$VIMRUNTIME" ]; then
echo "[${cyan}vim shell${normal}]"
fi
}
prompt() {
prompt()
{
SCM_PROMPT_FORMAT=' %s (%s)'
PS1="${white}${background_blue} \u${normal}${background_blue}@${red}${background_blue}\h $(clock_prompt) ${reset_color}${normal} $(battery_charge)\n${bold_black}${background_white} \w ${normal}$(scm_prompt)$(is_vim_shell)\n${white}>${normal} "
}

View File

@ -2,7 +2,8 @@
# shellcheck disable=SC2034 # Expected behavior for themes.
# shellcheck disable=SC2154 #TODO: fix these all.
function prompt_command() {
function prompt_command()
{
PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue}${bold_blue} ${reset_color} ${normal}"
}

View File

@ -1,7 +1,8 @@
# shellcheck shell=bash
if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then
_command_duration() {
_command_duration()
{
echo -n
}
return
@ -16,17 +17,20 @@ COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'}
trap _command_duration_delete_temp_file EXIT HUP INT TERM
_command_duration_delete_temp_file() {
_command_duration_delete_temp_file()
{
if [[ -f "$COMMAND_DURATION_FILE" ]]; then
rm -f "$COMMAND_DURATION_FILE"
fi
}
_command_duration_pre_exec() {
_command_duration_pre_exec()
{
date +%s.%1N > "$COMMAND_DURATION_FILE"
}
_command_duration() {
_command_duration()
{
local command_duration command_start current_time
local minutes seconds deciseconds
local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds

View File

@ -7,7 +7,8 @@ SCM_THEME_PROMPT_SUFFIX="${bold_green} ] "
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
prompt_command() {
prompt_command()
{
if [ "$(whoami)" = root ]; then
cursor_color="${bold_red}"
user_color="${green}"

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
function _git-symbolic-ref {
function _git-symbolic-ref
{
git symbolic-ref -q HEAD 2> /dev/null
}
@ -8,7 +9,8 @@ function _git-symbolic-ref {
# but this can be different when two branches are pointing to the
# same commit. _git-branch is used to explicitly choose the checked-out
# branch.
function _git-branch {
function _git-branch
{
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1
else
@ -16,7 +18,8 @@ function _git-branch {
fi
}
function _git-tag {
function _git-tag
{
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}"
else
@ -24,11 +27,13 @@ function _git-tag {
fi
}
function _git-commit-description {
function _git-commit-description
{
git describe --contains --all 2> /dev/null
}
function _git-short-sha {
function _git-short-sha
{
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
echo ${VCS_STATUS_COMMIT:0:7}
else
@ -37,7 +42,8 @@ function _git-short-sha {
}
# Try the checked-out branch first to avoid collision with branches pointing to the same ref.
function _git-friendly-ref {
function _git-friendly-ref
{
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
_git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus
else
@ -45,17 +51,20 @@ function _git-friendly-ref {
fi
}
function _git-num-remotes {
function _git-num-remotes
{
git remote | wc -l
}
function _git-upstream {
function _git-upstream
{
local ref
ref="$(_git-symbolic-ref)" || return 1
git for-each-ref --format="%(upstream:short)" "${ref}"
}
function _git-upstream-remote {
function _git-upstream-remote
{
local upstream
upstream="$(_git-upstream)" || return 1
@ -64,7 +73,8 @@ function _git-upstream-remote {
echo "${upstream%"/${branch}"}"
}
function _git-upstream-branch {
function _git-upstream-branch
{
local ref
ref="$(_git-symbolic-ref)" || return 1
@ -74,25 +84,30 @@ function _git-upstream-branch {
git for-each-ref --format="%(upstream:strip=3)" "${ref}" 2> /dev/null || git for-each-ref --format="%(upstream)" "${ref}" | sed -e "s/.*\/.*\/.*\///"
}
function _git-upstream-behind-ahead {
function _git-upstream-behind-ahead
{
git rev-list --left-right --count "$(_git-upstream)...HEAD" 2> /dev/null
}
function _git-upstream-branch-gone {
function _git-upstream-branch-gone
{
[[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]]
}
function _git-hide-status {
function _git-hide-status
{
[[ "$(git config --get bash-it.hide-status)" == "1" ]]
}
function _git-status {
function _git-status
{
local git_status_flags=
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true
git status --porcelain ${git_status_flags} 2> /dev/null
}
function _git-status-counts {
function _git-status-counts
{
_git-status | awk '
BEGIN {
untracked=0;
@ -116,7 +131,8 @@ function _git-status-counts {
}'
}
function _git-remote-info {
function _git-remote-info
{
# prompt handling only, reimplement because patching the routine below gets ugly
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
@ -134,7 +150,7 @@ function _git-remote-info {
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="${VCS_STATUS_REMOTE_BRANCH}"
fi
if [[ -n "${remote_info}" ]];then
if [[ -n "${remote_info}" ]]; then
# no support for gone remote branches in gitstatusd
local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
echo "${branch_prefix}${remote_info}"
@ -155,7 +171,7 @@ function _git-remote-info {
elif [[ ${same_branch_name} != "true" ]]; then
remote_info="\$(_git-upstream-branch)"
fi
if [[ -n "${remote_info}" ]];then
if [[ -n "${remote_info}" ]]; then
local branch_prefix
if _git-upstream-branch-gone; then
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
@ -168,7 +184,8 @@ function _git-remote-info {
}
# Unused by bash-it, present for API compatibility
function git_status_summary {
function git_status_summary
{
awk '
BEGIN {
untracked=0;

View File

@ -22,13 +22,15 @@ esac
PS3=">> "
is_vim_shell() {
is_vim_shell()
{
if [ -n "$VIMRUNTIME" ]; then
echo "[${cyan}vim shell${normal}]"
fi
}
detect_venv() {
detect_venv()
{
python_venv=""
# Detect python venv
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
@ -38,7 +40,8 @@ detect_venv() {
fi
}
prompt() {
prompt()
{
SCM_PROMPT_FORMAT='[%s][%s]'
retval=$?
if [[ retval -ne 0 ]]; then

View File

@ -1,10 +1,12 @@
#!/usr/bin/env bash
function _p4-opened {
function _p4-opened
{
timeout 2.0s p4 opened -s 2> /dev/null
}
function _p4-opened-counts {
function _p4-opened-counts
{
# Return the following counts seperated by tabs:
# - count of opened files
# - count of pending changesets (other than defaults)

View File

@ -5,7 +5,8 @@
# Define this here so it can be used by all of the Powerline themes
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
function set_color() {
function set_color()
{
set +u
if [[ "${1}" != "-" ]]; then
fg="38;5;${1}"
@ -17,7 +18,8 @@ function set_color() {
echo -e "\[\033[${fg}${bg}m\]"
}
function __powerline_user_info_prompt() {
function __powerline_user_info_prompt()
{
local user_info=""
local color=${USER_INFO_THEME_PROMPT_COLOR}
@ -43,7 +45,8 @@ function __powerline_user_info_prompt() {
[[ -n "${user_info}" ]] && echo "${user_info}|${color}"
}
function __powerline_terraform_prompt() {
function __powerline_terraform_prompt()
{
local terraform_workspace=""
if [ -d .terraform ]; then
@ -52,21 +55,24 @@ function __powerline_terraform_prompt() {
fi
}
function __powerline_gcloud_prompt() {
function __powerline_gcloud_prompt()
{
local active_gcloud_account=""
active_gcloud_account="$(active_gcloud_account_prompt)"
[[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR}"
}
function __powerline_node_prompt() {
function __powerline_node_prompt()
{
local node_version=""
node_version="$(node_version_prompt)"
[[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}"
}
function __powerline_ruby_prompt() {
function __powerline_ruby_prompt()
{
local ruby_version=""
if _command_exists rvm; then
@ -78,7 +84,8 @@ function __powerline_ruby_prompt() {
[[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}"
}
function __powerline_k8s_context_prompt() {
function __powerline_k8s_context_prompt()
{
local kubernetes_context=""
if _command_exists kubectl; then
@ -88,7 +95,8 @@ function __powerline_k8s_context_prompt() {
[[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR}"
}
function __powerline_k8s_namespace_prompt() {
function __powerline_k8s_namespace_prompt()
{
local kubernetes_namespace=""
if _command_exists kubectl; then
@ -98,7 +106,8 @@ function __powerline_k8s_namespace_prompt() {
[[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR}"
}
function __powerline_python_venv_prompt() {
function __powerline_python_venv_prompt()
{
set +u
local python_venv=""
@ -112,7 +121,8 @@ function __powerline_python_venv_prompt() {
[[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}"
}
function __powerline_scm_prompt() {
function __powerline_scm_prompt()
{
local color=""
local scm_prompt=""
@ -141,23 +151,28 @@ function __powerline_scm_prompt() {
fi
}
function __powerline_cwd_prompt() {
function __powerline_cwd_prompt()
{
echo "\w|${CWD_THEME_PROMPT_COLOR}"
}
function __powerline_hostname_prompt() {
function __powerline_hostname_prompt()
{
echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}"
}
function __powerline_wd_prompt() {
function __powerline_wd_prompt()
{
echo "\W|${CWD_THEME_PROMPT_COLOR}"
}
function __powerline_clock_prompt() {
function __powerline_clock_prompt()
{
echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}"
}
function __powerline_battery_prompt() {
function __powerline_battery_prompt()
{
local color="" battery_status
battery_status="$(battery_percentage 2> /dev/null)"
@ -176,25 +191,29 @@ function __powerline_battery_prompt() {
fi
}
function __powerline_in_vim_prompt() {
function __powerline_in_vim_prompt()
{
if [[ -n "$VIMRUNTIME" ]]; then
echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}"
fi
}
function __powerline_aws_profile_prompt() {
function __powerline_aws_profile_prompt()
{
if [[ -n "${AWS_PROFILE}" ]]; then
echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}"
fi
}
function __powerline_in_toolbox_prompt() {
function __powerline_in_toolbox_prompt()
{
if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then
echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}"
fi
}
function __powerline_shlvl_prompt() {
function __powerline_shlvl_prompt()
{
if [[ "${SHLVL}" -gt 1 ]]; then
local prompt="${SHLVL_THEME_PROMPT_CHAR}"
local level=$((SHLVL - 1))
@ -202,7 +221,8 @@ function __powerline_shlvl_prompt() {
fi
}
function __powerline_dirstack_prompt() {
function __powerline_dirstack_prompt()
{
if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then
local depth=$((${#DIRSTACK[@]} - 1))
local prompt="${DIRSTACK_THEME_PROMPT_CHAR}"
@ -213,21 +233,25 @@ function __powerline_dirstack_prompt() {
fi
}
function __powerline_history_number_prompt() {
function __powerline_history_number_prompt()
{
echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}"
}
function __powerline_command_number_prompt() {
function __powerline_command_number_prompt()
{
echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}"
}
function __powerline_duration_prompt() {
function __powerline_duration_prompt()
{
local duration
duration=$(_command_duration)
[[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}"
}
function __powerline_left_segment() {
function __powerline_left_segment()
{
local params
IFS="|" read -ra params <<< "${1}"
local pad_before_segment=" "
@ -257,15 +281,18 @@ function __powerline_left_segment() {
((SEGMENTS_AT_LEFT += 1))
}
function __powerline_left_last_segment_padding() {
function __powerline_left_last_segment_padding()
{
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
}
function __powerline_last_status_prompt() {
function __powerline_last_status_prompt()
{
[[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}"
}
function __powerline_prompt_command() {
function __powerline_prompt_command()
{
local last_status="$?" ## always the first
local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color

View File

@ -20,7 +20,8 @@ VIRTUALENV_THEME_PROMPT_SUFFIX=")"
# export LSCOLORS="Gxfxcxdxbxegedabagacad"
# export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:'
pure_prompt() {
pure_prompt()
{
ps_host="${bold_blue}\h${normal}"
ps_user="${green}\u${normal}"
ps_user_mark="${green} $ ${normal}"

View File

@ -16,7 +16,8 @@ STATUS_THEME_PROMPT_BAD="${bold_red}${reset_color}${normal} "
STATUS_THEME_PROMPT_OK="${bold_green}${reset_color}${normal} "
PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}"
venv_prompt() {
venv_prompt()
{
python_venv=""
# Detect python venv
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
@ -27,7 +28,8 @@ venv_prompt() {
[[ -n "${python_venv}" ]] && echo "${python_venv}"
}
function prompt_command() {
function prompt_command()
{
local retval=$? ret_status
ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")"
PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)"

View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash
if [ -z "$BASH_IT" ];
then
if [ -z "$BASH_IT" ]; then
BASH_IT="$HOME/.bash_it"
fi