Akuli / porcupine

A decent editor written in tkinter
MIT License
156 stars 46 forks source link

The {project_name} substitution #1113

Open Akuli opened 2 years ago

Akuli commented 2 years ago

In the Shift+F5 dialog, you can say {project_name} and it will be substituted with the name of the project. This is great, except that it's unusable when I use a different folder name than the project's name, and then {project_name} is wrongly the folder's name.

Example: If I clone Porcupine to /home/akuli/porcu, so that I have /home/akuli/porcu/README.md for example, then {project_name} will be substituted with porcu, not with porcupine. This means commands like python3 -m {project_name} or mypy {project_name} wrong.

We could look in .git/config, if it exists. We don't have to parse it perfectly, because we can always use the folder's name as a fallback.

Akuli commented 2 years ago

I was thinking of just taking all lines containing url =, but I looked at a couple .git/config files I have on this computer:

$ grep 'url =' {porcu,typeshed}/.git/config
porcu/.git/config:  url = https://akuli@github.com/Akuli/porcupine
porcu/.git/config:# url = ssh://akuli-thinkpad/home/akuli/porcu/.git
porcu/.git/config:  url = https://github.com/python/typeshed
porcu/.git/config:  url = https://github.com/python/typeshed
typeshed/.git/config:   url = https://github.com/python/typeshed/
typeshed/.git/config:   url = https://akuli@github.com/Akuli/typeshed

The typeshed lines in porcu/.git/config are from a Git submodule (that no longer exists):

[submodule "typeshed"]
    url = https://github.com/python/typeshed
    active = true
[submodule "typeshed2"]
    url = https://github.com/python/typeshed
    active = true

So if we decide to parse .git/config, we can't just do line_containing_url.split("/")[-1]. We have to do a few more things:

Taking the first url = line is probably best: I think any extra remotes you add afterwards will go to the end of the file (but I have to check this), and they are likely not your "primary" remote you usually pull and push to. An example would be adding the fork of another contributor with git remote add contributor https://github.com/contributor/projectname.

Akuli commented 5 months ago

I renamed my folder to porcupine.