]> 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:

push tempfile commands to history
[etc/zsh.git] / .zsh / zshrc / 20-tempfile+dir_functions
index f44c0582bf36edbd47b379ac5833146b8eb9bf8d..6ca6998c579aaa4ef76fc6b9cc7c51df6b73e407 100644 (file)
@@ -9,14 +9,22 @@
 
 cdt() {
   emulate -L zsh
 
 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
+  local dirname="$(date +'%F-%H%M%S')${1:+-$1}"
+  REPLY="${TMPDIR:-/tmp}/$dirname"
+  mkdir -m700 "$REPLY"
+  if [[ -n "$1" ]]; then
+    local link="${TMPDIR:-/tmp}/${1:-cdt}"
+    ln -Tnsf "$dirname" "$link"
+    builtin cd "$link"
+  else
+    builtin cd "$REPLY"
+  fi
+  echo "$REPLY"
+  print -s cd "$REPLY"
 }
 
 _cdt() {
 }
 
 _cdt() {
-  cdt "$@"
+  cdt "$@" >/dev/null
   zle reset-prompt
   zle -M "$REPLY"
 }
   zle reset-prompt
   zle -M "$REPLY"
 }
@@ -25,23 +33,31 @@ bindkey '\ed' _cdt
 
 vit() {
   emulate -L zsh
 
 vit() {
   emulate -L zsh
-  local prefix i
+  local i tag
   for i in "$@"; do
     case "$i" in
       -) local stdin=1; shift;;
   for i in "$@"; do
     case "$i" in
       -) local stdin=1; shift;;
-      *) if [ -z "${prefix:-}" ]; then
-           prefix="$i"; shift
+      .*) if [ -z "${ft:-}" ]; then
+            ft="${i#.}"; shift
+          else
+            zwarn "filetype $ft already specified, skipping: ${i#.}"
+          fi
+          ;;
+      *) if [ -z "${tag:-}" ]; then
+           tag="$i"; shift
          else
          else
-           zwarn "prefix $prefix already specified, skipping: $i"
+           zwarn "tag $tag already specified, skipping: $i"
          fi
          ;;
     esac
   done
          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
+  local file="$(date +'%F-%H%M%S')${tag:+-$tag}"
+  REPLY="${TMPDIR:-/tmp}/$file"
+  [ -n "$stdin" ] && cat >| "$REPLY"
+  sensible-editor +start "$REPLY" </dev/tty >/dev/tty
+  ln -Tsf $file ${TMPDIR:-/tmp}/${tag:-vit}
   echo "$REPLY"
   echo "$REPLY"
+  print -s sensible-editor "$REPLY"
 }
 _vit() {
   vit "$@" >/dev/null
 }
 _vit() {
   vit "$@" >/dev/null
@@ -52,7 +68,12 @@ zle -N _vit
 bindkey '\ef' _vit
 
 pastebin() {
 bindkey '\ef' _vit
 
 pastebin() {
-  local target="${(%):-"%D{%F-%H%M%S}"}-${1##*/}"
+  local target basename;
+  basename="${1##*/}"
+  case "$basename" in
+    (????-??-??-*) target="$basename";;
+    (*) target="${(%):-"%D{%F-%H%M%S}"}-$basename";;
+  esac
   pub "${1}==${target}" 2>&1
 }
 
   pub "${1}==${target}" 2>&1
 }