From 122bbf0c6da226fc7e8a7e2a8d173b3e6259f7cf Mon Sep 17 00:00:00 2001 From: Mike Burns Date: Mon, 5 Aug 2013 04:41:38 +0200 Subject: Inclusionary patterns: -I The `-I` flag serves as an "undo" for the `-e` pattern. It overrides any matching exclusions, allowing for temporary listing/installation/removal. For example, if you want to try a `.pythonrc` but leave it in your `EXCLUDES` in rcrc(5), you can do: rcup -Ipythonrc pythonrc --- NEWS.md.in | 6 ++++++ bin/lsrc | 48 ++++++++++++++++++++++++++++++++---------------- bin/mkrc | 2 +- bin/rcdn | 7 ++++++- bin/rcup | 7 ++++++- man/lsrc.1 | 14 ++++++++++++-- man/rcdn.1 | 15 ++++++++++++++- man/rcup.1 | 13 +++++++++++++ 8 files changed, 90 insertions(+), 22 deletions(-) diff --git a/NEWS.md.in b/NEWS.md.in index 7665527..df52095 100644 --- a/NEWS.md.in +++ b/NEWS.md.in @@ -1,5 +1,11 @@ rcm (@PACKAGE_VERSION@) unstable; urgency=low + * Exclusion and inclusion with -e and -I + + -- Mike Burns Mon, 05 Aug 2013 16:43:33 +0200 + +rcm (1.0.0) unstable; urgency=low + * Improved Debian handling. * Introduce mkrc -o to install host-specific dotfiles. * Add rcdn(1) to remove rc files. diff --git a/bin/lsrc b/bin/lsrc index 6267f03..9ed2a71 100755 --- a/bin/lsrc +++ b/bin/lsrc @@ -35,15 +35,16 @@ link_dir() { local dotfiles_dir=$3 local dotted=$4 local exclude_file_globs="$5" + local include_file_globs="$6" local dest_path=`build_path $dest_dir $dir $dotted` - $DEBUG "link_dir $1 $2 $3 $4 $5" + $DEBUG "link_dir $1 $2 $3 $4 $5 $6" $VERBOSE "recurring on $dest_path" pushdir $dir for f in *; do $DEBUG "handling the file $f" - handle_file $f $dest_path $dotfiles_dir/$dir 1 "$exclude_file_globs" + handle_file $f $dest_path $dotfiles_dir/$dir 1 "$exclude_file_globs" "$include_file_globs" done popdir } @@ -68,15 +69,16 @@ handle_file() { local dotfiles_dir=$3 local dotted=$4 local exclude_file_globs="$5" + local include_file_globs="$6" - $DEBUG "handle_file $1 $2 $3 $4 $5" + $DEBUG "handle_file $1 $2 $3 $4 $5 $6" if [ ! -e $file ]; then $VERBOSE "skipping non-existent file $file" - elif is_excluded $file "$exclude_file_globs"; then + elif is_excluded $file "$exclude_file_globs" "$include_file_globs"; then $VERBOSE "skipping excluded file $file" elif [ -d $file ]; then - link_dir $file $dest_dir $dotfiles_dir $dotted "$exclude_file_globs" + link_dir $file $dest_dir $dotfiles_dir $dotted "$exclude_file_globs" "$include_file_globs" else link_file $file $dest_dir $dotfiles_dir $dotted fi @@ -91,11 +93,12 @@ is_metafile() { dotfiles_dir_excludes() { local dotfiles_dir=$1 + local excludes="$2" $DEBUG "dotfiles_dir_excludes $dotfiles_dir" - $DEBUG " with EXCLUDES: $EXCLUDES" + $DEBUG " with excludes: $excludes" - for exclude in $EXCLUDES; do + for exclude in $excludes; do if echo $exclude | grep -q :; then dotfiles_dir_pat=`echo $exclude | sed 's/:.*//'` file_glob=`echo $exclude | sed 's/.*://'` @@ -116,15 +119,24 @@ dotfiles_dir_excludes() { is_excluded() { local file=$1 local exclude_file_globs="$2" + local include_file_globs="$3" - $DEBUG "is_excluded $file $exclude_file_globs" + $DEBUG "is_excluded $file $exclude_file_globs $include_file_globs" - for file_glob in $exclude_file_globs; do - $DEBUG "file_glob: $file_glob" + for exclude_file_glob in $exclude_file_globs; do $DEBUG "file: $file" + $DEBUG "exclude_file_glob: $exclude_file_glob" case $file in - $file_glob) return 0;; + $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 done @@ -137,10 +149,12 @@ handle_command_line() { local version=0 local dotfiles_dirs= local excludes= + local includes= - while getopts Vqve:t:d: opt; do + while getopts VqvI:e:t:d: opt; do case "$opt" in e) excludes="$excludes $OPTARG";; + I) includes="$includes $OPTARG";; t) arg_tags="$arg_tags $OPTARG";; v) verbosity=$(($verbosity + 1));; q) verbosity=$(($verbosity - 1));; @@ -154,6 +168,7 @@ handle_command_line() { TAGS=${arg_tags:-$TAGS} DOTFILES_DIRS=${dotfiles_dirs:-$DOTFILES_DIRS} EXCLUDES=${excludes:-$EXCLUDES} + INCLUDES=${includes:-$INCLUDES} FILES=$@ $DEBUG "TAGS: $TAGS" @@ -181,8 +196,9 @@ for DOTFILES_DIR in $DOTFILES_DIRS; do continue fi - exclude_file_globs=`dotfiles_dir_excludes $DOTFILES_DIR` + exclude_file_globs=`dotfiles_dir_excludes $DOTFILES_DIR "$EXCLUDES"` $DEBUG "exclude_file_globs: $exclude_file_globs" + include_file_globs=`dotfiles_dir_excludes $DOTFILES_DIR "$INCLUDES"` cd $DOTFILES_DIR DIR_STACK=":$DOTFILES_DIR" @@ -192,7 +208,7 @@ for DOTFILES_DIR in $DOTFILES_DIRS; do continue fi - handle_file $file $DEST_DIR $DOTFILES_DIR 0 "$exclude_file_globs" + handle_file $file $DEST_DIR $DOTFILES_DIR 0 "$exclude_file_globs" "$include_file_globs" done cd $DOTFILES_DIR @@ -201,7 +217,7 @@ for DOTFILES_DIR in $DOTFILES_DIRS; do if [ -d $host_files ]; then pushdir `basename $host_files` for file in ${FILES:-*}; do - handle_file $file $DEST_DIR $host_files 0 "$exclude_file_globs" + handle_file $file $DEST_DIR $host_files 0 "$exclude_file_globs" "$include_file_globs" done popdir fi @@ -213,7 +229,7 @@ for DOTFILES_DIR in $DOTFILES_DIRS; do pushdir `basename tag-$tag` for file in ${FILES:-*}; do $DEBUG "TAG: $tag, exclude_file_globs: $exclude_file_globs" - handle_file $file $DEST_DIR $DOTFILES_DIR/tag-$tag 0 "$exclude_file_globs" + handle_file $file $DEST_DIR $DOTFILES_DIR/tag-$tag 0 "$exclude_file_globs" "$include_file_globs" done popdir fi diff --git a/bin/mkrc b/bin/mkrc index 5a70482..d3effb8 100755 --- a/bin/mkrc +++ b/bin/mkrc @@ -23,7 +23,7 @@ if [ -e $HOME/.rcrc ]; then fi if [ $# -eq 0 ]; then - echo "Usage: mkrc [-d dir] [-t tag] [-o] [-v] [-q] filename ..." + echo "Usage: mkrc [-vqo] [-t tag] [-d dir] files ..." exit 1 fi diff --git a/bin/rcdn b/bin/rcdn index 66e064f..a7fb81d 100755 --- a/bin/rcdn +++ b/bin/rcdn @@ -10,10 +10,12 @@ handle_command_line() { local dotfiles_dirs= local files= local excludes= + local includes= - while getopts Vqve:t:d: opt; do + while getopts VqvI:e:t:d: opt; do case "$opt" in e) excludes="$excludes $OPTARG";; + I) includes="$includes $OPTARG";; t) arg_tags="$arg_tags $OPTARG" ;; v) verbosity=$(($verbosity + 1));; q) verbosity=$(($verbosity - 1));; @@ -38,6 +40,9 @@ handle_command_line() { for exclude in $excludes; do LS_ARGS="$LS_ARGS -e $exclude" done + for include in $includes; do + LS_ARGS="$LS_ARGS -I $include" + done LS_ARGS="$LS_ARGS $files" $DEBUG "LS_ARGS: $LS_ARGS" diff --git a/bin/rcup b/bin/rcup index 7c1cf16..37ccb2f 100755 --- a/bin/rcup +++ b/bin/rcup @@ -77,14 +77,16 @@ handle_command_line() { local dotfiles_dirs= local files= local excludes= + local includes= REPLACE_ALL=0 - while getopts Vqvfie:t:d: opt; do + while getopts VqvfiI:e:t:d: opt; do case "$opt" in e) excludes="$excludes $OPTARG";; f) REPLACE_ALL=1 ;; i) REPLACE_ALL=0 ;; + I) includes="$includes $OPTARG";; t) arg_tags="$arg_tags $OPTARG" ;; v) verbosity=$(($verbosity + 1)) ;; q) verbosity=$(($verbosity - 1)) ;; @@ -109,6 +111,9 @@ handle_command_line() { for exclude in $excludes; do LS_ARGS="$LS_ARGS -e $exclude" done + for include in $includes; do + LS_ARGS="$LS_ARGS -I $include" + done LS_ARGS="$LS_ARGS $files" $DEBUG "LS_ARGS: $LS_ARGS" diff --git a/man/lsrc.1 b/man/lsrc.1 index 863ceb8..fb48680 100644 --- a/man/lsrc.1 +++ b/man/lsrc.1 @@ -7,9 +7,10 @@ .Sh SYNOPSIS .Nm lsrc .Op Fl vq -.Op Fl t Ar tag .Op Fl d Ar dir .Op Fl e Ar excl_pat +.Op Fl I Ar excl_pat +.Op Fl t Ar tag .Op files ... .Sh DESCRIPTION This program lists all configuration files, both the sources in the @@ -31,10 +32,19 @@ list dotfiles according to TAG list dotfiles from the DIR. This can be specified multiple times. . .It Fl e Ar excl_pat -Exclude the files that matches the given pattern. See +exclude the files that match the given pattern. See .Sx EXCLUDE PATTERN for more details. This option can be repeated. . +.It Fl I Ar excl_pat +include the files that match the given pattern. This is applied after +any +.Fl e +options. It uses the same pattern language as +.Fl e ; +more details are in the +.Sx EXCLUDE PATTERN +section. .It Fl v increase verbosity. This can be repeated for extra verbosity. . diff --git a/man/rcdn.1 b/man/rcdn.1 index c6f8e9f..9007783 100644 --- a/man/rcdn.1 +++ b/man/rcdn.1 @@ -7,8 +7,10 @@ .Sh SYNOPSIS .Nm rcdn .Op Fl vq -.Op Fl t Ar tag .Op Fl d Ar dir +.Op Fl e Ar excl_pat +.Op Fl I Ar excl_pat +.Op Fl t Ar tag .Op Ar files ... .Sh DESCRIPTION This program will remove all the rc files that the @@ -30,6 +32,17 @@ This can be repeated with additional patterns. See .Xr lsrc 1 , .Sx EXCLUDE PATTERN , for more details. +.It Fl I Ar EXCL_PAT +remove rc files that match +.Ar EXCL_PAT +despite being excluded by the +.Fl e +flag or a setting in +.Xr rcrc 5 . +This can be repeated with additional patterns. See +.Xr lsrc 1 , +.Sx EXCLUDE PATTERN , +for more details. .It Fl q decrease verbosity .It Fl t Ar TAG diff --git a/man/rcup.1 b/man/rcup.1 index 16c818c..342ee6b 100644 --- a/man/rcup.1 +++ b/man/rcup.1 @@ -8,6 +8,8 @@ .Nm rcup .Op Fl fiqv .Op Fl d Ar dir +.Op Fl e Ar excl_pat +.Op Fl I Ar excl_pat .Op Fl t Ar tag .Op Ar files ... .Sh DESCRIPTION @@ -42,6 +44,17 @@ symlink If the rc file already exists in your home directory but does not match the file in your dotfiles directory, prompt for how to handle it. This is the default +.It Fl I Ar EXCL_PAT +install rc files that match +.Ar EXCL_PAT +despite being excluded by the +.Fl e +flag or a setting in +.Xr rcrc 5 . +This can be repeated with additional patterns. See +.Xr lsrc 1 , +.Sx EXCLUDE PATTERN , +for more details. .It Fl t Ar TAG install dotfiles according to .Ar TAG -- cgit v1.2.3