Skip to content

Instantly share code, notes, and snippets.

@apuignav
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save apuignav/f6f145c27f24ee302558 to your computer and use it in GitHub Desktop.

Select an option

Save apuignav/f6f145c27f24ee302558 to your computer and use it in GitHub Desktop.
Create a temp directory and open a shell in it. When finished, delete the temp directory.
#!/usr/bin/env zsh --login
# Create temp dir
tmp=${1-$TMPDIR}
tmp=$tmp/tmp.$RANDOM.$RANDOM.$RANDOM.$$
(umask 077 && mkdir $tmp) || {
echo "Could not create temporary directory! Exiting." 1>&2
exit 1
}
# Go to it and start a new shell
cd $tmp
/usr/bin/env TMPSHELL=1 zsh
# Delete temp files
rm -rf $tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment