diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-04-22 21:55:13 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-04-22 21:55:13 +0200 |
| commit | 091583b9dd4dcca9981dc5dffec5665f200d1a01 (patch) | |
| tree | 6075a484f1cd498a8bc2244343d10a39df5d1d08 /.config/zsh/.zshrc | |
| parent | f47319ecb9db1e15f84ee10996172a7e964f1bf0 (diff) | |
| download | dotfiles-091583b9dd4dcca9981dc5dffec5665f200d1a01.tar.gz dotfiles-091583b9dd4dcca9981dc5dffec5665f200d1a01.zip | |
Re-enabled setting git environment variables dynamically by allowing package managers to use default git varibables
Diffstat (limited to '.config/zsh/.zshrc')
| -rw-r--r-- | .config/zsh/.zshrc | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index f83cac5..5aa5f14 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -374,35 +374,39 @@ extract () { alias config='git --git-dir=$HOME/.cfg --work-tree=$HOME' ## Set bare dotfiles repository git environment variables dynamically -#function set_git_env_vars() { -# local git_dir="$(git rev-parse --git-dir -C . 2>/dev/null)" -# if [[ -n "$git_dir" ]]; then -# local is_bare="$(git -C "$git_dir" rev-parse --is-bare-repository 2>/dev/null)" -# if [[ "$is_bare" == "true" ]]; then -# export GIT_DIR="$HOME/.cfg" -# export GIT_WORK_TREE=$(realpath $(eval echo ~)) -# else -# unset GIT_DIR -# unset GIT_WORK_TREE -# fi -# else -# local root_dir="$(git rev-parse --show-toplevel 2>/dev/null)" -# if [[ -n "$root_dir" ]]; then -# unset GIT_DIR -# export GIT_WORK_TREE="$root_dir" -# else -# export GIT_DIR="$HOME/.cfg" -# export GIT_WORK_TREE=$(realpath $(eval echo ~)) -# fi -# fi -#} -# -## Define an auto_cd hook to automatically update Git environment variables -#function chpwd() { -# set_git_env_vars -#} -## Call the function to set Git environment variables when the shell starts up -#set_git_env_vars +function set_git_env_vars() { + # Check if the current command is a package manager command + if [[ "${(%)${(z)history[1]}}" =~ ^(pacman|yay|apt|dnf|yum|brew) ]]; then + return + fi + local git_dir="$(git rev-parse --git-dir -C . 2>/dev/null)" + if [[ -n "$git_dir" ]]; then + local is_bare="$(git -C "$git_dir" rev-parse --is-bare-repository 2>/dev/null)" + if [[ "$is_bare" == "true" ]]; then + export GIT_DIR="$HOME/.cfg" + export GIT_WORK_TREE=$(realpath $(eval echo ~)) + else + unset GIT_DIR + unset GIT_WORK_TREE + fi + else + local root_dir="$(git rev-parse --show-toplevel 2>/dev/null)" + if [[ -n "$root_dir" ]]; then + unset GIT_DIR + export GIT_WORK_TREE="$root_dir" + else + export GIT_DIR="$HOME/.cfg" + export GIT_WORK_TREE=$(realpath $(eval echo ~)) + fi + fi +} + +# Define an auto_cd hook to automatically update Git environment variables +function chpwd() { + set_git_env_vars +} +# Call the function to set Git environment variables when the shell starts up +set_git_env_vars function gsp { |
