aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-08-07 11:33:03 +0200
committerEgor Tensin <egor@tensin.name>2026-08-07 11:33:03 +0200
commita8cd8f01a2477852c433306fe75eed358572bb0f (patch)
treef2d2d9dfc26cc0fa181a282ffe381c9d534661f9
parent.bashrc: rename service functions (diff)
downloadlinux-home-a8cd8f01a2477852c433306fe75eed358572bb0f.tar.gz
linux-home-a8cd8f01a2477852c433306fe75eed358572bb0f.zip
bash: dedupe function preludes
-rw-r--r--%HOME%/.bash_utils/cxx.sh10
-rw-r--r--%HOME%/.bash_utils/distr.sh25
-rw-r--r--%HOME%/.bash_utils/file.sh6
-rw-r--r--%HOME%/.bash_utils/git.sh20
-rw-r--r--%HOME%/.bash_utils/net.sh10
-rw-r--r--%HOME%/.bash_utils/path.sh4
-rw-r--r--%HOME%/.bash_utils/text.sh34
-rw-r--r--%HOME%/.bashrc6
8 files changed, 37 insertions, 78 deletions
diff --git a/%HOME%/.bash_utils/cxx.sh b/%HOME%/.bash_utils/cxx.sh
index 13c5176..50371ac 100644
--- a/%HOME%/.bash_utils/cxx.sh
+++ b/%HOME%/.bash_utils/cxx.sh
@@ -24,8 +24,7 @@ _runc_get_absolute_path() {
}
_runc_usage() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
local prefix="${FUNCNAME[0]}"
[ "${#FUNCNAME[@]}" -gt 1 ] && prefix="${FUNCNAME[1]}"
@@ -39,9 +38,7 @@ _runc_usage() (
)
runc() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -a c_flags=(${runc_flags[@]+"${runc_flags[@]}"})
local -a src_files=()
@@ -146,8 +143,7 @@ runc() (
)
runcxx() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
local -a runc_flags=(${runcxx_flags[@]+"${runcxx_flags[@]}"})
BASH_ENV=<( declare -p runc_flags ) \
diff --git a/%HOME%/.bash_utils/distr.sh b/%HOME%/.bash_utils/distr.sh
index 844f6b3..f45bf2c 100644
--- a/%HOME%/.bash_utils/distr.sh
+++ b/%HOME%/.bash_utils/distr.sh
@@ -7,8 +7,7 @@ sums_path='sha1sums.txt'
sums_name="$( basename -- "$sums_path" )"
_sums_unescape_path() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 1 ]; then
echo "usage: ${FUNCNAME[0]} PATH" >&2
@@ -22,8 +21,7 @@ _sums_unescape_path() (
)
sums_list_paths() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
local print_lines=
local print_sums=
@@ -94,9 +92,7 @@ sums_list_paths() (
)
sums_add() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -A existing
local -a missing=()
@@ -116,9 +112,7 @@ sums_add() (
)
sums_add_all() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -a paths
@@ -131,9 +125,7 @@ sums_add_all() (
)
sums_add_distr() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -a paths
local path
@@ -156,16 +148,13 @@ sums_add_distr() (
)
sums_verify() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
sha1sum --check --strict --quiet -- "$sums_path"
)
sums_remove_missing() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local dry_run=
diff --git a/%HOME%/.bash_utils/file.sh b/%HOME%/.bash_utils/file.sh
index 69be5ef..9b239aa 100644
--- a/%HOME%/.bash_utils/file.sh
+++ b/%HOME%/.bash_utils/file.sh
@@ -4,8 +4,7 @@
# Distributed under the MIT License.
swap_files() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} PATH1 PATH2" >&2
@@ -37,8 +36,7 @@ swap_files() (
)
pastebin() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -gt 1 ]; then
echo "usage: ${FUNCNAME[0]} [PATH]" >&2
diff --git a/%HOME%/.bash_utils/git.sh b/%HOME%/.bash_utils/git.sh
index 79e8c80..3542ed6 100644
--- a/%HOME%/.bash_utils/git.sh
+++ b/%HOME%/.bash_utils/git.sh
@@ -4,9 +4,7 @@
# Distributed under the MIT License.
branch_eol_normalized() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local status
status="$( git status --porcelain )"
@@ -47,9 +45,7 @@ branch_eol_normalized() (
)
branch_doslint() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -a paths
@@ -62,9 +58,7 @@ branch_doslint() (
)
branch_lint() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local -a paths
@@ -77,9 +71,7 @@ branch_lint() (
)
git_replace() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB" 1>&2
@@ -93,9 +85,7 @@ git_replace() (
)
git_replace_word() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB" 1>&2
diff --git a/%HOME%/.bash_utils/net.sh b/%HOME%/.bash_utils/net.sh
index 6d4f74b..3cd1d0f 100644
--- a/%HOME%/.bash_utils/net.sh
+++ b/%HOME%/.bash_utils/net.sh
@@ -8,17 +8,11 @@ _curl() {
}
whatsmyip() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
-
+ _bash_func_prelude
_curl "https://ifconfig.co/"
)
whatsmycountry() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
-
+ _bash_func_prelude
_curl "https://ifconfig.co/country"
)
diff --git a/%HOME%/.bash_utils/path.sh b/%HOME%/.bash_utils/path.sh
index 5e4dc58..4acdf20 100644
--- a/%HOME%/.bash_utils/path.sh
+++ b/%HOME%/.bash_utils/path.sh
@@ -4,9 +4,7 @@
# Distributed under the MIT License.
path_add() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local prepend=
diff --git a/%HOME%/.bash_utils/text.sh b/%HOME%/.bash_utils/text.sh
index 6e3bae7..09ab20a 100644
--- a/%HOME%/.bash_utils/text.sh
+++ b/%HOME%/.bash_utils/text.sh
@@ -25,8 +25,7 @@ doslint() {
}
_sed_escape_pattern() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 1 ]; then
echo "usage: ${FUNCNAME[0]} STR" >&2
@@ -49,8 +48,7 @@ _sed_escape_pattern() (
)
_sed_escape_substitution() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 1 ]; then
echo "usage: ${FUNCNAME[0]} STR" >&2
@@ -66,8 +64,7 @@ _sed_escape_substitution() (
)
file_replace() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -lt 3 ]; then
echo "usage: ${FUNCNAME[0]} OLD NEW PATH..." >&2
@@ -85,8 +82,7 @@ file_replace() (
)
file_replace_word() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -lt 3 ]; then
echo "usage: ${FUNCNAME[0]} OLD NEW PATH..." >&2
@@ -104,8 +100,7 @@ file_replace_word() (
)
str_replace() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 3 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB REP" >&2
@@ -122,8 +117,7 @@ str_replace() (
)
_bash_escape_pattern() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 1 ]; then
echo "usage: ${FUNCNAME[0]} STR" >&2
@@ -142,8 +136,7 @@ _bash_escape_pattern() (
)
str_contains() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB" >&2
@@ -160,8 +153,7 @@ str_contains() (
)
str_starts_with() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB" >&2
@@ -178,8 +170,7 @@ str_starts_with() (
)
str_ends_with() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -ne 2 ]; then
echo "usage: ${FUNCNAME[0]} STR SUB" >&2
@@ -196,9 +187,7 @@ str_ends_with() (
)
str_split() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
- shopt -s lastpipe
+ _bash_func_prelude
local fmt='%s\n'
local -a args
@@ -252,8 +241,7 @@ str_split() (
)
str_join() (
- set -o errexit -o nounset -o pipefail
- shopt -s inherit_errexit 2> /dev/null || true
+ _bash_func_prelude
if [ "$#" -lt 1 ]; then
echo "usage: ${FUNCNAME[0]} DELIM [STR]..." >&2
diff --git a/%HOME%/.bashrc b/%HOME%/.bashrc
index fabb862..6041ba7 100644
--- a/%HOME%/.bashrc
+++ b/%HOME%/.bashrc
@@ -27,6 +27,12 @@ export HISTSIZE=20000
# Includes
# -----------------------------------------------------------------------------
+_bash_func_prelude() {
+ set -o errexit -o nounset -o pipefail
+ shopt -s inherit_errexit 2> /dev/null || true
+ shopt -s lastpipe
+}
+
_bash_includes() {
local file
for file in file text cxx distr git net path; do