aboutsummaryrefslogtreecommitdiff
path: root/bin/tmpname
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-11-17 17:58:41 -0300
committerEuAndreh <eu@euandre.org>2022-11-17 17:58:41 -0300
commit62ca1a97e0848ef5f9043da69c6af8a9b0bb9808 (patch)
tree9fa23a49cf205c7162a3604418775cbc798ee3c7 /bin/tmpname
parentInitial empty commit (diff)
parentopt/bin-dirs/clisp: Include custom build of CLISP (diff)
downloaddotfiles-62ca1a97e0848ef5f9043da69c6af8a9b0bb9808.tar.gz
dotfiles-62ca1a97e0848ef5f9043da69c6af8a9b0bb9808.tar.xz
Merge remote-tracking branch 'tilde/main'
Diffstat (limited to 'bin/tmpname')
-rwxr-xr-xbin/tmpname66
1 files changed, 66 insertions, 0 deletions
diff --git a/bin/tmpname b/bin/tmpname
new file mode 100755
index 0000000..89d7e4d
--- /dev/null
+++ b/bin/tmpname
@@ -0,0 +1,66 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ tmpname
+ tmpname -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+
+ Generate a temporary name.
+
+
+ Examples:
+
+ Create a temporary file:
+
+ $ OUT="$(tmpname)"; touch "$OUT"; cmd > "$OUT"
+
+
+ `cd` into a temporary directory:
+
+ $ DIR="$(tmpname)"; mkdir -p "$DIR"; cd "$DIR"
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+echo "${TMPDIR:-/tmp}/uuid-tmpname with spaces.$(uuid)"