https://github.com/alainQtec/PsImport
Import functions from other scripts.
https://github.com/alainQtec/PsImport
Last synced: 5 months ago
JSON representation
Import functions from other scripts.
- Host: GitHub
- URL: https://github.com/alainQtec/PsImport
- Owner: alainQtec
- License: mit
- Created: 2023-03-27T22:21:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-22T00:08:49.000Z (5 months ago)
- Last Synced: 2024-11-22T01:18:22.497Z (5 months ago)
- Language: PowerShell
- Homepage:
- Size: 239 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - alainQtec/PsImport - Import functions from other scripts. (PowerShell)
README
# [**PsImport**](https://www.powershellgallery.com/packages/PsImport)
A PowerShell module for importing functions.
[](https://github.com/alainQtec/PsImport/actions/workflows/CI.yaml)
[](https://github.com/alainQtec/PsImport/actions/workflows/Publish.yaml)
## **Installation**
```PowerShell
Install-Module PsImport
```## **Features**
- **Supports wildcards**:
```PowerShell
(Import * -from '/relative/path/to/script.ps1').ForEach({ . $_.ScriptBlock })
```Will load functions from the file into current script scope.
- **Importing from many files at once**:
```PowerShell
(Import * -from '/relative/path/to/fileNamedlikeabc*.ps1').ForEach({ . $_.ScriptBlock })
```Will load all functions from .ps1 files that look like fileNamedlikeabc
- **Import a function(s) from same repo**
```PowerShell
Cd GitHubRepo
(Import funcName1, funcName2).ForEach({ . $_.ScriptBlock })
```Will only load functions funcName1 and funcName2 from fileNameb.
*if you are sure no other file is named fileNameb is in the repo.
- **Import a function(s) from a remote script**
```PowerShell
(Import funcName -from https://example.com/MyRemoteScript.ps1).ForEach({ . $_.ScriptBlock })
```
- **more ?**```PowerShell
((ls ./Private -Filter "*.psm1" -Recurse).FullName | Get-Function)
```## **Todos**
- Fix edge cases when parsing files.
Sometimes it does not find all function declarations in file $filepath.
```PowerShell
[PsImport]::ParseFile($Filepath)
```For now it Works as expected only when there is a clear newline char (ie:
"`n") between each function in the file.- Remove (/ Find a workarround) for the '.ForEach({ . $_ })' that is used in the
import syntax.## **Contributions**

If you would like to contribute to psimport, please feel free to submit a pull
request on GitHub. We welcome contributions of all kinds, from bug fixes to new
features.## **License**
This module is licensed under the MIT
[License](https://alainQtec.MIT-license.org).