Windows也能拥有好用的命令行吗?Powershell+Terminal折腾记录(v1.0版本)

PS:本文写于2021年,现在已经是2024年,有了很多新变化,我在接下来的文章里会继续更新。

前言

Windows一向以图形化操作入门容易著称,所以对于命令行的支持一直为人所诟病,比起Linux或者mac都是被吊打的。这一局面在最近几个版本的Windows10更新里,特别是微软官方出了WindowsTerminal这个大杀器之后有所改善~

所以对于标题的这个问题,只能说「勉强可以吧」,本文介绍几个折腾命令行的方法。

效果图

偷一张官方的截图,应该没人发现吧

建议先熟读官方文档:https://docs.microsoft.com/zh-cn/windows/terminal/

软件包管理器 Scoop

不用羡慕Linux上好用的apt和yum,Windows上也有不错的软件包管理器,比如chocolate、官方的win-get,还有本文介绍的scoop,相比起chocol ate,scoop的软件包仓库都是社区维护开源的,安全性更有保障,并且比官方的win-get多很多~ 不够可以自己添加软件源,就像apt的PPA源。

官网:https://scoop.sh/

安装:

复制代码
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex

oh-my-posh & powerline

用过oh-my-zsh的同学就知道这个oh-my-xxx的项目了~ Windows上自然不能少~

地址: https://ohmyposh.dev/docs/

首先下载powerline字体并安装,These fonts can be installed from the Cascadia Code GitHub releases page.

输入命令安装powershell插件,post-git需要git支持,If you don't already have it, install Git for Windows.

复制代码
Install-Module posh-git -Scope CurrentUser
Install-Module oh-my-posh -Scope CurrentUser

Open your PowerShell profile with notepad $PROFILE,输入以下内容:

复制代码
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox

打开terminal配置,修改字体,for example:

json 复制代码
{
    // Make changes here to the powershell.exe profile.
    "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
    "name": "Windows PowerShell",
    "commandline": "powershell.exe",
    "fontFace": "Cascadia Code PL",
    "hidden": false
},

配置完的效果:

参考资料:https://docs.microsoft.com/en-us/windows/terminal/tutorials/powerline-setup

使用sudo(gsudo)

在用Windows的powershell的时候,有时一些操作是需要管理员权限的,但是不像Linux那么方便,一句sudo命令即可提权,Windows往往需要右键点击开始菜单,选择powershell的管理员模式。

麻烦不说,还可能导致心急的同学砸键盘

不过办法总比困难多,这不有了开源的gsudo,可以在Windows方便提权,安装方法如下~

安装:

复制代码
PowerShell -Command "Set-ExecutionPolicy RemoteSigned -scope Process; iwr -useb https://raw.githubusercontent.com/gerardog/gsudo/master/installgsudo.ps1 | iex"

装完就可以直接在powershell里使用sudo命令提权了,同时可以在Terminal里添加一个管理员权限的标签卡,看看怎么配置

在terminal的配置文件中添加一项:

json 复制代码
"list": [
  {
      "guid": "{41dd7a51-f0e1-4420-a2ec-1a7130b7e950}",
      "name": "Windows PowerShell Elevated",
      "commandline": "gsudo.exe powershell.exe",
      "hidden": false,
      "colorScheme": "Solarized Dark",
      "fontFace": "Fira Code",
      "icon" : "https://i.imgur.com/Giuj3FT.png"
  },
  //...
]

参考资料

相关推荐
杼蛘2 小时前
XXL-Job工具使用操作记录
linux·windows·python·jdk·kettle·xxl-job
qq_251533592 小时前
查找 Python 中对象使用的内存量
开发语言·windows·python
JH灰色2 小时前
【大模型】-LangChain--Agent
windows·microsoft·langchain
世转神风-3 小时前
windows-ps1-脚本-删除文件
windows
TToolss3 小时前
新手使用frp,3端全部Windows
windows
普通网友4 小时前
24年9月最新微软copilot国内Windows11强制开启使用教程方法
windows·ai·微软·copilot
qq_420443274 小时前
AMD显卡在windows中通过WSL安装使用stable diffusion(WebUI和ComfyUI)
linux·windows·ubuntu·stable diffusion·wsl
网安入门学习4 小时前
2025年AIGC人才需求报告:从招聘数据看行业趋势与技能要求
人工智能·windows·ai作画·stable diffusion·aigc
HLJ洛神千羽4 小时前
使用MediaCreationTool修复/升级到Windows10系统
windows
小新软件园4 小时前
视频字幕提取自由!望言 OCR 免费版 零门槛提字幕
windows·电脑·开源软件