From: Steven Baltakatei Sandoval Date: Wed, 1 Feb 2023 08:05:54 +0000 (+0000) Subject: feat(u/bkfeh):Accept sample dir size and file count via envvar X-Git-Tag: 0.8.1~16 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/acaa0f3d55adfadcec3cc2c3ff494c768d0faf0d?ds=inline;hp=-c feat(u/bkfeh):Accept sample dir size and file count via envvar --- acaa0f3d55adfadcec3cc2c3ff494c768d0faf0d diff --git a/user/bkfeh b/user/bkfeh index c0410ef..0f8154a 100755 --- a/user/bkfeh +++ b/user/bkfeh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -# Version: 0.1.0 +# Desc: Wrapper for feh that accepts directory paths via posargs or stdin lines. +# Version: 0.2.0 # Ref/Attrib: [1] Tange, Ole. GNU Parallel with Bash Array. 2019-03-24. https://unix.stackexchange.com/a/508365/411854 # Depends: GNU Parallel, GNU Bash v5.1.16, feh 3.6.3 @@ -155,6 +156,35 @@ check_depends() { if ! checkapp feh parallel; then displayMissing; die "FATAL:Missing apps."; fi; return 1; }; # check dependencies +checkInt() { + # Desc: Checks if arg is integer + # Usage: checkInt arg + # Input: arg: integer + # Output: - return code 0 (if arg is integer) + # - return code 1 (if arg is not integer) + # Example: if ! checkInt $arg; then echo "not int"; fi; + # Version: 0.0.1 + local returnState + + #===Process Arg=== + if [[ $# -ne 1 ]]; then + die "ERROR:Invalid number of arguments:$#"; + fi; + + RETEST1='^[0-9]+$'; # Regular Expression to test + if [[ ! $1 =~ $RETEST1 ]] ; then + returnState="false"; + else + returnState="true"; + fi; + + #===Determine function return code=== + if [ "$returnState" = "true" ]; then + return 0; + else + return 1; + fi; +} # Checks if arg is integer read_stdin() { # Desc: Consumes stdin; outputs as stdout lines # Input: stdin (consumes) @@ -218,12 +248,20 @@ save_sample() { # Usage: save_sample arg1 # Input: arg1 list_paths (list of files to take samples from) # envvar BKFEH_SAMPLE_DIR (environment variable set outside of this script) + # envvar BKFEH_SAMPLE_SIZE (space limit for sample dir files) # Depends: yell(), GNU Parallel, GNU find, GNU Coreutils 8.32 (cut, find, du) local list_paths - sample_count="100"; - sample_max_space="100000000"; # bytes - + sample_count="100"; # max number of images to put in sample dir + sample_max_space="10000000"; # max bytes to put in sample dir + + # Load environment variables if set if [[ ! -v BKFEH_SAMPLE_DIR ]]; then return 0; fi; # return early if environment var not set. + if [[ -v BKFEH_SAMPLE_SIZE ]] && checkInt "$BKFEH_SAMPLE_SIZE"; then + sample_max_space="$BKFEH_SAMPLE_SIZE"; + fi; + if [[ -v BKFEH_SAMPLE_COUNT ]] && checkInt "$BKFEH_SAMPLE_COUNT"; then + sample_count="$BKFEH_SAMPLE_COUNT"; + fi; if [[ ! -z "$1" ]]; then list_paths="$1"; # newline-delimited list of file paths to sample from @@ -341,17 +379,17 @@ main() { # Write list_paths_images_tmp="/dev/shm/$(date +%Y%m%dT%H%M%S.%N%z)"..feh_paths.txt; must echo -n "$list_paths_images" > "$list_paths_images_tmp"; - ## Save sample to path in env. var. BKFEH_SAMPLE_DIR if set - save_sample "$list_paths_images"; # Print stats yell "STATUS:Built file list in $SECONDS seconds."; # Run feh with filelist - feh --full-screen --auto-zoom --draw-filename --filelist "$list_paths_images_tmp"; + feh --full-screen --auto-zoom --draw-filename --filelist "$list_paths_images_tmp" && \ + must rm "$list_paths_images_tmp" & - # Cleanup - must rm "$list_paths_images_tmp"; + # Save sample to path in env. var. BKFEH_SAMPLE_DIR if set + save_sample "$list_paths_images"; + }; export -f yell die must read_stdin read_psarg find_flist; #==END Define local functions==