-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2047 from vors/powershell
Replace vendor powershell.tmBundle by SublimeText powershell
- Loading branch information
Showing
9 changed files
with
277 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# | ||
# Module manifest for module 'ZLocation' | ||
# | ||
# Generated by: sevoroby | ||
# | ||
# Generated on: 12/10/2014 | ||
# | ||
|
||
@{ | ||
|
||
# Script module or binary module file associated with this manifest. | ||
RootModule = 'ZLocation.psm1' | ||
|
||
# Version number of this module. | ||
ModuleVersion = '0.1' | ||
|
||
# ID used to uniquely identify this module | ||
GUID = '18e8ca17-7f67-4f1c-85ff-159373bf66f5' | ||
|
||
# Author of this module | ||
Author = 'Sergei Vorobev' | ||
|
||
# Company or vendor of this module | ||
CompanyName = 'Microsoft' | ||
|
||
# Copyright statement for this module | ||
Copyright = '(c) 2014 Sergei Vorobev. All rights reserved.' | ||
|
||
# Description of the functionality provided by this module | ||
# Description = '' | ||
|
||
# Minimum version of the Windows PowerShell engine required by this module | ||
# PowerShellVersion = '' | ||
|
||
# Name of the Windows PowerShell host required by this module | ||
# PowerShellHostName = '' | ||
|
||
# Minimum version of the Windows PowerShell host required by this module | ||
# PowerShellHostVersion = '' | ||
|
||
# Minimum version of Microsoft .NET Framework required by this module | ||
# DotNetFrameworkVersion = '' | ||
|
||
# Minimum version of the common language runtime (CLR) required by this module | ||
# CLRVersion = '' | ||
|
||
# Processor architecture (None, X86, Amd64) required by this module | ||
# ProcessorArchitecture = '' | ||
|
||
# Modules that must be imported into the global environment prior to importing this module | ||
# RequiredModules = @() | ||
|
||
# Assemblies that must be loaded prior to importing this module | ||
# RequiredAssemblies = @() | ||
|
||
# Script files (.ps1) that are run in the caller's environment prior to importing this module. | ||
# ScriptsToProcess = @() | ||
|
||
# Type files (.ps1xml) to be loaded when importing this module | ||
# TypesToProcess = @() | ||
|
||
# Format files (.ps1xml) to be loaded when importing this module | ||
# FormatsToProcess = @() | ||
|
||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | ||
NestedModules = @("ZLocation.Storage.psm1", "ZLocation.Search.psm1") | ||
|
||
# Functions to export from this module | ||
FunctionsToExport = '*' | ||
|
||
# Cmdlets to export from this module | ||
CmdletsToExport = '*' | ||
|
||
# Variables to export from this module | ||
VariablesToExport = '*' | ||
|
||
# Aliases to export from this module | ||
AliasesToExport = '*' | ||
|
||
# List of all modules packaged with this module | ||
# ModuleList = @() | ||
|
||
# List of all files packaged with this module | ||
# FileList = @() | ||
|
||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | ||
PrivateData = @{ | ||
|
||
PSData = @{ | ||
|
||
# Tags applied to this module. These help with module discovery in online galleries. | ||
# Tags = @() | ||
|
||
# A URL to the license for this module. | ||
# LicenseUri = '' | ||
|
||
# A URL to the main website for this project. | ||
# ProjectUri = '' | ||
|
||
# A URL to an icon representing this module. | ||
# IconUri = '' | ||
|
||
# ReleaseNotes of this module | ||
# ReleaseNotes = '' | ||
|
||
} # End of PSData hashtable | ||
|
||
} # End of PrivateData hashtable | ||
|
||
# HelpInfo URI of this module | ||
# HelpInfoURI = '' | ||
|
||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | ||
# DefaultCommandPrefix = '' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# | ||
# Weight function. | ||
# | ||
function Update-ZLocation([string]$path) | ||
{ | ||
$now = [datetime]::Now | ||
if (Test-Path variable:global:__zlocation_current) | ||
{ | ||
$prev = $global:__zlocation_current | ||
$weight = $now.Subtract($prev.Time).TotalSeconds | ||
Add-ZWeight ($prev.Location) $weight | ||
} | ||
|
||
$global:__zlocation_current = @{ | ||
Location = $path | ||
Time = [datetime]::Now | ||
} | ||
|
||
# populate folder immidiatly after the first cd | ||
Add-ZWeight $path 0 | ||
} | ||
|
||
# this approach hurts `cd` performance (0.0008 sec vs 0.025 sec). | ||
# Consider replace it with OnIdle Event. | ||
(Get-Variable pwd).attributes.Add((new-object ValidateScript { Update-ZLocation $_.Path; return $true })) | ||
# | ||
# End of weight function. | ||
# | ||
|
||
|
||
# | ||
# Tab complention. | ||
# | ||
if (Test-Path Function:\TabExpansion) { | ||
Rename-Item Function:\TabExpansion PreZTabExpansion | ||
} | ||
|
||
function Get-EscapedPath | ||
{ | ||
param( | ||
[Parameter( | ||
Position=0, | ||
Mandatory=$true, | ||
ValueFromPipeline=$true, | ||
ValueFromPipelineByPropertyName=$true) | ||
] | ||
[string]$path | ||
) | ||
|
||
process { | ||
if ($path.Contains(' ')) | ||
{ | ||
return '"' + $path + '"' | ||
} | ||
return $path | ||
} | ||
} | ||
|
||
function global:TabExpansion($line, $lastWord) { | ||
switch -regex ($line) { | ||
"^(Set-ZLocation|z) .*" { | ||
$arguments = $line -split ' ' | Where { $_.length -gt 0 } | select -Skip 1 | ||
Find-Matches (Get-ZLocation) $arguments | Get-EscapedPath | ||
} | ||
default { | ||
if (Test-Path Function:\PreZTabExpansion) { | ||
PreZTabExpansion $line $lastWord | ||
} | ||
} | ||
} | ||
} | ||
# | ||
# End of tab completion. | ||
# | ||
|
||
function Set-ZLocation() | ||
{ | ||
if (-not $args) { | ||
$args = @() | ||
} | ||
$matches = Find-Matches (Get-ZLocation) $args | ||
if ($matches) { | ||
Push-Location ($matches | Select-Object -First 1) | ||
} else { | ||
Write-Warning "Cannot find matching location" | ||
} | ||
} | ||
|
||
|
||
Set-Alias -Name z -Value Set-ZLocation | ||
Export-ModuleMember -Function Set-ZLocation, Get-ZLocation -Alias z |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
function Save-HistoryAll() { | ||
$history = Get-History -Count $MaximumHistoryCount | ||
[array]::Reverse($history) | ||
$history = $history | Group CommandLine | Foreach {$_.Group[0]} | ||
[array]::Reverse($history) | ||
$history | Export-Csv $historyPath | ||
} | ||
|
||
function Save-HistoryIncremental() { | ||
# Get-History -Count $MaximumHistoryCount | Group CommandLine | Foreach {$_.Group[0]} | Export-Csv $historyPath | ||
Get-History -Count 1 | Export-Csv -Append $historyPath | ||
} | ||
|
||
# hook powershell's exiting event & hide the registration with -supportevent. | ||
#Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action { Save-History } | ||
|
||
$oldPrompt = Get-Content function:\prompt | ||
|
||
if( $oldPrompt -notlike '*Save-HistoryIncremental*' ) | ||
{ | ||
$newPrompt = @' | ||
Save-HistoryIncremental | ||
'@ | ||
$newPrompt += $oldPrompt | ||
$function:prompt = [ScriptBlock]::Create($newPrompt) | ||
} | ||
|
||
# load previous history, if it exists | ||
if ((Test-Path $historyPath)) { | ||
$loadTime = | ||
( | ||
Measure-Command { | ||
Import-Csv $historyPath | Add-History | ||
Save-HistoryAll | ||
Clear-History | ||
Import-Csv $historyPath | ? {$count++;$true} | Add-History | ||
} | ||
).totalseconds | ||
Write-Host -Fore Green "`nLoaded $count history item(s) in $loadTime seconds.`n" | ||
} | ||
|
||
|
||
function Search-History() | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Retrive and filter history based on query | ||
.DESCRIPTION | ||
.PARAMETER Name | ||
.EXAMPLE | ||
.LINK | ||
#> | ||
|
||
param( | ||
[string[]] $query | ||
) | ||
|
||
$history = Get-History -Count $MaximumHistoryCount | ||
foreach ($item in $query){ | ||
$item = $item.ToLower() | ||
$history = $history | where {$_.CommandLine.ToLower().Contains($item)} | ||
} | ||
$history | ||
} |
Submodule powershell
added at
84fd97
Submodule powershell.tmbundle
deleted from
f8716b