-
Notifications
You must be signed in to change notification settings - Fork 42
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
Forcing a directory to be split open #29
Comments
Sounds like you are looking for You can add that to a |
But (I think?) this completely disables folding, whereas I only want to disable it for specific directories. |
Yes, it completely disables folding (for the package you want to stow). I don't think there's a better way currently than pre-creating a fake directory tree that will cause stow to not fold certain directories. |
That's unfortunately correct. I recently uploaded the repository I use for this, so you can use that as an example for the workaround, but I agree it would be much nicer if Stow could be configured to never fold certain directories. Sadly I don't have time to implement this right now but I'd gladly review pull requests if someone else does. |
I'll share my solution. Normally I don't want directories to be folded: I want them to be created as actual directories, but I want some of them to be folded, e.g. I wrote this wrapper script that by default disabled foldins, allowing it for directory trees which begin in a directory containing a file named #!/bin/sh
set -e
stow=stow
if ! "$stow" -V >/dev/null 2>/dev/null; then
echo "Not found: '$stow'" >&2
return 1
fi
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <directory>" >&2
return 1
fi
dir=$1
if [ ! -d "$dir" ]; then
echo "Not found: '$dir'." >&2
return 1
fi
if [ -z "$(find "$dir" -name fold-here)" ]; then
# No "fold-here" file found, assume no-folding.
$stow --no-folding "$dir"
else
# Create the parent folders of the "fold-here" files.
# The deepest "fold-here" in a tree wins.
cd "$dir"
find . -mindepth 2 -name fold-here -exec dirname {} + | xargs -I{} mkdir -vp ../../{}
cd ..
$stow --ignore="/fold-here$" "$dir"
fi I keep this script in my |
The script is buggy. I wrote an improved version of it, but I'm not yet sure it is a good approach. |
I ended up with a simper (and more flexible) solution. I define the list of directories which should not be folded in a file named #!/bin/sh
set -e
for arg; do
if [ -f "$arg/stow-skel.nostow" ]; then
xargs -a "$arg/stow-skel.nostow" -I{} mkdir -pv ../{}
fi
done
stow --ignore="\.nostow" $@ It would be very nice to have this functionality handled directly by |
For a good discussion see <aspiers/stow#29>. The way Stow symlinks non-existent directories means that we often get generated files being placed back in this repository (e.g. if `.ipython` points here, then the history etc. appear as untracked files). Rather, we often want the real directory structure with just symlinked files, which is what the new `--no-folding` suggestion achieves. However, this is still a blunt instrument, and will recurse to arbitrary depth. For e.g. `vim/` this is unnecessary, as we just want a `.vim/colors/` symlink (otherwise it propagates through the whole set of submodules there). For that, we just provide explicit instructions.
FWIW, I have a similar but inverted use-case where I want most of my dotfiles to be non-folded; with some exceptions such as To achieve this, I adopted a similar strategy as @paride and added a hidden file called
The
The logic of all this is encoded in fold_stow() {
# define local variabless
local command="$1"
local source="${2//\~/$HOME}"
local destination="${3//\~/$HOME}"
local dotfiles="$4"
local dotfiles_nofold=()
local dotfiles_fold=()
# loop over files and execute logic
for dotfile in $dotfiles; do
# check for the existence of .fold
src_dotfile="$source/$dotfile"
if [ -f "$src_dotfile/.fold" ]; then
# loop through all foldable directories
for fold in $(xargs -a "$src_dotfile/.fold"); do
src_fold_directory="$src_dotfile/$fold"
dest_fold_directory="$destination/$fold"
# prompt to delete directories if they are not symlinks
if [[ -d "$src_fold_directory" && -d "$dest_fold_directory" && \
! -L "$dest_fold_directory" ]]; then
read -rp "Delete $dest_fold_directory for folding? (y/N): " ans
# only delete if answer is y or Y
if [[ "$ans" == [yY] ]]; then
rm -rf "$dest_fold_directory"
fi
fi
done
dotfiles_fold+=("$dotfile")
else
dotfiles_nofold+=("$dotfile")
fi
done
# execute stow for folding directories
if ((${#dotfiles_fold[@]})); then
eval "$command -d $source -t $destination --ignore='^\.fold$' ${dotfiles_fold[*]}"
fi
# execute stow for --no-folding directories
if ((${#dotfiles_nofold[@]})); then
eval "$command -d $source -t $destination --no-folding ${dotfiles_nofold[*]}"
fi
} |
In case anyone missed my comment above, my solution is here: https://github.com/aspiers/ANTIFOLD. |
Upon further thought, maybe this is a candidate to be added to the (non-existent) FAQ. |
I have started doing this, which seems to work so far, so it seems a lot simpler to do?
|
(Initially posted on the help-stow mailing list.)
Like many others, I use stow to manage my dotfiles across multiple machines. In particular, a small exerpt of my stow tree includes
~/dotfiles/vim/plugin
~/dotfiles/vim/syntax
...
so I can just cd ~/dotfiles && stow -S vim after git-cloning dotfiles to a new machine.
But that'll just do a symlink ~/.vim -> ~/dotfiles/.vim, which is not what I want: this will cause e.g. ~/.vim/undo to end up in ~/dotfiles as well. So I always want to split open ~/.vim. In this specific case I could alternatively get away with gitignoring all other directories in ~/.vim, but this is less optimal for dotfiles which reside e.g. in ~/.config, as I really don't want ~/.config to be a symlink but rather ~/.config/foo to be one.
So I need to first create ~/.vim myself and manually add a directory into it (e.g. ~/.vim/undo) before stowing my dotfiles, to force splitting that directory. It would be nice it it was possible to create e.g. ~/dotfiles/vim/.stow-force-split (name is up to bikeshedding) to say, "you are not allowed to symlink this directory directly, but must split it" (and that file shouldn't get symlinked itself).
Looking forward to your thoughts.
The text was updated successfully, but these errors were encountered: