aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-22 15:36:33 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-22 17:27:13 +0200
commitb1b76d058a5a30a8e02a7c5d5d5134e189bf62cf (patch)
treea4c6c911fa93cdccf3f90360efee51d2cc11362c /scripts
parent526dc2bdb22e66457785fc112c531031bc1584fa (diff)
downloadman-pages-b1b76d058a5a30a8e02a7c5d5d5134e189bf62cf.tar.gz
bash_aliases: srcfix
SC2034 (warning): EX_OK appears unused. SC2035 (info): Use ./*glob* or -- *glob* so names with dashes won't become options. SC2068 (error): Double quote array expansions to avoid re-splitting elements. SC2086 (info): Double quote to prevent globbing and word splitting. SC2112 (warning): 'function' keyword is non-standard. Delete it. SC2124 (warning): Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. SC3001 (warning): In POSIX sh, process substitution is undefined. SC3006 (warning): In POSIX sh, standalone ((..)) is undefined. Also, remove unnecessary braces, and update copyright. Reported-by: shellcheck(1) Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bash_aliases100
1 files changed, 49 insertions, 51 deletions
diff --git a/scripts/bash_aliases b/scripts/bash_aliases
index a9608e3598..32d0138373 100644
--- a/scripts/bash_aliases
+++ b/scripts/bash_aliases
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
########################################################################
#
-# (C) Copyright 2020, 2021, Alejandro Colomar
+# (C) Copyright 2020-2022, Alejandro Colomar
# These functions are free software; you can redistribute them and/or
# modify them under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2.
@@ -17,7 +17,6 @@
########################################################################
# Exit status
-EX_OK=0;
EX_USAGE=64;
########################################################################
@@ -28,7 +27,7 @@ EX_USAGE=64;
# nor mixed or embedded //... and /*...*/ comments.
# Use as a filter (see man_lsfunc() in this file).
-function sed_rm_ccomments()
+sed_rm_ccomments()
{
sed 's%/\*.*\*/%%' \
|sed -E '\%/\*%,\%\*/%{\%(\*/|/\*)%!d; s%/\*.*%%; s%.*\*/%%;}' \
@@ -45,25 +44,25 @@ function sed_rm_ccomments()
#
# See also: grepc(1)
-function grep_syscall()
+grep_syscall()
{
- if (($# != 1)); then
+ if [ $# -ne 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
- find * -type f \
+ find ./* -type f \
|grep '\.c$' \
- |xargs grep -l "${1}" \
+ |xargs grep -l "$1" \
|sort \
- |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1}\b.*?\)" \
+ |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\($1\b.*?\)" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
- find * -type f \
+ find ./* -type f \
|grep '\.[ch]$' \
- |xargs grep -l "${1}" \
+ |xargs grep -l "$1" \
|sort \
- |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_${1}\s*\(.*?\)" \
+ |xargs pcregrep -Mn "(?s)^asmlinkage\s+[\w\s]+\**sys_$1\s*\(.*?\)" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
}
@@ -74,18 +73,18 @@ function grep_syscall()
#
# See also: grepc(1)
-function grep_syscall_def()
+grep_syscall_def()
{
- if (($# != 1)); then
+ if [ $# -ne 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <syscall>";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
- find * -type f \
+ find ./* -type f \
|grep '\.c$' \
- |xargs grep -l "${1}" \
+ |xargs grep -l "$1" \
|sort \
- |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\(${1}\b.*?^}" \
+ |xargs pcregrep -Mn "(?s)^\w*SYSCALL_DEFINE.\($1\b.*?^}" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
}
@@ -96,31 +95,30 @@ function grep_syscall_def()
# ...) of all manual pages in a directory (or in a single manual page file).
# Usage example: .../man-pages$ man_section man2 SYNOPSIS 'CONFORMING TO';
-function man_section()
+man_section()
{
- if (($# < 2)); then
+ if [ $# -lt 2 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <dir> <section>...";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
local page="$1";
shift;
- local sect="$@";
+ local sect="$*";
- find "${page}" -type f \
+ find "$page" -type f \
|xargs wc -l \
|grep -v -e '\b1 ' -e '\btotal\b' \
|awk '{ print $2 }' \
|sort \
|while read -r manpage; do
- cat \
- <(<${manpage} sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}') \
- <(for s in ${sect}; do
- <${manpage} \
+ (sed -n '/^\.TH/,/^\.SH/{/^\.SH/!p}' <"$manpage";
+ for s in $sect; do
+ <"$manpage" \
sed -n \
- -e "/^\.SH ${s}/p" \
- -e "/^\.SH ${s}/,/^\.SH/{/^\.SH/!p}"; \
- done;) \
+ -e "/^\.SH $s/p" \
+ -e "/^\.SH $s/,/^\.SH/{/^\.SH/!p}";
+ done;) \
|man -P cat -l - 2>/dev/null;
done;
}
@@ -130,15 +128,15 @@ function man_section()
# Each name is printed in a separate line
# Usage example: .../man-pages$ man_lsfunc man2;
-function man_lsfunc()
+man_lsfunc()
{
- if (($# < 1)); then
+ if [ $# -lt 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
for arg in "$@"; do
- man_section "${arg}" 'SYNOPSIS';
+ man_section "$arg" 'SYNOPSIS';
done \
|sed_rm_ccomments \
|pcregrep -Mn '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]*?(...)?\s*\); *$' \
@@ -153,15 +151,15 @@ function man_lsfunc()
# Each name is printed in a separate line
# Usage example: .../man-pages$ man_lsvar man3;
-function man_lsvar()
+man_lsvar()
{
- if (($# < 1)); then
+ if [ $# -lt 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <manpage|manNdir>...";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
for arg in "$@"; do
- man_section "${arg}" 'SYNOPSIS';
+ man_section "$arg" 'SYNOPSIS';
done \
|sed_rm_ccomments \
|pcregrep -Mv '(?s)^ [\w ]+ \**\w+\([\w\s(,)[\]*]+?(...)?\s*\); *$' \
@@ -178,26 +176,26 @@ function man_lsvar()
# pdfman() renders a manual page in PDF
# Usage example: .../man-pages$ pdfman man2/membarrier.2;
-function pdfman()
+pdfman()
{
- if (($# == 0)); then
+ if [ $# -eq 0 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} [man(1) options] [section] page";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi;
local tmp="$(mktemp -t "${!###*/}.XXXXXX")";
- man -Tps $@ \
+ man -Tps "$@" \
|ps2pdf - - \
- >${tmp};
- xdg-open ${tmp};
+ >"$tmp";
+ xdg-open "$tmp";
}
# man_gitstaged prints a list of all files with changes staged for commit
# (basename only if the files are within <man?/>), separated by ", ".
# Usage example: .../man-pages$ git commit -m "$(man_gitstaged): msg";
-function man_gitstaged()
+man_gitstaged()
{
git diff --staged --name-only \
|sed "s/$/, /" \
@@ -216,18 +214,18 @@ function man_gitstaged()
#
# See also: grepc(1)
-function grep_glibc_prototype()
+grep_glibc_prototype()
{
- if (($# != 1)); then
+ if [ $# -ne 1 ]; then
>&2 echo "Usage: ${FUNCNAME[0]} <func>";
- return ${EX_USAGE};
+ return $EX_USAGE;
fi
- find * -type f \
+ find ./* -type f \
|grep '\.h$' \
- |xargs grep -l "${1}" \
+ |xargs grep -l "$1" \
|sort \
|xargs pcregrep -Mn \
- "(?s)^[\w[][\w\s(,)[:\]]+\s+\**${1}\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" \
+ "(?s)^[\w[][\w\s(,)[:\]]+\s+\**$1\s*\([\w\s(,)[\]*]+?(...)?\)[\w\s(,)[:\]]*;" \
|sed -E 's/^[^:]+:[0-9]+:/&\n/';
}