From: martin f. krafft Date: Thu, 3 Feb 2022 06:15:40 +0000 (+0100) Subject: Improved tmpdir functions X-Git-Url: https://git.madduck.net/etc/zsh.git/commitdiff_plain/2188fcdf52262cc8ed492d9ad439e6ca91f5e9ca?ds=sidebyside;hp=3461c406d3de0fa8152660096c0514a39194c41c Improved tmpdir functions --- diff --git a/.zsh/zshenv/00-tmpdir b/.zsh/zshenv/00-tmpdir index 9bce287..1184b07 100644 --- a/.zsh/zshenv/00-tmpdir +++ b/.zsh/zshenv/00-tmpdir @@ -7,7 +7,7 @@ # Source repository: http://git.madduck.net/v/etc/zsh.git # -export TMPDIR="/tmp/${(%):-%n}" +TMPDIR="/tmp/${(%):-%n}" mkdir --mode=700 --parent "${TMPDIR}" typeset -l LTMPDIR="${HOME}/.tmp" @@ -19,4 +19,6 @@ fi TMPPREFIX="${TMPDIR}/zsh" +export TMPDIR + # vim:ft=zsh diff --git a/.zsh/zshrc/20-tempfile+dir_functions b/.zsh/zshrc/20-tempfile+dir_functions index 6781557..c45c3c3 100644 --- a/.zsh/zshrc/20-tempfile+dir_functions +++ b/.zsh/zshrc/20-tempfile+dir_functions @@ -9,10 +9,16 @@ 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" } @@ -26,22 +32,23 @@ 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 "${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) + local file="$(date +'%F-%H%M%S')${tag:+-$tag}" + REPLY="${TMPDIR:-/tmp}/$file" [ -n "$stdin" ] && cat >| "$REPLY" sensible-editor +start "$REPLY" /dev/tty - ln -sf "$REPLY" ${TMPDIR:-/tmp}/vit.latest + ln -Tsf $file ${TMPDIR:-/tmp}/${tag:-vit} echo "$REPLY" } _vit() { @@ -53,7 +60,12 @@ 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 }