From 9412e8bfb1b58496e953bfad1db02bbd9d576a49 Mon Sep 17 00:00:00 2001 From: Lucas Kanashiro Date: Sun, 4 Mar 2018 22:33:40 -0300 Subject: [PATCH] Use mktemp to create temporary directory and files Closes #81 --- bin/run | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/run b/bin/run index 804a137..4d51a55 100755 --- a/bin/run +++ b/bin/run @@ -36,8 +36,8 @@ done ### AW_PATH=$HOME/.vim-anywhere -TMPFILE_DIR=/tmp/vim-anywhere -TMPFILE=$TMPFILE_DIR/doc-$(date +"%y%m%d%H%M%S") +TMPFILE_DIR="$(mktemp -d /tmp/vim-anywhere.XXX)" +TMPFILE_TEMPLATE=doc-$(date +"%y%m%d%H%M%S").XXX VIM_OPTS=--nofork # Use ~/.gvimrc.min or ~/.vimrc.min if one exists @@ -50,8 +50,14 @@ for vimrc_path in "${VIMRC_PATH[@]}"; do fi done -mkdir -p $TMPFILE_DIR -touch $TMPFILE +TMPFILE="$(mktemp -p $TMPFILE_DIR -t $TMPFILE_TEMPLATE)" + +function remove_tmp_dir() { + rm -rf $TMPFILE_DIR +} + +## Removes all temp files on exit and sigint +trap "remove_tmp_dir" EXIT SIGINT # Linux if [[ $OSTYPE == "linux-gnu" ]]; then