Практическое написание сценариев командной оболочки Bash/Код-сниппеты: различия между версиями

Перейти к навигации Перейти к поиску
fi
__settings[col_set]=${__settings[col_set]#?}
if [[ -n ${__settings['hidesorting-headeroptions']} == 'no' ]]; then
local sorter="sort ${__settings['sorting-options']} -k ${__settings['sorting-column']}"
while read -d ';' || [[ -n $REPLY ]]; do
wdth=$(echo -n "$REPLY" | grep -oE "w:[[:digit:]]+" | grep -oE "[[:digit:]]+")
wdth=${wdth:-${__settings['default-column-width']}}
[[ $wdth -ge ${#__titles[$counter]} ]] || wdth=${#__titles[$counter]}
align=$(echo -n "$REPLY" | grep -oE "t:[rlc]" | grep -oE "[rlc]")
if [[ $align == r ]]; then
align='--right'
elif [[ $align == c ]]; then
align='--center'
else
align='--left'
fi
if [[ $counter -eq 0 ]]; then
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_field_drawer $wdth "${__titles[$counter]}" ${align})"
else
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_field_drawer $wdth "${__titles[$counter]}" ${align})"
fi
: $((counter++))
done <<<"${__settings[col_set]}"
if [[ ${__settings['underline-titles']} != 'no' && -n ${__settings['underline-titles-char']} ]]; then
counter=0
echo
while read -d ';' || [[ -n $REPLY ]]; do
wdth=$(echo -n "$REPLY" | grep -oE "w:[[:digit:]]+" | grep -oE "[[:digit:]]+")
wdth=${wdth:-${__settings['default-column-width']}}
[[ $wdth -ge ${#__titles[$counter]} ]] || wdth=${#__titles[$counter]}
align='--left'
if [[ $((counter++)) -eq 0 ]]; then
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_line_drawer "${__settings['underline-titles-char']}" $wdth)"
else
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_line_drawer "${__settings['underline-titles-char']}" $wdth)"
fi
done <<<"${__settings[col_set]}"
fi
fi
local lineprogram
[[ ${__settings['hide-header']} == 'no' ]] && program="${program} header"
[[ (${__settings['underline-titles']} != 'no' && ${__settings['hide-header']} == 'no') && -n ${__settings['underline-titles-char']} ]] && program="${program} nline underlines"
[[ -n $sorter ]] && program="${program} sorted_lines" || program="${program} lines"
local -a arr_col_set
counter=0
while read -d ';' || [[ -n $REPLY ]]; do
arr_col_set[$((counter++))]=$REPLY
done <<<"${__settings[col_set]}"
local line element column
counter=0
for element in $program; do
if [[ -n ${__settings['sorting-options']} ]]; then
counter=0
local sorter="sort ${__settings['sorting-options']} -k ${__settings['sorting-column']}"
if [[ $element =~ (header|underlines) ]]; then
fi
for column in "${arr_col_set[@]}"; do
if [[ -n $sorter ]]; then
while IFS= read -r line <&4 || [[ wdth=$(echo -n "$linecolumn" | grep -oE "w:[[:digit:]];+" do| grep -oE "[[:digit:]]+")
counter=0
local tail="$line"
while
IFS="${__settings['default-data-delim']:-$IFS}"
read -r line tail <<<"$tail"
[[ -n $line ]]
do
(($counter != 0)) || echo
wdth=$(echo -n "${arr_col_set[$counter]}" | grep -oE "w:[[:digit:]]+" | grep -oE "[[:digit:]]+")
wdth=${wdth:-${__settings['default-column-width']}}
align=[[ $(echowdth -nge "${arr_col_set#__titles[$counter]}" | grep -oE "a:[rlc]"] || grep -oE "wdth=${#__titles[rlc$counter]")}
align=$(echo -n "$column" | grep -oE "t:[rlc]" | grep -oE "[rlc]")
if [[ $align == r ]]; then
align='--right'
else
align='--left'
fi
line=${line#"${line%%[![:space:]]*}"}
line=${line%"${line##*[![:space:]]}"}
if [[ ${__settings['crop-to-width']} == 'yes' ]]; then
line=${line:0:$wdth}
fi
if [[ $counter -eq 0 ]]; then
[[ $element == 'header' ]] &&
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_field_drawer $wdth "${__titles[$counter]}" ${align})" ||
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_line_drawer "${__settings['underline-titles-char']}" $wdth)"
else
[[ $element == 'header' ]] &&
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_field_drawer $wdth "${__titles[$counter]}" ${align})" ||
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_line_drawer "${__settings['underline-titles-char']}" $wdth)"
fi
: $((counter++))
(($counter > ${#__titles[@]} - 1)) && {
counter=0
}
done
elif [[ $element == 'sorted_lines' ]]; then
done 4<&0 | $sorter
while IFS= read -r line <&4 || [[ -n $line ]]; do
else
while IFS= read -r line <&4 || [[ -nlocal tail="$line ]]; do"
counter=0 while
local tail IFS="$line{__settings['default-data-delim']:-$IFS}"
while read -r line tail <<<"$tail"
IFS="${__settings ['default[ -data-delim'n $line ]]:-$IFS}"
read -r line tail <<<"$tail"do
[[ -n (($linecounter != 0)) || ]]echo
wdth=$(echo -n "${arr_col_set[$counter]}" | grep -oE "w:[[:digit:]]+" | grep -oE "[[:digit:]]+")
do
(($counter != 0)) || echowdth=${wdth:-${__settings['default-column-width']}}
wdth align=$(echo -n "${arr_col_set[$counter]}" | grep -oE "wa:[[:digit:rlc]]+" | grep -oE "[[:digit:]rlc]+")
wdth=${wdth:-${__settings if ['default-column-width'[ $align == r ]]}}; then
align=$(echo -n "${arr_col_set[$counter]}" | grep -oE "a:[rlc]" | grep align='-oE "[rlc]")-right'
if elif [[ $align == rc ]]; then
align='--rightcenter'
elif [[ $align == c ]]; thenelse
align='--centerleft'
else fi
alignline='--left'${line#"${line%%[![:space:]]*}"}
fi line=${line%"${line##*[![:space:]]}"}
line= if [[ ${line#"${line%%__settings[![:space:'crop-to-width']]*}"} == 'yes' ]]; then
line=${line%"${line##*[![:space0:]]}"$wdth}
if [[ ${__settings['crop-to-width']} == 'yes' ]]; thenfi
line=if [[ ${line:counter -eq 0:$wdth} ]]; then
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
fi
if [[ $counter -eq 0 ]]; thenelse
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-leftwidth-between-margincolumns']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
else fi
: $((counter++))
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
fi (($counter > ${#__titles[@]} - 1)) && {
: $(( counter++))=0
(($counter > ${#__titles[@]} - 1)) && {}
counter=0done
done 4<&0 | }$sorter
elif [[ $element == done'lines' ]]; then
while IFS= read -r line <&4 || [[ -n $line ]]; do
done 4<&0
echo local tail="$line"
while
fi
IFS="${__settings['default-data-delim']:-$IFS}"
read -r line tail <<<"$tail"
[[ -n $line ]]
do
(($counter != 0)) || echo
wdth=$(echo -n "${arr_col_set[$counter]}" | grep -oE "w:[[:digit:]]+" | grep -oE "[[:digit:]]+")
wdth=${wdth:-${__settings['default-column-width']}}
align=$(echo -n "${arr_col_set[$counter]}" | grep -oE "a:[rlc]" | grep -oE "[rlc]")
if [[ $align == r ]]; then
align='--right'
elif [[ $align == c ]]; then
align='--center'
else
align='--left'
fi
line=${line#"${line%%[![:space:]]*}"}
line=${line%"${line##*[![:space:]]}"}
if [[ ${__settings['crop-to-width']} == 'yes' ]]; then
line=${line:0:$wdth}
fi
if [[ $counter -eq 0 ]]; then
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-left-margin']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
else
printf "%s%s" "$(__helper_line_drawer ' ' ${__settings['default-width-between-columns']})" "$(__helper_field_drawer $wdth "${line}" ${align})"
fi
: $((counter++))
(($counter > ${#__titles[@]} - 1)) && {
counter=0
}
done
done 4<&0
echo
elif [[ $element == 'nline' ]]; then
echo
fi
done
return 0
}
</source>
Анонимный участник

Навигация