]> git.madduck.net Git - etc/zsh.git/blobdiff - .zsh/zshrc/20-tempfile+dir_functions

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

do not glob for mkdir
[etc/zsh.git] / .zsh / zshrc / 20-tempfile+dir_functions
index 5288098c0f35d8918ce97c319d97f6bd5f0e93a2..6781557728e351b76b2a6e455e3e17ee60b91ff1 100644 (file)
 cdt() {
   emulate -L zsh
   REPLY=$(mktemp -td ${1:-cdt}.XXXXXX)
-  builtin cd $REPLY
+  builtin cd "$REPLY"
   rm -f ${TMPDIR:-/tmp}/cdt.latest
-  ln -s $REPLY ${TMPDIR:-/tmp}/cdt.latest
+  ln -s "$REPLY" ${TMPDIR:-/tmp}/cdt.latest
+  echo "$REPLY"
 }
 
 _cdt() {
@@ -38,12 +39,13 @@ vit() {
     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
+  [ -n "$stdin" ] && cat >| "$REPLY"
+  sensible-editor +start "$REPLY" </dev/tty >/dev/tty
+  ln -sf "$REPLY" ${TMPDIR:-/tmp}/vit.latest
+  echo "$REPLY"
 }
 _vit() {
-  vit "$@"
+  vit "$@" >/dev/null
   zle reset-prompt
   zle -M "$REPLY"
 }
@@ -57,13 +59,9 @@ pastebin() {
 
 _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
+  [[ -f "$REPLY" ]] || vit paste
+  read -q "yesno?\rShould I paste the file $REPLY? [yN] "
+  zle reset-prompt
   if [[ ${yesno:-n} == y ]]; then
     zle -cR "pasting $REPLY …"
     REPLY=$(pastebin "${REPLY}")
@@ -89,14 +87,21 @@ zle -N _copy_reply
 bindkey '\ec' _copy_reply
 
 TS() {
-  local topic ret quiet
-  typeset -g REPLY
+  local topic ts ret script
   topic="${(j:_:)@}"
-  REPLY="${TMPDIR:-/tmp}/script.${topic:-$LOGNAME}.$$.${(%):-"%D{%Y%m%d.%H%M}"}"
+  ts=${(%):-%D{%Y-%m-%d-%H%M}}
+  script="${TMPDIR:-/tmp}/$ts.$$.${topic:-$LOGNAME}.typescript"
   PS1="
-%# " RPS1= script -qe -c "zsh -f" -f "$REPLY"
+%# " RPS1= script -qe -c "zsh -f" -f "$script"
   ret=$?
-  zinfo "typescript is in $REPLY ."
+  zinfo "typescript is in $script ."
+  typeset -g REPLY
+  REPLY="$script"
+  if command -v unterm >/dev/null; then
+    REPLY="${script}.txt"
+    unterm "$script" > "$REPLY"
+  zinfo "plain text transcript is in $REPLY ."
+  fi
   return $ret
 }