Skip to content

Wielding/WieldingLocation

Repository files navigation

WieldingLocation

Powershell Quick Locations.

This module adds functions to assist with navigating to common directories and files quickly with autocompletion.

It is growing beyond its original purpose and now supports executing frequent commands and copying stored locations and commands to the clipboard. The clipboard functionality only works with Windows hosts at the moment.

Quick Start

  1. Install Module
Install-Module -Name WieldingLocation
  1. Set a frequently used location
Set-QuickLocation -Alias "doc" -Location "~\Documents"

or using the short form with the exported alias ql

ql doc "~\Documents"
  1. Now that you have added a location you can jump to your documents folder from wherever you are in your filesystem by simply typing the name of the alias after the ql alias. The command implements tab completion with the names from your saved locations to make navigating even faster.
ql doc
  1. Set a frequently used file to an alias
Set-QuickLocation -Alias pro -Location $profile

Now when you type

ql pro

The system should open the Powershell profile using the default application for the file extension. So far this only seems to work under Windows. Maybe some Linux Distributions or MacOs has the capability to open files from the command line but I can't test them all. It does not work under my WSL distributions.

If you want to remove a location prefix the name with a "!"

Set-QuickLocation -Alias !pro

or with the alias

ql !pro

This will remove the alias "pro" from your location list.

  1. Copy location to clipboard

You can also have your quick location entries copied to the clipboard (Windows only).

Copy-QuickLocation pro

or with the alias

qlc pro

This will put the contents of the 'pro' alias to the clipboard on Windows. I will investigate checking for linux and maybe using xclip to implement this functionality under an X11 environment.

You can store arbitrary data in the location list by using the -Force option. This will prevent validating that the data is a location on your file system.

qlc name "Joe User" -Force

This will add "Joe User" to the quick location list which can then be place on the clipboard with

qlc name
  1. You can store shortcuts to frequently used powershell commands by adding a '~' prefix to your alias. You can put anything that Powershell understands when using the Invoke-Command script block.

For example

ql ~wh "Write-Host 'test'" -Force

This will store an alias named "[wh" with the value "Write-Host 'test'" .

You can now execute that command with

ql ~wh

To see your current quick locations use Show-QuickLocation or the alias qll.

If you have tried the above examples the qll command should output something like

Name                           Value
----                           -----
doc                            C:\Users\<user name>\Documents
name                           Joe User
~wh                            Write-Host 'test'

The command has Tab-Completion so if you have many location aliases set you can start typing and hit the tab key to cycle through the available names.

You can save your current quick locations and restore them by adding some code to your Powershell profile.

I don't want the module to be responsible for deciding how and where you store your data so I am leaving it to the user. Here is an example of how you might implement that for yourself under Windows.

In your powershell profile you can add the following.

Import-Module WieldingLocation

$quickConfigLocation = "~\.config\WieldingLocation\locations.json"

function Save-QuickLocations {
  Set-Content -Path $quickConfigLocation (ConvertTo-Json -InputObject $QuickLocation -Depth 10)
}

if (Test-Path -Path $quickConfigLocation) {
  $QuickLocation = (Get-Content -Path $quickConfigLocation | ConvertFrom-Json -AsHashtable)
}

This will load your saved locations when you start a new Powershell session and gives you a function Save-QuickLocations that you can manually call if you want to save your current quick location data so that it will be reloaded on the next start of your Powershell console. This way you are in control and can even load different quick locations for different situations.

Examples

ql doc "~\Documents" # set the name doc to point to your documents folder (Windows)
ql doc # change to your documents folder
ql # change to the previous folder you were in
ql # toggle back to the documents folder.
ql # toggle again
qll # lists all of the folder definitions
qlc doc # copy the location referenced by 'doc' to the clipboard
ql !doc # remove the doc alias from your locations
ql ~env "Get-ChildItem env:" -Force # create a quick command to show your enviroment variables
ql ~env # executes the '~env' alias which will show your environment variables

About

Powershell module to enable quick access to locations and commands.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published