Skip to content

Commit cc871fb

Browse files
committed
Merge branch 'release/v1.0.0'
2 parents 2f06bad + eace770 commit cc871fb

File tree

7 files changed

+136
-128
lines changed

7 files changed

+136
-128
lines changed

.github/assets/day.svg

Lines changed: 6 additions & 6 deletions
Loading

.github/assets/night.svg

Lines changed: 6 additions & 6 deletions
Loading

.github/workflows/release.yml renamed to .github/workflows/auto-release.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
name: Generate release
1+
name: Auto Release
22

33
on:
44
push:
55
tags:
66
- "v*"
77

88
jobs:
9-
build:
9+
release:
1010
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: write
14+
discussions: write
15+
1116
steps:
1217
- name: Checkout
1318
uses: actions/checkout@v3
19+
1420
- name: Generate release
1521
uses: softprops/action-gh-release@v1
1622
env:
@@ -21,4 +27,3 @@ jobs:
2127
files: |
2228
dist/*.zip
2329
dist/*.tar.gz
24-
git-profiles.plugin.zsh

LICENSE renamed to LICENSE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Copyright (c) 2023 Bruno Sales <[email protected]>
1+
# The MIT License (MIT)
2+
3+
Copyright (c) `2023-2025` `Bruno Sales <[email protected]>`
24

35
Permission is hereby granted, free of charge, to any person obtaining a copy
46
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<p align="center">
22
<a href="#gh-dark-mode-only" target="_blank" rel="noopener noreferrer">
3-
<img src=".github/assets/night.svg" alt="git-extra-profiles.plugin.zsh">
3+
<img src=".github/assets/night.svg" alt="gitprofiles.plugin.zsh">
44
</a>
55

66
<a href="#gh-light-mode-only" target="_blank" rel="noopener noreferrer">
7-
<img src=".github/assets/day.svg" alt="git-extra-profiles.plugin.zsh">
7+
<img src=".github/assets/day.svg" alt="gitprofiles.plugin.zsh">
88
</a>
99
</p>
1010

@@ -14,53 +14,52 @@ Plugin for managing multiple `git` profiles.
1414

1515
## Installation
1616

17-
### Using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)
17+
#### [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)
1818

19-
```sh
20-
git clone https://github.com/baliestri/git-profiles.plugin.zsh.git $ZSH_CUSTOM/plugins/git-profiles
19+
```shell
20+
git clone https://github.com/empresslabs/gitprofiles.plugin.zsh.git $ZSH_CUSTOM/plugins/gitprofiles
2121
```
2222

23-
Then add `git-profiles` to the plugins array in your zshrc file:
24-
25-
```sh
26-
plugins=(... git-profiles)
23+
```shell
24+
~/.zshrc
25+
plugins=(... gitprofiles)
2726
```
2827

29-
### Using [zplug](https://github.com/zplug/zplug)
28+
#### [zinit](https://github.com/zdharma-continuum/zinit)
3029

31-
```sh
32-
zplug "baliestri/git-profiles.plugin.zsh"
30+
```shell
31+
zinit light empresslabs/gitprofiles.plugin.zsh
3332
```
3433

35-
### Using [zinit](https://github.com/zdharma-continuum/zinit)
34+
#### [zi](https://github.com/z-shell/zi)
3635

37-
```sh
38-
zinit light baliestri/git-profiles.plugin.zsh
36+
```shell
37+
zi light empresslabs/gitprofiles.plugin.zsh
3938
```
4039

41-
### Using [zgenom](https://github.com/jandamm/zgenom)
40+
#### [zgenom](https://github.com/jandamm/zgenom)
4241

43-
```sh
44-
zgenom load baliestri/git-profiles.plugin.zsh
42+
```shell
43+
zgenom load empresslabs/gitprofiles.plugin.zsh
4544
```
4645

47-
### Using [zi](https://github.com/z-shell/zi)
46+
#### [zplug](https://github.com/zplug/zplug)
4847

49-
```sh
50-
zi light baliestri/git-profiles.plugin.zsh
48+
```shell
49+
zplug empresslabs/gitprofiles.plugin.zsh
5150
```
5251

5352
## Usage
5453

55-
### Define where your profiles are stored
54+
#### Define where your profiles are stored
5655

5756
```sh
5857
# ~/.zshrc
5958

60-
export GIT_PROFILES_FILE="$HOME/.config/git/profiles" # Fallback to $HOME/.git-profiles
59+
zstyle ":empresslabs:git:profiles" path "$HOME/.config/git/profiles"
6160
```
6261

63-
### Add a new profile
62+
#### Add a new profile
6463

6564
```sh
6665
# ~/.config/git/profiles

git-profiles.plugin.zsh

Lines changed: 0 additions & 88 deletions
This file was deleted.

gitprofiles.plugin.zsh

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (c) Bruno Sales <[email protected]>. Licensed under the MIT License.
2+
# See the LICENSE file in the project root for full license information.
3+
4+
#!/usr/bin/env zsh
5+
6+
function __gitprofiles_hook() {
7+
## Check if git is installed
8+
if (( ! $+commands[git] )); then
9+
return 1
10+
fi
11+
12+
local -A profile_path_map=()
13+
local -A profile_cfg_map=()
14+
15+
## Get the path to the profile file
16+
zstyle -s ":empresslabs:git:profile" path profile_filepath
17+
18+
## Check if the file exists
19+
if [[ ! -f "${profile_filepath}" ]]; then
20+
return 1
21+
fi
22+
23+
## Load all stored profiles
24+
local profiles=($(grep -o '\[profile [^]]*\]' ${profile_filepath} | tr -d '[]" ' | sed 's/profile//g' | tr '\n' ' '))
25+
26+
## Check if default profile exists
27+
if [[ ! "${profiles}" =~ "default" ]]; then
28+
echo "gitprofiles: 'default' profile not found in '${profile_filepath}'"
29+
return 1
30+
fi
31+
32+
## Iterate over all profiles to get the name, email, signingkey and path
33+
for profile in ${profiles}; do
34+
local -A profile_value_map=()
35+
36+
while read -r key value; do
37+
case "${key}" in
38+
name)
39+
profile_value_map[name]="${value}"
40+
;;
41+
email)
42+
profile_value_map[email]="${value}"
43+
;;
44+
signingkey)
45+
profile_value_map[signingkey]="${value}"
46+
;;
47+
path)
48+
profile_value_map[path]="${value}"
49+
;;
50+
esac
51+
done < <(awk -F ' = ' '/^\[profile/{p=0} /^\[profile "[^"]*'"${profile}"'"/{p=1} p {gsub(/"/, "", $2); print $1,$2}' ${profile_filepath})
52+
53+
profile_path_map[${profile}]="${profile_value_map[path]}"
54+
55+
profile_cfg_map[${profile}.name]="${profile_value_map[name]}"
56+
profile_cfg_map[${profile}.email]="${profile_value_map[email]}"
57+
58+
if [[ -n "${profile[signingkey]}" ]]; then
59+
profile_cfg_map[${profile}.signingkey]="${profile_value_map[signingkey]}"
60+
fi
61+
done
62+
63+
## Get the current directory
64+
local -A current=()
65+
current[dir]=$(pwd)
66+
67+
## Check if the current directory is in one of the profiles paths
68+
for profile in ${(k)profile_path_map}; do
69+
if [[ "${current[dir]}" =~ "${profile_path_map[${profile}]}" ]]; then
70+
local current[profile]="${profile}"
71+
break
72+
fi
73+
done
74+
75+
## If the current directory is not in any profile path, use the default profile
76+
if [[ -z "${current[profile]}" ]]; then
77+
local current[profile]="default"
78+
fi
79+
80+
## Set the current profile name and email
81+
git config --global user.name "${profile_cfg_map[${current[profile]}.name]}"
82+
git config --global user.email "${profile_cfg_map[${current[profile]}.email]}"
83+
84+
## Set the current profile signingkey if it exists
85+
if [[ -n "${profile_cfg_map[${current[profile]}.signingkey]}" ]]; then
86+
git config --global user.signingkey "${profile_cfg_map[${current[profile]}.signingkey]}"
87+
fi
88+
}
89+
90+
add-zsh-hook chpwd __gitprofiles_hook

0 commit comments

Comments
 (0)