zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Feature request: set extension for =( ) created file
Date: Sat, 24 Sep 2016 14:06:38 -0700	[thread overview]
Message-ID: <160924140638.ZM29136@torch.brasslantern.com> (raw)
In-Reply-To: <A69FBAB9-747D-450C-8355-990DEB759801@macports.org>

On Sep 24,  3:55pm, Lawrence Velazquez wrote:
}
} > Extension-aware =( ) would be a masterpiece feature for Zsh, though,
} > IMO.
} 
} Unless it were implemented using libmagic or something, I would consider
} it a massive waste of time and effort.

Hence my suggestion of a wrapper function that calls "file".

You can generalize my example to have a mapping from "file" output strings
to file extensions, and then do something like this:

appendfileext() {
  local filetype="$(file $1)"
  if [[ -n "${filextcache[$filetype]} ]]; then
    REPLY="$1.${filextcache[$filetype]}"
  else
    case "$filetype" in 
    (...) : you fill this in;;
    (*) unset REPLY;;
    esac
  fi
}

fixfiletype() {
  local REPLY
  integer i
  declare -a removes
  { 
    for ((i=1; i <= $#; ++i)); do
      if [[ "${argv[i]}" = "$TMPPREFIX"* ]]; then
        appendfileext "${argv[i]}"
        if [[ -n "$REPLY" ]];then
          removes+="$REPLY"
          ln "${argv[i]}" "$REPLY"
          argv[i]="$REPLY"
        fi
      fi
    done
    "${argv[@]}"
  } always {
    [[ -n "$removes" ]] && /bin/rm -f "${removes[@]}"
  }
}

alias vim='fixfiletype vim '


  parent reply	other threads:[~2016-09-24 21:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-24 17:51 Sebastian Gniazdowski
2016-09-24 17:55 ` Vadim Zeitlin
2016-09-24 18:43   ` Lawrence Velázquez
2016-09-24 19:30     ` Sebastian Gniazdowski
2016-09-24 19:55       ` Lawrence Velázquez
2016-09-24 20:14         ` Sebastian Gniazdowski
2016-09-24 20:36           ` Lawrence Velázquez
2016-09-24 20:44             ` Sebastian Gniazdowski
2016-09-24 21:06               ` Lawrence Velázquez
2016-09-24 21:24                 ` Bart Schaefer
2016-09-24 21:58                   ` Lawrence Velázquez
2016-09-25  0:05           ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-09-25  5:17             ` Bart Schaefer
2016-09-25  6:17               ` Sebastian Gniazdowski
2016-09-25 15:21                 ` Lawrence Velázquez
2016-09-26 18:03                 ` Bart Schaefer
2016-09-25 16:58               ` Nikolay Aleksandrovich Pavlov (ZyX)
2016-09-25 22:37                 ` Bart Schaefer
2016-09-24 21:06         ` Bart Schaefer [this message]
2016-09-24 18:56   ` Sebastian Gniazdowski
2016-09-24 18:22 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160924140638.ZM29136@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).