gfetch - a fast, lightweight Git fetch utility written in POSIX sh

栏目: IT技术 · 发布时间: 4年前

gfetch

gfetch - a fast, lightweight Git fetch utility written in POSIX sh

gfetch is a tiny, lightweight shell script that can be used as an alternative to onefetch .

what?

gfetch is

  • small : the entire script is less than 300 lines of code (not counting comments).
  • fast : shows information for the git repository in just a few seconds.
  • POSIX : runs on just about any modern POSIX shell: bash , dash , mksh , loksh , anything short of tcsh or mksh .
  • less distracting . gfetch does not have and never will have huge, ridiculous ASCII art that takes up half the screen.
  • configurable . This fetch script was designed from the ground up to be completely configurable, down to the order of the information fields. Every single field -- even the (small) ASCII art -- can be disabled.

Note that gfetch is still in very early stages. Expect bugs, incorrect information, and lots of missing features.

where?

You will need:

  • a Unix-like system (Windows support is planned)
  • a fairly modern version of Git (duh)
  • a POSIX-compliant shell. (so no fish, tcsh, etc)
  • GNU sed and GNU awk (other sed/awk implementations might work, but are untested.)
  • GNU Make (the Makefile is incompatible with bmake )
  • SCC (optional, only required for language detection and LOC count)

Then, simply grab a release tarball from the GitHub releases, extract, and run:

$ make clean all
# make install

directory is in your path first. If you want to install to a different location (e.g. /usr/bin ) you can run make PREFIX=/usr install instead.

how?

Ensure that the gfe script is in your path, then execute it.

Configurationis done by editing the shell script at ~/.config/gfe/config.sh , which is created by default if it doesn't exist. It is then source d by gfe on startup.

The configuration file consists of some environment variable definitions, which are only set if they are empty. This allows them to be overridden at runtime.

The list of environment variables is as follows:

# ensure that you use the
# form GFE_VALUE=\${GFE_VALUE:-othervalue}
# to ensure that it can be overridden on
# the command line!!
#
# GFE_LOGO: path to file with ASCII art.
# if it\'s value is not a valid file, then
# it is treated as ASCII art itself.
GFE_LOGO=\"\${GFE_LOGO:-}\"

# GFE_ALIGN: number of spaces for padding between
# name and info columnds
GFE_ALIGN=\"\${GFE_ALIGN:-13}\"

# GFE_COL1: color for the first column (the
# name column). possible values: 1-7
GFE_COL1=\"\${GFE_COL1:-1}\"

# GFE_COL2: color for the second column (the
# info column). possible values: 1-7
GFE_COL2=\"\${GFE_COL2:-7}\"

# GFE_COL3: color for the header/title.
# possible values: 1-7
GFE_COL3=\"\${GFE_COL3:-1}\"

# GFE_SEP: character or text to separate each name
# and info line.
# e.g. using the value ':' would become 'name: info'
# in output.
GFE_SEP=\"\${GFE_SEP:-}\"

# GFE_DIR: directory/repository for gfetch to cd
# into.
GFE_DIR=\"\${GFE_DIR:-}\"

# GFE_AUTHOR_MAX: maximum number of authors for the
# AUTHORS gfe field.
GFE_AUTHORS_MAX=\"\${GFE_AUTHORS_MAX:-2}\"

# GFE_LANG_MAX: maximum number of languages for the
# LANGUAGES gfe field.
GFE_LANG_MAX=\"\${GFE_LANG_MAX:-2}\"

The config file also contains gfe_info() function, which is executed by gfe to show the information. It looks something like this:

gfe_info() {
    # print a newline.
    printf ''

    # print the default ASCII art.
    # note that the show_ascii() function must be
    # the FIRST if it is used.
    show_ascii

    # print a Onefetch-esque header, with the
    # Git username and Git version.
    # usage: showheader <left> <right> <sep>
    showheader "$(get_user)" "$(get_gitver)" " ~ "

    # Each showinfo call prints one row of info.
    # By default, all available info is printed.
    # each command inside the "$()" is a gfetch
    # function to get information.
    #
    # if you wish, you can even display your own text
    # with the showinfo function.
    # e.g. showinfo "$(hostname)" "HOSTNAME"

    # usage: showinfo <info> <label>
    showinfo "$(get_project_name)" 'PROJECT'

    # note: get_head_long() shows the branch name
    # as well as latest commit. if you want to see
    # only the latest commit, you can use the
    # get_head() function instead.
    showinfo "$(get_head_long)"    'HEAD'

    showinfo "$(get_version)"      'VERSION'
    showinfo "$(get_created)"      'CREATED'
    showinfo "$(get_languages)"    'LANGUAGES'
    showinfo "$(get_authors)"      'AUTHORS'
    showinfo "$(get_latest)"       'LAST CHANGE'
    showinfo "$(get_upstream)"     'UPSTREAM'
    showinfo "$(get_commit_count)" 'COMMITS'
    showinfo "$(get_loc)"          'LOC'
    showinfo "$(get_srcsize)"      'SOURCE SIZE'

    # print a newline.
    printf ''
}

By default, all available information is printed.

why?

See ONEFETCH.md for a Onefetch vs gfetch comparison.

faq

  • Q : Why is a lambda the default ASCII art?
    • A : well, it's supposed to be a branch. (you know, git branch ?) If you think you can do better, feel free to submit an issue with your ASCII art :)
  • Q : Are there any plans to add language-specific ASCII art (as in Onefetch)?
    • A : Eventually. The goal is to first add other missing info fields and further optimize the code.

license

gfetch is licensed under the MIT license. See COPYING for more information.


以上所述就是小编给大家介绍的《gfetch - a fast, lightweight Git fetch utility written in POSIX sh》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C++ 程序设计语言(特别版)(英文影印版)

C++ 程序设计语言(特别版)(英文影印版)

[美] Bjarne Stroustrup / 高等教育出版社 / 2001-8-1 / 55.00

《C++程序设计语言》(特别版)(影印版)作者是C++的发明人,对C++语言有着全面、深入的理解,因此他强调应将语言作为设计与编程的工具,而不仅仅是语言本身,强调只有对语言功能有了深入了解之后才能真正掌握它。《C++程序设计语言》编写的目的就是帮助读者了解C++是如何支持编程技术的,使读者能从中获得新的理解,从而成为一名优秀的编程人员和设计人员。一起来看看 《C++ 程序设计语言(特别版)(英文影印版)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换