【问题标题】:Is there any way to type some text automatically on terminal?有没有办法在终端上自动输入一些文本?
【发布时间】:2019-03-19 11:03:32
【问题描述】:

当我通过终端使用 git 时,我只打开一个专用于 git 命令的选项卡,然后我不想每次都输入“git”。有什么方法可以让每一行都自动输入一些文字?

【问题讨论】:

  • ~/.bashrc: alias g=git
  • 你真的太忙了,不能输入三个字符?

标签: bash git terminal


【解决方案1】:

您可以将每个 git 命令定义为别名,例如输入diff mybranch 将调用git diff mybranch。要调用普通的 shell 命令,请在其前面键入反斜杠,例如 \diff file ../elsewhere/file 调用 /usr/bin/diff 而不是 git diff

将以下代码放入文件~/.git.bashrc。将您的 git 终端配置为运行 bash --rcfile ~/.git.bashrc 而不是仅运行 bash

. ~/.bashrc
for c in $(COLUMNS=4 git help -a | sed -n 's/^  \([a-z]\)/\1/p';
           git config --get-regexp '^alias.' | sed 's/alias\.//; s/ .*//')
do
  alias "$c=git $c"
  complete -F _complete_alias foo
done

complete 行需要_complete_alias function

【讨论】:

    【解决方案2】:

    我创建了这个 .bashrc 函数来推送代码并标记它。 你需要给它的只是你想要推送的评论。

    函数的别名是“gp”(代表git push)。

    所以如果你想推送和标记一些代码,在你将这些代码添加到你的 .bashrc 之后,你需要的是:

    $ gp "测试我的新 git push 功能"

    gpfunction() {
        git status
        echo [Enter to continue...]
        read a
        git pull
        git commit -am"$1"
        git push
        tag_major_min=$(git tag |sort -V|tail -1|awk -F. '{print $1 "." $2 "."}')
        echo Tag major min $tag_major_min
        latest_tag_number=$(git tag |sort -V|tail -1|awk -F. '{print $3}')
        echo Latest tag number $latest_tag_number
        next=$(echo $latest_tag_number + 1 | bc)
        echo Next $next
        new_tag=$(echo $tag_major_min $next | sed 's/ //g')
        echo New tag $new_tag
        git tag $new_tag
        git push origin $new_tag
    }
    alias gp=gpfunction
    

    此脚本使用major.minor.patch 版本标准并递增补丁版本。

    您可以随意调整它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 1970-01-01
      • 2010-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多