-
Notifications
You must be signed in to change notification settings - Fork 3
/
PSNotes.psm1
56 lines (48 loc) · 1.89 KB
/
PSNotes.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Global Variables
if ($IsLinux) {
$script:UserPSNotesJsonPath = '/home/'
}
else {
$script:UserPSNotesJsonPath = Join-Path $env:APPDATA '\PSNotes\'
}
if($global:IsPesterTest){
$script:UserPSNotesJsonPath = Join-Path $UserPSNotesJsonPath 'Pester'
Get-ChildItem -Path $UserPSNotesJsonPath -Filter '*.json' | Remove-Item -Force
}
$global:UserPSNotesJsonFile = Join-Path $UserPSNotesJsonPath '\PSNotes.json'
[System.Collections.Generic.List[PSNote]] $script:noteObjects = @()
if (-not $PSScriptRoot) {
$Path = '.\'
}
else {
$Path = $PSScriptRoot
}
# Import the functions
foreach ($folder in @('private', 'public')) {
$root = Join-Path -Path $Path -ChildPath $folder
if (Test-Path -Path $root) {
Write-Verbose "processing folder $root"
$files = Get-ChildItem -Path $root -Filter *.ps1 -Recurse
# dot source each file
$files | where-Object { $_.name -NotLike '*.Tests.ps1' } |
ForEach-Object { Write-Verbose $_.name; . $_.FullName }
}
}
# Load all commands to noteObjects
Initialize-PSNotesJsonFile
# Check id Set-Clipboard cmdlet is found. If not
if (-not (Get-Command -Name 'Set-Clipboard' -ErrorAction SilentlyContinue)) {
# ClipboardText module is found then set an alias for the Set-Clipboard command
if (Get-Module ClipboardText -ListAvailable) {
if (-not (Get-Alias -Name 'Set-Clipboard' -ErrorAction SilentlyContinue)) {
Set-Alias -Name 'Set-Clipboard' -Value 'Set-ClipboardText'
}
}
else {
$warning = "Cmdlet 'Set-Clipboard' not found. Copy functionality will not work until this is resovled. " +
"`n`t You can install the ClipboardText module from PowerShell Gallery, to add this functionality. " +
"`n`n`t`t Install-Module -Name ClipboardText`n" +
"`n`t More Details: https://www.powershellgallery.com/packages/ClipboardText"
Write-Warning $warning
}
}