【问题标题】:How to use a line of hyphen to separate git command results within git alias in git-bash如何在 git-bash 的 git 别名中使用一行连字符来分隔 git 命令结果
【发布时间】:2019-11-11 18:34:05
【问题描述】:

我已经创建了一个名为 info 的别名来显示状态、分支和登录 git-bash。然而,所有的信息都被捆绑在一起,阅读起来有些烦人,所以我想通过在上面和下面添加一行带有新行的连字符来让自己在阅读时更容易。经过多次尝试,我无法让它工作。因此,我在这里寻求帮助。

这是我之前尝试过的,试图在将它复制到 git branch 和 git log 之间之前让一个工作。

$ git config --global alias.info '!git status && echo && !printf -- '-%.0s' {1..80}; echo "" && echo && git branch && git log'

下面是结果的样子。

git status result

-----------------------

git branch result

-----------------------

git log result

【问题讨论】:

    标签: bash git github git-bash


    【解决方案1】:

    如果!语法没有给出预期的结果,试试embed your commands in a shell function within your Git alias:

    alias.info !f() { echo begin arg=$1/$2/end; }; f
    

    甚至在单独的脚本中:

    git config --global alias.info '!sh info.sh'
    

    重点是:如果你可以让它在常规的 shell 脚本中工作,你就可以从别名中调用它。

    或者您甚至可以将您的脚本命名为git-info(可执行,无扩展名),然后输入:

    git info
    

    那里不需要别名:任何git-xxx 脚本都可以称为git xxx(如果git-xxx 在您的PATH 中)

    【讨论】:

      猜你喜欢
      • 2012-09-29
      • 2022-01-24
      • 1970-01-01
      • 2022-07-09
      • 2021-07-13
      • 2016-05-13
      • 2017-08-23
      • 2022-12-23
      • 2011-02-02
      相关资源
      最近更新 更多