diff --git a/README.md b/README.md index 785b36ca..d432d9a2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/doc/vcsh.1.ronn b/doc/vcsh.1.ronn index 56df4ed2..66cdebff 100644 --- a/doc/vcsh.1.ronn +++ b/doc/vcsh.1.ronn @@ -29,12 +29,16 @@ vcsh(1) - Version Control System for $HOME - multiple Git repositories in $HOME `vcsh` run +`vcsh` setup + `vcsh` status [] `vcsh` upgrade `vcsh` version +`vcsh` where + `vcsh` which `vcsh` write-gitignore @@ -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. @@ -139,6 +153,10 @@ an interactive user. * version: Print version information. +* where: + + Print base <$VCSH_BASE> and config <$XDG_CONFIG_HOME> variables. + * which : Find in name of any tracked file. @@ -164,6 +182,7 @@ ascending precedence, they are: * `VARIABLE=foo vcsh` * * <$XDG_CONFIG_HOME/vcsh/config> +* <./.config/vcsh/config> * `vcsh -c ` Please note that those files are sourced. Any and all commands will be diff --git a/vcsh b/vcsh index 029a2b26..4f106644 100755 --- a/vcsh +++ b/vcsh @@ -54,6 +54,16 @@ source_all() { esac; } +test_dir_upwards() { + # Recurses upwards testing [ $1 $2 ], returning pwd when true + (while [ $(pwd) != / ]; do + if [ "$1" "$2" ]; then + pwd + return + fi + cd .. + done) +} # Read configuration and set defaults if anything's not set [ -n "$VCSH_DEBUG" ] && set -vx @@ -62,6 +72,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" + +# Recursively look up the directory tree for configuration file +configdir=$(test_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 @@ -114,9 +130,11 @@ help() { Rename repository run \\ Use this repository + setup Create ./.config/vcsh/config for local vcsh use status [] Show statuses of all/one vcsh repositories upgrade Upgrade repository to currently recommended settings version Print version information + where Print base and config directories which Find substring in name of any tracked file write-gitignore \\ Write .gitignore.d/ via git ls-files @@ -302,6 +320,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" @@ -347,6 +373,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 @@ -419,10 +450,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 @@ -437,6 +470,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 @@ -461,7 +496,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" diff --git a/vcsh.1 b/vcsh.1 index 967aee8c..5cfe285e 100644 --- a/vcsh.1 +++ b/vcsh.1 @@ -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 @@ -46,6 +46,9 @@ \fBvcsh\fR run \fIrepo\fR \fIshell command\fR . .P +\fBvcsh\fR setup +. +.P \fBvcsh\fR status [\fIrepo\fR] . .P @@ -55,6 +58,9 @@ \fBvcsh\fR version . .P +\fBvcsh\fR where +. +.P \fBvcsh\fR which \fIsubstring\fR . .P @@ -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\. . @@ -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\. . @@ -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 \fR . .IP "" 0