Skip to content
Snippets Groups Projects
Commit cf930b24 authored by Thomas Arendsen Hein's avatar Thomas Arendsen Hein
Browse files

Cleanup of spacing in bash_completion

parent 063e0483
No related branches found
No related tags found
No related merge requests found
...@@ -4,23 +4,23 @@ ...@@ -4,23 +4,23 @@
{ {
"$hg" --debug help 2>/dev/null | \ "$hg" --debug help 2>/dev/null | \
awk 'function command_line(line) { awk 'function command_line(line) {
gsub(/,/, "", line) gsub(/,/, "", line)
gsub(/:.*/, "", line) gsub(/:.*/, "", line)
split(line, aliases) split(line, aliases)
command = aliases[1] command = aliases[1]
delete aliases[1] delete aliases[1]
print command print command
for (i in aliases) for (i in aliases)
if (index(command, aliases[i]) != 1) if (index(command, aliases[i]) != 1)
print aliases[i] print aliases[i]
} }
/^list of commands:/ {commands=1} /^list of commands:/ {commands=1}
commands && /^ debug/ {a[i++] = $0; next;} commands && /^ debug/ {a[i++] = $0; next;}
commands && /^ [^ ]/ {command_line($0)} commands && /^ [^ ]/ {command_line($0)}
/^global options:/ {exit 0} /^global options:/ {exit 0}
END {for (i in a) command_line(a[i])}' END {for (i in a) command_line(a[i])}'
} }
_hg_option_list() _hg_option_list()
{ {
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
} }
_hg_option_list() _hg_option_list()
{ {
"$hg" -v help $1 2> /dev/null | \ "$hg" -v help $1 2>/dev/null | \
awk '/^ *-/ { awk '/^ *-/ {
for (i = 1; i <= NF; i ++) { for (i = 1; i <= NF; i ++) {
if (index($i, "-") != 1) if (index($i, "-") != 1)
...@@ -30,3 +30,3 @@ ...@@ -30,3 +30,3 @@
if (index($i, "-") != 1) if (index($i, "-") != 1)
break; break;
print $i; print $i;
...@@ -32,6 +32,6 @@ ...@@ -32,6 +32,6 @@
print $i; print $i;
} }
}' }'
} }
...@@ -56,10 +56,10 @@ ...@@ -56,10 +56,10 @@
_hg_paths() _hg_paths()
{ {
local paths="$("$hg" paths 2> /dev/null | sed -e 's/ = .*$//')" local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"
COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W '$paths' -- "$cur" )) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$paths' -- "$cur"))
} }
_hg_repos() _hg_repos()
{ {
local i local i
...@@ -61,12 +61,12 @@ ...@@ -61,12 +61,12 @@
} }
_hg_repos() _hg_repos()
{ {
local i local i
for i in $( compgen -d -- "$cur" ); do for i in $(compgen -d -- "$cur"); do
test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i") test ! -d "$i"/.hg || COMPREPLY=(${COMPREPLY[@]:-} "$i")
done done
} }
_hg_status() _hg_status()
{ {
...@@ -68,11 +68,11 @@ ...@@ -68,11 +68,11 @@
done done
} }
_hg_status() _hg_status()
{ {
local files="$( "$hg" status -n$1 . 2> /dev/null)" local files="$("$hg" status -n$1 . 2>/dev/null)"
COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W '$files' -- "$cur" )) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$files' -- "$cur"))
} }
_hg_tags() _hg_tags()
{ {
...@@ -75,10 +75,10 @@ ...@@ -75,10 +75,10 @@
} }
_hg_tags() _hg_tags()
{ {
local tags="$("$hg" tags 2> /dev/null | local tags="$("$hg" tags 2>/dev/null |
sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur") ) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$tags' -- "$cur"))
} }
# this is "kind of" ugly... # this is "kind of" ugly...
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
local i count=0 local i count=0
local filters="$1" local filters="$1"
for (( i=1; $i<=$COMP_CWORD; i++ )); do for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ "${COMP_WORDS[i]}" != -* ]]; then if [[ "${COMP_WORDS[i]}" != -* ]]; then
if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
continue continue
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
# searching for the command # searching for the command
# (first non-option argument that doesn't follow a global option that # (first non-option argument that doesn't follow a global option that
# receives an argument) # receives an argument)
for (( i=1; $i<=$COMP_CWORD; i++ )); do for ((i=1; $i<=$COMP_CWORD; i++)); do
if [[ ${COMP_WORDS[i]} != -* ]]; then if [[ ${COMP_WORDS[i]} != -* ]]; then
if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
cmd="${COMP_WORDS[i]}" cmd="${COMP_WORDS[i]}"
...@@ -125,7 +125,7 @@ ...@@ -125,7 +125,7 @@
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
opts=$(_hg_option_list $cmd) opts=$(_hg_option_list $cmd)
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur") ) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$opts' -- "$cur"))
return return
fi fi
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
fi fi
# canonicalize command name # canonicalize command name
cmd=$("$hg" -q help "$cmd" 2> /dev/null | sed -e 's/^hg //; s/ .*//; 1q') cmd=$("$hg" -q help "$cmd" 2>/dev/null | sed -e 's/^hg //; s/ .*//; 1q')
if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then
_hg_tags _hg_tags
...@@ -191,6 +191,6 @@ ...@@ -191,6 +191,6 @@
if [ $count = 1 ]; then if [ $count = 1 ]; then
_hg_paths _hg_paths
fi fi
_hg_repos _hg_repos
;; ;;
debugindex|debugindexdot) debugindex|debugindexdot)
...@@ -195,5 +195,5 @@ ...@@ -195,5 +195,5 @@
;; ;;
debugindex|debugindexdot) debugindex|debugindexdot)
COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.i" -- "$cur"))
;; ;;
debugdata) debugdata)
...@@ -198,8 +198,8 @@ ...@@ -198,8 +198,8 @@
;; ;;
debugdata) debugdata)
COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.d" -- "$cur" )) COMPREPLY=(${COMPREPLY[@]:-} $(compgen -f -X "!*.d" -- "$cur"))
;; ;;
esac esac
} }
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
;; ;;
esac esac
} }
complete -o bashdefault -o default -F _hg hg 2> /dev/null \ complete -o bashdefault -o default -F _hg hg 2>/dev/null \
|| complete -o default -F _hg hg || complete -o default -F _hg hg
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment