Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for XDG compliant directories and configuration #292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ TESTS = \
test/rcup-hooks-failure.t \
test/rcup-hooks-run-in-situ.t \
test/rcup-hooks-run-in-order.t \
test/rcup-spaces.t
test/rcup-spaces.t \
test/xdg.t \
test/xdg-compatibilty-rcrc-symlink.t \
test/xdg-config-with-dotfiles.t \
test/xdg-error-both-config.t \
test/xdg-favor-rcm_dotfiles-over-tilde_dotfiles.t

dist_check_SCRIPTS = $(TESTS)
dist_check_DATA = test/helper.sh
Expand Down
1 change: 1 addition & 0 deletions NEWS.md.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rcm (@PACKAGE_VERSION@) unstable; urgency=low

* Feature: rcup/rcdn hooks can bail early (Patrick Brisbin)
* Feature: XDG-compliance ~/.config/rcm/rcrc and ~/local/share/rcm/dotfiles
* Documentation improvement (Teo Ljungberg)

-- Mike Burns <[email protected]> Fri, 30 Dec 2022 11:43:00 -0500
Expand Down
8 changes: 7 additions & 1 deletion man/lsrc.1
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,16 @@ when using an exclude pattern.
.Bl -tag -width ".Ev RCRC"
.It Ev RCRC
User configuration file. Defaults to
.Pa ~/.rcrc .
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc .
.El
.Sh FILES
.Pp
.Pa ${XDG_DATA_HOME}/rcm/dotfiles
or
.Pa ~/.dotfiles
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh SEE ALSO
.Xr mkrc 1 ,
Expand Down
8 changes: 7 additions & 1 deletion man/mkrc.1
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ section in
.Bl -tag -width ".Ev RCRC"
.It Ev RCRC
User configuration file. Defaults to
.Pa ~/.rcrc .
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc .
.El
.Sh FILES
.Pp
.Pa ${XDG_DATA_HOME}/rcm/dotfiles
or
.Pa ~/.dotfiles
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh EXAMPLES
.Dl mkrc ~/.vimrc
Expand Down
5 changes: 4 additions & 1 deletion man/rcdn.1
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ only remove the specified file(s)
.Bl -tag -width ".Ev RCRC"
.It Ev RCRC
User configuration file. Defaults to
.Pa ~/.rcrc .
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc .
.El
.Sh FILES
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh EXAMPLES
.Dl rcdn -v
Expand Down
6 changes: 6 additions & 0 deletions man/rcm.7.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ share tools and develop this further as a first-class entity. It is also
our hope that a common set of tools will encourage others to share their
dotfiles, too.
.Sh FILES
.Pp
.Pa ${XDG_DATA_HOME}/rcm/dotfiles
or
.Pa ~/.dotfiles
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh SEE ALSO
.Xr lsrc 1 ,
Expand Down
3 changes: 3 additions & 0 deletions man/rcrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ under the section
.
.El
.Sh FILES
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh EXAMPLES
.Dl COPY_ALWAYS="ssh/id_* weechat/* netrc"
Expand Down
8 changes: 7 additions & 1 deletion man/rcup.1
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,16 @@ The post-up hook is run.
.Bl -tag -width ".Ev RCRC"
.It Ev RCRC
User configuration file. Defaults to
.Pa ~/.rcrc .
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc .
.El
.Sh FILES
.Pp
.Pa ${XDG_DATA_HOME}/rcm/dotfiles
or
.Pa ~/.dotfiles
.Pp
.Pa ${XDG_CONFIG_HOME}/rcm/rcrc
or
.Pa ~/.rcrc
.Sh SEE ALSO
.Xr lsrc 1 ,
Expand Down
38 changes: 36 additions & 2 deletions share/rcm.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ PRINT=echo
PROMPT=echo_n
ERROR=echo_error
VERBOSE=:
DEFAULT_DOTFILES_DIR="$HOME/.dotfiles"
DEFAULT_DOTFILES_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/rcm/dotfiles"
MKDIR=mkdir
INSTALL=rcup
ROOT_DIR="$HOME"

# Default is XDG-style
if [ ! -d "$DEFAULT_DOTFILES_DIR" ] &&
[ -d "$HOME/.dotfiles" ]; then
DEFAULT_DOTFILES_DIR="$HOME/.dotfiles"
fi

if [ -z "$LOGNAME" ]; then
LOGNAME=$(whoami)
fi
Expand Down Expand Up @@ -101,6 +107,8 @@ handle_common_flags() {
PRINT=:
INSTALL="$INSTALL -q"
fi

$DEBUG "Default dotfiles dir is $DEFAULT_DOTFILES_DIR"
}

determine_hostname() {
Expand Down Expand Up @@ -185,7 +193,33 @@ append_variable() {
fi
}

: ${RCRC:=$HOME/.rcrc}
if [ -z "$RCRC" ]; then

# Error to have 2 possible conflicting rcrc files

if [ -r "$HOME/.rcrc" ] &&
[ -r "${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc" ] &&
[ -h "$HOME/.rcrc" ] &&
diff -q "$HOME/.rcrc" "${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc" >/dev/null 2>&1; then

# Allow ~/.rcrc to be a link to ~/.config/rcm/rcrc for compatibility
RCRC="${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc"

elif [ -r "$HOME/.rcrc" ] &&
[ -r "${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc" ]; then

echo "Both $HOME/.rcrc and ${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc exists. Please remove one to use rcm" >&2
exit 1
else

# To be more XDG-compliant favor ~/.config/rcm/rcrc and set it as `default`
RCRC="${XDG_CONFIG_HOME:-${HOME}/.config}/rcm/rcrc"
if [ -r "${HOME}/.rcrc" ]; then
RCRC="${HOME}/.rcrc"
fi
fi

fi

if [ -r "$RCRC" ]; then
. "$RCRC"
Expand Down
2 changes: 2 additions & 0 deletions test/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ for bin in lsrc mkrc rcup rcdn; do
done

export HOME="$PWD"
export XDG_CONFIG_HOME="$PWD/.config"
export XDG_DATA_HOME="$PWD/.local/share"
export PATH="$TESTDIR/../bin:$PATH"
export RCRC="$HOME/.rcrc"
export RCM_LIB="$TESTDIR/../share"
Expand Down
2 changes: 1 addition & 1 deletion test/mkrc-no-dotfiles-dir-found.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Exit when no location found
$ touch .exampleno

$ mkrc -d .missing-dotfiles .exampleno >/dev/null
No dotfiles directories found in .missing-dotfiles */.dotfiles (glob)
No dotfiles directories found in .missing-dotfiles */share/rcm/dotfiles (glob)
[1]

$ refute "should not be a symlink" -h $HOME/.examplenob
Expand Down
2 changes: 1 addition & 1 deletion test/mkrc-one-dotfile-arg.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Trying to fool should result in no dir found error

$ mkrc -d ".other-dotfiles .another-dotfiles" rcfile
No dotfiles directories found in .other-dotfiles .another-dotfiles /*/.dotfiles (glob)
No dotfiles directories found in .other-dotfiles .another-dotfiles /*/share/rcm/dotfiles (glob)
[1]

Giving 2 dotfiles dir should result in an error and exit EX_USAGE
Expand Down
11 changes: 11 additions & 0 deletions test/xdg-compatibilty-rcrc-symlink.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ . "$TESTDIR/helper.sh"
$ unset RCRC
$ unset XDG_CONFIG_HOME
$ unset XDG_DATA_HOME

Should allow when ~/.rcrc is a symlink to ~/.config/rcm/rcrc

$ mkdir -p ~/.config/rcm
$ touch ~/.config/rcm/rcrc
$ ln -s ~/.config/rcm/rcrc ~/.rcrc
$ rcup
15 changes: 15 additions & 0 deletions test/xdg-config-with-dotfiles.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$ . "$TESTDIR/helper.sh"
$ unset RCRC
$ unset XDG_CONFIG_HOME
$ unset XDG_DATA_HOME

Should support ~/.config/rcm/rcrc with ~/.dotfiles

$ mkdir -p ~/.config/rcm
$ touch ~/.config/rcm/rcrc
$ mkdir -p .dotfiles
> mkdir -p ".dotfiles/config/software2/"
> touch ".dotfiles/config/software2/foobar"

$ rcup
> assert_linked "$HOME/.config/software2/foobar" "$HOME/.dotfiles/config/software2/foobar"
13 changes: 13 additions & 0 deletions test/xdg-error-both-config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$ . "$TESTDIR/helper.sh"
$ unset RCRC
$ unset XDG_CONFIG_HOME
$ unset XDG_DATA_HOME

Should exit when using both ~/.rcrc and ~/.config/rcm/rcrc

$ mkdir -p ~/.config/rcm
$ touch ~/.config/rcm/rcrc
$ touch ~/.rcrc
$ rcup
Both \/[\/\d\w_.-]+\.rcrc and \/[\/\d\w_.-]+\.config\/rcm\/rcrc exists\. Please remove one to use rcm (re)
[1]
17 changes: 17 additions & 0 deletions test/xdg-favor-rcm_dotfiles-over-tilde_dotfiles.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$ . "$TESTDIR/helper.sh"
$ unset RCRC
$ unset XDG_CONFIG_HOME
$ unset XDG_DATA_HOME

Should prefer ~/.local/share/rcm/dotfiles over ~/.dotfiles

$ mkdir -p .dotfiles
> mkdir -p .dotfiles/config/software3/
> touch ".dotfiles/config/software3/traditional-config"
$ mkdir -p .local/share/rcm/dotfiles
> mkdir -p .local/share/rcm/dotfiles/config/software3
> touch ".local/share/rcm/dotfiles/config/software3/xdg-config"

$ rcup
> assert_linked "$HOME/.config/software3/xdg-config" "$HOME/.local/share/rcm/dotfiles/config/software3/xdg-config"
> refute "used ~/.dotfiles" -r $HOME/.config/software3/traditional-config
19 changes: 19 additions & 0 deletions test/xdg.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$ . "$TESTDIR/helper.sh"
$ unset RCRC
$ unset XDG_CONFIG_HOME
$ unset XDG_DATA_HOME

Should support complete XDG-style directories and configuration

$ mkdir -p .local/share/rcm/dotfiles
> mkdir -p ".local/share/rcm/dotfiles/config"
> mkdir -p ".local/share/rcm/dotfiles/config/software1"
> mkdir -p ".local/share/rcm/dotfiles/config/software4"
> touch ".local/share/rcm/dotfiles/config/software1/config"
> touch ".local/share/rcm/dotfiles/config/software4/config"
> touch ".local/share/rcm/dotfiles/config/software4/more"

$ rcup
> assert_linked "$HOME/.config/software1/config" "$HOME/.local/share/rcm/dotfiles/config/software1/config"
> assert_linked "$HOME/.config/software4/config" "$HOME/.local/share/rcm/dotfiles/config/software4/config"
> assert_linked "$HOME/.config/software4/more" "$HOME/.local/share/rcm/dotfiles/config/software4/more"