mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 04:22:34 +03:00
shell: replace which
with command -v
for speed and POSIX compatibility
https://stackoverflow.com/a/677212/5132088 Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
parent
572312bd88
commit
50976cec62
@ -25,9 +25,9 @@ staroffice_console() {
|
||||
}
|
||||
|
||||
get_ooffice_executable() {
|
||||
if which loffice >/dev/null 2>&1; then
|
||||
if command -v loffice >/dev/null 2>&1; then
|
||||
echo "loffice"
|
||||
elif which ooffice >/dev/null 2>&1; then
|
||||
elif command -v ooffice >/dev/null 2>&1; then
|
||||
echo "ooffice"
|
||||
else
|
||||
echo -n
|
||||
@ -52,35 +52,35 @@ do_view_action() {
|
||||
fi
|
||||
;;
|
||||
msdoc)
|
||||
if which wvHtml >/dev/null 2>&1; then
|
||||
if command -v wvHtml >/dev/null 2>&1; then
|
||||
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
||||
wvHtml "${MC_EXT_FILENAME}" --targetdir="$tmp" page.html
|
||||
elinks -dump "$tmp/page.html"
|
||||
rm -rf "$tmp"
|
||||
elif which antiword >/dev/null 2>&1; then
|
||||
elif command -v antiword >/dev/null 2>&1; then
|
||||
antiword -t "${MC_EXT_FILENAME}"
|
||||
elif which catdoc >/dev/null 2>&1; then
|
||||
elif command -v catdoc >/dev/null 2>&1; then
|
||||
catdoc -w "${MC_EXT_FILENAME}"
|
||||
elif which word2x >/dev/null 2>&1; then
|
||||
elif command -v word2x >/dev/null 2>&1; then
|
||||
word2x -f text "${MC_EXT_FILENAME}" -
|
||||
else
|
||||
strings "${MC_EXT_FILENAME}"
|
||||
fi
|
||||
;;
|
||||
msxls)
|
||||
if which xlhtml >/dev/null 2>&1; then
|
||||
if command -v xlhtml >/dev/null 2>&1; then
|
||||
tmp=`mktemp -d ${TMPDIR:-/tmp}/%p.XXXXXX`
|
||||
xlhtml -a "${MC_EXT_FILENAME}" > "$tmp/page.html"
|
||||
elinks -dump "$tmp/page.html"
|
||||
rm -rf "$tmp"
|
||||
elif which xls2csv >/dev/null 2>&1; then
|
||||
elif command -v xls2csv >/dev/null 2>&1; then
|
||||
xls2csv "${MC_EXT_FILENAME}"
|
||||
else
|
||||
strings "${MC_EXT_FILENAME}"
|
||||
fi
|
||||
;;
|
||||
dvi)
|
||||
which dvi2tty >/dev/null 2>&1 && \
|
||||
command -v dvi2tty >/dev/null 2>&1 && \
|
||||
dvi2tty "${MC_EXT_FILENAME}" || \
|
||||
catdvi "${MC_EXT_FILENAME}"
|
||||
;;
|
||||
|
@ -18,13 +18,13 @@ do_view_action() {
|
||||
[ -n "$DISPLAY" ] && sxpm "${MC_EXT_FILENAME}"
|
||||
;;
|
||||
*)
|
||||
if which exif >/dev/null 2>&1; then
|
||||
if command -v exif >/dev/null 2>&1; then
|
||||
exif "${MC_EXT_FILENAME}" 2>/dev/null
|
||||
E=$?
|
||||
else
|
||||
E=1
|
||||
fi
|
||||
if [ $E != 0 ] && which exiftool >/dev/null 2>&1; then
|
||||
if [ $E != 0 ] && command -v exiftool >/dev/null 2>&1; then
|
||||
exiftool "${MC_EXT_FILENAME}" 2>/dev/null
|
||||
fi
|
||||
identify "${MC_EXT_FILENAME}"
|
||||
@ -47,20 +47,20 @@ do_open_action() {
|
||||
;;
|
||||
*)
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
if which geeqie >/dev/null 2>&1; then
|
||||
if command -v geeqie >/dev/null 2>&1; then
|
||||
(geeqie "${MC_EXT_FILENAME}" &)
|
||||
else
|
||||
(gqview "${MC_EXT_FILENAME}" &)
|
||||
fi
|
||||
# no backgrounding for console viewers
|
||||
elif which fim >/dev/null 2>&1; then
|
||||
elif command -v fim >/dev/null 2>&1; then
|
||||
fim "${MC_EXT_FILENAME}"
|
||||
elif which fbi >/dev/null 2>&1; then
|
||||
elif command -v fbi >/dev/null 2>&1; then
|
||||
fbi "${MC_EXT_FILENAME}"
|
||||
elif which zgv >/dev/null 2>&1; then
|
||||
elif command -v zgv >/dev/null 2>&1; then
|
||||
zgv "${MC_EXT_FILENAME}"
|
||||
# run-mailcap as a last resort
|
||||
elif which see >/dev/null 2>&1; then
|
||||
elif command -v see >/dev/null 2>&1; then
|
||||
(see "${MC_EXT_FILENAME}" &)
|
||||
fi
|
||||
;;
|
||||
|
@ -13,7 +13,7 @@ do_view_action() {
|
||||
|
||||
case "${filetype}" in
|
||||
iso9660)
|
||||
if which isoinfo > /dev/null 2>&1; then
|
||||
if command -v isoinfo >/dev/null 2>&1; then
|
||||
isoinfo -d -i "${MC_EXT_FILENAME}" && isoinfo -l -R -J -i "${MC_EXT_FILENAME}"
|
||||
else
|
||||
7za l "${MC_EXT_FILENAME}"
|
||||
@ -74,7 +74,7 @@ do_open_action() {
|
||||
sqlite3 "${MC_EXT_FILENAME}"
|
||||
;;
|
||||
glade)
|
||||
if which glade-3 >/dev/null 2>&1; then
|
||||
if command -v glade-3 >/dev/null 2>&1; then
|
||||
(glade-3 "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
|
||||
else
|
||||
(glade-2 "${MC_EXT_FILENAME}" >/dev/null 2>&1 &)
|
||||
|
@ -129,7 +129,7 @@ do_open_action() {
|
||||
;;
|
||||
chm)
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
which kchmviewer > /dev/null 2>&1 \
|
||||
command -v kchmviewer >/dev/null 2>&1 \
|
||||
&& (kchmviewer "${MC_EXT_FILENAME}" &) \
|
||||
|| (xchm "${MC_EXT_FILENAME}" &)
|
||||
else
|
||||
|
@ -15,10 +15,10 @@ do_view_action() {
|
||||
|
||||
case "${filetype}" in
|
||||
*)
|
||||
if which mplayer >/dev/null 2>&1; then
|
||||
if command -v mplayer >/dev/null 2>&1; then
|
||||
mplayer -identify -vo null -ao null -frames 0 "${MC_EXT_FILENAME}" 2>&1 | \
|
||||
sed -n 's/^ID_//p'
|
||||
elif which mpv_identify.sh >/dev/null 2>&1; then
|
||||
elif command -v mpv_identify.sh >/dev/null 2>&1; then
|
||||
mpv_identify.sh "${MC_EXT_FILENAME}"
|
||||
else
|
||||
echo "Please install either mplayer or mpv to get information for this file"
|
||||
@ -30,7 +30,7 @@ do_view_action() {
|
||||
do_open_action() {
|
||||
filetype=$1
|
||||
|
||||
if which mpv >/dev/null 2>&1; then
|
||||
if command -v mpv >/dev/null 2>&1; then
|
||||
PLAYER="mpv --really-quiet"
|
||||
else
|
||||
PLAYER="mplayer -really-quiet"
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#*** file scope functions **********************************************
|
||||
|
||||
XORRISO=$(which xorriso 2>/dev/null)
|
||||
XORRISO=$(command -v xorriso >/dev/null 2>&1)
|
||||
|
||||
# This snippet is used to undo xorriso's Text_shellsafe(). Pseudocode for the
|
||||
# function:
|
||||
@ -144,7 +144,7 @@ xorriso_rm() {
|
||||
|
||||
# tested to comply with isoinfo 2.0's output
|
||||
test_iso () {
|
||||
ISOINFO=$(which isoinfo 2>/dev/null)
|
||||
ISOINFO=$(command -v isoinfo >/dev/null 2>&1)
|
||||
if test -z "$ISOINFO"; then
|
||||
echo "isoinfo not found" >&2
|
||||
return 1
|
||||
|
@ -17,10 +17,10 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
P7ZIP=`which 7z 2>/dev/null` \
|
||||
|| P7ZIP=`which 7zz 2>/dev/null` \
|
||||
|| P7ZIP=`which 7za 2>/dev/null` \
|
||||
|| P7ZIP=`which 7zr 2>/dev/null` \
|
||||
P7ZIP=`command -v 7z >/dev/null 2>&1` \
|
||||
|| P7ZIP=`command -v 7zz >/dev/null 2>&1` \
|
||||
|| P7ZIP=`command -v 7za >/dev/null 2>&1` \
|
||||
|| P7ZIP=`command -v 7zr >/dev/null 2>&1` \
|
||||
|| P7ZIP=""
|
||||
|
||||
# Let the test framework hook in:
|
||||
|
@ -16,7 +16,7 @@
|
||||
RAR=rar
|
||||
|
||||
# Prefer unrar (freeware).
|
||||
UNRAR=`which unrar 2>/dev/null`
|
||||
UNRAR=`command -v unrar >/dev/null 2>&1`
|
||||
|
||||
[ -z $UNRAR ] && UNRAR=$RAR
|
||||
[ ! -x $UNRAR -a -x $RAR ] && UNRAR=$RAR
|
||||
|
@ -10,8 +10,8 @@
|
||||
# On Debian/Ubuntu wimtools can be installed via:
|
||||
# apt install wimtools
|
||||
|
||||
which wimlib-imagex 2>/dev/null > /dev/null || exit 1
|
||||
WIM=`which wimlib-imagex`
|
||||
command -v wimlib-imagex >/dev/null 2>&1 || exit 1
|
||||
WIM=`command -v wimlib-imagex >/dev/null 2>&1`
|
||||
AWK=@AWK@
|
||||
|
||||
[ -n "$2" ] || exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user