--- /dev/null
+#
+# Helper functions for temporary files, directories, and pastebining
+#
+# Copyright © 1994–2017 martin f. krafft <madduck@madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+# Source repository: http://git.madduck.net/v/etc/zsh.git
+#
+
+cdt() {
+ emulate -L zsh
+ REPLY=$(mktemp -td ${1:-cdt}.XXXXXX)
+ builtin cd $REPLY
+ rm -f ${TMPDIR:-/tmp}/cdt.latest
+ ln -s $REPLY ${TMPDIR:-/tmp}/cdt.latest
+}
+
+_cdt() {
+ cdt "$@"
+ zle reset-prompt
+ zle -M "$REPLY"
+}
+zle -N _cdt
+bindkey '\ed' _cdt
+
+vit() {
+ emulate -L zsh
+ local prefix i
+ for i in "$@"; do
+ case "$i" in
+ -) local stdin=1; shift;;
+ *) if [ -z "${prefix:-}" ]; then
+ prefix="$i"; shift
+ else
+ zwarn "prefix $prefix already specified, skipping: $i"
+ fi
+ ;;
+ esac
+ done
+ REPLY=$(mktemp -t ${prefix:-vit}-XXXXXX.txt)
+ [ -n "$stdin" ] && cat >| $REPLY
+ sensible-editor +start $REPLY </dev/tty >/dev/tty
+ ln -sf $REPLY ${TMPDIR:-/tmp}/vit.latest
+}
+_vit() {
+ vit "$@"
+ zle reset-prompt
+ zle -M "$REPLY"
+}
+zle -N _vit
+bindkey '\ef' _vit
+
+pastebin() {
+ local target="${(%):-"%D{%F-%H%M%S}"}-${1##*/}"
+ pub "${1}==${target}" 2>&1
+}
+
+_pastebinit() {
+ emulate -L zsh
+ if [[ -f "$REPLY" ]]; then
+ read -q "yesno?\rShould I paste the file $REPLY? [yN] "
+ zle reset-prompt
+ else
+ vit paste
+ yesno=y
+ fi
+ if [[ ${yesno:-n} == y ]]; then
+ zle -cR "pasting $REPLY …"
+ REPLY=$(pastebin "${REPLY}")
+ zle -M "$REPLY"
+ fi
+}
+zle -N _pastebinit
+bindkey '\ep' _pastebinit
+
+_copy_reply() {
+ if [[ -n "$REPLY" ]]; then
+ if (( $+commands[xclip] )); then
+ echo -En "$REPLY" | xclip -in
+ zle -M "Copied to primary clipboard: $REPLY"
+ else
+ zle -M "Cannot copy to clipboard, xclip command not found"
+ fi
+ else
+ zle -M "Nothing to copy, \$REPLY is empty"
+ fi
+}
+zle -N _copy_reply
+bindkey '\ec' _copy_reply
+
+TS() {
+ local topic ret quiet
+ typeset -g REPLY
+ topic="${(j:_:)@}"
+ REPLY="${TMPDIR:-/tmp}/script.${topic:-$LOGNAME}.$$.${(%):-"%D{%Y%m%d.%H%M}"}"
+ PS1="
+%# " RPS1= script -qe -c "zsh -f" -f "$REPLY"
+ ret=$?
+ zinfo "typescript is in $REPLY ."
+ return $ret
+}
+
+# vim:ft=zsh