`shfmt`
parent
8bcc44fa13
commit
70f3b56dcc
|
|
@ -194,11 +194,13 @@ case $OSTYPE in
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
function gdv() {
|
function gdv()
|
||||||
|
{
|
||||||
git diff --ignore-all-space "$@" | vim -R -
|
git diff --ignore-all-space "$@" | vim -R -
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_default_branch() {
|
function get_default_branch()
|
||||||
|
{
|
||||||
if git branch | grep -q main; then
|
if git branch | grep -q main; then
|
||||||
echo main
|
echo main
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,11 @@ alias vimh='vim -c ":h | only"'
|
||||||
|
|
||||||
# open vim in new tab is taken from
|
# open vim in new tab is taken from
|
||||||
# http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek
|
# http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek
|
||||||
_command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; }
|
_command_exists mvim && function mvimt
|
||||||
_command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; }
|
{
|
||||||
|
command mvim --remote-tab-silent "$@" || command mvim "$@"
|
||||||
|
}
|
||||||
|
_command_exists gvim && function gvimt
|
||||||
|
{
|
||||||
|
command gvim --remote-tab-silent "$@" || command gvim "$@"
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
cite "about-completion"
|
cite "about-completion"
|
||||||
about-completion "composer completion"
|
about-completion "composer completion"
|
||||||
|
|
||||||
function __composer_completion() {
|
function __composer_completion()
|
||||||
|
{
|
||||||
local cur coms opts com words
|
local cur coms opts com words
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
_get_comp_words_by_ref -n : cur words
|
_get_comp_words_by_ref -n : cur words
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
__dart_completion() {
|
__dart_completion()
|
||||||
|
{
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local prev=$(_get_pword)
|
local prev=$(_get_pword)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
function __dmidecode_completion() {
|
function __dmidecode_completion()
|
||||||
|
{
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local prev=$(_get_pword)
|
local prev=$(_get_pword)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
cite "about-completion"
|
cite "about-completion"
|
||||||
about-completion "gem completion"
|
about-completion "gem completion"
|
||||||
|
|
||||||
__gem_completion() {
|
__gem_completion()
|
||||||
|
{
|
||||||
local cur=${COMP_WORDS[COMP_CWORD]}
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
local prev=${COMP_WORDS[COMP_CWORD - 1]}
|
local prev=${COMP_WORDS[COMP_CWORD - 1]}
|
||||||
case $prev in
|
case $prev in
|
||||||
|
|
|
||||||
|
|
@ -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
|
# returns 0 iff the file whose path is given as 1st argument
|
||||||
# exists and has last been modified in the last $2 seconds
|
# exists and has last been modified in the last $2 seconds
|
||||||
# returns 1 otherwise
|
# returns 1 otherwise
|
||||||
_KAC_is_file_newer_than() {
|
_KAC_is_file_newer_than()
|
||||||
|
{
|
||||||
[ -f "$1" ] || return 1
|
[ -f "$1" ] || return 1
|
||||||
[ $(($(date +%s) - $($_KAC_STAT_COMMAND "$1"))) -gt "$2" ] && return 1 || return 0
|
[ $(($(date +%s) - $($_KAC_STAT_COMMAND "$1"))) -gt "$2" ] && return 1 || return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# helper function for _KAC_get_and_regen_cache, see doc below
|
# helper function for _KAC_get_and_regen_cache, see doc below
|
||||||
_KAC_regen_cache() {
|
_KAC_regen_cache()
|
||||||
|
{
|
||||||
local CACHE_NAME=$1
|
local CACHE_NAME=$1
|
||||||
local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
|
local CACHE_PATH="$_KNIFE_AUTOCOMPLETE_CACHE_DIR/$CACHE_NAME"
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
@ -54,12 +56,14 @@ _KAC_regen_cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# cached files can't have spaces in their names
|
# cached files can't have spaces in their names
|
||||||
_KAC_get_cache_name_from_command() {
|
_KAC_get_cache_name_from_command()
|
||||||
|
{
|
||||||
echo "${@/ /_SPACE_}"
|
echo "${@/ /_SPACE_}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# the reverse operation from the function above
|
# the reverse operation from the function above
|
||||||
_KAC_get_command_from_cache_name() {
|
_KAC_get_command_from_cache_name()
|
||||||
|
{
|
||||||
echo "${@/_SPACE_/ }"
|
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
|
# in either case, it regenerates the cache, and sets the _KAC_CACHE_PATH env variable
|
||||||
# for obvious reason, do NOT call that in a sub-shell (in particular, no piping)
|
# for obvious reason, do NOT call that in a sub-shell (in particular, no piping)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
_KAC_get_and_regen_cache() {
|
_KAC_get_and_regen_cache()
|
||||||
|
{
|
||||||
# the cache name can't have space in it
|
# the cache name can't have space in it
|
||||||
local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@")
|
local CACHE_NAME=$(_KAC_get_cache_name_from_command "$@")
|
||||||
local REGEN_CMD="_KAC_regen_cache $CACHE_NAME $*"
|
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
|
# performs two things: first, deletes all obsolete temp files
|
||||||
# then refreshes stale caches that haven't been called in a long time
|
# then refreshes stale caches that haven't been called in a long time
|
||||||
_KAC_clean_cache() {
|
_KAC_clean_cache()
|
||||||
|
{
|
||||||
local FILE CMD
|
local FILE CMD
|
||||||
# delete all obsolete temp files, could be lingering there for any kind of crash in the caching process
|
# 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
|
for FILE in "$_KAC_CACHE_TMP_DIR"/*; do
|
||||||
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" || rm -f "$FILE"
|
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" || rm -f "$FILE"
|
||||||
done
|
done
|
||||||
# refresh really stale caches
|
# refresh really stale caches
|
||||||
find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' \
|
find "$_KNIFE_AUTOCOMPLETE_CACHE_DIR" -maxdepth 1 -type f -not -name '.*' |
|
||||||
| while read -r FILE; do
|
while read -r FILE; do
|
||||||
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" && continue
|
_KAC_is_file_newer_than "$FILE" "$_KNIFE_AUTOCOMPLETE_MAX_CACHE_AGE" && continue
|
||||||
# first let's get the original command
|
# first let's get the original command
|
||||||
CMD=$(_KAC_get_command_from_cache_name "$(basename "$FILE")")
|
CMD=$(_KAC_get_command_from_cache_name "$(basename "$FILE")")
|
||||||
|
|
@ -109,14 +115,16 @@ _KAC_clean_cache() {
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
# returns all the possible knife sub-commands
|
# returns all the possible knife sub-commands
|
||||||
_KAC_knife_commands() {
|
_KAC_knife_commands()
|
||||||
|
{
|
||||||
knife --help | grep -E "^knife" | sed -E 's/ \(options\)//g'
|
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
|
# 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
|
# 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
|
# 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 PREVIOUS="knife"
|
||||||
local I=1
|
local I=1
|
||||||
local CURRENT
|
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...)
|
# (i.e. handles "plural" arguments such as knife cookbook upload cookbook1 cookbook2 and so on...)
|
||||||
# assumes the current base command is complete
|
# assumes the current base command is complete
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
_KAC_get_current_arg_position() {
|
_KAC_get_current_arg_position()
|
||||||
|
{
|
||||||
local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1))
|
local CURRENT_ARG_POS=$((_KAC_CURRENT_COMMAND_NB_WORDS + 1))
|
||||||
local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH")
|
local COMPLETE_COMMAND=$(grep -E "^$_KAC_CURRENT_COMMAND" "$_KAC_CACHE_PATH")
|
||||||
local CURRENT_ARG
|
local CURRENT_ARG
|
||||||
|
|
@ -150,7 +159,8 @@ _KAC_get_current_arg_position() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# the actual auto-complete function
|
# the actual auto-complete function
|
||||||
_knife() {
|
_knife()
|
||||||
|
{
|
||||||
_KAC_get_and_regen_cache _KAC_knife_commands
|
_KAC_get_and_regen_cache _KAC_knife_commands
|
||||||
local RAW_LIST ITEM REGEN_CMD ARG_POSITION
|
local RAW_LIST ITEM REGEN_CMD ARG_POSITION
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
_command_exists laravel || return
|
_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 OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new')
|
||||||
local _opt_
|
local _opt_
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
cite "about-completion"
|
cite "about-completion"
|
||||||
about-completion "lerna(javascript project manager tool) completion"
|
about-completion "lerna(javascript project manager tool) completion"
|
||||||
|
|
||||||
function __lerna_completion() {
|
function __lerna_completion()
|
||||||
|
{
|
||||||
local cur compls
|
local cur compls
|
||||||
|
|
||||||
# The currently-being-completed word.
|
# The currently-being-completed word.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
__ngrok_completion() {
|
__ngrok_completion()
|
||||||
|
{
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local prev=$(_get_pword)
|
local prev=$(_get_pword)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
function __notify-send_completions() {
|
function __notify-send_completions()
|
||||||
|
{
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local curr=$(_get_cword)
|
local curr=$(_get_cword)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
# So that pip is in the system's path.
|
# So that pip is in the system's path.
|
||||||
_command_exists pip || return
|
_command_exists pip || return
|
||||||
|
|
||||||
function __bash_it_complete_pip() {
|
function __bash_it_complete_pip()
|
||||||
|
{
|
||||||
if _command_exists _pip_completion; then
|
if _command_exists _pip_completion; then
|
||||||
complete -o default -F _pip_completion pip
|
complete -o default -F _pip_completion pip
|
||||||
_pip_completion "$@"
|
_pip_completion "$@"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@
|
||||||
# So that pip3 is in the system's path.
|
# So that pip3 is in the system's path.
|
||||||
_command_exists pip3 || return
|
_command_exists pip3 || return
|
||||||
|
|
||||||
function __bash_it_complete_pip3() {
|
function __bash_it_complete_pip3()
|
||||||
|
{
|
||||||
if _command_exists _pip_completion; then
|
if _command_exists _pip_completion; then
|
||||||
complete -o default -F _pip_completion pip3
|
complete -o default -F _pip_completion pip3
|
||||||
_pip_completion "$@"
|
_pip_completion "$@"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
function _sdkman_complete() {
|
function _sdkman_complete()
|
||||||
|
{
|
||||||
local CANDIDATES
|
local CANDIDATES
|
||||||
local CANDIDATE_VERSIONS
|
local CANDIDATE_VERSIONS
|
||||||
local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}"
|
local SDKMAN_CANDIDATES_CSV="${SDKMAN_CANDIDATES_CSV:-}"
|
||||||
|
|
@ -48,13 +49,15 @@ function _sdkman_complete() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function _sdkman_candidate_local_versions() {
|
function _sdkman_candidate_local_versions()
|
||||||
|
{
|
||||||
|
|
||||||
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1")
|
CANDIDATE_VERSIONS=$(__sdkman_cleanup_local_versions "$1")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _sdkman_candidate_all_versions() {
|
function _sdkman_candidate_all_versions()
|
||||||
|
{
|
||||||
|
|
||||||
candidate="$1"
|
candidate="$1"
|
||||||
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate")
|
CANDIDATE_LOCAL_VERSIONS=$(__sdkman_cleanup_local_versions "$candidate")
|
||||||
|
|
@ -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 ',' ' '
|
__sdkman_build_version_csv "$1" | tr ',' ' '
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
__vuejs_completion() {
|
__vuejs_completion()
|
||||||
|
{
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
local prev=$(_get_pword)
|
local prev=$(_get_pword)
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
_command_exists wpscan || return
|
_command_exists wpscan || return
|
||||||
|
|
||||||
function __wpscan_completion() {
|
function __wpscan_completion()
|
||||||
|
{
|
||||||
local _opt_
|
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')
|
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=()
|
COMPREPLY=()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ if [ "$file" != "clean_files.txt" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function compare_lines() {
|
function compare_lines()
|
||||||
|
{
|
||||||
prev=""
|
prev=""
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
# Skip unimportant lines
|
# Skip unimportant lines
|
||||||
|
|
|
||||||
30
install.sh
30
install.sh
|
|
@ -2,7 +2,8 @@
|
||||||
# bash-it installer
|
# bash-it installer
|
||||||
|
|
||||||
# Show how to use this 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 "\n$0 : Install bash-it"
|
||||||
echo -e "Usage:\n$0 [arguments] \n"
|
echo -e "Usage:\n$0 [arguments] \n"
|
||||||
echo "Arguments:"
|
echo "Arguments:"
|
||||||
|
|
@ -16,7 +17,8 @@ function _bash-it_show_usage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# enable a thing
|
# enable a thing
|
||||||
function _bash-it_load_one() {
|
function _bash-it_load_one()
|
||||||
|
{
|
||||||
file_type=$1
|
file_type=$1
|
||||||
file_to_enable=$2
|
file_to_enable=$2
|
||||||
mkdir -p "$BASH_IT/${file_type}/enabled"
|
mkdir -p "$BASH_IT/${file_type}/enabled"
|
||||||
|
|
@ -30,7 +32,8 @@ function _bash-it_load_one() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Interactively enable several things
|
# Interactively enable several things
|
||||||
function _bash-it_load_some() {
|
function _bash-it_load_some()
|
||||||
|
{
|
||||||
file_type=$1
|
file_type=$1
|
||||||
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
|
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
|
||||||
enable_func="_enable-$single_type"
|
enable_func="_enable-$single_type"
|
||||||
|
|
@ -57,27 +60,31 @@ function _bash-it_load_some() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Back up existing profile
|
# Back up existing profile
|
||||||
function _bash-it_backup() {
|
function _bash-it_backup()
|
||||||
test -w "$HOME/$CONFIG_FILE" \
|
{
|
||||||
&& cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" \
|
test -w "$HOME/$CONFIG_FILE" &&
|
||||||
&& echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
|
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
|
# Back up existing profile and create new one for bash-it
|
||||||
function _bash-it_backup_new() {
|
function _bash-it_backup_new()
|
||||||
|
{
|
||||||
_bash-it_backup
|
_bash-it_backup
|
||||||
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
|
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"
|
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
|
# 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
|
_bash-it_backup
|
||||||
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
|
(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"
|
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
|
if ! [[ -e "$HOME/$BACKUP_FILE" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
@ -111,7 +118,8 @@ function _bash-it_check_for_backup() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it_modify_config_files() {
|
function _bash-it_modify_config_files()
|
||||||
|
{
|
||||||
_bash-it_check_for_backup
|
_bash-it_check_for_backup
|
||||||
|
|
||||||
if [[ -z "${silent}" ]]; then
|
if [[ -z "${silent}" ]]; then
|
||||||
|
|
|
||||||
202
lib/helpers.bash
202
lib/helpers.bash
|
|
@ -12,10 +12,10 @@ BASH_IT_LOAD_PRIORITY_SEPARATOR="---"
|
||||||
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
|
# sed "${BASH_IT_SED_I_PARAMETERS[@]}" -e "..." file
|
||||||
BASH_IT_SED_I_PARAMETERS=(-i)
|
BASH_IT_SED_I_PARAMETERS=(-i)
|
||||||
case "$OSTYPE" in
|
case "$OSTYPE" in
|
||||||
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
|
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "") ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
function _command_exists ()
|
function _command_exists()
|
||||||
{
|
{
|
||||||
_about 'checks for existence of a command'
|
_about 'checks for existence of a command'
|
||||||
_param '1: command to check'
|
_param '1: command to check'
|
||||||
|
|
@ -23,8 +23,7 @@ function _command_exists ()
|
||||||
_example '$ _command_exists ls && echo exists'
|
_example '$ _command_exists ls && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Command '$1' does not exist!}"
|
local msg="${2:-Command '$1' does not exist!}"
|
||||||
if type -t "$1" &> /dev/null
|
if type -t "$1" &> /dev/null; then
|
||||||
then
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_log_warning "$msg"
|
_log_warning "$msg"
|
||||||
|
|
@ -32,7 +31,7 @@ function _command_exists ()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _binary_exists ()
|
function _binary_exists()
|
||||||
{
|
{
|
||||||
_about 'checks for existence of a binary'
|
_about 'checks for existence of a binary'
|
||||||
_param '1: binary to check'
|
_param '1: binary to check'
|
||||||
|
|
@ -40,8 +39,7 @@ function _binary_exists ()
|
||||||
_example '$ _binary_exists ls && echo exists'
|
_example '$ _binary_exists ls && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Binary '$1' does not exist!}"
|
local msg="${2:-Binary '$1' does not exist!}"
|
||||||
if type -P "$1" &> /dev/null
|
if type -P "$1" &> /dev/null; then
|
||||||
then
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_log_warning "$msg"
|
_log_warning "$msg"
|
||||||
|
|
@ -49,7 +47,7 @@ function _binary_exists ()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _completion_exists ()
|
function _completion_exists()
|
||||||
{
|
{
|
||||||
_about 'checks for existence of a completion'
|
_about 'checks for existence of a completion'
|
||||||
_param '1: command to check'
|
_param '1: command to check'
|
||||||
|
|
@ -57,15 +55,13 @@ function _completion_exists ()
|
||||||
_example '$ _completion_exists gh && echo exists'
|
_example '$ _completion_exists gh && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Completion for '$1' already exists!}"
|
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()
|
function _bash_it_homebrew_check()
|
||||||
{
|
{
|
||||||
if _binary_exists 'brew'
|
if _binary_exists 'brew'; then # Homebrew is installed
|
||||||
then # Homebrew is installed
|
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]; then # variable isn't set
|
||||||
if [[ "${BASH_IT_HOMEBREW_PREFIX:-unset}" == 'unset' ]]
|
|
||||||
then # variable isn't set
|
|
||||||
BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)"
|
BASH_IT_HOMEBREW_PREFIX="$(brew --prefix)"
|
||||||
else
|
else
|
||||||
true # Variable is set already, don't invoke `brew`.
|
true # Variable is set already, don't invoke `brew`.
|
||||||
|
|
@ -76,7 +72,8 @@ function _bash_it_homebrew_check()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _make_reload_alias() {
|
function _make_reload_alias()
|
||||||
|
{
|
||||||
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
|
echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +89,7 @@ alias reload_completion="$(_make_reload_alias completion completion)"
|
||||||
# shellcheck disable=SC2139
|
# shellcheck disable=SC2139
|
||||||
alias reload_plugins="$(_make_reload_alias plugin plugins)"
|
alias reload_plugins="$(_make_reload_alias plugin plugins)"
|
||||||
|
|
||||||
bash-it ()
|
bash-it()
|
||||||
{
|
{
|
||||||
about 'Bash-it help and maintenance'
|
about 'Bash-it help and maintenance'
|
||||||
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload | restart | doctor ] '
|
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
|
case $verb in
|
||||||
show)
|
show)
|
||||||
func=_bash-it-$component;;
|
func=_bash-it-$component
|
||||||
|
;;
|
||||||
enable)
|
enable)
|
||||||
func=_enable-$component;;
|
func=_enable-$component
|
||||||
|
;;
|
||||||
disable)
|
disable)
|
||||||
func=_disable-$component;;
|
func=_disable-$component
|
||||||
|
;;
|
||||||
help)
|
help)
|
||||||
func=_help-$component;;
|
func=_help-$component
|
||||||
|
;;
|
||||||
doctor)
|
doctor)
|
||||||
func=_bash-it-doctor-$component;;
|
func=_bash-it-doctor-$component
|
||||||
|
;;
|
||||||
search)
|
search)
|
||||||
_bash-it-search $component "$@"
|
_bash-it-search $component "$@"
|
||||||
return;;
|
return
|
||||||
|
;;
|
||||||
update)
|
update)
|
||||||
func=_bash-it-update-$component;;
|
func=_bash-it-update-$component
|
||||||
|
;;
|
||||||
migrate)
|
migrate)
|
||||||
func=_bash-it-migrate;;
|
func=_bash-it-migrate
|
||||||
|
;;
|
||||||
version)
|
version)
|
||||||
func=_bash-it-version;;
|
func=_bash-it-version
|
||||||
|
;;
|
||||||
restart)
|
restart)
|
||||||
func=_bash-it-restart;;
|
func=_bash-it-restart
|
||||||
|
;;
|
||||||
reload)
|
reload)
|
||||||
func=_bash-it-reload;;
|
func=_bash-it-reload
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
reference bash-it
|
reference bash-it
|
||||||
return;;
|
return
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# pluralize component if necessary
|
# pluralize component if necessary
|
||||||
|
|
@ -163,8 +172,7 @@ bash-it ()
|
||||||
# Automatically run a migration if required
|
# Automatically run a migration if required
|
||||||
_bash-it-migrate
|
_bash-it-migrate
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"; do
|
||||||
do
|
|
||||||
$func $arg
|
$func $arg
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -176,15 +184,15 @@ bash-it ()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_is_function ()
|
_is_function()
|
||||||
{
|
{
|
||||||
_about 'sets $? to true if parameter is the name of a function'
|
_about 'sets $? to true if parameter is the name of a function'
|
||||||
_param '1: name of alleged function'
|
_param '1: name of alleged function'
|
||||||
_group 'lib'
|
_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'
|
_about 'summarizes available bash_it aliases'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
@ -192,7 +200,7 @@ _bash-it-aliases ()
|
||||||
_bash-it-describe "aliases" "an" "alias" "Alias"
|
_bash-it-describe "aliases" "an" "alias" "Alias"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-completions ()
|
_bash-it-completions()
|
||||||
{
|
{
|
||||||
_about 'summarizes available bash_it completions'
|
_about 'summarizes available bash_it completions'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
@ -200,7 +208,7 @@ _bash-it-completions ()
|
||||||
_bash-it-describe "completion" "a" "completion" "Completion"
|
_bash-it-describe "completion" "a" "completion" "Completion"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-plugins ()
|
_bash-it-plugins()
|
||||||
{
|
{
|
||||||
_about 'summarizes available bash_it plugins'
|
_about 'summarizes available bash_it plugins'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
@ -208,21 +216,24 @@ _bash-it-plugins ()
|
||||||
_bash-it-describe "plugins" "a" "plugin" "Plugin"
|
_bash-it-describe "plugins" "a" "plugin" "Plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-update-dev() {
|
_bash-it-update-dev()
|
||||||
|
{
|
||||||
_about 'updates Bash-it to the latest master'
|
_about 'updates Bash-it to the latest master'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-update- dev "$@"
|
_bash-it-update- dev "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-update-stable() {
|
_bash-it-update-stable()
|
||||||
|
{
|
||||||
_about 'updates Bash-it to the latest tag'
|
_about 'updates Bash-it to the latest tag'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-update- stable "$@"
|
_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!)'
|
_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 '1: Which branch to checkout to'
|
||||||
_param '2: Which type of version we are using'
|
_param '2: Which type of version we are using'
|
||||||
|
|
@ -242,7 +253,8 @@ _bash-it_update_migrate_and_restart() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-update-() {
|
_bash-it-update-()
|
||||||
|
{
|
||||||
_about 'updates Bash-it'
|
_about 'updates Bash-it'
|
||||||
_param '1: What kind of update to do (stable|dev)'
|
_param '1: What kind of update to do (stable|dev)'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
@ -320,7 +332,7 @@ _bash-it-update-() {
|
||||||
else
|
else
|
||||||
read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP
|
read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP
|
||||||
case $RESP in
|
case $RESP in
|
||||||
[yY]|"")
|
[yY] | "")
|
||||||
_bash-it_update_migrate_and_restart $TARGET $version
|
_bash-it_update_migrate_and_restart $TARGET $version
|
||||||
;;
|
;;
|
||||||
[nN])
|
[nN])
|
||||||
|
|
@ -341,17 +353,16 @@ _bash-it-update-() {
|
||||||
popd &> /dev/null
|
popd &> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-migrate() {
|
_bash-it-migrate()
|
||||||
|
{
|
||||||
_about 'migrates Bash-it configuration from a previous format to the current one'
|
_about 'migrates Bash-it configuration from a previous format to the current one'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
declare migrated_something
|
declare migrated_something
|
||||||
migrated_something=false
|
migrated_something=false
|
||||||
|
|
||||||
for file_type in "aliases" "plugins" "completion"
|
for file_type in "aliases" "plugins" "completion"; do
|
||||||
do
|
for f in $(sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")); do
|
||||||
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
|
|
||||||
do
|
|
||||||
typeset ff="${f##*/}"
|
typeset ff="${f##*/}"
|
||||||
|
|
||||||
# Get the type of component from the extension
|
# Get the type of component from the extension
|
||||||
|
|
@ -381,7 +392,8 @@ _bash-it-migrate() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-version() {
|
_bash-it-version()
|
||||||
|
{
|
||||||
_about 'shows current Bash-it version'
|
_about 'shows current Bash-it version'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
|
|
@ -419,7 +431,8 @@ _bash-it-version() {
|
||||||
cd - &> /dev/null || return
|
cd - &> /dev/null || return
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-doctor() {
|
_bash-it-doctor()
|
||||||
|
{
|
||||||
_about 'reloads a profile file with a BASH_IT_LOG_LEVEL set'
|
_about 'reloads a profile file with a BASH_IT_LOG_LEVEL set'
|
||||||
_param '1: BASH_IT_LOG_LEVEL argument: "errors" "warnings" "all"'
|
_param '1: BASH_IT_LOG_LEVEL argument: "errors" "warnings" "all"'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
@ -429,35 +442,40 @@ _bash-it-doctor() {
|
||||||
unset BASH_IT_LOG_LEVEL
|
unset BASH_IT_LOG_LEVEL
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-doctor-all() {
|
_bash-it-doctor-all()
|
||||||
|
{
|
||||||
_about 'reloads a profile file with error, warning and debug logs'
|
_about 'reloads a profile file with error, warning and debug logs'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-doctor $BASH_IT_LOG_LEVEL_ALL
|
_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'
|
_about 'reloads a profile file with error and warning logs'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING
|
_bash-it-doctor $BASH_IT_LOG_LEVEL_WARNING
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-doctor-errors() {
|
_bash-it-doctor-errors()
|
||||||
|
{
|
||||||
_about 'reloads a profile file with error logs'
|
_about 'reloads a profile file with error logs'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-doctor $BASH_IT_LOG_LEVEL_ERROR
|
_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'
|
_about 'default bash-it doctor behavior, behaves like bash-it doctor all'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
_bash-it-doctor-all
|
_bash-it-doctor-all
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-restart() {
|
_bash-it-restart()
|
||||||
|
{
|
||||||
_about 'restarts the shell in order to fully reload it'
|
_about 'restarts the shell in order to fully reload it'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
|
|
@ -474,7 +492,8 @@ _bash-it-restart() {
|
||||||
exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"")
|
exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-reload() {
|
_bash-it-reload()
|
||||||
|
{
|
||||||
_about 'reloads a profile file'
|
_about 'reloads a profile file'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
|
|
@ -492,7 +511,7 @@ _bash-it-reload() {
|
||||||
popd &> /dev/null || return
|
popd &> /dev/null || return
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-describe ()
|
_bash-it-describe()
|
||||||
{
|
{
|
||||||
_about 'summarizes available bash_it components'
|
_about 'summarizes available bash_it components'
|
||||||
_param '1: subdirectory'
|
_param '1: subdirectory'
|
||||||
|
|
@ -509,8 +528,7 @@ _bash-it-describe ()
|
||||||
typeset f
|
typeset f
|
||||||
typeset enabled
|
typeset enabled
|
||||||
printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description'
|
printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description'
|
||||||
for f in "${BASH_IT}/$subdirectory/available/"*.bash
|
for f in "${BASH_IT}/$subdirectory/available/"*.bash; do
|
||||||
do
|
|
||||||
# Check for both the old format without the load priority, and the extended format with the priority
|
# Check for both the old format without the load priority, and the extended format with the priority
|
||||||
declare enabled_files enabled_file
|
declare enabled_files enabled_file
|
||||||
enabled_file="${f##*/}"
|
enabled_file="${f##*/}"
|
||||||
|
|
@ -540,7 +558,7 @@ _on-disable-callback()
|
||||||
_command_exists $callback && $callback
|
_command_exists $callback && $callback
|
||||||
}
|
}
|
||||||
|
|
||||||
_disable-plugin ()
|
_disable-plugin()
|
||||||
{
|
{
|
||||||
_about 'disables bash_it plugin'
|
_about 'disables bash_it plugin'
|
||||||
_param '1: plugin name'
|
_param '1: plugin name'
|
||||||
|
|
@ -551,7 +569,7 @@ _disable-plugin ()
|
||||||
_on-disable-callback $1
|
_on-disable-callback $1
|
||||||
}
|
}
|
||||||
|
|
||||||
_disable-alias ()
|
_disable-alias()
|
||||||
{
|
{
|
||||||
_about 'disables bash_it alias'
|
_about 'disables bash_it alias'
|
||||||
_param '1: alias name'
|
_param '1: alias name'
|
||||||
|
|
@ -561,7 +579,7 @@ _disable-alias ()
|
||||||
_disable-thing "aliases" "alias" $1
|
_disable-thing "aliases" "alias" $1
|
||||||
}
|
}
|
||||||
|
|
||||||
_disable-completion ()
|
_disable-completion()
|
||||||
{
|
{
|
||||||
_about 'disables bash_it completion'
|
_about 'disables bash_it completion'
|
||||||
_param '1: completion name'
|
_param '1: completion name'
|
||||||
|
|
@ -571,7 +589,7 @@ _disable-completion ()
|
||||||
_disable-thing "completion" "completion" $1
|
_disable-thing "completion" "completion" $1
|
||||||
}
|
}
|
||||||
|
|
||||||
_disable-thing ()
|
_disable-thing()
|
||||||
{
|
{
|
||||||
_about 'disables a bash_it component'
|
_about 'disables a bash_it component'
|
||||||
_param '1: subdirectory'
|
_param '1: subdirectory'
|
||||||
|
|
@ -593,24 +611,22 @@ _disable-thing ()
|
||||||
|
|
||||||
if [ "$file_entity" = "all" ]; then
|
if [ "$file_entity" = "all" ]; then
|
||||||
# Disable everything that's using the old structure
|
# Disable everything that's using the old structure
|
||||||
for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"`
|
for f in $(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"); do
|
||||||
do
|
|
||||||
rm "$f"
|
rm "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Disable everything in the global "enabled" directory
|
# Disable everything in the global "enabled" directory
|
||||||
for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"`
|
for f in $(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"); do
|
||||||
do
|
|
||||||
rm "$f"
|
rm "$f"
|
||||||
done
|
done
|
||||||
else
|
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
|
if [ -z "$plugin_global" ]; then
|
||||||
# Use a glob to search for both possible patterns
|
# Use a glob to search for both possible patterns
|
||||||
# 250---node.plugin.bash
|
# 250---node.plugin.bash
|
||||||
# node.plugin.bash
|
# node.plugin.bash
|
||||||
# Either one will be matched by this glob
|
# 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
|
if [ -z "$plugin" ]; then
|
||||||
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
|
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
|
||||||
return
|
return
|
||||||
|
|
@ -626,7 +642,7 @@ _disable-thing ()
|
||||||
printf '%s\n' "$file_entity disabled."
|
printf '%s\n' "$file_entity disabled."
|
||||||
}
|
}
|
||||||
|
|
||||||
_enable-plugin ()
|
_enable-plugin()
|
||||||
{
|
{
|
||||||
_about 'enables bash_it plugin'
|
_about 'enables bash_it plugin'
|
||||||
_param '1: plugin name'
|
_param '1: plugin name'
|
||||||
|
|
@ -636,7 +652,7 @@ _enable-plugin ()
|
||||||
_enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN
|
_enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN
|
||||||
}
|
}
|
||||||
|
|
||||||
_enable-alias ()
|
_enable-alias()
|
||||||
{
|
{
|
||||||
_about 'enables bash_it alias'
|
_about 'enables bash_it alias'
|
||||||
_param '1: alias name'
|
_param '1: alias name'
|
||||||
|
|
@ -646,7 +662,7 @@ _enable-alias ()
|
||||||
_enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS
|
_enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS
|
||||||
}
|
}
|
||||||
|
|
||||||
_enable-completion ()
|
_enable-completion()
|
||||||
{
|
{
|
||||||
_about 'enables bash_it completion'
|
_about 'enables bash_it completion'
|
||||||
_param '1: completion name'
|
_param '1: completion name'
|
||||||
|
|
@ -656,7 +672,7 @@ _enable-completion ()
|
||||||
_enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION
|
_enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION
|
||||||
}
|
}
|
||||||
|
|
||||||
_enable-thing ()
|
_enable-thing()
|
||||||
{
|
{
|
||||||
cite _about _param _example
|
cite _about _param _example
|
||||||
_about 'enables a bash_it component'
|
_about 'enables a bash_it component'
|
||||||
|
|
@ -678,8 +694,7 @@ _enable-thing ()
|
||||||
|
|
||||||
if [ "$file_entity" = "all" ]; then
|
if [ "$file_entity" = "all" ]; then
|
||||||
typeset f $file_type
|
typeset f $file_type
|
||||||
for f in "${BASH_IT}/$subdirectory/available/"*.bash
|
for f in "${BASH_IT}/$subdirectory/available/"*.bash; do
|
||||||
do
|
|
||||||
to_enable=$(basename $f .$file_type.bash)
|
to_enable=$(basename $f .$file_type.bash)
|
||||||
if [ "$file_type" = "alias" ]; then
|
if [ "$file_type" = "alias" ]; then
|
||||||
to_enable=$(basename $f ".aliases.bash")
|
to_enable=$(basename $f ".aliases.bash")
|
||||||
|
|
@ -687,7 +702,7 @@ _enable-thing ()
|
||||||
_enable-thing $subdirectory $file_type $to_enable $load_priority
|
_enable-thing $subdirectory $file_type $to_enable $load_priority
|
||||||
done
|
done
|
||||||
else
|
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
|
if [ -z "$to_enable" ]; then
|
||||||
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
|
printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
|
||||||
return
|
return
|
||||||
|
|
@ -695,14 +710,14 @@ _enable-thing ()
|
||||||
|
|
||||||
to_enable="${to_enable##*/}"
|
to_enable="${to_enable##*/}"
|
||||||
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
|
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
|
||||||
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
|
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2> /dev/null | head -1)
|
||||||
if [ ! -z "$enabled_plugin" ] ; then
|
if [ ! -z "$enabled_plugin" ]; then
|
||||||
printf '%s\n' "$file_entity is already enabled."
|
printf '%s\n' "$file_entity is already enabled."
|
||||||
return
|
return
|
||||||
fi
|
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)
|
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
|
if [ ! -z "$enabled_plugin_global" ]; then
|
||||||
printf '%s\n' "$file_entity is already enabled."
|
printf '%s\n' "$file_entity is already enabled."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
@ -750,8 +765,7 @@ _help-aliases()
|
||||||
else
|
else
|
||||||
typeset f
|
typeset f
|
||||||
|
|
||||||
for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")`
|
for f in $(sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")); do
|
||||||
do
|
|
||||||
_help-list-aliases $f
|
_help-list-aliases $f
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -761,7 +775,7 @@ _help-aliases()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_help-list-aliases ()
|
_help-list-aliases()
|
||||||
{
|
{
|
||||||
typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g')
|
typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g')
|
||||||
printf '\n\n%s:\n' "${file}"
|
printf '\n\n%s:\n' "${file}"
|
||||||
|
|
@ -778,8 +792,7 @@ _help-plugins()
|
||||||
printf '%s' 'please wait, building help...'
|
printf '%s' 'please wait, building help...'
|
||||||
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
|
typeset grouplist=$(mktemp -t grouplist.XXXXXX)
|
||||||
typeset func
|
typeset func
|
||||||
for func in $(_typeset_functions)
|
for func in $(_typeset_functions); do
|
||||||
do
|
|
||||||
typeset group="$(typeset -f $func | metafor group)"
|
typeset group="$(typeset -f $func | metafor group)"
|
||||||
if [ -z "$group" ]; then
|
if [ -z "$group" ]; then
|
||||||
group='misc'
|
group='misc'
|
||||||
|
|
@ -792,8 +805,7 @@ _help-plugins()
|
||||||
printf '\r%s\n' ' '
|
printf '\r%s\n' ' '
|
||||||
typeset group
|
typeset group
|
||||||
typeset gfile
|
typeset gfile
|
||||||
for gfile in $(cat $grouplist | sort | uniq)
|
for gfile in $(cat $grouplist | sort | uniq); do
|
||||||
do
|
|
||||||
printf '%s\n' "${gfile##*.}:"
|
printf '%s\n' "${gfile##*.}:"
|
||||||
cat $gfile
|
cat $gfile
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
|
@ -802,14 +814,16 @@ _help-plugins()
|
||||||
rm $grouplist 2> /dev/null
|
rm $grouplist 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
_help-update () {
|
_help-update()
|
||||||
|
{
|
||||||
_about 'help message for update command'
|
_about 'help message for update command'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
echo "Check for a new version of Bash-it and update it."
|
echo "Check for a new version of Bash-it and update it."
|
||||||
}
|
}
|
||||||
|
|
||||||
_help-migrate () {
|
_help-migrate()
|
||||||
|
{
|
||||||
_about 'help message for migrate command'
|
_about 'help message for migrate command'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
|
|
@ -817,31 +831,30 @@ _help-migrate () {
|
||||||
echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'."
|
echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'."
|
||||||
}
|
}
|
||||||
|
|
||||||
all_groups ()
|
all_groups()
|
||||||
{
|
{
|
||||||
about 'displays all unique metadata groups'
|
about 'displays all unique metadata groups'
|
||||||
group 'lib'
|
group 'lib'
|
||||||
|
|
||||||
typeset func
|
typeset func
|
||||||
typeset file=$(mktemp -t composure.XXXX)
|
typeset file=$(mktemp -t composure.XXXX)
|
||||||
for func in $(_typeset_functions)
|
for func in $(_typeset_functions); do
|
||||||
do
|
|
||||||
typeset -f $func | metafor group >> $file
|
typeset -f $func | metafor group >> $file
|
||||||
done
|
done
|
||||||
cat $file | sort | uniq
|
cat $file | sort | uniq
|
||||||
rm $file
|
rm $file
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! type pathmunge > /dev/null 2>&1
|
if ! type pathmunge > /dev/null 2>&1; then
|
||||||
then
|
function pathmunge()
|
||||||
function pathmunge () {
|
{
|
||||||
about 'prevent duplicate directories in you PATH variable'
|
about 'prevent duplicate directories in you PATH variable'
|
||||||
group 'helpers'
|
group 'helpers'
|
||||||
example 'pathmunge /path/to/dir is equivalent to PATH=/path/to/dir:$PATH'
|
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'
|
example 'pathmunge /path/to/dir after is equivalent to PATH=$PATH:/path/to/dir'
|
||||||
|
|
||||||
if ! [[ $PATH =~ (^|:)$1($|:) ]] ; then
|
if ! [[ $PATH =~ (^|:)$1($|:) ]]; then
|
||||||
if [ "$2" = "after" ] ; then
|
if [ "$2" = "after" ]; then
|
||||||
export PATH=$PATH:$1
|
export PATH=$PATH:$1
|
||||||
else
|
else
|
||||||
export PATH=$1:$PATH
|
export PATH=$1:$PATH
|
||||||
|
|
@ -853,7 +866,8 @@ fi
|
||||||
# `_bash-it-find-in-ancestor` uses the shell's ability to run a function in
|
# `_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 ]]`
|
# 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.
|
# 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'
|
about 'searches parents of the current directory for any of the specified file names'
|
||||||
group 'helpers'
|
group 'helpers'
|
||||||
param '*: names of files or folders to search for'
|
param '*: names of files or folders to search for'
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
if [[ "${BASH_PREVIEW:-}" ]];
|
if [[ "${BASH_PREVIEW:-}" ]]; then
|
||||||
then
|
|
||||||
unset BASH_PREVIEW #Prevent infinite looping
|
unset BASH_PREVIEW #Prevent infinite looping
|
||||||
echo "
|
echo "
|
||||||
|
|
||||||
|
|
@ -8,8 +7,7 @@ then
|
||||||
"
|
"
|
||||||
|
|
||||||
THEMES="$BASH_IT/themes/*/*.theme.bash"
|
THEMES="$BASH_IT/themes/*/*.theme.bash"
|
||||||
for theme in $THEMES
|
for theme in $THEMES; do
|
||||||
do
|
|
||||||
BASH_IT_THEME=${theme%.theme.bash}
|
BASH_IT_THEME=${theme%.theme.bash}
|
||||||
BASH_IT_THEME=${BASH_IT_THEME##*/}
|
BASH_IT_THEME=${BASH_IT_THEME##*/}
|
||||||
echo "
|
echo "
|
||||||
|
|
|
||||||
|
|
@ -47,20 +47,21 @@
|
||||||
# completions: git
|
# completions: git
|
||||||
#
|
#
|
||||||
|
|
||||||
_bash-it-search() {
|
_bash-it-search()
|
||||||
|
{
|
||||||
_about 'searches for given terms amongst bash-it plugins, aliases and completions'
|
_about 'searches for given terms amongst bash-it plugins, aliases and completions'
|
||||||
_param '1: term1'
|
_param '1: term1'
|
||||||
_param '2: [ term2 ]...'
|
_param '2: [ term2 ]...'
|
||||||
_example '$ _bash-it-search @git ruby -rvm rake bundler'
|
_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
|
local component
|
||||||
export BASH_IT_SEARCH_USE_COLOR=true
|
export BASH_IT_SEARCH_USE_COLOR=true
|
||||||
export BASH_IT_GREP=${BASH_IT_GREP:-$(which egrep)}
|
export BASH_IT_GREP=${BASH_IT_GREP:-$(which egrep)}
|
||||||
declare -a BASH_IT_COMPONENTS=(aliases plugins completions)
|
declare -a BASH_IT_COMPONENTS=(aliases plugins completions)
|
||||||
|
|
||||||
if [[ -z "$*" ]] ; then
|
if [[ -z "$*" ]]; then
|
||||||
_bash-it-search-help
|
_bash-it-search-help
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
@ -80,7 +81,7 @@ _bash-it-search() {
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#args} -gt 0 ]]; then
|
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[@]}"
|
_bash-it-search-component "${component}" "${args[@]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
@ -88,7 +89,8 @@ _bash-it-search() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-search-help() {
|
_bash-it-search-help()
|
||||||
|
{
|
||||||
printf "${echo_normal}
|
printf "${echo_normal}
|
||||||
${echo_underline_yellow}USAGE${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 component="$1"
|
||||||
local term="$2"
|
local term="$2"
|
||||||
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -i -q -- "${term}"
|
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -i -q -- "${term}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-component-term-matches-negation() {
|
_bash-it-component-term-matches-negation()
|
||||||
local match="$1"; shift
|
{
|
||||||
|
local match="$1"
|
||||||
|
shift
|
||||||
local negative
|
local negative
|
||||||
for negative in "$@"; do
|
for negative in "$@"; do
|
||||||
[[ "${match}" =~ "${negative}" ]] && return 0
|
[[ "${match}" =~ "${negative}" ]] && return 0
|
||||||
|
|
@ -181,7 +186,8 @@ _bash-it-component-term-matches-negation() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-search-component() {
|
_bash-it-search-component()
|
||||||
|
{
|
||||||
local component="$1"
|
local component="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
|
|
@ -218,50 +224,54 @@ _bash-it-search-component() {
|
||||||
local -a negative_terms=() # negated partial terms that should be excluded
|
local -a negative_terms=() # negated partial terms that should be excluded
|
||||||
|
|
||||||
unset component_list
|
unset component_list
|
||||||
local -a component_list=( $(_bash-it-component-list "${component}") )
|
local -a component_list=($(_bash-it-component-list "${component}"))
|
||||||
local term
|
local term
|
||||||
|
|
||||||
for term in "${terms[@]}"; do
|
for term in "${terms[@]}"; do
|
||||||
local search_term="${term:1}"
|
local search_term="${term:1}"
|
||||||
if [[ "${term:0:2}" == "--" ]] ; then
|
if [[ "${term:0:2}" == "--" ]]; then
|
||||||
continue
|
continue
|
||||||
elif [[ "${term:0:1}" == "-" ]] ; then
|
elif [[ "${term:0:1}" == "-" ]]; then
|
||||||
negative_terms=(${negative_terms[@]} "${search_term}")
|
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
|
if $(_bash-it-array-contains-element "${search_term}" "${component_list[@]}"); then
|
||||||
exact_terms=(${exact_terms[@]} "${search_term}")
|
exact_terms=(${exact_terms[@]} "${search_term}")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}") )
|
partial_terms=(${partial_terms[@]} $(_bash-it-component-list-matching "${component}" "${term}"))
|
||||||
fi
|
fi
|
||||||
done
|
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
|
unset matches
|
||||||
declare -a matches=()
|
declare -a matches=()
|
||||||
for match in ${total_matches[@]}; do
|
for match in ${total_matches[@]}; do
|
||||||
local include_match=true
|
local include_match=true
|
||||||
if [[ ${#negative_terms[@]} -gt 0 ]]; then
|
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
|
fi
|
||||||
( ${include_match} ) && matches=(${matches[@]} "${match}")
|
(${include_match}) && matches=(${matches[@]} "${match}")
|
||||||
done
|
done
|
||||||
_bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]}"
|
_bash-it-search-result "${component}" "${action}" "${action_func}" "${matches[@]}"
|
||||||
unset matches final_matches terms
|
unset matches final_matches terms
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-search-result() {
|
_bash-it-search-result()
|
||||||
local component="$1"; shift
|
{
|
||||||
local action="$1"; shift
|
local component="$1"
|
||||||
local action_func="$1"; shift
|
shift
|
||||||
|
local action="$1"
|
||||||
|
shift
|
||||||
|
local action_func="$1"
|
||||||
|
shift
|
||||||
local -a matches=($@)
|
local -a matches=($@)
|
||||||
|
|
||||||
local color_component color_enable color_disable color_off
|
local color_component color_enable color_disable color_off
|
||||||
|
|
||||||
color_sep=':'
|
color_sep=':'
|
||||||
|
|
||||||
( ${BASH_IT_SEARCH_USE_COLOR} ) && {
|
(${BASH_IT_SEARCH_USE_COLOR}) && {
|
||||||
color_component='\e[1;34m'
|
color_component='\e[1;34m'
|
||||||
color_enable='\e[1;32m'
|
color_enable='\e[1;32m'
|
||||||
suffix_enable=''
|
suffix_enable=''
|
||||||
|
|
@ -270,7 +280,7 @@ _bash-it-search-result() {
|
||||||
color_off='\e[0;0m'
|
color_off='\e[0;0m'
|
||||||
}
|
}
|
||||||
|
|
||||||
( ${BASH_IT_SEARCH_USE_COLOR} ) || {
|
(${BASH_IT_SEARCH_USE_COLOR}) || {
|
||||||
color_component=''
|
color_component=''
|
||||||
suffix_enable=' ✓ ︎'
|
suffix_enable=' ✓ ︎'
|
||||||
suffix_disable=' '
|
suffix_disable=' '
|
||||||
|
|
@ -282,23 +292,23 @@ _bash-it-search-result() {
|
||||||
local match
|
local match
|
||||||
local modified=0
|
local modified=0
|
||||||
|
|
||||||
if [[ "${#matches[@]}" -gt 0 ]] ; then
|
if [[ "${#matches[@]}" -gt 0 ]]; then
|
||||||
printf "${color_component}%13s${color_sep} ${color_off}" "${component}"
|
printf "${color_component}%13s${color_sep} ${color_off}" "${component}"
|
||||||
|
|
||||||
for match in "${matches[@]}"; do
|
for match in "${matches[@]}"; do
|
||||||
local enabled=0
|
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
|
local match_color compatible_action suffix opposite_suffix
|
||||||
|
|
||||||
(( ${enabled} )) && {
|
((${enabled})) && {
|
||||||
match_color=${color_enable}
|
match_color=${color_enable}
|
||||||
suffix=${suffix_enable}
|
suffix=${suffix_enable}
|
||||||
opposite_suffix=${suffix_disable}
|
opposite_suffix=${suffix_disable}
|
||||||
compatible_action="disable"
|
compatible_action="disable"
|
||||||
}
|
}
|
||||||
|
|
||||||
(( ${enabled} )) || {
|
((${enabled})) || {
|
||||||
match_color=${color_disable}
|
match_color=${color_disable}
|
||||||
suffix=${suffix_disable}
|
suffix=${suffix_disable}
|
||||||
opposite_suffix=${suffix_enable}
|
opposite_suffix=${suffix_enable}
|
||||||
|
|
@ -332,25 +342,28 @@ _bash-it-search-result() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-rewind() {
|
_bash-it-rewind()
|
||||||
|
{
|
||||||
local len="$1"
|
local len="$1"
|
||||||
printf "\033[${len}D"
|
printf "\033[${len}D"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-flash-term() {
|
_bash-it-flash-term()
|
||||||
|
{
|
||||||
local len="$1"
|
local len="$1"
|
||||||
local match="$2"
|
local match="$2"
|
||||||
local delay=0.1
|
local delay=0.1
|
||||||
local color
|
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}
|
sleep ${delay}
|
||||||
_bash-it-rewind "${len}"
|
_bash-it-rewind "${len}"
|
||||||
printf "${color}${match}"
|
printf "${color}${match}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-erase-term() {
|
_bash-it-erase-term()
|
||||||
|
{
|
||||||
local len="$1"
|
local len="$1"
|
||||||
_bash-it-rewind ${len}
|
_bash-it-rewind ${len}
|
||||||
for a in {0..30}; do
|
for a in {0..30}; do
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
# Generic utilies
|
# Generic utilies
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
function _bash-it-get-component-name-from-path() {
|
function _bash-it-get-component-name-from-path()
|
||||||
|
{
|
||||||
local filename
|
local filename
|
||||||
# filename without path
|
# filename without path
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
|
|
@ -16,7 +17,8 @@ function _bash-it-get-component-name-from-path() {
|
||||||
echo "${filename%.*.bash}"
|
echo "${filename%.*.bash}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it-get-component-type-from-path() {
|
function _bash-it-get-component-type-from-path()
|
||||||
|
{
|
||||||
local filename
|
local filename
|
||||||
# filename without path
|
# filename without path
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
|
|
@ -46,7 +48,8 @@ function _bash-it-get-component-type-from-path() {
|
||||||
# contains pear!
|
# contains pear!
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
function _bash-it-array-contains-element() {
|
function _bash-it-array-contains-element()
|
||||||
|
{
|
||||||
local e
|
local e
|
||||||
for e in "${@:2}"; do
|
for e in "${@:2}"; do
|
||||||
[[ "$e" == "$1" ]] && return 0
|
[[ "$e" == "$1" ]] && return 0
|
||||||
|
|
@ -55,18 +58,21 @@ function _bash-it-array-contains-element() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dedupe an array (without embedded newlines).
|
# Dedupe an array (without embedded newlines).
|
||||||
function _bash-it-array-dedup() {
|
function _bash-it-array-dedup()
|
||||||
|
{
|
||||||
printf '%s\n' "$@" | sort -u
|
printf '%s\n' "$@" | sort -u
|
||||||
}
|
}
|
||||||
|
|
||||||
# Outputs a full path of the grep found on the filesystem
|
# Outputs a full path of the grep found on the filesystem
|
||||||
function _bash-it-grep() {
|
function _bash-it-grep()
|
||||||
|
{
|
||||||
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
|
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
|
||||||
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
|
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Runs `grep` with extended regular expressions
|
# 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:=$(type -p egrep || type -p grep)}"
|
||||||
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +82,8 @@ function _bash-it-egrep() {
|
||||||
# completion).
|
# completion).
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
function _bash-it-component-help() {
|
function _bash-it-component-help()
|
||||||
|
{
|
||||||
local component file func
|
local component file func
|
||||||
component="$(_bash-it-pluralize-component "${1}")"
|
component="$(_bash-it-pluralize-component "${1}")"
|
||||||
file="$(_bash-it-component-cache-file "${component}")"
|
file="$(_bash-it-component-cache-file "${component}")"
|
||||||
|
|
@ -87,7 +94,8 @@ function _bash-it-component-help() {
|
||||||
cat "${file}"
|
cat "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it-component-cache-file() {
|
function _bash-it-component-cache-file()
|
||||||
|
{
|
||||||
local component file
|
local component file
|
||||||
component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")"
|
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}"
|
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}"
|
printf '%s' "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it-pluralize-component() {
|
function _bash-it-pluralize-component()
|
||||||
|
{
|
||||||
local component="${1}"
|
local component="${1}"
|
||||||
local -i len=$((${#component} - 1))
|
local -i len=$((${#component} - 1))
|
||||||
# pluralize component name for consistency
|
# pluralize component name for consistency
|
||||||
|
|
@ -104,7 +113,8 @@ function _bash-it-pluralize-component() {
|
||||||
printf '%s' "${component}"
|
printf '%s' "${component}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it-clean-component-cache() {
|
function _bash-it-clean-component-cache()
|
||||||
|
{
|
||||||
local component="$1"
|
local component="$1"
|
||||||
local cache
|
local cache
|
||||||
local -a BASH_IT_COMPONENTS=(aliases plugins completions)
|
local -a BASH_IT_COMPONENTS=(aliases plugins completions)
|
||||||
|
|
@ -121,24 +131,28 @@ function _bash-it-clean-component-cache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Returns an array of items within each compoenent.
|
# Returns an array of items within each compoenent.
|
||||||
function _bash-it-component-list() {
|
function _bash-it-component-list()
|
||||||
|
{
|
||||||
local IFS=$'\n' component="$1"
|
local IFS=$'\n' component="$1"
|
||||||
_bash-it-component-help "${component}" | awk '{print $1}' | sort -u
|
_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"
|
local component="$1"
|
||||||
shift
|
shift
|
||||||
local term="$1"
|
local term="$1"
|
||||||
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -- "${term}" | awk '{print $1}' | sort -u
|
_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"
|
local IFS=$'\n' component="$1"
|
||||||
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | awk '{print $1}' | sort -u
|
_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"
|
local IFS=$'\n' component="$1"
|
||||||
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | awk '{print $1}' | sort -u
|
_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:
|
# Examples:
|
||||||
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
|
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
|
||||||
function _bash-it-component-item-is-enabled() {
|
function _bash-it-component-item-is-enabled()
|
||||||
|
{
|
||||||
local component="$1"
|
local component="$1"
|
||||||
local item="$2"
|
local item="$2"
|
||||||
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
|
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
|
||||||
|
|
@ -165,7 +180,8 @@ function _bash-it-component-item-is-enabled() {
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
|
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
|
||||||
function _bash-it-component-item-is-disabled() {
|
function _bash-it-component-item-is-disabled()
|
||||||
|
{
|
||||||
local component="$1"
|
local component="$1"
|
||||||
local item="$2"
|
local item="$2"
|
||||||
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
|
_bash-it-component-help "${component}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -v '\[x\]' | ${BASH_IT_GREP:-$(_bash-it-grep)} -E -q -- "^${item}\s"
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
|
# shellcheck disable=SC2002 # Prefer 'cat' for cleaner script
|
||||||
mapfile -t FILES < <(
|
mapfile -t FILES < <(
|
||||||
cat clean_files.txt \
|
cat clean_files.txt |
|
||||||
| grep -v -E '^\s*$' \
|
grep -v -E '^\s*$' |
|
||||||
| grep -v -E '^\s*#' \
|
grep -v -E '^\s*#' |
|
||||||
| xargs -n1 -I{} find "{}" -type f
|
xargs -n1 -I{} find "{}" -type f
|
||||||
)
|
)
|
||||||
|
|
||||||
# We clear the BASH_IT variable to help the shellcheck checker
|
# We clear the BASH_IT variable to help the shellcheck checker
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ about-plugin 'Automatic completion of aliases'
|
||||||
# 4) Custom scripts
|
# 4) Custom scripts
|
||||||
|
|
||||||
# Automatically add completion for all aliases to commands having completion functions
|
# Automatically add completion for all aliases to commands having completion functions
|
||||||
function alias_completion {
|
function alias_completion
|
||||||
|
{
|
||||||
local namespace="alias_completion"
|
local namespace="alias_completion"
|
||||||
local tmp_file completion_loader alias_name alias_tokens line completions
|
local tmp_file completion_loader alias_name alias_tokens line completions
|
||||||
local alias_arg_words new_completion compl_func compl_wrapper
|
local alias_arg_words new_completion compl_func compl_wrapper
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'miscellaneous tools'
|
about-plugin 'miscellaneous tools'
|
||||||
|
|
||||||
function ips() {
|
function ips()
|
||||||
|
{
|
||||||
about 'display all ip addresses for this host'
|
about 'display all ip addresses for this host'
|
||||||
group 'base'
|
group 'base'
|
||||||
if _command_exists ifconfig; then
|
if _command_exists ifconfig; then
|
||||||
|
|
@ -14,7 +15,8 @@ function ips() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function down4me() {
|
function down4me()
|
||||||
|
{
|
||||||
about 'checks whether a website is down for you, or everybody'
|
about 'checks whether a website is down for you, or everybody'
|
||||||
param '1: website url'
|
param '1: website url'
|
||||||
example '$ down4me http://www.google.com'
|
example '$ down4me http://www.google.com'
|
||||||
|
|
@ -22,7 +24,8 @@ function down4me() {
|
||||||
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
curl -Ls "http://downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g'
|
||||||
}
|
}
|
||||||
|
|
||||||
function myip() {
|
function myip()
|
||||||
|
{
|
||||||
about 'displays your ip address, as seen by the Internet'
|
about 'displays your ip address, as seen by the Internet'
|
||||||
group 'base'
|
group 'base'
|
||||||
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
|
list=("http://myip.dnsomatic.com/" "http://checkip.dyndns.com/" "http://checkip.dyndns.org/")
|
||||||
|
|
@ -35,7 +38,8 @@ function myip() {
|
||||||
echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
|
echo -e "Your public IP is: ${echo_bold_green-} $res ${echo_normal-}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickfrom() {
|
function pickfrom()
|
||||||
|
{
|
||||||
about 'picks random line from file'
|
about 'picks random line from file'
|
||||||
param '1: filename'
|
param '1: filename'
|
||||||
example '$ pickfrom /usr/share/dict/words'
|
example '$ pickfrom /usr/share/dict/words'
|
||||||
|
|
@ -50,7 +54,8 @@ function pickfrom() {
|
||||||
head -n "$n" "$file" | tail -1
|
head -n "$n" "$file" | tail -1
|
||||||
}
|
}
|
||||||
|
|
||||||
function passgen() {
|
function passgen()
|
||||||
|
{
|
||||||
about 'generates random password from dictionary words'
|
about 'generates random password from dictionary words'
|
||||||
param 'optional integer length'
|
param 'optional integer length'
|
||||||
param 'if unset, defaults to 4'
|
param 'if unset, defaults to 4'
|
||||||
|
|
@ -72,7 +77,8 @@ if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if _command_exists markdown && _command_exists browser; then
|
if _command_exists markdown && _command_exists browser; then
|
||||||
function pmdown() {
|
function pmdown()
|
||||||
|
{
|
||||||
about 'preview markdown file in a browser'
|
about 'preview markdown file in a browser'
|
||||||
param '1: markdown file'
|
param '1: markdown file'
|
||||||
example '$ pmdown README.md'
|
example '$ pmdown README.md'
|
||||||
|
|
@ -82,7 +88,8 @@ if _command_exists markdown && _command_exists browser; then
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function mkcd() {
|
function mkcd()
|
||||||
|
{
|
||||||
about 'make one or more directories and cd into the last one'
|
about 'make one or more directories and cd into the last one'
|
||||||
param 'one or more directories to create'
|
param 'one or more directories to create'
|
||||||
example '$ mkcd foo'
|
example '$ mkcd foo'
|
||||||
|
|
@ -94,19 +101,22 @@ function mkcd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2010
|
# shellcheck disable=SC2010
|
||||||
function lsgrep() {
|
function lsgrep()
|
||||||
|
{
|
||||||
about 'search through directory contents with grep'
|
about 'search through directory contents with grep'
|
||||||
group 'base'
|
group 'base'
|
||||||
ls | grep "$@"
|
ls | grep "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function quiet() {
|
function quiet()
|
||||||
|
{
|
||||||
about 'what *does* this do?'
|
about 'what *does* this do?'
|
||||||
group 'base'
|
group 'base'
|
||||||
nohup "$@" &> /dev/null < /dev/null &
|
nohup "$@" &> /dev/null < /dev/null &
|
||||||
}
|
}
|
||||||
|
|
||||||
function usage() {
|
function usage()
|
||||||
|
{
|
||||||
about 'disk usage per directory, in Mac OS X and Linux'
|
about 'disk usage per directory, in Mac OS X and Linux'
|
||||||
param '1: directory name'
|
param '1: directory name'
|
||||||
group 'base'
|
group 'base'
|
||||||
|
|
@ -124,7 +134,8 @@ function usage() {
|
||||||
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
|
if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
|
||||||
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
|
! -e "${BASH_IT?}/plugins/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR-}todo.plugin.bash" ]]; then
|
||||||
# if user has installed todo plugin, skip this...
|
# if user has installed todo plugin, skip this...
|
||||||
function t() {
|
function t()
|
||||||
|
{
|
||||||
about 'one thing todo'
|
about 'one thing todo'
|
||||||
param 'if not set, display todo item'
|
param 'if not set, display todo item'
|
||||||
param '1: todo text'
|
param '1: todo text'
|
||||||
|
|
@ -137,7 +148,8 @@ if [[ ! -e "${BASH_IT?}/plugins/enabled/todo.plugin.bash" &&
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if _command_exists mkisofs; then
|
if _command_exists mkisofs; then
|
||||||
function mkiso() {
|
function mkiso()
|
||||||
|
{
|
||||||
about 'creates iso from current dir in the parent dir (unless defined)'
|
about 'creates iso from current dir in the parent dir (unless defined)'
|
||||||
param '1: ISO name'
|
param '1: ISO name'
|
||||||
param '2: dest/path'
|
param '2: dest/path'
|
||||||
|
|
@ -160,7 +172,8 @@ if _command_exists mkisofs; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# useful for administrators and configs
|
# useful for administrators and configs
|
||||||
function buf() {
|
function buf()
|
||||||
|
{
|
||||||
about 'back up file with timestamp'
|
about 'back up file with timestamp'
|
||||||
param 'filename'
|
param 'filename'
|
||||||
group 'base'
|
group 'base'
|
||||||
|
|
@ -170,7 +183,8 @@ function buf() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! _command_exists del; then
|
if ! _command_exists del; then
|
||||||
function del() {
|
function del()
|
||||||
|
{
|
||||||
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
|
about 'move files to hidden folder in tmp, that gets cleared on each reboot'
|
||||||
param 'file or folder to be deleted'
|
param 'file or folder to be deleted'
|
||||||
example 'del ./file.txt'
|
example 'del ./file.txt'
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,15 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'Alert (BEL) when process ends after a threshold of seconds'
|
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)}))
|
export LAST_COMMAND_DURATION=$(($(date +%s) - ${LAST_COMMAND_TIME:=$(date +%s)}))
|
||||||
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
|
[[ ${LAST_COMMAND_DURATION} -gt ${NOTIFY_IF_COMMAND_RETURNS_AFTER:-5} ]] && echo -e "\a"
|
||||||
export LAST_COMMAND_TIME=
|
export LAST_COMMAND_TIME=
|
||||||
}
|
}
|
||||||
|
|
||||||
preexec_return_notification() {
|
preexec_return_notification()
|
||||||
|
{
|
||||||
[[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s)
|
[[ -z "${LAST_COMMAND_TIME}" ]] && LAST_COMMAND_TIME=$(date +%s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ alias pu="pushd"
|
||||||
# Pop current location
|
# Pop current location
|
||||||
alias po="popd"
|
alias po="popd"
|
||||||
|
|
||||||
function dirs-help() {
|
function dirs-help()
|
||||||
|
{
|
||||||
about 'directory navigation alias usage'
|
about 'directory navigation alias usage'
|
||||||
group 'dirs'
|
group 'dirs'
|
||||||
|
|
||||||
|
|
@ -67,39 +68,48 @@ fi
|
||||||
alias L='cat ~/.dirs'
|
alias L='cat ~/.dirs'
|
||||||
|
|
||||||
# Goes to destination dir, otherwise stay in the dir
|
# Goes to destination dir, otherwise stay in the dir
|
||||||
G () {
|
G()
|
||||||
|
{
|
||||||
about 'goes to destination dir'
|
about 'goes to destination dir'
|
||||||
param '1: directory'
|
param '1: directory'
|
||||||
example '$ G ..'
|
example '$ G ..'
|
||||||
group 'dirs'
|
group 'dirs'
|
||||||
|
|
||||||
cd "${1:-${PWD}}" ;
|
cd "${1:-${PWD}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
S () {
|
S()
|
||||||
|
{
|
||||||
about 'save a bookmark'
|
about 'save a bookmark'
|
||||||
param '1: bookmark name'
|
param '1: bookmark name'
|
||||||
example '$ S mybkmrk'
|
example '$ S mybkmrk'
|
||||||
group 'dirs'
|
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;
|
sed "/$@/d" ~/.dirs > ~/.dirs1
|
||||||
\mv ~/.dirs1 ~/.dirs;
|
\mv ~/.dirs1 ~/.dirs
|
||||||
echo "$@"=\""${PWD}"\" >> ~/.dirs;
|
echo "$@"=\""${PWD}"\" >> ~/.dirs
|
||||||
source ~/.dirs ;
|
source ~/.dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
R () {
|
R()
|
||||||
|
{
|
||||||
about 'remove a bookmark'
|
about 'remove a bookmark'
|
||||||
param '1: bookmark name'
|
param '1: bookmark name'
|
||||||
example '$ R mybkmrk'
|
example '$ R mybkmrk'
|
||||||
group 'dirs'
|
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;
|
sed "/$@/d" ~/.dirs > ~/.dirs1
|
||||||
\mv ~/.dirs1 ~/.dirs;
|
\mv ~/.dirs1 ~/.dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
alias U='source ~/.dirs' # Update bookmark stack
|
alias U='source ~/.dirs' # Update bookmark stack
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ cite about-plugin
|
||||||
about-plugin 'git helper functions'
|
about-plugin 'git helper functions'
|
||||||
|
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
function git_remote {
|
function git_remote
|
||||||
|
{
|
||||||
about 'adds remote $GIT_HOSTING:$1 to current repo'
|
about 'adds remote $GIT_HOSTING:$1 to current repo'
|
||||||
group "git"
|
group "git"
|
||||||
|
|
||||||
|
|
@ -11,7 +12,8 @@ function git_remote {
|
||||||
git remote add origin "${GIT_HOSTING}:${1}".git
|
git remote add origin "${GIT_HOSTING}:${1}".git
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_first_push {
|
function git_first_push
|
||||||
|
{
|
||||||
about 'push into origin refs/heads/master'
|
about 'push into origin refs/heads/master'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
|
|
@ -19,7 +21,8 @@ function git_first_push {
|
||||||
git push origin master:refs/heads/master
|
git push origin master:refs/heads/master
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_pub() {
|
function git_pub()
|
||||||
|
{
|
||||||
about 'publishes current branch to remote origin'
|
about 'publishes current branch to remote origin'
|
||||||
group 'git'
|
group 'git'
|
||||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
@ -28,7 +31,8 @@ function git_pub() {
|
||||||
git push -u origin "${BRANCH}"
|
git push -u origin "${BRANCH}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_revert() {
|
function git_revert()
|
||||||
|
{
|
||||||
about 'applies changes to HEAD that revert all changes after this commit'
|
about 'applies changes to HEAD that revert all changes after this commit'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
|
|
@ -38,25 +42,29 @@ function git_revert() {
|
||||||
git reset --hard
|
git reset --hard
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_rollback() {
|
function git_rollback()
|
||||||
|
{
|
||||||
about 'resets the current HEAD to this commit'
|
about 'resets the current HEAD to this commit'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
function is_clean() {
|
function is_clean()
|
||||||
|
{
|
||||||
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
|
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
|
||||||
echo "Your branch is dirty, please commit your changes"
|
echo "Your branch is dirty, please commit your changes"
|
||||||
kill -INT $$
|
kill -INT $$
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function commit_exists() {
|
function commit_exists()
|
||||||
|
{
|
||||||
if git rev-list --quiet "${1:?}"; then
|
if git rev-list --quiet "${1:?}"; then
|
||||||
echo "Commit ${1} does not exist"
|
echo "Commit ${1} does not exist"
|
||||||
kill -INT $$
|
kill -INT $$
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function keep_changes() {
|
function keep_changes()
|
||||||
|
{
|
||||||
while true; do
|
while true; do
|
||||||
# shellcheck disable=SC2162
|
# shellcheck disable=SC2162
|
||||||
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
read -p "Do you want to keep all changes from rolled back revisions in your working tree? [Y/N]" RESP
|
||||||
|
|
@ -105,7 +113,8 @@ function git_rollback() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_remove_missing_files() {
|
function git_remove_missing_files()
|
||||||
|
{
|
||||||
about "git rm's missing files"
|
about "git rm's missing files"
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
|
|
@ -113,7 +122,8 @@ function git_remove_missing_files() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Adds files to git's exclude file (same as .gitignore)
|
# 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'
|
about 'adds file or path to git exclude file'
|
||||||
param '1: file or path fragment to ignore'
|
param '1: file or path fragment to ignore'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
@ -121,7 +131,8 @@ function local-ignore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# get a quick overview for your git repo
|
# get a quick overview for your git repo
|
||||||
function git_info() {
|
function git_info()
|
||||||
|
{
|
||||||
about 'overview for your git repo'
|
about 'overview for your git repo'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
|
|
@ -158,7 +169,8 @@ function git_info() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_stats {
|
function git_stats
|
||||||
|
{
|
||||||
about 'display stats per author'
|
about 'display stats per author'
|
||||||
group 'git'
|
group 'git'
|
||||||
|
|
||||||
|
|
@ -203,7 +215,8 @@ function git_stats {
|
||||||
fi
|
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'
|
about 'Places the latest .gitignore file for a given project type in the current directory, or concatenates onto an existing .gitignore'
|
||||||
group 'git'
|
group 'git'
|
||||||
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
param '1: the language/type of the project, used for determining the contents of the .gitignore file'
|
||||||
|
|
@ -224,7 +237,8 @@ function gittowork() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function gitignore-reload() {
|
function gitignore-reload()
|
||||||
|
{
|
||||||
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
|
about 'Empties the git cache, and readds all files not blacklisted by .gitignore'
|
||||||
group 'git'
|
group 'git'
|
||||||
example '$ gitignore-reload'
|
example '$ gitignore-reload'
|
||||||
|
|
@ -274,7 +288,8 @@ function gitignore-reload() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git-changelog() {
|
function git-changelog()
|
||||||
|
{
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
|
# ORIGINAL ANSWER: https://stackoverflow.com/a/2979587/10362396 |
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -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
|
# Test `go version` because goenv creates shim scripts that will be found in PATH
|
||||||
# but do not always resolve to a working install.
|
# 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 GOROOT="${GOROOT:-$(go env GOROOT)}"
|
||||||
export GOPATH="${GOPATH:-$(go env GOPATH)}"
|
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,
|
# might be managed differently, we add each path's /bin folder to PATH using pathmunge,
|
||||||
# while preserving ordering.
|
# while preserving ordering.
|
||||||
# e.g. GOPATH=foo:bar -> PATH=foo/bin:bar/bin
|
# 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'
|
_about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended'
|
||||||
_group 'go'
|
_group 'go'
|
||||||
if [[ -z $GOPATH ]]; then
|
if [[ -z $GOPATH ]]; then
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ about-plugin 'load goenv, if you are using it'
|
||||||
# - Check if in $PATH already
|
# - Check if in $PATH already
|
||||||
# - Check if installed manually to $GOENV_ROOT
|
# - Check if installed manually to $GOENV_ROOT
|
||||||
# - Check if installed manually to $HOME
|
# - Check if installed manually to $HOME
|
||||||
_command_exists goenv \
|
_command_exists goenv ||
|
||||||
|| [[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] \
|
[[ -n "$GOENV_ROOT" && -x "$GOENV_ROOT/bin/goenv" ]] ||
|
||||||
|| [[ -x "$HOME/.goenv/bin/goenv" ]] \
|
[[ -x "$HOME/.goenv/bin/goenv" ]] ||
|
||||||
|| return 0
|
return 0
|
||||||
|
|
||||||
# Set GOENV_ROOT, if not already set
|
# Set GOENV_ROOT, if not already set
|
||||||
export GOENV_ROOT="${GOENV_ROOT:-$HOME/.goenv}"
|
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
|
# If moving to a directory with a goenv version set, reload the shell
|
||||||
# to ensure the shell environment matches expectations.
|
# to ensure the shell environment matches expectations.
|
||||||
_bash-it-goenv-preexec() {
|
_bash-it-goenv-preexec()
|
||||||
|
{
|
||||||
GOENV_OLD_VERSION="$(goenv version-name)"
|
GOENV_OLD_VERSION="$(goenv version-name)"
|
||||||
}
|
}
|
||||||
_bash-it-goenv-precmd() {
|
_bash-it-goenv-precmd()
|
||||||
|
{
|
||||||
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
|
if [[ -n $GOENV_OLD_VERSION ]] && [[ "$GOENV_OLD_VERSION" != "$(goenv version-name)" ]]; then
|
||||||
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
|
exec env -u PATH -u GOROOT -u GOPATH -u GOENV_OLD_VERSION "${0/-/}" --login
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ export HISTCONTROL=${HISTCONTROL:-ignorespace:erasedups}
|
||||||
# resize history to 100x the default (500)
|
# resize history to 100x the default (500)
|
||||||
export HISTSIZE=${HISTSIZE:-50000}
|
export HISTSIZE=${HISTSIZE:-50000}
|
||||||
|
|
||||||
top-history() {
|
top-history()
|
||||||
|
{
|
||||||
about 'print the name and count of the most commonly run tools'
|
about 'print the name and count of the most commonly run tools'
|
||||||
|
|
||||||
if [[ -n $HISTTIMEFORMAT ]]; then
|
if [[ -n $HISTTIMEFORMAT ]]; then
|
||||||
|
|
@ -23,16 +24,16 @@ top-history() {
|
||||||
unset HISTTIMEFORMAT
|
unset HISTTIMEFORMAT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
history \
|
history |
|
||||||
| awk '{
|
awk '{
|
||||||
a[$2]++
|
a[$2]++
|
||||||
}END{
|
}END{
|
||||||
for(i in a)
|
for(i in a)
|
||||||
printf("%s\t%s\n", a[i], i)
|
printf("%s\t%s\n", a[i], i)
|
||||||
}' \
|
}' |
|
||||||
| sort --reverse --numeric-sort \
|
sort --reverse --numeric-sort |
|
||||||
| head \
|
head |
|
||||||
| column \
|
column \
|
||||||
--table \
|
--table \
|
||||||
--table-columns 'Command Count,Command Name' \
|
--table-columns 'Command Count,Command Name' \
|
||||||
--output-separator ' | '
|
--output-separator ' | '
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding'
|
about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding'
|
||||||
|
|
||||||
function __init_jump() {
|
function __init_jump()
|
||||||
|
{
|
||||||
if _command_exists jump; then
|
if _command_exists jump; then
|
||||||
eval "$(jump shell bash "${JUMP_OPTS[@]}")"
|
eval "$(jump shell bash "${JUMP_OPTS[@]}")"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ _command_exists pygmentize || return
|
||||||
|
|
||||||
# pigmentize cat and less outputs - call them ccat and cless to avoid that
|
# pigmentize cat and less outputs - call them ccat and cless to avoid that
|
||||||
# especially cat'ed output in scripts gets mangled with pygemtized meta characters
|
# especially cat'ed output in scripts gets mangled with pygemtized meta characters
|
||||||
function ccat() {
|
function ccat()
|
||||||
|
{
|
||||||
about 'runs pygmentize on each file passed in'
|
about 'runs pygmentize on each file passed in'
|
||||||
param '*: files to concatenate (as normally passed to cat)'
|
param '*: files to concatenate (as normally passed to cat)'
|
||||||
example 'ccat mysite/manage.py dir/text-file.txt'
|
example '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 "$@"
|
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'
|
about 'pigments the files passed in and passes to less for pagination'
|
||||||
param '*: the files to paginate with less'
|
param '*: the files to paginate with less'
|
||||||
example 'cless mysite/manage.py'
|
example 'cless mysite/manage.py'
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ if [[ ${BASH_VERSINFO[0]} -lt 4 ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function _replace_by_history() {
|
function _replace_by_history()
|
||||||
|
{
|
||||||
local HISTTIMEFORMAT= # Ensure we can parse history properly
|
local HISTTIMEFORMAT= # Ensure we can parse history properly
|
||||||
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
|
#TODO: "${histlines[@]/*( )+([[:digit:]])*( )/}"
|
||||||
local l
|
local l
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ about-plugin 'load pyenv, if you are using it'
|
||||||
# - Check if in $PATH already
|
# - Check if in $PATH already
|
||||||
# - Check if installed manually to $PYENV_ROOT
|
# - Check if installed manually to $PYENV_ROOT
|
||||||
# - Check if installed manually to $HOME
|
# - Check if installed manually to $HOME
|
||||||
_command_exists pyenv \
|
_command_exists pyenv ||
|
||||||
|| [[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] \
|
[[ -n "$PYENV_ROOT" && -x "$PYENV_ROOT/bin/pyenv" ]] ||
|
||||||
|| [[ -x "$HOME/.pyenv/bin/pyenv" ]] \
|
[[ -x "$HOME/.pyenv/bin/pyenv" ]] ||
|
||||||
|| return 0
|
return 0
|
||||||
|
|
||||||
# Set PYENV_ROOT, if not already set
|
# Set PYENV_ROOT, if not already set
|
||||||
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
|
export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}"
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ if _command_exists ruby && _command_exists gem; then
|
||||||
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
|
pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function remove_gem() {
|
function remove_gem()
|
||||||
|
{
|
||||||
about 'removes installed gem'
|
about 'removes installed gem'
|
||||||
param '1: installed gem name'
|
param '1: installed gem name'
|
||||||
group 'ruby'
|
group 'ruby'
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
cite about-plugin
|
cite about-plugin
|
||||||
about-plugin 'automatically set your xterm title with host and location info'
|
about-plugin 'automatically set your xterm title with host and location info'
|
||||||
|
|
||||||
_short-dirname() {
|
_short-dirname()
|
||||||
|
{
|
||||||
local dir_name="${PWD/~/\~}"
|
local dir_name="${PWD/~/\~}"
|
||||||
if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
|
if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then
|
||||||
echo "${dir_name##*/}"
|
echo "${dir_name##*/}"
|
||||||
|
|
@ -11,7 +12,8 @@ _short-dirname() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_short-command() {
|
_short-command()
|
||||||
|
{
|
||||||
local input_command="$*"
|
local input_command="$*"
|
||||||
if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
|
if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then
|
||||||
echo "${input_command%% *}"
|
echo "${input_command%% *}"
|
||||||
|
|
@ -20,16 +22,19 @@ _short-command() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
set_xterm_title() {
|
set_xterm_title()
|
||||||
|
{
|
||||||
local title="${1:-}"
|
local title="${1:-}"
|
||||||
echo -ne "\033]0;${title}\007"
|
echo -ne "\033]0;${title}\007"
|
||||||
}
|
}
|
||||||
|
|
||||||
precmd_xterm_title() {
|
precmd_xterm_title()
|
||||||
|
{
|
||||||
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
|
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}"
|
||||||
}
|
}
|
||||||
|
|
||||||
preexec_xterm_title() {
|
preexec_xterm_title()
|
||||||
|
{
|
||||||
set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
set_xterm_title "$(_short-command "${1:-}") {$(_short-dirname)} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,13 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
|
||||||
_bash_it_config_type=""
|
_bash_it_config_type=""
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
alias|completion|plugin)
|
alias | completion | plugin)
|
||||||
_bash_it_config_type=$1
|
_bash_it_config_type=$1
|
||||||
_log_debug "Loading enabled $1 components..." ;;
|
_log_debug "Loading enabled $1 components..."
|
||||||
''|*)
|
;;
|
||||||
_log_debug "Loading all enabled components..." ;;
|
'' | *)
|
||||||
|
_log_debug "Loading all enabled components..."
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do
|
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
|
if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
|
||||||
case $2 in
|
case $2 in
|
||||||
aliases|completion|plugins)
|
aliases | completion | plugins)
|
||||||
_log_warning "Using legacy enabling for $2, please update your bash-it version and migrate"
|
_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
|
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do
|
||||||
if [[ -e "$_bash_it_config_file" ]]; then
|
if [[ -e "$_bash_it_config_file" ]]; then
|
||||||
|
|
@ -45,7 +47,8 @@ if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
|
||||||
else
|
else
|
||||||
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
|
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
|
||||||
fi
|
fi
|
||||||
done ;;
|
done
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,13 @@ load "${TEST_DEPS_DIR}/bats-file/load.bash"
|
||||||
# support 'plumbing' metadata
|
# support 'plumbing' metadata
|
||||||
cite _about _param _example _group _author _version
|
cite _about _param _example _group _author _version
|
||||||
|
|
||||||
local_setup() {
|
local_setup()
|
||||||
|
{
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
local_teardown() {
|
local_teardown()
|
||||||
|
{
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,7 +36,8 @@ local_teardown() {
|
||||||
# fresh and isolated Bash-it directory. This is done to avoid
|
# fresh and isolated Bash-it directory. This is done to avoid
|
||||||
# messing with your own Bash-it source directory.
|
# messing with your own Bash-it source directory.
|
||||||
# If you need this, call it in your .bats file's `local_setup` function.
|
# If you need this, call it in your .bats file's `local_setup` function.
|
||||||
setup_test_fixture() {
|
setup_test_fixture()
|
||||||
|
{
|
||||||
mkdir -p "$BASH_IT"
|
mkdir -p "$BASH_IT"
|
||||||
lib_directory="$(cd "$(dirname "$0")" && pwd)"
|
lib_directory="$(cd "$(dirname "$0")" && pwd)"
|
||||||
local src_topdir="$lib_directory/../../../.."
|
local src_topdir="$lib_directory/../../../.."
|
||||||
|
|
@ -66,7 +69,8 @@ setup_test_fixture() {
|
||||||
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
|
export BASH_IT_TEST_HOME="$TEST_TEMP_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() {
|
setup()
|
||||||
|
{
|
||||||
# The `temp_make` function from "bats-file" requires the tralston/bats-file fork,
|
# 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.
|
# since the original ztombol/bats-file's `temp_make` does not work on macOS.
|
||||||
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
|
TEST_TEMP_DIR="$(temp_make --prefix 'bash-it-test-')"
|
||||||
|
|
@ -96,7 +100,8 @@ setup() {
|
||||||
local_setup
|
local_setup
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown()
|
||||||
|
{
|
||||||
local_teardown
|
local_teardown
|
||||||
|
|
||||||
rm -rf "${BASH_IT_TEST_DIR}"
|
rm -rf "${BASH_IT_TEST_DIR}"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ GIT_THEME_PROMPT_PREFIX=" ${green}|"
|
||||||
GIT_THEME_PROMPT_SUFFIX="${green}|"
|
GIT_THEME_PROMPT_SUFFIX="${green}|"
|
||||||
|
|
||||||
# Nicely formatted terminal prompt
|
# 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}\$ "
|
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}\$ "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ PROMPT_DIRTRIM=2 # bash4 and above
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
debug() {
|
debug()
|
||||||
|
{
|
||||||
if [[ ${DEBUG} -ne 0 ]]; then
|
if [[ ${DEBUG} -ne 0 ]]; then
|
||||||
echo >&2 -e "$@"
|
echo >&2 -e "$@"
|
||||||
fi
|
fi
|
||||||
|
|
@ -87,7 +88,8 @@ RIGHT_SEPARATOR=''
|
||||||
LEFT_SUBSEG=''
|
LEFT_SUBSEG=''
|
||||||
RIGHT_SUBSEG=''
|
RIGHT_SUBSEG=''
|
||||||
|
|
||||||
text_effect() {
|
text_effect()
|
||||||
|
{
|
||||||
case "$1" in
|
case "$1" in
|
||||||
reset) echo 0 ;;
|
reset) echo 0 ;;
|
||||||
bold) echo 1 ;;
|
bold) echo 1 ;;
|
||||||
|
|
@ -98,7 +100,8 @@ text_effect() {
|
||||||
# to add colors, see
|
# to add colors, see
|
||||||
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
|
# 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
|
# under the "256 (8-bit) Colors" section, and follow the example for orange below
|
||||||
fg_color() {
|
fg_color()
|
||||||
|
{
|
||||||
case "$1" in
|
case "$1" in
|
||||||
black) echo 30 ;;
|
black) echo 30 ;;
|
||||||
red) echo 31 ;;
|
red) echo 31 ;;
|
||||||
|
|
@ -112,7 +115,8 @@ fg_color() {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
bg_color() {
|
bg_color()
|
||||||
|
{
|
||||||
case "$1" in
|
case "$1" in
|
||||||
black) echo 40 ;;
|
black) echo 40 ;;
|
||||||
red) echo 41 ;;
|
red) echo 41 ;;
|
||||||
|
|
@ -129,7 +133,8 @@ bg_color() {
|
||||||
# TIL: declare is global not local, so best use a different name
|
# TIL: declare is global not local, so best use a different name
|
||||||
# for codes (mycodes) as otherwise it'll clobber the original.
|
# for codes (mycodes) as otherwise it'll clobber the original.
|
||||||
# this changes from BASH v3 to BASH v4.
|
# this changes from BASH v3 to BASH v4.
|
||||||
ansi() {
|
ansi()
|
||||||
|
{
|
||||||
local seq
|
local seq
|
||||||
declare -a mycodes=("${!1}")
|
declare -a mycodes=("${!1}")
|
||||||
|
|
||||||
|
|
@ -147,14 +152,16 @@ ansi() {
|
||||||
# PR="$PR\[\033[${seq}m\]"
|
# PR="$PR\[\033[${seq}m\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
ansi_single() {
|
ansi_single()
|
||||||
|
{
|
||||||
echo -ne '\[\033['"$1"'m\]'
|
echo -ne '\[\033['"$1"'m\]'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Begin a segment
|
# Begin a segment
|
||||||
# Takes two arguments, background and foreground. Both can be omitted,
|
# Takes two arguments, background and foreground. Both can be omitted,
|
||||||
# rendering default background/foreground.
|
# rendering default background/foreground.
|
||||||
prompt_segment() {
|
prompt_segment()
|
||||||
|
{
|
||||||
local bg fg
|
local bg fg
|
||||||
declare -a codes
|
declare -a codes
|
||||||
|
|
||||||
|
|
@ -196,7 +203,8 @@ prompt_segment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# End the prompt, closing any open segments
|
# End the prompt, closing any open segments
|
||||||
prompt_end() {
|
prompt_end()
|
||||||
|
{
|
||||||
if [[ -n $CURRENT_BG ]]; then
|
if [[ -n $CURRENT_BG ]]; then
|
||||||
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
|
declare -a codes=("$(text_effect reset)" "$(fg_color "$CURRENT_BG")")
|
||||||
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
PR="$PR $(ansi codes[@])$SEGMENT_SEPARATOR"
|
||||||
|
|
@ -207,7 +215,8 @@ prompt_end() {
|
||||||
}
|
}
|
||||||
|
|
||||||
### virtualenv prompt
|
### virtualenv prompt
|
||||||
prompt_virtualenv() {
|
prompt_virtualenv()
|
||||||
|
{
|
||||||
if [[ -n $VIRTUAL_ENV ]]; then
|
if [[ -n $VIRTUAL_ENV ]]; then
|
||||||
color=cyan
|
color=cyan
|
||||||
prompt_segment $color "$PRIMARY_FG"
|
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
|
# 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)
|
# Context: user@hostname (who am I and where am I)
|
||||||
prompt_context() {
|
prompt_context()
|
||||||
|
{
|
||||||
local user="${USER:-${LOGNAME:?}}"
|
local user="${USER:-${LOGNAME:?}}"
|
||||||
|
|
||||||
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
|
if [[ $user != "$DEFAULT_USER" || -n $SSH_CLIENT ]]; then
|
||||||
|
|
@ -230,17 +240,20 @@ prompt_context() {
|
||||||
|
|
||||||
# prints history followed by HH:MM, useful for remembering what
|
# prints history followed by HH:MM, useful for remembering what
|
||||||
# we did previously
|
# we did previously
|
||||||
prompt_histdt() {
|
prompt_histdt()
|
||||||
|
{
|
||||||
prompt_segment black default "\! [\A]"
|
prompt_segment black default "\! [\A]"
|
||||||
}
|
}
|
||||||
|
|
||||||
git_status_dirty() {
|
git_status_dirty()
|
||||||
|
{
|
||||||
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
dirty=$(git status -s 2> /dev/null | tail -n 1)
|
||||||
[[ -n $dirty ]] && echo " ●"
|
[[ -n $dirty ]] && echo " ●"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Git: branch/detached head, dirty status
|
# Git: branch/detached head, dirty status
|
||||||
prompt_git() {
|
prompt_git()
|
||||||
|
{
|
||||||
local ref dirty
|
local ref dirty
|
||||||
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
if git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||||
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
ZSH_THEME_GIT_PROMPT_DIRTY='±'
|
||||||
|
|
@ -256,7 +269,8 @@ prompt_git() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dir: current working directory
|
# Dir: current working directory
|
||||||
prompt_dir() {
|
prompt_dir()
|
||||||
|
{
|
||||||
prompt_segment blue black '\w'
|
prompt_segment blue black '\w'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -264,7 +278,8 @@ prompt_dir() {
|
||||||
# - was there an error
|
# - was there an error
|
||||||
# - am I root
|
# - am I root
|
||||||
# - are there background jobs?
|
# - are there background jobs?
|
||||||
prompt_status() {
|
prompt_status()
|
||||||
|
{
|
||||||
local symbols
|
local symbols
|
||||||
symbols=()
|
symbols=()
|
||||||
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘")
|
[[ $RETVAL -ne 0 ]] && symbols+=("$(ansi_single "$(fg_color red)")✘")
|
||||||
|
|
@ -280,12 +295,14 @@ prompt_status() {
|
||||||
# requires setting prompt_foo to use PRIGHT vs PR
|
# requires setting prompt_foo to use PRIGHT vs PR
|
||||||
# doesn't quite work per above
|
# doesn't quite work per above
|
||||||
|
|
||||||
rightprompt() {
|
rightprompt()
|
||||||
|
{
|
||||||
printf "%*s" $COLUMNS "$PRIGHT"
|
printf "%*s" $COLUMNS "$PRIGHT"
|
||||||
}
|
}
|
||||||
|
|
||||||
# quick right prompt I grabbed to test things.
|
# quick right prompt I grabbed to test things.
|
||||||
__command_rprompt() {
|
__command_rprompt()
|
||||||
|
{
|
||||||
local times=n=$COLUMNS tz
|
local times=n=$COLUMNS tz
|
||||||
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
for tz in ZRH:Europe/Zurich PIT:US/Eastern \
|
||||||
MTV:US/Pacific TOK:Asia/Tokyo; do
|
MTV:US/Pacific TOK:Asia/Tokyo; do
|
||||||
|
|
@ -299,7 +316,8 @@ __command_rprompt() {
|
||||||
# PROMPT_COMMAND=__command_rprompt
|
# PROMPT_COMMAND=__command_rprompt
|
||||||
|
|
||||||
# this doens't wrap code in \[ \]
|
# this doens't wrap code in \[ \]
|
||||||
ansi_r() {
|
ansi_r()
|
||||||
|
{
|
||||||
local seq
|
local seq
|
||||||
declare -a mycodes2=("${!1}")
|
declare -a mycodes2=("${!1}")
|
||||||
|
|
||||||
|
|
@ -320,7 +338,8 @@ ansi_r() {
|
||||||
# Begin a segment on the right
|
# Begin a segment on the right
|
||||||
# Takes two arguments, background and foreground. Both can be omitted,
|
# Takes two arguments, background and foreground. Both can be omitted,
|
||||||
# rendering default background/foreground.
|
# rendering default background/foreground.
|
||||||
prompt_right_segment() {
|
prompt_right_segment()
|
||||||
|
{
|
||||||
local bg fg
|
local bg fg
|
||||||
declare -a codes
|
declare -a codes
|
||||||
|
|
||||||
|
|
@ -383,7 +402,8 @@ prompt_right_segment() {
|
||||||
# (add-hook 'comint-preoutput-filter-functions
|
# (add-hook 'comint-preoutput-filter-functions
|
||||||
# 'dirtrack-filter-out-pwd-prompt t t)))
|
# 'dirtrack-filter-out-pwd-prompt t t)))
|
||||||
|
|
||||||
prompt_emacsdir() {
|
prompt_emacsdir()
|
||||||
|
{
|
||||||
# no color or other setting... this will be deleted per above
|
# no color or other setting... this will be deleted per above
|
||||||
PR="DIR \w DIR$PR"
|
PR="DIR \w DIR$PR"
|
||||||
}
|
}
|
||||||
|
|
@ -391,7 +411,8 @@ prompt_emacsdir() {
|
||||||
######################################################################
|
######################################################################
|
||||||
## Main prompt
|
## Main prompt
|
||||||
|
|
||||||
build_prompt() {
|
build_prompt()
|
||||||
|
{
|
||||||
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
[[ -n ${AG_EMACS_DIR+x} ]] && prompt_emacsdir
|
||||||
prompt_status
|
prompt_status
|
||||||
#[[ -z ${AG_NO_HIST+x} ]] && prompt_histdt
|
#[[ -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
|
# this doesn't work... new model: create a prompt via a PR variable and
|
||||||
# use that.
|
# use that.
|
||||||
|
|
||||||
set_bash_prompt() {
|
set_bash_prompt()
|
||||||
|
{
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
PR=""
|
PR=""
|
||||||
PRIGHT=""
|
PRIGHT=""
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ Face="\342\230\273"
|
||||||
## Parsers ##
|
## Parsers ##
|
||||||
#############
|
#############
|
||||||
|
|
||||||
____atomic_top_left_parse() {
|
____atomic_top_left_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -44,7 +45,8 @@ ____atomic_top_left_parse() {
|
||||||
_TOP_LEFT+=""
|
_TOP_LEFT+=""
|
||||||
}
|
}
|
||||||
|
|
||||||
____atomic_top_right_parse() {
|
____atomic_top_right_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -61,7 +63,8 @@ ____atomic_top_right_parse() {
|
||||||
((__SEG_AT_RIGHT += 1))
|
((__SEG_AT_RIGHT += 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
____atomic_bottom_parse() {
|
____atomic_bottom_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -70,7 +73,8 @@ ____atomic_bottom_parse() {
|
||||||
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
||||||
}
|
}
|
||||||
|
|
||||||
____atomic_top() {
|
____atomic_top()
|
||||||
|
{
|
||||||
_TOP_LEFT=""
|
_TOP_LEFT=""
|
||||||
_TOP_RIGHT=""
|
_TOP_RIGHT=""
|
||||||
__TOP_RIGHT_LEN=0
|
__TOP_RIGHT_LEN=0
|
||||||
|
|
@ -96,7 +100,8 @@ ____atomic_top() {
|
||||||
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
||||||
}
|
}
|
||||||
|
|
||||||
____atomic_bottom() {
|
____atomic_bottom()
|
||||||
|
{
|
||||||
_BOTTOM=""
|
_BOTTOM=""
|
||||||
for seg in $___ATOMIC_BOTTOM; do
|
for seg in $___ATOMIC_BOTTOM; do
|
||||||
info="$(___atomic_prompt_"${seg}")"
|
info="$(___atomic_prompt_"${seg}")"
|
||||||
|
|
@ -109,7 +114,8 @@ ____atomic_bottom() {
|
||||||
## Segments ##
|
## Segments ##
|
||||||
##############
|
##############
|
||||||
|
|
||||||
___atomic_prompt_user_info() {
|
___atomic_prompt_user_info()
|
||||||
|
{
|
||||||
color=$white
|
color=$white
|
||||||
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
|
box="${normal}${LineA}\$([[ \$? != 0 ]] && echo \"${BIWhite}[${IRed}${SX}${BIWhite}]${normal}${Line}\")${Line}${BIWhite}[|${BIWhite}]${normal}${Line}"
|
||||||
info="${IYellow}\u${IRed}@${IGreen}\h"
|
info="${IYellow}\u${IRed}@${IGreen}\h"
|
||||||
|
|
@ -117,14 +123,16 @@ ___atomic_prompt_user_info() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_dir() {
|
___atomic_prompt_dir()
|
||||||
|
{
|
||||||
color=${IRed}
|
color=${IRed}
|
||||||
box="[|]${normal}"
|
box="[|]${normal}"
|
||||||
info="\w"
|
info="\w"
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_scm() {
|
___atomic_prompt_scm()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
||||||
color=$bold_green
|
color=$bold_green
|
||||||
box="${Line}[${IWhite}$(scm_char)] "
|
box="${Line}[${IWhite}$(scm_char)] "
|
||||||
|
|
@ -132,7 +140,8 @@ ___atomic_prompt_scm() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_python() {
|
___atomic_prompt_python()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
||||||
color=$bold_yellow
|
color=$bold_yellow
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -140,7 +149,8 @@ ___atomic_prompt_python() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_ruby() {
|
___atomic_prompt_ruby()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -148,16 +158,18 @@ ___atomic_prompt_ruby() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_todo() {
|
___atomic_prompt_todo()
|
||||||
[ "${THEME_SHOW_TODO}" != "true" ] \
|
{
|
||||||
|| [ -z "$(which todo.sh)" ] && return
|
[ "${THEME_SHOW_TODO}" != "true" ] ||
|
||||||
|
[ -z "$(which todo.sh)" ] && return
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
box="[|]"
|
box="[|]"
|
||||||
info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')"
|
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}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_clock() {
|
___atomic_prompt_clock()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
||||||
color=$THEME_CLOCK_COLOR
|
color=$THEME_CLOCK_COLOR
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -165,10 +177,11 @@ ___atomic_prompt_clock() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_battery() {
|
___atomic_prompt_battery()
|
||||||
! _command_exists battery_percentage \
|
{
|
||||||
|| [ "${THEME_SHOW_BATTERY}" != "true" ] \
|
! _command_exists battery_percentage ||
|
||||||
|| [ "$(battery_percentage)" = "no" ] && return
|
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
|
||||||
|
[ "$(battery_percentage)" = "no" ] && return
|
||||||
|
|
||||||
batp=$(battery_percentage)
|
batp=$(battery_percentage)
|
||||||
if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then
|
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}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_exitcode() {
|
___atomic_prompt_exitcode()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
||||||
color=$bold_purple
|
color=$bold_purple
|
||||||
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___atomic_prompt_char() {
|
___atomic_prompt_char()
|
||||||
|
{
|
||||||
color=$white
|
color=$white
|
||||||
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
|
prompt_char="${__ATOMIC_PROMPT_CHAR_PS1}"
|
||||||
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
||||||
|
|
@ -207,19 +222,22 @@ ___atomic_prompt_char() {
|
||||||
## cli ##
|
## cli ##
|
||||||
#########
|
#########
|
||||||
|
|
||||||
__atomic_show() {
|
__atomic_show()
|
||||||
|
{
|
||||||
typeset _seg=${1:-}
|
typeset _seg=${1:-}
|
||||||
shift
|
shift
|
||||||
export "THEME_SHOW_${_seg}"=true
|
export "THEME_SHOW_${_seg}"=true
|
||||||
}
|
}
|
||||||
|
|
||||||
__atomic_hide() {
|
__atomic_hide()
|
||||||
|
{
|
||||||
typeset _seg=${1:-}
|
typeset _seg=${1:-}
|
||||||
shift
|
shift
|
||||||
export "THEME_SHOW_${_seg}"=false
|
export "THEME_SHOW_${_seg}"=false
|
||||||
}
|
}
|
||||||
|
|
||||||
_atomic_completion() {
|
_atomic_completion()
|
||||||
|
{
|
||||||
local cur _action actions segments
|
local cur _action actions segments
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
@ -239,7 +257,8 @@ _atomic_completion() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic() {
|
atomic()
|
||||||
|
{
|
||||||
typeset action=${1:-}
|
typeset action=${1:-}
|
||||||
shift
|
shift
|
||||||
typeset segs=${*:-}
|
typeset segs=${*:-}
|
||||||
|
|
@ -303,16 +322,19 @@ ___ATOMIC_BOTTOM=${___ATOMIC_BOTTOM:-"char"}
|
||||||
## Prompt ##
|
## Prompt ##
|
||||||
############
|
############
|
||||||
|
|
||||||
__atomic_ps1() {
|
__atomic_ps1()
|
||||||
|
{
|
||||||
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
|
printf "%s%s%s" "$(____atomic_top)" "$(____atomic_bottom)" "${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__atomic_ps2() {
|
__atomic_ps2()
|
||||||
|
{
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
|
printf "%s%s%s" "${color}" "${__ATOMIC_PROMPT_CHAR_PS2} " "${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_atomic_prompt() {
|
_atomic_prompt()
|
||||||
|
{
|
||||||
exitcode="$?"
|
exitcode="$?"
|
||||||
|
|
||||||
PS1="$(__atomic_ps1)"
|
PS1="$(__atomic_ps1)"
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ else
|
||||||
RESET="\033[m"
|
RESET="\033[m"
|
||||||
fi
|
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\]"
|
PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]@ \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\[$SCM_THEME_PROMPT_PREFIX\]$(clock_prompt) \[$PURPLE\]$(scm_prompt_info) \n\$ \[$RESET\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
|
||||||
RVM_THEME_PROMPT_PREFIX="|"
|
RVM_THEME_PROMPT_PREFIX="|"
|
||||||
RVM_THEME_PROMPT_SUFFIX="|"
|
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="${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${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} "
|
#PS1="\n${cyan}\h: ${reset_color} ${yellow}\w\n${red}$(scm_char)${red}$(scm_prompt_info) ${green}→${reset_color} "
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ SCM_THEME_BRANCH_TRACK_PREFIX="${normal} ⤏ ${cyan}"
|
||||||
SCM_THEME_CURRENT_USER_PREFFIX=' '
|
SCM_THEME_CURRENT_USER_PREFFIX=' '
|
||||||
SCM_GIT_SHOW_CURRENT_USER=false
|
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"
|
[[ "$(_git-upstream)" == "" ]] && SCM_GIT_CHAR="$SCM_GIT_CHAR_DEFAULT"
|
||||||
|
|
||||||
local remote remote_domain
|
local remote remote_domain
|
||||||
|
|
@ -59,12 +60,14 @@ function _git-uptream-remote-logo {
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_prompt_info {
|
function git_prompt_info
|
||||||
|
{
|
||||||
git_prompt_vars
|
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"
|
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
|
if [[ "$1" -ne 0 ]]; then
|
||||||
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
exit_code=" ${purple}${EXIT_CODE_ICON}${yellow}${exit_code}${bold_orange}"
|
||||||
else
|
else
|
||||||
|
|
@ -72,7 +75,8 @@ function _exit-code {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _prompt {
|
function _prompt
|
||||||
|
{
|
||||||
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
local exit_code="$?" wrap_char=' ' dir_color=$green ssh_info='' python_venv='' host command_duration=
|
||||||
|
|
||||||
command_duration=$(_command_duration)
|
command_duration=$(_command_duration)
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,8 @@ RBFU_THEME_PROMPT_SUFFIX='|'
|
||||||
: "${HG_EXE:=$SCM_HG}"
|
: "${HG_EXE:=$SCM_HG}"
|
||||||
: "${SVN_EXE:=$SCM_SVN}"
|
: "${SVN_EXE:=$SCM_SVN}"
|
||||||
|
|
||||||
function _bash_it_appearance_scm_init() {
|
function _bash_it_appearance_scm_init()
|
||||||
|
{
|
||||||
GIT_EXE="$(type -P $SCM_GIT || true)"
|
GIT_EXE="$(type -P $SCM_GIT || true)"
|
||||||
P4_EXE="$(type -P $SCM_P4 || true)"
|
P4_EXE="$(type -P $SCM_P4 || true)"
|
||||||
HG_EXE="$(type -P $SCM_HG || true)"
|
HG_EXE="$(type -P $SCM_HG || true)"
|
||||||
|
|
@ -108,7 +109,8 @@ function _bash_it_appearance_scm_init() {
|
||||||
}
|
}
|
||||||
_bash_it_appearance_scm_init
|
_bash_it_appearance_scm_init
|
||||||
|
|
||||||
function scm {
|
function scm
|
||||||
|
{
|
||||||
if [[ "$SCM_CHECK" = false ]]; then
|
if [[ "$SCM_CHECK" = false ]]; then
|
||||||
SCM=$SCM_NONE
|
SCM=$SCM_NONE
|
||||||
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
|
elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then
|
||||||
|
|
@ -130,7 +132,8 @@ function scm {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
scm_prompt() {
|
scm_prompt()
|
||||||
|
{
|
||||||
local CHAR
|
local CHAR
|
||||||
CHAR="$(scm_char)"
|
CHAR="$(scm_char)"
|
||||||
local format=${SCM_PROMPT_FORMAT:-'[%s%s]'}
|
local format=${SCM_PROMPT_FORMAT:-'[%s%s]'}
|
||||||
|
|
@ -141,7 +144,8 @@ scm_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_char {
|
function scm_prompt_char
|
||||||
|
{
|
||||||
if [[ -z $SCM ]]; then scm; fi
|
if [[ -z $SCM ]]; then scm; fi
|
||||||
if [[ $SCM == "$SCM_GIT" ]]; then
|
if [[ $SCM == "$SCM_GIT" ]]; then
|
||||||
SCM_CHAR=$SCM_GIT_CHAR
|
SCM_CHAR=$SCM_GIT_CHAR
|
||||||
|
|
@ -156,7 +160,8 @@ function scm_prompt_char {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_vars {
|
function scm_prompt_vars
|
||||||
|
{
|
||||||
scm
|
scm
|
||||||
scm_prompt_char
|
scm_prompt_char
|
||||||
SCM_DIRTY=0
|
SCM_DIRTY=0
|
||||||
|
|
@ -167,19 +172,22 @@ function scm_prompt_vars {
|
||||||
[[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return
|
[[ $SCM == "$SCM_SVN" ]] && svn_prompt_vars && return
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_info {
|
function scm_prompt_info
|
||||||
|
{
|
||||||
scm
|
scm
|
||||||
scm_prompt_char
|
scm_prompt_char
|
||||||
scm_prompt_info_common
|
scm_prompt_info_common
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_char_info {
|
function scm_prompt_char_info
|
||||||
|
{
|
||||||
scm_prompt_char
|
scm_prompt_char
|
||||||
echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
echo -ne "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
||||||
scm_prompt_info_common
|
scm_prompt_info_common
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_prompt_info_common {
|
function scm_prompt_info_common
|
||||||
|
{
|
||||||
SCM_DIRTY=0
|
SCM_DIRTY=0
|
||||||
SCM_STATE=''
|
SCM_STATE=''
|
||||||
|
|
||||||
|
|
@ -195,12 +203,19 @@ function scm_prompt_info_common {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# TODO: consider adding minimal status information for hg and svn
|
# 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_P4}" ]] && p4_prompt_info && return
|
||||||
{ [[ ${SCM} == "${SCM_SVN}" ]] && svn_prompt_info && return; } || true
|
} || 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 _command_exists terraform; then
|
||||||
if [ -d .terraform ]; then
|
if [ -d .terraform ]; then
|
||||||
echo -e "$(terraform workspace show 2> /dev/null)"
|
echo -e "$(terraform workspace show 2> /dev/null)"
|
||||||
|
|
@ -208,13 +223,15 @@ function terraform_workspace_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function active_gcloud_account_prompt {
|
function active_gcloud_account_prompt
|
||||||
|
{
|
||||||
if _command_exists gcloud; then
|
if _command_exists gcloud; then
|
||||||
echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)"
|
echo -e "$(gcloud config list account --format "value(core.account)" 2> /dev/null)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function git_prompt_minimal_info {
|
function git_prompt_minimal_info
|
||||||
|
{
|
||||||
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
|
SCM_STATE=${SCM_THEME_PROMPT_CLEAN}
|
||||||
|
|
||||||
_git-hide-status && return
|
_git-hide-status && return
|
||||||
|
|
@ -232,7 +249,8 @@ function git_prompt_minimal_info {
|
||||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
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
|
if ${SCM_GIT_USE_GITSTATUS} && _command_exists gitstatus_query && gitstatus_query && [[ "${VCS_STATUS_RESULT}" == "ok-sync" ]]; then
|
||||||
# we can use faster gitstatus
|
# we can use faster gitstatus
|
||||||
# use this variable in githelpers and below to choose gitstatus output
|
# 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 "")
|
SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "")
|
||||||
}
|
}
|
||||||
|
|
||||||
function p4_prompt_vars {
|
function p4_prompt_vars
|
||||||
|
{
|
||||||
IFS=$'\t' read -r \
|
IFS=$'\t' read -r \
|
||||||
opened_count non_default_changes default_count \
|
opened_count non_default_changes default_count \
|
||||||
add_file_count edit_file_count delete_file_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}
|
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
|
if [[ -n $(svn status | head -c1 2> /dev/null) ]]; then
|
||||||
SCM_DIRTY=1
|
SCM_DIRTY=1
|
||||||
SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
|
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
|
# - lets say we cd into ~/Projects/Foo/Bar
|
||||||
# - .hg is located in ~/Projects/Foo/.hg
|
# - .hg is located in ~/Projects/Foo/.hg
|
||||||
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
|
# - get_hg_root starts at ~/Projects/Foo/Bar and sees that there is no .hg directory, so then it goes into ~/Projects/Foo
|
||||||
function get_hg_root {
|
function get_hg_root
|
||||||
|
{
|
||||||
local CURRENT_DIR="${PWD}"
|
local CURRENT_DIR="${PWD}"
|
||||||
|
|
||||||
while [[ "${CURRENT_DIR:-/}" != "/" ]]; do
|
while [[ "${CURRENT_DIR:-/}" != "/" ]]; do
|
||||||
|
|
@ -364,7 +385,8 @@ function get_hg_root {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function hg_prompt_vars {
|
function hg_prompt_vars
|
||||||
|
{
|
||||||
if [[ -n $(hg status 2> /dev/null) ]]; then
|
if [[ -n $(hg status 2> /dev/null) ]]; then
|
||||||
SCM_DIRTY=1
|
SCM_DIRTY=1
|
||||||
SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
|
SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY}
|
||||||
|
|
@ -394,7 +416,8 @@ function hg_prompt_vars {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function nvm_version_prompt {
|
function nvm_version_prompt
|
||||||
|
{
|
||||||
local node
|
local node
|
||||||
if _is_function nvm; then
|
if _is_function nvm; then
|
||||||
node=$(nvm current 2> /dev/null)
|
node=$(nvm current 2> /dev/null)
|
||||||
|
|
@ -403,11 +426,13 @@ function nvm_version_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function node_version_prompt {
|
function node_version_prompt
|
||||||
|
{
|
||||||
echo -e "$(nvm_version_prompt)"
|
echo -e "$(nvm_version_prompt)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function rvm_version_prompt {
|
function rvm_version_prompt
|
||||||
|
{
|
||||||
if which rvm &> /dev/null; then
|
if which rvm &> /dev/null; then
|
||||||
rvm=$(rvm-prompt) || return
|
rvm=$(rvm-prompt) || return
|
||||||
if [ -n "$rvm" ]; then
|
if [ -n "$rvm" ]; then
|
||||||
|
|
@ -416,7 +441,8 @@ function rvm_version_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function rbenv_version_prompt {
|
function rbenv_version_prompt
|
||||||
|
{
|
||||||
if which rbenv &> /dev/null; then
|
if which rbenv &> /dev/null; then
|
||||||
rbenv=$(rbenv version-name) || return
|
rbenv=$(rbenv version-name) || return
|
||||||
rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
|
rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}"
|
||||||
|
|
@ -426,13 +452,15 @@ function rbenv_version_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function rbfu_version_prompt {
|
function rbfu_version_prompt
|
||||||
|
{
|
||||||
if [[ $RBFU_RUBY_VERSION ]]; then
|
if [[ $RBFU_RUBY_VERSION ]]; then
|
||||||
echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}"
|
echo -e "${RBFU_THEME_PROMPT_PREFIX}${RBFU_RUBY_VERSION}${RBFU_THEME_PROMPT_SUFFIX}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function chruby_version_prompt {
|
function chruby_version_prompt
|
||||||
|
{
|
||||||
if _is_function chruby; then
|
if _is_function chruby; then
|
||||||
if _is_function chruby_auto; then
|
if _is_function chruby_auto; then
|
||||||
chruby_auto
|
chruby_auto
|
||||||
|
|
@ -447,43 +475,51 @@ function chruby_version_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function ruby_version_prompt {
|
function ruby_version_prompt
|
||||||
|
{
|
||||||
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
|
if [[ "${THEME_SHOW_RUBY_PROMPT}" = "true" ]]; then
|
||||||
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
|
echo -e "$(rbfu_version_prompt)$(rbenv_version_prompt)$(rvm_version_prompt)$(chruby_version_prompt)"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function k8s_context_prompt {
|
function k8s_context_prompt
|
||||||
|
{
|
||||||
echo -e "$(kubectl config current-context 2> /dev/null)"
|
echo -e "$(kubectl config current-context 2> /dev/null)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function k8s_namespace_prompt {
|
function k8s_namespace_prompt
|
||||||
|
{
|
||||||
echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)"
|
echo -e "$(kubectl config view --minify --output 'jsonpath={..namespace}' 2> /dev/null)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function virtualenv_prompt {
|
function virtualenv_prompt
|
||||||
|
{
|
||||||
if [[ -n "$VIRTUAL_ENV" ]]; then
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
||||||
virtualenv=$(basename "$VIRTUAL_ENV")
|
virtualenv=$(basename "$VIRTUAL_ENV")
|
||||||
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
|
echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function condaenv_prompt {
|
function condaenv_prompt
|
||||||
|
{
|
||||||
if [[ $CONDA_DEFAULT_ENV ]]; then
|
if [[ $CONDA_DEFAULT_ENV ]]; then
|
||||||
echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}"
|
echo -e "${CONDAENV_THEME_PROMPT_PREFIX}${CONDA_DEFAULT_ENV}${CONDAENV_THEME_PROMPT_SUFFIX}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function py_interp_prompt {
|
function py_interp_prompt
|
||||||
|
{
|
||||||
py_version=$(python --version 2>&1 | awk 'NR==1{print "py-"$2;}') || return
|
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}"
|
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)"
|
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
|
# support two or more initials, set by 'git pair' plugin
|
||||||
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
|
SCM_CURRENT_USER=$(git config user.initials | sed 's% %+%')
|
||||||
# if `user.initials` weren't set, attempt to extract initials from `user.name`
|
# 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"
|
[[ -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=${THEME_CLOCK_CHAR:-"⌚"}
|
||||||
CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"}
|
CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$normal"}
|
||||||
SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
|
SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"true"}
|
||||||
|
|
@ -501,7 +538,8 @@ function clock_char {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function clock_prompt {
|
function clock_prompt
|
||||||
|
{
|
||||||
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
|
CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"}
|
||||||
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
|
CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%H:%M:%S"}
|
||||||
[ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
|
[ -z "$THEME_SHOW_CLOCK" ] && THEME_SHOW_CLOCK=${THEME_CLOCK_CHECK:-"true"}
|
||||||
|
|
@ -513,44 +551,52 @@ function clock_prompt {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_host_prompt {
|
function user_host_prompt
|
||||||
|
{
|
||||||
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
|
if [[ "${THEME_SHOW_USER_HOST}" = "true" ]]; then
|
||||||
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
|
echo -e "${USER_HOST_THEME_PROMPT_PREFIX}\u@\h${USER_HOST_THEME_PROMPT_SUFFIX}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# backwards-compatibility
|
# backwards-compatibility
|
||||||
function git_prompt_info {
|
function git_prompt_info
|
||||||
|
{
|
||||||
_git-hide-status && return
|
_git-hide-status && return
|
||||||
git_prompt_vars
|
git_prompt_vars
|
||||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function p4_prompt_info() {
|
function p4_prompt_info()
|
||||||
|
{
|
||||||
p4_prompt_vars
|
p4_prompt_vars
|
||||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
|
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE}${SCM_STATE}${SCM_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function svn_prompt_info {
|
function svn_prompt_info
|
||||||
|
{
|
||||||
svn_prompt_vars
|
svn_prompt_vars
|
||||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
echo -e "${SCM_PREFIX}${SCM_BRANCH}${SCM_STATE}${SCM_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function hg_prompt_info() {
|
function hg_prompt_info()
|
||||||
|
{
|
||||||
hg_prompt_vars
|
hg_prompt_vars
|
||||||
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
|
echo -e "${SCM_PREFIX}${SCM_BRANCH}:${SCM_CHANGE#*:}${SCM_STATE}${SCM_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function scm_char {
|
function scm_char
|
||||||
|
{
|
||||||
scm_prompt_char
|
scm_prompt_char
|
||||||
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
echo -e "${SCM_THEME_CHAR_PREFIX}${SCM_CHAR}${SCM_THEME_CHAR_SUFFIX}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_char {
|
function prompt_char
|
||||||
|
{
|
||||||
scm_char
|
scm_char
|
||||||
}
|
}
|
||||||
|
|
||||||
function battery_char {
|
function battery_char
|
||||||
|
{
|
||||||
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
|
if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then
|
||||||
echo -e "${bold_red:-}$(battery_percentage)%"
|
echo -e "${bold_red:-}$(battery_percentage)%"
|
||||||
fi
|
fi
|
||||||
|
|
@ -558,7 +604,8 @@ function battery_char {
|
||||||
|
|
||||||
if ! _command_exists battery_charge; then
|
if ! _command_exists battery_charge; then
|
||||||
# if user has installed battery plugin, skip this...
|
# if user has installed battery plugin, skip this...
|
||||||
function battery_charge() {
|
function battery_charge()
|
||||||
|
{
|
||||||
# no op
|
# no op
|
||||||
echo -n
|
echo -n
|
||||||
}
|
}
|
||||||
|
|
@ -567,13 +614,15 @@ fi
|
||||||
# The battery_char function depends on the presence of the battery_percentage function.
|
# 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 battery_percentage is not defined, then define battery_char as a no-op.
|
||||||
if ! _command_exists battery_percentage; then
|
if ! _command_exists battery_percentage; then
|
||||||
function battery_char() {
|
function battery_char()
|
||||||
|
{
|
||||||
# no op
|
# no op
|
||||||
echo -n
|
echo -n
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function aws_profile {
|
function aws_profile
|
||||||
|
{
|
||||||
if [[ $AWS_DEFAULT_PROFILE ]]; then
|
if [[ $AWS_DEFAULT_PROFILE ]]; then
|
||||||
echo -e "${AWS_DEFAULT_PROFILE}"
|
echo -e "${AWS_DEFAULT_PROFILE}"
|
||||||
else
|
else
|
||||||
|
|
@ -581,7 +630,8 @@ function aws_profile {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __check_precmd_conflict() {
|
function __check_precmd_conflict()
|
||||||
|
{
|
||||||
local f
|
local f
|
||||||
for f in "${precmd_functions[@]}"; do
|
for f in "${precmd_functions[@]}"; do
|
||||||
if [[ "${f}" == "${1}" ]]; then
|
if [[ "${f}" == "${1}" ]]; then
|
||||||
|
|
@ -591,7 +641,8 @@ function __check_precmd_conflict() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command
|
||||||
|
{
|
||||||
local prompt_re
|
local prompt_re
|
||||||
|
|
||||||
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
||||||
|
|
@ -619,7 +670,8 @@ function safe_append_prompt_command {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _save-and-reload-history() {
|
function _save-and-reload-history()
|
||||||
|
{
|
||||||
local autosave=${1:-0}
|
local autosave=${1:-0}
|
||||||
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
[[ $autosave -eq 1 ]] && history -a && history -c && history -r
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
# shellcheck disable=SC2154 #TODO: fix these all.
|
# shellcheck disable=SC2154 #TODO: fix these all.
|
||||||
|
|
||||||
# Detect whether a reboot is required
|
# Detect whether a reboot is required
|
||||||
function show_reboot_required() {
|
function show_reboot_required()
|
||||||
|
{
|
||||||
if [ -n "$_bf_prompt_reboot_info" ]; then
|
if [ -n "$_bf_prompt_reboot_info" ]; then
|
||||||
if [ -f /var/run/reboot-required ]; then
|
if [ -f /var/run/reboot-required ]; then
|
||||||
printf "Reboot required!"
|
printf "Reboot required!"
|
||||||
|
|
@ -12,7 +13,8 @@ function show_reboot_required() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set different host color for local and remote sessions
|
# Set different host color for local and remote sessions
|
||||||
function set_host_color() {
|
function set_host_color()
|
||||||
|
{
|
||||||
# Detect if connection is through SSH
|
# Detect if connection is through SSH
|
||||||
if [[ -n $SSH_CLIENT ]]; then
|
if [[ -n $SSH_CLIENT ]]; then
|
||||||
printf '%s' "${lime_yellow}"
|
printf '%s' "${lime_yellow}"
|
||||||
|
|
@ -22,7 +24,8 @@ function set_host_color() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set different username color for users and root
|
# Set different username color for users and root
|
||||||
function set_user_color() {
|
function set_user_color()
|
||||||
|
{
|
||||||
case $(id -u) in
|
case $(id -u) in
|
||||||
0)
|
0)
|
||||||
printf '%s' "${red}"
|
printf '%s' "${red}"
|
||||||
|
|
@ -36,7 +39,8 @@ function set_user_color() {
|
||||||
# Define custom colors we need
|
# Define custom colors we need
|
||||||
# non-printable bytes in PS1 need to be contained within \[ \].
|
# non-printable bytes in PS1 need to be contained within \[ \].
|
||||||
# Otherwise, bash will count them in the length of the prompt
|
# Otherwise, bash will count them in the length of the prompt
|
||||||
function set_custom_colors() {
|
function set_custom_colors()
|
||||||
|
{
|
||||||
dark_grey="\[$(tput setaf 8)\]"
|
dark_grey="\[$(tput setaf 8)\]"
|
||||||
light_grey="\[$(tput setaf 248)\]"
|
light_grey="\[$(tput setaf 248)\]"
|
||||||
|
|
||||||
|
|
@ -47,11 +51,13 @@ function set_custom_colors() {
|
||||||
powder_blue="\[$(tput setaf 153)\]"
|
powder_blue="\[$(tput setaf 153)\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
__ps_time() {
|
__ps_time()
|
||||||
|
{
|
||||||
printf '%s' "$(clock_prompt)${normal}\n"
|
printf '%s' "$(clock_prompt)${normal}\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_command() {
|
function prompt_command()
|
||||||
|
{
|
||||||
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
|
ps_reboot="${bright_yellow}$(show_reboot_required)${normal}\n"
|
||||||
|
|
||||||
ps_username="$(set_user_color)\u${normal}"
|
ps_username="$(set_user_color)\u${normal}"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ else
|
||||||
user_host="${bold_green}\u@\h${normal}${reset_color}"
|
user_host="${bold_green}\u@\h${normal}${reset_color}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function prompt_command() {
|
function prompt_command()
|
||||||
|
{
|
||||||
local current_dir=" ${bold_blue}\w${normal}${reset_color}"
|
local current_dir=" ${bold_blue}\w${normal}${reset_color}"
|
||||||
PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}"
|
PS1="╭─${user_host}${current_dir}$(virtualenv_prompt)$(scm_prompt_info)\n╰─${bold}\\$ ${normal}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
|
||||||
|
|
||||||
CONDAENV_THEME_PROMPT_SUFFIX="|"
|
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="\n${yellow}$(python_version_prompt) " # Name of virtual env followed by python version
|
||||||
PS1+="${purple}\h "
|
PS1+="${purple}\h "
|
||||||
PS1+="${reset_color}in "
|
PS1+="${reset_color}in "
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ GIT_THEME_PROMPT_SUFFIX="${green}|"
|
||||||
RVM_THEME_PROMPT_PREFIX="|"
|
RVM_THEME_PROMPT_PREFIX="|"
|
||||||
RVM_THEME_PROMPT_SUFFIX="|"
|
RVM_THEME_PROMPT_SUFFIX="|"
|
||||||
|
|
||||||
__bobby_clock() {
|
__bobby_clock()
|
||||||
|
{
|
||||||
printf '%s' "$(clock_prompt) "
|
printf '%s' "$(clock_prompt) "
|
||||||
|
|
||||||
if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then
|
if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then
|
||||||
|
|
@ -23,7 +24,8 @@ __bobby_clock() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_command() {
|
function prompt_command()
|
||||||
|
{
|
||||||
PS1="\n$(battery_char) $(__bobby_clock)"
|
PS1="\n$(battery_char) $(__bobby_clock)"
|
||||||
PS1+="${yellow}$(ruby_version_prompt) "
|
PS1+="${yellow}$(ruby_version_prompt) "
|
||||||
PS1+="${purple}\h "
|
PS1+="${purple}\h "
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
## Parsers ##
|
## Parsers ##
|
||||||
#############
|
#############
|
||||||
|
|
||||||
____brainy_top_left_parse() {
|
____brainy_top_left_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -24,7 +25,8 @@ ____brainy_top_left_parse() {
|
||||||
_TOP_LEFT+=" "
|
_TOP_LEFT+=" "
|
||||||
}
|
}
|
||||||
|
|
||||||
____brainy_top_right_parse() {
|
____brainy_top_right_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -41,7 +43,8 @@ ____brainy_top_right_parse() {
|
||||||
((__SEG_AT_RIGHT += 1))
|
((__SEG_AT_RIGHT += 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
____brainy_bottom_parse() {
|
____brainy_bottom_parse()
|
||||||
|
{
|
||||||
ifs_old="${IFS}"
|
ifs_old="${IFS}"
|
||||||
IFS="|"
|
IFS="|"
|
||||||
read -r -a args <<< "$@"
|
read -r -a args <<< "$@"
|
||||||
|
|
@ -50,7 +53,8 @@ ____brainy_bottom_parse() {
|
||||||
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
[ ${#args[1]} -gt 0 ] && _BOTTOM+=" "
|
||||||
}
|
}
|
||||||
|
|
||||||
____brainy_top() {
|
____brainy_top()
|
||||||
|
{
|
||||||
_TOP_LEFT=""
|
_TOP_LEFT=""
|
||||||
_TOP_RIGHT=""
|
_TOP_RIGHT=""
|
||||||
__TOP_RIGHT_LEN=0
|
__TOP_RIGHT_LEN=0
|
||||||
|
|
@ -76,7 +80,8 @@ ____brainy_top() {
|
||||||
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
printf "%s%s" "${_TOP_LEFT}" "${_TOP_RIGHT}"
|
||||||
}
|
}
|
||||||
|
|
||||||
____brainy_bottom() {
|
____brainy_bottom()
|
||||||
|
{
|
||||||
_BOTTOM=""
|
_BOTTOM=""
|
||||||
for seg in $___BRAINY_BOTTOM; do
|
for seg in $___BRAINY_BOTTOM; do
|
||||||
info="$(___brainy_prompt_"${seg}")"
|
info="$(___brainy_prompt_"${seg}")"
|
||||||
|
|
@ -89,7 +94,8 @@ ____brainy_bottom() {
|
||||||
## Segments ##
|
## Segments ##
|
||||||
##############
|
##############
|
||||||
|
|
||||||
___brainy_prompt_user_info() {
|
___brainy_prompt_user_info()
|
||||||
|
{
|
||||||
color=$bold_blue
|
color=$bold_blue
|
||||||
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
if [ "${THEME_SHOW_SUDO}" == "true" ]; then
|
||||||
if sudo -vn 1> /dev/null 2>&1; then
|
if sudo -vn 1> /dev/null 2>&1; then
|
||||||
|
|
@ -105,14 +111,16 @@ ___brainy_prompt_user_info() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_dir() {
|
___brainy_prompt_dir()
|
||||||
|
{
|
||||||
color=$bold_yellow
|
color=$bold_yellow
|
||||||
box="[|]"
|
box="[|]"
|
||||||
info="\w"
|
info="\w"
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_scm() {
|
___brainy_prompt_scm()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
[ "${THEME_SHOW_SCM}" != "true" ] && return
|
||||||
color=$bold_green
|
color=$bold_green
|
||||||
box="$(scm_char) "
|
box="$(scm_char) "
|
||||||
|
|
@ -120,7 +128,8 @@ ___brainy_prompt_scm() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_python() {
|
___brainy_prompt_python()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
[ "${THEME_SHOW_PYTHON}" != "true" ] && return
|
||||||
color=$bold_yellow
|
color=$bold_yellow
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -128,7 +137,8 @@ ___brainy_prompt_python() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_blue}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_ruby() {
|
___brainy_prompt_ruby()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
[ "${THEME_SHOW_RUBY}" != "true" ] && return
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -136,16 +146,18 @@ ___brainy_prompt_ruby() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_red}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_todo() {
|
___brainy_prompt_todo()
|
||||||
[ "${THEME_SHOW_TODO}" != "true" ] \
|
{
|
||||||
|| [ -z "$(which todo.sh)" ] && return
|
[ "${THEME_SHOW_TODO}" != "true" ] ||
|
||||||
|
[ -z "$(which todo.sh)" ] && return
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
box="[|]"
|
box="[|]"
|
||||||
info="t:$(todo.sh ls | grep -E "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }')"
|
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}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_green}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_clock() {
|
___brainy_prompt_clock()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
[ "${THEME_SHOW_CLOCK}" != "true" ] && return
|
||||||
color=$THEME_CLOCK_COLOR
|
color=$THEME_CLOCK_COLOR
|
||||||
box="[|]"
|
box="[|]"
|
||||||
|
|
@ -153,10 +165,11 @@ ___brainy_prompt_clock() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_purple}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_purple}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_battery() {
|
___brainy_prompt_battery()
|
||||||
! _command_exists battery_percentage \
|
{
|
||||||
|| [ "${THEME_SHOW_BATTERY}" != "true" ] \
|
! _command_exists battery_percentage ||
|
||||||
|| [ "$(battery_percentage)" = "no" ] && return
|
[ "${THEME_SHOW_BATTERY}" != "true" ] ||
|
||||||
|
[ "$(battery_percentage)" = "no" ] && return
|
||||||
|
|
||||||
info=$(battery_percentage)
|
info=$(battery_percentage)
|
||||||
color=$bold_green
|
color=$bold_green
|
||||||
|
|
@ -173,13 +186,15 @@ ___brainy_prompt_battery() {
|
||||||
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_exitcode() {
|
___brainy_prompt_exitcode()
|
||||||
|
{
|
||||||
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
[ "${THEME_SHOW_EXITCODE}" != "true" ] && return
|
||||||
color=$bold_purple
|
color=$bold_purple
|
||||||
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
[ "$exitcode" -ne 0 ] && printf "%s|%s" "${color}" "${exitcode}"
|
||||||
}
|
}
|
||||||
|
|
||||||
___brainy_prompt_char() {
|
___brainy_prompt_char()
|
||||||
|
{
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
prompt_char="${__BRAINY_PROMPT_CHAR_PS1}"
|
prompt_char="${__BRAINY_PROMPT_CHAR_PS1}"
|
||||||
printf "%s|%s" "${color}" "${prompt_char}"
|
printf "%s|%s" "${color}" "${prompt_char}"
|
||||||
|
|
@ -189,19 +204,22 @@ ___brainy_prompt_char() {
|
||||||
## cli ##
|
## cli ##
|
||||||
#########
|
#########
|
||||||
|
|
||||||
__brainy_show() {
|
__brainy_show()
|
||||||
|
{
|
||||||
typeset _seg=${1:-}
|
typeset _seg=${1:-}
|
||||||
shift
|
shift
|
||||||
export "THEME_SHOW_${_seg}"=true
|
export "THEME_SHOW_${_seg}"=true
|
||||||
}
|
}
|
||||||
|
|
||||||
__brainy_hide() {
|
__brainy_hide()
|
||||||
|
{
|
||||||
typeset _seg=${1:-}
|
typeset _seg=${1:-}
|
||||||
shift
|
shift
|
||||||
export "THEME_SHOW_${_seg}"=false
|
export "THEME_SHOW_${_seg}"=false
|
||||||
}
|
}
|
||||||
|
|
||||||
_brainy_completion() {
|
_brainy_completion()
|
||||||
|
{
|
||||||
local cur _action actions segments
|
local cur _action actions segments
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
|
@ -221,7 +239,8 @@ _brainy_completion() {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
brainy() {
|
brainy()
|
||||||
|
{
|
||||||
typeset action=${1:-}
|
typeset action=${1:-}
|
||||||
shift
|
shift
|
||||||
typeset segs=${*:-}
|
typeset segs=${*:-}
|
||||||
|
|
@ -284,16 +303,19 @@ ___BRAINY_BOTTOM=${___BRAINY_BOTTOM:-"exitcode char"}
|
||||||
## Prompt ##
|
## Prompt ##
|
||||||
############
|
############
|
||||||
|
|
||||||
__brainy_ps1() {
|
__brainy_ps1()
|
||||||
|
{
|
||||||
printf "%s%s%s" "$(____brainy_top)" "$(____brainy_bottom)" "${normal}"
|
printf "%s%s%s" "$(____brainy_top)" "$(____brainy_bottom)" "${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__brainy_ps2() {
|
__brainy_ps2()
|
||||||
|
{
|
||||||
color=$bold_white
|
color=$bold_white
|
||||||
printf "%s%s%s" "${color}" "${__BRAINY_PROMPT_CHAR_PS2} " "${normal}"
|
printf "%s%s%s" "${color}" "${__BRAINY_PROMPT_CHAR_PS2} " "${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_brainy_prompt() {
|
_brainy_prompt()
|
||||||
|
{
|
||||||
exitcode="$?"
|
exitcode="$?"
|
||||||
|
|
||||||
PS1="$(__brainy_ps1)"
|
PS1="$(__brainy_ps1)"
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,15 @@ SCM_GIT_CHAR="${bold_green}±${normal}"
|
||||||
SCM_SVN_CHAR="${bold_cyan}⑆${normal}"
|
SCM_SVN_CHAR="${bold_cyan}⑆${normal}"
|
||||||
SCM_HG_CHAR="${bold_red}☿${normal}"
|
SCM_HG_CHAR="${bold_red}☿${normal}"
|
||||||
|
|
||||||
is_vim_shell() {
|
is_vim_shell()
|
||||||
|
{
|
||||||
if [ -n "$VIMRUNTIME" ]; then
|
if [ -n "$VIMRUNTIME" ]; then
|
||||||
echo "[${cyan}vim shell${normal}]"
|
echo "[${cyan}vim shell${normal}]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt() {
|
prompt()
|
||||||
|
{
|
||||||
SCM_PROMPT_FORMAT=' %s (%s)'
|
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} "
|
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} "
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
# shellcheck disable=SC2034 # Expected behavior for themes.
|
# shellcheck disable=SC2034 # Expected behavior for themes.
|
||||||
# shellcheck disable=SC2154 #TODO: fix these all.
|
# 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}"
|
PS1="${green}\u@\h $(clock_prompt) ${reset_color}${white}\w${reset_color}$(scm_prompt_info)${blue} →${bold_blue} ${reset_color} ${normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
|
||||||
if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then
|
if [ -z "$BASH_IT_COMMAND_DURATION" ] || [ "$BASH_IT_COMMAND_DURATION" != true ]; then
|
||||||
_command_duration() {
|
_command_duration()
|
||||||
|
{
|
||||||
echo -n
|
echo -n
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
@ -16,17 +17,20 @@ COMMAND_DURATION_MIN_SECONDS=${COMMAND_DURATION_MIN_SECONDS:-'1'}
|
||||||
|
|
||||||
trap _command_duration_delete_temp_file EXIT HUP INT TERM
|
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
|
if [[ -f "$COMMAND_DURATION_FILE" ]]; then
|
||||||
rm -f "$COMMAND_DURATION_FILE"
|
rm -f "$COMMAND_DURATION_FILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_command_duration_pre_exec() {
|
_command_duration_pre_exec()
|
||||||
|
{
|
||||||
date +%s.%1N > "$COMMAND_DURATION_FILE"
|
date +%s.%1N > "$COMMAND_DURATION_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
_command_duration() {
|
_command_duration()
|
||||||
|
{
|
||||||
local command_duration command_start current_time
|
local command_duration command_start current_time
|
||||||
local minutes seconds deciseconds
|
local minutes seconds deciseconds
|
||||||
local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds
|
local command_start_sseconds current_time_seconds command_start_deciseconds current_time_deciseconds
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ SCM_THEME_PROMPT_SUFFIX="${bold_green} ] "
|
||||||
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
|
||||||
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
|
||||||
|
|
||||||
prompt_command() {
|
prompt_command()
|
||||||
|
{
|
||||||
if [ "$(whoami)" = root ]; then
|
if [ "$(whoami)" = root ]; then
|
||||||
cursor_color="${bold_red}"
|
cursor_color="${bold_red}"
|
||||||
user_color="${green}"
|
user_color="${green}"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
function _git-symbolic-ref {
|
function _git-symbolic-ref
|
||||||
|
{
|
||||||
git symbolic-ref -q HEAD 2> /dev/null
|
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
|
# but this can be different when two branches are pointing to the
|
||||||
# same commit. _git-branch is used to explicitly choose the checked-out
|
# same commit. _git-branch is used to explicitly choose the checked-out
|
||||||
# branch.
|
# branch.
|
||||||
function _git-branch {
|
function _git-branch
|
||||||
|
{
|
||||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||||
test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1
|
test -n "${VCS_STATUS_LOCAL_BRANCH}" && echo "${VCS_STATUS_LOCAL_BRANCH}" || return 1
|
||||||
else
|
else
|
||||||
|
|
@ -16,7 +18,8 @@ function _git-branch {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-tag {
|
function _git-tag
|
||||||
|
{
|
||||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||||
test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}"
|
test -n "${VCS_STATUS_TAG}" && echo "${VCS_STATUS_TAG}"
|
||||||
else
|
else
|
||||||
|
|
@ -24,11 +27,13 @@ function _git-tag {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-commit-description {
|
function _git-commit-description
|
||||||
|
{
|
||||||
git describe --contains --all 2> /dev/null
|
git describe --contains --all 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-short-sha {
|
function _git-short-sha
|
||||||
|
{
|
||||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||||
echo ${VCS_STATUS_COMMIT:0:7}
|
echo ${VCS_STATUS_COMMIT:0:7}
|
||||||
else
|
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.
|
# 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
|
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||||
_git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus
|
_git-branch || _git-tag || _git-short-sha # there is no tag based describe output in gitstatus
|
||||||
else
|
else
|
||||||
|
|
@ -45,17 +51,20 @@ function _git-friendly-ref {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-num-remotes {
|
function _git-num-remotes
|
||||||
|
{
|
||||||
git remote | wc -l
|
git remote | wc -l
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-upstream {
|
function _git-upstream
|
||||||
|
{
|
||||||
local ref
|
local ref
|
||||||
ref="$(_git-symbolic-ref)" || return 1
|
ref="$(_git-symbolic-ref)" || return 1
|
||||||
git for-each-ref --format="%(upstream:short)" "${ref}"
|
git for-each-ref --format="%(upstream:short)" "${ref}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-upstream-remote {
|
function _git-upstream-remote
|
||||||
|
{
|
||||||
local upstream
|
local upstream
|
||||||
upstream="$(_git-upstream)" || return 1
|
upstream="$(_git-upstream)" || return 1
|
||||||
|
|
||||||
|
|
@ -64,7 +73,8 @@ function _git-upstream-remote {
|
||||||
echo "${upstream%"/${branch}"}"
|
echo "${upstream%"/${branch}"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-upstream-branch {
|
function _git-upstream-branch
|
||||||
|
{
|
||||||
local ref
|
local ref
|
||||||
ref="$(_git-symbolic-ref)" || return 1
|
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/.*\/.*\/.*\///"
|
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
|
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]" ]]
|
[[ "$(git status -s -b | sed -e 's/.* //')" == "[gone]" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-hide-status {
|
function _git-hide-status
|
||||||
|
{
|
||||||
[[ "$(git config --get bash-it.hide-status)" == "1" ]]
|
[[ "$(git config --get bash-it.hide-status)" == "1" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-status {
|
function _git-status
|
||||||
|
{
|
||||||
local git_status_flags=
|
local git_status_flags=
|
||||||
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true
|
[[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' || true
|
||||||
git status --porcelain ${git_status_flags} 2> /dev/null
|
git status --porcelain ${git_status_flags} 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function _git-status-counts {
|
function _git-status-counts
|
||||||
|
{
|
||||||
_git-status | awk '
|
_git-status | awk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
untracked=0;
|
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
|
# prompt handling only, reimplement because patching the routine below gets ugly
|
||||||
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
if [[ "${SCM_GIT_GITSTATUS_RAN}" == "true" ]]; then
|
||||||
|
|
@ -134,7 +150,7 @@ function _git-remote-info {
|
||||||
elif [[ ${same_branch_name} != "true" ]]; then
|
elif [[ ${same_branch_name} != "true" ]]; then
|
||||||
remote_info="${VCS_STATUS_REMOTE_BRANCH}"
|
remote_info="${VCS_STATUS_REMOTE_BRANCH}"
|
||||||
fi
|
fi
|
||||||
if [[ -n "${remote_info}" ]];then
|
if [[ -n "${remote_info}" ]]; then
|
||||||
# no support for gone remote branches in gitstatusd
|
# no support for gone remote branches in gitstatusd
|
||||||
local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
|
local branch_prefix="${SCM_THEME_BRANCH_TRACK_PREFIX}"
|
||||||
echo "${branch_prefix}${remote_info}"
|
echo "${branch_prefix}${remote_info}"
|
||||||
|
|
@ -155,7 +171,7 @@ function _git-remote-info {
|
||||||
elif [[ ${same_branch_name} != "true" ]]; then
|
elif [[ ${same_branch_name} != "true" ]]; then
|
||||||
remote_info="\$(_git-upstream-branch)"
|
remote_info="\$(_git-upstream-branch)"
|
||||||
fi
|
fi
|
||||||
if [[ -n "${remote_info}" ]];then
|
if [[ -n "${remote_info}" ]]; then
|
||||||
local branch_prefix
|
local branch_prefix
|
||||||
if _git-upstream-branch-gone; then
|
if _git-upstream-branch-gone; then
|
||||||
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
|
branch_prefix="${SCM_THEME_BRANCH_GONE_PREFIX}"
|
||||||
|
|
@ -168,7 +184,8 @@ function _git-remote-info {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Unused by bash-it, present for API compatibility
|
# Unused by bash-it, present for API compatibility
|
||||||
function git_status_summary {
|
function git_status_summary
|
||||||
|
{
|
||||||
awk '
|
awk '
|
||||||
BEGIN {
|
BEGIN {
|
||||||
untracked=0;
|
untracked=0;
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,15 @@ esac
|
||||||
|
|
||||||
PS3=">> "
|
PS3=">> "
|
||||||
|
|
||||||
is_vim_shell() {
|
is_vim_shell()
|
||||||
|
{
|
||||||
if [ -n "$VIMRUNTIME" ]; then
|
if [ -n "$VIMRUNTIME" ]; then
|
||||||
echo "[${cyan}vim shell${normal}]"
|
echo "[${cyan}vim shell${normal}]"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_venv() {
|
detect_venv()
|
||||||
|
{
|
||||||
python_venv=""
|
python_venv=""
|
||||||
# Detect python venv
|
# Detect python venv
|
||||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||||
|
|
@ -38,7 +40,8 @@ detect_venv() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt() {
|
prompt()
|
||||||
|
{
|
||||||
SCM_PROMPT_FORMAT='[%s][%s]'
|
SCM_PROMPT_FORMAT='[%s][%s]'
|
||||||
retval=$?
|
retval=$?
|
||||||
if [[ retval -ne 0 ]]; then
|
if [[ retval -ne 0 ]]; then
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
function _p4-opened {
|
function _p4-opened
|
||||||
|
{
|
||||||
timeout 2.0s p4 opened -s 2> /dev/null
|
timeout 2.0s p4 opened -s 2> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
function _p4-opened-counts {
|
function _p4-opened-counts
|
||||||
|
{
|
||||||
# Return the following counts seperated by tabs:
|
# Return the following counts seperated by tabs:
|
||||||
# - count of opened files
|
# - count of opened files
|
||||||
# - count of pending changesets (other than defaults)
|
# - count of pending changesets (other than defaults)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
# Define this here so it can be used by all of the Powerline themes
|
# Define this here so it can be used by all of the Powerline themes
|
||||||
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
|
THEME_CHECK_SUDO=${THEME_CHECK_SUDO:=true}
|
||||||
|
|
||||||
function set_color() {
|
function set_color()
|
||||||
|
{
|
||||||
set +u
|
set +u
|
||||||
if [[ "${1}" != "-" ]]; then
|
if [[ "${1}" != "-" ]]; then
|
||||||
fg="38;5;${1}"
|
fg="38;5;${1}"
|
||||||
|
|
@ -17,7 +18,8 @@ function set_color() {
|
||||||
echo -e "\[\033[${fg}${bg}m\]"
|
echo -e "\[\033[${fg}${bg}m\]"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_user_info_prompt() {
|
function __powerline_user_info_prompt()
|
||||||
|
{
|
||||||
local user_info=""
|
local user_info=""
|
||||||
local color=${USER_INFO_THEME_PROMPT_COLOR}
|
local color=${USER_INFO_THEME_PROMPT_COLOR}
|
||||||
|
|
||||||
|
|
@ -43,7 +45,8 @@ function __powerline_user_info_prompt() {
|
||||||
[[ -n "${user_info}" ]] && echo "${user_info}|${color}"
|
[[ -n "${user_info}" ]] && echo "${user_info}|${color}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_terraform_prompt() {
|
function __powerline_terraform_prompt()
|
||||||
|
{
|
||||||
local terraform_workspace=""
|
local terraform_workspace=""
|
||||||
|
|
||||||
if [ -d .terraform ]; then
|
if [ -d .terraform ]; then
|
||||||
|
|
@ -52,21 +55,24 @@ function __powerline_terraform_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_gcloud_prompt() {
|
function __powerline_gcloud_prompt()
|
||||||
|
{
|
||||||
local active_gcloud_account=""
|
local active_gcloud_account=""
|
||||||
|
|
||||||
active_gcloud_account="$(active_gcloud_account_prompt)"
|
active_gcloud_account="$(active_gcloud_account_prompt)"
|
||||||
[[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR}"
|
[[ -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=""
|
local node_version=""
|
||||||
|
|
||||||
node_version="$(node_version_prompt)"
|
node_version="$(node_version_prompt)"
|
||||||
[[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}"
|
[[ -n "${node_version}" ]] && echo "${NODE_CHAR}${node_version}|${NODE_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_ruby_prompt() {
|
function __powerline_ruby_prompt()
|
||||||
|
{
|
||||||
local ruby_version=""
|
local ruby_version=""
|
||||||
|
|
||||||
if _command_exists rvm; then
|
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}"
|
[[ -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=""
|
local kubernetes_context=""
|
||||||
|
|
||||||
if _command_exists kubectl; then
|
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}"
|
[[ -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=""
|
local kubernetes_namespace=""
|
||||||
|
|
||||||
if _command_exists kubectl; then
|
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}"
|
[[ -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
|
set +u
|
||||||
local python_venv=""
|
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}"
|
[[ -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 color=""
|
||||||
local scm_prompt=""
|
local scm_prompt=""
|
||||||
|
|
||||||
|
|
@ -141,23 +151,28 @@ function __powerline_scm_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_cwd_prompt() {
|
function __powerline_cwd_prompt()
|
||||||
|
{
|
||||||
echo "\w|${CWD_THEME_PROMPT_COLOR}"
|
echo "\w|${CWD_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_hostname_prompt() {
|
function __powerline_hostname_prompt()
|
||||||
|
{
|
||||||
echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}"
|
echo "${SHORT_HOSTNAME:-$(hostname -s)}|${HOST_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_wd_prompt() {
|
function __powerline_wd_prompt()
|
||||||
|
{
|
||||||
echo "\W|${CWD_THEME_PROMPT_COLOR}"
|
echo "\W|${CWD_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_clock_prompt() {
|
function __powerline_clock_prompt()
|
||||||
|
{
|
||||||
echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}"
|
echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_battery_prompt() {
|
function __powerline_battery_prompt()
|
||||||
|
{
|
||||||
local color="" battery_status
|
local color="" battery_status
|
||||||
battery_status="$(battery_percentage 2> /dev/null)"
|
battery_status="$(battery_percentage 2> /dev/null)"
|
||||||
|
|
||||||
|
|
@ -176,25 +191,29 @@ function __powerline_battery_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_in_vim_prompt() {
|
function __powerline_in_vim_prompt()
|
||||||
|
{
|
||||||
if [[ -n "$VIMRUNTIME" ]]; then
|
if [[ -n "$VIMRUNTIME" ]]; then
|
||||||
echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}"
|
echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_aws_profile_prompt() {
|
function __powerline_aws_profile_prompt()
|
||||||
|
{
|
||||||
if [[ -n "${AWS_PROFILE}" ]]; then
|
if [[ -n "${AWS_PROFILE}" ]]; then
|
||||||
echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}"
|
echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_in_toolbox_prompt() {
|
function __powerline_in_toolbox_prompt()
|
||||||
|
{
|
||||||
if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then
|
if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then
|
||||||
echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}"
|
echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_shlvl_prompt() {
|
function __powerline_shlvl_prompt()
|
||||||
|
{
|
||||||
if [[ "${SHLVL}" -gt 1 ]]; then
|
if [[ "${SHLVL}" -gt 1 ]]; then
|
||||||
local prompt="${SHLVL_THEME_PROMPT_CHAR}"
|
local prompt="${SHLVL_THEME_PROMPT_CHAR}"
|
||||||
local level=$((SHLVL - 1))
|
local level=$((SHLVL - 1))
|
||||||
|
|
@ -202,7 +221,8 @@ function __powerline_shlvl_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_dirstack_prompt() {
|
function __powerline_dirstack_prompt()
|
||||||
|
{
|
||||||
if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then
|
if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then
|
||||||
local depth=$((${#DIRSTACK[@]} - 1))
|
local depth=$((${#DIRSTACK[@]} - 1))
|
||||||
local prompt="${DIRSTACK_THEME_PROMPT_CHAR}"
|
local prompt="${DIRSTACK_THEME_PROMPT_CHAR}"
|
||||||
|
|
@ -213,21 +233,25 @@ function __powerline_dirstack_prompt() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_history_number_prompt() {
|
function __powerline_history_number_prompt()
|
||||||
|
{
|
||||||
echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR}"
|
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}"
|
echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_duration_prompt() {
|
function __powerline_duration_prompt()
|
||||||
|
{
|
||||||
local duration
|
local duration
|
||||||
duration=$(_command_duration)
|
duration=$(_command_duration)
|
||||||
[[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}"
|
[[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_left_segment() {
|
function __powerline_left_segment()
|
||||||
|
{
|
||||||
local params
|
local params
|
||||||
IFS="|" read -ra params <<< "${1}"
|
IFS="|" read -ra params <<< "${1}"
|
||||||
local pad_before_segment=" "
|
local pad_before_segment=" "
|
||||||
|
|
@ -257,15 +281,18 @@ function __powerline_left_segment() {
|
||||||
((SEGMENTS_AT_LEFT += 1))
|
((SEGMENTS_AT_LEFT += 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
function __powerline_left_last_segment_padding() {
|
function __powerline_left_last_segment_padding()
|
||||||
|
{
|
||||||
LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR}") ${normal}"
|
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}"
|
[[ "$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 last_status="$?" ## always the first
|
||||||
local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color
|
local separator_char="${POWERLINE_PROMPT_CHAR}" info prompt_color
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ VIRTUALENV_THEME_PROMPT_SUFFIX=")"
|
||||||
# export LSCOLORS="Gxfxcxdxbxegedabagacad"
|
# 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:'
|
# 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_host="${bold_blue}\h${normal}"
|
||||||
ps_user="${green}\u${normal}"
|
ps_user="${green}\u${normal}"
|
||||||
ps_user_mark="${green} $ ${normal}"
|
ps_user_mark="${green} $ ${normal}"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ STATUS_THEME_PROMPT_BAD="${bold_red}❯${reset_color}${normal} "
|
||||||
STATUS_THEME_PROMPT_OK="${bold_green}❯${reset_color}${normal} "
|
STATUS_THEME_PROMPT_OK="${bold_green}❯${reset_color}${normal} "
|
||||||
PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}"
|
PURITY_THEME_PROMPT_COLOR="${PURITY_THEME_PROMPT_COLOR:=$blue}"
|
||||||
|
|
||||||
venv_prompt() {
|
venv_prompt()
|
||||||
|
{
|
||||||
python_venv=""
|
python_venv=""
|
||||||
# Detect python venv
|
# Detect python venv
|
||||||
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then
|
||||||
|
|
@ -27,7 +28,8 @@ venv_prompt() {
|
||||||
[[ -n "${python_venv}" ]] && echo "${python_venv}"
|
[[ -n "${python_venv}" ]] && echo "${python_venv}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_command() {
|
function prompt_command()
|
||||||
|
{
|
||||||
local retval=$? ret_status
|
local retval=$? ret_status
|
||||||
ret_status="$([ $retval -eq 0 ] && echo -e "$STATUS_THEME_PROMPT_OK" || echo -e "$STATUS_THEME_PROMPT_BAD")"
|
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)"
|
PS1="\n${PURITY_THEME_PROMPT_COLOR}\w $(scm_prompt_info)\n${ret_status}$(venv_prompt)"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
if [ -z "$BASH_IT" ];
|
if [ -z "$BASH_IT" ]; then
|
||||||
then
|
|
||||||
BASH_IT="$HOME/.bash_it"
|
BASH_IT="$HOME/.bash_it"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue