2011-11-02 27 views

回答

4

您可以添加以下到$profile

$marks = @{}; 

$marksPath = Join-Path (split-path -parent $profile) .bookmarks 

if(test-path $marksPath){ 
import-csv $marksPath | %{$marks[$_.key]=$_.value} 
} 

function m($number){ 
$marks["$number"] = (pwd).path 
} 

function g($number){ 
cd $marks["$number"] 
} 

function mdump{ 
$marks.getenumerator() | export-csv $marksPath -notype 
} 

function lma{ 
$marks 
} 

我不喜歡爲每個類似的定義別名的方式m1m2等。相反,你會做m 1g 1

您還可以添加行

Register-EngineEvent PowerShell.Exiting –Action { mdump } | out-null 

,這樣它會做mdump當您退出PowerShell會話。不幸的是,如果你關閉了控制檯窗口,但是輸入了exit,則不起作用。

PS:也看看CDPATH:CDPATH functionality in Powershell?

+0

完美的作品!謝謝! – tltjr

0

我用這一招:

IM我的$的個人資料我寫的功能是這樣的:

function win { Set-Location c:\windows} 

$ProfileDir = $PROFILE.Substring(0 , $PROFILE.LastIndexOf("\")+1) 
function pro { Set-Location $profiledir} 

等等...