Open
Description
It might happen that you only have /usr/bin/7zz
installed but not /usr/bin/7z
which will make simple-extract foo.7z
fail.
Given with those choices/coming changes:
% apt-file --filter-suites bookworm search bin/7z
7zip: /usr/bin/7zz
p7zip: /usr/bin/7zr
p7zip-full: /usr/bin/7z
p7zip-full: /usr/bin/7za
% apt-file --filter-suites trixie search bin/7z
7zip: /usr/bin/7z
7zip: /usr/bin/7za
7zip: /usr/bin/7zr
7zip-standalone: /usr/bin/7zz
We would need either something like this or similiar
grml-etc-core (git)-[master] % git diff master simple-extract-7z-ifelse
diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index f26af6c..9179ec3 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -3367,6 +3367,11 @@ function simple-extract () {
;;
*7z)
DECOMP_CMD="7z x"
+ if ! check_com 7z; then
+ if check_com "7zz"; then DECOMP_CMD="7zz x"
+ elif check_com "7zr"; then DECOMP_CMD="7zr x"
+ fi
+ fi
USES_STDIN=false
USES_STDOUT=false
;;
Or maybe use an array (in general?) w/ fallback of DECOMP_CMD
grml-etc-core (git)-[master] % git diff master simple-extract-7z
diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc
index f26af6c..1510725 100644
--- a/etc/zsh/zshrc
+++ b/etc/zsh/zshrc
@@ -3320,7 +3320,7 @@ function trans () {
function simple-extract () {
emulate -L zsh
setopt extended_glob noclobber
- local ARCHIVE DELETE_ORIGINAL DECOMP_CMD USES_STDIN USES_STDOUT GZTARGET WGET_CMD
+ local ARCHIVE DELETE_ORIGINAL DECOMP_CMD DECOMP_CMDS CMD USES_STDIN USES_STDOUT GZTARGET WGET_CMD
local RC=0
zparseopts -D -E "d=DELETE_ORIGINAL"
for ARCHIVE in "${@}"; do
@@ -3366,6 +3366,7 @@ function simple-extract () {
USES_STDOUT=false
;;
*7z)
+ DECOMP_CMDS=( "7z x" "7zz x" "7zr x" )
DECOMP_CMD="7z x"
USES_STDIN=false
USES_STDOUT=false
@@ -3412,6 +3413,15 @@ function simple-extract () {
;;
esac
+ if (( ${+DECOMP_CMDS} )); then
+ for CMD in ${DECOMP_CMDS[@]}; do
+ if check_com "${CMD[(w)1]}"; then
+ DECOMP_CMD="$CMD"
+ break
+ fi
+ done
+ fi
+
if ! check_com ${DECOMP_CMD[(w)1]}; then
echo "ERROR: ${DECOMP_CMD[(w)1]} not installed." >&2
RC=$((RC+2))
not really happy with it but just to illustrate how it could be achieved 🙈
Another idea i got was to check if we got an string(scalar) or array in $DECOMP_CMDS
and do the magic accordingly ?_?
obelix% MOO=( "MOO moo" "OOM moo" "OOM oom" "MOO oom" ); [[ ${(t)MOO} == array ]] && print -l "\$MOO is a ${(t)MOO}\n${MOO[@]}" || print -l "\$MOO is a ${(t)MOO}\n$MOO"
$MOO is a array
MOO moo
OOM moo
OOM oom
MOO oom
obelix% MOO="MOO moo"; [[ ${(t)MOO} == array ]] && print -l "\$MOO is a ${(t)MOO}\n${MOO[@]}" || print -l "\$MOO is a ${(t)MOO}\n$MOO"
$MOO is a scalar
MOO moo
EDIT: maybe other commands also have alternatives that might need fix/adding?
Metadata
Metadata
Assignees
Labels
No labels