From ff92382330151fc8c0f47e446a78e3f2335d8977 Mon Sep 17 00:00:00 2001 From: Bruno Sales Date: Thu, 26 Dec 2024 17:18:40 -0300 Subject: [PATCH 1/5] chore: update auto-release workflow --- .github/workflows/{release.yml => auto-release.yml} | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) rename .github/workflows/{release.yml => auto-release.yml} (80%) diff --git a/.github/workflows/release.yml b/.github/workflows/auto-release.yml similarity index 80% rename from .github/workflows/release.yml rename to .github/workflows/auto-release.yml index 84c8d9a..c679805 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/auto-release.yml @@ -1,4 +1,4 @@ -name: Generate release +name: Auto Release on: push: @@ -6,11 +6,17 @@ on: - "v*" jobs: - build: + release: runs-on: ubuntu-latest + + permissions: + contents: write + discussions: write + steps: - name: Checkout uses: actions/checkout@v3 + - name: Generate release uses: softprops/action-gh-release@v1 env: @@ -21,4 +27,3 @@ jobs: files: | dist/*.zip dist/*.tar.gz - git-profiles.plugin.zsh From 7743c88b314a235b0cb923f202670c243a8d7d42 Mon Sep 17 00:00:00 2001 From: Bruno Sales Date: Thu, 26 Dec 2024 17:18:56 -0300 Subject: [PATCH 2/5] chore: update assets --- .github/assets/day.svg | 12 ++++++------ .github/assets/night.svg | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/assets/day.svg b/.github/assets/day.svg index 4ab7745..ee3d744 100755 --- a/.github/assets/day.svg +++ b/.github/assets/day.svg @@ -1,7 +1,7 @@ - - - - - - + + + + + + diff --git a/.github/assets/night.svg b/.github/assets/night.svg index facfca9..4023767 100755 --- a/.github/assets/night.svg +++ b/.github/assets/night.svg @@ -1,7 +1,7 @@ - - - - - - + + + + + + From 54eee41f98ec87040fc090143feb9144bcf7cb68 Mon Sep 17 00:00:00 2001 From: Bruno Sales Date: Thu, 26 Dec 2024 17:19:06 -0300 Subject: [PATCH 3/5] chore: update LICENSE year --- LICENSE => LICENSE.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename LICENSE => LICENSE.md (92%) diff --git a/LICENSE b/LICENSE.md similarity index 92% rename from LICENSE rename to LICENSE.md index 8442f75..2db9a7a 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,4 +1,6 @@ -Copyright (c) 2023 Bruno Sales +# The MIT License (MIT) + +Copyright (c) `2023-2025` `Bruno Sales ` Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From bcfaa10566ec4424b816f7dece77e66b7044ba78 Mon Sep 17 00:00:00 2001 From: Bruno Sales Date: Thu, 26 Dec 2024 17:19:30 -0300 Subject: [PATCH 4/5] feat: refactor and use zstyle for options --- git-profiles.plugin.zsh | 88 ---------------------------------------- gitprofiles.plugin.zsh | 90 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 88 deletions(-) delete mode 100755 git-profiles.plugin.zsh create mode 100644 gitprofiles.plugin.zsh diff --git a/git-profiles.plugin.zsh b/git-profiles.plugin.zsh deleted file mode 100755 index f86910d..0000000 --- a/git-profiles.plugin.zsh +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (c) Bruno Sales . Licensed under the MIT License. -# See the LICENSE file in the project root for full license information. - -#!/usr/bin/env zsh - -## File to store the profiles -export GIT_PROFILES_FILE="${GIT_PROFILES_FILE:-${HOME}/.config/git/profiles}" -export GIT_PROFILES_FILE_FALLBACK="${HOME}/.git-profiles" - -function __git_profiles_hook() { - ## Check if git is installed - if (( ! $+commands[git] )); then - return 1 - fi - - ## Check if the file exists - if [[ ! -f "${GIT_PROFILES_FILE}" ]]; then - export GIT_PROFILES_FILE="${GIT_PROFILES_FILE_FALLBACK}" - fi - - ## Load all stored profiles - local profiles=($(grep -o '\[profile [^]]*\]' ${GIT_PROFILES_FILE} | tr -d '[]" ' | sed 's/profile//g' | tr '\n' ' ')) - - local -A profiles_paths=() - local -A profiles_configs=() - - ## Iterate over all profiles to get the name, email, signingkey and path - for profile in ${profiles}; do - while read -r key value; do - case "${key}" in - name) - profile_name="${value}" - ;; - email) - profile_email="${value}" - ;; - signingkey) - profile_signingkey="${value}" - ;; - path) - profile_path="${value}" - ;; - esac - done < <(awk -F ' = ' '/^\[profile/{p=0} /^\[profile "[^"]*'"${profile}"'"/{p=1} p {gsub(/"/, "", $2); print $1,$2}' ${GIT_PROFILES_FILE}) - - profiles_paths[${profile}]="${profile_path}" - - profiles_configs[${profile}.name]="${profile_name}" - profiles_configs[${profile}.email]="${profile_email}" - - if [[ -n "${profile_signingkey}" ]]; then - profiles_configs[${profile}.signingkey]="${profile_signingkey}" - fi - done - - ## Get the current directory - local current_dir=$(pwd) - - ## Check if the current directory is in one of the profiles paths - for profile in ${(k)profiles_paths}; do - if [[ "${current_dir}" =~ "${profiles_paths[${profile}]}" ]]; then - local current_profile="${profile}" - break - fi - done - - ## If the current directory is not in any profile path, use the default profile - if [[ -z "${current_profile}" ]]; then - local current_profile="default" - fi - - ## Define the current profile name and email - local current_profile_name="${profiles_configs[${current_profile}.name]}" - local current_profile_email="${profiles_configs[${current_profile}.email]}" - - ## Set the current profile name and email - git config --global user.name "${current_profile_name}" - git config --global user.email "${current_profile_email}" - - ## Set the current profile signingkey if it exists - if [[ -n "${profiles_configs[${current_profile}.signingkey]}" ]]; then - local current_profile_signingkey="${profiles_configs[${current_profile}.signingkey]}" - - git config --global user.signingkey "${current_profile_signingkey}" - fi -} - -add-zsh-hook chpwd __git_profiles_hook diff --git a/gitprofiles.plugin.zsh b/gitprofiles.plugin.zsh new file mode 100644 index 0000000..5d4909f --- /dev/null +++ b/gitprofiles.plugin.zsh @@ -0,0 +1,90 @@ +# Copyright (c) Bruno Sales . Licensed under the MIT License. +# See the LICENSE file in the project root for full license information. + +#!/usr/bin/env zsh + +function __gitprofiles_hook() { + ## Check if git is installed + if (( ! $+commands[git] )); then + return 1 + fi + + local -A profile_path_map=() + local -A profile_cfg_map=() + + ## Get the path to the profile file + zstyle -s ":empresslabs:git:profile" path profile_filepath + + ## Check if the file exists + if [[ ! -f "${profile_filepath}" ]]; then + return 1 + fi + + ## Load all stored profiles + local profiles=($(grep -o '\[profile [^]]*\]' ${profile_filepath} | tr -d '[]" ' | sed 's/profile//g' | tr '\n' ' ')) + + ## Check if default profile exists + if [[ ! "${profiles}" =~ "default" ]]; then + echo "gitprofiles: 'default' profile not found in '${profile_filepath}'" + return 1 + fi + + ## Iterate over all profiles to get the name, email, signingkey and path + for profile in ${profiles}; do + local -A profile_value_map=() + + while read -r key value; do + case "${key}" in + name) + profile_value_map[name]="${value}" + ;; + email) + profile_value_map[email]="${value}" + ;; + signingkey) + profile_value_map[signingkey]="${value}" + ;; + path) + profile_value_map[path]="${value}" + ;; + esac + done < <(awk -F ' = ' '/^\[profile/{p=0} /^\[profile "[^"]*'"${profile}"'"/{p=1} p {gsub(/"/, "", $2); print $1,$2}' ${profile_filepath}) + + profile_path_map[${profile}]="${profile_value_map[path]}" + + profile_cfg_map[${profile}.name]="${profile_value_map[name]}" + profile_cfg_map[${profile}.email]="${profile_value_map[email]}" + + if [[ -n "${profile[signingkey]}" ]]; then + profile_cfg_map[${profile}.signingkey]="${profile_value_map[signingkey]}" + fi + done + + ## Get the current directory + local -A current=() + current[dir]=$(pwd) + + ## Check if the current directory is in one of the profiles paths + for profile in ${(k)profile_path_map}; do + if [[ "${current[dir]}" =~ "${profile_path_map[${profile}]}" ]]; then + local current[profile]="${profile}" + break + fi + done + + ## If the current directory is not in any profile path, use the default profile + if [[ -z "${current[profile]}" ]]; then + local current[profile]="default" + fi + + ## Set the current profile name and email + git config --global user.name "${profile_cfg_map[${current[profile]}.name]}" + git config --global user.email "${profile_cfg_map[${current[profile]}.email]}" + + ## Set the current profile signingkey if it exists + if [[ -n "${profile_cfg_map[${current[profile]}.signingkey]}" ]]; then + git config --global user.signingkey "${profile_cfg_map[${current[profile]}.signingkey]}" + fi +} + +add-zsh-hook chpwd __gitprofiles_hook From eace77057342a6786c0c7cd4cbfd360c30ba17ac Mon Sep 17 00:00:00 2001 From: Bruno Sales Date: Thu, 26 Dec 2024 17:19:53 -0300 Subject: [PATCH 5/5] chore: update README.md --- README.md | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 22a787e..8fa5766 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@

- git-extra-profiles.plugin.zsh + gitprofiles.plugin.zsh - git-extra-profiles.plugin.zsh + gitprofiles.plugin.zsh

@@ -14,53 +14,52 @@ Plugin for managing multiple `git` profiles. ## Installation -### Using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) +#### [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh) -```sh -git clone https://github.com/baliestri/git-profiles.plugin.zsh.git $ZSH_CUSTOM/plugins/git-profiles +```shell +git clone https://github.com/empresslabs/gitprofiles.plugin.zsh.git $ZSH_CUSTOM/plugins/gitprofiles ``` -Then add `git-profiles` to the plugins array in your zshrc file: - -```sh -plugins=(... git-profiles) +```shell +~/.zshrc +plugins=(... gitprofiles) ``` -### Using [zplug](https://github.com/zplug/zplug) +#### [zinit](https://github.com/zdharma-continuum/zinit) -```sh -zplug "baliestri/git-profiles.plugin.zsh" +```shell +zinit light empresslabs/gitprofiles.plugin.zsh ``` -### Using [zinit](https://github.com/zdharma-continuum/zinit) +#### [zi](https://github.com/z-shell/zi) -```sh -zinit light baliestri/git-profiles.plugin.zsh +```shell +zi light empresslabs/gitprofiles.plugin.zsh ``` -### Using [zgenom](https://github.com/jandamm/zgenom) +#### [zgenom](https://github.com/jandamm/zgenom) -```sh -zgenom load baliestri/git-profiles.plugin.zsh +```shell +zgenom load empresslabs/gitprofiles.plugin.zsh ``` -### Using [zi](https://github.com/z-shell/zi) +#### [zplug](https://github.com/zplug/zplug) -```sh -zi light baliestri/git-profiles.plugin.zsh +```shell +zplug empresslabs/gitprofiles.plugin.zsh ``` ## Usage -### Define where your profiles are stored +#### Define where your profiles are stored ```sh # ~/.zshrc -export GIT_PROFILES_FILE="$HOME/.config/git/profiles" # Fallback to $HOME/.git-profiles +zstyle ":empresslabs:git:profiles" path "$HOME/.config/git/profiles" ``` -### Add a new profile +#### Add a new profile ```sh # ~/.config/git/profiles