Skip to content

Commit

Permalink
improve: shrink for statement var scope to local
Browse files Browse the repository at this point in the history
  • Loading branch information
ishbguy committed Nov 18, 2019
1 parent d66209f commit 13e9dc6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions configs/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ if bacon_defined BACON_PROMPT_PS1_LAYOUT && bacon_definedf bacon_promptc; then
brch="${brchi[1]//..*/}"
# check whether the local repo is different from remote tracked repo
[[ -n ${brchi[2]} && ${brchi[*]:2} =~ '[' ]] && brch+="${trki[${brchi[2]#[}]}${brchi[3]%]}"
local c
local tmp=()
for c in "${bstat[@]:1}"; do
# prevent special chars to be expand
Expand Down
1 change: 1 addition & 0 deletions configs/pip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ hash pip &>/dev/null || return 1
bacon_export pip

pip_upgrade() {
local pkg
for pkg in $(pip list --outdate --format legacy | awk '{print $1}'); do
sudo pip install --upgrade "${pkg}"
done
Expand Down
4 changes: 4 additions & 0 deletions lib/bacon-async.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ bacon_async_add() {
bacon_async_del() {
[[ $# == 1 ]] || return 1
local jobs=()
local j
[[ $# == 0 ]] && jobs=("${!BACON_ASYNC_RUN[@]}") || jobs=("$@")
for j in "${jobs[@]}"; do
[[ -n $j && -n ${BACON_ASYNC_RUN[$j]} ]] && unset BACON_ASYNC_RUN["$j"]
Expand Down Expand Up @@ -81,6 +82,7 @@ bacon_async_run() {
bacon_async_start() {
[[ -n $BACON_ASYNC_MQ ]] || bacon_async_mq_init || return 1
local jobs=()
local j
[[ $# == 0 ]] && jobs=("${!BACON_ASYNC_RUN[@]}") || jobs=("$@")
for j in "${jobs[@]}"; do
if [[ -n ${BACON_ASYNC_RUN[$j]} ]]; then
Expand All @@ -91,6 +93,7 @@ bacon_async_start() {

bacon_async_stop() {
local jobs=()
local j
[[ $# == 0 ]] && jobs=("${!BACON_ASYNC_JQ[@]}") || jobs=("$@")
for j in "${jobs[@]}"; do
if [[ -n ${BACON_ASYNC_JQ[$j]} ]] && bacon_is_running "${BACON_ASYNC_JQ[$j]}"; then
Expand All @@ -102,6 +105,7 @@ bacon_async_stop() {

bacon_async_wait() {
local pids=() runs=()
local p
[[ $# == 0 ]] && pids=("${BACON_ASYNC_JQ[@]}") || pids=("$@")
for p in "${pids[@]}"; do
[[ -n $p && $p =~ [0-9]+ ]] && bacon_is_running "$p" && runs+=("$p")
Expand Down
1 change: 1 addition & 0 deletions lib/bacon-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export BACON_MAIN_ABS_DIR="$(dirname "$BACON_MAIN_ABS_SRC")"

bacon_init() {
local BACON_LIB_DIR=("$BACON_MAIN_ABS_DIR")
local c
for c in "$@"; do
bacon_load "${c}.sh" || true
done
Expand Down
1 change: 1 addition & 0 deletions lib/bacon-precmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare -ga BACON_PRECMD_TRAP=()
declare -g BACON_PRECMD_TRAP_SIG="${BACON_PRECMD_TRAP_SIG:-}"

bacon_precmd_handler() {
local cmd
for cmd in "${BACON_PRECMD_TRAP[@]}"; do
eval "$cmd"
done
Expand Down
4 changes: 2 additions & 2 deletions lib/bacon-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ bacon_prompt_location() {

bacon_prompt_counter() {
local -A counters
local str=''
local str='' cnt
for cnt in "${BACON_PROMPT_COUNTERS[@]}"; do
# shellcheck disable=SC2155
local nr="$(eval "$cnt")"
Expand All @@ -57,7 +57,7 @@ bacon_prompt_dollar() {
}

bacon_prompt_ps1() {
ps1=
local ps1 layout
for layout in "${BACON_PROMPT_PS1_LAYOUT[@]}"; do
bacon_definedf "$layout" && ps1+="$($layout)"
done
Expand Down
8 changes: 6 additions & 2 deletions lib/bacon-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bacon_has_map() {
# Assigns the selected set of escape mappings to the given associative array names.
bacon_color_init() {
local -a fg_clrs bg_clrs msc
local x
fg_clrs=(black red green yellow blue magenta cyan grey darkgrey ltred ltgreen ltyellow ltblue ltmagenta ltcyan white)
bg_clrs=($(IFS=,; eval "echo bg_{${fg_clrs[*]}}"))
msc=(sgr0 bold dim smul blink rev invis)
Expand Down Expand Up @@ -53,7 +54,7 @@ bacon_color_init() {
bacon_color_init --setaf BACON_COLOR --setab BACON_COLOR --misc BACON_COLOR

bacon_set_color() {
local color
local color c
for c in "$@"; do
bacon_has_map BACON_COLOR "$c" && color+="${BACON_COLOR[$c]}"
done
Expand Down Expand Up @@ -255,7 +256,7 @@ bacon_popts() {
shift 4
local -a soa=() loa=()
local -A som=() lom=()
local sos los tmp m n
local sos los tmp o m n

# construct optstrings
for o in "${!__optstr[@]}"; do
Expand Down Expand Up @@ -311,6 +312,7 @@ bacon_require_base() {
local cmd="$1"
local msg="$2"
shift 2
local obj
for obj in "$@"; do
"$cmd" "$obj" || miss+=("$obj")
done
Expand Down Expand Up @@ -417,6 +419,7 @@ bacon_filter() {
local -n __array="$1"
local p="$2"
shift 2
local arg
for arg in "$@"; do
[[ $arg =~ $p ]] && __array+=("$arg") || true
done
Expand All @@ -431,6 +434,7 @@ bacon_map() {
local -n __array="$1"
local func="$2"
shift 2
local i
__array+=("$@")
for i in "${__array[@]}"; do
"$func" "__array[$i]"
Expand Down

0 comments on commit 13e9dc6

Please sign in to comment.