Skip to content

Commit 44e6f37

Browse files
committed
Release 0.2.4
This commit adds the possibility of using a config file to specify some params. For now, only the name_separator used by the gith branch -c command. It requires the user creates a config file in /home/user/.githconfig with key: value
1 parent 8f00874 commit 44e6f37

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ gith branch -c this is my branch name with spaces and other separator --name-sep
146146
```
147147
This will replace the spaces with the specified separator: `this-is-my-branch-name-with-spaces-and-other-separator`
148148
149+
If you are not happy with the default separator and do not want to pass the `--name-separator` flag every time no worries, there is a possibility to add a `.githconfig` file and set this value. Continue reading until the section *Using a Configuration file*
150+
149151
In every of the previous cases, **gith** will **automatically checkout to the created branch** 😎
150152
151153
If you want to create your branch, wihtout doing checkout, then just call the command like:
@@ -258,6 +260,21 @@ $ gith branch -d
258260
```
259261
And you will get a list of local branches, with their indexes, so you can easily find the indexes without the need of typing an extra command.
260262
263+
## Using a configuration file
264+
Adding a configuration file to set some default values while using **gith** is also possible. Right now, then only possible parameter to define is the `name_separator` used by the `gith branch -c` command, but in the future we might add other configurables there 😊
265+
266+
In order to change the default value of this command, follow these steps:
267+
268+
Create a file called `.githconfig` on your *Home* folder
269+
```
270+
nano ~/.githconfig
271+
```
272+
Add in this file the default separator you want to use while creating branches with spaces in the name.
273+
```yaml
274+
name_separator: "-"
275+
```
276+
After that, you will be able to use `gith branch -c my branch name with spaces` and your configured separator will be used instead of the default.
277+
261278
## Final words
262279
**gith** is built using **Typer**. Big thanks 🙏 to [Sebastián Ramírez](https://github.com/tiangolo) for creating such amazing tool.
263280

gith/cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,32 @@
44

55
from .helpers import gith
66
from .messages import GithMessage, GithMessageLevel
7+
from pathlib import Path
8+
import yaml
79

810
app = typer.Typer()
911
console = Console()
1012

1113

14+
def get_config_path() -> Path:
15+
"""
16+
Get the path to the configuration file.
17+
"""
18+
return Path.home() / ".githconfig"
19+
20+
21+
def load_config() -> dict:
22+
"""
23+
Load the configuration file.
24+
"""
25+
config_path = get_config_path()
26+
if config_path.exists():
27+
with open(config_path, "r") as f:
28+
return yaml.safe_load(f)
29+
return {}
30+
31+
config = load_config()
32+
1233
def branch_name_autocomplete(ctx: typer.Context, incomplete: str) -> List[str]:
1334
"""
1435
Autocomplete function for branch names.
@@ -83,6 +104,8 @@ def branch(
83104
elif list or not list and not create and not branch_name:
84105
gith.git_branch()
85106
elif create:
107+
# get name_separator from config file
108+
name_separator = config.get("name_separator", False) or name_separator
86109
name = f"{name_separator}".join(branch_name)
87110
gith.create_branch(name, from_branch, checkout, name_separator)
88111
if checkout:

gith/helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import subprocess
2-
import typer
32

43
from .console import GithConsole
54
from .messages import GithMessage, GithMessageLevel

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "gith"
7-
version = "0.2.3"
7+
version = "0.2.4"
88
description = "A Typer-based helper for Git operations"
99
authors = [
1010
{ name = "Reinaldo J. Menéndez", email = "rejamen@gmail.com" }
@@ -15,7 +15,8 @@ readme = "README.md"
1515
requires-python = ">=3.7"
1616
dependencies = [
1717
"typer>=0.15.1",
18-
"rich >=10.11.0"
18+
"rich>=10.11.0",
19+
"pyyaml>=5.4"
1920
]
2021

2122
classifiers = [

0 commit comments

Comments
 (0)