How do I convert this zsh function to fish shell?

时间秒杀一切 提交于 2019-12-14 02:30:43

问题


I have this function which works great in zsh, but I want to convert it to fish shell and I can't get it working.

function ogf () {
  echo "Cloning, your editor will open when clone has completed..."
  source <(TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts "$1")
}

回答1:


First of all, since fish's syntax differs from zsh, you also have to change the output of clone_git_file to source it.

For example, if clone_git_file is something like:

#!/bin/bash
echo "FOO=$TARGET_DIRECTORY"
echo "BAR=$2"

you have to change it to fish syntax.

#!/bin/bash
echo "set -gx FOO $TARGET_DIRECTORY"
echo "set -gx BAR $2"

Now here's the ogf() function, and sample code for fish:

function ogf
  echo "Cloning, your editor will open when clone has completed..."
  source (env TARGET_DIRECTORY=~/students EDITOR=$EDITOR clone_git_file -ts $argv[1] | psub)
end

ogf MY_ARGUMENT
echo "FOO is $FOO"
echo "BAR is $BAR"

Running this code with fish, the output is:

FOO is /home/MY_USER/students
BAR is MY_ARGUMENT


来源:https://stackoverflow.com/questions/41691787/how-do-i-convert-this-zsh-function-to-fish-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!