olets / zsh-abbr

The zsh manager for auto-expanding abbreviations, inspired by fish. ~18,000 clones by ~12,000 unique cloners as of Sept '24, and averaging ~60 Homebrew installs monthly since June 2023
https://zsh-abbr.olets.dev
Other
554 stars 19 forks source link

Adjust mktemp usage for GNU mktemp compatibility #1

Closed ifreund closed 4 years ago

ifreund commented 4 years ago

GNU mktemp requires a minimum of three X's at the end of the filename.

Also, $TMPDIR is usually not defined on linux distributions, in which case /tmp should be used as a default.

https://linux.die.net/man/1/mktemp

Hopefully this still works on mac, I tried to keep it as compatible as possible.

olets commented 4 years ago

Good to know, I'll check this out this weekend. Thanks!

ifreund commented 4 years ago

cool, an alternative solution which would better mirror the current behavior would be applying this patch

From 64cce9b35591863658f0afaf54ced68650a94baa Mon Sep 17 00:00:00 2001
From: Isaac Freund <ifreund@ifreund.xyz>
Date: Sat, 22 Feb 2020 17:18:54 +0100
Subject: [PATCH] Remove unneeded mktemp usage

---
 zsh-abbr.zsh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/zsh-abbr.zsh b/zsh-abbr.zsh
index 441021e..63b943b 100755
--- a/zsh-abbr.zsh
+++ b/zsh-abbr.zsh
@@ -482,7 +482,7 @@ _zsh_abbr() {
       typeset -p ZSH_ABBR_UNIVERSALS > "$ZSH_ABBR_UNIVERSALS_SCRATCH_FILE"

       rm "$abbr_universals_updated" 2> /dev/null
-      mktemp "$abbr_universals_updated" 1> /dev/null
+      touch "$abbr_universals_updated" 1> /dev/null

       for abbreviation expansion in ${(kv)ZSH_ABBR_UNIVERSALS}; do
         echo "abbr -a -U -- $abbreviation $expansion" >> "$abbr_universals_updated"
@@ -739,10 +739,10 @@ _zsh_abbr_init() {
   fi

   # Scratch file
-  ZSH_ABBR_UNIVERSALS_SCRATCH_FILE="${TMPDIR}/abbr_universals"
+  ZSH_ABBR_UNIVERSALS_SCRATCH_FILE="${TMPDIR:-/tmp}/abbr_universals"

   rm "$ZSH_ABBR_UNIVERSALS_SCRATCH_FILE" 2> /dev/null
-  mktemp "$ZSH_ABBR_UNIVERSALS_SCRATCH_FILE" 1> /dev/null
+  touch "$ZSH_ABBR_UNIVERSALS_SCRATCH_FILE" 1> /dev/null

   # Load saved universal abbreviations
   if [ -f "$ZSH_ABBR_UNIVERSALS_FILE" ]; then
-- 
2.25.1
ifreund commented 4 years ago

Closing this in favor of #3.