Added Perforce plugin.
[profile.git] / .vim / perforce / restor.sh
1 #!/bin/bash
2 # Author: Hari Krishna Dara ( hari_vim at yahoo dot com ) 
3 # Last Change: 06-Jan-2004 @ 19:07
4 # Requires:
5 #   - bash or ksh (tested on cygwin and MKS respectively).
6 #   - Info Zip for the -z option to work (comes with linux/cygwin). Download for
7 #     free from:
8 #       http://www.info-zip.org/
9 # Version: 1.1.0
10 # Licence: This program is free software; you can redistribute it and/or
11 #          modify it under the terms of the GNU General Public License.
12 #          See http://www.gnu.org/copyleft/gpl.txt 
13 usage()
14 {
15 cat <<END
16 $0 <input package>
17   The input package is the name of the backup directory or the archive file(with
18   or without extension).
19 END
20 }
21
22 inputType=''
23 inputPackage=''
24 verboseMode=1
25 if [ -d $1 ]; then
26     inputType='dir'
27     inputPackage=$1
28 elif [ -r $1.zip ]; then
29     inputType='zip'
30     inputPackage=$1.zip
31 elif [ -r $1.tar.gz ]; then
32     inputType='tar'
33     inputPackage=$1.tar.gz
34     tarOpt='z'
35 elif [ -r $1.tar.bz2 ]; then
36     inputType='tar'
37     inputPackage=$1.tar.bz2
38     tarOpt='j'
39 elif [ -r $1.tar.Z ]; then
40     inputType='tar'
41     inputPackage=$1.tar.Z
42     tarOpt='Z'
43 elif [ -r $1.tar ]; then
44     inputType='tar'
45     inputPackage=$1.tar
46     tarOpt=''
47 elif [ -r $1 ]; then
48     case $1 in
49     *.zip)
50         inputType='zip'
51         ;;
52     *.tar.gz)
53         inputType='tar'
54         tarOpt='z'
55         ;;
56     *.tar.bz2)
57         inputType='tar'
58         tarOpt='j'
59         ;;
60     *.tar.Z)
61         inputType='tar'
62         tarOpt='Z'
63         ;;
64     *.tar)
65         inputType='tar'
66         tarOpt=''
67         ;;
68     *)
69         echo "$0: Unknown input package type."
70         exit 1
71         ;;
72     esac
73     inputPackage=$1
74 else
75     echo "$0: No input package found for $1"
76     exit 1
77 fi
78
79 if [ $inputType = 'dir' ]; then
80     listCmd="find $inputPackage -type f -print | sed -e 's;^$1/*;;'"
81     copyCmd="cp"
82     if [ $verboseMode -ne 0 ]; then
83         copyCmd="$copyCmd -v"
84     fi
85     copyCmd="$copyCmd -r $inputPackage/* ."
86 elif [ $inputType = 'zip' ]; then
87     listCmd="unzip -l -qq $inputPackage | awk 'BEGIN{OFS=\"\"}{\$1=\"\"; \$2=\"\"; \$3=\"\"; print \$0}'"
88     copyCmd="unzip"
89     if [ $verboseMode -ne 1 ]; then
90         copyCmd="$copyCmd -q"
91     fi
92     copyCmd="$copyCmd $inputPackage.zip"
93 elif [ $inputType = 'tar' ]; then
94     listCmd="tar -t${tarOpt}f $inputPackage"
95     copyCmd="tar"
96     if [ $verboseMode -ne 0 ]; then
97         copyCmd="$copyCmd -v"
98     fi
99     copyCmd="$copyCmd -x${tarOpt}f $inputPackage"
100 fi
101
102 if [ $verboseMode -eq 1 ]; then
103     echo "Opening files in Perforce for edit."
104 fi
105 discardOutput=''
106 if [ $verboseMode -eq 0 ]; then
107     discardOutput=' > /dev/null'
108 fi
109 #eval $listCmd | cat
110 eval $listCmd | p4 -x - edit $discardOutput
111 if [ $? -ne 0 ]; then
112     echo "$0: There was an error opening files in Perforce for edit."
113     echo "Make sure you are in the right directory and try again."
114     exit 1
115 fi
116
117 if [ $verboseMode -eq 1 ]; then
118     echo "$0: Copying files to the target directories."
119 fi
120 #echo $copyCmd
121 eval $copyCmd
122 if [ $? -ne 0 ]; then
123     echo "$0: Error copying files."
124     exit 1
125 fi