diff options
author | Mike Burns and Eric Collins <mburns@thoughtbot.com> | 2015-11-27 13:07:17 +0100 |
---|---|---|
committer | Mike Burns and Eric Collins <mike@mike-burns.com> | 2016-12-26 16:24:19 -0500 |
commit | 0651e4f5e0e71b57d6564f2f2887ab98f13f1995 (patch) | |
tree | a2972cd67447f615fa6c83f9bdf6ff1e26b1f3ca /bin/lsrc.in | |
parent | bc0d5b63f6c4762b7d39fb32b525f977015ff4b3 (diff) |
Fix relative exclude globs
Pass the dotfiles subdir along with the file to `is_excluded` so that we
can match against it.
Preserve single-file compatibility by looping twice.
Diffstat (limited to 'bin/lsrc.in')
-rwxr-xr-x | bin/lsrc.in | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/bin/lsrc.in b/bin/lsrc.in index fcf5fbe..8fb1fcd 100755 --- a/bin/lsrc.in +++ b/bin/lsrc.in @@ -141,9 +141,9 @@ handle_file() { if [ ! -e "$file" ]; then $VERBOSE "skipping non-existent file $file" - elif is_excluded "$file" "$exclude_file_globs" "$include_file_globs"; then + elif is_excluded "$dotfiles_subdir/$file" "$exclude_file_globs" "$include_file_globs"; then $VERBOSE "skipping excluded file $file" - elif [ -d "$file" ] && is_excluded "$file" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"; then + elif [ -d "$file" ] && is_excluded "$dotfiles_subdir/$file" "$symlink_dirs_file_globs" "$mk_dirs_file_globs"; then show_file "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted elif [ -d "$file" ]; then show_dir "$file" "$dest_dir" "$dotfiles_dir" "$dotfiles_subdir" $dotted "$exclude_file_globs" "$include_file_globs" "$symlink_dirs_file_globs" "$mk_dirs_file_globs" @@ -188,6 +188,7 @@ is_excluded() { local file="$1" local exclude_file_globs="$2" local include_file_globs="$3" + local base_file="$(basename "$file")" $DEBUG "is_excluded $file $exclude_file_globs $include_file_globs" @@ -195,22 +196,42 @@ is_excluded() { $DEBUG "file: $file" $DEBUG "exclude_file_glob: $exclude_file_glob" - case "$file" in - $exclude_file_glob) - for include_file_glob in $include_file_globs; do - case "$file" in - $include_file_glob) return 1;; - esac - done - - return 0 - ;; - esac + is_single_excluded "$file" "$exclude_file_glob" "$include_file_globs" + ret=$? + if [ $ret -eq 0 -o $ret -eq 1 ]; then + return $ret + fi + + is_single_excluded "$base_file" "$exclude_file_glob" "$include_file_globs" + ret=$? + if [ $ret -eq 0 -o $ret -eq 1 ]; then + return $ret + fi done return 1 } +is_single_excluded() { + local file="$1" + local exclude_file_glob="$2" + local include_file_globs="$3" + + case "$file" in + $exclude_file_glob) + for include_file_glob in $include_file_globs; do + case "$file" in + $include_file_glob) return 1;; + esac + done + + return 0 + ;; + esac + + return 2 +} + show_help() { local exit_code=${1:-0} |