{"id":14064497,"url":"https://github.com/hackf5/powershell-profile-alias","last_synced_at":"2025-07-29T18:32:42.230Z","repository":{"id":99041644,"uuid":"328428466","full_name":"hackf5/powershell-profile-alias","owner":"hackf5","description":"Bash style aliases in PowerShell","archived":false,"fork":false,"pushed_at":"2021-01-15T19:52:08.000Z","size":47,"stargazers_count":35,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-14T07:07:14.752Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackf5.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-10T16:33:53.000Z","updated_at":"2024-07-12T13:40:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"233c6fc3-1474-4d09-99f8-dd1f7b983f9b","html_url":"https://github.com/hackf5/powershell-profile-alias","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackf5%2Fpowershell-profile-alias","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackf5%2Fpowershell-profile-alias/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackf5%2Fpowershell-profile-alias/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackf5%2Fpowershell-profile-alias/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackf5","download_url":"https://codeload.github.com/hackf5/powershell-profile-alias/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228040683,"owners_count":17860211,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:03:53.782Z","updated_at":"2024-12-04T03:30:57.303Z","avatar_url":"https://github.com/hackf5.png","language":"PowerShell","funding_links":[],"categories":["PowerShell"],"sub_categories":[],"readme":"# PowerShell Profile Alias\n\n[![powershellgallery](https://img.shields.io/powershellgallery/v/HackF5.ProfileAlias)](https://www.powershellgallery.com/packages/HackF5.ProfileAlias)\n[![downloads](https://img.shields.io/powershellgallery/dt/HackF5.ProfileAlias.svg?label=downloads)](https://www.powershellgallery.com/packages/PowerShellForGitHub)\n[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/hackf5/powershell-profile-alias)](https://github.com/hackf5/powershell-profile-alias)\n[![downloads](https://img.shields.io/badge/license-MIT-green)](https://github.com/hackf5/powershell-profile-alias/blob/master/LICENSE)\n\nHaven't you ever wanted to write [bash aliases](https://opensource.com/article/19/7/bash-aliases) in PowerShell? You know, like all the cool kids do on their overpriced Mac books with the stickers on them that say things like *Reagan Bush '84*?\n\nJust imagine if you could do this?\n\n```powershell\n\u003e Set-ProfileAlias laws -Command (-join(\n    'docker run --network crypto_crypto-net --rm -it ',\n    '-v $env:userprofile\\.aws\\\\localstack:/root/.aws amazon/aws-cli ',\n    '--endpoint-url=http://localstack:4566 #{*}')) -Bash\n\u003e laws sqs list-queues\n    QueueUrls:\n    - http://localhost:4566/000000000000/my_queue\n    - http://localhost:4566/000000000000/queue1\n```\n\nHow awesome would it be? The possibilities are truly endless.\n\n## Installation\n\nThe module is available from the [PowerShell Gallery](https://www.powershellgallery.com/packages/HackF5.ProfileAlias). Once installed it needs to be registered with your  `$profile`.\n\n```powershell\n\u003e Install-Module HackF5.ProfileAlias\n\u003e Register-ProfileAliasInProfile\n```\n\nAll the registration does is add an explicit `Import-Module` to your `$profile`. This is necessary because the aliases are only available while the module is loaded. Since PowerShell lazy loads its modules, this is the only way to ensure that the aliases are always available.\n\n## Operations\n\nThe module supports the standard operations you would expect:\n\n- Create and Update via `Set-ProfileAlias`\n- Remove via `Remove-ProfileAlias`\n- Get via `Get-ProfileAlias`\n\n## Create and Update\n\nPowerShell has `New-Alias` and `Set-Alias`, which do the same thing with some nuance around the behavior of `-Force`. This module only has a `Set-` function.\n\nAfter creating or updating an alias it is persisted between sessions.\n\nIf your module is registered with more than one `$profile` then the alias will be available to those other profiles too.\n\n### Function\n\n```powershell\nSet-Alias\n    [-Name] \u003cstring\u003e\n    [-Command] \u003cstring\u003e\n    [-Bash]\n    [-Force]\n    [-Confirm]\n    [-Verbose]\n```\n\n- `Name` - the name of the alias.\n- `Command` - either something that you would pass to `Set-Alias -Value`, or a something more `bash`-like.\n- `Bash` - a switch that indicates whether this is a `bash`-style alias.\n- `Force` - overwrites an existing alias if one is present.\n- `Confirm` - prompts for confirmation before creating the alias.\n- `Verbose` - outputs verbose messages.\n\n### Arguments\n\nIn order for the `bash`-style aliases to be really useful you need to be able to inject arguments into them. This is done using the following placeholders:\n\n- `#{N}` - Injects argument `N` into the command. The first argument is `#{0}`.\n- `#{*}` - Injects all of the arguments into the command.\n- `#{:*}` - Injects all remaining arguments into the command. So if `#{0}` and `#{1}` are referenced in the command then this will inject arguments `#{2}, #{3}` and so on. Note that if you only reference `#{0}` and `#{2}` and forget `#{1}` this will inject `#{3}, #{4}` and so on. It won't warn you, it isn't very sophisticated.\n\nCurrently there is no way of escaping these arguments, so if you have a command where you actually need this syntax you are currently out of luck. Raise an issue stating why this is a problem for you and I will take a look at adding some escape mechanism. Better still, send me a pull request with the fix.\n\nIf you want to use these arguments inside a string, then you need to use double quoted `\"\"` strings and wrap them inside a `$()` statement. For example:\n\n```powershell\n\u003e Set-ProfileAlias echoecho 'echo \"$(#{0})$(#{0})\"' -Bash\n\u003e echoecho foo\n\nfoofoo\n```\n\n### Examples\n\nCreate a PowerShell-style alias.\n\n```powershell\n\u003e Set-ProfileAlias wget Invoke-WebRequest\n\u003e wget http://hackf5.io\n```\n\nCreate a bash-style alias without any arguments.\n\n```powershell\n\u003e Set-ProfileAlias sayhello 'echo \"hello world!\"' -Bash\n\u003e sayhello\n\nhello world!\n```\n\nCreate a bash-style alias with a single argument.\n\n```powershell\n\u003e Set-ProfileAlias e 'echo #{0}' -Bash\n\u003e e foo\n\nfoo\n```\n\nCreate a bash-style alias with multiple arguments.\n\n```powershell\n\u003e Set-ProfileAlias arr '@(#{0}, #{1}, #{2})' -Bash\n\u003e arr foo bar moo\n\nfoo\nbar\nmoo\n```\n\nCreate a bash style alias that uses remaining arguments.\n\n```powershell\n\u003e Set-ProfileAlias snip '#{:*} | where { $_ -ne #{0} }' -Bash\n\u003e snip foo bar moo foo bar moo foo\n\nbar\nmoo\nbar\nmoo\n```\n\nCreate a bash style alias that uses all of the arguments in one place.\n\n```powershell\n\u003e Set-ProfileAlias echoall '#{*} | echo' -Bash\n\u003e echoall foo bar moo\n\nfoo\nbar\nmoo\n```\n\n## How it works\n\nIn order for the `bash`-style aliases to work, the command needs to be wrapped in a function. For example in the original `docker` alias at the top of the readme, the function could look something like this:\n\n```powershell\nfunction Invoke-AwsDocker {\n    docker run --network crypto_crypto-net --rm -it `\n        -v $env:userprofile\\.aws\\\\localstack:/root/.aws amazon/aws-cli `\n        --endpoint-url=http://localstack:4566 $args\n}\n```\n\nNote the use of the catch all `$args` variable that is an array containing all of the arguments that the function was called with.\n\nNow I can create an alias to this function.\n\n```powershell\nSet-Alias laws Invoke-AwsDocker\n```\n\nAnd that's about it.\n\nThe problem of course is that defining one line functions and aliasing them in your modules folder is actually a real pain. It certainly isn't something you can do directly from the command line without significant effort.\n\nWhat this module does is save the commands it is given, modifying them slightly to inject the `$args` variable in such a way that it is available in nested script-blocks. Then from this saved list it builds a module that contains functions that wrap the commands along with all of the aliases against which these commands are registered. When the module is removed it removes all of the aliases that it has registered.\n\nEach time `Set-ProfileAlias` or `Remove-ProfileAlias` is called the old module is removed and a new one is built and loaded.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackf5%2Fpowershell-profile-alias","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackf5%2Fpowershell-profile-alias","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackf5%2Fpowershell-profile-alias/lists"}