lessã§zipãã¡ã¤ã«ã®ä¸èº«ãè¦ãããã ãLESSOPENã¨lesspipe.shã
ååãzipãã¡ã¤ã«ãå±éããä¸èº«ãè¦ãã«ã¯lessã³ãã³ãã使ãã®ãããã¨ããè¨äºãæ¸ãããããããããªãlessã§zipãã¡ã¤ã«ã®ä¸ãè¦ããã®ã調ã¹ã¦ã¿ãã
â»ååè¨äº: Linuxでzipファイルの中身を展開せずに見るにはlessがおすすめ - カタカタブログ
lessã³ãã³ãã®ä»çµã¿
ã©ããããLESSOPENã¨ããç°å¢å¤æ°ã«lesspipe.shã¨ããã·ã§ã«ã¹ã¯ãªãããå®ç¾©ããã¦ããããããlesså®è¡å¯¾è±¡ã®ãã¡ã¤ã«ã«å¯¾ãã¦äºåã«å¦çãå ¥ãã
$ env | grep LESS LESSOPEN=||/usr/bin/lesspipe.sh %s
ã¤ã¾ããtargetã¨ãããã¡ã¤ã«ã«å¯¾ãã¦lessã³ãã³ããæã¤å ´åã
$ less target
以ä¸ã®ãããªå¦çãå é¨ã§è¡ããã¦ãããããªã¤ã¡ã¼ã¸ã
$ lesspipe.sh target | less
ããã¦ãlesspipe.shã®ä¸ã§ã¯å¼æ°ã§æ¸¡ããããã¡ã¤ã«ã®æ¡å¼µåããã§ãã¯ããæ¡å¼µåãã¨ã«ããã¹ã表示ããããå½¢å¼ã«å¤æããå¦çããã¾ãã¦ãããä¾ãã°ãzipãjarã®å ´åã¯å é¨ã§zipinfoã³ãã³ããçºè¡ãã¦ããããã®çµæãlessã«æ¸¡ãã¦ãã¦ããã¦ãããååã®è¨äºã§ã¯zipã¨jarã¯è¦ãããwarãearã¯è¦ããªãã¨æ¸ããããããã¯ãããåå ã ã£ãã
lesspipe.shã®zipã®é¨åä¸é¨æç²
case "$1" in (ã»ã»ã»ç¥ï¼ *.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
ä¾ãã°ãzipã®å ´åã
$ less target.zip
ã¨ããã³ãã³ãã¯ã
$ zipinfo target.zip | less
ã®ãããªåãã¨ãªããzipã®ä¸èº«ãlessã§è¦ããã¨ããä»çµã¿ã«ãªã£ã¦ããã
ã¡ãªã¿ã«ãå½ç°å¢ã®lesspipe.shã®ãã¸ãã¯ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãããzip以å¤ã«ãæ§ã ãªå½¢å¼ã«å¯¾å¿ãã¦ããããã
lesspipe.shã®ä¸é¨æç²
case "$1" in *.[1-9n].bz2|*.[1-9]x.bz2|*.man.bz2|*.[1-9n].[gx]z|*.[1-9]x.[gx]z|*.man.[gx]z|*.[1-9n]. lzma|*.[1-9]x.lzma|*.man.lzma)        case "$1" in        *.gz)          DECOMPRESSOR="gzip -dc" ;;        *.bz2)         DECOMPRESSOR="bzip2 -dc" ;;        *.xz|*.lzma)   DECOMPRESSOR="xz -dc" ;;        esac        if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then                $DECOMPRESSOR -- "$1" | groff -Tascii -mandoc -                exit $?        fi ;;& *.[1-9n]|*.[1-9]x|*.man)        if file "$1" | grep -q troff; then                man -l "$1" | cat -s                exit $?        fi ;;& *.tar) tar tvvf "$1" ;; *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;; *.tar.xz) tar Jtvvf "$1" ;; *.xz|*.lzma) xz -dc -- "$1" ;; *.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;; *.[zZ]|*.gz) gzip -dc -- "$1" ;; *.bz2) bzip2 -dc -- "$1" ;; *.zip|*.jar|*.nbm) zipinfo -- "$1" ;; *.rpm) rpm -qpivl --changelog -- "$1" ;; *.cpi|*.cpio) cpio -itv < "$1" ;; *.gpg) gpg -d "$1" ;; *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
lesspipe.shã®æ¤è¨¼
ã¨ããã§ãç°å¢å¤æ°LESSOPENã®è¨å®ãlesspipe.shã®å®è£
ã¯ç°å¢ã«ãã£ã¦ç°ãªãããã ããããã¯ã¤ã¾ãlesspipe.shã®å®è£
ã好ãã«ã«ã¹ã¿ãã¤ãºã§ããã¨ãããã¨ã ããããã¨ãããã¨ã§ãä»åã¯Cent OS 7.0ã§ç°¡åãªç¬èªlesspipe.shãèªã¾ãã¦lessã³ãã³ãã®å¦çãå¤ããã試ãã¦ã¿ãã
ã¾ãOSã¨lessã®ãã¼ã¸ã§ã³ã示ãã¦ããã
$ cat /etc/redhat-release CentOS Linux release 7.0.1406 (Core) $ less --version less 458 (POSIX regular expressions) Copyright (C) 1984-2012 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less
ãã¦ãå½ç°å¢ã§ã¯ããã©ã«ãã®ç¶æ ã§ç°å¢å¤æ°LESSOPENã«ã¯lesspipe.shãå ¥ã£ã¦ããã%sã®é¨åã«å¯¾è±¡ã®ãã¡ã¤ã«ãç½®æãããããã
$ env | grep LESS LESSOPEN=||/usr/bin/lesspipe.sh %s
LESSOPENã®åãã確èªãããããç¬èªã®ã·ã§ã«ã¹ã¯ãªããã«å¤æ´ãã¦ã¿ãã
$ export LESSOPEN="||/tmp/mylesspipe.sh %s"
ç¬èªã®ã·ã§ã«ã¹ã¯ãªããã®ä¸èº«ã¯ãåãåã£ãå¼æ°ãcat -nããã ããã¤ã¾ããè¡çªå·ã¤ãã§ç¬¬ä¸å¼æ°ã®ãã¹ãæ¨æºåºåããã¨ãããã®ã
$ cat /tmp/mylesspipe.sh cat -n $1 $ chmod +x /tmp/mylesspipe.sh
ãã®ç¶æ ã§lessã³ãã³ããå®è¡ãã¦ã¿ãã¨ãcat -nã«å¯¾ãã¦ãã¼ã¸ã£ãåãããããªå®è¡çµæã«ãªãã
$ less test.txt     1 1234     2 abcd     3 XYZ test.txt (END)
ãã®ãã¨ãããLESSOPENã§æå®ãããã«ã¹ã¿ã ã®ã·ã§ã«ã¹ã¯ãªãããå¼ã°ãããã®åºåãlessããã¦ãããã¨ãåããã
ã¨ãããã¨ã¯ã話ãå ã®lesspipe.shã«æ»ãã¨ã以ä¸ã®ããã«ã¹ã¯ãªãããç·¨éããwarãearã®ã¨ããzipinfoããã¾ãããã«å¤ãã¦ããã°ãlessã§ä¸èº«ãè¦ããããã«ãªãï¼
case "$1" in (ã»ã»ã»ç¥ï¼ *.zip|*.jar|*.nbm|*.war|*.ear) zipinfo -- "$1" ;;
ã¾ã¨ã
lessãå®éã«å®è¡ãããã¨ããLESSOPENã¨ããç°å¢å¤æ°ã«å®ç¾©ãããlesspipe.shã¹ã¯ãªããã«ããå¦çãããã§ãããã¨ãããã£ããã¾ãããã®ã¹ã¯ãªããèªä½ã¯æ§ã ãªå½¢å¼ã®ãã¡ã¤ã«ã«å¯¾ãã¦ãlessããããããã工夫ããã¦ãããzipãlessã§ã¿ããã®ããã®å®è£ ã®ä¸ã¤ã«ãããªãã¨ãããã¨ã ã£ããããã«lesspipe.shãã«ã¹ã¿ãã¤ãºããã°ããã使ãããããªãªã¸ãã«lessãå®ç¾ã§ãããããããªãï¼
以ä¸