Skip to content

Commit 70d0f08

Browse files
committed
Revert "Merge pull request #63 from HS-Teams/codex/replace-read-calls-with-__hhs_read-and-__hhs_read_array"
This reverts commit c3fc98e, reversing changes made to 34dce8e.
1 parent c3fc98e commit 70d0f08

File tree

12 files changed

+37
-37
lines changed

12 files changed

+37
-37
lines changed

bin/hhs-functions/bash/classic/hhs-mchoose.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function __hhs_classic_mchoose() {
102102
# } Menu Renderization
103103

104104
# Navigation input {
105-
IFS= __hhs_read -rsn 1 keypress
105+
IFS= read -rsn 1 keypress
106106
case "${keypress}" in
107107
[[:space:]]) # Mark option
108108
if [[ ${all_checks[cur_index]} -eq 0 ]]; then
@@ -127,7 +127,7 @@ function __hhs_classic_mchoose() {
127127
typed_index="${keypress}"
128128
echo -en "${keypress}" && index_len=1
129129
while [[ ${#typed_index} -lt ${#len} ]]; do
130-
IFS= __hhs_read -rsn1 num_press
130+
IFS= read -rsn1 num_press
131131
[[ -z "${num_press}" ]] && break
132132
[[ ! "${num_press}" =~ ^[0-9]*$ ]] && unset typed_index && break
133133
typed_index="${typed_index}${num_press}"
@@ -142,7 +142,7 @@ function __hhs_classic_mchoose() {
142142
fi
143143
;;
144144
$'\033') # Handle escape '\e[nX' codes
145-
IFS= __hhs_read -rsn2 -t 1 keypress
145+
IFS= read -rsn2 -t 1 keypress
146146
case "${keypress}" in
147147
[A) # Cursor up
148148
if [[ ${cur_index} -eq ${show_from} ]] && [[ ${show_from} -gt 0 ]]; then

bin/hhs-functions/bash/classic/hhs-mselect.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ function __hhs_classic_mselect() {
8181
# } Menu Renderization
8282

8383
# Navigation input {
84-
IFS= __hhs_read -rsn 1 keypress
84+
IFS= read -rsn 1 keypress
8585
case "${keypress}" in
8686
[[:digit:]]) # An index was typed
8787
typed_index="${keypress}"
8888
echo -en "${keypress}" && index_len=1
8989
while [[ ${#typed_index} -lt ${#len} ]]; do
90-
__hhs_read -rs -n 1 numpress
90+
read -rs -n 1 numpress
9191
[[ -z "${numpress}" ]] && break
9292
[[ ! "${numpress}" =~ ^[0-9]*$ ]] && unset typed_index && break
9393
typed_index="${typed_index}${numpress}"
@@ -102,7 +102,7 @@ function __hhs_classic_mselect() {
102102
fi
103103
;;
104104
$'\033') # Handle escape '\e[nX' codes
105-
IFS= __hhs_read -rsn2 -t 1 keypress
105+
IFS= read -rsn2 -t 1 keypress
106106
case "${keypress}" in
107107
[A) # Cursor up
108108
if [[ $sel_index -eq $show_from && $show_from -gt 0 ]]; then

bin/hhs-functions/bash/hhs-aliases.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function __hhs_aliases() {
7070
alias_expr="${alias_expr//$'\n'/ }"
7171

7272
if [[ -z "${alias_expr}" || "$1" == '-l' || "$1" == "--list" ]]; then
73-
__hhs_read_array all_aliases < <(grep -i -v '^#' "${HHS_ALIASES_FILE}")
73+
while IFS= read -r line; do all_aliases+=("$line"); done < <(grep -i -v '^#' "${HHS_ALIASES_FILE}")
7474
IFS="${OLDIFS}"
7575
if [[ ${#all_aliases[@]} -gt 0 ]]; then
7676
pad=$(printf '%0.1s' "."{1..60})

bin/hhs-functions/bash/hhs-built-ins.bash

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function __hhs_about() {
9898
[[ ${recurse} -eq 0 ]] && echo ''
9999
cmd=${1}
100100
IFS=$'\n'
101-
__hhs_read_array type_ret < <(type "${cmd}" 2> /dev/null)
101+
read -r -d '' -a type_ret < <(type "${cmd}" 2> /dev/null)
102102
IFS="${OLDIFS}"
103103
if [[ ${#type_ret[@]} -gt 0 ]]; then
104104
if [[ ${type_ret[0]} =~ ${re_alias} ]]; then
@@ -224,7 +224,7 @@ function __hhs_envs() {
224224
OLDIFS="$IFS"
225225
IFS=$'\n'
226226
\shopt -s nocasematch
227-
env | sort | while IFS= __hhs_read -r env_var; do
227+
env | sort | while IFS= read -r env_var; do
228228
if [[ $env_var =~ ^([a-zA-Z0-9_]+)=(.*) ]]; then
229229
name=${BASH_REMATCH[1]}
230230
value=${BASH_REMATCH[2]}
@@ -315,7 +315,7 @@ function __hhs_repeat() {
315315

316316
hist_lines=$(history | tail -n "$((count + 1))" | head -n "${count}")
317317
cmd_index=0
318-
echo "${hist_lines}" | while IFS= __hhs_read -r line; do
318+
echo "${hist_lines}" | while IFS= read -r line; do
319319
cmd=$(printf '%s\n' "${line}" | sed -E 's/^[[:space:]]*[0-9]+[[:space:]]+\[[^]]+\][[:space:]]+//')
320320
[[ "${cmd}" == "${FUNCNAME[0]}"* ]] && continue
321321
echo -e "${BLUE}Executing [${cmd_index}] -> ${cmd}${NC}"

bin/hhs-functions/bash/hhs-command.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function __hhs_command() {
3838
echo ' MSelect default : When no arguments is provided, a menu with options will be displayed.'
3939
else
4040

41-
__hhs_read_array all_cmds < "${HHS_CMD_FILE}"
41+
while IFS= read -r line; do all_cmds+=("$line"); done < "${HHS_CMD_FILE}"
4242
IFS="${OLDIFS}"
4343

4444
case "$1" in

bin/hhs-functions/bash/hhs-dirs.bash

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ function __hhs_dirs() {
129129

130130
# Load saved directories from file
131131
[[ -f "${HHS_DIRS_FILE}" ]] && {
132-
while IFS= __hhs_read -r line; do [[ -d "${line}" ]] && results+=("${line}"); done < "${HHS_DIRS_FILE}"
132+
while IFS= read -r line; do [[ -d "${line}" ]] && results+=("${line}"); done < "${HHS_DIRS_FILE}"
133133
}
134134

135135
# Append current shell dirs stack
136-
while IFS= __hhs_read -r line; do [[ -d "${line}" ]] && results+=("${line}"); done < <(dirs -p -l)
136+
while IFS= read -r line; do [[ -d "${line}" ]] && results+=("${line}"); done < <(dirs -p -l)
137137

138138
# Deduplicate and sort
139-
__hhs_read_array all_dirs < <(printf "%s\n" "${results[@]}" | sort -u)
139+
while IFS= read -r line; do all_dirs+=("$line"); done < <(printf "%s\n" "${results[@]}" | sort -u)
140140
len=${#all_dirs[@]}
141141

142142
if [[ "$1" == "-l" ]]; then
@@ -254,7 +254,7 @@ function __hhs_save_dir() {
254254
ret_val=0
255255
fi
256256
elif [[ "$1" == "-c" ]]; then
257-
__hhs_read_array all_dirs < "${HHS_SAVED_DIRS_FILE}"
257+
while IFS= read -r l; do all_dirs+=("$l"); done < "${HHS_SAVED_DIRS_FILE}"
258258
for idx in $(seq 1 "${#all_dirs[@]}"); do
259259
dir=${all_dirs[idx - 1]}
260260
dir_alias=${dir%%=*}
@@ -275,7 +275,7 @@ function __hhs_save_dir() {
275275
else
276276
# Remove the old saved directory aliased
277277
ised -e "s#(^${dir_alias}=.*)*##g" -e '/^\s*$/d' "${HHS_SAVED_DIRS_FILE}"
278-
__hhs_read_array all_dirs < "${HHS_SAVED_DIRS_FILE}"
278+
while IFS= read -r l; do all_dirs+=("$l"); done < "${HHS_SAVED_DIRS_FILE}"
279279
all_dirs+=("${dir_alias}=${dir}")
280280
printf "%s\n" "${all_dirs[@]}" > "${HHS_SAVED_DIRS_FILE}"
281281
sort -u "${HHS_SAVED_DIRS_FILE}" -o "${HHS_SAVED_DIRS_FILE}"
@@ -311,7 +311,7 @@ function __hhs_load_dir() {
311311
echo ' MSelect default : If no arguments is provided, a menu with options will be displayed.'
312312
else
313313

314-
__hhs_read_array all_dirs < "${HHS_SAVED_DIRS_FILE}"
314+
while IFS= read -r l; do all_dirs+=("$l"); done < "${HHS_SAVED_DIRS_FILE}"
315315

316316
if [ ${#all_dirs[@]} -ne 0 ]; then
317317

@@ -408,7 +408,7 @@ function __hhs_godir() {
408408
fi
409409
search_name="$(basename "${2:-$1}")"
410410
pushd "${search_path%/}" &> /dev/null || echo
411-
__hhs_read_array found_dirs < <(find -L . -type d -iname "*""${search_name}" 2> /dev/null)
411+
while IFS= read -r l; do found_dirs+=("$l"); done < <(find -L . -type d -iname "*""${search_name}" 2> /dev/null)
412412
popd &> /dev/null || echo
413413
len=${#found_dirs[@]}
414414
# If no directory is found under the specified name

bin/hhs-functions/bash/hhs-files.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function __hhs_del_tree() {
108108
if [[ -n "${all}" ]]; then
109109
if [[ "${dry_run}" == 'N' || "${dry_run}" == 'I' ]]; then
110110
for next in ${all}; do
111-
[[ "${dry_run}" == 'I' ]] && __hhs_read -r -n 1 -p "Delete ${next} y/[n]? " ans && echo ''
111+
[[ "${dry_run}" == 'I' ]] && read -r -n 1 -p "Delete ${next} y/[n]? " ans && echo ''
112112
[[ "${dry_run}" == 'I' ]] || ans='Y'
113113
if [[ "${ans}" == 'y' || "${ans}" == 'Y' ]]; then
114114
trash_dest="${next##*/}"

bin/hhs-functions/bash/hhs-network.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if __hhs_has ifconfig; then
2525
return 1
2626
fi
2727

28-
IFS=$'\n' __hhs_read_array all_ifaces < <(ifconfig -a | grep '^[a-z0-9]*: ')
28+
IFS=$'\n' read -r -d '' -a all_ifaces < <(ifconfig -a | grep '^[a-z0-9]*: ')
2929
IFS="${OLDIFS}"
3030

3131
if [[ ${#all_ifaces[@]} == 0 ]]; then
@@ -90,7 +90,7 @@ if __hhs_has ifconfig; then
9090
fi
9191
if_name='all|vpn|local|(lo|eth|en|wl|utun|tun)[a-z0-9]+'
9292
if [[ ${ip_kind} =~ ${if_name} ]]; then
93-
__hhs_read_array if_list < <(__hhs_active_ifaces -flat 2>/dev/null)
93+
read -r -d '' -a if_list < <(__hhs_active_ifaces -flat 2>/dev/null)
9494
[[ "vpn" == "${ip_kind}" ]] && if_prefix='(utun|tun)[a-z0-9]+'
9595
[[ "local" == "${ip_kind}" ]] && if_prefix='(eth|en|wl)[a-z0-9]+'
9696
[[ -z "${if_prefix}" ]] && if_prefix="${ip_kind}"

bin/hhs-functions/bash/hhs-shell-utils.bash

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function __hhs_hist_stats() {
7676
echo "${YELLOW}Top ${top_n} used commands in history:${NC}"
7777
echo ''
7878

79-
while __hhs_read -r cmd_qty cmd_name; do
79+
while read -r cmd_qty cmd_name; do
8080
[[ -z "${cmd_qty}" || -z "${cmd_name}" ]] && continue
8181

8282
bar_len=$(((cmd_qty * width) / max_size))
@@ -162,7 +162,7 @@ function __hhs_shell_select() {
162162
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
163163
echo "usage: ${FUNCNAME[0]} "
164164
else
165-
__hhs_read_array avail_shells <<<"$(grep '/.*' '/etc/shells')"
165+
read -d '' -r -a avail_shells <<<"$(grep '/.*' '/etc/shells')"
166166
if __hhs_has brew; then
167167
echo "${BLUE}Checking: HomeBrew's shells...${NC}"
168168
for next_sh in "${avail_shells[@]}"; do
@@ -219,7 +219,7 @@ function __hhs_shopt() {
219219
echo ' Notes:'
220220
echo ' If no option is provided, then, display all set & unset options.'
221221
elif [[ ${#} -eq 0 || ${enable} =~ on|off|-p ]]; then
222-
IFS=$'\n' __hhs_read_array shell_options < <(\shopt | awk '{print $1"="$2}')
222+
IFS=$'\n' read -r -d '' -a shell_options < <(\shopt | awk '{print $1"="$2}')
223223
IFS="${OLDIFS}"
224224
echo ' '
225225
echo "${YELLOW}Available shell ${enable:-on and off} options (${#shell_options[@]}):"
@@ -236,7 +236,7 @@ function __hhs_shopt() {
236236
elif [[ ${#} -ge 1 && ${enable} =~ -(s|u) ]]; then
237237
[[ -z "${option}" ]] && return 1
238238
if \shopt "${enable}" "${option}"; then
239-
__hhs_read -r option enable < <(\shopt "${option}" | awk '{print $1, $2}')
239+
read -r option enable < <(\shopt "${option}" | awk '{print $1, $2}')
240240
[[ 'off' == "${enable}" ]] && color="${RED}"
241241
__hhs_toml_set "${HHS_SHOPTS_FILE}" "${option}=${enable}" && {
242242
echo -e "${WHITE}Shell option ${CYAN}${option}${WHITE} set to ${color:-${GREEN}}${enable} ${NC}"
@@ -310,7 +310,7 @@ function __hhs_du() {
310310
echo "${YELLOW}Top ${top_n} disk usage at: ${BLUE}\"${dir//\./$(pwd)}\"${NC}"
311311
echo ''
312312

313-
while __hhs_read -r size_human path; do
313+
while read -r size_human path; do
314314
[[ -z "${size_human}" || -z "${path}" ]] && continue
315315

316316
# Convert to KiB for scaling

bin/hhs-functions/bash/hhs-sys-utils.bash

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function __hhs_sysinfo() {
6161

6262
OLDIFS=$IFS
6363
IFS=$'\n'
64-
__hhs_read_array all_users < <(who -H)
64+
while IFS= read -r line; do all_users+=("$line"); done < <(who -H)
6565
if [[ ${#all_users[@]} -gt 0 ]]; then
6666
echo -e "\n${GREEN}Currently Logged in Users:${WHITE}"
6767
for next in "${all_users[@]}"; do
@@ -82,7 +82,7 @@ function __hhs_sysinfo() {
8282
if __hhs_has docker && __hhs_has __hhs_docker_ps; then
8383
OLDIFS=$IFS
8484
IFS=$'\n'
85-
__hhs_read_array containers < <(__hhs_docker_ps -a && printf '\0')
85+
read -r -d '' -a containers < <(__hhs_docker_ps -a && printf '\0')
8686
if [[ ${#containers[@]} -gt 0 && $(__hhs_docker_count) -ge 1 ]]; then
8787
echo -e "\n${GREEN}Online Docker Containers:${WHITE}"
8888
for next in "${containers[@]}"; do
@@ -141,7 +141,7 @@ function __hhs_process_list() {
141141
done
142142

143143
IFS=$'\n'
144-
__hhs_read_array all_pids < <(ps -axco uid,pid,ppid,comm | grep ${gflags} "${1:-.}")
144+
while IFS= read -r line; do all_pids+=("$line"); done < <(ps -axco uid,pid,ppid,comm | grep ${gflags} "${1:-.}")
145145
IFS="${OLDIFS}"
146146

147147
if [[ ${#all_pids[@]} -gt 0 ]]; then
@@ -230,7 +230,7 @@ function __hhs_partitions() {
230230
return 1
231231
else
232232
IFS=$'\n'
233-
__hhs_read_array all_parts < <(df -H | tail -n +2)
233+
while IFS= read -r line; do all_parts+=("$line"); done < <(df -H | tail -n +2)
234234
IFS="${OLDIFS}"
235235
echo "${WHITE}"
236236
printf '%-4s\t%-5s\t%-4s\t%-8s\t%-s\n' 'Size' 'Avail' 'Used' 'Capacity' 'Mounted-ON'
@@ -260,7 +260,7 @@ function __hhs_os_info() {
260260
IFS=$'\n'
261261
code_name=$(__hhs_get_codename)
262262
if [[ "${HHS_MY_OS}" == "Darwin" ]]; then
263-
__hhs_read_array os_info < <(sw_vers | awk '{print $2}')
263+
while IFS= read -r line; do os_info+=("$line"); done < <(sw_vers | awk '{print $2}')
264264
echo "${HHS_HIGHLIGHT_COLOR} Type: ${WHITE}Darwin"
265265
echo "${HHS_HIGHLIGHT_COLOR} Name: ${WHITE}${os_info[0]}"
266266
echo "${HHS_HIGHLIGHT_COLOR} Version: ${WHITE}${os_info[1]}"

0 commit comments

Comments
 (0)