mc in solarized
[misc.git] / .local / share / mc / extfs.d / ganneff
1 #! /bin/bash
2
3 set -e
4 set -u
5 set -E
6
7 # (C) 2011 Joerg Jaspert <joerg@debian.org>
8 # GPLv2, no later
9
10 LC_ALL=C
11 export LC_ALL=C
12
13 function dofslist () {
14 case "$1" in
15 *.lzma) ZCAT="lzma -dc" ;;
16 *.xz) ZCAT="xz -dc" ;;
17 *.bz2) ZCAT="bzip2 -dc";;
18 *.gz) ZCAT="gzip -dc" ;;
19 *.z) ZCAT="gzip -dc" ;;
20 *.Z) ZCAT="gzip -dc" ;;
21 *) ZCAT="cat" ;;
22 esac
23
24 $ZCAT "$1" | tar tvvf - |
25 while read MODE OWNER SIZE DATE TIME NAME LINK; do
26 # Filter out directories. They would be empty anyways
27 if [[ ${MODE} =~ ^d.* ]]; then
28 continue
29 fi
30 OUTLINE="${MODE}" # permission string
31 OUTLINE="${OUTLINE} 1" # number of links. definitely wrong right now
32 OUTLINE="${OUTLINE} ${OWNER%%/*}" # file owner
33 OUTLINE="${OUTLINE} ${OWNER##*/}" # file group
34 OUTLINE="${OUTLINE} ${SIZE}" # file size
35 if [[ ${DATE} =~ ([0-9]{4})-([0-9]{2})-([0-9]{2}) ]]; then
36 DATE="${BASH_REMATCH[2]}-${BASH_REMATCH[3]}-${BASH_REMATCH[1]}"
37 fi
38 OUTLINE="${OUTLINE} ${DATE} ${TIME}" # file date/time
39 # NAME=${NAME#*/}
40 OUTLINE="${OUTLINE} ${NAME//\//\\}" # filename
41 OUTLINE="${OUTLINE} " # filepath
42
43 if [[ "${LINK}" =~ "^->.*" ]]; then
44 OUTLINE="${OUTLINE} ${LINK}"
45 fi
46 echo ${OUTLINE}
47 done
48 }
49
50 function docopyout () {
51 case "$2" in
52 *.lzma) ZCAT="lzma -dc" ;;
53 *.xz) ZCAT="xz -dc" ;;
54 *.bz2) ZCAT="bzip2 -dc";;
55 *.gz) ZCAT="gzip -dc" ;;
56 *.z) ZCAT="gzip -dc" ;;
57 *.Z) ZCAT="gzip -dc" ;;
58 *) ZCAT="cat" ;;
59 esac
60 NAME=${3//\\/\/}
61 $ZCAT "$2" | tar -xO "$NAME" > "$4"
62 }
63
64 case "$1" in
65 list)
66 dofslist "$2" | sort -k 8;
67 exit 0
68 ;;
69 copyout)
70 docopyout "$@"
71 exit 0
72 ;;
73 esac
74 exit 1