Skip to content

Script to run onefetch whe navigating to a git repository for Powershell #1452

@kiapanahi

Description

@kiapanahi

This is a sample script to put in $PROFILE similar to the ones for bash, zsh, or fish for Powershell to run onefetch (vanilla command) upon navigating to a git repository.

# git repository greeter
$global:lastRepository = $null

function Check-DirectoryForNewRepository {
    $currentRepository = git rev-parse --show-toplevel 2>$null
    if ($currentRepository -and ($currentRepository -ne $global:lastRepository)) {
        onefetch
    }
    $global:lastRepository = $currentRepository
}

function Set-Location {
    param (
        [string]$path
    )

    # Use the default Set-Location to change the directory
    Microsoft.PowerShell.Management\Set-Location -Path $path

    # Check if we are in a new Git repository
    Check-DirectoryForNewRepository
}

# Optional: Check the repository also when opening a shell directly in a repository directory
# Uncomment the following line if desired
#Check-DirectoryForNewRepository

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions