zed icon indicating copy to clipboard operation
zed copied to clipboard

Support for reading from stdin

Open tuladhar opened this issue 1 year ago • 1 comments

Check for existing issues

  • [X] Completed

Describe the feature

Have - flag in zed CLI which allows reading from stdin:

Example:

ps auxf | zed -

Currently, zed - just opens the editor with - as filename.

If applicable, add mockups / screenshots to help present your vision of the feature

No response

tuladhar avatar May 01 '23 14:05 tuladhar

strictly speaking, - flag is not a requirement. I know that TextMate's mate cli command detects stdin automagically and does the right thing without additional flags

indeyets avatar Apr 26 '24 08:04 indeyets

I use this so frequently, e.g. with git diff | mate or similar, this would be great to have.

Unfortunately, zed can somehow not open anonymous FDs, so this workaround:

$ pzed() { cat <(cat); }        
$ echo "foo" | pzed     
foo

... does not work:

$ pzed() { zed <(cat); }
$ echo "foo" | pzed     
error opening PathLikeWithPosition { path_like: "/dev/fd/11", row: None, column: None }: failed to read path after update

The only way I've found is to copy to a temp file first, like so:

$ pzed() { local fn=$(mktemp); cat >"$fn"; zed "$fn"; }

This can be turned into a script that dynamically detects stdin and adds it as an argument (works both in Bash and Zsh):

zed() {
  local args=("$@")
  if [[ ! -t 0 ]]; then
    local tmp=$(mktemp)
    cat >"$tmp"
    args+=("$tmp")
  fi
  command zed "${args[@]}"
}

But it's not ideal with the tempfile creation etc.

dzuelke avatar Jul 30 '24 16:07 dzuelke

I have the same issue. My workaround:

alias to_zed='(cat > /tmp/zed.tmp.txt && zed /tmp/zed.tmp.txt)'

funivan avatar Aug 14 '24 05:08 funivan