An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# [**PsImport**](https://www.powershellgallery.com/packages/PsImport)

A PowerShell module for importing functions.

[![CI](https://github.com/alainQtec/PsImport/actions/workflows/CI.yaml/badge.svg)](https://github.com/alainQtec/PsImport/actions/workflows/CI.yaml)

[![Publish to PowerShell Gallery](https://github.com/alainQtec/PsImport/actions/workflows/Publish.yaml/badge.svg?branch=main)](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**

![Alt](https://repobeats.axiom.co/api/embed/c7f1a37fb73368e4265faca921b76e3d4448defb.svg "Repobeats analytics image")

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).