Allow change to a top-level directory within $GIT_REPO_DIR by prefixing the arg with '/'. Comes with tab completion. For example, if you have a directory ~/src/rails, you can move here by typing 's /ra[TAB]'
This commit is contained in:
@@ -29,6 +29,9 @@
|
|||||||
# - Produce a count of repos for each host: 'git_index --count-by-host'
|
# - Produce a count of repos for each host: 'git_index --count-by-host'
|
||||||
# - Run a custom command for each repo: 'git_index --batch-cmd <command>'
|
# - Run a custom command for each repo: 'git_index --batch-cmd <command>'
|
||||||
#
|
#
|
||||||
|
# * You can also change to a top-level directory within $GIT_REPO_DIR by prefixing the argument
|
||||||
|
# with '/'
|
||||||
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
#
|
#
|
||||||
# $ git_index --list
|
# $ git_index --list
|
||||||
@@ -52,7 +55,7 @@ function git_index() {
|
|||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
# Just change to $GIT_REPO_DIR if no params given.
|
# Just change to $GIT_REPO_DIR if no params given.
|
||||||
cd $GIT_REPO_DIR
|
cd $GIT_REPO_DIR
|
||||||
else
|
else
|
||||||
if [ "$1" = "--rebuild" ]; then
|
if [ "$1" = "--rebuild" ]; then
|
||||||
_rebuild_git_index
|
_rebuild_git_index
|
||||||
elif [ "$1" = "--update-all" ]; then
|
elif [ "$1" = "--update-all" ]; then
|
||||||
@@ -71,6 +74,12 @@ function git_index() {
|
|||||||
sed -e "s/\(\([^/]*\/\/\)\?\([^@]*@\)\?\([^:/]*\)\).*/\1/" |
|
sed -e "s/\(\([^/]*\/\/\)\?\([^@]*@\)\?\([^:/]*\)\).*/\1/" |
|
||||||
sort | uniq -c
|
sort | uniq -c
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
# If $1 starts with '/', change to top-level directory within $GIT_REPO_DIR
|
||||||
|
elif ([ $shell = "bash" ] && [ "${1:0:1}" = "/" ]) || \
|
||||||
|
([ $shell = "zsh" ] && [ "${1[1]}" = "/" ]); then
|
||||||
|
if [ -d "$GIT_REPO_DIR$1" ]; then cd "$GIT_REPO_DIR$1"; fi
|
||||||
|
|
||||||
else
|
else
|
||||||
_check_git_index
|
_check_git_index
|
||||||
# Figure out which directory we need to change to.
|
# Figure out which directory we need to change to.
|
||||||
@@ -231,7 +240,13 @@ function _git_index_tab_completion() {
|
|||||||
if [[ -n "$base_path" && $curw == */* ]]; then
|
if [[ -n "$base_path" && $curw == */* ]]; then
|
||||||
local search_path=$(echo "$curw" | sed "s:^${project/\\/\\\\\\}::")
|
local search_path=$(echo "$curw" | sed "s:^${project/\\/\\\\\\}::")
|
||||||
COMPREPLY=($(compgen -d "$base_path$search_path" | grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" ))
|
COMPREPLY=($(compgen -d "$base_path$search_path" | grep -v "/.git" | sed -e "s:$base_path:$project:" -e "s:$:/:" ))
|
||||||
# Else, tab complete all the entries in .git_index, plus '--' commands
|
|
||||||
|
# If curr string starts with /, tab complete top-level directories in root project dir
|
||||||
|
elif ([ $shell = "bash" ] && [ "${curw:0:1}" = "/" ]) || \
|
||||||
|
([ $shell = "zsh" ] && [ "${curw[1]}" = "/" ]); then
|
||||||
|
COMPREPLY=($(compgen -d "$GIT_REPO_DIR$curw" | sed -e "s:$GIT_REPO_DIR/::" -e "s:^:/:"))
|
||||||
|
|
||||||
|
# Else, tab complete the entries in .git_index, plus '--' commands
|
||||||
else
|
else
|
||||||
local commands="--list\n--rebuild\n--update-all\n--batch-cmd\n--count-by-host"
|
local commands="--list\n--rebuild\n--update-all\n--batch-cmd\n--count-by-host"
|
||||||
COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)$(echo -e "\n"$commands)' -- $curw))
|
COMPREPLY=($(compgen -W '$(sed -e "s:.*/::" -e "s:$:/:" "$GIT_REPO_DIR/.git_index" | sort)$(echo -e "\n"$commands)' -- $curw))
|
||||||
|
|||||||
@@ -179,6 +179,14 @@ test_git_index_tab_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Test changing to top-level directory (when arg begins with '/')
|
||||||
|
test_changing_to_top_level_directory() {
|
||||||
|
mkdir "$GIT_REPO_DIR/gems"
|
||||||
|
git_index "/gems"
|
||||||
|
assertEquals "$GIT_REPO_DIR/gems" "$PWD"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# load and run shUnit2
|
# load and run shUnit2
|
||||||
# Call this function to run tests
|
# Call this function to run tests
|
||||||
. "$scmbDir/test/support/shunit2"
|
. "$scmbDir/test/support/shunit2"
|
||||||
|
|||||||
Reference in New Issue
Block a user