This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
hadoop-completion.sh
123 lines (103 loc) · 5.08 KB
/
hadoop-completion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Provides tab completion for the main hadoop script.
#
# On debian-based systems, place in /etc/bash_completion.d/ and either restart
# Bash or source the script manually (. /etc/bash_completion.d/hadoop.sh).
_complete_path() {
STERM="$1"
$2 fs -ls -d "${STERM}*" 2>/dev/null | grep -vE "^Found.*items" | sed -r -e 's/^(d.*)/\1\//' -e 's/.*[0-9:]{5,5} //'
}
_hadoop() {
local script cur prev temp
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
script=${COMP_WORDS[0]}
# Bash lets you tab complete things even if the script doesn't
# exist (or isn't executable). Check to make sure it is, as we
# need to execute it to get options/info
case $COMP_CWORD in
1)
# Completing the first argument (the command).
temp=`$script | grep -n "^\s*or"`;
temp=`$script | head -n $((${temp%%:*} - 1)) | awk '/^ / {print $1}' | sort | uniq`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
2)
# Completing the second arg (first arg to the command)
# The output of commands isn't hugely consistent, so certain
# names are hardcoded and parsed differently. Some aren't
# handled at all (mostly ones without args).
case ${COMP_WORDS[1]} in
dfs | dfsadmin | fs | job | pipes | mradmin)
# One option per line, enclosed in square brackets
temp=`$script ${COMP_WORDS[1]} 2>&1 | awk '/^[ \t]*\[/ {gsub(/[\[\]]/, ""); print $1}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
jar)
# Any (jar) file
COMPREPLY=(`compgen -A file -- ${cur}`);
return 0;;
namenode | jobtracker)
# All options specified in the Usage line from "haooop namenode --help"
# enclosed in [] and separated with |
temp=`$script ${COMP_WORDS[1]} --help 2>&1 | grep -i "Usage:" | cut -d '[' -f 2- | awk '{gsub(/[\[\] \t\|]/, " "); print}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
datanode)
# All options specified in the Usage line from "hadoop datanode --help"
# note that the options are provided on a separate new line
temp=`$script ${COMP_WORDS[1]} --help 2>&1 | awk '/Usage:/ {getline; gsub(/[\[\]]/, ""); print}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
fsck)
temp=`$script ${COMP_WORDS[1]} 2>&1 | grep -i "Usage:" | cut -d '>' -f 2 | awk '{gsub(/[\[\]\|]/, ""); print}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
balancer)
temp=`$script ${COMP_WORDS[1]} --help 2>&1 | awk '/Usage:/ {getline; gsub(/[\[\]]/, ""); gsub(/<.*/, ""); print}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
fetchdt)
temp=`$script ${COMP_WORDS[1]} 2>&1 | awk '/\s*-{2}/ {print $1}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
pipes | job | queue)
temp=`$script ${COMP_WORDS[1]} 2>&1 | awk '/\s*\[-/ {gsub(/\[/, ""); print $1}'`;
COMPREPLY=(`compgen -W "${temp}" -- ${cur}`);
return 0;;
*)
# Other commands - no idea
return 1;;
esac;;
*)
# Completing the third, fourth, etc arg.
# We complete it only for commands that take HDFS paths
# as their arguments.
case ${COMP_WORDS[1]} in
dfs | dfsadmin | fs | job | pipes | mradmin)
# One option per line, enclosed in square brackets
temp=`_complete_path "${cur}" "${script}"`;
COMPREPLY=(`compgen -o filenames -W "${temp}" -- ${cur}`);
compopt -o nospace -o filenames
return 0;;
*)
return 1;;
esac;;
esac;
}
complete -F _hadoop hadoop