X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/e7f4a8c5997e22bae02d741e9b1f40c42b0b0eb8..a89e29c6ee8aec55e559f411431108c850533154:/.zsh/zshrc/39_tempfuncs?ds=sidebyside diff --git a/.zsh/zshrc/39_tempfuncs b/.zsh/zshrc/39_tempfuncs index de2e232..79f43dd 100644 --- a/.zsh/zshrc/39_tempfuncs +++ b/.zsh/zshrc/39_tempfuncs @@ -9,15 +9,32 @@ # cdt () { - builtin cd $(mktemp -td cdt.XXXXXX) + local tmpdir + tmpdir=$(mktemp -td ${1:-cdt}.XXXXXX) + builtin cd $tmpdir pwd + ln -sf $tmpdir ${TMPDIR:-/tmp}/cdt.latest } vit () { - local tmpfile=$(mktemp -t vit.XXXXXX) - [ "$1" = '-' ] && cat >| $tmpfile + local prefix + for i in "$@"; do + case "$i" in + -) local stdin=1; shift;; + *) if [ -z "${prefix:-}" ]; then + prefix="$i"; shift + else + error "prefix already specified: $prefix" + return 1 + fi + ;; + esac + done + local tmpfile=$(mktemp -t ${prefix:-vit}.XXXXXX) + [ -n "$stdin" ] && cat >| $tmpfile sensible-editor $tmpfile /dev/tty echo $tmpfile + ln -sf $tmpfile ${TMPDIR:-/tmp}/vit.latest } # vim:ft=zsh