Skip to content

Commit ae7cafd

Browse files
author
jonathan 'jonthn' buschmann
committed
Allow user to specify the target directory
A new default target can be set using: * A target option in rcrc(5) * -T flag (based on the work in #255) for #246
1 parent ef34b0b commit ae7cafd

File tree

14 files changed

+102
-6
lines changed

14 files changed

+102
-6
lines changed

Makefile.am

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ TESTS = \
5555
test/rcup-hooks-failure.t \
5656
test/rcup-hooks-run-in-situ.t \
5757
test/rcup-hooks-run-in-order.t \
58-
test/rcup-spaces.t
58+
test/rcup-spaces.t \
59+
test/rcup-target.t \
60+
test/rcup-target-subst.t \
61+
test/rcrc-target.t
5962

6063
dist_check_SCRIPTS = $(TESTS)
6164
dist_check_DATA = test/helper.sh

NEWS.md.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
rcm (@PACKAGE_VERSION@) unstable; urgency=low
22

33
* Feature: rcup/rcdn hooks can bail early (Patrick Brisbin)
4+
* Feature: specify a target directory instead of $HOME (see -T or TARGET setting .rcrc(5))
45
* Documentation improvement (Teo Ljungberg)
56

67
-- Mike Burns <[email protected]> Fri, 30 Dec 2022 11:43:00 -0500

bin/lsrc.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ handle_command_line() {
257257
local undotted=
258258
local never_undotted=
259259

260-
while getopts :FVqvhI:x:B:S:s:U:u:t:d: opt; do
260+
while getopts :FVqvhI:x:B:S:s:U:u:t:d:T: opt; do
261261
case "$opt" in
262262
F) show_sigils=1;;
263263
h) show_help ;;
264264
I) includes="$(append_variable "$includes" "$OPTARG")" ;;
265265
t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
266+
T) DEST_DIR="$OPTARG" ;;
266267
v) verbosity=$(($verbosity + 1));;
267268
q) verbosity=$(($verbosity - 1));;
268269
d) dotfiles_dirs="$(append_variable "$dotfiles_dirs" "$OPTARG")" ;;

bin/rcdn.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ handle_command_line() {
4444
local never_undotted=
4545
local hostname=
4646

47-
while getopts :VqvhIKk:x:S:s:U:u:t:d:B: opt; do
47+
while getopts :VqvhIKk:x:S:s:U:u:t:d:B:T: opt; do
4848
case "$opt" in
4949
h) show_help ;;
5050
B) hostname="$OPTARG" ;;
5151
I) includes="$(append_variable "$includes" "$OPTARG")" ;;
5252
k) run_hooks=1 ;;
5353
K) run_hooks=0 ;;
5454
t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
55+
T) DEST_DIR="$OPTARG" ;;
5556
S) symlink_dirs="$(append_variable "$symlink_dirs" "$OPTARG")" ;;
5657
s) never_symlink_dirs="$(append_variable "$never_symlink_dirs" "$OPTARG")" ;;
5758
U) undotted="$(append_variable "$undotted" "$OPTARG")" ;;

bin/rcup.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ handle_command_line() {
209209
REPLACE_ALL=0
210210
GENERATE=
211211

212-
while getopts :CVqvfghikKI:x:S:s:U:u:t:d:B: opt; do
212+
while getopts :CVqvfghikKI:x:S:s:U:u:t:d:B:T: opt; do
213213
case "$opt" in
214214
B) hostname="$OPTARG" ;;
215215
C) always_copy=1 ;;
@@ -223,6 +223,7 @@ handle_command_line() {
223223
K) run_hooks=0 ;;
224224
q) verbosity=$(($verbosity - 1)) ;;
225225
t) arg_tags="$(append_variable "$arg_tags" "$OPTARG")" ;;
226+
T) DEST_DIR="$OPTARG" ;;
226227
S) symlink_dirs="$(append_variable "$symlink_dirs" "$OPTARG")" ;;
227228
s) never_symlink_dirs="$(append_variable "$never_symlink_dirs" "$OPTARG")";;
228229
U) undotted="$(append_variable "$undotted" "$OPTARG")" ;;
@@ -302,7 +303,7 @@ if [ "$pre_up_ret" -ne 0 ]; then
302303
exit "$pre_up_ret"
303304
fi
304305

305-
dests_and_srcs="$(eval "lsrc $LS_ARGS")"
306+
dests_and_srcs="$(eval "lsrc -T \"$DEST_DIR\" $LS_ARGS")"
306307

307308
saved_ifs="$IFS"
308309
IFS='

man/lsrc.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
.Op files ...
2020
.Sh DESCRIPTION
2121
This program lists all configuration files, both the sources in the
22-
dotfiles directories and the destinations in your home directory.
22+
dotfiles directories and the destinations in the destination
23+
directory (by default your home directory).
2324
.
2425
See
2526
.Xr rcup 1 ,
@@ -90,6 +91,8 @@ protect it from your shell.
9091
.
9192
.It Fl t Ar TAG
9293
list dotfiles according to TAG
94+
.It Fl T Ar DIR
95+
consider dotfiles having destinations within target directory DIR
9396
.
9497
.It Fl U Ar excl_pat
9598
the rc files or directories matching this pattern will not be symlinked or

man/rcdn.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ This can be repeated.
9898
.It Fl t Ar TAG
9999
remove dotfiles according to
100100
.Ar TAG
101+
.It Fl T Ar DIR
102+
remove dotfiles relative to target directory DIR
101103
.It Fl U Ar EXCL_PAT
102104
any rc file or directory that matches
103105
.Ar EXCL_PAT

man/rcm.7.mustache

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ option. For example:
139139
.Pp
140140
.Dl mkrc -U bin
141141
.
142+
.Ss COMMON PROBLEM: CHANGING THE TARGET LOCATION DEPENDENT ON THE VALUE OF AN ENVIRONMENT VARIABLE
143+
By default, the rcm suite will assume that all dotfiles are installed relative to
144+
.Pa $HOME .
145+
If instead, the dotfiles are to be installed to, say,
146+
.Pa $XDG_CONFIG_HOME ,
147+
there are two options:
148+
149+
The default target can be redefined by using
150+
.Va TARGET
151+
location in the rcrc file, or by using the
152+
.Fl T
153+
flag. References to environment variables can be specified in any of these,
154+
e.g.
155+
.Pp
156+
.Dl rcup -T $XDG_CONFIG_HOME
157+
.
142158
.Sh QUICK START FOR EMPTY DOTFILES DIRECTORIES
143159
This section is for those who do not have an existing dotfiles
144160
directory and whose dotfiles are standard.
@@ -249,6 +265,35 @@ macOS users should see the
249265
.Sx BUGS
250266
section for more details.
251267
.
268+
.Sh ALTERNATIVE TARGET INSTALL LOCATIONS
269+
.
270+
Sometimes it is useful to instruct rcm to install dotfiles to a location
271+
other than
272+
.Sx $HOME .
273+
274+
The default target directory is taken to be the first specified by:
275+
.Bl -enum offset indent -compact
276+
.It
277+
command-line flag
278+
.Fl T ,
279+
for an invocation of rcup, rcdn, or lsrc.
280+
.It
281+
Variable
282+
.Va TARGET
283+
in the rcrc file. (see
284+
.Xr rcrc 5
285+
and the
286+
.Sx FILES
287+
section below)
288+
.It
289+
$HOME
290+
.El
291+
292+
A target location can also be specified on a per dotfiles directory basis.
293+
This is achieved by placing meta-file
294+
.Pa target
295+
in the root, which contains a single line denoting the desired target directory.
296+
252297
.Sh STANDALONE INSTALLATION SCRIPT
253298
.
254299
The

man/rcrc.5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ command, but this command is non-standard and can prove unreliable. The
5454
variable forces a known hostname.
5555
.It Va TAGS
5656
the default tags.
57+
.It Va TARGET
58+
the new default location to manage dotfiles relative to.
5759
.
5860
.It Va SYMLINK_DIRS
5961
a space-separated list of patterns. Directories matching a pattern are

man/rcup.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ This option can be repeated.
9393
.It Fl t Ar TAG
9494
install dotfiles according to
9595
.Ar TAG .
96+
.It Fl T Ar DIR
97+
install dotfiles relative to target directory DIR
9698
.It Fl U Ar EXCL_PAT
9799
any rc file that matches
98100
.Ar EXCL_PAT

0 commit comments

Comments
 (0)