Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,27 @@ and `git commit`, use the vcsh wrapper (like above):
vcsh foo commit
vcsh foo push

### Using vcsh in directories other than $HOME

You can use `vcsh` in an agnostic manner by changing the `$VCSH_BASE`
and `$XDG_CONFIG_HOME` variables to the desired git working directory
and `vcsh` config directory respectively. These variables can be
changed a hierarchy of config files documented in the manpage, the
agnostic file being `./.config/vcsh/config`.

If the current working directory has a `.config` folder with the necessary `vcsh`
config file, it will be automatically sourced. You can execute `vcsh
where` to print out the values of the above two variables.

Setting this up for a local folder is easy, just run `vcsh
setup`. This will create `./.config/vcsh/config` with `$VCSH_BASE` set
to `$(pwd)` and `$XDG_CONFIG_HOME` set to `$(pwd)/.config`. Now, when
`vcsh` is run in this folder, it will track files in the folder, and
use the local `.config` folder for `mr` and `repos.d`.

Please note that `vcsh` will default back to `$HOME` if run in a
sub-directory. It must be run from the root folder you wish to track.

### Using vcsh without myrepos

vcsh encourages you to use [myrepos][myrepos]. It helps you manage a large number of
Expand Down
19 changes: 19 additions & 0 deletions doc/vcsh.1.ronn
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ vcsh(1) - Version Control System for $HOME - multiple Git repositories in $HOME

`vcsh` run <repo> <shell command>

`vcsh` setup

`vcsh` status [<repo>]

`vcsh` upgrade <repo>

`vcsh` version

`vcsh` where

`vcsh` which <substring>

`vcsh` write-gitignore <repo>
Expand Down Expand Up @@ -130,6 +134,16 @@ an interactive user.
This is needed to support mr and other scripts properly and of no concern to
an interactive user.

* setup:
Creates ./config/vcsh/config with <$VCSH_BASE> and
<$XDG_CONFIG_HOME> variables set to `$(dir)` and `$(dir)/.config`
respectively. Allows for agnostic `vcsh` use in folders that are not
<$HOME>. Can also be run in <$HOME> for basic initial setup without
cloning the template.

`vcsh` will detect the configuration from any directory below the
setup directory. Use `vcsh where` to verify the above settings.

* status:
Show statuses of all/one vcsh repositories.

Expand All @@ -139,6 +153,10 @@ an interactive user.
* version:
Print version information.

* where:

Print base <$VCSH_BASE> and config <$XDG_CONFIG_HOME> variables.

* which <substring>:
Find <substring> in name of any tracked file.

Expand All @@ -164,6 +182,7 @@ ascending precedence, they are:
* `VARIABLE=foo vcsh`
* </etc/vcsh/config>
* <$XDG_CONFIG_HOME/vcsh/config>
* <./.config/vcsh/config>
* `vcsh -c <file>`

Please note that those files are sourced. Any and all commands will be
Expand Down
44 changes: 42 additions & 2 deletions vcsh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ source_all() {
esac;
}

find_dir_upwards() {
op="$1"
dir="$2"
(
while [ `pwd` != / ] ; do
if [ $op "$dir" ] ; then
pwd
return
fi
cd ..
done
)
}


# Read configuration and set defaults if anything's not set
[ -n "$VCSH_DEBUG" ] && set -vx
Expand All @@ -62,6 +76,12 @@ source_all() {
# Read configuration files if there are any
[ -r "/etc/vcsh/config" ] && . "/etc/vcsh/config"
[ -r "$XDG_CONFIG_HOME/vcsh/config" ] && . "$XDG_CONFIG_HOME/vcsh/config"
[ -r ".config/vcsh/config" ] && . ".config/vcsh/config"

# Look up the directory tree for the appropriate flag
configdir=`find_dir_upwards -r .config/vcsh/config`
[ -n "$configdir" ] && . "$configdir/.config/vcsh/config"

if [ -n "$VCSH_OPTION_CONFIG" ]; then
# Source $VCSH_OPTION_CONFIG if it can be read and is in $PWD of $PATH
if [ -r "$VCSH_OPTION_CONFIG" ]; then
Expand Down Expand Up @@ -114,9 +134,11 @@ help() {
<newname> Rename repository
run <repo> \\
<command> Use this repository
setup Create ./.config/vcsh/config for local vcsh use
status [<repo>] Show statuses of all/one vcsh repositories
upgrade <repo> Upgrade repository to currently recommended settings
version Print version information
where Print base and config directories
which <substring> Find substring in name of any tracked file
write-gitignore \\
<repo> Write .gitignore.d/<repo> via git ls-files
Expand Down Expand Up @@ -302,6 +324,14 @@ run() {
hook post-run
}

setup() {
mkdir -p .config/vcsh
echo "export VCSH_BASE=\"$(pwd)\"" >> .config/vcsh/config
echo "export XDG_CONFIG_HOME=\"$(pwd)/.config\"" >> .config/vcsh/config
echo "$SELF $VCSH_COMMAND: $SELF has been initialized in \"$(pwd)/.config\""
echo "$SELF will now track files locally if run from this directory"
}

status() {
if [ ! "x$VCSH_REPO_NAME" = "x" ]; then
export GIT_DIR="$VCSH_REPO_D/$VCSH_REPO_NAME.git"
Expand Down Expand Up @@ -347,6 +377,11 @@ use() {
export VCSH_DIRECTORY="$VCSH_REPO_NAME"
}

where() {
echo "\$VCSH_BASE is $VCSH_BASE"
echo "\$XDG_CONFIG_HOME is $XDG_CONFIG_HOME"
}

which() {
for VCSH_REPO_NAME in $(list); do
for VCSH_FILE in $(get_files); do
Expand Down Expand Up @@ -419,10 +454,12 @@ case "$VCSH_COMMAND" in
pus) VCSH_COMMAND=push;;
renam|rena|ren|re) VCSH_COMMAND=rename;;
ru) VCSH_COMMAND=run;;
setup|setu|set|se) VCSH_COMMAND=setup;;
statu|stat|sta|st) VCSH_COMMAND=status;;
upgrad|upgra|upgr|up) VCSH_COMMAND=upgrade;;
versio|versi|vers|ver|ve) VCSH_COMMAND=version;;
which|whi|wh) VCSH_COMMAND=which;;
where|whe) VCSH_COMMAND=where;;
which|whi) VCSH_COMMAND=which;;
write|writ|wri|wr) VCSH_COMMAND=write-gitignore;;
esac

Expand All @@ -437,6 +474,8 @@ elif [ "$VCSH_COMMAND" = 'version' ]; then
echo "$SELF $VERSION"
git version
exit
elif [ "$VCSH_COMMAND" = 'setup' ]; then
[ -r "./.config/vcsh/config" ] && fatal "$VCSH_COMMAND: .config already exists!"
elif [ "$VCSH_COMMAND" = 'which' ]; then
[ -z "$2" ] && fatal "$VCSH_COMMAND: please specify a filename" 1
[ -n "$3" ] && fatal "$VCSH_COMMAND: too many parameters" 1
Expand All @@ -461,7 +500,8 @@ elif [ "$VCSH_COMMAND" = 'commit' ] ||
[ "$VCSH_COMMAND" = 'list' ] ||
[ "$VCSH_COMMAND" = 'list-tracked' ] ||
[ "$VCSH_COMMAND" = 'pull' ] ||
[ "$VCSH_COMMAND" = 'push' ]; then
[ "$VCSH_COMMAND" = 'push' ] ||
[ "$VCSH_COMMAND" = 'where' ]; then
:
elif [ "$VCSH_COMMAND" = 'status' ]; then
export VCSH_REPO_NAME="$2"
Expand Down
24 changes: 23 additions & 1 deletion vcsh.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "VCSH" "1" "February 2014" "" ""
.TH "VCSH" "1" "March 2014" "" ""
.
.SH "NAME"
\fBvcsh\fR \- Version Control System for $HOME \- multiple Git repositories in $HOME
Expand Down Expand Up @@ -46,6 +46,9 @@
\fBvcsh\fR run \fIrepo\fR \fIshell command\fR
.
.P
\fBvcsh\fR setup
.
.P
\fBvcsh\fR status [\fIrepo\fR]
.
.P
Expand All @@ -55,6 +58,9 @@
\fBvcsh\fR version
.
.P
\fBvcsh\fR where
.
.P
\fBvcsh\fR which \fIsubstring\fR
.
.P
Expand Down Expand Up @@ -159,6 +165,13 @@ Run command with \fI$GIT_DIR\fR and \fI$GIT_WORK_TREE\fR set\. Allows you to run
Please note that there is a somewhat magic feature for run\. Instead of \fIrepo\fR it accepts \fIpath\fR, as well\. Anything that has a slash in it will be assumed to be a path\. \fBvcsh run\fR will then operate on this directory instead of the one normally generated from the repository\'s name\. This is needed to support mr and other scripts properly and of no concern to an interactive user\.
.
.TP
setup
Creates \./config/vcsh/config with \fI$VCSH_BASE\fR and \fI$XDG_CONFIG_HOME\fR variables set to \fB$(dir)\fR and \fB$(dir)/\.config\fR respectively\. Allows for agnostic \fBvcsh\fR use in folders that are not \fI$HOME\fR\. Can also be run in \fI$HOME\fR for basic initial setup without cloning the template\.
.
.IP
\fBvcsh\fR will detect the configuration from any directory below the setup directory\. Use \fBvcsh where\fR to verify the above settings\.
.
.TP
status
Show statuses of all/one vcsh repositories\.
.
Expand All @@ -171,6 +184,12 @@ version
Print version information\.
.
.TP
where:
.
.IP
Print base \fI$VCSH_BASE\fR and config \fI$XDG_CONFIG_HOME\fR variables\.
.
.TP
which \fIsubstring\fR
Find \fIsubstring\fR in name of any tracked file\.
.
Expand Down Expand Up @@ -202,6 +221,9 @@ There are several ways to turn the various knobs on \fBvcsh\fR\. In order of asc
<$XDG_CONFIG_HOME/vcsh/config>
.
.IP "\(bu" 4
<\./\.config/vcsh/config>
.
.IP "\(bu" 4
\fBvcsh \-c <file>\fR
.
.IP "" 0
Expand Down