ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yiiyama/Toolset/scripts/castorcomp
Revision: 1.1
Committed: Tue Apr 3 08:44:56 2012 UTC (13 years, 1 month ago) by yiiyama
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 yiiyama 1.1 #!/bin/bash
2     #to be used with nsls
3    
4     _castorcomp()
5     {
6     local curw
7     list=""
8    
9     COMPREPLY=()
10     curw=${COMP_WORDS[COMP_CWORD]}
11    
12     if [ -z "$curw" ]; then
13     list="/castor/cern.ch/"
14     else
15     path=$(echo "$curw" | sed -n -r 's|^(.*)[/][^/]*$|\1|p')
16     name=$(echo "$curw" | sed -r 's|([^/]*)$|/ \1|' | awk '{print $2}')
17    
18     insertion=""
19     if [ -n "$name" ]; then
20     insertion="${path}/"
21     fi
22    
23     lines=$(nsls -l $path)
24     ifsorig=$IFS
25     IFS=$'\n'
26     for line in $lines; do
27     type="${line:0:1}"
28     file="$(echo $line | sed -r 's/^.*[ ]([^ ]+)$/\1/')"
29     if [ -z "$name" -o -n "$(echo $file | grep '^'$name'')" ]; then
30     if [ $type == "d" ]; then
31     list="${list}${insertion}${file}/ "
32     else
33     list="${list}${insertion}${file} "
34     fi
35     fi
36     done
37     IFS=$ifsorig
38    
39     if [ -z "$list" ]; then
40     list=$curw
41     fi
42     fi
43    
44     COMPREPLY=($list)
45    
46     return 0
47     }
48    
49    
50