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 |
|