diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9154a0bc7..38dd4862df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: bats-test: strategy: matrix: - os: [ubuntu-20.04, ubuntu-22.04, macos-14, macos-15] + os: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-14] runs-on: ${{ matrix.os }} @@ -62,3 +62,21 @@ jobs: run: python3 -m pip install -r test/lint-requirements.txt - name: Run lint run: ./lint_clean_files.sh + + lint-differential: + runs-on: ubuntu-latest + + permissions: + security-events: write + + steps: + - name: Repository checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - id: ShellCheck + name: Differential ShellCheck + uses: redhat-plumbers-in-action/differential-shellcheck@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/clean_files.txt b/clean_files.txt index 93fbfca475..1c205381ec 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -40,13 +40,16 @@ completion/available/awscli.completion.bash completion/available/bash-it.completion.bash completion/available/brew.completion.bash completion/available/bundler.completion.bash +completion/available/capistrano.completion.bash completion/available/cargo.completion.bash completion/available/composer.completion.bash completion/available/conda.completion.bash completion/available/consul.completion.bash completion/available/dart.completion.bash +completion/available/dirs.completion.bash completion/available/django.completion.bash completion/available/dmidecode.completion.bash +completion/available/docker-compose.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/dotnet.completion.bash @@ -130,19 +133,16 @@ plugins/available/pyenv.plugin.bash plugins/available/python.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash +plugins/available/sudo.plugin.bash plugins/available/textmate.plugin.bash +plugins/available/thefuck.plugin.bash plugins/available/todo.plugin.bash plugins/available/url.plugin.bash +plugins/available/virtualenv.plugin.bash plugins/available/xterm.plugin.bash plugins/available/z_autoenv.plugin.bash plugins/available/zoxide.plugin.bash -# tests -# -test/completion/aliases.completion.bats -test/run -test/test_helper.bash - # themes # themes/90210 @@ -164,6 +164,7 @@ themes/easy themes/elixr themes/essential themes/githelpers.theme.bash +themes/gitline themes/inretio themes/lambda themes/modern diff --git a/completion/available/capistrano.completion.bash b/completion/available/capistrano.completion.bash index d5fda06fa5..d84a5bd2dd 100644 --- a/completion/available/capistrano.completion.bash +++ b/completion/available/capistrano.completion.bash @@ -1,24 +1,25 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for Capistrano. export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/} _capcomplete() { - if [ -f Capfile ]; then - recent=`ls -t .cap_tasks~ Capfile **/*.cap 2> /dev/null | head -n 1` - if [[ $recent != '.cap_tasks~' ]]; then - cap --version | grep 'Capistrano v2.' > /dev/null - if [ $? -eq 0 ]; then - # Capistrano 2.x - cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ - else - # Capistrano 3.x - cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ - fi - fi - COMPREPLY=($(compgen -W "`cat .cap_tasks~`" -- ${COMP_WORDS[COMP_CWORD]})) - return 0 - fi + if [ -f Capfile ]; then + # shellcheck disable=SC2012 + recent=$(ls -t .cap_tasks~ Capfile ./**/*.cap 2> /dev/null | head -n 1) + if [[ $recent != '.cap_tasks~' ]]; then + if cap --version | grep -q 'Capistrano v2.'; then + # Capistrano 2.x + cap --tool --verbose --tasks | cut -d " " -f 2 > .cap_tasks~ + else + # Capistrano 3.x + cap --all --tasks | cut -d " " -f 2 > .cap_tasks~ + fi + fi + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$(cat .cap_tasks~)" -- "${COMP_WORDS[COMP_CWORD]}")) + return 0 + fi } complete -o default -o nospace -F _capcomplete cap diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash index ba18db3241..c6e01155d6 100644 --- a/completion/available/dirs.completion.bash +++ b/completion/available/dirs.completion.bash @@ -1,15 +1,16 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Bash completion support for the 'dirs' plugin (commands G, R). _dirs-complete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" + local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" - # parse all defined shortcuts from ~/.dirs - if [ -r "$HOME/.dirs" ]; then - COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) ) - fi + # parse all defined shortcuts from ~/.dirs + if [ -r "$HOME/.dirs" ]; then + # shellcheck disable=SC2207 + COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- "${CURRENT_PROMPT}")) + fi - return 0 + return 0 } complete -o default -o nospace -F _dirs-complete G R diff --git a/completion/available/docker-compose.completion.bash b/completion/available/docker-compose.completion.bash old mode 100755 new mode 100644 index 1102f5d97e..57d414fd5a --- a/completion/available/docker-compose.completion.bash +++ b/completion/available/docker-compose.completion.bash @@ -1,4 +1,5 @@ -#!/bin/bash +# shellcheck shell=bash +# shellcheck disable=SC2207 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,13 +36,13 @@ __docker_compose_previous_extglob_setting=$(shopt -p extglob) shopt -s extglob __docker_compose_q() { - docker-compose 2>/dev/null "${top_level_options[@]}" "$@" + docker-compose 2> /dev/null "${top_level_options[@]}" "$@" } # Transforms a multiline list of strings into a single line string # with the words separated by "|". __docker_compose_to_alternatives() { - local parts=( $1 ) + local parts=("$1") local IFS='|' echo "${parts[*]}" } @@ -49,7 +50,8 @@ __docker_compose_to_alternatives() { # Transforms a multiline list of options into an extglob pattern # suitable for use in case statements. __docker_compose_to_extglob() { - local extglob=$( __docker_compose_to_alternatives "$1" ) + local extglob + extglob=$(__docker_compose_to_alternatives "$1") echo "@($extglob)" } @@ -57,8 +59,8 @@ __docker_compose_to_extglob() { # the commandline. The option may be a pattern, e.g. `--force|-f`. __docker_compose_has_option() { local pattern="$1" - for (( i=2; i < $cword; ++i)); do - if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then + for ((i = 2; i < cword; ++i)); do + if [[ ${words[$i]} =~ ^($pattern)$ ]]; then return 0 fi done @@ -69,34 +71,33 @@ __docker_compose_has_option() { # which matches the extglob passed in as an argument. # This function is needed for key-specific completions. __docker_compose_map_key_of_current_option() { - local glob="$1" + local glob="$1" - local key glob_pos - if [ "$cur" = "=" ] ; then # key= case - key="$prev" - glob_pos=$((cword - 2)) - elif [[ $cur == *=* ]] ; then # key=value case (OSX) - key=${cur%=*} - glob_pos=$((cword - 1)) - elif [ "$prev" = "=" ] ; then - key=${words[$cword - 2]} # key=value case - glob_pos=$((cword - 3)) - else - return - fi + local key glob_pos + if [ "$cur" = "=" ]; then # key= case + key="$prev" + glob_pos=$((cword - 2)) + elif [[ $cur == *=* ]]; then # key=value case (OSX) + key=${cur%=*} + glob_pos=$((cword - 1)) + elif [ "$prev" = "=" ]; then + key=${words[$cword - 2]} # key=value case + glob_pos=$((cword - 3)) + else + return + fi - [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax + [ "${words[$glob_pos]}" = "=" ] && ((glob_pos--)) # --option=key=value syntax - [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" + [[ ${words[$glob_pos]} == @($glob) ]] && echo "$key" } # suppress trailing whitespace __docker_compose_nospace() { # compopt is not available in ancient bash versions - type compopt &>/dev/null && compopt -o nospace + type compopt &> /dev/null && compopt -o nospace } - # Outputs a list of all defined services, regardless of their running state. # Arguments for `docker-compose ps` may be passed in order to filter the service list, # e.g. `status=running`. @@ -108,31 +109,31 @@ __docker_compose_services() { # Arguments for `docker-compose ps` may be passed in order to filter the service list, # see `__docker_compose_services`. __docker_compose_complete_services() { - COMPREPLY=( $(compgen -W "$(__docker_compose_services "$@")" -- "$cur") ) + COMPREPLY=($(compgen -W "$(__docker_compose_services "$@")" -- "$cur")) } # The services for which at least one running container exists __docker_compose_complete_running_services() { - local names=$(__docker_compose_services --filter status=running) - COMPREPLY=( $(compgen -W "$names" -- "$cur") ) + local names + names=$(__docker_compose_services --filter status=running) + COMPREPLY=($(compgen -W "$names" -- "$cur")) } - _docker_compose_build() { case "$prev" in --build-arg) - COMPREPLY=( $( compgen -e -- "$cur" ) ) + COMPREPLY=($(compgen -e -- "$cur")) __docker_compose_nospace return ;; - --memory|-m) + --memory | -m) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--build-arg --compress --force-rm --help --memory -m --no-cache --no-rm --pull --parallel -q --quiet" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--build-arg --compress --force-rm --help --memory -m --no-cache --no-rm --pull --parallel -q --quiet" -- "$cur")) ;; *) __docker_compose_complete_services --filter source=build @@ -140,39 +141,36 @@ _docker_compose_build() { esac } - _docker_compose_bundle() { case "$prev" in - --output|-o) + --output | -o) _filedir return ;; esac - COMPREPLY=( $( compgen -W "--push-images --help --output -o" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--push-images --help --output -o" -- "$cur")) } - _docker_compose_config() { case "$prev" in --hash) - if [[ $cur == \\* ]] ; then - COMPREPLY=( '\*' ) + if [[ $cur == \\* ]]; then + COMPREPLY=('\*') else - COMPREPLY=( $(compgen -W "$(__docker_compose_services) \\\* " -- "$cur") ) + COMPREPLY=($(compgen -W "$(__docker_compose_services) \\\* " -- "$cur")) fi return ;; esac - COMPREPLY=( $( compgen -W "--hash --help --quiet -q --resolve-image-digests --services --volumes" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--hash --help --quiet -q --resolve-image-digests --services --volumes" -- "$cur")) } - _docker_compose_create() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--build --force-recreate --help --no-build --no-recreate" -- "$cur")) ;; *) __docker_compose_complete_services @@ -180,60 +178,57 @@ _docker_compose_create() { esac } - _docker_compose_docker_compose() { case "$prev" in - --tlscacert|--tlscert|--tlskey) + --tlscacert | --tlscert | --tlskey) _filedir return ;; - --file|-f) + --file | -f) _filedir "y?(a)ml" return ;; --log-level) - COMPREPLY=( $( compgen -W "debug info warning error critical" -- "$cur" ) ) + COMPREPLY=($(compgen -W "debug info warning error critical" -- "$cur")) return ;; --project-directory) _filedir -d return ;; - $(__docker_compose_to_extglob "$daemon_options_with_args") ) + "$(__docker_compose_to_extglob "$daemon_options_with_args")") return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "$daemon_boolean_options $daemon_options_with_args $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur" ) ) + COMPREPLY=($(compgen -W "$daemon_boolean_options $daemon_options_with_args $top_level_options_with_args --help -h --no-ansi --verbose --version -v" -- "$cur")) ;; *) - COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) ;; esac } - _docker_compose_down() { case "$prev" in --rmi) - COMPREPLY=( $( compgen -W "all local" -- "$cur" ) ) + COMPREPLY=($(compgen -W "all local" -- "$cur")) return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --rmi --timeout -t --volumes -v --remove-orphans" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --rmi --timeout -t --volumes -v --remove-orphans" -- "$cur")) ;; esac } - _docker_compose_events() { case "$prev" in --json) @@ -243,7 +238,7 @@ _docker_compose_events() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --json" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --json" -- "$cur")) ;; *) __docker_compose_complete_services @@ -251,17 +246,16 @@ _docker_compose_events() { esac } - _docker_compose_exec() { case "$prev" in - --index|--user|-u|--workdir|-w) + --index | --user | -u | --workdir | -w) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "-d --detach --help --index --privileged -T --user -u --workdir -w" -- "$cur" ) ) + COMPREPLY=($(compgen -W "-d --detach --help --index --privileged -T --user -u --workdir -w" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -269,15 +263,14 @@ _docker_compose_exec() { esac } - _docker_compose_help() { - COMPREPLY=( $( compgen -W "${commands[*]}" -- "$cur" ) ) + COMPREPLY=($(compgen -W "${commands[*]}" -- "$cur")) } _docker_compose_images() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --quiet -q" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --quiet -q" -- "$cur")) ;; *) __docker_compose_complete_services @@ -288,14 +281,14 @@ _docker_compose_images() { _docker_compose_kill() { case "$prev" in -s) - COMPREPLY=( $( compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo $cur | tr '[:lower:]' '[:upper:]')" ) ) + COMPREPLY=($(compgen -W "SIGHUP SIGINT SIGKILL SIGUSR1 SIGUSR2" -- "$(echo "$cur" | tr '[:lower:]' '[:upper:]')")) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help -s" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help -s" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -303,7 +296,6 @@ _docker_compose_kill() { esac } - _docker_compose_logs() { case "$prev" in --tail) @@ -313,7 +305,7 @@ _docker_compose_logs() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--follow -f --help --no-color --tail --timestamps -t" -- "$cur")) ;; *) __docker_compose_complete_services @@ -321,11 +313,10 @@ _docker_compose_logs() { esac } - _docker_compose_pause() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -333,21 +324,20 @@ _docker_compose_pause() { esac } - _docker_compose_port() { case "$prev" in --protocol) - COMPREPLY=( $( compgen -W "tcp udp" -- "$cur" ) ) - return; + COMPREPLY=($(compgen -W "tcp udp" -- "$cur")) + return ;; --index) - return; + return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --index --protocol" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --index --protocol" -- "$cur")) ;; *) __docker_compose_complete_services @@ -355,31 +345,31 @@ _docker_compose_port() { esac } - _docker_compose_ps() { - local key=$(__docker_compose_map_key_of_current_option '--filter') + local key + key=$(__docker_compose_map_key_of_current_option '--filter') case "$key" in source) - COMPREPLY=( $( compgen -W "build image" -- "${cur##*=}" ) ) + COMPREPLY=($(compgen -W "build image" -- "${cur##*=}")) return ;; status) - COMPREPLY=( $( compgen -W "paused restarting running stopped" -- "${cur##*=}" ) ) + COMPREPLY=($(compgen -W "paused restarting running stopped" -- "${cur##*=}")) return ;; esac case "$prev" in --filter) - COMPREPLY=( $( compgen -W "source status" -S "=" -- "$cur" ) ) + COMPREPLY=($(compgen -W "source status" -S "=" -- "$cur")) __docker_compose_nospace - return; + return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--all -a --filter --help --quiet -q --services" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--all -a --filter --help --quiet -q --services" -- "$cur")) ;; *) __docker_compose_complete_services @@ -387,11 +377,10 @@ _docker_compose_ps() { esac } - _docker_compose_pull() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --ignore-pull-failures --include-deps --no-parallel --quiet -q" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --ignore-pull-failures --include-deps --no-parallel --quiet -q" -- "$cur")) ;; *) __docker_compose_complete_services --filter source=image @@ -399,11 +388,10 @@ _docker_compose_pull() { esac } - _docker_compose_push() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --ignore-push-failures" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --ignore-push-failures" -- "$cur")) ;; *) __docker_compose_complete_services @@ -411,17 +399,16 @@ _docker_compose_push() { esac } - _docker_compose_restart() { case "$prev" in - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -429,14 +416,13 @@ _docker_compose_restart() { esac } - _docker_compose_rm() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--force -f --help --stop -s -v" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--force -f --help --stop -s -v" -- "$cur")) ;; *) - if __docker_compose_has_option "--stop|-s" ; then + if __docker_compose_has_option "--stop|-s"; then __docker_compose_complete_services else __docker_compose_complete_services --filter status=stopped @@ -445,22 +431,21 @@ _docker_compose_rm() { esac } - _docker_compose_run() { case "$prev" in -e) - COMPREPLY=( $( compgen -e -- "$cur" ) ) + COMPREPLY=($(compgen -e -- "$cur")) __docker_compose_nospace return ;; - --entrypoint|--label|-l|--name|--user|-u|--volume|-v|--workdir|-w) + --entrypoint | --label | -l | --name | --user | -u | --volume | -v | --workdir | -w) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--detach -d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --use-aliases --user -u --volume -v --workdir -w" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--detach -d --entrypoint -e --help --label -l --name --no-deps --publish -p --rm --service-ports -T --use-aliases --user -u --volume -v --workdir -w" -- "$cur")) ;; *) __docker_compose_complete_services @@ -468,34 +453,32 @@ _docker_compose_run() { esac } - _docker_compose_scale() { case "$prev" in =) COMPREPLY=("$cur") return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) - COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") ) + COMPREPLY=($(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur")) __docker_compose_nospace ;; esac } - _docker_compose_start() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_services --filter status=stopped @@ -503,17 +486,16 @@ _docker_compose_start() { esac } - _docker_compose_stop() { case "$prev" in - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -521,11 +503,10 @@ _docker_compose_stop() { esac } - _docker_compose_top() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_running_services @@ -533,11 +514,10 @@ _docker_compose_top() { esac } - _docker_compose_unpause() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--help" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--help" -- "$cur")) ;; *) __docker_compose_complete_services --filter status=paused @@ -545,7 +525,6 @@ _docker_compose_unpause() { esac } - _docker_compose_up() { case "$prev" in =) @@ -557,18 +536,18 @@ _docker_compose_up() { return ;; --scale) - COMPREPLY=( $(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur") ) + COMPREPLY=($(compgen -S "=" -W "$(__docker_compose_services)" -- "$cur")) __docker_compose_nospace return ;; - --timeout|-t) + --timeout | -t) return ;; esac case "$cur" in -*) - COMPREPLY=( $( compgen -W "--abort-on-container-exit --always-recreate-deps --build -d --detach --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --renew-anon-volumes -V --remove-orphans --scale --timeout -t" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--abort-on-container-exit --always-recreate-deps --build -d --detach --exit-code-from --force-recreate --help --no-build --no-color --no-deps --no-recreate --no-start --renew-anon-volumes -V --remove-orphans --scale --timeout -t" -- "$cur")) ;; *) __docker_compose_complete_services @@ -576,18 +555,17 @@ _docker_compose_up() { esac } - _docker_compose_version() { case "$cur" in -*) - COMPREPLY=( $( compgen -W "--short" -- "$cur" ) ) + COMPREPLY=($(compgen -W "--short" -- "$cur")) ;; esac } - _docker_compose() { - local previous_extglob_setting=$(shopt -p extglob) + local previous_extglob_setting + previous_extglob_setting=$(shopt -p extglob) shopt -s extglob local commands=( @@ -651,32 +629,32 @@ _docker_compose() { local top_level_options=() local counter=1 - while [ $counter -lt $cword ]; do + while [ $counter -lt "$cword" ]; do case "${words[$counter]}" in - $(__docker_compose_to_extglob "$daemon_boolean_options") ) + "$(__docker_compose_to_extglob "$daemon_boolean_options")") local opt=${words[counter]} - top_level_options+=($opt) + top_level_options+=("$opt") ;; - $(__docker_compose_to_extglob "$daemon_options_with_args") ) + "$(__docker_compose_to_extglob "$daemon_options_with_args")") local opt=${words[counter]} local arg=${words[++counter]} - top_level_options+=($opt $arg) + top_level_options+=("$opt" "$arg") ;; - $(__docker_compose_to_extglob "$top_level_options_with_args") ) - (( counter++ )) - ;; - -*) + "$(__docker_compose_to_extglob "$top_level_options_with_args")") + ((counter++)) ;; + -*) ;; + *) command="${words[$counter]}" break ;; esac - (( counter++ )) + ((counter++)) done local completions_func=_docker_compose_${command//-/_} - _is_function $completions_func && $completions_func + _is_function "$completions_func" && $completions_func eval "$previous_extglob_setting" return 0 diff --git a/docs/README.md b/docs/README.md index b307a7abfd..44c438babe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -46,6 +46,13 @@ That's it! :smiley: You can check out more components of Bash-it, and customize it to your desire. For more information, see detailed instructions [here](https://bash-it.readthedocs.io/en/latest/installation/). +### custom configuration file location + +By default the instller modifies/creates the actual ``~/.bashrc`` is updated. +If this is undesirable, you can create another file, by run the installer: +```bash +BASH_IT_CONFIG_FILE=path/to/my/custom/location.bash ~/.bash_it/install.sh +``` ## Contributing diff --git a/install.sh b/install.sh index 58c25537b6..4063f516ed 100755 --- a/install.sh +++ b/install.sh @@ -194,6 +194,13 @@ case $OSTYPE in ;; esac +# overriding CONFIG_FILE: +CONFIG_FILE="${BASH_IT_CONFIG_FILE:-"${CONFIG_FILE}"}" +# create subdir if CONFIG_FILE has subdirectory components +if [[ "${CONFIG_FILE%/*}" != "${CONFIG_FILE}" ]]; then + mkdir -p "${HOME}/${CONFIG_FILE%/*}" +fi + BACKUP_FILE=$CONFIG_FILE.bak echo "Installing bash-it" if [[ -z "${no_modify_config}" ]]; then diff --git a/plugins/available/sudo.plugin.bash b/plugins/available/sudo.plugin.bash index eb155daa04..6451eb74c1 100644 --- a/plugins/available/sudo.plugin.bash +++ b/plugins/available/sudo.plugin.bash @@ -1,22 +1,23 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice' function sudo-command-line() { - about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" - group "sudo" + about "toggle sudo at the beginning of the current or the previous command by hitting the ESC key twice" + group "sudo" - [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) - if [[ $READLINE_LINE == sudo\ * ]]; then - READLINE_LINE="${READLINE_LINE#sudo }" - else - READLINE_LINE="sudo $READLINE_LINE" - fi - READLINE_POINT=${#READLINE_LINE} + [[ ${#READLINE_LINE} -eq 0 ]] && READLINE_LINE=$(fc -l -n -1 | xargs) + if [[ $READLINE_LINE == sudo\ * ]]; then + READLINE_LINE="${READLINE_LINE#sudo }" + else + READLINE_LINE="sudo $READLINE_LINE" + fi + READLINE_POINT=${#READLINE_LINE} } # Define shortcut keys: [Esc] [Esc] # Readline library requires bash version 4 or later -if [ "${BASH_VERSINFO}" -ge 4 ]; then - bind -x '"\e\e": sudo-command-line' +if [ "${BASH_VERSINFO[0]}" -ge 4 ]; then + bind -x '"\e\e": sudo-command-line' fi diff --git a/plugins/available/thefuck.plugin.bash b/plugins/available/thefuck.plugin.bash index 242a77df22..3427e7c58e 100644 --- a/plugins/available/thefuck.plugin.bash +++ b/plugins/available/thefuck.plugin.bash @@ -1,9 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Initialization for fuck' # https://github.com/nvbn/thefuck if _command_exists thefuck; then - # shellcheck disable=SC2046 - eval $(thefuck --alias) + # shellcheck disable=SC2046 + eval $(thefuck --alias) fi diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index 41d55ddfb1..94ea39f4d2 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -11,35 +11,33 @@ elif _command_exists virtualenvwrapper.sh; then source virtualenvwrapper.sh fi - function mkvenv { - about 'create a new virtualenv for this directory' - group 'virtualenv' + about 'create a new virtualenv for this directory' + group 'virtualenv' - local cwd="${PWD##*/}" - mkvirtualenv --distribute "$cwd" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "$cwd" } - function mkvbranch { - about 'create a new virtualenv for the current branch' - group 'virtualenv' + about 'create a new virtualenv for the current branch' + group 'virtualenv' - local cwd="${PWD##*/}" - mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" + local cwd="${PWD##*/}" + mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}" } function wovbranch { - about 'sets workon branch' - group 'virtualenv' + about 'sets workon branch' + group 'virtualenv' - local cwd="${PWD##*/}" - workon "${cwd}@${SCM_BRANCH}" + local cwd="${PWD##*/}" + workon "${cwd}@${SCM_BRANCH}" } function wovenv { - about 'works on the virtualenv for this directory' - group 'virtualenv' + about 'works on the virtualenv for this directory' + group 'virtualenv' - workon "${PWD##*/}" + workon "${PWD##*/}" } diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 283be98ceb..8ffd11e6e6 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -1,4 +1,5 @@ # shellcheck shell=bash +# shellcheck disable=SC2207 cite about-plugin about-plugin 'source into environment when cding to directories' diff --git a/themes/gitline/gitline.theme.bash b/themes/gitline/gitline.theme.bash index 9a68f3703f..e5aaa904ba 100644 --- a/themes/gitline/gitline.theme.bash +++ b/themes/gitline/gitline.theme.bash @@ -1,6 +1,7 @@ -#!/usr/bin/env bash - -. "$BASH_IT/themes/gitline/powerline.base.bash" +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. +# shellcheck source-path=SCRIPTDIR/../gitline +source "${BASH_IT?}/themes/gitline/powerline.base.bash" #For the logo(Uncomment if you want a logo before your name) #PROMPT_DISTRO_LOGO="💻" @@ -9,7 +10,7 @@ PROMPT_DISTRO_LOGO_COLORBG=52 #Prompt Seperator Charactors PROMPT_CHAR=${POWERLINE_PROMPT_CHAR:=""} -POWERLINE_LEFT_SEPARATOR=${POWERLINE_LEFT_SEPARATOR:=""} +: "${POWERLINE_LEFT_SEPARATOR:=""}" #USER INFO CHARACTERS USER_INFO_SSH_CHAR=${POWERLINE_USER_INFO_SSH_CHAR:=" "} @@ -54,12 +55,12 @@ LAST_STATUS_THEME_PROMPT_COLOR=52 CLOCK_THEME_PROMPT_COLOR=240 #For Battery Plugin -BATTERY_AC_CHAR=${BATTERY_AC_CHAR:="⚡"} +: "${BATTERY_AC_CHAR:="⚡"}" BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR=70 BATTERY_STATUS_THEME_PROMPT_LOW_COLOR=208 BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR=160 -THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:="%H:%M:%S"} +: "${THEME_CLOCK_FORMAT:="%H:%M:%S"}" IN_VIM_THEME_PROMPT_COLOR=245 IN_VIM_THEME_PROMPT_TEXT="vim" @@ -67,5 +68,6 @@ IN_VIM_THEME_PROMPT_TEXT="vim" IN_TOOLBOX_THEME_PROMPT_COLOR=125 IN_TOOLBOX_THEME_PROMPT_TEXT="⬢ " +: "${POWERLINE_PROMPT:="user_info scm python_venv ruby node cwd"}" safe_append_prompt_command __powerline_prompt_command diff --git a/themes/gitline/powerline.base.bash b/themes/gitline/powerline.base.bash index 7f6f313001..af31f27177 100644 --- a/themes/gitline/powerline.base.bash +++ b/themes/gitline/powerline.base.bash @@ -1,233 +1,340 @@ +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. #To set color for foreground and background -function set_color { - set +u - if [[ "${1}" != "-" ]]; then - fg="38;5;${1}" - fi - if [[ "${2}" != "-" ]]; then - bg="48;5;${2}" - [[ -n "${fg}" ]] && bg=";${bg}" - fi - echo -e "\[\033[${fg}${bg}m\]" +function set_color() { + local fg='' bg='' + if [[ "${1:-}" != "-" ]]; then + fg="38;5;${1}" + fi + if [[ "${2:-}" != "-" ]]; then + bg="48;5;${2}" + [[ -n "${fg}" ]] && bg=";${bg}" + fi + echo -e "\[\033[${fg}${bg}m\]" } #Customising User Info Segment -function __powerline_user_info_prompt { - local user_info="${USER}" - local color=${USER_INFO_THEME_PROMPT_COLOR} - local fg_color=15 - - if [[ "${THEME_CHECK_SUDO}" = true ]]; then - if sudo -n uptime 2>&1 | grep -q "load"; then - color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} - fi - fi - - case "${POWERLINE_PROMPT_USER_INFO_MODE}" in - "sudo") - if [[ "${color}" = "${USER_INFO_THEME_PROMPT_COLOR_SUDO}" ]]; then - user_info="👑 ${USER}" - fg_color=227 - color=${USER_INFO_THEME_PROMPT_COLOR_SUDO} - fi - ;; - *) - if [[ -n "${SSH_CLIENT}" ]] || [[ -n "${SSH_CONNECTION}" ]]; then - user_info="${USER_INFO_SSH_CHAR}${USER}" - else - user_info="${USER}" - fi - ;; - esac - [[ -n "${user_info}" ]] && echo "${user_info}|${color}|${fg_color}" +function __powerline_user_info_prompt() { + local user_info="${SHORT_USER:-${USER}}" + local color=${USER_INFO_THEME_PROMPT_COLOR-${POWERLINE_USER_INFO_COLOR-"32"}} + local -i fg_color=15 + + if [[ "${THEME_CHECK_SUDO:-false}" == true ]]; then + if sudo -vn 2> /dev/null; then + color=${USER_INFO_THEME_PROMPT_COLOR_SUDO-${POWERLINE_USER_INFO_COLOR_SUDO-"202"}} + fi + fi + + case "${POWERLINE_PROMPT_USER_INFO_MODE:-}" in + "sudo") + if [[ "${color}" == "${USER_INFO_THEME_PROMPT_COLOR_SUDO?}" ]]; then + user_info="👑 ${USER}" + fg_color=227 + fi + ;; + *) + if [[ -n "${SSH_CLIENT:-}" ]] || [[ -n "${SSH_CONNECTION:-}" ]]; then + user_info="${USER_INFO_SSH_CHAR-${POWERLINE_USER_INFO_SSH_CHAR-"⌁ "}}${user_info}" + fi + ;; + esac + echo "${user_info}|${color}|${fg_color}" +} + +function __powerline_terraform_prompt() { + local terraform_workspace="" + + if [[ -d .terraform ]]; then + terraform_workspace="$(terraform_workspace_prompt)" + [[ -n "${terraform_workspace}" ]] && echo "${TERRAFORM_CHAR-${POWERLINE_TERRAFORM_CHAR-"❲t❳ "}}${terraform_workspace}|${TERRAFORM_THEME_PROMPT_COLOR-${POWERLINE_TERRAFORM_COLOR-"161"}}" + fi +} + +function __powerline_gcloud_prompt() { + local active_gcloud_account="" + + active_gcloud_account="$(active_gcloud_account_prompt)" + [[ -n "${active_gcloud_account}" ]] && echo "${GCLOUD_CHAR-${POWERLINE_GCLOUD_CHAR-"❲G❳ "}}${active_gcloud_account}|${GCLOUD_THEME_PROMPT_COLOR-${POWERLINE_GCLOUD_COLOR-"161"}}" +} + +function __powerline_node_prompt() { + local node_version="" + + node_version="$(node_version_prompt)" + [[ -n "${node_version}" ]] && echo "${NODE_CHAR-${POWERLINE_NODE_CHAR-="❲n❳ "}}${node_version}|${NODE_THEME_PROMPT_COLOR-${POWERLINE_NODE_COLOR-"22"}}" } #Customising Ruby Prompt -function __powerline_ruby_prompt { - local ruby_version="" - local fg_color=206 +function __powerline_ruby_prompt() { + local ruby_version + local -i fg_color=206 + + if _command_exists rvm; then + ruby_version="$(rvm_version_prompt)" + elif _command_exists rbenv; then + ruby_version=$(rbenv_version_prompt) + fi + + if [[ -n "${ruby_version:-}" ]]; then + echo "${RUBY_CHAR?}${ruby_version}|${RUBY_THEME_PROMPT_COLOR?}|${fg_color}" + fi +} - if _command_exists rvm; then - ruby_version="$(rvm_version_prompt)" - elif _command_exists rbenv; then - ruby_version=$(rbenv_version_prompt) - fi +function __powerline_k8s_context_prompt() { + local kubernetes_context="" - [[ -n "${ruby_version}" ]] && echo "${RUBY_CHAR}${ruby_version}|${RUBY_THEME_PROMPT_COLOR}|${fg_color}" + if _command_exists kubectl; then + kubernetes_context="$(k8s_context_prompt)" + fi + + [[ -n "${kubernetes_context}" ]] && echo "${KUBERNETES_CONTEXT_THEME_CHAR-${POWERLINE_KUBERNETES_CONTEXT_CHAR-"⎈ "}}${kubernetes_context}|${KUBERNETES_CONTEXT_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_CONTEXT_COLOR-"26"}}" } -#Customising Python (venv) Prompt -function __powerline_python_venv_prompt { - set +u - local python_venv="" - local fg_color=206 +function __powerline_k8s_namespace_prompt() { + local kubernetes_namespace="" - if [[ -n "${CONDA_DEFAULT_ENV}" ]]; then - python_venv="${CONDA_DEFAULT_ENV}" - PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR} - elif [[ -n "${VIRTUAL_ENV}" ]]; then - python_venv=$(basename "${VIRTUAL_ENV}") - fi + if _command_exists kubectl; then + kubernetes_namespace="$(k8s_namespace_prompt)" + fi - [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR}|${fg_color}" + [[ -n "${kubernetes_namespace}" ]] && echo "${KUBERNETES_NAMESPACE_THEME_CHAR-${POWERLINE_KUBERNETES_NAMESPACE_CHAR-"⎈ "}}${kubernetes_namespace}|${KUBERNETES_NAMESPACE_THEME_PROMPT_COLOR-${POWERLINE_KUBERNETES_NAMESPACE_COLOR-"60"}}" } -#Customising SCM(GIT) Prompt -function __powerline_scm_prompt { - local color="" - local scm_prompt="" - local fg_color=206 +#Customising Python (venv) Prompt +function __powerline_python_venv_prompt() { + local python_venv="" + local -i fg_color=206 + + if [[ -n "${CONDA_DEFAULT_ENV:-}" ]]; then + python_venv="${CONDA_DEFAULT_ENV}" + local PYTHON_VENV_CHAR=${CONDA_PYTHON_VENV_CHAR-${POWERLINE_CONDA_PYTHON_VENV_CHAR-"ⓔ "}} + elif [[ -n "${VIRTUAL_ENV:-}" ]]; then + python_venv="${VIRTUAL_ENV##*/}" + fi + + [[ -n "${python_venv}" ]] && echo "${PYTHON_VENV_CHAR?}${python_venv}|${PYTHON_VENV_THEME_PROMPT_COLOR?}|${fg_color}" +} - scm_prompt_vars +#Customising SCM(GIT) Prompt +function __powerline_scm_prompt() { + local color="" + local scm_prompt="" + local -i fg_color=206 + + scm_prompt_vars + + if [[ "${SCM_NONE_CHAR?}" != "${SCM_CHAR?}" ]]; then + if [[ "${SCM_DIRTY?}" -eq 3 ]]; then + color=${SCM_THEME_PROMPT_STAGED_COLOR-${POWERLINE_SCM_STAGED_COLOR-"30"}} + fg_color=124 + elif [[ "${SCM_DIRTY?}" -eq 2 ]]; then + color=${SCM_THEME_PROMPT_UNSTAGED_COLOR-${POWERLINE_SCM_UNSTAGED_COLOR-"92"}} + fg_color=56 + elif [[ "${SCM_DIRTY?}" -eq 1 ]]; then + color=${SCM_THEME_PROMPT_DIRTY_COLOR-${POWERLINE_SCM_DIRTY_COLOR-"88"}} + fg_color=118 + elif [[ "${SCM_DIRTY?}" -eq 0 ]]; then + color=${SCM_THEME_PROMPT_CLEAN_COLOR-${POWERLINE_SCM_CLEAN_COLOR-"25"}} + fg_color=16 + else + color=${SCM_THEME_PROMPT_COLOR-${POWERLINE_SCM_CLEAN_COLOR-"25"}} + fg_color=255 + fi + if [[ "${SCM_GIT_CHAR?}" == "${SCM_CHAR?}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_P4_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_HG_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + elif [[ "${SCM_SVN_CHAR?}" == "${SCM_CHAR}" ]]; then + scm_prompt+="${SCM_CHAR}${SCM_BRANCH?}${SCM_STATE?}" + fi + echo "${scm_prompt?}|${color}|${fg_color}" + fi +} +function __powerline_cwd_prompt() { + local -i fg_color=16 - if [[ "${SCM_NONE_CHAR}" != "${SCM_CHAR}" ]]; then - if [[ "${SCM_DIRTY}" -eq 3 ]]; then - color=${SCM_THEME_PROMPT_STAGED_COLOR} - fg_color=124 - elif [[ "${SCM_DIRTY}" -eq 2 ]]; then - color=${SCM_THEME_PROMPT_UNSTAGED_COLOR} - fg_color=56 - elif [[ "${SCM_DIRTY}" -eq 1 ]]; then - color=${SCM_THEME_PROMPT_DIRTY_COLOR} - fg_color=118 - elif [[ "${SCM_DIRTY}" -eq 0 ]]; then - color=${SCM_THEME_PROMPT_CLEAN_COLOR} - fg_color=16 - else - color=${SCM_THEME_PROMPT_COLOR} - fg_color=255 - fi - if [[ "${SCM_GIT_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - elif [[ "${SCM_P4_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - elif [[ "${SCM_HG_CHAR}" == "${SCM_CHAR}" ]]; then - scm_prompt+="${SCM_CHAR}${SCM_BRANCH}${SCM_STATE}" - fi - echo "${scm_prompt}${scm}|${color}|${fg_color}" - fi + echo "\w|${CWD_THEME_PROMPT_COLOR?}|${fg_color}" } -function __powerline_cwd_prompt { - local cwd=$(pwd | sed "s|^${HOME}|~|") - local fg_color=16 +function __powerline_hostname_prompt() { + local -i fg_color=206 - echo "${cwd}|${CWD_THEME_PROMPT_COLOR}|${fg_color}" + echo "\h|${HOST_THEME_PROMPT_COLOR?}|${fg_color}" } -function __powerline_hostname_prompt { - local fg_color=206 +function __powerline_wd_prompt() { + local -i fg_color=206 - echo "$(hostname -s)|${HOST_THEME_PROMPT_COLOR}|${fg_color}" + echo "\W|${CWD_THEME_PROMPT_COLOR?}|${fg_color}" } -function __powerline_wd_prompt { - local fg_color=206 +function __powerline_clock_prompt() { + local -i fg_color=206 - echo "\W|${CWD_THEME_PROMPT_COLOR}|${fg_color}" + echo "\D{${THEME_CLOCK_FORMAT?}}|${CLOCK_THEME_PROMPT_COLOR?}|${fg_color}" } -function __powerline_clock_prompt { - local fg_color=206 +function __powerline_battery_prompt() { + local color="" battery_status + battery_status="$(battery_percentage 2> /dev/null)" + local -i fg_color=255 + + if [[ -z "${battery_status}" || "${battery_status}" == "-1" || "${battery_status}" == "no" ]]; then + true + else + if [[ "$((10#${battery_status}))" -le 5 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR-"160"}" + elif [[ "$((10#${battery_status}))" -le 25 ]]; then + color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR-"208"}" + else + color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR-"70"}" + fi + ac_adapter_connected && battery_status="${BATTERY_AC_CHAR?}${battery_status}" + echo "${battery_status}%|${color}|${fg_color}" + fi +} + +function __powerline_in_vim_prompt() { + local -i fg_color=206 - echo "$(date +"${THEME_CLOCK_FORMAT}")|${CLOCK_THEME_PROMPT_COLOR}|${fg_color}" + if [[ -n "${VIMRUNTIME:-}" ]]; then + echo "${IN_VIM_THEME_PROMPT_TEXT?}|${IN_VIM_THEME_PROMPT_COLOR?}|${fg_color}" + fi } -function __powerline_battery_prompt { - local color="" - local battery_status="$(battery_percentage 2> /dev/null)" - local fg_color=255 +function __powerline_aws_profile_prompt() { + local -i fg_color=206 - if [[ -z "${battery_status}" ]] || [[ "${battery_status}" = "-1" ]] || [[ "${battery_status}" = "no" ]]; then - true - else - if [[ "$((10#${battery_status}))" -le 5 ]]; then - color="${BATTERY_STATUS_THEME_PROMPT_CRITICAL_COLOR}" - elif [[ "$((10#${battery_status}))" -le 25 ]]; then - color="${BATTERY_STATUS_THEME_PROMPT_LOW_COLOR}" - else - color="${BATTERY_STATUS_THEME_PROMPT_GOOD_COLOR}" - fi - ac_adapter_connected && battery_status="${BATTERY_AC_CHAR}${battery_status}" - echo "${battery_status}%|${color}|${fg_color}" - fi + if [[ -n "${AWS_PROFILE:-}" ]]; then + echo "${AWS_PROFILE_CHAR?}${AWS_PROFILE?}|${AWS_PROFILE_PROMPT_COLOR?}|${fg_color}" + fi } -function __powerline_in_vim_prompt { - local fg_color=206 +function __powerline_in_toolbox_prompt() { + local -i fg_color=206 - if [ -n "$VIMRUNTIME" ]; then - echo "${IN_VIM_THEME_PROMPT_TEXT}|${IN_VIM_THEME_PROMPT_COLOR}|${fg_color}" - fi + if [[ -f /run/.containerenv ]] && [[ -f /run/.toolboxenv ]]; then + echo "${IN_TOOLBOX_THEME_PROMPT_TEXT?}|${IN_TOOLBOX_THEME_PROMPT_COLOR?}|${fg_color}" + fi } -function __powerline_aws_profile_prompt { - local fg_color=206 +function __powerline_shlvl_prompt() { + if [[ "${SHLVL}" -gt 1 ]]; then + local prompt="${SHLVL_THEME_PROMPT_CHAR-"§"}" + local level=$((SHLVL - 1)) + echo "${prompt}${level}|${SHLVL_THEME_PROMPT_COLOR-${HOST_THEME_PROMPT_COLOR-"0"}}" + fi +} - if [[ -n "${AWS_PROFILE}" ]]; then - echo "${AWS_PROFILE_CHAR}${AWS_PROFILE}|${AWS_PROFILE_PROMPT_COLOR}|${fg_color}" - fi +function __powerline_dirstack_prompt() { + if [[ "${#DIRSTACK[@]}" -gt 1 ]]; then + local depth=$((${#DIRSTACK[@]} - 1)) + local prompt="${DIRSTACK_THEME_PROMPT_CHAR-${POWERLINE_DIRSTACK_CHAR-"←"}}" + if [[ "${depth}" -ge 2 ]]; then + prompt+="${depth}" + fi + echo "${prompt}|${DIRSTACK_THEME_PROMPT_COLOR-${POWERLINE_DIRSTACK_COLOR-${CWD_THEME_PROMPT_COLOR-${POWERLINE_CWD_COLOR-"240"}}}}" + fi } -function __powerline_in_toolbox_prompt { - local fg_color=206 +function __powerline_history_number_prompt() { + echo "${HISTORY_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_HISTORY_NUMBER_CHAR-"#"}}\!|${HISTORY_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_HISTORY_NUMBER_COLOR-"0"}}" +} + +function __powerline_command_number_prompt() { + echo "${COMMAND_NUMBER_THEME_PROMPT_CHAR-${POWERLINE_COMMAND_NUMBER_CHAR-"#"}}\#|${COMMAND_NUMBER_THEME_PROMPT_COLOR-${POWERLINE_COMMAND_NUMBER_COLOR-"0"}}" +} - if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then - echo "${IN_TOOLBOX_THEME_PROMPT_TEXT}|${IN_TOOLBOX_THEME_PROMPT_COLOR}|${fg_color}" - fi +function __powerline_duration_prompt() { + local duration + duration=$(_command_duration) + [[ -n "$duration" ]] && echo "${duration}|${COMMAND_DURATION_PROMPT_COLOR?}" } -function __powerline_left_segment { - local OLD_IFS="${IFS}"; IFS="|" - local params=( $1 ) - IFS="${OLD_IFS}" - local separator_char="${POWERLINE_LEFT_SEPARATOR}" - local separator="" - local fg_color=206 +function __powerline_left_segment() { + local -a params + IFS="|" read -ra params <<< "${1}" + local pad_before_segment=" " + local -i fg_color=206 + + #for seperator character + if [[ "${SEGMENTS_AT_LEFT?}" -eq 0 ]]; then + if [[ "${POWERLINE_COMPACT_BEFORE_FIRST_SEGMENT:-0}" -ne 0 ]]; then + pad_before_segment="" + fi + else + if [[ "${POWERLINE_COMPACT_AFTER_SEPARATOR:-0}" -ne 0 ]]; then + pad_before_segment="" + fi + # Since the previous segment wasn't the last segment, add padding, if needed + # + if [[ "${POWERLINE_COMPACT_BEFORE_SEPARATOR:-0}" -eq 0 ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}" + fi + if [[ "${LAST_SEGMENT_COLOR?}" -eq "${params[1]:-}" ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_SEPARATOR_SOFT:- }${normal?}" + else + LEFT_PROMPT+="$(set_color "${LAST_SEGMENT_COLOR?}" "${params[1]:-}")${POWERLINE_LEFT_SEPARATOR:- }${normal?}" + fi + fi + + #change here to cahnge fg color + LEFT_PROMPT+="$(set_color "${params[2]:-}" "${params[1]:-}")${pad_before_segment}${params[0]}${normal?}" + #seperator char color == current bg + LAST_SEGMENT_COLOR="${params[1]:-}" + ((SEGMENTS_AT_LEFT += 1)) +} - #for seperator character - if [[ "${SEGMENTS_AT_LEFT}" -gt 0 ]]; then - separator="$(set_color ${LAST_SEGMENT_COLOR} ${params[1]})${separator_char}${normal}" - fi - #change here to cahnge fg color - LEFT_PROMPT+="${separator}$(set_color ${params[2]} ${params[1]}) ${params[0]} ${normal}" - #seperator char color = current bg - LAST_SEGMENT_COLOR=${params[1]} - (( SEGMENTS_AT_LEFT += 1 )) +function __powerline_left_last_segment_padding() { + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}") ${normal?}" } -function __powerline_last_status_prompt { - [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR}" +function __powerline_last_status_prompt() { + [[ "$1" -ne 0 ]] && echo "${1}|${LAST_STATUS_THEME_PROMPT_COLOR-"52"}" } -function __powerline_prompt_command { - local last_status="$?" ## always the first - local separator_char="${POWERLINE_PROMPT_CHAR}" +function __powerline_prompt_command() { + local last_status="$?" ## always the first + local info prompt_color + + local LEFT_PROMPT="" + local SEGMENTS_AT_LEFT=0 + local LAST_SEGMENT_COLOR="" + + _save-and-reload-history "${HISTORY_AUTOSAVE:-0}" - LEFT_PROMPT="" - SEGMENTS_AT_LEFT=0 - LAST_SEGMENT_COLOR="" + if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO:-}" ]]; then + LEFT_PROMPT+="$(set_color "${PROMPT_DISTRO_LOGO_COLOR?}" "${PROMPT_DISTRO_LOGO_COLORBG?}")${PROMPT_DISTRO_LOGO?}$(set_color - -)" + fi + ## left prompt ## + for segment in ${POWERLINE_PROMPT-"user_info" "scm" "python_venv" "ruby" "node" "cwd"}; do + info="$("__powerline_${segment}_prompt")" + [[ -n "${info}" ]] && __powerline_left_segment "${info}" + done - if [[ -n "${POWERLINE_PROMPT_DISTRO_LOGO}" ]]; then - LEFT_PROMPT+="$(set_color ${PROMPT_DISTRO_LOGO_COLOR} ${PROMPT_DISTRO_LOGO_COLORBG})${PROMPT_DISTRO_LOGO}$(set_color - -)" - fi + [[ "${last_status}" -ne 0 ]] && __powerline_left_segment "$(__powerline_last_status_prompt "${last_status}")" - ## left prompt ## - for segment in $POWERLINE_PROMPT; do - local info="$(__powerline_${segment}_prompt)" - [[ -n "${info}" ]] && __powerline_left_segment "${info}" - done + if [[ -n "${LEFT_PROMPT:-}" ]] && [[ "${POWERLINE_COMPACT_AFTER_LAST_SEGMENT:-0}" -eq 0 ]]; then + __powerline_left_last_segment_padding + fi - [[ "${last_status}" -ne 0 ]] && __powerline_left_segment $(__powerline_last_status_prompt ${last_status}) - [[ -n "${LEFT_PROMPT}" ]] && LEFT_PROMPT+="$(set_color ${LAST_SEGMENT_COLOR} -)${separator_char}${normal}" + # By default we try to match the prompt to the adjacent segment's background color, + # but when part of the prompt exists within that segment, we instead match the foreground color. + prompt_color="$(set_color "${LAST_SEGMENT_COLOR?}" -)" + if [[ -n "${LEFT_PROMPT:-}" ]] && [[ -n "${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR:-}" ]]; then + LEFT_PROMPT+="$(set_color - "${LAST_SEGMENT_COLOR?}")${POWERLINE_LEFT_LAST_SEGMENT_PROMPT_CHAR}" + prompt_color="${normal?}" + fi + [[ -n "${LEFT_PROMPT:-}" ]] && LEFT_PROMPT+="${prompt_color}${POWERLINE_PROMPT_CHAR-\\$}${normal?}" - PS1="${LEFT_PROMPT} " + if [[ "${POWERLINE_COMPACT_PROMPT:-0}" -eq 0 ]]; then + LEFT_PROMPT+=" " + fi - ## cleanup ## - unset LAST_SEGMENT_COLOR \ - LEFT_PROMPT \ - SEGMENTS_AT_LEFT + PS1="${LEFT_PROMPT?}" } diff --git a/uninstall.sh b/uninstall.sh index 1771261060..f1e559bdcf 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -13,6 +13,9 @@ case $OSTYPE in ;; esac +# overriding CONFIG_FILE: +CONFIG_FILE="${BASH_IT_CONFIG_FILE:-"${CONFIG_FILE}"}" + BACKUP_FILE=$CONFIG_FILE.bak if [ ! -e "$HOME/$BACKUP_FILE" ]; then