cmdlets/Get-BookmarksDataFile.ps1



function Get-BookmarksDataFile {
    $moduleName = "Bookmarks"
 
    $os = [System.Runtime.InteropServices.RuntimeInformation]::OSDescription
    if ($os -match "Linux") {
        $appData = "$HOME/.config"
    } elseif ($os -match "Darwin") {
        $appData = "$HOME/Library/Application Support"
    } elseif ($os -match "Windows") {
        $appData = "$ENV:APPDATA"
    } elseif ($os -match "Unix") {
        $appData = "$HOME/.config"
    } elseif ($os -match "BSD") {
        $appData = "$HOME/.config"
    } else {
        throw "Unsupported OS"
    }


    if( [string]::IsNullOrWhitespace( $moduleName ) ){
        if ( $script:MyInvocation.MyCommand.Name.EndsWith('.psm1') ){
            $moduleName = $script:MyInvocation.MyCommand.Name
        }

        if ( $script:MyInvocation.MyCommand.Name.EndsWith('.ps1') ){
            $modulePath = Split-Path -Path $script:MyInvocation.MyCommand.Path
            $moduleName = Split-Path -Path $modulePath -Leaf
        }
    }

    if( [string]::IsNullOrWhitespace( $moduleName ) ){
        throw "Unable to read module name."             
    }
    
    $scriptProfile = [System.IO.Path]::Combine($appData, '.ps1', 'ScriptData', $moduleName)

    if ( ! (Test-Path $scriptProfile -PathType Container )) { 
        New-Item -Path $scriptProfile  -ItemType 'Directory'
    }

    return Join-Path $scriptProfile bookmarks 
}