Skip to main content
Sign in
Snippets Groups Projects
Commit 6fc7778e authored by Kevin Lyda's avatar Kevin Lyda
Browse files

Merge branch 'master' into commit-alias

parents a47acce4 cb335460
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ function _vcsh-enter () { ...@@ -24,7 +24,7 @@ function _vcsh-enter () {
} }
function _vcsh-foreach () { function _vcsh-foreach () {
_dispatch git git _dispatch vcsh-foreach git
} }
function _vcsh-help () { function _vcsh-help () {
...@@ -63,10 +63,12 @@ function _vcsh-rename () { ...@@ -63,10 +63,12 @@ function _vcsh-rename () {
function _vcsh-run () { function _vcsh-run () {
(( CURRENT == 2 )) && __vcsh_repositories (( CURRENT == 2 )) && __vcsh_repositories
if (( CURRENT >= 3 )); then (( CURRENT == 3 )) && _command_names -e
if (( CURRENT >= 4 )); then
# see _precommand in zsh
words=( "${(@)words[3,-1]}" ) words=( "${(@)words[3,-1]}" )
(( CURRENT -= 2 )) (( CURRENT -= 2 ))
_complete _normal
fi fi
} }
...@@ -95,6 +97,9 @@ function _vcsh () { ...@@ -95,6 +97,9 @@ function _vcsh () {
local state vcshcommand local state vcshcommand
local -a args subcommands local -a args subcommands
local VCSH_REPO_D
: ${VCSH_REPO_D:="${XDG_CONFIG_HOME:-"$HOME/.config"}/vcsh/repo.d"}
subcommands=( subcommands=(
"clone:clone an existing repository" "clone:clone an existing repository"
"commit:commit in all repositories" "commit:commit in all repositories"
...@@ -135,10 +140,11 @@ function _vcsh () { ...@@ -135,10 +140,11 @@ function _vcsh () {
if ! (( ${+functions[_vcsh-$vcshcommand]} )); then if ! (( ${+functions[_vcsh-$vcshcommand]} )); then
# There is no handler function, so this is probably the name # There is no handler function, so this is probably the name
# of a repository. Act accordingly. # of a repository. Act accordingly.
_dispatch git git # FIXME: this may want to use '_dispatch vcsh git'
GIT_DIR=$VCSH_REPO_D/$words[1].git _dispatch git git
else else
curcontext="${curcontext%:*:*}:vcsh-${vcshcommand}:" curcontext="${curcontext%:*:*}:vcsh-${vcshcommand}:"
_call_function ret _vcsh-${vcshcommand} _call_function ret _vcsh-${vcshcommand} && (( ret ))
fi fi
fi fi
fi fi
... ...
......
# 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:
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
2011-11-19 Richard Hartmann <richih.mailinglist@gmail.com> 2011-11-19 Richard Hartmann <richih.mailinglist@gmail.com>
* Bugfixes * Bugfixes
* Improve XDG compability * Improve XDG compatibility
2011-11-18 Richard Hartmann <richih.mailinglist@gmail.com> 2011-11-18 Richard Hartmann <richih.mailinglist@gmail.com>
... ...
......
...@@ -293,7 +293,7 @@ Note the portage package for myrepos still has the old project name: ...@@ -293,7 +293,7 @@ Note the portage package for myrepos still has the old project name:
vcsh is available via this [AUR](https://aur.archlinux.org/packages/vcsh/) vcsh is available via this [AUR](https://aur.archlinux.org/packages/vcsh/)
package. Likewise myrepos is available [here](https://aur.archlinux.org/packages/myrepos/). package. Likewise myrepos is available [here](https://aur.archlinux.org/packages/myrepos/).
You may install both useing your favorite AUR helper. e.g. with yaourt: You may install both using your favorite AUR helper. e.g. with yaourt:
yaourt -Sya myrepos vcsh yaourt -Sya myrepos vcsh
... ...
......
...@@ -98,7 +98,7 @@ an interactive user. ...@@ -98,7 +98,7 @@ an interactive user.
Delete an existing repository. Delete an existing repository.
* enter: * enter:
Enter repository; spawn new <$SHELL>. Enter repository; spawn new <$SHELL> with <$GIT_DIR> set.
* foreach: * foreach:
Execute git command for every vcsh repository. Execute git command for every vcsh repository.
...@@ -173,7 +173,7 @@ an interactive user. ...@@ -173,7 +173,7 @@ an interactive user.
Write .gitignore.d/<repo> via `git ls-files`. Write .gitignore.d/<repo> via `git ls-files`.
* <repo> <gitcommand>: * <repo> <gitcommand>:
Shortcut to run `vcsh` on a repo. Will prepend `git` to <command>. Shortcut to run `git` commands on a repo. Will prepend `git` to <gitcommand>.
* <repo>: * <repo>:
Shortcut to run `vcsh enter <repo>`. Shortcut to run `vcsh enter <repo>`.
...@@ -220,7 +220,7 @@ Interesting knobs you can turn: ...@@ -220,7 +220,7 @@ Interesting knobs you can turn:
Defaults to <exact>. Defaults to <exact>.
* <$VCSH_VCSH_WORKTREE>: * <$VCSH_WORKTREE>:
Can be <absolute>, or <relative>. Can be <absolute>, or <relative>.
<absolute> will set an absolute path; defaulting to <$HOME>. <absolute> will set an absolute path; defaulting to <$HOME>.
...@@ -338,7 +338,7 @@ config files, all of which were soft-linked into <$HOME>. ...@@ -338,7 +338,7 @@ config files, all of which were soft-linked into <$HOME>.
Martin F. Krafft aka madduck came up with the concept of fake bare Git Martin F. Krafft aka madduck came up with the concept of fake bare Git
repositories. repositories.
vcsh was initally written by madduck. This version is a re-implementation from vcsh was initially written by madduck. This version is a re-implementation from
scratch with a lot more features. madduck graciously agreed to let the author scratch with a lot more features. madduck graciously agreed to let the author
take over the name. take over the name.
... ...
......
...@@ -18,7 +18,7 @@ ok $output eq "", 'No repos set up yet.'; ...@@ -18,7 +18,7 @@ ok $output eq "", 'No repos set up yet.';
$output = `./vcsh init test1`; $output = `./vcsh init test1`;
ok $output eq "Initialized empty shared Git repository in " . $ENV{'HOME'} . "/.config/vcsh/repo.d/test1.git/\n"; ok $output eq "Initialized empty Git repository in " . $ENV{'HOME'} . "/.config/vcsh/repo.d/test1.git/\n";
$output = `./vcsh status`; $output = `./vcsh status`;
... ...
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
VERSION='1.20141026' VERSION='1.20141026'
SELF=$(basename $0) SELF=$(basename $0)
# Ensure all files created are accessible only to the current user.
umask 0077
fatal() { fatal() {
echo "$SELF: fatal: $1" >&2 echo "$SELF: fatal: $1" >&2
[ -z $2 ] && exit 1 [ -z $2 ] && exit 1
...@@ -106,6 +109,7 @@ help() { ...@@ -106,6 +109,7 @@ 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
with \$GIT_DIR set.
foreach [<-g>] foreach [<-g>]
<git command> Execute a command for every repository <git command> Execute a command for every repository
help Display this help text help Display this help text
...@@ -162,7 +166,7 @@ clone() { ...@@ -162,7 +166,7 @@ clone() {
You should add files to your new repository." You should add files to your new repository."
exit exit
fi fi
GIT_VERSION_MAJOR=$(git --version | sed -n 's/.* \([0-9]\)\..*/\1/p' ) GIT_VERSION_MAJOR=$(git --version | sed -E -n 's/.* ([0-9]+)\..*/\1/p' )
if [ 1 -lt "$GIT_VERSION_MAJOR" ];then if [ 1 -lt "$GIT_VERSION_MAJOR" ];then
git fetch origin "$VCSH_BRANCH" git fetch origin "$VCSH_BRANCH"
else else
...@@ -186,11 +190,12 @@ clone() { ...@@ -186,11 +190,12 @@ clone() {
commit() { commit() {
hook pre-commit hook pre-commit
shift # remove the "commit" command.
for VCSH_REPO_NAME in $(list); do for VCSH_REPO_NAME in $(list); do
echo "$VCSH_REPO_NAME: " echo "$VCSH_REPO_NAME: "
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
use use
git commit --untracked-files=no --quiet $@ git commit --untracked-files=no --quiet "$@"
VCSH_COMMAND_RETURN_CODE=$? VCSH_COMMAND_RETURN_CODE=$?
echo echo
done done
...@@ -261,7 +266,7 @@ init() { ...@@ -261,7 +266,7 @@ init() {
[ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10 [ ! -e "$GIT_DIR" ] || fatal "'$GIT_DIR' exists" 10
mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50 mkdir -p "$VCSH_BASE" || fatal "could not create '$VCSH_BASE'" 50
cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11 cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
git init --shared=0600 git init --shared=false
upgrade upgrade
hook post-init hook post-init
} }
...@@ -274,7 +279,7 @@ list() { ...@@ -274,7 +279,7 @@ list() {
get_files() { get_files() {
GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR GIT_DIR=$VCSH_REPO_D/$VCSH_REPO_NAME.git; export GIT_DIR
git ls-files git ls-files --full-name
} }
list_tracked() { list_tracked() {
...@@ -477,8 +482,8 @@ write_gitignore() { ...@@ -477,8 +482,8 @@ write_gitignore() {
use use
cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11 cd "$VCSH_BASE" || fatal "could not enter '$VCSH_BASE'" 11
local GIT_VERSION="$(git --version)" local GIT_VERSION="$(git --version)"
local GIT_VERSION_MAJOR=$(echo $GIT_VERSION | sed -n 's/.* \([0-9]\)\..*/\1/p') local GIT_VERSION_MAJOR=$(echo $GIT_VERSION | sed -E -n 's/.* ([0-9]+)\..*/\1/p')
local GIT_VERSION_MINOR=$(echo $GIT_VERSION | sed -n 's/.* \([0-9]\)\.\([0-9]\)\..*/\2/p') local GIT_VERSION_MINOR=$(echo $GIT_VERSION | sed -E -n 's/.* ([0-9]+)\.([0-9]+)\..*/\2/p')
OLDIFS=$IFS OLDIFS=$IFS
IFS=$(printf '\n\t') IFS=$(printf '\n\t')
gitignores=$(for file in $(git ls-files); do gitignores=$(for file in $(git ls-files); do
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment