#!/bin/zsh
#function subenv {
  emulate -L zsh; setopt local_options

  if (( $# == 0 )); then
    set -- HOME
  fi

  local -a sedargs=(-e "s|\$HOME|$HOME|g")
  while (( $# )); do
    if [[ -v "$1" ]]; then
      sedargs+=(-e "s|${(P)1}|\$$1|g")
    fi
    shift
  done
  sed "$sedargs[@]"
#}
