项目作者: mmitsu

项目描述 :
In-terminal language statistics.
高级语言: Python
项目地址: git://github.com/mmitsu/plangfo.git
创建时间: 2017-10-02T12:46:51Z
项目社区:https://github.com/mmitsu/plangfo

开源协议:

下载


plangfo

plangfo is a module with some tools. It only has the blob languages detection thing right now tho :P

Insallation

pip3 install plangfo

Usage

Add alias plangfo='python3 -m plangfo' to your .bashrc

And just use it. Go to a directory, type plangfo

Here is a test repo:
output

Here is my output:

plangfo_output

Something else:

another_output

How it works?

The percentages are calculated based on the bytes of code for each language as reported by the get_bytes() method.

Arguments/specifying directories

To specify a directory, you need to specify an argument, and vice versa.

To do that, use plangfo [option] [directory]

Arguments
a —all-files
b —bytes
sb —sorted-bytes
p —percentage
sp —sorted-percentage

TODO:

  • sb | --sorted-bytes
  • .${file} | It seems like the script doesn’t detect hidden files. Will fix that soon.
  • --code-all | How many lines of code in the whole directory.
  • --code-lang | How many lines of code each language has.
  • --ignore | Ignore some specific languages.
  • Switch to C#.

Languages

If you’re wondering how I got that large data of languages. Then, no, of course I didn’t make it myself.

I used wget to download languages.yml

wget https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml

Then, a Python script to generate a dictionary.

  1. import yaml
  2. with open("languages.yml") as f:
  3. dataMap = yaml.safe_load(f)
  4. file = open("data.py", "a+")
  5. file.seek(0)
  6. file.truncate()
  7. file.write("languages = {\n")
  8. for language in dataMap:
  9. try:
  10. file.write("\t\"" + language + "\"" + ": " + str(dataMap[language]["extensions"]) + ",\n")
  11. except KeyError:
  12. continue
  13. file.write("\t}")

The result is, as expected, data.py.