bin: improve handling of compressed files
This commit is contained in:
parent
55b50e747e
commit
31ef6a7109
|
@ -37,6 +37,7 @@ fileinfo() {
|
||||||
for arg
|
for arg
|
||||||
do case "$arg" in (-*) continue;; esac
|
do case "$arg" in (-*) continue;; esac
|
||||||
$elevate file --exclude elf -E "$arg"
|
$elevate file --exclude elf -E "$arg"
|
||||||
|
$elevate ssh-keygen -l -f "$arg" 2>/dev/null
|
||||||
# TODO do not grep bitrate but extract properly
|
# TODO do not grep bitrate but extract properly
|
||||||
#probe="$($elevate ffprobe "$arg" 2>&1)"
|
#probe="$($elevate ffprobe "$arg" 2>&1)"
|
||||||
#echo $probe | grep -v -e '00:00:00.04' -e 'ansi' &&
|
#echo $probe | grep -v -e '00:00:00.04' -e 'ansi' &&
|
||||||
|
@ -89,7 +90,7 @@ for arg; do
|
||||||
;;
|
;;
|
||||||
(*\ image/*)
|
(*\ image/*)
|
||||||
timg+=("$arg")
|
timg+=("$arg")
|
||||||
which identify && continue;;
|
which identify >/dev/null && continue;;
|
||||||
(*\ inode/directory\;*)
|
(*\ inode/directory\;*)
|
||||||
ls+=("$arg")
|
ls+=("$arg")
|
||||||
test -L "$arg" || continue
|
test -L "$arg" || continue
|
||||||
|
@ -114,18 +115,25 @@ for arg; do
|
||||||
;;
|
;;
|
||||||
(*:\ *compress*|*\ archive*)
|
(*:\ *compress*|*\ archive*)
|
||||||
list="$tmpfile-list.txt"
|
list="$tmpfile-list.txt"
|
||||||
|
case "$arg" in
|
||||||
|
(*.7z) test $# = 1 && 7z l "$arg";;
|
||||||
|
(*.tar*) tar --list --file "$arg";;
|
||||||
|
(*)
|
||||||
if test $# = 1
|
if test $# = 1
|
||||||
then nvim "$arg"
|
then nvim "$arg"
|
||||||
else case "$arg" in (*.part);; (*)
|
else case "$arg" in (*.part);; (*)
|
||||||
nvim -es "+2w$list|5,w>>$list" "$arg"
|
nvim -es "+2w$list|5,w>>$list" "$arg"
|
||||||
batplain+=("$list");;
|
batplain+=("$list");;
|
||||||
esac; fi
|
esac
|
||||||
|
fi
|
||||||
|
esac
|
||||||
;;
|
;;
|
||||||
(*:\ *database*) highlight "Tables" && sqlite3 "$arg" ".tables";;
|
(*:\ *database*) highlight "Tables" && sqlite3 "$arg" ".tables";;
|
||||||
(*:\ data) ;;
|
(*:\ data) ;;
|
||||||
(*) bat+=("$arg")
|
(*) bat+=("$arg")
|
||||||
timga+=("$arg")
|
timga+=("$arg")
|
||||||
continue;;
|
continue
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -137,7 +145,7 @@ done
|
||||||
if test "$timg"; then
|
if test "$timg"; then
|
||||||
# TODO Don't show info on all images for gifs
|
# TODO Don't show info on all images for gifs
|
||||||
$inspect ||
|
$inspect ||
|
||||||
if which timg
|
if which timg >/dev/null
|
||||||
then $elevate timg $(test "$timga" && echo "-V") --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
then $elevate timg $(test "$timga" && echo "-V") --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
||||||
$(test $# -gt 1 &&
|
$(test $# -gt 1 &&
|
||||||
echo "-t0.2 --center $(test $# -lt 20 && echo "--title") --grid=$((grid < $# ? grid : $#))x2") \
|
echo "-t0.2 --center $(test $# -lt 20 && echo "--title") --grid=$((grid < $# ? grid : $#))x2") \
|
||||||
|
@ -146,10 +154,11 @@ if test "$timg"; then
|
||||||
do catimg -H $(expr $(tput lines) / 2) $img
|
do catimg -H $(expr $(tput lines) / 2) $img
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if which identify && ( $inspect || test $# -lt 10 ); then
|
if which identify >/dev/null && ( $inspect || test $# -lt 10 ); then
|
||||||
tput setaf 6
|
tput setaf 6
|
||||||
for img in "${timg[@]}"
|
for img in "${timg[@]}"
|
||||||
do ident="$(identify -ping -precision 3 -format "%wx%h %b %m %[bit-depth]-bit %[colorspace]" "$img")"
|
do case $img in (*.gif) continue;; esac
|
||||||
|
ident="$(identify -ping -precision 3 -format "%wx%h %b %m %[bit-depth]-bit %[colorspace]" "$img")"
|
||||||
printf "%11s %-30s %s\n" "${ident%% *}" "$(basename "$img")" "${ident#* }"
|
printf "%11s %-30s %s\n" "${ident%% *}" "$(basename "$img")" "${ident#* }"
|
||||||
done
|
done
|
||||||
tput sgr0
|
tput sgr0
|
||||||
|
@ -185,7 +194,7 @@ if test "$bat" -o "$batplain"; then
|
||||||
done;;
|
done;;
|
||||||
esac
|
esac
|
||||||
else $inspect || $batcommand "${batpager:-$pager}" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}"
|
else $inspect || $batcommand "${batpager:-$pager}" $batstyle,header$(test $# -gt 1 && echo ",numbers") "${bat[@]}"
|
||||||
test $# -lt $(expr $(tput lines) / 3) && fileinfo "${bat[@]}"
|
{ $inspect || test $# -lt $(expr $(tput lines) / 3); } && fileinfo "${bat[@]}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -194,6 +203,7 @@ if test "$ls" -o $# -le $(echo "$flags" | wc -w); then
|
||||||
# Alternative: find -exec ls -dl {} +
|
# Alternative: find -exec ls -dl {} +
|
||||||
{
|
{
|
||||||
# TODO handle single quotes in filenames
|
# TODO handle single quotes in filenames
|
||||||
|
# TODO listing sometimes doubles as exa prints partial listings while working
|
||||||
timeout .6s sh -c "
|
timeout .6s sh -c "
|
||||||
if test '$tree'
|
if test '$tree'
|
||||||
then $elevate tree -a --dirsfirst --du -h -C -L 3 $flags $(printf "'%s' " "${ls[@]:-.}")
|
then $elevate tree -a --dirsfirst --du -h -C -L 3 $flags $(printf "'%s' " "${ls[@]:-.}")
|
||||||
|
|
|
@ -24,12 +24,11 @@ case $arg in
|
||||||
(*.tar.*|*.tar) tar --extract --file "$fullpath";;
|
(*.tar.*|*.tar) tar --extract --file "$fullpath";;
|
||||||
(*.tbz2) tar xjf "$fullpath" ;;
|
(*.tbz2) tar xjf "$fullpath" ;;
|
||||||
(*.tgz) tar xzf "$fullpath" ;;
|
(*.tgz) tar xzf "$fullpath" ;;
|
||||||
(*.7z|*.z01|*.zip|*.jar)
|
(*.7z) 7z$(which 7z >/dev/null || echo r) x $param "$fullpath";;
|
||||||
|
(*.z01|*.zip|*.jar)
|
||||||
if which 7z >/dev/null
|
if which 7z >/dev/null
|
||||||
then 7z x $param "$fullpath"
|
then 7z x $param "$fullpath"
|
||||||
else which p7zip >/dev/null &&
|
else unzip "$fullpath" | rewrite
|
||||||
p7zip --decompress $param "$fullpath" ||
|
|
||||||
unzip "$fullpath" | rewrite
|
|
||||||
fi;;
|
fi;;
|
||||||
(*.gz) gunzip "$fullpath" ;;
|
(*.gz) gunzip "$fullpath" ;;
|
||||||
(*.bz2) bunzip2 "$fullpath" ;;
|
(*.bz2) bunzip2 "$fullpath" ;;
|
||||||
|
@ -37,7 +36,9 @@ case $arg in
|
||||||
(*.deb) ar x "$fullpath" ;;
|
(*.deb) ar x "$fullpath" ;;
|
||||||
(*.zst) unzstd "$fullpath" ;;
|
(*.zst) unzstd "$fullpath" ;;
|
||||||
(*.Z) uncompress "$fullpath";;
|
(*.Z) uncompress "$fullpath";;
|
||||||
(*) echo "'$arg' cannot be extracted by ex" >&2;;
|
(*) which 7z >/dev/null &&
|
||||||
|
7z x $param "$fullpath" ||
|
||||||
|
echo "'$arg' cannot be extracted by ex" >&2;;
|
||||||
esac
|
esac
|
||||||
# If we created a temporary subfolder, check if it can be eliminated
|
# If we created a temporary subfolder, check if it can be eliminated
|
||||||
if test "$(basename "$PWD")" = "$namepart"
|
if test "$(basename "$PWD")" = "$namepart"
|
||||||
|
|
Loading…
Reference in New Issue