diff options
| author | Suleyman Farajli <suleyman@farajli.net> | 2025-11-18 16:47:04 +0400 |
|---|---|---|
| committer | Suleyman Farajli <suleyman@farajli.net> | 2025-11-18 16:47:04 +0400 |
| commit | 4d69e36a1248f99d1adf37c6ce47a0bb5a333a62 (patch) | |
| tree | cce9d9a2517cd1e3bc4c0d27b5c24d1af07087c4 | |
| parent | 6bdf89bd7378bf188998deb59f8089b1e4e94776 (diff) | |
slib: add `get_random_filename`
| -rwxr-xr-x | scripts/slib | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scripts/slib b/scripts/slib index 828c4cb..0df4a50 100755 --- a/scripts/slib +++ b/scripts/slib @@ -76,6 +76,24 @@ send_notification() { xsetroot -name "fsignal:1" } +# @FUNCTION: get_random_filename +# @USAGE: get_random_filename [parentdir] <extension> +# @DESCRIPTION: +# Write a random file path to stdout, under parentdir, (if provided else under /tmp) with the extension. +# +# @EXAMPLE: +# Get a filepath in the `/var` directory with the extension `.png` +# +# get_random_filename /var .png + +get_random_filename() { + [ "${#}" -eq 2 ] && parentdir="${2}" || parentdir="/tmp" + + extension="${1}" + + echo "${parentdir}/$(date '+%b%d::%H%M%S')${extension}" +} + # @FUNCTION: run # @USAGE: [--reload-status] [--reload-compositor] [--success-notify <msg>] [--failure-notify <msg>] <command> [success-msg] [failure-msg] # @DESCRIPTION: |
