简体   繁体   English

git别名使用$((LINES / 2))

[英]git alias using $((LINES / 2))

我已经尝试了大约30种变体,包括sh -c版本,双引号和单引号,嵌套引号等。我缺少什么?

shortlog = "!git log -n $((LINES / 2))"

What if you define a function? 如果定义函数怎么办?

function shortlog { tmp=$(($LINES / 2)); git log -n "$tmp"; }

then export it: 然后将其导出:

export -f shortlog

You should put it in your .bashrc I guess if you want to use it each time you start a terminal (but you can first try it on a isolated sterminal of course). 您应该将其放在.bashrc我想您是否希望每次启动终端时都使用它(但是您当然可以先在隔离的sterminal上尝试使用它)。


EDIT : 编辑

does this help? 这有帮助吗?

git config alias.shortlog '!f() { tmp=$(($LINES / 2)); git log -n "$tmp"; }; f'

I don't love how I finally got this to work, but it's literally the only thing that's worked at all, and I want this to be over. 我不喜欢我最终如何使它工作,但是从字面上看,这是唯一可行的方法,我希望这一切能够结束。 I removed everything relating to the shorter log aliases from my ~/.gitconfig , and in my ~/scripts folder - which is in my $PATH - I made files with names like git-las (list all short), with code like this in each: 我从~/.gitconfig~/scripts文件夹(位于$PATH删除了与较短的日志别名相关的所有内容,并使用如下代码制作了名称类似于git-las (全部列出)每个:

#!/bin/bash

$height=$(tput lines)
$height=$((height / 3))
git la -$height

I made each executable. 我制作了每个可执行文件。 Git will take git las and find git-las (no extension) on my path, if its executable, and execute it, and it works. Git将使用git las并在我的路径中找到git-las (无扩展名)(如果可执行),然后执行它,然后它可以工作。 That git la (list all) is in my ~/.gitconfig , and is just the typical git log --all --oneline --graph --decorate everyone gives their own name to. git la (列出所有列表)在我的~/.gitconfig ,并且只是典型的git log --all --oneline --graph --decorate每个人都有自己的名字。 This is the only thing that works, after easily 100 variations on every bit of online info I could find. 这是唯一可行的方法,在我能找到的每一点在线信息上轻松实现了100种变化之后。 Even trying to move the tput stuff back into ~/.gitconfig fails, and $LINES also fails in these working files; 甚至尝试移动tput东西放回~/.gitconfig失败,和$LINES也没有在这些工作文件; it's always 0. 始终为0。

What a battle, but now I have short logs (a few different sizes and settings) that scale dynamically with the window to always give me roughly 1/2 to 1/4 oneline log output - dividing by 3 (and 6 for 1/4) accounts for some extra space around merge commits and tricky branch pathways. 真是一场大战,但是现在我有一些短日志(一些不同的大小和设置),它们随窗口动态缩放,始终为我提供大约1/2到1/4的单行日志输出-除以3(对于1/4则为6) )在合并提交和棘手的分支路径周围占了一些额外的空间。 I've had these hard-coded for a year, but now I'm starting to properly version and share my dotfiles between machines, so I wanted it dynamic for all my different monitor heights, and so it would work in an expected fashion no matter how big I had the window. 我已经对这些文件进行了一年的硬编码,但是现在我开始在各个机器之间正确地版本化和共享我的dotfile,因此我希望它在所有不同的显示器高度上都可以动态显示,因此可以按预期的方式工作。我有多大的窗户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM