Skip to content

Commit

Permalink
more linting and fixes re regexp, deno, unziptar
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Sep 15, 2024
1 parent 0e02dc9 commit 7c7265d
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 8 deletions.
14 changes: 12 additions & 2 deletions commands.beta/get-codec
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ function get_codec_test() (
ogg_media_file="$(fs-temp --directory='get-codec' --file --extension='ogg')"
down --url="$ogg_media_url" --filepath="$ogg_media_file"

eval-tester --name='ogg vorbis file is ogg vorbis' --stdout='vorbis' \
-- get-codec --path="$ogg_media_file"
if command-exists -- ffprobe; then
eval-tester --name='ogg vorbis file is ogg vorbis' --stdout='vorbis' \
-- get-codec --path="$ogg_media_file"
else
eval-tester --name='ogg vorbis file is ogg vorbis' --status=6 \
-- get-codec --path="$ogg_media_file"
fi

echo-style --g1="TEST: $0"
return 0
Expand Down Expand Up @@ -64,6 +69,11 @@ function get_codec() (
# =====================================
# Action

if ! command-exists -- ffprobe; then
echo-error 'ffprobe is required for this command.'
return 6 # ENXIO 6 No such device or address
fi

if test "$option_verbose" = 'no'; then
# trunk-ignore(shellcheck/SC2016)
ffprobe -i "$option_path" |& echo-regexp -fon --regexp='Audio: ([\w\d-]+)' --replace='$1'
Expand Down
1 change: 1 addition & 0 deletions commands.beta/setup-server
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ function setup_server() (
# verify nordvpn connection
local vpn_address vpn_prefix clear_address clear_prefix
if nordvpn status | echo-regexp -q --regexp='Status: Connected'; then
# trunk-ignore(shellcheck/SC2016)
vpn_address="$(nordvpn status | echo-regexp -o --regexp='(?:Server )?IP: (.+)' --replace='$1')"
vpn_prefix="$(__print_lines "$vpn_address" | echo-regexp -o --regexp='^[0-9]+[.][0-9]+[.][0-9]+[.]')"
clear_address="$(what-is-my-ip remote)"
Expand Down
1 change: 1 addition & 0 deletions commands/fs-bytes
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function fs_bytes() (
# get apparent size in bytes
local path
for path in "${option_paths[@]}"; do
# trunk-ignore(shellcheck/SC2016)
dust -sbcP -ob -d0 "$path" | echo-regexp -fo '^(\d+)B' '$1'
done
)
Expand Down
1 change: 1 addition & 0 deletions commands/fs-kilobytes
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function fs_kilobytes() (
# get apparent size in bytes
local path
for path in "${option_paths[@]}"; do
# trunk-ignore(shellcheck/SC2016)
dust -sbcP -ok -d0 "$path" | echo-regexp -fo '^(\d+)K' '$1'
done
)
Expand Down
1 change: 1 addition & 0 deletions commands/fs-megabytes
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function fs_megabytes() (
# get apparent size in bytes
local path
for path in "${option_paths[@]}"; do
# trunk-ignore(shellcheck/SC2016)
dust -sbcP -om -d0 "$path" | echo-regexp -fo '^(\d+)M' '$1'
done
)
Expand Down
1 change: 1 addition & 0 deletions commands/get-opensuse-release
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function get_opensuse_release() (
if is-opensuse && test -f /etc/os-release; then
# config-helper /etc/os-release -- \
# --field=NAME --field=VERSION | "$bin_gsed_or_sed" -e 's/"//g' -e 's/ /_/g' | echo-join '_' --stdin
# trunk-ignore(shellcheck/SC2016)
echo-regexp -fongm '^\s*(NAME|VERSION)="*(.+?)"*$' '$2' </etc/os-release | echo-regexp -g '[_\s\n]+' '_'
else
return 1
Expand Down
3 changes: 3 additions & 0 deletions commands/git-helper
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ function git_helper() (
}

function get_github_slug {
# trunk-ignore(shellcheck/SC2016)
git remote -v | echo-regexp -o --regexp='.+?github[.]com[:/](.+?)[.]git.+' --replace='$1'
}

Expand All @@ -257,6 +258,7 @@ function git_helper() (
}

function get_first_commit_hash {
# trunk-ignore(shellcheck/SC2016)
get_first_commit_entry | echo-regexp -o --regexp='(.+?) .+' --replace='$1'
}

Expand Down Expand Up @@ -294,6 +296,7 @@ function git_helper() (
# Adjustments

local emails
# trunk-ignore(shellcheck/SC2016)
mapfile -t emails < <(git shortlog --summary --email | echo-regexp -ong --regexp='<(.+?)>' --replace='$1')

old_email="$(
Expand Down
1 change: 1 addition & 0 deletions commands/is-bash-version-outdated
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function is_bash_version_outdated_test() (

local bash_version_latest_available
bash_version_latest_available="$(
# trunk-ignore(shellcheck/SC2016)
fetch 'https://ftp.gnu.org/gnu/bash/?C=M;O=D' | echo-regexp -o --regexp='href="bash-([0-9.]+?)[.]tar[.]gz"' --replace='$1'
)"
echo-style --h2='latest known bash version is the latest available bash version'
Expand Down
2 changes: 2 additions & 0 deletions commands/mount-helper
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,10 @@ function mount_helper() (
function update_existing_mounts {
local haystack="$1"
if is-mac; then
# trunk-ignore(shellcheck/SC2016)
mapfile -t EXISTING_MOUNTS < <(echo-regexp -ong --regexp=" on (.+?) \(" --replace='$1' -- "$haystack")
else
# trunk-ignore(shellcheck/SC2016)
mapfile -t EXISTING_MOUNTS < <(echo-regexp -ong --regexp=" on (.+?) type " --replace='$1' -- "$haystack")
fi
}
Expand Down
1 change: 1 addition & 0 deletions commands/network-interface
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function network_interface() (
# An asterisk (*) denotes that a network service is disabled.
networksetup -listallnetworkservices | grep --invert-match --fixed-strings --regexp='*'
else
# trunk-ignore(shellcheck/SC2016)
resolvectl status --no-pager | echo-regexp -ong --regexp='Link \d \((.+?)\)' --replace='$1'
fi
}
Expand Down
1 change: 1 addition & 0 deletions commands/setup-dns
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ function setup_dns() (
# to use dns-crypt
if test "${#dnscrypt_names[@]}" -eq 0 -a "$action" = 'enable'; then
mapfile -t dnscrypt_options < <(
# trunk-ignore(shellcheck/SC2016)
fetch 'https://download.dnscrypt.info/resolvers-list/v2/public-resolvers.md' | echo-regexp -ongm --regexp='^## (.+)$' --replace='$1'
)
mapfile -t dnscrypt_names < <(
Expand Down
1 change: 1 addition & 0 deletions commands/setup-util
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ function setup_util() (
if test "$option_action" = 'uninstall'; then
# if uninstalling, use the package name
packages[download_index]="$(
# trunk-ignore(shellcheck/SC2016)
dpkg -I "$download_filepath" | echo-regexp -o --regexp='Package:\s+(.+)' --replace='$1'
)"
else
Expand Down
1 change: 1 addition & 0 deletions commands/setup-util-1password-cli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function setup_util_1password() (
platform="$(uname -s)"

# fetcch latest cli version
# trunk-ignore(shellcheck/SC2016)
version="v$(fetch 'https://app-updates.agilebits.com/product_history/CLI2' | echo-regexp -o --regexp='https://cache.agilebits.com/dist/1P/op2/pkg/v([^/-]+)/' --replace='$1')"

# fetch appropriate platform url for that cli version
Expand Down
2 changes: 2 additions & 0 deletions commands/setup-util-nerd-fonts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function setup_util_nerd_fonts() (
if is-brew; then
local choices=()
mapfile -t choices < <(
# trunk-ignore(shellcheck/SC2016)
brew search --cask --quiet '/-nerd-font$/' | echo-regexp -ong --regexp='font-(.+?)-nerd-font' --replace='$1'
)
local selection=()
Expand Down Expand Up @@ -50,6 +51,7 @@ function setup_util_nerd_fonts() (
for asset in "${assets[@]}"; do
choices+=(
"$asset"
# trunk-ignore(shellcheck/SC2016)
"$(echo-regexp -o --regexp='([^/]+?)[.]tar[.]xz$' --replace='$1'-- "$asset")"
)
done
Expand Down
1 change: 1 addition & 0 deletions commands/setup-util-node
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function setup_util_node() (
# Helpers

function __get_nvm_versions {
# trunk-ignore(shellcheck/SC2016)
nvm-env -- nvm ls --no-colors --no-alias | echo-regexp -ong --regexp='v([^\s]+)' --replace='$1'
}

Expand Down
33 changes: 27 additions & 6 deletions commands/unziptar
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,26 @@ function unziptar_() (
dmg_device=''
fi
}
if is-alpine; then
function __unzip {
unzip "$@"
}
else
function __unzip {
unzip -u "$@"
}
fi
function __tar {
tar -xvf "$@"
}
if test "$format" = 'dmg'; then
if test "$0" != "${BASH_SOURCE[0]}"; then
help 'Must be run as a command, not a function, such that DMG cleanup always occurs, even on failures.'
fi
trap dmg_unmount EXIT
# install what is necessary for identifying the DMG volume
# attach the DMG to a volume
# trunk-ignore(shellcheck/SC2016)
dmg_device="$(hdiutil attach -readonly -nobrowse -mountroot "$archive_directory" "$archive" | echo-wait | echo-regexp -fo --regexp='(/dev/.+?)\s' --replace='$1')"
function relocate {
cp -Rfv "$@"
Expand All @@ -161,10 +174,14 @@ function unziptar_() (
if command-missing -- unzip; then
setup-util-unziptar --quiet
fi
unzip -u "$archive" 2>/dev/null || {
__unzip "$archive" 2>/dev/null || {
setup-util-unziptar --quiet
unzip -u "$archive" || {
echo-error 'Failed to extract the archive:' $'\n' "$(get-file -- "$archive")" $'\n' "$(unzip --help)"
__unzip "$archive" || {
{
echo-error 'Failed to extract the archive:'
get-file -- "$archive"
unzip --help
} >/dev/stderr
return 1
}
}
Expand All @@ -175,10 +192,14 @@ function unziptar_() (
fi
# don't use -z flag, as that enforces gzip (tar.xy) which is not valid for (.tar.xz)
# without -z, auto-detection is used
tar -xvf "$archive" 2>/dev/null || {
__tar "$archive" 2>/dev/null || {
setup-util-unziptar --quiet
tar -xvf "$archive" || {
echo-error 'Failed to extract the archive:' $'\n' "$(get-file -- "$archive")" $'\n' "$(tar --help)"
__tar "$archive" || {
{
echo-error 'Failed to extract the archive:'
get-file -- "$archive"
tar --help
} >/dev/stderr
return 1
}
}
Expand Down
1 change: 1 addition & 0 deletions commands/what-is-my-subnet
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function what_is_my_subnet() (

if command-exists -- ip; then
# `ip route show dev eth0` is too specific, doesn't work on vms among others
# trunk-ignore(shellcheck/SC2016)
ip route show | echo-regexp -fon --regexp='(.+?/\d+?) dev e' --replace='$1'
else
echo-style --error='Install [ip] try again' >/dev/stderr
Expand Down

0 comments on commit 7c7265d

Please sign in to comment.