summaryrefslogtreecommitdiff
path: root/share/rcm.sh.in
Commit message (Collapse)AuthorAge
* Fix shell globbing bugsGravatar Edd Salkield2020-04-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are several problems leading to the unintentional globbing issue: Firstly, within `rcup` and `rcdn`, when constructing arguments to pass to `lsrc`, the _for_ loops over the arguments do not have quoted variables, leading to globbing. I have quoted these accordingly. Secondly, `lsrc` is invoked as follows: ```sh dests_and_srcs="$(lsrc $LS_ARGS)" ``` When shells use command substitution like this, they go through two stages: - Word expansion. This is useful because it splits `LS_ARGS` back up into its constituent strings. - File name expansion. The side effect of this is to introduce globbing. You can read more about how this works [here](https://www.tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html#sect_03_04_07). To fix this, I have passed `lsrc` and its arguments to `eval`. This involves quoting the relevant arguments, so: ```sh for dotfiles_dir in "$DOTFILES_DIRS"; do LS_ARGS="$LS_ARGS -d $dotfiles_dir" done ``` becomes ```sh for dotfiles_dir in "$DOTFILES_DIRS"; do LS_ARGS="$LS_ARGS -d \"$dotfiles_dir\"" done ``` Then `lsrc` is invoked as follows: ```sh dests_and_srcs="$(eval "lsrc $LS_ARGS")" ``` There is one final non-globbing issue: the parsing of arguments can introduce extra spaces in the variables, which then trip up the `dotfiles_dir_excludes` function. For example: ```sh I) includes="$includes $OPTARG";; ``` introduces a space if `includes` is empty or null. I have introduced the function `append_variable`, which allows two variables to be appended without introducing unnecessary whitespace. Then the additional whitespace is never added in the first place. Fixes #256.
* Do not symlink a symlink in mkrcGravatar Mat M2020-01-17
| | | | | | | | | | | | | | We have a bug when calling mkrc(1) on a symlink: ```sh mkrc ~/.vimrc # links ~/.vimrc to ~/.dotfiles/vimrc mkrc ~/.vimrc # deletes ~/.dotfiles/vimrc ``` This catches that case ahead of time, preventing the user from running mkrc(1) on a symlink. Fix #144.
* Expand DOTFILE_DIR tilde in hooksGravatar Eric Collins2018-07-13
| | | | | Still does not expand in every usecase, possibly does not expand in all DOTFILE_DIRS usecases.
* avoid cd having issues with paths that begin with -Gravatar Christian Höltje2018-07-06
|
* Set the LOGNAME from whoamiGravatar Mike Burns2018-07-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Well, $LOGNAME is defined by POSIX (see a801c4c58902cae7b835d890487edc39bd7da142) but it's not appearing in reality under clean environments: ~% env -i /bin/bash mike:/home/mike$ echo $LOGNAME mike:/home/mike$ exit ~% env -i /bin/dash $ echo $LOGNAME $ exit ~% env -i /bin/ksh $ echo $LOGNAME $ exit ~% env -i /usr/bin/zsh ~% echo $LOGNAME mike ~% exit Fall back to whoami(1) when $LOGNAME is not set. Modify one of the tests to run with a restricted environment in order to test this. I had tried modifying the test-driver to run all tests in a restricted environment but the test-driver script is generated by Automake. Closes #165.
* Handle spaces in dotfile nameGravatar Mike Burns and Eric Collins2016-12-26
| | | | | | | | | | | | | | | | | In mkrc, separate the list of files with newlines instead of spaces. Change the `$IFS` when iterating to handle this. We hand the file off to rcup, which encodes the file name by replacing spaces with the bell character (`\a`). rcup then sends the file name off to lsrc, which decodes the bell back into a space. The test makes sure an `a` character is in the filename, in case some encoding goes wrong. We use tr(1) instead of sed(1) because tr(1) handles `\a`. Shoutout to Sublime Text 3 for forcing this issue.
* Run hooks in a defined orderGravatar David Alexander2016-11-12
| | | | | | | Run the hooks in alphabetical order so that people can more predictably manage their hooks. While here, clean up the NEWS.md.in.
* Use $LOGNAME instead of $USERGravatar Mike Burns2015-11-13
| | | | | | | | | | | The $USER environment variable is not guaranteed to exist, but $LOGNAME is defined by POSIX[0] (Environment Variables, section 8.3 Other Environment Variables). Use that instead. Thanks to Scott Stevenson for pointing out this solution, and Debian for raising the problem. [0]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
* Fix hooks so that they are run in the directory where they are locatedGravatar Jarkko Kniivilä2015-11-01
| | | | | | | | | | | | Calls `find(1)` with the `-exec` action just like before but instead of `run_hooks()` letting `find` execute the hook directly it is wrapped in a shell one-liner which changes to the hook's directory and executes the hook with "./" prepended to its basename. These changes allow hooks to refer to dotfiles with relative paths. For instance we can call a Makefile two directories up simply with `make -C ../..`. Also make sure we are compatible with Solaris' Bourne shell and `find(1)`. Closes #150. Closes #149.
* Do not depend on readlink(1) or -qGravatar Jarkko Kniivilä2015-11-01
| | | | | | | | | | | | | | | | | Solaris 10 lacks readlink(1). Additionally, its different grep(1) and diff(1) do not take a `-q` flag. Use a Perl one-liner instead of readlink(1) which is missing on Solaris 10. Also because /usr/bin/grep and diff(1) don't understand the `-q` option, make them go quiet by redirecting stdout to `/dev/null` instead. The Perl dependency only exists in the test suite, so it does not incur a runtime penalty for end users. This is to work around the fact that readlink(1) is missing on Solaris. The tradeoff is: on Solaris, installing third-party software (readlink) is a pain, whereas on e.g. FreeBSD installing third-party software (Perl) is simple and common.
* Add a hostname overrideGravatar Mike Burns2014-05-07
| | | | | | | | | | | | | | | | | | | Based on issue #82, we now provide `-B` to override the hostname. In particular: - `mkrc -B foo` will enable `-o` but with the hostname set up `foo`. - `lsrc -B foo` will work like normal `lsrc` except it treats `host-foo` as the host-specific directory. - `rcup -B foo` will run a normal `rcup` except `host-foo` is the host-specific directory. - `rcdn -B foo` is just like normal `rcdn`, but with `host-foo` as the host-specific directory. The `HOSTNAME` can also be set in the rcrc(5), and this is overridden by the aforementioned `-B`. While making this change: The `test/Makefile.am` used a mix of tabs and spaces. Since it's a Makefile, replace it all with tabs.
* Update the copyright, assign it to thoughtbotGravatar Mike Burns2014-05-05
| | | | This is a thoughtbot project now, so assign copyright to thoughtbot.
* Partial fix for finding hook executablesGravatar Christian Höltje2014-04-22
| | | | | | | | | This allows, at least, more executables to be picked up. It doesn't pick up group-executable scripts and ignore xattr files but it should be better than what was there before. Closes #80
* Only show hook filename when debuggingGravatar Mike Burns2014-03-28
| | | | | This uses a bit of a hack: if `$DEBUG` is set to `:`, then we are not in debug mode.
* Fixed hooks not executing under CygwinGravatar Daniel Watson2014-03-19
|
* Add support for -v option on OpenBSDGravatar The Linux Kitten2014-03-19
| | | | | | | | | | The `-v` (verbose) flag for `cp`, `ln`, and `rm` is not standard. It is simple to implement using shell functions, so introduce `cp_v`, `ln_v`, and `rm_v`. These shell functions use the existing `$VERBOSE` variable for printing, which simplifies the code and reduces the number of variables. Fixes #61.
* Fix bad merge in run_hooksGravatar patrick brisbin2014-03-06
| | | | | | It's likely that while shuffling commits for the quoting of "$@" issue, some lines were kept from both that branch and master resulting in an invalid state.
* Add quoting, remove backticks, use $PWDGravatar patrick brisbin2014-03-04
| | | | | | | | | * http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_03 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08 Fixes #46. This does not handle quotes around `$@`. That is taken separately in #53.
* Correctly set hook_file in run_hooksGravatar patrick brisbin2014-02-28
| | | | | | | | | | The code was setting the $hook_file variable to $dotfiles_dir/hooks/$when-$direction outside of the loop which actually sets the $dotfiles_dir variable to each of the dotfiles directories being processed in turn. This would lead to (for example) /hooks/post-up which is not correct. The fix is to move that logic into the loop.
* Fix error when hooks files/dirs don't existGravatar Pablo Olmos de Aguilera Corradini2014-02-24
| | | | | | | We had been relying on `hooks/pre-up` and `hooks/post-up` files to exist. This explicitly checks first. Fixes #34.
* Use sed to split out the short hostnameGravatar Mike Burns2014-02-19
| | | | | | | | Instead of using the non-standard `-s` argument to `hostname`, use `sed` to split out everything after the first period. This fixes lsrc(1) on Cygwin, among others. Fixes #28.
* Force some directories to be symlinksGravatar Pablo Olmos de Aguilera Corradini and Mike Burns2014-02-18
| | | | | | | | | | | | | | | | | | | | | | | Typically a directory structure is copied instead of symlinked, while files are symlinked. However, some cases require symlinked dirs: git submodules, vim plugins, and so on. This introduces a `SYMLINK_DIRS` option for rcrc(5) that takes a space-separated list of "exclude patterns". Any directory matching these patterns is symlinked. This also introduces a `-S` argument for lsrc(1), rcup(1), and rcdn(1). This argument takes a pattern, for one-off directory symlinking. It can be repeated. This also introduces `-S` and `-s` for mkrc(1). `-S` will re-install the files as symlinks, and `-s` will not. This does work with `-C`, though perhaps unintuitively - we don't know what the user means in this case. However, it will not crash. Bug: `-s` does not work right if `SYMLINK_DIRS` is set. Bug #36 addresses this.
* Allow {pre,post}-up hook directoriesGravatar Pablo Olmos de Aguilera Corradini2014-02-07
| | | | | If the `pre-up` or `post-up` files are actually directories, run the executable contents of them in an arbitrary order.
* Unset the CDPATH before running the programGravatar Mike Burns2014-01-27
| | | | | | | | | | | | | | | | | As reported in #23, you can trick `rcup` into installing into `.` with this `CDPATH`: export CDPATH=/tmp:. As described [online][1], it is a mistake to export the `CDPATH` environment variable to begin with. Since it is a one-liner to work around it, though, it's worth fixing. The workaround is to unset `CDPATH` at the beginning of the script. This does not affect the outside environment, it only affects the script and its functions. [1]: http://bosker.wordpress.com/2012/02/12/bash-scripters-beware-of-the-cdpath/
* Prefer RCRC environment variable over ~/.rcrcGravatar patrick brisbin2013-12-11
| | | | | | | | | * Centralize configuration loading in rcm.sh(.in) * Check for readability, not just existence Add RCRC notes to all manpages. Putting the environment variables in a table lines them up more neatly and definitively, across all output formats, and also follows the examples used by e.g. BSD ls(1).
* Add -kK for rcup and rcdnGravatar Mike Burns2013-08-16
| | | | | The hooks can be skipped using `-K`, if needed and they can be forced with the `-k` flag.
* Pre-up, post-up, pre-down, and post-down hooksGravatar Mike Burns2013-08-16
| | | | | | | | | | | | | | | | These are programs that, if they exist, will run before or after the syncronization/removal is run. Three use cases caused this: 1. The thoughtbot dotfiles will run a vundle installation set of commands after intitial synchronization. 2. I changed the location of `.bash_history` to `.bash/history` and wanted to move `.bash_history` to `.bash/history` after up to preserve existing history. 3. Moving from an existing old-style custom install script to `rcup` might require some cleanup; this happened in practice, and required a simple script.
* Add the COPY_ALWAYS optionGravatar Mike Burns2013-08-11
| | | | | | | | | | | | | | | | | | | | The suite now honors the `COPY_ALWAYS` option in rcrc(5). This can be set to a space-separated list of file globs. Any file matching a glob is copied instead of symlinked. This is handy both for secure programs (`netrc`, `ssh/id_*`) and for programs that oddly re-write files (`weechat/*`). To always copy everything, use the `*` glob. This is reflected throughout the suite as follows: * lsrc now has a `-F` option which shows a symbol to indicate whether it is a symlink (`@`) or a copy (`X`). * rcdn only removes symlinks unless the file under question matches a `COPY_ALWAYS` glob, in which case it is removed regardless of whether it is a symlink. * rcup will copy instead of symlinking any file that matches any `COPY_ALWAYS` glob.
* Add -C for copying filesGravatar Mike Burns2013-08-05
| | | | | | | | | | | | | | Some files prefer to be copies instead of symlinks---for example, OpenSSH ignores symlinks. Add the `-C` option to mkrc(1) and rcup(1) to handle this. mkrc -C .ssh rcup -C ssh This does raise a synchronization problem that I do not yet know how to solve; namely, what to do when the rc file changes. Perhaps a `rcsync` command is in order; perhaps `rcup` should handle this; perhaps `rcsync` is a better name for `rcup`.
* Introduce exclusion patternsGravatar Mike Burns2013-08-05
| | | | | | | | | | | | | | | | | | | The lsrc(1), rcup(1), and rcdn(1) commands now take any number of `-e` flags, used to specify an exclusion pattern. This can also be controlled via rcrc(5), the `EXCLUDES` variable. An exclusion pattern specifies a file glob to skip. In the case of lsrc(1), any file matching the glob is not listed; in rcup(1) it is not symlinked; and in rcdn(1) it is not removed. The file glob can be preceded by the name of a dotfiles directory (separated from the file glob by a colon) to increase the specificity. Useful for: rcdn -e rcrc rcup -d work-dotfiles -e bashrc rcup -d ~/.dotfiles -d wife-dotfiles -d sys-dotfiles -e wife-dotfiles:tigrc
* Add rcdnGravatar Mike Burns2013-08-03
| | | | | | | | | | | | | | | This program will remove all your rc files that are symlinked. This can be further controlled by `-d` and `-t`. For example, you can feel comfortable trying new rc files because you can quickly remove them again with `-d`. rcup -d thoughtbot-dotfiles rcdn -d thoughtbot-dotfiles Likewise, when you're done with Python just drop it: rcdn -t python
* Add `mkrc -o` to install host-specific filesGravatar Mike Burns2013-08-02
| | | | | | | | To make it easier to manage host-specific rc files, `mkrc` now supports a `-o` option. This causes the specified file to be added to the host section named for the current machine. This option is in conflict with the `-t` option.
* Extra argument parsing into rcm.shGravatar Mike Burns2013-08-02
| | | | | | Pull the `-V`, `-v`, `-q`, `-t`, and `-d` out into the `handle_common_flags` and `handle_metadata_flags` functions, shared between the different programs.
* Add a release targetGravatar Mike Burns2013-08-01
The `make release` command will build the Debian package, push the version to a git tag on GitHub, and upload the docs to GitHub pages. This also adds a `deb` target, along with `build-docs`, `upload-docs`, `build-tag`, and `push-tag`. In addition, introduce a `NEWS.md` file. Both `rcm.sh.in` and `NEWS.md.in` will act as input files. This is to abstract over the version number.