X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/c560a7fe17aedf2393b7d3313e60e795702bbc14..26f0533782d8c57fb95b8df4f55057edcbf17703:/user/bk-naut-hide diff --git a/user/bk-naut-hide b/user/bk-naut-hide index 7f88e41..7f24496 100755 --- a/user/bk-naut-hide +++ b/user/bk-naut-hide @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Desc: Scan file system and update '.hidden' files to hide certain # files based on filenames. -# Version: 0.0.1 +# Version: 0.0.3 # Usage: bk-naut-hide [DIRS...] yell() { echo "$0: $*" >&2; } # print script path and all args to stderr @@ -173,7 +173,7 @@ get_paths_dothide() { 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() { @@ -188,40 +188,40 @@ 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 @@ -240,16 +240,16 @@ main() { ## 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 @@ -260,14 +260,14 @@ main() { ### 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