2012-08-27 47 views
5

什麼腳本,並在PowerShell的配置我應該按順序寫來定義:與RC-like文件

  1. alias for ll="ls -l"
  2. alias/function cd = "original cd; ll"

所以,我的問題有部分地方是Windows 7上的Power Shell的rc文件以及如何將ll改爲ls -lcd改爲cd; ll

回答

7

在鍵入$profile時在電源外殼指向的位置創建文件,如果不存在,請按Enter鍵。 (欲瞭解更多信息看here。)

而且我已經找到了很多很好的例子旁邊我的系統powershell.exe有一個例子文件夾,其中有一個文件名爲profile.ps1用下面的代碼:

set-alias cat  get-content 
set-alias cd   set-location 
set-alias clear  clear-host 
set-alias cp   copy-item 
set-alias h   get-history 
set-alias history get-history 
set-alias kill  stop-process 
set-alias lp   out-printer 
set-alias ls   get-childitem 
set-alias mount  new-mshdrive 
set-alias mv   move-item 
set-alias popd  pop-location 
set-alias ps   get-process 
set-alias pushd  push-location 
set-alias pwd  get-location 
set-alias r   invoke-history 
set-alias rm   remove-item 
set-alias rmdir  remove-item 
set-alias echo  write-output 

set-alias cls  clear-host 
set-alias chdir  set-location 
set-alias copy  copy-item 
set-alias del  remove-item 
set-alias dir  get-childitem 
set-alias erase  remove-item 
set-alias move  move-item 
set-alias rd   remove-item 
set-alias ren  rename-item 
set-alias set  set-variable 
set-alias type  get-content 

function help 
{ 
    get-help $args[0] | out-host -paging 
} 

function man 
{ 
    get-help $args[0] | out-host -paging 
} 

function mkdir 
{ 
    new-item -type directory -path $args 
} 

function md 
{ 
    new-item -type directory -path $args 
} 

function prompt 
{ 
    "PS " + $(get-location) + "> " 
} 

& { 
    for ($i = 0; $i -lt 26; $i++) 
    { 
     $funcname = ([System.Char]($i+65)) + ':' 
     $str = "function global:$funcname { set-location $funcname } " 
     invoke-expression $str 
    } 
} 

還考慮到以下問題。在執行位於$profile的文件時,您可能會遇到以下錯誤:

Microsoft.PowerShell_profile.ps1無法加載,因爲在此係統上禁用了腳本的執行。請參閱get-help about_signing瞭解更多詳情。

解決方案: 檢查當前執行的策略

PS C:\Windows\System32> Get-ExecutionPolicy 
Restricted 
PS C:\Windows\System32> 

要改變當前執行的策略使用: 注:此命令必須運行升高(啓動PowerShell中使用「以管理員身份運行」)

PS C:\Windows\System32> Set-Executionpolicy -ExecutionPolicy Unrestricted