porcupine
porcupine copied to clipboard
The {project_name} substitution
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.
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://[email protected]/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://[email protected]/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:
- Strip trailing slash:
https://github.com/python/typeshed/
-->typeshed
- Skip submodule sections
- Remove
.git
at the end if it is there:github.com/foo/bar.git
-->bar
- Sanity-check for empty strings, so that
foo/.git
doesn't turn into.git
and then into empty string as we split by slash
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
.
I renamed my folder to porcupine
.