X-Git-Url: https://git.madduck.net/etc/zsh.git/blobdiff_plain/a465abc69e8bb12baf6e42dd5234e61a584c6071..4b5c0d3763f9fb157b8df7623907e4735371ebe6:/.zsh/zshrc/20-tempfile%20dir_functions/etc/zsh.git/blobdiff_plain/a465abc69e8bb12baf6e42dd5234e61a584c6071..4b5c0d3763f9fb157b8df7623907e4735371ebe6:/.zsh/zshrc/20-tempfile+dir_functions diff --git a/.zsh/zshrc/20-tempfile+dir_functions b/.zsh/zshrc/20-tempfile+dir_functions index 52ceb19..6ca6998 100644 --- a/.zsh/zshrc/20-tempfile+dir_functions +++ b/.zsh/zshrc/20-tempfile+dir_functions @@ -9,14 +9,22 @@ 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 "$@" >/dev/null zle reset-prompt zle -M "$REPLY" } @@ -25,23 +33,31 @@ bindkey '\ed' _cdt vit() { emulate -L zsh - local prefix i + local i tag 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 - zwarn "prefix $prefix already specified, skipping: $i" + zwarn "tag $tag already specified, skipping: $i" fi ;; esac done - REPLY=$(mktemp -t ${prefix:-vit}-XXXXXX.txt) - [ -n "$stdin" ] && cat >| $REPLY - sensible-editor +start $REPLY /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 + ln -Tsf $file ${TMPDIR:-/tmp}/${tag:-vit} echo "$REPLY" + print -s sensible-editor "$REPLY" } _vit() { vit "$@" >/dev/null @@ -52,19 +68,20 @@ zle -N _vit 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 } _pastebinit() { emulate -L zsh - if [[ -f "$REPLY" ]]; then - read -q "yesno? Should I paste the file $REPLY? [yN] " - zle reset-prompt - else - vit paste - yesno=y - fi + [[ -f "$REPLY" ]] || vit paste + read -q "yesno? Should I paste the file $REPLY? [yN] " + zle reset-prompt if [[ ${yesno:-n} == y ]]; then zle -cR "pasting $REPLY …" REPLY=$(pastebin "${REPLY}") @@ -90,14 +107,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 }