diff --git a/commands/config-helper b/commands/config-helper index c8e0181a6..fd4defabe 100755 --- a/commands/config-helper +++ b/commands/config-helper @@ -360,6 +360,7 @@ function config_helper() ( # this will then leave the first occurance in the whole # which we can use sd to perform our final intended replacement # of the primary occurance + # printf '%s' "$content" | sd -n 1 "$search_pattern" 'REPLACE_THIS_LINE' | sd "$search_pattern" '' | sd $'(REPLACE_THIS_LINE\n)+' "$replace_pattern" >"$option_file" <-- this fails to handle replacement groups printf '%s' "$content" | teip -g "$search_pattern" -- teip -l 2- -- sed 's/.*/REMOVE_THIS_LINE/' | sd $'(REMOVE_THIS_LINE\n)+' '' | diff --git a/commands/echo-nothing-or-fail b/commands/echo-nothing-or-fail new file mode 100755 index 000000000..8ee77e28d --- /dev/null +++ b/commands/echo-nothing-or-fail @@ -0,0 +1,50 @@ +#!/usr/bin/env bash + +function echo_nothing_or_fail() ( + source "$DOROTHY/sources/stdinargs.bash" + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + If input is provided, fail. + If no input was provided, success. + + USAGE: + echo-nothing-or-fail [...options] [--] ... + echo-lines ... | echo-nothing-or-fail [...options] + + OPTIONS: + $(stdinargs_options_help --) + + EXAMPLE: + + # success cases + echo-nothing-or-fail -- 'sup' + echo 'sup' | echo-nothing-or-fail --stdin + + # exit status: 1 + + # failure cases, no stdin, no arguments + echo-nothing-or-fail -- + true | echo-nothing-or-fail --stdin + + # exit status: 0 + EOF + return 22 # EINVAL 22 Invalid argument + } + + function on_input { + return 1 # failure + } + + function on_no_input { + return 0 # success + } + + stdinargs "$@" +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + echo_nothing_or_fail "$@" +fi diff --git a/commands/fs-dequarantine b/commands/fs-dequarantine new file mode 100755 index 000000000..93a12f810 --- /dev/null +++ b/commands/fs-dequarantine @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +function fs_dequaratine() ( + source "$DOROTHY/sources/bash.bash" + + # ===================================== + # Arguments + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Remove the quaratine flag from a path. + + USAGE: + fs-dequarantine [--] ... + EOF + if test "$#" -ne 0; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process + local item option_paths=() + while test "$#" -ne 0; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--') + option_paths+=("$@") + shift $# + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; + *) option_paths+=("$item") ;; + esac + done + + # check + if test "${#option_paths[@]}" -eq 0; then + help 'No s were provided.' + fi + + # ===================================== + # Action + + if ! is-mac || command-missing xattr; then + return 0 # not needed + fi + + function disable_quarantine_on_path { + local path="$1" output status cmd=('xattr') + # https://apple.stackexchange.com/a/436677/15131 + # option -r not recognized + if test -d "$path"; then + cmd+=('-dr') + else + cmd+=('-d') + fi + cmd+=('com.apple.quarantine' "$path") + eval_capture --outputvar=output --statusvar=status -- "${cmd[@]}" + if test "$status" -eq 0 -o "$output" = 'No such xattr: com.apple.quarantine'; then + return 0 + fi + eval_capture --outputvar=output --statusvar=status -- sudo-helper -- "${cmd[@]}" + if test "$status" -eq 0 -o "$output" = 'No such xattr: com.apple.quarantine'; then + return 0 + fi + print_line "$output" >/dev/stderr + return "$status" + } + + local path + for path in "${option_paths[@]}"; do + disable_quarantine_on_path "$path" + done +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + fs_dequaratine "$@" +fi diff --git a/commands/fs-structure b/commands/fs-structure index f1e09376d..0bb551ca1 100755 --- a/commands/fs-structure +++ b/commands/fs-structure @@ -84,7 +84,7 @@ function fs_structure() ( else cd "$(dirname "$path")" || return 1 basename="$(basename "$path")" - "${cmd[@]}" "$basename" | sd -s "$basename" '' + "${cmd[@]}" "$basename" | sd --fixed-strings "$basename" '' fi done ) diff --git a/commands/setup-util b/commands/setup-util index 04bf01032..1a0439cf3 100755 --- a/commands/setup-util +++ b/commands/setup-util @@ -513,6 +513,7 @@ function setup_util() ( # adjust fs-own --permissions='+x' -- "$path" + fs-dequarantine -- "$path" # verify if [[ $path == *'.app' ]] && test -d "$path"; then diff --git a/commands/setup-util-sd b/commands/setup-util-sd index a9776a496..b9b942269 100755 --- a/commands/setup-util-sd +++ b/commands/setup-util-sd @@ -4,19 +4,15 @@ # sed/awk alternative # https://github.com/chmln/sd/releases -# sd-v0.7.6-x86_64-apple-darwin -# sd-v0.7.6-x86_64-unknown-linux-gnu -# sd-v0.7.6-x86_64-unknown-linux-musl - -# arm64 -# https://github.com/chmln/sd/issues/152 -# https://github.com/yhakbar/sd/releases/tag/v0.7.7-yhakbar -# sd-v0.7.7-yhakbar-aarch64-apple-darwin -# sd-v0.7.7-yhakbar-aarch64-unknown-linux-musl -# sd-v0.7.7-yhakbar-arm-unknown-linux-gnueabihf -# sd-v0.7.7-yhakbar-x86_64-apple-darwin -# sd-v0.7.7-yhakbar-x86_64-unknown-linux-gnu -# sd-v0.7.7-yhakbar-x86_64-unknown-linux-musl +# sd-v1.0.0-aarch64-apple-darwin.tar.gz +# sd-v1.0.0-aarch64-unknown-linux-musl.tar.gz +# sd-v1.0.0-arm-unknown-linux-gnueabihf.tar.gz +# sd-v1.0.0-armv7-unknown-linux-gnueabihf.tar.gz +# sd-v1.0.0-x86_64-apple-darwin.tar.gz +# sd-v1.0.0-x86_64-pc-windows-gnu.zip +# sd-v1.0.0-x86_64-pc-windows-msvc.zip +# sd-v1.0.0-x86_64-unknown-linux-gnu.tar.gz +# sd-v1.0.0-x86_64-unknown-linux-musl.tar.gz # https://repology.org/project/sd-find-replace/versions @@ -48,27 +44,35 @@ function setup_util_sd() ( function get_github_asset_url { github-download \ --dry \ - --slug='yhakbar/sd' \ + --slug='chmln/sd' \ --release='latest' \ --asset-filter="$(echo-escape-regex -- "$1")$" | echo-first-line || : } function add_download_option { options+=( DOWNLOAD="$(get_github_asset_url "$1")" + DOWNLOAD_UNZIP_FILTER="*/$2" ) } if is-mac; then if test "$arch" = 'a64'; then - add_download_option '-aarch64-apple-darwin' + add_download_option '-aarch64-apple-darwin.tar.gz' 'sd' else - add_download_option '-x86_64-apple-darwin' + add_download_option '-x86_64-apple-darwin.tar.gz' 'sd' fi - else + elif is-linux; then arch="$(get-arch)" if test "$arch" = 'a64'; then - add_download_option '-aarch64-unknown-linux-musl' + add_download_option '-aarch64-unknown-linux-musl.tar.gz' 'sd' elif test "$arch" = 'x64'; then - add_download_option '-x86_64-unknown-linux-musl' + add_download_option '-x86_64-unknown-linux-musl.tar.gz' 'sd' + elif test "$arch" = 'a32'; then + add_download_option '-armv7-unknown-linux-gnueabihf.tar.gz' 'sd' + fi + elif is-wsl; then + arch="$(get-arch)" + if test "$arch" = 'x64'; then + add_download_option '-x86_64-pc-windows-msvc.zip' 'sd.exe' fi fi setup-util "${options[@]}"