Skip to content

Commit

Permalink
Merge pull request #21 from JPHutchins/fix/windows-aliases-run-from-s…
Browse files Browse the repository at this point in the history
…cript

Fix/windows aliases run from script
  • Loading branch information
JPHutchins authored May 24, 2024
2 parents 0a38fc6 + e22a52a commit c8928d0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ envr can be used with bash, zsh, and PowerShell in Linux, Windows, and MacOS. S
# Usage

- Activate the environment: `. ./envr.ps1`
- You can [alias](#installation) `envr` to `. ./envr.ps1` in your shell profile for convenience
- Deactivate the environment: `unsource`
- Upgrade to the latest version:
```
Expand Down Expand Up @@ -92,6 +93,27 @@ flash=cmake -GNinja -Bbuild -DBOARD=hrv43 -DCMAKE_BUILD_TYPE=Debug -DLOG_LEVEL=I

* `unsource`

## Installation

`envr` does not need to be installed, but it can be nice to add the alias `envr`
to your shell profile, allowing you to activate the environment of the current
directory with `envr` instead of `. ./envr.ps1`.

### PowerShell
```powershell
Add-Content -Path $profile -Value "function envr { . ./envr.ps1 }"
```

### bash
```bash
echo "alias envr='. ./envr.ps1'" >> ~/.bashrc
```

### zsh
```bash
echo "alias envr='. ./envr.ps1'" >> ~/.zshrc
```

### Why .ps1?

#$&*%^
Expand Down
21 changes: 17 additions & 4 deletions envr.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
# envr v0.5.4
# envr v0.5.5
# https://www.github.com/JPHutchins/envr
# https://www.crumpledpaper.tech

# MIT License
# Copyright (c) 2022-2023 J.P. Hutchins
# Copyright (c) 2022-2024 JP Hutchins
# License text at the bottom of this source file

# Usage: . ./envr.ps1

# To "install" envr, add the alias `envr = . ./envr.ps1` to your shell profile.
# This will allow you to run `envr` instead of `. ./envr.ps1` to activate the
# environment defined for the current directory,

# Windows (PowerShell) "installation":
# Add-Content -Path $profile -Value "function envr { . ./envr.ps1 }"

# bash "installation":
# echo "alias envr='. ./envr.ps1'" >> ~/.bashrc

# zsh "installation":
# echo "alias envr='. ./envr.ps1'" >> ~/.zshrc

# The following line is for PowerShell/bash cross compatability.
# - The bash section shall begin with the delimiter "<#'"
# - The bash section shall end with the delimiter "#>"
Expand Down Expand Up @@ -678,7 +691,7 @@ $global:_ENVR_NEW_ALIASES.GetEnumerator().ForEach({
function _ENVR_ALIAS_FN_7 { Invoke-Expression "$($global:_ALIAS_COMMAND_ARR[7]) $args" }
function _ENVR_ALIAS_FN_8 { Invoke-Expression "$($global:_ALIAS_COMMAND_ARR[8]) $args" }
function _ENVR_ALIAS_FN_9 { Invoke-Expression "$($global:_ALIAS_COMMAND_ARR[9]) $args" }
Set-Alias -Name $key -Value "_ENVR_ALIAS_FN_$global:_ALIAS_FN_INDEX"
Set-Alias -Name $key -Value "_ENVR_ALIAS_FN_$global:_ALIAS_FN_INDEX" -Scope script
$global:_ALIAS_FN_INDEX += 1
})

Expand Down Expand Up @@ -746,7 +759,7 @@ POWERSHELL_SECTION
# License text continued

# MIT License
# Copyright (c) 2022 J.P. Hutchins
# Copyright (c) 2022-2024 JP Hutchins

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit c8928d0

Please sign in to comment.