我最喜歡的Bash技巧之一是創建用於標記和返回目錄的別名,如下所述:http://www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/。Powershell中的目錄書籤?
在bash,它看起來像這樣:
alias m1='alias g1="cd `pwd`"'
是否有可能建立在PowerShell中有類似的功能?
我最喜歡的Bash技巧之一是創建用於標記和返回目錄的別名,如下所述:http://www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/。Powershell中的目錄書籤?
在bash,它看起來像這樣:
alias m1='alias g1="cd `pwd`"'
是否有可能建立在PowerShell中有類似的功能?
您可以添加以下到$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
}
我不喜歡爲每個類似的定義別名的方式m1
,m2
等。相反,你會做m 1
和g 1
等
您還可以添加行
Register-EngineEvent PowerShell.Exiting –Action { mdump } | out-null
,這樣它會做mdump
當您退出PowerShell會話。不幸的是,如果你關閉了控制檯窗口,但是輸入了exit,則不起作用。
PS:也看看CDPATH:CDPATH functionality in Powershell?
我用這一招:
IM我的$的個人資料我寫的功能是這樣的:
function win { Set-Location c:\windows}
$ProfileDir = $PROFILE.Substring(0 , $PROFILE.LastIndexOf("\")+1)
function pro { Set-Location $profiledir}
等等...
安裝:
Install-Module -Name PSBookmark
用途:
#This will save $PWD as scripts
save scripts
#This will save C:\Documents as docs
save docs C:\Documents
#You don't have to type the alias name.
#Instead, you can just tab complete. This function uses dynamic parameters.
goto docs
完美的作品!謝謝! – tltjr