Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust mktemp usage for GNU mktemp compatibility #1

Closed
wants to merge 1 commit into from

Conversation

ifreund
Copy link
Contributor

@ifreund ifreund commented Feb 13, 2020

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.

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.
@olets
Copy link
Owner

olets commented Feb 22, 2020

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

@ifreund
Copy link
Contributor Author

ifreund commented Feb 22, 2020

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
Copy link
Contributor Author

ifreund commented Feb 22, 2020

Closing this in favor of #3.

@ifreund ifreund closed this Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants