From 155c033ccfb669e230467a13b5d9945155267be0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 6 Mar 2014 19:39:07 -0800 Subject: [PATCH 1/8] Sourcing ./.config/vcsh/config --- vcsh | 1 + 1 file changed, 1 insertion(+) diff --git a/vcsh b/vcsh index 029a2b26..b9de7554 100755 --- a/vcsh +++ b/vcsh @@ -62,6 +62,7 @@ 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" 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 From 073601dacd7577ef55aa9d8af2d1838796229581 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 6 Mar 2014 19:39:56 -0800 Subject: [PATCH 2/8] Adding where subcommand --- vcsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vcsh b/vcsh index b9de7554..eb642982 100755 --- a/vcsh +++ b/vcsh @@ -118,6 +118,7 @@ help() { 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 @@ -348,6 +349,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 @@ -423,7 +429,8 @@ case "$VCSH_COMMAND" in 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 @@ -462,7 +469,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" From 56f05a034d607c678bd473d73424a21329e099c2 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 6 Mar 2014 19:40:07 -0800 Subject: [PATCH 3/8] Adding setup subcommand --- vcsh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vcsh b/vcsh index eb642982..59f3683c 100755 --- a/vcsh +++ b/vcsh @@ -115,6 +115,7 @@ 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 @@ -304,6 +305,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" @@ -426,6 +435,7 @@ 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;; @@ -445,6 +455,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 From 15d31a634a3d7a6bff6e3b303d8b062d8bff20d1 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 6 Mar 2014 19:51:55 -0800 Subject: [PATCH 4/8] Updating docs for setup and where subcommands --- README.md | 21 +++++++++++++++++++++ doc/vcsh.1.ronn | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) 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..3edafca5 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,17 @@ 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. + + Please note that `vcsh` will only detect the configuration from the + local working directory, and so will default back to <$HOME> if run + in a sub-directory. Use `vcsh where` to verify the above settings. + * status: Show statuses of all/one vcsh repositories. @@ -139,6 +154,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 +183,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 From e255e590118bc9050edd54f6452b01fa69495235 Mon Sep 17 00:00:00 2001 From: Dewey Sasser Date: Fri, 7 Mar 2014 00:04:09 -0500 Subject: [PATCH 5/8] Ascend the directory tree to find the vcsh config directory --- vcsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vcsh b/vcsh index 59f3683c..6e412626 100755 --- a/vcsh +++ b/vcsh @@ -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 @@ -63,6 +77,11 @@ source_all() { [ -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 From e31b37bf8bd43e6aa45e3deb650f8b4e9df693f8 Mon Sep 17 00:00:00 2001 From: Dewey Sasser Date: Fri, 7 Mar 2014 00:09:34 -0500 Subject: [PATCH 6/8] Regenerated man page --- vcsh.1 | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vcsh.1 b/vcsh.1 index 967aee8c..65f34def 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 +Please note that \fBvcsh\fR will only detect the configuration from the local working directory, and so will default back to \fI$HOME\fR if run in a sub\-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 From c5489581ab188d679a5fb940ffced4e21b45fdc2 Mon Sep 17 00:00:00 2001 From: Dewey Sasser Date: Fri, 7 Mar 2014 00:24:56 -0500 Subject: [PATCH 7/8] Updated docs to reflect directory ascension --- doc/vcsh.1.ronn | 5 ++--- vcsh.1 | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/vcsh.1.ronn b/doc/vcsh.1.ronn index 3edafca5..66cdebff 100644 --- a/doc/vcsh.1.ronn +++ b/doc/vcsh.1.ronn @@ -141,9 +141,8 @@ an interactive user. <$HOME>. Can also be run in <$HOME> for basic initial setup without cloning the template. - Please note that `vcsh` will only detect the configuration from the - local working directory, and so will default back to <$HOME> if run - in a sub-directory. Use `vcsh where` to verify the above settings. + `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. diff --git a/vcsh.1 b/vcsh.1 index 65f34def..5cfe285e 100644 --- a/vcsh.1 +++ b/vcsh.1 @@ -169,7 +169,7 @@ 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 -Please note that \fBvcsh\fR will only detect the configuration from the local working directory, and so will default back to \fI$HOME\fR if run in a sub\-directory\. Use \fBvcsh where\fR to verify the above settings\. +\fBvcsh\fR will detect the configuration from any directory below the setup directory\. Use \fBvcsh where\fR to verify the above settings\. . .TP status From 7d6a314400ec8631b2993e38a179f479d39b684c Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 12 Mar 2014 22:56:44 -0700 Subject: [PATCH 8/8] Bringing test_dir_upwards() up to project standards Using this function to recurse up the directory tree looking for the configuration file. Renamed to test_dir_upwards() because the function is just testing with [ $1 $2 ]. Switched to $(execute) from `execute` as the latter is preferred. Tested, this works well. --- vcsh | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/vcsh b/vcsh index 6e412626..4f106644 100755 --- a/vcsh +++ b/vcsh @@ -54,21 +54,17 @@ source_all() { esac; } -find_dir_upwards() { - op="$1" - dir="$2" - ( - while [ `pwd` != / ] ; do - if [ $op "$dir" ] ; then - pwd - return - fi - cd .. - done - ) +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 : ${XDG_CONFIG_HOME:=$HOME/.config} @@ -78,9 +74,9 @@ find_dir_upwards() { [ -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" +# 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