Skip to content
Snippets Groups Projects
Commit 84136a71 authored by Richard Hartmann's avatar Richard Hartmann
Browse files

Merge branch 'feature/foreach'

parents 29b6c287 2cc7ffcd
Branches
Tags
No related merge requests found
...@@ -23,6 +23,10 @@ function _vcsh-enter () { ...@@ -23,6 +23,10 @@ function _vcsh-enter () {
(( CURRENT == 2 )) && __vcsh_repositories (( CURRENT == 2 )) && __vcsh_repositories
} }
function _vcsh-foreach () {
_dispatch git git
}
function _vcsh-help () { function _vcsh-help () {
_nothing _nothing
} }
...@@ -96,6 +100,7 @@ function _vcsh () { ...@@ -96,6 +100,7 @@ function _vcsh () {
"commit:commit in all repositories" "commit:commit in all repositories"
"delete:delete an existing repository" "delete:delete an existing repository"
"enter:enter repository; spawn new <\$SHELL>" "enter:enter repository; spawn new <\$SHELL>"
"foreach:execute for all repos"
"help:display help" "help:display help"
"init:initialize an empty repository" "init:initialize an empty repository"
"list:list all local vcsh repositories" "list:list all local vcsh repositories"
......
...@@ -11,6 +11,8 @@ vcsh(1) - Version Control System for $HOME - multiple Git repositories in $HOME ...@@ -11,6 +11,8 @@ vcsh(1) - Version Control System for $HOME - multiple Git repositories in $HOME
`vcsh` enter <repo> `vcsh` enter <repo>
`vcsh` foreach [-g] <git command>
`vcsh` help `vcsh` help
`vcsh` init <repo> `vcsh` init <repo>
...@@ -98,6 +100,11 @@ an interactive user. ...@@ -98,6 +100,11 @@ an interactive user.
* enter: * enter:
Enter repository; spawn new <$SHELL>. Enter repository; spawn new <$SHELL>.
* foreach:
Execute git command for every vcsh repository.
`-g`: Execute in general context.
* help: * help:
Display help. Display help.
......
...@@ -106,6 +106,8 @@ help() { ...@@ -106,6 +106,8 @@ help() {
commit Commit in all repositories commit Commit in all repositories
delete <repo> Delete an existing repository delete <repo> Delete an existing repository
enter <repo> Enter repository; spawn new instance of \$SHELL enter <repo> Enter repository; spawn new instance of \$SHELL
foreach [<-g>]
<git command> Execute a command for every repository
help Display this help text help Display this help text
init <repo> Initialize a new repository init <repo> Initialize a new repository
list List all repositories list List all repositories
...@@ -216,6 +218,27 @@ enter() { ...@@ -216,6 +218,27 @@ enter() {
hook post-enter hook post-enter
} }
foreach() {
hook pre-foreach
# We default to prefixing `git` to all commands passed to foreach, but
# allow running in general context with -g
command_prefix=git
while getopts "g" flag; do
if [ x"$1" = x'-g' ]; then
unset command_prefix
fi
shift 1
done
for VCSH_REPO_NAME in $(list); do
echo "$VCSH_REPO_NAME:"
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
use
$command_prefix "$@"
done
hook post-foreach
}
git_dir_exists() { git_dir_exists() {
[ -d "$GIT_DIR" ] || fatal "no repository found for '$VCSH_REPO_NAME'" 12 [ -d "$GIT_DIR" ] || fatal "no repository found for '$VCSH_REPO_NAME'" 12
} }
...@@ -558,6 +581,9 @@ elif [ x"$VCSH_COMMAND" = x'delete' ] || ...@@ -558,6 +581,9 @@ elif [ x"$VCSH_COMMAND" = x'delete' ] ||
[ x"$VCSH_COMMAND" = x'rename' ] && { VCSH_REPO_NAME_NEW=$3; export VCSH_REPO_NAME_NEW; [ x"$VCSH_COMMAND" = x'rename' ] && { VCSH_REPO_NAME_NEW=$3; export VCSH_REPO_NAME_NEW;
GIT_DIR_NEW=$VCSH_REPO_D/$VCSH_REPO_NAME_NEW.git; export GIT_DIR_NEW; } GIT_DIR_NEW=$VCSH_REPO_D/$VCSH_REPO_NAME_NEW.git; export GIT_DIR_NEW; }
[ x"$VCSH_COMMAND" = x'run' ] && shift 2 [ x"$VCSH_COMMAND" = x'run' ] && shift 2
elif [ x"$VCSH_COMMAND" = x'foreach' ]; then
[ -z "$2" ] && fatal "$VCSH_COMMAND: please specify a command" 1
shift 1
elif [ x"$VCSH_COMMAND" = x'commit' ] || elif [ x"$VCSH_COMMAND" = x'commit' ] ||
[ x"$VCSH_COMMAND" = x'list' ] || [ x"$VCSH_COMMAND" = x'list' ] ||
[ x"$VCSH_COMMAND" = x'list-tracked' ] || [ x"$VCSH_COMMAND" = x'list-tracked' ] ||
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment