Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vcsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
vcsh
Commits
aeb2de1f
Commit
aeb2de1f
authored
7 years ago
by
Richard Hartmann
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #232 from rhopfer/feature-bash-completion
Add bash-completion
parents
36a7cedf
6d52838a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
_vcsh_bash
+138
-0
138 additions, 0 deletions
_vcsh_bash
with
138 additions
and
0 deletions
_vcsh_bash
0 → 100644
+
138
−
0
View file @
aeb2de1f
# bash completion for vcsh.
# run git command
# based on bash_completion:_command_offset()
_vcsh_git_command
()
{
local
word_offset
=
$1
for
((
i
=
0
;
i <
$word_offset
;
i++
))
;
do
for
((
j
=
0
;
j <
=
${#
COMP_LINE
}
;
j++
))
;
do
[[
"
$COMP_LINE
"
==
"
${
COMP_WORDS
[i]
}
"
*
]]
&&
break
COMP_LINE
=
${
COMP_LINE
:1
}
((
COMP_POINT--
))
done
COMP_LINE
=
${
COMP_LINE
#
"
${
COMP_WORDS
[i]
}
"
}
((
COMP_POINT-
=
${#
COMP_WORDS
[i]
}
))
done
COMP_LINE
=
"git
$COMP_LINE
"
((
COMP_POINT+
=
4
))
# shift COMP_WORDS elements and adjust COMP_CWORD
for
((
i
=
1
;
i <
=
COMP_CWORD -
$word_offset
+ 1
;
i++
))
;
do
COMP_WORDS[i]
=
${
COMP_WORDS
[i+
$word_offset
-1]
}
done
for
((
i
;
i <
=
COMP_CWORD
;
i++
))
;
do
unset
'COMP_WORDS[i]'
done
COMP_WORDS[0]
=
git
((
COMP_CWORD -
=
$word_offset
- 1
))
local
cspec
=
$(
complete
-p
git 2>/dev/null
)
if
[[
-n
$cspec
]]
;
then
if
[[
${
cspec
#* -F
}
!=
$cspec
]]
;
then
local
func
=
${
cspec
#*-F
}
func
=
${
func
%% *
}
if
[[
${#
COMP_WORDS
[@]
}
-ge
2
]]
;
then
$func
git
"
${
COMP_WORDS
[
${#
COMP_WORDS
[@]
}
-1]
}
"
"
${
COMP_WORDS
[
${#
COMP_WORDS
[@]
}
-2]
}
"
else
$func
git
"
${
COMP_WORDS
[
${#
COMP_WORDS
[@]
}
-1]
}
"
fi
# restore initial compopts
local
opt
while
[[
$cspec
==
*
" -o "
*
]]
;
do
# FIXME: should we take "+o opt" into account?
cspec
=
${
cspec
#*-o
}
opt
=
${
cspec
%% *
}
compopt
-o
$opt
cspec
=
${
cspec
#
$opt
}
done
fi
fi
}
_vcsh
()
{
local
cur prev words cword OPTS
_init_completion
-n
=
||
return
local
repos cmds
repos
=(
$(
command
vcsh list
)
)
cmds
=
"clone delete enter foreach help init list list-tracked list-untracked
pull push rename run status upgrade version which write-gitignore"
local
subcword cmd subcmd
for
((
subcword
=
1
;
subcword <
${#
words
[@]
}
-1
;
subcword++
))
;
do
[[
-n
$cmd
&&
${
words
[subcword]
}
!=
-
*
]]
&&
subcmd
=
${
words
[subcword]
}
&&
break
[[
${
words
[subcword]
}
!=
-
*
]]
&&
cmd
=
${
words
[subcword]
}
done
if
[[
-z
$cmd
]]
;
then
case
$prev
in
-c
)
COMPREPLY
=(
$(
compgen
-f
--
$cur
)
)
return
;;
esac
case
$cur
in
-
*
)
OPTS
=
'-c -d -h -v'
COMPREPLY
=(
$(
compgen
-W
"
${
OPTS
[*]
}
"
--
$cur
)
)
return
;;
esac
COMPREPLY
=(
$(
compgen
-W
"
${
repos
[*]
}
${
cmds
[*]
}
"
--
$cur
)
)
return
0
fi
case
$cmd
in
help
|
init|list|pull|push|version|which
)
return
;;
list-untracked
)
[[
$cur
==
-
*
]]
&&
\
COMPREPLY
=(
$(
compgen
-W
'-a -r'
--
$cur
)
)
&&
return
;;
&
run
)
if
[[
-n
$subcmd
&&
-n
"
${
repos
[
$subcmd
]
}
"
]]
;
then
_command_offset
$((
$subcword
+
1
))
return
fi
;;
&
delete|enter|list-tracked|list-untracked|rename|run|status|upgrade|write-gitignore
)
# return repos
if
[[
-z
$subcmd
]]
;
then
COMPREPLY
=(
$(
compgen
-W
"
${
repos
[*]
}
"
--
$cur
)
)
return
fi
return
;;
clone
)
[[
$cur
==
-
*
]]
&&
\
COMPREPLY
=(
$(
compgen
-W
'-b'
--
$cur
)
)
return
;;
foreach
)
[[
$cur
==
-
*
]]
\
&&
COMPREPLY
=(
$(
compgen
-W
"-g"
--
$cur
)
)
&&
return
_vcsh_git_command
$subcword
return
;;
esac
# git command on repository
if
[[
-n
"
${
repos
[
$cmd
]
}
"
]]
;
then
_vcsh_git_command
$subcword
fi
return
0
}
complete
-F
_vcsh vcsh
# vim: ft=sh:
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment