#!/usr/bin/env bash
# Desc: Scan file system and update '.hidden' files to hide certain
# files based on filenames.
+# Version: 0.0.3
# Usage: bk-naut-hide [DIRS...]
yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
if [[ ! -d "$1" ]]; then die "FATAL:Not a dir:$1"; fi;
# Search for files named '.hidden'
- find -L "$1" -type f -name ".hidden" 2>/dev/null
+ find "$1" -type f -name ".hidden" 2>/dev/null
}; # Return list of paths of '.hidden' files
main() {
die "FATAL:Not a dir:arg:$arg";
fi;
done;
- yell "DEBUG:dirs_target:${dirs_target[*]}";
+ #yell "DEBUG:dirs_target:${dirs_target[*]}";
# specify filename regex patterns to mark '.hidden'
pat_tohide+=(".ots$");
pat_tohide+=(".ots.bak$");
- yell "DEBUG:pat_tohide:${pat_tohide[*]}";
+ #yell "DEBUG:pat_tohide:${pat_tohide[*]}";
# generate list of paths of '.hidden' files
for dir in "${dirs_target[@]}"; do
- yell "DEBUG:generating list of paths of '.hidden' files in dir:$dir";
+ #yell "DEBUG:generating list of paths of '.hidden' files in dir:$dir";
while read -r file; do
ls_dothide_f+=("$file");
done < <(get_paths_dothide "$dir");
done;
- yell "DEBUG:ls_dothide_f:${ls_dothide_f[*]}";
- yell "DEBUG:";
+ #yell "DEBUG:ls_dothide_f:${ls_dothide_f[*]}";
+ #yell "DEBUG:";
# get list of dirs containing the files
while read -r line; do
- yell "DEBUG:found .hidden file at:$line";
+ #yell "DEBUG:found .hidden file at:$line";
dir="$(dirname "$line")";
ls_dothide_d+=("$dir");
done < <(printf "%s\n" "${ls_dothide_f[@]}")
- yell "DEBUG:ls_dothide_d:${ls_dothide_d[*]}";
- yell "DEBUG:";
+ #yell "DEBUG:ls_dothide_d:${ls_dothide_d[*]}";
+ #yell "DEBUG:";
# for each dir, write list of files to hide in '.hidden'
while read -r dir; do
- yell "DEBUG:performing actions in dir:$dir";
+ #yell "DEBUG:performing actions in dir:$dir";
declare -a ls_tohide_fn; # array for filenames to write in '.hidden'
## act on each file
while read -r file; do
- yell "DEBUG:considering file:$file";
+ #yell "DEBUG:considering file:$file";
filename="$(basename "$file")";
## check if file is actually a file
## add file to list to add to '.hidden'
if [[ $flag_pat_match == "true" ]]; then
- yell "DEBUG:adding to ls_tohide_fn:file:$file":
- yell "DEBUG:filename:$filename";
+ #yell "DEBUG:adding to ls_tohide_fn:file:$file":
+ #yell "DEBUG:filename:$filename";
ls_tohide_fn+=("$filename");
fi;
- yell "DEBUG:";
+ #yell "DEBUG:";
## unset variables defined only for this file
unset filename flag_pat_match;
done < <(find "$dir" -mindepth 1 -maxdepth 1 -type f 2>/dev/null);
- yell "DEBUG:";
+ #yell "DEBUG:";
## add file names to $dir/'.hidden'
### remove blank lines and sort and uniq
### write '.hidden'
path_hidefile="$dir"/.hidden;
- yell "DEBUG:Writing contents of .hidden file at path_hidefile:$path_hidefile";
- yell "DEBUG:ls_tohide_fn:$(printf "%s\n" "${ls_tohide_fn[@]}" )";
+ #yell "DEBUG:Writing contents of .hidden file at path_hidefile:$path_hidefile";
+ #yell "DEBUG:ls_tohide_fn:$(printf "%s\n" "${ls_tohide_fn[@]}" )";
printf "%s\n" "${ls_tohide_fn[@]}" > "$path_hidefile"
## unset variables defined only for this dir
unset ls_tohide_fn path_hidefile;
- yell "DEBUG:";
+ #yell "DEBUG:";
done < <(printf "%s\n" "${ls_dothide_d[@]}");
}; # main program